InvoiceController.php 330 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110
  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. //echo $routeRs ['1'];
  102. //die('dd');
  103. if (isset ( $_COOKIE ["staff"] )) {
  104. if (! empty ( $_COOKIE ["staff"] )) {
  105. Doo::loadModel ( 'staff' );
  106. $staff = new staff ();
  107. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  108. $this->ACTION = $uriPartsOrig [1];
  109. $this->data ['new'] = $this->isInvoiceNew ();
  110. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  111. $this->data ['isStaffCompleteMsg'] = false;
  112. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  113. if (! empty ( $detail ))
  114. $this->data ['isStaffCompleteMsg'] = true;
  115. return "/";
  116. }
  117. }
  118. Doo::loadCore ( 'uri/DooUriRouter' );
  119. $router = new DooUriRouter ();
  120. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  121. if ($routeRs ['1'] != "login") {
  122. header ( 'Content-Type:text/html;charset=utf-8' );
  123. @header ( "Location: /login" );
  124. }
  125. }
  126. function testSend() {
  127. // 测试根据规则发送信息 普通发送
  128. // $pendingApprovalsSid = 41;
  129. // Doo::loadModel ( 'staff' );
  130. // $staff = new staff ();
  131. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  132. // // 发送微信审批通知
  133. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  134. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  135. // Doo::loadModel ( 'staff' );
  136. // $staff = new staff ();
  137. // $toparty = $this->getToparty ( '广东办' );
  138. // $wxList = array ();
  139. // if (! empty ( $toparty )) {
  140. // $userList = $this->getUserByToparty ( $toparty );
  141. // $userCon = implode ( ',', $userList );
  142. // // echo $userCon;
  143. // $sidList = $staff->getStaffByWxid ( $userCon );
  144. // foreach ( $sidList as $key => $value ) {
  145. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  146. // if ($falg) {
  147. // array_push ( $wxList, $value ['wxid'] );
  148. // }
  149. // }
  150. // $wxString = implode ( '|', $wxList );
  151. // print_r ( $wxList );
  152. // echo $wxString;
  153. // }
  154. // 测试发送
  155. /*
  156. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  157. */
  158. // print_r ( $userList );
  159. // $msTouser='caipin|outaozhen';
  160. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  161. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  162. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  163. // $toparty= $this->getToparty('广东办');
  164. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  165. // $toparty = 26;
  166. // $msg = '';
  167. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  168. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  169. }
  170. function invoice() {
  171. Doo::loadModel ( 'invoice' );
  172. $invoice = new invoice ();
  173. Doo::loadModel ( 'express' );
  174. $express = new express ();
  175. $expressList = $express->getExpressByAll ();
  176. $this->data ['expressList'] = $expressList;
  177. // Doo::loadModel ( 'invoiceReceivables' );
  178. // $invoiceReceivables = new invoiceReceivables ();
  179. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  180. Doo::loadClass ( 'XDeode' );
  181. $XDeode = new XDeode ( 5 );
  182. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  183. Doo::loadModel ( 'invoiceStatistics' );
  184. $invoiceStatistics = new invoiceStatistics ();
  185. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $sid );
  186. // 缓存统计结果
  187. $year = date ( "Y" );
  188. $tmp_date = date ( "Ym" );
  189. $tmp_year = substr ( $tmp_date, 0, 4 );
  190. $tmp_mon = substr ( $tmp_date, 4, 2 );
  191. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  192. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  193. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . "_" . $sid . ".htm";
  194. if (is_file ( $path ))
  195. $htm = file_get_contents ( $path );
  196. else
  197. $htm = $this->showCache ( $path, $sid );
  198. $invoiceList = $invoice->getMyInvoice ( $sid );
  199. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  200. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  201. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  202. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  203. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  204. // 获得已退票功能
  205. $untreadStatusList = $invoice->getMyInvoiceByUntreadStatus ( 2, 0, 5, $sid );
  206. $this->data ['untreadStatusList'] = $untreadStatusList;
  207. // print_r($untreadStatusList);
  208. $this->data ['isMonth'] = $isMonth;
  209. $this->data ['htm'] = $htm;
  210. $this->data ['invoiceList'] = $invoiceList;
  211. $this->data ['receivablesList'] = $list;
  212. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  213. $this->data ['memu'] = "invoice";
  214. $this->data ['staff'] = $this->staff;
  215. $this->data ['receiptMemu'] = 'invoice';
  216. $this->render ( "/admin/invoice", $this->data );
  217. }
  218. function invoiceExpress() {
  219. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  220. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  221. $this->data ['expressCom'] = $expressCom;
  222. $this->data ['expressNumber'] = $expressNumber;
  223. $this->render ( "/admin/invoiceExpress", $this->data );
  224. }
  225. function invoiceAdd() {
  226. session_start ();
  227. /*Doo::loadModel ( 'invoice' );
  228. $invoice = new invoice ();
  229. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );*/
  230. Doo::loadModel ( 'L_category' );
  231. $lCategory = new L_category ();
  232. $category = $lCategory->find ( array (
  233. 'asArray' => true
  234. ) );
  235. $this->data ['category'] = $category;
  236. Doo::loadModel ( 'invoiceTraining' );
  237. $invoiceTraining = new invoiceTraining ();
  238. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  239. Doo::loadModel ( 'receipt' );
  240. $receipt = new receipt ();
  241. foreach ( $itList as $key => $value ) { // 不展示已结算完结的培训班
  242. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['itid'] );
  243. if (! empty ( $receiptDetail )) {
  244. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  245. unset ( $itList [$key] );
  246. }
  247. }
  248. }
  249. $this->data ['itList'] = $itList;
  250. $token = $this->set_token ();
  251. $tokenTime=time().rand(5, 15);
  252. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  253. $this->data ['token'] = $token;
  254. $this->data['tokenTime']=$tokenTime;
  255. $this->data ['memu'] = "invoice";
  256. $this->data ['staff'] = $this->staff;
  257. $this->data ['receiptMemu'] = 'invoice';
  258. $this->render ( "/admin/invoiceAdd", $this->data );
  259. }
  260. /**
  261. * 自更新发票信息库
  262. * @param unknown $invoicePrintDetail
  263. */
  264. function autoUpdateInvoiceInfoBase($invoicePrintDetail) {
  265. // 发票信息库
  266. Doo::loadModel ( 'invoiceInfoBase' );
  267. $invoiceInfoBase = new invoiceInfoBase ();
  268. $updateDate = strtotime ( $invoicePrintDetail ['date'] );
  269. $TIN = $invoicePrintDetail ['TIN'];
  270. $invoiceTitle = $invoicePrintDetail ['invoiceTitle'];
  271. if (empty ( $invoiceTitle ))
  272. $invoiceTitle = $invoicePrintDetail ['invoiceCompany'];
  273. $IIBList = $invoiceInfoBase->getInvoiceInfoByTT ( $TIN, $invoiceTitle );
  274. // 确认有该条发票信息
  275. $invoiceInfoBase = new invoiceInfoBase ();
  276. if (! empty ( $IIBList )) {
  277. // 发票库里的信息数量
  278. $IIBListCount = count ( $IIBList );
  279. if ($IIBListCount == 1) { // 更新发票--提交是最新的时间
  280. $item = array (
  281. 'iibID' => $IIBList [0] ['iibID'],
  282. 'invoiceTitle' => $invoiceTitle,
  283. 'TIN' => $TIN
  284. );
  285. if (! empty ( $invoicePrintDetail ['address'] )) {
  286. $item += array (
  287. 'address' => $invoicePrintDetail ['address']
  288. );
  289. }
  290. if (! empty ( $invoicePrintDetail ['phone'] )) {
  291. $item += array (
  292. 'phone' => $invoicePrintDetail ['phone']
  293. );
  294. }
  295. if (! empty ( $invoicePrintDetail ['bank'] )) {
  296. $item += array (
  297. 'bank' => $invoicePrintDetail ['bank']
  298. );
  299. }
  300. if (! empty ( $invoicePrintDetail ['bankAccount'] )) {
  301. $item += array (
  302. 'bankAccount' => $invoicePrintDetail ['bankAccount']
  303. );
  304. }
  305. if ($updateDate >= strtotime ($IIBList [0] ['updateDate'])) {
  306. $item += array (
  307. 'updateDate' => $invoicePrintDetail ['date']
  308. );
  309. $invoiceInfoBase->setInvoiceInfoBaseByCondition ( $item );
  310. }
  311. } else { // 删除多张发票,重新添加发票
  312. $iibIDStr = '';
  313. $iibID = array ();
  314. foreach ( $IIBList as $key => $value ) {
  315. array_push ( $iibID, $value ['iibID'] );
  316. }
  317. $iibIDStr = implode ( ",", $iibID ); // 删除
  318. $invoiceInfoBase->delInvoiceInfoBaseByIibStr ( $iibIDStr );
  319. $item = array (
  320. 'invoiceTitle' => $invoiceTitle,
  321. 'TIN' => $TIN,
  322. 'address' => $invoicePrintDetail ['address'],
  323. 'phone' => $invoicePrintDetail ['phone'],
  324. 'bank' => $invoicePrintDetail ['bank'],
  325. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  326. 'updateDate' => $invoicePrintDetail ['date']
  327. );
  328. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  329. }
  330. } else { // 没有新增发票信息
  331. $item = array (
  332. 'invoiceTitle' => $invoiceTitle,
  333. 'TIN' => $TIN,
  334. 'address' => $invoicePrintDetail ['address'],
  335. 'phone' => $invoicePrintDetail ['phone'],
  336. 'bank' => $invoicePrintDetail ['bank'],
  337. 'bankAccount' => $invoicePrintDetail ['bankAccount'],
  338. 'updateDate' => $invoicePrintDetail ['date']
  339. );
  340. $invoiceInfoBase->addInvoiceInfoBase ( $item );
  341. }
  342. }
  343. function invoiceAddFill() {
  344. session_start ();
  345. Doo::loadModel ( 'L_category' );
  346. $lCategory = new L_category ();
  347. $category = $lCategory->find ( array (
  348. 'asArray' => true
  349. ) );
  350. $this->data ['category'] = $category;
  351. Doo::loadModel ( 'invoiceTraining' );
  352. $invoiceTraining = new invoiceTraining ();
  353. $itList = $invoiceTraining->getInvoiceTrainingByCid ( $this->staff [0] ['cid'] );
  354. $this->data ['itList'] = $itList;
  355. Doo::loadModel ( 'invoice' );
  356. $invoice = new invoice ();
  357. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  358. $detail ['mailItemsArray'] = json_decode ( $detail ['mailItemsJson'], true );
  359. $token = $this->set_token ();
  360. $tokenTime=time().rand(5, 15);
  361. $_SESSION ['token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime] = $token;
  362. $this->data ['token'] = $token;
  363. $this->data['tokenTime']=$tokenTime;
  364. $this->data ['invoiceDetail'] = $detail;
  365. $this->data ['memu'] = "invoice";
  366. $this->data ['staff'] = $this->staff;
  367. $this->data ['receiptMemu'] = 'invoice';
  368. $this->render ( "/admin/invoiceAddFill", $this->data );
  369. }
  370. /**
  371. * 提交一份开票申请,并记录下操作日志
  372. *
  373. * @since 1.0.0
  374. * @var integer cid 办事处ID
  375. * @var integer invoiceType 发票类型
  376. * @var integer doPost 是否邮寄
  377. * @var integer invoicePrice 开票金额
  378. * @var string invoiceElement 开票内容
  379. * @var string invoiceTitle 发票抬头
  380. * @var string invoiceCompany 单位名称
  381. * @var string TIN 纳税人识别码
  382. * @var string address 注册地址
  383. * @var string phone 注册电话
  384. * @var string bank 开户银行
  385. * @var string bankAccount 银行账户
  386. * @var string recipients 收件人
  387. * @var string recipientsPhone 收件人手机/电话
  388. * @var string recipientsAddress 收件地址
  389. * @var string mailItems 邮寄物品
  390. * @var string remark 备注
  391. * @return string 返回跳转开票主页路径
  392. */
  393. function invoiceAddDo() {
  394. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  395. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  396. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  397. // $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  398. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  399. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  400. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  401. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  402. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  403. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  404. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  405. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  406. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  407. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  408. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  409. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  410. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  411. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  412. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  413. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  414. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  415. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  416. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  417. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  418. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  419. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  420. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  421. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  422. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  423. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  424. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  425. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  426. $trainId = $this->get_args ( 'trainId' ) ? $this->get_args ( 'trainId' ) : 0;
  427. $settlementType = $this->get_args ( 'settlementType' ) ? $this->get_args ( 'settlementType' ) : "";
  428. $electronicPhone= $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  429. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  430. /*
  431. * $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;
  432. */
  433. $token = $this->get_args ( 'token' ) ? $this->get_args ( 'token' ) : "";
  434. $tokenTime = $this->get_args ( 'tokenTime' ) ? $this->get_args ( 'tokenTime' ) : "";
  435. if (empty ( $token )) {
  436. die ( 'illegal request-token' );
  437. } else {
  438. session_start ();
  439. $sessionKey='token_' . $this->staff [0] ['sidKey'].'_'.$tokenTime;
  440. header ( 'Content-Type:text/html;charset=utf-8' );
  441. if (!isset($_SESSION [$sessionKey])||empty($_SESSION [$sessionKey])) {
  442. die ( '请重新刷新发票申请页面' );
  443. }elseif($_SESSION [$sessionKey]=='repeat'){
  444. die ( '请勿重复申请发票' );
  445. } else {
  446. if ($_SESSION [$sessionKey] != $token){
  447. die ( '请勿重复申请发票' );
  448. }else{
  449. $_SESSION [$sessionKey] = 'repeat';
  450. }
  451. }
  452. }
  453. if($invoiceForm=='electronic'){
  454. if(empty(trim($electronicPhone))&&empty(trim($electronicEmail))){
  455. die ( '请至少填写一种联系方式--电子发票' );
  456. }
  457. }
  458. if ($invoiceType == 1) {
  459. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  460. if ($temporary > 100001) {
  461. header ( 'Content-Type:text/html;charset=utf-8' );
  462. die ( '专用发票总金额暂时不能超过100000.00(十万)元。' );
  463. }
  464. }elseif($invoiceType == 0){
  465. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  466. if ($temporary > 100001) {
  467. header ( 'Content-Type:text/html;charset=utf-8' );
  468. die ( '专用发票总金额暂时不能超过100000.00(十万)元。' );
  469. }
  470. }else{
  471. die ( 'illegal request-invoiceType' );
  472. }
  473. if (empty ( $this->staff [0] ))
  474. die ( 'illegal request-Please login' );
  475. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $settlementType )&&!empty($invoiceForm)) {
  476. Doo::loadModel ( 'invoice' );
  477. $invoice = new invoice ();
  478. Doo::loadModel ( 'L_category' );
  479. $lCategory = new L_category ();
  480. Doo::loadModel ( 'invoiceManage' );
  481. $invoiceManage = new invoiceManage ();
  482. Doo::loadModel ( 'invoiceOperationLog' );
  483. $invoiceOperationLog = new invoiceOperationLog ();
  484. Doo::loadClass ( 'XDeode' );
  485. $XDeode = new XDeode ( 5 );
  486. $trainId = $XDeode->decode ( $trainId );
  487. $categoryDetil = $lCategory->getOne ( array (
  488. 'SELECT' => 'title',
  489. 'where' => 'cid=' . $cid,
  490. 'asArray' => true
  491. ) );
  492. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  493. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  494. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  495. // print_r(current($invoiceManageDetail ['staffList']));
  496. // die;
  497. $moldManage = array ();
  498. foreach ( $invoiceManageList as $key => $value ) {
  499. if ($value ['mold'] == '发票打印')
  500. $moldManage [$value ['mold']] = $value ['staffList'];
  501. elseif ($value ['mold'] == '发票邮寄')
  502. $moldManage [$value ['mold']] = $value ['staffList'];
  503. elseif ($value ['mold'] == '发票退票')
  504. $moldManage [$value ['mold']] = $value ['staffList'];
  505. }
  506. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  507. $st = '';
  508. if ($settlementType == 'SOFTWARE') {
  509. $st = 0;
  510. $trainId = 0;
  511. } elseif ($settlementType == 'TRAINING') {
  512. $st = 1;
  513. if (empty ( $trainId ) && ! is_numeric ( $trainId )) {
  514. die ( 'illegal request-trainingIdError' );
  515. }
  516. } else {
  517. die ( 'illegal request-settlementError' );
  518. }
  519. if($invoiceForm=='electronic'){
  520. $invoiceSerial="#FE" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  521. $invoiceForm=1;
  522. $invoiceType=0;
  523. if(!empty($electronicPhone)||!empty($electronicEmail)){
  524. }else{
  525. die ( 'illegal request-electronicContact' );
  526. }
  527. $mailList = array ();
  528. $mailString = '备注:' . $mailItems;
  529. }elseif($invoiceForm=='paper'){
  530. $invoiceSerial="#F" . date('Ymd') . str_pad(mt_rand(1, 99999), 5, '0', STR_PAD_LEFT);
  531. $invoiceForm=0;
  532. $mailList = array (
  533. 'invoice' => 1,
  534. 'mailItems' => $mailItems
  535. );
  536. $mailString = '发票x1张,备注:' . $mailItems;
  537. }else{
  538. die ( 'illegal request-invoiceForm' );
  539. }
  540. $item = array (
  541. 'cid' => $cid,
  542. 'categoryName' => $categoryDetil ['title'],
  543. 'invoiceElement' => $invoiceElement,
  544. 'invoiceForm'=>$invoiceForm,
  545. 'electronicPhone'=>$electronicPhone,
  546. 'electronicEmail'=>$electronicEmail,
  547. 'invoiceQuantity' => $invoiceQuantity,
  548. 'invoiceUnitPrice' => $invoiceUnitPrice,
  549. 'invoicePrice' => $invoicePrice,
  550. 'invoiceType' => $invoiceType,
  551. 'settlementType' => $st,
  552. 'doPost' => $doPost,
  553. 'status' => 1,
  554. 'invoiceSerial' => $invoiceSerial,
  555. 'date' => date ( "Y-m-d H:i:s" ),
  556. 'updateTime' => date ( "Y-m-d H:i:s" ),
  557. 'sid' => $this->staff [0] ['sid'],
  558. 'userName' => $this->staff [0] ['username'],
  559. 'invoiceManage' => $invoiceManageDetail ['staff'],
  560. 'pendingApprovals' => $pendingApprovalsSid,
  561. 'moldManage' => json_encode ( $moldManage ),
  562. 'remark' => $remark,
  563. 'trainId' => $trainId
  564. );
  565. if ($invoiceType == 0)
  566. $item += array (
  567. 'invoiceTitle' => $invoiceTitle,
  568. 'TIN' => $TINT,
  569. 'address' => $addressT,
  570. 'phone' => $phoneT,
  571. 'bank' => $bankT,
  572. 'bankAccount' => $bankAccountT
  573. );
  574. else {
  575. $item += array (
  576. 'invoiceCompany' => $invoiceCompany,
  577. 'TIN' => $TIN,
  578. 'address' => $address,
  579. 'phone' => $phone,
  580. 'bank' => $bank,
  581. 'bankAccount' => $bankAccount
  582. );
  583. }
  584. if ($doPost == 1) {
  585. if (! empty ( $softLock ))
  586. $mailList += array (
  587. 'softLock' => $softLockNum
  588. );
  589. else
  590. $mailList += array (
  591. 'softLock' => 0
  592. );
  593. if (! empty ( $contract ))
  594. $mailList += array (
  595. 'contract' => $contractNum
  596. );
  597. else
  598. $mailList += array (
  599. 'contract' => 0
  600. );
  601. if (! empty ( $instructions ))
  602. $mailList += array (
  603. 'instructions' => $instructionsNum
  604. );
  605. else
  606. $mailList += array (
  607. 'instructions' => 0
  608. );
  609. if (! empty ( $remittance ))
  610. $mailList += array (
  611. 'remittance' => $remittance
  612. );
  613. else
  614. $mailList += array (
  615. 'remittance' => ''
  616. );
  617. if (! empty ( $softLock ))
  618. $mailString .= ',软件锁x' . $softLockNum . '个';
  619. if (! empty ( $contract ))
  620. $mailString .= ',合同x' . $contractNum . '份';
  621. if (! empty ( $instructions ))
  622. $mailString .= ',说明书x' . $instructionsNum . '本';
  623. if (! empty ( $remittance ))
  624. $mailString .= ',汇款账号单(张)';
  625. $item += array (
  626. 'recipients' => $recipients,
  627. 'recipientsPhone' => $recipientsPhone,
  628. 'recipientsAddress' => $recipientsAddress,
  629. 'mailItems' => $mailString,
  630. 'mailItemsJson' => json_encode ( $mailList )
  631. );
  632. }
  633. $iid = $invoice->addInvoice ( $item );
  634. // 如果是培训班结算 创建培训班发票到培训班备份中
  635. if (! empty ( $st ) && $st == 1) {
  636. Doo::loadModel ( 'invoiceStore' );
  637. $invoiceStore = new invoiceStore ();
  638. Doo::loadModel ( 'invoiceTraining' );
  639. $invoiceTraining = new invoiceTraining ();
  640. $isid = $invoiceStore->setInvoiceToInvoiceStore ( $iid );
  641. $itemIS = array (
  642. 'isid' => $isid,
  643. 'ipSource' => 1,
  644. 'apStatus' => 1,
  645. 'iid' => $iid
  646. );
  647. $invoiceStore->setInvoiceStoreByCondition ( $itemIS );
  648. // 更新培训班总数量
  649. $detailIT = $invoiceTraining->getInvoiceTrainingByItid ( $trainId );
  650. $item = array (
  651. 'itid' => $trainId,
  652. 'invoiceTotal' => $detailIT ['invoiceTotal'] + 1,
  653. 'submitStatus' => 1
  654. );
  655. $itid = $invoiceTraining->setInvoiceTrainByCondition ( $item );
  656. }
  657. // 操作日志
  658. $item = array (
  659. 'date' => date ( "Y-m-d H:i:s" ),
  660. 'operation' => "创建",
  661. 'status' => 1,
  662. 'img' => $this->staff [0] ['avatar'],
  663. 'username' => $this->staff [0] ['username'],
  664. 'uid' => $this->staff [0] ['sid'],
  665. 'category' => $this->staff [0] ['category'],
  666. 'iid' => $iid
  667. );
  668. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  669. $item = array (
  670. 'date' => date ( "Y-m-d H:i:s" ),
  671. 'operation' => "提交审批",
  672. 'status' => 1,
  673. 'img' => $this->staff [0] ['avatar'],
  674. 'username' => $this->staff [0] ['username'],
  675. 'uid' => $this->staff [0] ['sid'],
  676. 'category' => $this->staff [0] ['category'],
  677. 'iid' => $iid
  678. );
  679. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  680. Doo::loadModel ( 'staff' );
  681. $staff = new staff ();
  682. $username2 = $staff->getOne ( array (
  683. 'select' => 'wxid',
  684. 'where' => 'sid=' . $pendingApprovalsSid,
  685. 'asArray' => TRUE
  686. ) );
  687. // 发送微信审批通知
  688. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  689. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  690. }
  691. return "/invoice";
  692. }
  693. function invoiceEdit() {
  694. Doo::loadClass ( 'XDeode' );
  695. $XDeode = new XDeode ( 5 );
  696. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  697. $iid = $XDeode->decode ( $iid );
  698. if (! is_numeric ( $iid ))
  699. die ( 'illegal request' );
  700. Doo::loadModel ( 'invoice' );
  701. $invoice = new invoice ();
  702. Doo::loadModel ( 'invoiceOperationLog' );
  703. $invoiceOperationLog = new invoiceOperationLog ();
  704. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  705. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  706. $invoiceDetail ['mailItemsJson'] ='';
  707. if(isset($invoiceDetail ['mailItemsJson'])){
  708. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  709. }
  710. $this->data ['operation'] = $operation;
  711. $this->data ['invoiceDetail'] = $invoiceDetail;
  712. $this->data ['memu'] = "invoice";
  713. $this->data ['staff'] = $this->staff;
  714. $this->data ['receiptMemu'] = 'invoice';
  715. $this->render ( "/admin/invoiceEdit", $this->data );
  716. }
  717. /**
  718. * 重新编辑退回的发票
  719. * @return string
  720. */
  721. function invoiceEditDo() {
  722. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  723. Doo::loadModel ( 'invoice' );
  724. $invoice = new invoice ();
  725. $iid = $invoice->authcode ( $iidKey );
  726. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  727. die ( 'illegal request' );
  728. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  729. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  730. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  731. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  732. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  733. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  734. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  735. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  736. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  737. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  738. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  739. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  740. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  741. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  742. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  743. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  744. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  745. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  746. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  747. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  748. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  749. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  750. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  751. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  752. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  753. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  754. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  755. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  756. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  757. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  758. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  759. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  760. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  761. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  762. if ($invoiceType == 1) {
  763. $temporary = $invoiceQuantity * $invoiceUnitPrice;
  764. if ($temporary > 100001)
  765. die ( 'illegal request-Please priceError' );
  766. }
  767. if($invoiceForm=='electronic'){
  768. if(empty(trim($electronicPhone))&&empty(trim($electronicEmail))){
  769. die ( '请至少填写一种联系方式--电子发票' );
  770. }
  771. }
  772. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  773. Doo::loadModel ( 'invoiceManage' );
  774. $invoiceManage = new invoiceManage ();
  775. Doo::loadModel ( 'invoiceOperationLog' );
  776. $invoiceOperationLog = new invoiceOperationLog ();
  777. Doo::loadModel ( 'invoiceStore' );
  778. $invoiceStore = new invoiceStore ();
  779. $cid = explode ( ':', $cid );
  780. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  781. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  782. $moldManage = array ();
  783. foreach ( $invoiceManageList as $key => $value ) {
  784. if ($value ['mold'] == '发票打印')
  785. $moldManage [$value ['mold']] = $value ['staffList'];
  786. elseif ($value ['mold'] == '发票邮寄')
  787. $moldManage [$value ['mold']] = $value ['staffList'];
  788. elseif ($value ['mold'] == '发票打印')
  789. $moldManage [$value ['mold']] = $value ['staffList'];
  790. }
  791. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  792. if($invoiceForm=='electronic'){
  793. $invoiceForm=1;
  794. $invoiceType=0;
  795. if(!empty($electronicPhone)||!empty($electronicEmail)){
  796. }else{
  797. die ( 'illegal request-electronicContact' );
  798. }
  799. $mailList = array ();
  800. $mailString = '备注:' . $mailItems;
  801. }elseif($invoiceForm=='paper'){
  802. $invoiceForm=0;
  803. $mailList = array (
  804. 'invoice' => 1,
  805. 'mailItems' => $mailItems
  806. );
  807. $mailString = '发票x1张,备注:' . $mailItems;
  808. }else{
  809. die ( 'illegal request-invoiceForm' );
  810. }
  811. $item = array (
  812. 'iid' => $iid,
  813. 'cid' => $cid [0],
  814. 'categoryName' => $cid [1],
  815. 'invoiceElement' => $invoiceElement,
  816. 'invoiceForm'=>$invoiceForm,
  817. 'electronicPhone'=>$electronicPhone,
  818. 'electronicEmail'=>$electronicEmail,
  819. 'invoiceQuantity' => $invoiceQuantity,
  820. 'invoiceUnitPrice' => $invoiceUnitPrice,
  821. 'invoicePrice' => $invoicePrice,
  822. 'invoiceType' => $invoiceType,
  823. 'doPost' => $doPost,
  824. 'status' => 1,
  825. 'updateTime' => date ( "Y-m-d H:i:s" ),
  826. 'remark' => $remark
  827. );
  828. if ($invoiceType == 0)
  829. $item += array (
  830. 'invoiceTitle' => $invoiceTitle,
  831. 'TIN' => $TINT,
  832. 'address' => $addressT,
  833. 'phone' => $phoneT,
  834. 'bank' => $bankT,
  835. 'bankAccount' => $bankAccountT
  836. );
  837. else {
  838. $item += array (
  839. 'invoiceCompany' => $invoiceCompany,
  840. 'TIN' => $TIN,
  841. 'address' => $address,
  842. 'phone' => $phone,
  843. 'bank' => $bank,
  844. 'bankAccount' => $bankAccount
  845. );
  846. }
  847. if ($doPost == 1) {
  848. if (! empty ( $softLock ))
  849. $mailList += array (
  850. 'softLock' => $softLockNum
  851. );
  852. else
  853. $mailList += array (
  854. 'softLock' => '0'
  855. );
  856. if (! empty ( $contract ))
  857. $mailList += array (
  858. 'contract' => $contractNum
  859. );
  860. else
  861. $mailList += array (
  862. 'contract' => '0'
  863. );
  864. if (! empty ( $instructions ))
  865. $mailList += array (
  866. 'instructions' => $instructionsNum
  867. );
  868. else
  869. $mailList += array (
  870. 'instructions' => '0'
  871. );
  872. if (! empty ( $remittance ))
  873. $mailList += array (
  874. 'remittance' => $remittance
  875. );
  876. else
  877. $mailList += array (
  878. 'remittance' => ''
  879. );
  880. if (! empty ( $softLock ))
  881. $mailString .= ',软件锁x' . $softLockNum;
  882. if (! empty ( $contract ))
  883. $mailString .= ',合同x' . $contractNum;
  884. if (! empty ( $instructions ))
  885. $mailString .= ',说明书x' . $instructionsNum;
  886. if (! empty ( $remittance ))
  887. $mailString .= ',汇款账号单';
  888. $item += array (
  889. 'recipients' => $recipients,
  890. 'recipientsPhone' => $recipientsPhone,
  891. 'recipientsAddress' => $recipientsAddress,
  892. 'mailItems' => $mailString,
  893. 'mailItemsJson' => json_encode ( $mailList )
  894. );
  895. }
  896. $invoice->setInvoiceByCondition ( $item );
  897. // 更新培训班仓库里的发票
  898. $detail = $invoice->getInvoiceByIid ( $iid );
  899. if (! empty ( $detail ['isid'] )) {
  900. $invoiceStore->isid = $detail ['isid'];
  901. $invoiceStore->invoiceQuantity = $invoiceQuantity;
  902. $invoiceStore->invoiceUnitPrice = $invoiceUnitPrice;
  903. $invoiceStore->invoicePrice = $invoicePrice;
  904. $invoiceStore->update ();
  905. }
  906. $item = array (
  907. 'date' => date ( "Y-m-d H:i:s" ),
  908. 'operation' => "重新提交审批",
  909. 'status' => 1,
  910. 'img' => $this->staff [0] ['avatar'],
  911. 'username' => $this->staff [0] ['username'],
  912. 'uid' => $this->staff [0] ['sid'],
  913. 'category' => $this->staff [0] ['category'],
  914. 'iid' => $iid
  915. );
  916. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  917. }
  918. return "/invoice";
  919. }
  920. /**
  921. * 培训班
  922. */
  923. function invoiceTraining() {
  924. Doo::loadModel ( 'L_category' );
  925. $lCategory = new L_category ();
  926. Doo::loadModel ( 'invoiceTraining' );
  927. $invoiceTraining = new invoiceTraining ();
  928. Doo::loadModel ( 'invoiceTrainManage' );
  929. $invoiceTrainManage = new invoiceTrainManage ();
  930. $imcStaff = $invoiceTrainManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  931. $cidList = array ();
  932. foreach ( $imcStaff as $key => $value ) {
  933. array_push ( $cidList, $value ['cid'] );
  934. }
  935. if (empty ( $cidList )) {
  936. $cidString = $this->staff [0] ['cid'];
  937. } else {
  938. $cidString = implode ( ',', $cidList );
  939. $cidString .= $cidString . ',' . $this->staff [0] ['cid'];
  940. }
  941. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $cidString, $this->staff [0] ['sid'] );
  942. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $cidString, $this->staff [0] ['sid'] );
  943. $category = $lCategory->getCategory ();
  944. $itid = array ();
  945. foreach ( $itTodoList as $key => $value ) {
  946. array_push ( $itid, $value ['itid'] );
  947. // 如果入账100%更新为已完成
  948. if ($itTodoList [$key] ['arriveSchedule'] >= 100) {
  949. $invoiceTraining = new invoiceTraining ();
  950. $invoiceTraining->itid = $value ['itid'];
  951. $invoiceTraining->status = 2;
  952. $invoiceTraining->update ();
  953. }
  954. }
  955. foreach ( $itedList as $value ) {
  956. array_push ( $itid, $value ['itid'] );
  957. }
  958. $itid = implode ( ',', $itid );
  959. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  960. // print_r($itTodoList);
  961. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  962. $this->data ['itTodoList'] = $itTodoList;
  963. $this->data ['itedList'] = $itedList;
  964. $this->data ['category'] = $category;
  965. $this->data ['memu'] = "invoice";
  966. $this->data ['staff'] = $this->staff;
  967. $this->data ['receiptMemu'] = 'invoiceTraining';
  968. $this->render ( "/admin/invoiceTraining", $this->data );
  969. }
  970. /**
  971. * 创建培训班
  972. */
  973. function invoiceTrainingAdd() {
  974. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  975. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  976. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  977. if (empty ( $this->staff [0] ))
  978. die ( 'illegal request' );
  979. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  980. Doo::loadModel ( 'invoiceTraining' );
  981. $invoiceTraining = new invoiceTraining ();
  982. Doo::loadModel ( 'invoice' );
  983. $invoice = new invoice ();
  984. Doo::loadModel ( 'L_category' );
  985. $lCategory = new L_category ();
  986. Doo::loadModel ( 'invoiceManage' );
  987. $invoiceManage = new invoiceManage ();
  988. Doo::loadModel ( 'invoiceOperationLog' );
  989. $invoiceOperationLog = new invoiceOperationLog ();
  990. $item = array (
  991. 'cid' => $cid,
  992. 'trainName' => $trainName,
  993. 'trainDate' => $trainDate,
  994. 'creator' => $this->staff [0] ['sid'],
  995. 'creatorDate' => date ( "Y-m-d H:i:s" )
  996. );
  997. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  998. }
  999. return "/invoiceTraining";
  1000. }
  1001. /**
  1002. * 删除培训班
  1003. */
  1004. function invoiceTrainingDelDo() {
  1005. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1006. if (! empty ( $itid )) {
  1007. Doo::loadModel ( 'invoiceTraining' );
  1008. $invoiceTraining = new invoiceTraining ();
  1009. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  1010. }
  1011. return "/invoiceTraining";
  1012. }
  1013. /**
  1014. * 培训班详情
  1015. */
  1016. function invoiceTrainingDetail() {
  1017. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  1018. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  1019. Doo::loadModel ( 'invoiceTraining' );
  1020. $invoiceTraining = new invoiceTraining ();
  1021. Doo::loadModel ( 'invoiceStore' );
  1022. $invoiceStore = new invoiceStore ();
  1023. if (empty ( $itid ))
  1024. die ( 'illegal request' );
  1025. $con = '(b.untreadStatus is null or b.untreadStatus!=2) and ';
  1026. if ($trainStatus == "SUBED")
  1027. $con = ' (b.untreadStatus is null ) and ';
  1028. elseif ($trainStatus == "APPROVAL")
  1029. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  1030. elseif ($trainStatus == "TICKET")
  1031. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  1032. elseif ($trainStatus == "TICKETING") {
  1033. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  1034. }
  1035. $con.=' a.invoiceForm=0 and ';
  1036. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  1037. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con,0 );
  1038. //print_r($isList);
  1039. $trainlistJson=$this->_trainList($isList);
  1040. if (empty ( $detail ))
  1041. die ( 'illegal request' );
  1042. // 培训班结算是否有和是否已经结算完成
  1043. Doo::loadModel ( 'receipt' );
  1044. $receipt = new receipt ();
  1045. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1046. $this->data ['receiptDetail'] = $receiptDetail;
  1047. $this->data ['trainStatus'] = $trainStatus;
  1048. $this->data ['itid'] = $itid;
  1049. $this->data ['trainlistJson'] = $trainlistJson;
  1050. $this->data ['iTrainDetail'] = $detail;
  1051. $this->data ['memu'] = "invoice";
  1052. $this->data ['staff'] = $this->staff;
  1053. $this->data ['receiptMemu'] = 'invoiceTraining';
  1054. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  1055. }
  1056. function invoiceTrainingElectronicDetail(){
  1057. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  1058. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  1059. Doo::loadModel ( 'invoiceTraining' );
  1060. $invoiceTraining = new invoiceTraining ();
  1061. Doo::loadModel ( 'invoiceStore' );
  1062. $invoiceStore = new invoiceStore ();
  1063. if (empty ( $itid ))
  1064. die ( 'illegal request' );
  1065. $con = ' (b.untreadStatus is null or b.untreadStatus!=2) and ';
  1066. if ($trainStatus == "SUBED")
  1067. $con = ' (b.untreadStatus is null ) and ';
  1068. elseif ($trainStatus == "APPROVAL")
  1069. $con = ' ( b.status=1 and b.untreadStatus!=2 ) and ';
  1070. elseif ($trainStatus == "TICKET")
  1071. $con = ' (b.printStatus=1 and b.status=2 and b.untreadStatus!=2) and ';
  1072. elseif ($trainStatus == "TICKETING") {
  1073. $con = ' (b.status=2 and b.untreadStatus=1) and ';
  1074. }
  1075. $con.=' a.invoiceForm=1 and ';
  1076. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  1077. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid, $con,1 );
  1078. //print_r($isList);
  1079. if (empty ( $detail )){
  1080. die ( 'illegal request' );
  1081. }
  1082. $trainlistJson=$this->_trainList($isList,1);
  1083. // 培训班结算是否有和是否已经结算完成
  1084. Doo::loadModel ( 'receipt' );
  1085. $receipt = new receipt ();
  1086. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1087. $this->data ['receiptDetail'] = $receiptDetail;
  1088. $this->data ['trainStatus'] = $trainStatus;
  1089. $this->data ['itid'] = $itid;
  1090. $this->data ['trainlistJson'] = $trainlistJson;
  1091. $this->data ['iTrainDetail'] = $detail;
  1092. $this->data ['memu'] = "invoice";
  1093. $this->data ['staff'] = $this->staff;
  1094. $this->data ['receiptMemu'] = 'invoiceTraining';
  1095. $this->render ( "/invoice/invoiceTrainingElectronicDetail", $this->data );
  1096. }
  1097. function _trainList($isList,$type=0){
  1098. $trainlist = array ();
  1099. foreach ( $isList as $key => $value ) {
  1100. $irDetail = array ();
  1101. if ($value ['apStatus'] == 1) {
  1102. // array_push ( $irDetail, '' );
  1103. array_push ( $irDetail, '<input disabled type="checkbox" style="display:none" >' );
  1104. } else {
  1105. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  1106. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  1107. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  1108. }
  1109. array_push ( $irDetail, $value ['invoiceSerial'] );
  1110. if ($value ['invoiceType'] == 1)
  1111. array_push ( $irDetail, $value ['invoiceCompany'] );
  1112. else
  1113. array_push ( $irDetail, $value ['invoiceTitle'] );
  1114. array_push ( $irDetail, $value ['TIN'] );
  1115. array_push ( $irDetail, $value ['userName'] );
  1116. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  1117. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  1118. } else
  1119. array_push ( $irDetail, $value ['mailItems'] );
  1120. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  1121. if($type==1){
  1122. array_push ( $irDetail, $value ['electronicPhone'] );
  1123. array_push ( $irDetail, $value ['electronicEmail'] );
  1124. }
  1125. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  1126. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  1127. array_push ( $irDetail, $value ['invoiceElement'] );
  1128. array_push ( $irDetail, $value ['invoiceQuantity'] );
  1129. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  1130. if ($value ['invoiceType'] == 1)
  1131. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  1132. else
  1133. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  1134. array_push ( $irDetail, $value ['remark'] );
  1135. if ($value ['status'] == 1)
  1136. array_push ( $irDetail, '审批中' );
  1137. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  1138. array_push ( $irDetail, '已出票' );
  1139. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  1140. array_push ( $irDetail, '已入账' );
  1141. else
  1142. array_push ( $irDetail, '' );
  1143. array_push ( $irDetail, $value ['invoiceNo'] );
  1144. array_push ( $irDetail, $value ['printTime'] );
  1145. $html = '';
  1146. foreach ( $value ['invoiceReceivables'] as $v ) {
  1147. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $v [2] . '" data-toggle="modal">' . $v [1] . '</a>';
  1148. }
  1149. array_push ( $irDetail, $html );
  1150. array_push ( $trainlist, $irDetail );
  1151. }
  1152. $trainlistJson = json_encode ( $trainlist );
  1153. return $trainlistJson;
  1154. }
  1155. /**
  1156. * 上传培训班发票
  1157. * @return string
  1158. */
  1159. function invoiceTrainingUpload() {
  1160. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  1161. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  1162. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  1163. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  1164. header ( "HTTP/1.1 500 Internal Server Error" );
  1165. echo "POST exceeded maximum allowed size.";
  1166. exit ( 0 );
  1167. }
  1168. // Settings
  1169. $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)
  1170. $upload_name = "Filedata";
  1171. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  1172. $extension_whitelist = array (
  1173. "doc",
  1174. "txt",
  1175. "jpg",
  1176. "gif",
  1177. "png"
  1178. ); // Allowed file extensions
  1179. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  1180. // Other variables
  1181. $MAX_FILENAME_LENGTH = 260;
  1182. $file_name = "";
  1183. $file_extension = "";
  1184. $uploadErrors = array (
  1185. 0 => "文件上传成功",
  1186. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  1187. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  1188. 3 => "上传的文件仅为部分文件",
  1189. 4 => "没有文件上传",
  1190. 6 => "缺少临时文件夹"
  1191. );
  1192. $nk = time ();
  1193. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  1194. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  1195. echo "文件无法保存.";
  1196. exit ( 0 );
  1197. }
  1198. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  1199. echo json_encode ( array (
  1200. 'filename' => $file_name,
  1201. 'id' => $nk
  1202. ) );
  1203. exit ( 0 );
  1204. }
  1205. /**
  1206. * 导入发票临时仓库
  1207. */
  1208. function invoiceStoreImport() {
  1209. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  1210. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  1211. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  1212. if ($path != "" && ! empty ( $trainingKey )) {
  1213. Doo::loadModel ( 'invoiceStore' );
  1214. Doo::loadModel ( 'staff' );
  1215. $staff = new staff ();
  1216. Doo::loadModel ( 'invoiceTraining' );
  1217. $invoiceTraining = new invoiceTraining ();
  1218. Doo::loadClass ( 'XDeode' );
  1219. $XDeode = new XDeode ( 5 );
  1220. $itid = $XDeode->decode ( $trainingKey );
  1221. // 培训班结算是否有和是否已经结算完成
  1222. Doo::loadModel ( 'receipt' );
  1223. $receipt = new receipt ();
  1224. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $itid );
  1225. if (! empty ( $receiptDetail )) {
  1226. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9)
  1227. die ( 'illegal request--status' );
  1228. }
  1229. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  1230. $userName = $this->staff [0] ['username'];
  1231. $sDetail = $staff->getStaffByName ( $userName );
  1232. //print_r($exlArray);die;
  1233. // die('sdd');
  1234. // 可以优化
  1235. foreach ( $exlArray as $key => $value ) {
  1236. // 开票
  1237. $invoice = new invoiceStore ();
  1238. $invoice->trainId = $itid;
  1239. $invoice->invoiceType = 0;
  1240. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1241. $invoice->invoiceType = 1;
  1242. elseif($value ['invoiceType'] == '电子'){
  1243. $invoice->invoiceType = 0;
  1244. $invoice->invoiceForm=1;
  1245. }
  1246. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  1247. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  1248. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  1249. $invoice->invoiceTitle = $value ['invoiceTitle'];
  1250. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  1251. $invoice->invoiceCompany = $value ['invoiceTitle'];
  1252. $invoice->userName = $userName;
  1253. $invoice->sid = $sDetail ['sid'];
  1254. $invoice->cid = $sDetail ['cid'];
  1255. $invoice->categoryName = $sDetail ['category'];
  1256. $invoice->invoiceElement = $value ['invoiceElement'];
  1257. $invoice->remark = $value ['remark'];
  1258. // $invoice->date = $value ['date'];
  1259. // $invoice->printTime = $value ['date'];
  1260. $invoice->ipSource = 1;
  1261. $invoice->printStatus = 0;
  1262. $invoice->status = 0;
  1263. $invoice->postStatus = 1;
  1264. $invoice->untreadStatus = 0;
  1265. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1266. $invoice->TIN = $value ['TIN'];
  1267. $invoice->address = $value ['address'];
  1268. $invoice->phone = $value ['phone'];
  1269. $invoice->bank = $value ['bank'];
  1270. $invoice->bankAccount = $value ['bankAccount'];
  1271. $invoice->recipientsAddress = $value ['recipientsAddress'];
  1272. $invoice->recipients = $value ['recipients'];
  1273. $invoice->recipientsPhone = $value ['recipientsPhone'];
  1274. $invoice->electronicPhone = $value ['electronicPhone'];
  1275. $invoice->electronicEmail = $value ['electronicEmail'];
  1276. $iid = $invoice->insert ();
  1277. }
  1278. // 加入发票总数量
  1279. $item = array (
  1280. 'itid' => $itid,
  1281. 'invoiceTotal' => count ( $exlArray )
  1282. );
  1283. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1284. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  1285. }
  1286. echo 'no file';
  1287. }
  1288. /**
  1289. * 编辑仓库里的发票
  1290. */
  1291. function invoiceStoreEdit() {
  1292. Doo::loadClass ( 'XDeode' );
  1293. $XDeode = new XDeode ( 5 );
  1294. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  1295. $iid = $XDeode->decode ( $iid );
  1296. if (! is_numeric ( $iid ))
  1297. die ( 'illegal request' );
  1298. Doo::loadModel ( 'invoiceStore' );
  1299. $invoiceStore = new invoiceStore ();
  1300. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  1301. // print_r($invoiceDetail);
  1302. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  1303. $this->data ['invoiceDetail'] = $invoiceDetail;
  1304. $this->data ['memu'] = "invoice";
  1305. $this->data ['staff'] = $this->staff;
  1306. $this->data ['receiptMemu'] = 'invoiceTraining';
  1307. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  1308. }
  1309. function invoiceStoreEditDo() {
  1310. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1311. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1312. Doo::loadModel ( 'invoiceStore' );
  1313. $invoice = new invoiceStore ();
  1314. Doo::loadClass ( 'XDeode' );
  1315. $XDeode = new XDeode ( 5 );
  1316. $iid = $XDeode->decode ( $storeKey );
  1317. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1318. die ( 'illegal request' );
  1319. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  1320. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  1321. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  1322. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  1323. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  1324. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  1325. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  1326. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  1327. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  1328. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  1329. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  1330. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  1331. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  1332. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  1333. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1334. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1335. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1336. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1337. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  1338. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  1339. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  1340. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  1341. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  1342. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  1343. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1344. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1345. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1346. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1347. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1348. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1349. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1350. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : "";
  1351. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : "";
  1352. $invoiceForm = $this->get_args ( 'invoiceForm' ) ? $this->get_args ( 'invoiceForm' ) : "";
  1353. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  1354. $cid = explode ( ':', $cid );
  1355. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  1356. $item = array (
  1357. 'isid' => $iid,
  1358. 'cid' => $cid [0],
  1359. 'categoryName' => $cid [1],
  1360. 'invoiceElement' => $invoiceElement,
  1361. 'invoiceQuantity' => $invoiceQuantity,
  1362. 'invoiceUnitPrice' => $invoiceUnitPrice,
  1363. 'invoicePrice' => $invoicePrice,
  1364. 'invoiceType' => $invoiceType,
  1365. 'doPost' => $doPost,
  1366. 'status' => 1,
  1367. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1368. 'remark' => $remark
  1369. );
  1370. if ($invoiceType == 0)
  1371. $item += array (
  1372. 'invoiceTitle' => $invoiceTitle,
  1373. 'TIN' => $TINT,
  1374. 'address' => $addressT,
  1375. 'phone' => $phoneT,
  1376. 'bank' => $bankT,
  1377. 'bankAccount' => $bankAccountT
  1378. );
  1379. else {
  1380. $item += array (
  1381. 'invoiceCompany' => $invoiceCompany,
  1382. 'TIN' => $TIN,
  1383. 'address' => $address,
  1384. 'phone' => $phone,
  1385. 'bank' => $bank,
  1386. 'bankAccount' => $bankAccount
  1387. );
  1388. }
  1389. if($invoiceForm=='paper'){
  1390. $item += array (
  1391. 'invoiceForm' => 0
  1392. );
  1393. }elseif($invoiceForm=='electronic'){
  1394. $item += array (
  1395. 'invoiceForm' => 1,
  1396. 'electronicPhone' => $electronicPhone,
  1397. 'electronicEmail' => $electronicEmail,
  1398. );
  1399. }
  1400. if ($doPost == 1) {
  1401. $mailList = array (
  1402. 'invoice' => 1,
  1403. 'mailItems' => $mailItems
  1404. );
  1405. if (! empty ( $softLock ))
  1406. $mailList += array (
  1407. 'softLock' => $softLockNum
  1408. );
  1409. else
  1410. $mailList += array (
  1411. 'softLock' => '0'
  1412. );
  1413. if (! empty ( $contract ))
  1414. $mailList += array (
  1415. 'contract' => $contractNum
  1416. );
  1417. else
  1418. $mailList += array (
  1419. 'contract' => '0'
  1420. );
  1421. if (! empty ( $instructions ))
  1422. $mailList += array (
  1423. 'instructions' => $instructionsNum
  1424. );
  1425. else
  1426. $mailList += array (
  1427. 'instructions' => '0'
  1428. );
  1429. if (! empty ( $remittance ))
  1430. $mailList += array (
  1431. 'remittance' => $remittance
  1432. );
  1433. else
  1434. $mailList += array (
  1435. 'remittance' => ''
  1436. );
  1437. $mailString = '发票x1,备注:' . $mailItems;
  1438. if (! empty ( $softLock ))
  1439. $mailString .= ',软件锁x' . $softLockNum;
  1440. if (! empty ( $contract ))
  1441. $mailString .= ',合同x' . $contractNum;
  1442. if (! empty ( $instructions ))
  1443. $mailString .= ',说明书x' . $instructionsNum;
  1444. if (! empty ( $remittance ))
  1445. $mailString .= ',汇款账号单';
  1446. $item += array (
  1447. 'recipients' => $recipients,
  1448. 'recipientsPhone' => $recipientsPhone,
  1449. 'recipientsAddress' => $recipientsAddress,
  1450. 'mailItems' => $mailString,
  1451. 'mailItemsJson' => json_encode ( $mailList )
  1452. );
  1453. }
  1454. $invoice->setInvoiceStoreByCondition ( $item );
  1455. }
  1456. if(!empty($invoiceForm)&&$invoiceForm=='electronic'){
  1457. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1458. }else{
  1459. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1460. }
  1461. }
  1462. /**
  1463. *
  1464. * @return string
  1465. */
  1466. function invoiceStoreDelete() {
  1467. Doo::loadClass ( 'XDeode' );
  1468. $XDeode = new XDeode ( 5 );
  1469. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1470. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1471. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1472. $isid = $XDeode->decode ( $iStoreKey );
  1473. $itid = $XDeode->decode ( $trainKey );
  1474. if (! is_numeric ( $isid ))
  1475. die ( 'illegal request' );
  1476. Doo::loadModel ( 'invoiceStore' );
  1477. $invoiceStore = new invoiceStore ();
  1478. $invoiceStore->delete ( array (
  1479. 'where' => 'isid=' . $isid,
  1480. 'limit' => 1
  1481. ) );
  1482. Doo::loadModel ( 'invoiceTraining' );
  1483. $invoiceTraining = new invoiceTraining ();
  1484. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1485. $item = array (
  1486. 'itid' => $itid,
  1487. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1488. );
  1489. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1490. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1491. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1492. }else{
  1493. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1494. }
  1495. }
  1496. /**
  1497. * 批量删除库里发票
  1498. */
  1499. function invoiceStoreBatchDelete() {
  1500. Doo::loadClass ( 'XDeode' );
  1501. $XDeode = new XDeode ( 5 );
  1502. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1503. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1504. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1505. if (empty ( $trainKey ) || empty ( $storeKey ))
  1506. die ( 'illegal request-IdKey' );
  1507. $tid = $XDeode->decode ( $trainKey );
  1508. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1509. die ( 'illegal request' );
  1510. Doo::loadModel ( 'invoiceStore' );
  1511. $isidKeyList = explode ( ',', $storeKey );
  1512. $isidList = array ();
  1513. foreach ( $isidKeyList as $value ) {
  1514. $isid = $XDeode->decode ( $value );
  1515. if (! empty ( $isid ) && is_numeric ( $isid ))
  1516. array_push ( $isidList, $isid );
  1517. }
  1518. $isidString = implode ( ',', $isidList );
  1519. $invoiceStore = new invoiceStore ();
  1520. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1521. $isidList = array ();
  1522. foreach ( $isList as $key => $value ) {
  1523. if ($value ['apStatus'] == 0)
  1524. array_push ( $isidList, $value ['isid'] );
  1525. }
  1526. $isidString = implode ( ',', $isidList );
  1527. // print_r($isList);
  1528. // echo $isidString;
  1529. $invoiceStore = new invoiceStore ();
  1530. $invoiceStore->delete ( array (
  1531. 'where' => "isid in ( " . $isidString . ")",
  1532. 'asArray' => TRUE
  1533. ) );
  1534. Doo::loadModel ( 'invoiceTraining' );
  1535. $invoiceTraining = new invoiceTraining ();
  1536. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1537. $item = array (
  1538. 'itid' => $tid,
  1539. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1540. );
  1541. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1542. // echo $tid;
  1543. // echo $storeKey;
  1544. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1545. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1546. }else{
  1547. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1548. }
  1549. }
  1550. function invoiceStoreBatchElectronicPhone(){
  1551. $electronicPhone = $this->get_args ( 'electronicPhone' ) ? $this->get_args ( 'electronicPhone' ) : '';
  1552. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1553. Doo::loadClass ( 'XDeode' );
  1554. $XDeode = new XDeode ( 5 );
  1555. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1556. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1557. if (empty ( $trainKey ) || empty ( $storeKey ))
  1558. die ( 'illegal request-IdKey' );
  1559. $isidKeyList = explode ( ',', $storeKey );
  1560. $isidList = array ();
  1561. foreach ( $isidKeyList as $value ) {
  1562. $isid = $XDeode->decode ( $value );
  1563. if (! empty ( $isid ) && is_numeric ( $isid ))
  1564. array_push ( $isidList, $isid );
  1565. }
  1566. $isidString = implode ( ',', $isidList );
  1567. $trainId = $XDeode->decode ( $trainKey );
  1568. if (! is_numeric ( $isid ))
  1569. die ( 'illegal request--isid' );
  1570. Doo::loadModel ( 'invoiceStore' );
  1571. $invoiceStore = new invoiceStore ();
  1572. $item = array (
  1573. 'electronicPhone' => $electronicPhone
  1574. );
  1575. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1576. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1577. }
  1578. function invoiceStoreBatchElectronicEmail(){
  1579. $electronicEmail = $this->get_args ( 'electronicEmail' ) ? $this->get_args ( 'electronicEmail' ) : '';
  1580. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1581. Doo::loadClass ( 'XDeode' );
  1582. $XDeode = new XDeode ( 5 );
  1583. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1584. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1585. if (empty ( $trainKey ) || empty ( $storeKey ))
  1586. die ( 'illegal request-IdKey' );
  1587. $isidKeyList = explode ( ',', $storeKey );
  1588. $isidList = array ();
  1589. foreach ( $isidKeyList as $value ) {
  1590. $isid = $XDeode->decode ( $value );
  1591. if (! empty ( $isid ) && is_numeric ( $isid ))
  1592. array_push ( $isidList, $isid );
  1593. }
  1594. $isidString = implode ( ',', $isidList );
  1595. $trainId = $XDeode->decode ( $trainKey );
  1596. if (! is_numeric ( $isid ))
  1597. die ( 'illegal request' );
  1598. Doo::loadModel ( 'invoiceStore' );
  1599. $invoiceStore = new invoiceStore ();
  1600. $item = array (
  1601. 'electronicEmail' => $electronicEmail
  1602. );
  1603. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1604. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1605. }
  1606. /**
  1607. * 仓库发票提交审批
  1608. * @return string
  1609. */
  1610. function invoiceStoreApproval() {
  1611. Doo::loadClass ( 'XDeode' );
  1612. $XDeode = new XDeode ( 5 );
  1613. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1614. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1615. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1616. $isid = $XDeode->decode ( $iStoreKey );
  1617. $trainId = $XDeode->decode ( $trainKey );
  1618. if (! is_numeric ( $isid ))
  1619. die ( 'illegal request' );
  1620. Doo::loadModel ( 'invoiceStore' );
  1621. Doo::loadModel ( 'invoice' );
  1622. $invoice = new invoice ();
  1623. // 加入限制必须填写入开票内容和邮寄物品
  1624. $invoiceStore = new invoiceStore ();
  1625. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson,electronicPhone,electronicEmail' );
  1626. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1627. header ( 'Content-Type:text/html;charset=utf-8' );
  1628. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1629. }
  1630. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1631. if (empty ( $isDetail ['electronicPhone'] ) && empty ( $isDetail ['electronicEmail'] )) {
  1632. header ( 'Content-Type:text/html;charset=utf-8' );
  1633. die ( 'illegal request! 请设置电子开票的收件人手机或者邮箱' );
  1634. }
  1635. }
  1636. // 拷贝插入一条发票数据
  1637. $invoiceStore = new invoiceStore ();
  1638. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1639. $invoiceStore = new invoiceStore ();
  1640. $item = array (
  1641. 'isid' => $isid,
  1642. 'iid' => $iid,
  1643. 'apStatus' => 1
  1644. );
  1645. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1646. Doo::loadModel ( 'invoiceManage' );
  1647. $invoiceManage = new invoiceManage ();
  1648. Doo::loadModel ( 'invoiceOperationLog' );
  1649. $invoiceOperationLog = new invoiceOperationLog ();
  1650. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1651. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1652. $moldManage = array ();
  1653. foreach ( $invoiceManageList as $key => $value ) {
  1654. if ($value ['mold'] == '发票打印')
  1655. $moldManage [$value ['mold']] = $value ['staffList'];
  1656. elseif ($value ['mold'] == '发票邮寄')
  1657. $moldManage [$value ['mold']] = $value ['staffList'];
  1658. elseif ($value ['mold'] == '发票退票')
  1659. $moldManage [$value ['mold']] = $value ['staffList'];
  1660. }
  1661. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1662. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1663. $invoiceSerial="#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1664. }else{
  1665. $invoiceSerial="#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1666. }
  1667. $item = array (
  1668. 'iid' => $iid,
  1669. 'isid' => $isid,
  1670. 'invoiceSerial' => $invoiceSerial,
  1671. 'date' => date ( "Y-m-d H:i:s" ),
  1672. 'status' => 1,
  1673. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1674. 'trainId' => $trainId,
  1675. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1676. 'moldManage' => json_encode ( $moldManage ),
  1677. 'settlementType' => 1,
  1678. 'pendingApprovals' => $pendingApprovalsSid
  1679. );
  1680. $invoice->setInvoiceByCondition ( $item );
  1681. Doo::loadModel ( 'invoiceTraining' );
  1682. $invoiceTraining = new invoiceTraining ();
  1683. $item = array (
  1684. 'itid' => $trainId,
  1685. 'submitStatus' => 1
  1686. );
  1687. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1688. $item = array (
  1689. 'date' => date ( "Y-m-d H:i:s" ),
  1690. 'operation' => "创建",
  1691. 'status' => 1,
  1692. 'img' => $this->staff [0] ['avatar'],
  1693. 'username' => $this->staff [0] ['username'],
  1694. 'uid' => $this->staff [0] ['sid'],
  1695. 'category' => $this->staff [0] ['category'],
  1696. 'iid' => $iid
  1697. );
  1698. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1699. $item = array (
  1700. 'date' => date ( "Y-m-d H:i:s" ),
  1701. 'operation' => "提交审批",
  1702. 'status' => 1,
  1703. 'img' => $this->staff [0] ['avatar'],
  1704. 'username' => $this->staff [0] ['username'],
  1705. 'uid' => $this->staff [0] ['sid'],
  1706. 'category' => $this->staff [0] ['category'],
  1707. 'iid' => $iid
  1708. );
  1709. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1710. Doo::loadModel ( 'staff' );
  1711. $staff = new staff ();
  1712. $username2 = $staff->getOne ( array (
  1713. 'select' => 'wxid',
  1714. 'where' => 'sid=' . $pendingApprovalsSid,
  1715. 'asArray' => TRUE
  1716. ) );
  1717. // 发送微信审批通知
  1718. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1719. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1720. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1721. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1722. }else{
  1723. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1724. }
  1725. }
  1726. /**
  1727. * 批量提交发票
  1728. * @return string
  1729. */
  1730. function invoiceStoreBatchApproval() {
  1731. Doo::loadClass ( 'XDeode' );
  1732. $XDeode = new XDeode ( 5 );
  1733. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1734. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1735. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : '';
  1736. if (empty ( $trainKey ) || empty ( $storeKey ))
  1737. die ( 'illegal request-IdKey' );
  1738. $trainId = $XDeode->decode ( $trainKey );
  1739. $isidKeyList = explode ( ',', $storeKey );
  1740. $isidList = array ();
  1741. foreach ( $isidKeyList as $value ) {
  1742. $isid = $XDeode->decode ( $value );
  1743. if (! empty ( $isid ) && is_numeric ( $isid ))
  1744. array_push ( $isidList, $isid );
  1745. }
  1746. $isidString = implode ( ',', $isidList );
  1747. if (! is_numeric ( $trainId ))
  1748. die ( 'illegal request' );
  1749. Doo::loadModel ( 'invoiceStore' );
  1750. Doo::loadModel ( 'invoice' );
  1751. // 判断哪些已经加入审批过
  1752. // 加入限制必须填写入开票内容和邮寄物品
  1753. $invoiceStore = new invoiceStore ();
  1754. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson,electronicPhone,electronicEmail,invoiceForm' );
  1755. foreach ( $isList as $key => $value ) {
  1756. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1757. header ( 'Content-Type:text/html;charset=utf-8' );
  1758. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1759. }
  1760. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic' ){
  1761. $value ['electronicPhone']=trim($value ['electronicPhone']);
  1762. $value ['electronicEmail']=trim($value ['electronicEmail']);
  1763. if(empty ( $value ['electronicPhone'] )&&empty ( $value ['electronicEmail'] )){
  1764. header ( 'Content-Type:text/html;charset=utf-8' );
  1765. die ( 'illegal request! 请设置电子开票的收件人手机或者邮箱' );
  1766. }
  1767. }
  1768. }
  1769. // 拷贝插入一条发票数据
  1770. $invoiceStore = new invoiceStore ();
  1771. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1772. $invoiceStore = new invoiceStore ();
  1773. $item = array (
  1774. 'apStatus' => 1
  1775. );
  1776. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1777. // 获得正式发票ID
  1778. $invoice = new invoice ();
  1779. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1780. $sqlList = array ();
  1781. $iidString = '';
  1782. $iida = array ();
  1783. foreach ( $iidList as $key => $value ) {
  1784. $sqlList [$value ['isid']] = $value ['iid'];
  1785. array_push ( $iida, $value ['iid'] );
  1786. }
  1787. $iidString = implode ( ',', $iida );
  1788. $ids = implode ( ',', array_keys ( $sqlList ) );
  1789. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1790. foreach ( $sqlList as $id => $ordinal ) {
  1791. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1792. }
  1793. $sql .= "END WHERE isid IN ($ids)";
  1794. $invoiceStore = new invoiceStore ();
  1795. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1796. Doo::loadModel ( 'invoiceManage' );
  1797. $invoiceManage = new invoiceManage ();
  1798. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1799. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1800. $moldManage = array ();
  1801. foreach ( $invoiceManageList as $key => $value ) {
  1802. if ($value ['mold'] == '发票打印')
  1803. $moldManage [$value ['mold']] = $value ['staffList'];
  1804. elseif ($value ['mold'] == '发票邮寄')
  1805. $moldManage [$value ['mold']] = $value ['staffList'];
  1806. elseif ($value ['mold'] == '发票退票')
  1807. $moldManage [$value ['mold']] = $value ['staffList'];
  1808. }
  1809. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1810. // 批量更新发票信息
  1811. $item = array (
  1812. 'date' => date ( "Y-m-d H:i:s" ),
  1813. 'status' => 1,
  1814. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1815. 'trainId' => $trainId,
  1816. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1817. 'moldManage' => json_encode ( $moldManage ),
  1818. 'settlementType' => 1,
  1819. 'pendingApprovals' => $pendingApprovalsSid
  1820. );
  1821. $invoice = new invoice ();
  1822. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1823. // 批量更新发票中仓库isid
  1824. $sql = "UPDATE CLD_invoiceStore SET isid = CASE iid ";
  1825. foreach ( $sqlList as $isid => $iid ) {
  1826. $sql .= sprintf ( "WHEN %d THEN %d ", $iid, $isid );
  1827. }
  1828. $sql .= "END WHERE iid IN ($iidString)";
  1829. $invoice = new invoice ();
  1830. $invoice->UpdateBatchInvoice ( $sql );
  1831. // 批量更新发票序列号
  1832. $sqlList = array ();
  1833. foreach ( $iida as $value ) {
  1834. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1835. $sqlList [$value] = "#FE" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1836. }else{
  1837. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1838. }
  1839. }
  1840. $ids = implode ( ',', array_keys ( $sqlList ) );
  1841. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1842. foreach ( $sqlList as $id => $ordinal ) {
  1843. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1844. }
  1845. $sql .= "END WHERE iid IN ($ids)";
  1846. $invoiceStore = new invoiceStore ();
  1847. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1848. // 批量生产操作日志
  1849. Doo::loadModel ( 'invoiceOperationLog' );
  1850. $sqlList = array ();
  1851. foreach ( $iida as $key => $value ) {
  1852. $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 . '"),
  1853. ("' . 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 . '") ';
  1854. array_push ( $sqlList, $sql );
  1855. }
  1856. $iolSql = implode ( ',', $sqlList );
  1857. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1858. $invoiceOperationLog = new invoiceOperationLog ();
  1859. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1860. Doo::loadModel ( 'invoiceTraining' );
  1861. $invoiceTraining = new invoiceTraining ();
  1862. $item = array (
  1863. 'itid' => $trainId,
  1864. 'submitStatus' => 1
  1865. );
  1866. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1867. Doo::loadModel ( 'staff' );
  1868. $staff = new staff ();
  1869. $username2 = $staff->getOne ( array (
  1870. 'select' => 'wxid',
  1871. 'where' => 'sid=' . $pendingApprovalsSid,
  1872. 'asArray' => TRUE
  1873. ) );
  1874. // 发送微信审批通知
  1875. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1876. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1877. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1878. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1879. }else{
  1880. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1881. }
  1882. }
  1883. /**
  1884. */
  1885. function invoiceStoreMailItemSet() {
  1886. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1887. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1888. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1889. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1890. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1891. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1892. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1893. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1894. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1895. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1896. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1897. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1898. Doo::loadClass ( 'XDeode' );
  1899. $XDeode = new XDeode ( 5 );
  1900. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1901. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1902. $isid = $XDeode->decode ( $storeKey );
  1903. $trainId = $XDeode->decode ( $trainKey );
  1904. if (! is_numeric ( $isid ))
  1905. die ( 'illegal request' );
  1906. Doo::loadModel ( 'invoiceStore' );
  1907. $invoiceStore = new invoiceStore ();
  1908. $mailList = array (
  1909. 'mailItems' => $mailItems
  1910. );
  1911. $mailString = '发票x1,备注:' . $mailItems;
  1912. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1913. $mailString = '备注:' . $mailItems;
  1914. }else{
  1915. $mailList += array (
  1916. 'invoice' => 1,
  1917. );
  1918. }
  1919. if (! empty ( $softLock ))
  1920. $mailList += array (
  1921. 'softLock' => $softLockNum
  1922. );
  1923. else
  1924. $mailList += array (
  1925. 'softLock' => 0
  1926. );
  1927. if (! empty ( $contract ))
  1928. $mailList += array (
  1929. 'contract' => $contractNum
  1930. );
  1931. else
  1932. $mailList += array (
  1933. 'contract' => 0
  1934. );
  1935. if (! empty ( $instructions ))
  1936. $mailList += array (
  1937. 'instructions' => $instructionsNum
  1938. );
  1939. else
  1940. $mailList += array (
  1941. 'instructions' => 0
  1942. );
  1943. if (! empty ( $remittance ))
  1944. $mailList += array (
  1945. 'remittance' => $remittance
  1946. );
  1947. else
  1948. $mailList += array (
  1949. 'remittance' => ''
  1950. );
  1951. if (! empty ( $softLock ))
  1952. $mailString .= ',软件锁x' . $softLockNum;
  1953. if (! empty ( $contract ))
  1954. $mailString .= ',合同x' . $contractNum;
  1955. if (! empty ( $instructions ))
  1956. $mailString .= ',说明书x' . $instructionsNum;
  1957. if (! empty ( $remittance ))
  1958. $mailString .= ',汇款账号单';
  1959. $item = array (
  1960. 'isid' => $isid,
  1961. 'doPost' => 1,
  1962. 'mailItems' => $mailString,
  1963. 'mailItemsJson' => json_encode ( $mailList )
  1964. );
  1965. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1966. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  1967. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  1968. }else{
  1969. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1970. }
  1971. }
  1972. /**
  1973. * 批量设置邮寄物品
  1974. */
  1975. function invoiceStoreBatchMailItemSet() {
  1976. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1977. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1978. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1979. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1980. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1981. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1982. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1983. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1984. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1985. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1986. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1987. $invoiceFrom = $this->get_args ( 'invoiceFrom' ) ? $this->get_args ( 'invoiceFrom' ) : "";
  1988. Doo::loadClass ( 'XDeode' );
  1989. $XDeode = new XDeode ( 5 );
  1990. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1991. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1992. if (empty ( $trainKey ) || empty ( $storeKey ))
  1993. die ( 'illegal request-IdKey' );
  1994. $isidKeyList = explode ( ',', $storeKey );
  1995. $isidList = array ();
  1996. foreach ( $isidKeyList as $value ) {
  1997. $isid = $XDeode->decode ( $value );
  1998. if (! empty ( $isid ) && is_numeric ( $isid ))
  1999. array_push ( $isidList, $isid );
  2000. }
  2001. $isidString = implode ( ',', $isidList );
  2002. $trainId = $XDeode->decode ( $trainKey );
  2003. if (! is_numeric ( $isid ))
  2004. die ( 'illegal request' );
  2005. Doo::loadModel ( 'invoiceStore' );
  2006. $invoiceStore = new invoiceStore ();
  2007. $mailList = array (
  2008. 'mailItems' => $mailItems
  2009. );
  2010. $mailString = '发票x1,备注:' . $mailItems;
  2011. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  2012. $mailString = '备注:' . $mailItems;
  2013. }else{
  2014. $mailList += array (
  2015. 'invoice' => 1,
  2016. );
  2017. }
  2018. if (! empty ( $softLock ))
  2019. $mailList += array (
  2020. 'softLock' => $softLockNum
  2021. );
  2022. else
  2023. $mailList += array (
  2024. 'softLock' => 0
  2025. );
  2026. if (! empty ( $contract ))
  2027. $mailList += array (
  2028. 'contract' => $contractNum
  2029. );
  2030. else
  2031. $mailList += array (
  2032. 'contract' => 0
  2033. );
  2034. if (! empty ( $instructions ))
  2035. $mailList += array (
  2036. 'instructions' => $instructionsNum
  2037. );
  2038. else
  2039. $mailList += array (
  2040. 'instructions' => 0
  2041. );
  2042. if (! empty ( $remittance ))
  2043. $mailList += array (
  2044. 'remittance' => $remittance
  2045. );
  2046. else
  2047. $mailList += array (
  2048. 'remittance' => ''
  2049. );
  2050. if (! empty ( $softLock ))
  2051. $mailString .= ',软件锁x' . $softLockNum;
  2052. if (! empty ( $contract ))
  2053. $mailString .= ',合同x' . $contractNum;
  2054. if (! empty ( $instructions ))
  2055. $mailString .= ',说明书x' . $instructionsNum;
  2056. if (! empty ( $remittance ))
  2057. $mailString .= ',汇款账号单';
  2058. $item = array (
  2059. 'doPost' => 1,
  2060. 'mailItems' => $mailString,
  2061. 'mailItemsJson' => json_encode ( $mailList )
  2062. );
  2063. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  2064. if(!empty($invoiceFrom)&&$invoiceFrom=='electronic'){
  2065. return "/invoiceTrainingElectronicDetail/" . $trainKey . ".html";
  2066. }else{
  2067. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  2068. }
  2069. }
  2070. /**
  2071. * 废弃
  2072. */
  2073. function ajaxGetMailItemByIstore() {
  2074. Doo::loadClass ( 'XDeode' );
  2075. $XDeode = new XDeode ( 5 );
  2076. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  2077. $isid = $XDeode->decode ( $storeKey );
  2078. if (! is_numeric ( $isid ))
  2079. die ( 'illegal request' );
  2080. Doo::loadModel ( 'invoiceStore' );
  2081. $invoiceStore = new invoiceStore ();
  2082. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  2083. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  2084. echo json_encode ( $isDetail ['mailItemsJson'] );
  2085. exit ();
  2086. }
  2087. /**
  2088. * 终止开票
  2089. */
  2090. function invoiceDroppedDo() {
  2091. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  2092. Doo::loadModel ( 'invoice' );
  2093. $invoice = new invoice ();
  2094. Doo::loadModel ( 'invoiceOperationLog' );
  2095. $invoiceOperationLog = new invoiceOperationLog ();
  2096. $iid = $invoice->authcode ( $droppedIidKey );
  2097. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2098. die ( 'illegal request' );
  2099. $item = array (
  2100. 'iid' => $iid,
  2101. 'status' => 4,
  2102. 'updateTime' => date ( "Y-m-d H:i:s" )
  2103. );
  2104. $invoice->setInvoiceByCondition ( $item );
  2105. $item = array (
  2106. 'date' => date ( "Y-m-d H:i:s" ),
  2107. 'operation' => '终止了开票',
  2108. 'status' => 4,
  2109. 'img' => $this->staff [0] ['avatar'],
  2110. 'username' => $this->staff [0] ['username'],
  2111. 'uid' => $this->staff [0] ['sid'],
  2112. 'category' => $this->staff [0] ['category'],
  2113. 'iid' => $iid
  2114. );
  2115. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2116. return "/invoice";
  2117. }
  2118. /**
  2119. * 更新退票的邮寄信息
  2120. */
  2121. function invoiceUntreadMailDo() {
  2122. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2123. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  2124. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  2125. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  2126. Doo::loadModel ( 'invoice' );
  2127. $invoice = new invoice ();
  2128. $iid = $invoice->authcode ( $untreadIidKey );
  2129. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2130. die ( 'illegal request' );
  2131. $item = array (
  2132. 'iid' => $iid,
  2133. 'untreadCompany' => $untreadCompany,
  2134. 'untreadNumber' => $untreadNumber,
  2135. 'untreadItems' => $untreadItems
  2136. );
  2137. $invoice->setInvoiceByCondition ( $item );
  2138. return "/invoice";
  2139. }
  2140. /**
  2141. * 申请退票 --
  2142. */
  2143. function invoiceUntreadDo() {
  2144. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2145. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  2146. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : 0;
  2147. Doo::loadModel ( 'invoice' );
  2148. $invoice = new invoice ();
  2149. Doo::loadModel ( 'invoiceOperationLog' );
  2150. $invoiceOperationLog = new invoiceOperationLog ();
  2151. Doo::loadModel ( 'invoiceReceivables' );
  2152. $invoiceReceivables = new invoiceReceivables ();
  2153. $iid = $invoice->authcode ( $untreadIidKey );
  2154. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2155. die ( 'illegal request' );
  2156. /*
  2157. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  2158. */
  2159. $item = array (
  2160. 'iid' => $iid,
  2161. 'untreadStatus' => 1,
  2162. 'untreadReason' => $untreadReason,
  2163. 'untreadPost' => $untreadPost,
  2164. 'updateTime' => date ( "Y-m-d H:i:s" )
  2165. );
  2166. $invoice->setInvoiceByCondition ( $item );
  2167. $item = array (
  2168. 'date' => date ( "Y-m-d H:i:s" ),
  2169. 'operation' => '申请退票',
  2170. 'status' => 7,
  2171. 'img' => $this->staff [0] ['avatar'],
  2172. 'username' => $this->staff [0] ['username'],
  2173. 'uid' => $this->staff [0] ['sid'],
  2174. 'category' => $this->staff [0] ['category'],
  2175. 'iid' => $iid
  2176. );
  2177. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2178. return "/invoice";
  2179. }
  2180. /**
  2181. * 删除已终止的开票
  2182. */
  2183. function invoiceDelDo() {
  2184. Doo::loadModel ( 'invoice' );
  2185. $invoice = new invoice ();
  2186. Doo::loadModel ( 'invoiceOperationLog' );
  2187. $invoiceOperationLog = new invoiceOperationLog ();
  2188. Doo::loadClass ( 'XDeode' );
  2189. $XDeode = new XDeode ( 5 );
  2190. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  2191. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2192. $iid = $XDeode->decode ( $iid );
  2193. Doo::loadModel ( 'invoiceStore' );
  2194. $invoiceStore = new invoiceStore ();
  2195. if (! is_numeric ( $iid ))
  2196. die ( 'illegal request' );
  2197. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  2198. if (empty ( $invoiceDetail ))
  2199. die ( 'illegal request' );
  2200. $item = array (
  2201. 'iid' => $iid,
  2202. 'isDelete' => 1,
  2203. 'updateTime' => date ( "Y-m-d H:i:s" )
  2204. );
  2205. $invoice->setInvoiceByCondition ( $item );
  2206. $item = array (
  2207. 'date' => date ( "Y-m-d H:i:s" ),
  2208. 'operation' => '删除了已终止的发票',
  2209. 'status' => 4,
  2210. 'img' => $this->staff [0] ['avatar'],
  2211. 'username' => $this->staff [0] ['username'],
  2212. 'uid' => $this->staff [0] ['sid'],
  2213. 'category' => $this->staff [0] ['category'],
  2214. 'iid' => $iid
  2215. );
  2216. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2217. // 删除培训班发票仓库里的发票
  2218. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  2219. return "/invoice";
  2220. }
  2221. /**
  2222. */
  2223. function invoiceApproval() {
  2224. Doo::loadModel ( 'invoice' );
  2225. $invoice = new invoice ();
  2226. Doo::loadClass ( 'XDeode' );
  2227. $XDeode = new XDeode ( 5 );
  2228. Doo::loadModel ( 'staff' );
  2229. $staff = new staff ();
  2230. $invoiceList = $invoice->find ( array (
  2231. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  2232. 'desc' => 'iid',
  2233. 'limit' => 10,
  2234. 'asArray' => true
  2235. ) );
  2236. foreach ( $invoiceList as $key => $value ) {
  2237. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2238. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2239. if (! empty ( $lastApprover )) {
  2240. $lastApproverKey = array_keys ( $lastApprover );
  2241. $lastApprover = end ( $lastApprover );
  2242. $staffDetail = $staff->getOne ( array (
  2243. 'where' => 'sid=' . end ( $lastApproverKey ),
  2244. 'asArray' => true
  2245. ) );
  2246. $lastApprover ['username'] = $staffDetail ['username'];
  2247. }
  2248. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  2249. }
  2250. $ilist = $invoice->getInvoiceByProcessStatus ();
  2251. foreach ( $ilist as $key => $value ) {
  2252. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2253. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2254. if (! empty ( $lastApprover )) {
  2255. $lastApproverKey = array_keys ( $lastApprover );
  2256. $lastApprover = end ( $lastApprover );
  2257. $staffDetail = $staff->getOne ( array (
  2258. 'where' => 'sid=' . end ( $lastApproverKey ),
  2259. 'asArray' => true
  2260. ) );
  2261. $lastApprover ['username'] = $staffDetail ['username'];
  2262. }
  2263. $ilist [$key] ['lastApprover'] = $lastApprover;
  2264. }
  2265. // print_r($ilist);
  2266. $this->data ['invoiceList'] = $invoiceList;
  2267. $this->data ['ilist'] = $ilist;
  2268. $this->data ['memu'] = "invoice";
  2269. $this->data ['staff'] = $this->staff;
  2270. $this->data ['receiptMemu'] = 'invoiceApproval';
  2271. $this->render ( "/admin/invoiceApproval", $this->data );
  2272. }
  2273. function invoiceDetail() {
  2274. Doo::loadClass ( 'XDeode' );
  2275. $XDeode = new XDeode ( 5 );
  2276. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2277. $iid = $XDeode->decode ( $iid );
  2278. if (! is_numeric ( $iid ))
  2279. die ( 'illegal request' );
  2280. Doo::loadModel ( 'invoice' );
  2281. $invoice = new invoice ();
  2282. Doo::loadModel ( 'invoiceOperationLog' );
  2283. $invoiceOperationLog = new invoiceOperationLog ();
  2284. $invoiceDetail = $invoice->getOne ( array (
  2285. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  2286. 'asArray' => true
  2287. ) );
  2288. if (empty ( $invoiceDetail ))
  2289. die ( 'illegal request' );
  2290. if ($invoiceDetail ['settlementType'] == 1) {
  2291. Doo::loadModel ( 'invoiceTraining' );
  2292. $invoiceTraining = new invoiceTraining ();
  2293. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2294. }
  2295. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2296. $this->data ['invoiceDetail'] = $invoiceDetail;
  2297. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2298. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2299. $this->data ['memu'] = "invoice";
  2300. $this->data ['staff'] = $this->staff;
  2301. $this->data ['receiptMemu'] = 'invoiceApproval';
  2302. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  2303. }
  2304. /**
  2305. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  2306. *
  2307. * @since 1.0.0
  2308. * @var integer iid 开票ID 已加密
  2309. * @var integer status 发票审批状态
  2310. * @var integer opintion 审批发票的意见
  2311. * @return string 如操作成功返回审批首页
  2312. */
  2313. function invoiceApprovalDo() {
  2314. Doo::loadModel ( 'invoice' );
  2315. $invoice = new invoice ();
  2316. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2317. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  2318. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  2319. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  2320. $iid = $invoice->authcode ( $iid );
  2321. if (! is_numeric ( $iid ))
  2322. die ( 'illegal request' );
  2323. // && ! empty ( $opinion )
  2324. if (! empty ( $iid ) && ! empty ( $status )) {
  2325. if (! ($status == 2 || $status == 3 || $status == 4))
  2326. die ( 'illegal request' );
  2327. Doo::loadModel ( 'invoiceOperationLog' );
  2328. $invoiceOperationLog = new invoiceOperationLog ();
  2329. $invoiceDetail = $invoice->getOne ( array (
  2330. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  2331. 'asArray' => true
  2332. ) );
  2333. if (empty ( $invoiceDetail ))
  2334. die ( 'illegal request' );
  2335. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  2336. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  2337. if ($status == 3) {
  2338. $invoice->status = $status;
  2339. $item = array (
  2340. 'operation' => $opinion
  2341. );
  2342. } else {
  2343. if (empty ( $processApprovals )) {
  2344. $processApprovals = array (
  2345. $this->staff [0] ['sid'] => array (
  2346. 'date' => date ( "Y-m-d H:i:s" ),
  2347. 'opinion' => $opinion,
  2348. 'status' => $status
  2349. )
  2350. );
  2351. // var_dump(next($invoiceManage));
  2352. $nextInvoiceManage = next ( $invoiceManage );
  2353. // print_r($nextInvoiceManage);
  2354. if ($status != 4 && $nextInvoiceManage !== false)
  2355. $invoice->pendingApprovals = $nextInvoiceManage [0];
  2356. $invoice->processApprovals = json_encode ( $processApprovals );
  2357. // var_dump($invoice);
  2358. // print_r($invoiceManage);
  2359. } else {
  2360. $processApprovals [$this->staff [0] ['sid']] = array (
  2361. 'date' => date ( "Y-m-d H:i:s" ),
  2362. 'opinion' => $opinion,
  2363. 'status' => $status
  2364. );
  2365. $pendingApprovals = 0;
  2366. foreach ( $invoiceManage as $key => $value ) {
  2367. if ($value [0] == $this->staff [0] ['sid']) {
  2368. if (isset ( $invoiceManage [$key + 1] ))
  2369. $pendingApprovals = $invoiceManage [$key + 1] [0];
  2370. break;
  2371. }
  2372. }
  2373. if ($status != 4 && ! empty ( $pendingApprovals ))
  2374. $invoice->pendingApprovals = $pendingApprovals;
  2375. $invoice->processApprovals = json_encode ( $processApprovals );
  2376. }
  2377. $item = array (
  2378. 'operation' => $opinion
  2379. );
  2380. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  2381. $invoice->status = $status;
  2382. $invoice->pendingApprovals = 0;
  2383. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  2384. } elseif ($status == 4) {
  2385. $invoice->status = $status;
  2386. $item = array (
  2387. 'operation' => $opinion
  2388. );
  2389. }
  2390. }
  2391. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  2392. $invoice->update ( array (
  2393. 'where' => 'iid=' . $iid
  2394. ) );
  2395. $item += array (
  2396. 'date' => date ( "Y-m-d H:i:s" ),
  2397. 'img' => $this->staff [0] ['avatar'],
  2398. 'username' => $this->staff [0] ['username'],
  2399. 'uid' => $this->staff [0] ['sid'],
  2400. 'category' => $this->staff [0] ['category'],
  2401. 'status' => $status,
  2402. 'iid' => $iid
  2403. );
  2404. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2405. if (empty ( $divApproval ))
  2406. return '/invoiceApproval';
  2407. else
  2408. return '/invoiceApprovalAchieve/PEND';
  2409. }
  2410. die ( 'illegal request' );
  2411. }
  2412. /**
  2413. * 展示需要打印的发票数据
  2414. *
  2415. * @since 1.0.0
  2416. */
  2417. function invoicePrint() {
  2418. Doo::loadModel ( 'invoice' );
  2419. $invoice = new invoice ();
  2420. Doo::loadClass ( 'XDeode' );
  2421. $XDeode = new XDeode ( 5 );
  2422. Doo::loadModel ( 'staff' );
  2423. $staff = new staff ();
  2424. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  2425. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  2426. foreach ( $toPrint as $key => $value ) {
  2427. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2428. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2429. if (! empty ( $lastApprover )) {
  2430. $lastApproverKey = array_keys ( $lastApprover );
  2431. $lastApprover = end ( $lastApprover );
  2432. $staffDetail = $staff->getOne ( array (
  2433. 'where' => 'sid=' . end ( $lastApproverKey ),
  2434. 'asArray' => true
  2435. ) );
  2436. $lastApprover ['username'] = $staffDetail ['username'];
  2437. }
  2438. $toPrint [$key] ['lastApprover'] = $lastApprover;
  2439. }
  2440. foreach ( $printed as $key => $value ) {
  2441. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2442. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2443. if (! empty ( $lastApprover )) {
  2444. $lastApproverKey = array_keys ( $lastApprover );
  2445. $lastApprover = end ( $lastApprover );
  2446. $staffDetail = $staff->getOne ( array (
  2447. 'where' => 'sid=' . end ( $lastApproverKey ),
  2448. 'asArray' => true
  2449. ) );
  2450. $lastApprover ['username'] = $staffDetail ['username'];
  2451. }
  2452. $printed [$key] ['lastApprover'] = $lastApprover;
  2453. }
  2454. $this->data ['printed'] = $printed;
  2455. $this->data ['toPrint'] = $toPrint;
  2456. $this->data ['memu'] = "invoice";
  2457. $this->data ['staff'] = $this->staff;
  2458. $this->data ['receiptMemu'] = 'invoicePrint';
  2459. $this->render ( "/admin/invoicePrint", $this->data );
  2460. }
  2461. /**
  2462. * 展示发票打印的详情页面
  2463. *
  2464. * @since 1.0.0
  2465. */
  2466. function invoicePrintDetail() {
  2467. Doo::loadClass ( 'XDeode' );
  2468. $XDeode = new XDeode ( 5 );
  2469. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  2470. $iid = $XDeode->decode ( $iid );
  2471. if (! is_numeric ( $iid ))
  2472. die ( 'illegal request' );
  2473. Doo::loadModel ( 'invoice' );
  2474. $invoice = new invoice ();
  2475. Doo::loadModel ( 'invoiceOperationLog' );
  2476. $invoiceOperationLog = new invoiceOperationLog ();
  2477. Doo::loadModel ( 'invoicePaper' );
  2478. $invoicePaper = new invoicePaper ();
  2479. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  2480. if (empty ( $invoiceDetail ))
  2481. die ( 'illegal request' );
  2482. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'],$invoiceDetail['invoiceForm'] );
  2483. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  2484. if ($invoiceDetail ['settlementType'] == 1) {
  2485. Doo::loadModel ( 'invoiceTraining' );
  2486. $invoiceTraining = new invoiceTraining ();
  2487. $invoiceDetail ['invoiceTraining'] = $invoiceTraining->getInvoiceTrainingByItid ( $invoiceDetail ['trainId'] );
  2488. }
  2489. $this->data ['invoicePaperList'] = $invoicePaperList;
  2490. $this->data ['invoiceDetail'] = $invoiceDetail;
  2491. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  2492. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  2493. $this->data ['memu'] = "invoice";
  2494. $this->data ['staff'] = $this->staff;
  2495. $this->data ['receiptMemu'] = 'invoicePrint';
  2496. $this->render ( "/admin/invoicePrintDetail", $this->data );
  2497. }
  2498. /**
  2499. * 所有待打印 发票
  2500. */
  2501. function invoicePrintStayAchieve() {
  2502. Doo::loadModel ( 'invoice' );
  2503. $invoice = new invoice ();
  2504. Doo::loadClass ( 'XDeode' );
  2505. $XDeode = new XDeode ( 5 );
  2506. Doo::loadModel ( 'staff' );
  2507. $staff = new staff ();
  2508. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  2509. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  2510. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  2511. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  2512. Doo::loadModel ( 'invoiceTraining' );
  2513. $invoiceTraining = new invoiceTraining ();
  2514. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  2515. $page_size = 12;
  2516. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2517. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  2518. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  2519. $get = "/" . $status;
  2520. $con = ' and status=2 ';
  2521. if ($status == 'TOPRINT')
  2522. $con = ' and status=2 and printStatus=0 ';
  2523. elseif ($status == 'PRINTED')
  2524. $con = ' and status=2 and printStatus=1';
  2525. if ($invoiceType == 'ORDINARY')
  2526. $con .= ' and invoiceType=0 ';
  2527. elseif ($invoiceType == 'SPECIAL')
  2528. $con .= ' and invoiceType=1 ';
  2529. if ($invoiceTrain == 'ORDINARY')
  2530. $con .= ' and trainId=0 ';
  2531. elseif ($invoiceTrain == 'TRAIN')
  2532. $con .= ' and trainId!=0 ';
  2533. if ($invoiceTrainName != 'ALL') {
  2534. $trainId = $XDeode->decode ( $invoiceTrainName );
  2535. if (is_numeric ( $trainId ))
  2536. $con .= ' and trainId =' . $trainId;
  2537. }
  2538. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2539. $dateArr = explode ( ':', $date );
  2540. $D1 = '';
  2541. $D2 = '';
  2542. if (! empty ( $date )) {
  2543. $D1 = $dateArr [0];
  2544. $D2 = $dateArr [1];
  2545. }
  2546. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  2547. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2548. if (! empty ( $MebSea )) {
  2549. $con .= ' and ( invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2550. }
  2551. $pageinfo ['page'] = array (
  2552. 'previous' => ''
  2553. );
  2554. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&invoiceType=" . urlencode ( $invoiceType ) . "&invoiceTrain=" . urlencode ( $invoiceTrain ) . "";
  2555. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2556. $action = "invoicePrintStayAchieve";
  2557. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2558. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2559. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  2560. $this->data ['trainList'] = $trainList;
  2561. $this->data ['invoiceType'] = $invoiceType;
  2562. $this->data ['invoiceTrain'] = $invoiceTrain;
  2563. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  2564. $this->data ['MebSeaEn'] = $MebSea;
  2565. $this->data ['MebSea'] = urlencode ( $MebSea );
  2566. $this->data ['get'] = $get;
  2567. $this->data ['page'] = $pageinfo;
  2568. $this->data ['date'] = $date;
  2569. $this->data ['status'] = $status;
  2570. $this->data ['invoiceType'] = $invoiceType;
  2571. $this->data ['memu'] = "invoice";
  2572. $this->data ['staff'] = $this->staff;
  2573. foreach ( $list as $key => $value ) {
  2574. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2575. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2576. if (! empty ( $lastApprover )) {
  2577. $lastApproverKey = array_keys ( $lastApprover );
  2578. $lastApprover = end ( $lastApprover );
  2579. $staffDetail = $staff->getOne ( array (
  2580. 'where' => 'sid=' . end ( $lastApproverKey ),
  2581. 'asArray' => true
  2582. ) );
  2583. $lastApprover ['username'] = $staffDetail ['username'];
  2584. }
  2585. $list [$key] ['lastApprover'] = $lastApprover;
  2586. }
  2587. $this->data ['receiptMemu'] = 'invoicePrint';
  2588. $this->data ['list'] = $list;
  2589. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2590. }
  2591. /**
  2592. * 填写票号并完成打印
  2593. * @since 1.0.0
  2594. */
  2595. function invoicePrintDo() {
  2596. Doo::loadModel ( 'invoice' );
  2597. $invoice = new invoice ();
  2598. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2599. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2600. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2601. $iid = $invoice->authcode ( $iid );
  2602. if (! is_numeric ( $iid ))
  2603. die ( 'illegal request-iid' );
  2604. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2605. Doo::loadModel ( 'invoiceOperationLog' );
  2606. $invoiceOperationLog = new invoiceOperationLog ();
  2607. Doo::loadModel ( 'invoiceStatistics' );
  2608. $invoiceStatistics = new invoiceStatistics ();
  2609. $XDeode = new XDeode ( 5 );
  2610. Doo::loadModel ( 'invoicePaper' );
  2611. $invoicePaper = new invoicePaper ();
  2612. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2613. if (empty ( $invoicePrintDetail ))
  2614. die ( 'illegal request-data_empty' );
  2615. //
  2616. $ipid = $XDeode->decode ( $invoiceNo );
  2617. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2618. if (empty ( $paperDetail ))
  2619. die ( 'illegal request-paper_empty' );
  2620. $invoicePaper = new invoicePaper ();
  2621. $item = array (
  2622. 'iid' => $iid,
  2623. 'ipid' => $ipid
  2624. );
  2625. $invoicePaper->setInvoicePaperByCondition ( $item );
  2626. $item = array (
  2627. 'iid' => $iid,
  2628. 'printStatus' => 1,
  2629. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2630. 'printer' => $this->staff [0] ['username'],
  2631. 'printTime' => date ( "Y-m-d H:i:s" ),
  2632. 'invoiceNo' => $paperDetail ['invoiceNo']
  2633. );
  2634. $invoice->setInvoiceByCondition ( $item );
  2635. $item = array (
  2636. 'date' => date ( "Y-m-d H:i:s" ),
  2637. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2638. 'status' => 5,
  2639. 'img' => $this->staff [0] ['avatar'],
  2640. 'username' => $this->staff [0] ['username'],
  2641. 'uid' => $this->staff [0] ['sid'],
  2642. 'category' => $this->staff [0] ['category'],
  2643. 'iid' => $iid
  2644. );
  2645. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2646. // 去统计--负票不汇总
  2647. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2648. $item = array (
  2649. 'date' => date ( "Y-m-d H:i:s" ),
  2650. 'priceClass' => 1,
  2651. 'cid' => $invoicePrintDetail ['cid'],
  2652. 'staff' => $invoicePrintDetail ['sid'],
  2653. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2654. );
  2655. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2656. }
  2657. // 发送通知信息到微信-去除
  2658. // $this->setWXMsg($iid,'PRINT');
  2659. // 发票信息库
  2660. $this->autoUpdateInvoiceInfoBase ( $invoicePrintDetail );
  2661. // 申请人获取微信通知
  2662. Doo::loadModel ( 'staff' );
  2663. $staff = new staff ();
  2664. Doo::loadClass ( 'XDeode' );
  2665. $XDeode = new XDeode ( 5 );
  2666. $username2 = $staff->getOne ( array (
  2667. 'select' => 'wxid',
  2668. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2669. 'asArray' => TRUE
  2670. ) );
  2671. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2672. $msg = '';
  2673. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2674. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2675. if (empty ( $invoicePrintType ))
  2676. return "/invoicePrint";
  2677. else
  2678. return "/invoicePrintStayAchieve";
  2679. }
  2680. }
  2681. /**
  2682. * 需要邮寄的发票
  2683. * @since 1.0.0
  2684. */
  2685. function invoicePost() {
  2686. Doo::loadModel ( 'invoice' );
  2687. $invoice = new invoice ();
  2688. Doo::loadModel ( 'express' );
  2689. $express = new express ();
  2690. $invoicePost = $invoice->getPostByInvoice ();
  2691. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2692. $expressList = $express->getExpressByAll ();
  2693. $invoicePostExpress = "";
  2694. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2695. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2696. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2697. $this->data ['expressList'] = $expressList;
  2698. $this->data ['invoicePost'] = $invoicePost;
  2699. $this->data ['invoicePosted'] = $invoicePosted;
  2700. $this->data ['memu'] = "invoice";
  2701. $this->data ['staff'] = $this->staff;
  2702. $this->data ['receiptMemu'] = 'invoicePost';
  2703. $this->render ( "/admin/invoicePost", $this->data );
  2704. }
  2705. /**
  2706. * 添加发票邮寄信息
  2707. */
  2708. function invoiceExpressAddDo() {
  2709. Doo::loadModel ( 'invoice' );
  2710. $invoice = new invoice ();
  2711. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2712. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2713. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2714. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2715. $iid = $iid = $invoice->authcode ( $iid );
  2716. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2717. die ( 'illegal request' );
  2718. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2719. setcookie ( 'invoicePostExpress', $expressNumber );
  2720. $item = array (
  2721. 'iid' => $iid,
  2722. 'postStatus' => 1,
  2723. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2724. 'postTime' => date ( "Y-m-d H:i:s" ),
  2725. 'expressCompany' => $expressCompany,
  2726. 'expressNumber' => $expressNumber,
  2727. 'actualItems' => $actualItems,
  2728. 'poster' => $this->staff [0] ['username']
  2729. );
  2730. $invoice->setInvoiceByCondition ( $item );
  2731. // 微信通知-去掉
  2732. // $this->setWXMsg ( $iid );
  2733. Doo::loadModel ( 'staff' );
  2734. $staff = new staff ();
  2735. Doo::loadClass ( 'XDeode' );
  2736. $XDeode = new XDeode ( 5 );
  2737. $username2 = $staff->getOne ( array (
  2738. 'select' => 'wxid',
  2739. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2740. 'asArray' => TRUE
  2741. ) );
  2742. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2743. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2744. if (empty ( $expCom ))
  2745. $expCom [0] = '';
  2746. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2747. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2748. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2749. return '/invoicePost';
  2750. }
  2751. function invoiceExpressUpdateDo() {
  2752. Doo::loadModel ( 'invoice' );
  2753. $invoice = new invoice ();
  2754. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2755. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2756. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2757. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2758. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2759. $iid = $invoice->authcode ( $iid );
  2760. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2761. die ( 'illegal request' );
  2762. $item = array (
  2763. 'iid' => $iid,
  2764. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2765. 'expressCompany' => $expressCompany,
  2766. 'expressNumber' => $expressNumber,
  2767. 'actualItems' => $actualItems,
  2768. 'poster' => $this->staff [0] ['username']
  2769. );
  2770. $invoice->setInvoiceByCondition ( $item );
  2771. return $action;
  2772. }
  2773. /**
  2774. * 可退票管理
  2775. */
  2776. function invoiceUntreadIsAchieve() {
  2777. Doo::loadModel ( 'invoice' );
  2778. $invoice = new invoice ();
  2779. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2780. /*
  2781. * 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' => '' );
  2782. */
  2783. if (empty ( $MebSea )) {//
  2784. $con = ' and invoiceNo like "NULL" ';
  2785. } else {
  2786. $con = ' and (invoiceNo like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2787. }
  2788. // printStatus=1 and
  2789. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2790. /*
  2791. * $action = "invoiceUntreadIsAchieve"; $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" ); $limit = $pageinfo ['lower'] . ',' . $page_size;
  2792. */
  2793. $limit = '0,20';
  2794. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2795. //print_r($list);
  2796. $this->data ['MebSeaEn'] = $MebSea;
  2797. /*
  2798. * $this->data ['get'] = $get; $this->data ['page'] = $pageinfo; $this->data ['date'] = $date;
  2799. */
  2800. $this->data ['list'] = $list;
  2801. $this->data ['memu'] = "invoice";
  2802. $this->data ['staff'] = $this->staff;
  2803. $this->data ['receiptMemu'] = 'invoice';
  2804. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2805. }
  2806. // 已经退票的发票
  2807. function invoiceUntreadED() {
  2808. Doo::loadModel ( 'invoice' );
  2809. $invoice = new invoice ();
  2810. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2811. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "";
  2812. Doo::loadClass ( 'XDeode' );
  2813. $XDeode = new XDeode ( 5 );
  2814. $page_size = 18;
  2815. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2816. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2817. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2818. $dateArr = explode ( ':', $date );
  2819. $D1 = '';
  2820. $D2 = '';
  2821. if (! empty ( $date )) {
  2822. $D1 = $dateArr [0];
  2823. $D2 = $dateArr [1];
  2824. }
  2825. $con = '';
  2826. if (! empty ( $D1 ) && ! empty ( $D2 )) {
  2827. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2828. }
  2829. // if ($date == 'MONTHO')
  2830. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2831. // elseif ($date == 'MONTHT')
  2832. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2833. // elseif ($date == 'MONTHY')
  2834. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2835. if (! empty ( $MebSea )) {
  2836. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  2837. }
  2838. if ($invoiceType == 'ORDINARY') {
  2839. $con .= ' and invoiceType=0 ';
  2840. } elseif ($invoiceType == 'SPECIAL') {
  2841. $con .= ' and invoiceType=1 ';
  2842. }
  2843. $pageinfo ['page'] = array (
  2844. 'previous' => ''
  2845. );
  2846. // printStatus=1 and
  2847. $sql = " (untreadStatus=2 ) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2848. $action = "invoiceUntreadED";
  2849. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2850. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2851. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2852. // print_r($list);
  2853. $this->data ['MebSeaEn'] = $MebSea;
  2854. $this->data ['get'] = $get;
  2855. $this->data ['page'] = $pageinfo;
  2856. $this->data ['date'] = $date;
  2857. $this->data ['invoiceType'] = $invoiceType;
  2858. $this->data ['list'] = $list;
  2859. $this->data ['memu'] = "invoice";
  2860. $this->data ['staff'] = $this->staff;
  2861. $this->data ['receiptMemu'] = 'invoice';
  2862. $this->render ( "/admin/invoiceUntreadED", $this->data );
  2863. }
  2864. /**
  2865. * 退票处理页面
  2866. */
  2867. function invoiceUntread() {
  2868. Doo::loadModel ( 'invoice' );
  2869. $invoice = new invoice ();
  2870. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1, 0, 50 );
  2871. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2872. //print_r($establishedInvoice);
  2873. // foreach ( $establishedInvoice as $key => $value ) {
  2874. // // months
  2875. // $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2876. // $nowDate = strtotime ( 'now' );
  2877. // $establishedInvoice [$key] ['lossShow'] = false;
  2878. // if ($lossDate < $nowDate)
  2879. // $establishedInvoice [$key] ['lossShow'] = true;
  2880. // }
  2881. $this->data ['untreadInvoice'] = $untreadInvoice;
  2882. $this->data ['establishedInvoice'] = $establishedInvoice;
  2883. $this->data ['memu'] = "invoice";
  2884. $this->data ['staff'] = $this->staff;
  2885. $this->data ['receiptMemu'] = 'invoiceUntread';
  2886. $this->render ( "/admin/invoiceUntread", $this->data );
  2887. }
  2888. /**
  2889. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2890. */
  2891. function invoiceUntreadEstablishedDo() {
  2892. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2893. Doo::loadModel ( 'invoice' );
  2894. $invoice = new invoice ();
  2895. Doo::loadModel ( 'invoiceOperationLog' );
  2896. $invoiceOperationLog = new invoiceOperationLog ();
  2897. Doo::loadModel ( 'invoiceReceivables' );
  2898. Doo::loadModel ( 'invoiceStatistics' );
  2899. $iid = $invoice->authcode ( $untreadIidKey );
  2900. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2901. die ( 'illegal request' );
  2902. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2903. if ($invoiceDetails ['untreadStatus'] != 1)
  2904. die ( 'illegal request untreadStatus error !=1' );
  2905. $item = array (
  2906. 'iid' => $iid,
  2907. // 'irid'=>'',
  2908. 'untreadStatus' => 2,
  2909. 'untreadTime'=>date ( "Y-m-d H:i:s" ) ,
  2910. 'updateTime' => date ( "Y-m-d H:i:s" )
  2911. );
  2912. $invoice->setInvoiceByCondition ( $item );
  2913. $item = array (
  2914. 'date' => date ( "Y-m-d H:i:s" ),
  2915. 'operation' => '已确认退票',
  2916. 'status' => 6,
  2917. 'img' => $this->staff [0] ['avatar'],
  2918. 'username' => $this->staff [0] ['username'],
  2919. 'uid' => $this->staff [0] ['sid'],
  2920. 'category' => $this->staff [0] ['category'],
  2921. 'iid' => $iid
  2922. );
  2923. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2924. // 收款解绑以及入账扣除 收款扣除
  2925. if (! empty ( $invoiceDetails ['irid'] )) {
  2926. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2927. foreach ( $iridList as $value ) {
  2928. $invoiceReceivables = new invoiceReceivables ();
  2929. $irDetails = $invoiceReceivables->getOne ( array (
  2930. 'where' => " irid=" . $value . ' ',
  2931. 'asArray' => TRUE
  2932. ) );
  2933. $bindPrice=$irDetails['bindPrice']-$invoiceDetails['invoicePrice'];
  2934. if($bindPrice<0){
  2935. $bindPrice=0;
  2936. }
  2937. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  2938. $item = array (
  2939. 'irid' => $value,
  2940. 'bindStatus' => 0,
  2941. 'untreadStatus' => 1,
  2942. 'bindPrice'=>$bindPrice,
  2943. 'untreadStaff' => $invoiceDetails ['userName'],
  2944. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2945. );
  2946. if($irDetails['iid']==$iid){
  2947. $item+=array(
  2948. 'iid' => 0
  2949. );
  2950. }else{
  2951. foreach ($iidExtend as $iek=>$iev){
  2952. if($iev==$iid){
  2953. unset($iidExtend[$iek]);
  2954. break;
  2955. }
  2956. }
  2957. if(empty($iidExtend)){
  2958. $item+=array(
  2959. 'iidExtend' => ''
  2960. );
  2961. }else{
  2962. $iidExtend=implode(",", $iidExtend);
  2963. $item+=array(
  2964. 'iidExtend' => $iidExtend
  2965. );
  2966. }
  2967. }
  2968. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2969. if (! empty ( $irDetails )) {
  2970. // 扣除入账
  2971. $invoiceStatistics = new invoiceStatistics ();
  2972. $item = array (
  2973. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2974. 'priceClass' => 3,
  2975. 'cid' => $invoiceDetails ['cid'],
  2976. 'staff' => $invoiceDetails ['sid'],
  2977. 'accountPrice' => - $irDetails ['receivablesPrice']
  2978. );
  2979. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2980. // 扣除收款
  2981. $invoiceStatistics = new invoiceStatistics ();
  2982. $item = array (
  2983. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2984. 'priceClass' => 2,
  2985. 'cid' => $invoiceDetails ['cid'],
  2986. 'staff' => $invoiceDetails ['sid'],
  2987. 'irid' => $irDetails ['irid'],
  2988. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2989. );
  2990. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2991. }
  2992. // 解绑时删除收入流水
  2993. Doo::loadModel ( 'wasteBook' );
  2994. $wasteBook = new wasteBook ();
  2995. $wasteBook->delete ( array (
  2996. 'where' => 'dataID=' . $value . ' and accountType=7',
  2997. 'limit' => 1
  2998. ) );
  2999. }
  3000. }
  3001. return "/invoiceUntread";
  3002. }
  3003. function invoiceUntreadRecallDo() {
  3004. $iidKey = isset ( $this->params ['iidKey'] ) ? $this->params ['iidKey'] : "";
  3005. Doo::loadModel ( 'invoice' );
  3006. $invoice = new invoice ();
  3007. Doo::loadClass ( 'XDeode' );
  3008. $XDeode = new XDeode ( 5 );
  3009. Doo::loadModel ( 'invoiceOperationLog' );
  3010. $invoiceOperationLog = new invoiceOperationLog ();
  3011. $iid = $XDeode->decode ( $iidKey );
  3012. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  3013. if (empty ( $invoiceDetail )) {
  3014. die ( 'illegal request-DATANULL' );
  3015. }
  3016. $item = array (
  3017. 'iid' => $iid,
  3018. 'untreadStatus' => 0
  3019. );
  3020. $invoice->setInvoiceByCondition ( $item );
  3021. $item = array (
  3022. 'date' => date ( "Y-m-d H:i:s" ),
  3023. 'operation' => '撤回申请退票',
  3024. 'status' => 13,
  3025. 'img' => $this->staff [0] ['avatar'],
  3026. 'username' => $this->staff [0] ['username'],
  3027. 'uid' => $this->staff [0] ['sid'],
  3028. 'category' => $this->staff [0] ['category'],
  3029. 'iid' => $iid
  3030. );
  3031. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3032. return "/invoiceUntread";
  3033. }
  3034. /**
  3035. * 建立负票,关联原来发票
  3036. */
  3037. function invoiceLossDo() {
  3038. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3039. if (! empty ( $iidKey )) {
  3040. Doo::loadClass ( 'XDeode' );
  3041. $XDeode = new XDeode ( 5 );
  3042. Doo::loadModel ( 'invoice' );
  3043. $invoice = new invoice ();
  3044. Doo::loadModel ( 'invoiceOperationLog' );
  3045. $invoiceOperationLog = new invoiceOperationLog ();
  3046. $iidKey = $XDeode->decode ( $iidKey );
  3047. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3048. // 拷贝插入一条发票数据
  3049. $iid = $invoice->setInvoiceLoss ( $iidKey );
  3050. // 更新负票
  3051. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3052. $invoice = new invoice ();
  3053. $item = array (
  3054. 'iid' => $iid,
  3055. 'sid' => $this->staff [0] ['sid'],
  3056. 'userName' => $this->staff [0] ['username'],
  3057. 'cid' => $this->staff [0] ['cid'],
  3058. 'categoryName' => $this->staff [0] ['category'],
  3059. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  3060. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  3061. 'invoiceSerial' => $invoiceSerial,
  3062. 'invoiceNo' => '',
  3063. 'printStatus' => 0,
  3064. 'untreadStatus' => 4,
  3065. // 关联发票号
  3066. 'lossIid' => $invoiceDetail ['iid']
  3067. );
  3068. $invoice->setInvoiceByCondition ( $item );
  3069. // 更新原发票
  3070. $invoice = new invoice ();
  3071. $item = array (
  3072. 'iid' => $invoiceDetail ['iid'],
  3073. 'lossIid' => $iid
  3074. );
  3075. $invoice->setInvoiceByCondition ( $item );
  3076. // 操作日志
  3077. $item = array (
  3078. 'date' => date ( "Y-m-d H:i:s" ),
  3079. 'operation' => "创建负票" . $invoiceSerial,
  3080. 'status' => 12,
  3081. 'img' => $this->staff [0] ['avatar'],
  3082. 'username' => $this->staff [0] ['username'],
  3083. 'uid' => $this->staff [0] ['sid'],
  3084. 'category' => $this->staff [0] ['category'],
  3085. 'iid' => $iid
  3086. );
  3087. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3088. // print_r($invoiceDetail);
  3089. // echo $iid;die;
  3090. }
  3091. return '/invoiceUntread';
  3092. }
  3093. /**
  3094. * 上传银行到账 收款文件
  3095. */
  3096. function invoiceReceivablesBankUpload() {
  3097. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  3098. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  3099. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  3100. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  3101. header ( "HTTP/1.1 500 Internal Server Error" );
  3102. echo "POST exceeded maximum allowed size.";
  3103. exit ( 0 );
  3104. }
  3105. // Settings
  3106. $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)
  3107. $upload_name = "Filedata";
  3108. $file_name = "";
  3109. $nk = time ();
  3110. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  3111. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  3112. echo "文件无法保存.";
  3113. exit ( 0 );
  3114. }
  3115. echo json_encode ( array (
  3116. 'filename' => $file_name,
  3117. 'id' => $nk
  3118. ) );
  3119. exit ( 0 );
  3120. }
  3121. /**
  3122. * 解析银行到账收款execl并导入库中
  3123. */
  3124. function invoiceReceivablesImport() {
  3125. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  3126. if ($path != "") {
  3127. Doo::loadModel ( 'invoiceReceivables' );
  3128. $invoiceReceivables = new invoiceReceivables ();
  3129. Doo::loadClass ( 'invoice.func' );
  3130. Doo::loadModel ( 'invoiceROLog' );
  3131. $invoiceROLog = new invoiceROLog ();
  3132. Doo::loadModel ( 'invoiceStatistics' );
  3133. $invoiceStatistics = new invoiceStatistics ();
  3134. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  3135. $bankBatchNumber = 'BBN_' . time ();
  3136. Doo::db ()->beginTransaction ();
  3137. // 批量存储收款--由于必须获得收款ID,
  3138. $sql = 'INSERT INTO CLD_invoiceReceivables (OriginalPrice,receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  3139. VALUES ';
  3140. $date = date ( "Y-m-d" );
  3141. $receivablesList = array ();
  3142. foreach ( $exlArray as $key => $value ) {
  3143. $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"] . '")';
  3144. array_push ( $receivablesList, $receivablesSql );
  3145. }
  3146. $sql = $sql . implode ( ',', $receivablesList );
  3147. // echo $sql;
  3148. Doo::db ()->query ( $sql );
  3149. // 批量存储收款统计
  3150. // 获得刚刚导入数据的irid组-缺少办事处和人员
  3151. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  3152. // 没有irid 回滚所有操作
  3153. if (empty ( $iridList )) {
  3154. Doo::db ()->rollBack ();
  3155. header ( 'Content-Type:text/html;charset=utf-8' );
  3156. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  3157. }
  3158. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  3159. VALUES ';
  3160. $statisticsList = array ();
  3161. foreach ( $iridList as $value ) {
  3162. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  3163. array_push ( $statisticsList, $statisticsSql );
  3164. }
  3165. $sql = $sql . implode ( ',', $statisticsList );
  3166. Doo::db ()->query ( $sql );
  3167. // 批量存储操作日志
  3168. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  3169. VALUES ';
  3170. $ROLogList = array ();
  3171. foreach ( $iridList as $value ) {
  3172. $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'] . '")';
  3173. array_push ( $ROLogList, $ROLogSql );
  3174. }
  3175. $sql = $sql . implode ( ',', $ROLogList );
  3176. Doo::db ()->query ( $sql );
  3177. // 批量写入流水
  3178. $sql = 'INSERT INTO CLD_wasteBook (dataID, expensesType,accountType,accountPriceShow, accountPrice,accountBank,category,cid,name,sid,inputDate)
  3179. VALUES ';
  3180. $wasteBookList = array ();
  3181. foreach ( $iridList as $value ) {
  3182. $accountBank = '';
  3183. if ($value ['receivablesBank'] == '纵横广发') {
  3184. $accountBank = 'CGBDeposit';
  3185. } elseif ($value ['receivablesBank'] == '纵横工行') {
  3186. $accountBank = 'ICBCDeposit';
  3187. } elseif ($value ['receivablesBank'] == '华润银行') {
  3188. $accountBank = 'HUADeposit';
  3189. } elseif ($value ['receivablesBank'] == '个人广发') {
  3190. $accountBank = 'PersonalDeposit';
  3191. }
  3192. $wasteBookSql = '("' . $value ['irid'] . ' ",1,7,"' . $value ['receivablesPrice'] . '","' . $value ['receivablesPrice'] . '","' . $accountBank . '",
  3193. "' . $this->staff [0] ['category'] . '","' . $this->staff [0] ['cid'] . '","' . $this->staff [0] ['username'] . '","' . $this->staff [0] ['sid'] . '","' . date ( "Y-m-d H:i:s" ) . '")';
  3194. array_push ( $wasteBookList, $wasteBookSql );
  3195. }
  3196. $sql = $sql . implode ( ',', $wasteBookList );
  3197. Doo::db ()->query ( $sql );
  3198. Doo::db ()->commit ();
  3199. return "/invoiceReceivables";
  3200. }
  3201. echo 'no file';
  3202. }
  3203. function invoiceReceivables() {
  3204. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  3205. Doo::loadModel ( 'L_category' );
  3206. $lCategory = new L_category ();
  3207. Doo::loadModel ( 'staff' );
  3208. $staff = new staff ();
  3209. Doo::loadModel ( 'invoiceReceivables' );
  3210. $invoiceReceivables = new invoiceReceivables ();
  3211. Doo::loadModel ( 'invoice' );
  3212. $invoice = new invoice ();
  3213. Doo::loadClass ( 'XDeode' );
  3214. $XDeode = new XDeode ( 5 );
  3215. $category = $lCategory->getCategory ();
  3216. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  3217. $sql = 'bindStatus=1 and iid!=0';
  3218. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  3219. // 获取未入账发票
  3220. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  3221. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  3222. foreach ( $invoiceUnAccount as $key => $value ) {
  3223. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  3224. $lastApprover = json_decode ( $value ['processApprovals'], true );
  3225. if (! empty ( $lastApprover )) {
  3226. $lastApproverKey = array_keys ( $lastApprover );
  3227. $lastApprover = end ( $lastApprover );
  3228. $staffDetail = $staff->getOne ( array (
  3229. 'where' => 'sid=' . end ( $lastApproverKey ),
  3230. 'asArray' => true
  3231. ) );
  3232. $lastApprover ['username'] = $staffDetail ['username'];
  3233. }
  3234. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  3235. }
  3236. foreach ( $invoiceExistAccount as $key => $value ) {
  3237. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  3238. // if (empty ( $irList ))
  3239. // $irList [0] ['sumPrice'] = 0;
  3240. //$balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  3241. $invoiceExistAccount [$key] ['existAccount'] = $value ['invoicePrice']-$value ['invoiceBalance'];
  3242. //$invoiceExistAccount [$key] ['balance'] = $balance;
  3243. }
  3244. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  3245. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  3246. $this->data ['halfList'] = $halfList;
  3247. $this->data ['halfCount'] = count ( $halfList );
  3248. // print_r($receivablesList);
  3249. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  3250. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  3251. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  3252. $this->data ['receivablesInput'] = $receivablesInput;
  3253. $this->data ['year'] = date ( 'Y' );
  3254. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  3255. $this->data ['receivablesList'] = $receivablesList;
  3256. $this->data ['staffList'] = $staffList;
  3257. $this->data ['category'] = $category;
  3258. $this->data ['memu'] = "invoice";
  3259. $this->data ['staff'] = $this->staff;
  3260. $this->data ['receiptMemu'] = 'invoiceReceivables';
  3261. $this->render ( "/admin/invoiceReceivables", $this->data );
  3262. }
  3263. /**
  3264. * 设置收款认领地区
  3265. */
  3266. function setInvoiceReceivablesClaim() {
  3267. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3268. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3269. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  3270. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  3271. Doo::loadModel ( 'invoiceReceivables' );
  3272. $invoiceReceivables = new invoiceReceivables ();
  3273. Doo::loadClass ( 'XDeode' );
  3274. $XDeode = new XDeode ( 5 );
  3275. Doo::loadModel ( 'invoiceROLog' );
  3276. $invoiceROLog = new invoiceROLog ();
  3277. $irid = $XDeode->decode ( $iridKey );
  3278. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3279. if (empty ( $irDetail ))
  3280. die ( 'illegal request' );
  3281. $item = array (
  3282. 'irid' => $irid,
  3283. 'receivablesCategory' => $receivablesCategory
  3284. );
  3285. if ($receivablesCategory != 'PUBLIC') {
  3286. $item += array (
  3287. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3288. 'inputType' => 1
  3289. );
  3290. }
  3291. $invoiceReceivables = new invoiceReceivables ();
  3292. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3293. // 收款操作日志
  3294. $item = array (
  3295. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  3296. 'date' => date ( "Y-m-d" ),
  3297. 'status' => 1,
  3298. 'img' => $this->staff [0] ['avatar'],
  3299. 'username' => $this->staff [0] ['username'],
  3300. 'uid' => $this->staff [0] ['sid'],
  3301. 'category' => $this->staff [0] ['category'],
  3302. 'irid' => $irid
  3303. );
  3304. $invoiceROLog->setInvoiceROLog ( $item );
  3305. if (empty ( $action ))
  3306. return '/invoiceReceivables';
  3307. else
  3308. return "/invoiceReceivablesAS";
  3309. }
  3310. die ( 'illegal request' );
  3311. }
  3312. /**
  3313. * 新添加收款直接入账发票
  3314. */
  3315. function invoiceCompareClaimPrice() {
  3316. // 收款录入
  3317. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3318. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3319. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3320. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3321. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3322. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  3323. Doo::loadModel ( 'invoiceReceivables' );
  3324. $invoiceReceivables = new invoiceReceivables ();
  3325. Doo::loadModel ( 'invoiceROLog' );
  3326. $invoiceROLog = new invoiceROLog ();
  3327. Doo::loadModel ( 'invoiceStatistics' );
  3328. Doo::loadModel ( 'invoice' );
  3329. $invoice = new invoice ();
  3330. Doo::loadModel ( 'bill' );
  3331. $bill = new bill ();
  3332. Doo::loadClass ( 'XDeode' );
  3333. $XDeode = new XDeode ( 5 );
  3334. Doo::loadModel ( 'invoiceOperationLog' );
  3335. $invoiceOperationLog = new invoiceOperationLog ();
  3336. $iidKey = $XDeode->decode ( $iidKey );
  3337. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  3338. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  3339. die ( 'illegal request' );
  3340. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3341. // 收款录入 并绑定发票
  3342. Doo::db ()->beginTransaction ();
  3343. //获得发票入账余额
  3344. //$bindInvicePrice=$invoiceReceivables->getSumOfReceivablesPrice ( $invoiceDetail['irid'] );
  3345. //$bindPrice=$invoiceDetail ['invoiceBalance']-$bindInvicePrice;
  3346. $bindStatus = 0;
  3347. $invoiceBalance=$invoiceDetail ['invoicePrice'];
  3348. if($invoiceDetail ['invoiceBalance']!=0){
  3349. $invoiceBalance=$invoiceDetail ['invoiceBalance'];
  3350. }
  3351. if ($receivablesPrice <= $invoiceBalance){
  3352. $bindStatus = 1;
  3353. //$bindPrice=$receivablesPrice;
  3354. }
  3355. $titleMark = $invoiceDetail ['invoiceTitle'];
  3356. if (! empty ( $invoiceDetail ['invoiceCompany'] ))
  3357. $titleMark = $invoiceDetail ['invoiceCompany'];
  3358. $item = array (
  3359. 'recepitTitleMark' => $titleMark,
  3360. 'bindStatus' => $bindStatus,
  3361. 'iid' => $invoiceDetail ['iid'],
  3362. 'bindPrice' => $receivablesPrice,
  3363. 'bindDate' => date ( "Y-m-d H:i:s" ),
  3364. 'receivablesPrice' => $receivablesPrice,
  3365. 'OriginalPrice' => $receivablesPrice,
  3366. 'receivablesMessage' => $receivablesMessage,
  3367. 'receivablesSerial' => $receivablesSerial,
  3368. 'receivablesBank' => $receivablesBank,
  3369. 'receivablesDate' => $receivablesDate,
  3370. 'inputStaff' => $this->staff [0] ['username'],
  3371. 'accountClerk' => $this->staff [0] ['username'],
  3372. 'date' => date ( "Y-m-d" ),
  3373. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  3374. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  3375. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3376. );
  3377. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3378. $item = array ();
  3379. // 收款操作日志
  3380. $item = array (
  3381. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  3382. );
  3383. $item += array (
  3384. 'date' => date ( "Y-m-d" ),
  3385. 'status' => 1,
  3386. 'img' => $this->staff [0] ['avatar'],
  3387. 'username' => $this->staff [0] ['username'],
  3388. 'uid' => $this->staff [0] ['sid'],
  3389. 'category' => $this->staff [0] ['category'],
  3390. 'irid' => $irid
  3391. );
  3392. $invoiceROLog->setInvoiceROLog ( $item );
  3393. // 收款统计
  3394. $invoiceStatistics = new invoiceStatistics ();
  3395. $item = array (
  3396. 'date' => $receivablesDate,
  3397. 'priceClass' => 2,
  3398. 'irid' => $irid,
  3399. 'cid' => $invoiceDetail ['cid'],
  3400. 'staff' => $invoiceDetail ['sid'],
  3401. 'receivablesPrice' => $receivablesPrice
  3402. );
  3403. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3404. // 收款 入 发票
  3405. $detail = $invoiceDetail;
  3406. $iridString = "";
  3407. if (empty ( $detail ['irid'] ))
  3408. $iridString = $irid;
  3409. else
  3410. $iridString = $detail ['irid'] . ',' . $irid;
  3411. $item = array (
  3412. 'irid' => $iridString,
  3413. 'bindTime' => date ( "Y-m-d H:i:s" ),
  3414. 'updateTime' => date ( "Y-m-d H:i:s" ),
  3415. 'iid' => $detail ['iid']
  3416. );
  3417. // $invoiceReceivables = new invoiceReceivables ();
  3418. // $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3419. // $sumBind = $bindInvicePrice;
  3420. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($irid);
  3421. // $sum=$sumBind+$sumBalance;
  3422. // ;
  3423. if ($receivablesPrice>=$invoiceBalance){
  3424. $item += array (
  3425. 'invoiceBalance'=>0,
  3426. 'untreadStatus' => 3
  3427. );
  3428. }else{
  3429. $item += array (
  3430. 'invoiceBalance'=>$invoiceBalance-$receivablesPrice
  3431. );
  3432. }
  3433. $invoice->setInvoiceByCondition ( $item );
  3434. // 操作日志
  3435. $item = array (
  3436. 'date' => date ( "Y-m-d H:i:s" ),
  3437. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  3438. 'status' => 8,
  3439. 'img' => $this->staff [0] ['avatar'],
  3440. 'username' => $this->staff [0] ['username'],
  3441. 'uid' => $this->staff [0] ['sid'],
  3442. 'category' => $this->staff [0] ['category'],
  3443. 'iid' => $detail ['iid']
  3444. );
  3445. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3446. // 入账汇总
  3447. $invoiceStatistics = new invoiceStatistics ();
  3448. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  3449. // $accountPrice = 0;
  3450. // foreach ( $list as $key => $value ) {
  3451. // $accountPrice += $value ['receivablesPrice'];
  3452. // }
  3453. $item = array (
  3454. 'date' => $receivablesDate,
  3455. 'priceClass' => 3,
  3456. 'cid' => $invoiceDetail ['cid'],
  3457. 'staff' => $invoiceDetail ['sid'],
  3458. 'accountPrice' => $receivablesPrice
  3459. );
  3460. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3461. //发票入账记录
  3462. $bill->iid=$invoiceDetail['iid'];
  3463. $bill->trainId=$invoiceDetail['trainId'];
  3464. $bill->irid=$irid;
  3465. $bill->create_time=date ( "Y-m-d H:i:s" );
  3466. $bill->price=$receivablesPrice;
  3467. $bill->insert ();
  3468. // 公司流水记录
  3469. Doo::loadModel ( 'wasteBook' );
  3470. $wasteBook = new wasteBook ();
  3471. $abDetail = $wasteBook->getAccountBookByAid ( 2, 7, $irid );
  3472. $accountBank = '';
  3473. if ($receivablesBank == '纵横广发') {
  3474. $accountBank = 'CGBDeposit';
  3475. } elseif ($receivablesBank == '纵横工行') {
  3476. $accountBank = 'ICBCDeposit';
  3477. } elseif ($receivablesBank == '华润银行') {
  3478. $accountBank = 'HUADeposit';
  3479. } elseif ($receivablesBank == '个人广发') {
  3480. $accountBank = 'PersonalDeposit';
  3481. }
  3482. if (empty ( $abDetail )) {
  3483. $item = array (
  3484. 'dataID' => $irid,
  3485. 'expensesType' => 1,
  3486. 'accountType' => 7,
  3487. 'accountPrice' => $receivablesPrice,
  3488. 'accountPriceShow' => $receivablesPrice,
  3489. 'accountBank' => $accountBank,
  3490. 'category' => $this->staff [0] ['category'],
  3491. 'cid' => $this->staff [0] ['cid'],
  3492. 'name' => $this->staff [0] ['username'],
  3493. 'sid' => $this->staff [0] ['sid'],
  3494. 'inputDate' => date ( "Y-m-d H:i:s" )
  3495. );
  3496. $wasteBook->setAccountBookStatistics ( $item );
  3497. }
  3498. Doo::db ()->commit ();
  3499. }
  3500. return '/invoiceReceivables';
  3501. }
  3502. /**
  3503. * 录入收款数据
  3504. * @return string
  3505. */
  3506. function invoiceReceivablesDo() {
  3507. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3508. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3509. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3510. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3511. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3512. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3513. Doo::loadModel ( 'invoiceReceivables' );
  3514. $invoiceReceivables = new invoiceReceivables ();
  3515. Doo::loadModel ( 'invoiceROLog' );
  3516. $invoiceROLog = new invoiceROLog ();
  3517. Doo::loadModel ( 'invoiceStatistics' );
  3518. $invoiceStatistics = new invoiceStatistics ();
  3519. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  3520. $item = array (
  3521. 'receivablesPrice' => $receivablesPrice,
  3522. 'OriginalPrice' => $receivablesPrice,
  3523. 'receivablesMessage' => $receivablesMessage,
  3524. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  3525. 'receivablesBank' => $receivablesBank,
  3526. 'receivablesDate' => $receivablesDate,
  3527. 'inputStaff' => $this->staff [0] ['username'],
  3528. 'date' => date ( "Y-m-d" ),
  3529. 'receivablesCategory' => $receivablesCategory,
  3530. 'receivablesStaff' => $receivablesStaff
  3531. );
  3532. if ($receivablesCategory != 'PUBLIC') {
  3533. $item += array (
  3534. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3535. 'inputType' => 1
  3536. );
  3537. }
  3538. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  3539. $item = array ();
  3540. // 收款操作日志
  3541. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3542. $item = array (
  3543. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3544. );
  3545. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3546. $item = array (
  3547. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3548. );
  3549. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3550. $receivablesStaff = explode ( '-', $receivablesStaff );
  3551. $item = array (
  3552. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3553. );
  3554. }
  3555. $item += array (
  3556. 'date' => date ( "Y-m-d" ),
  3557. 'status' => 1,
  3558. 'img' => $this->staff [0] ['avatar'],
  3559. 'username' => $this->staff [0] ['username'],
  3560. 'uid' => $this->staff [0] ['sid'],
  3561. 'category' => $this->staff [0] ['category'],
  3562. 'irid' => $irid
  3563. );
  3564. $invoiceROLog->setInvoiceROLog ( $item );
  3565. $item = array (
  3566. 'date' => $receivablesDate,
  3567. 'priceClass' => 2,
  3568. 'irid' => $irid,
  3569. 'receivablesPrice' => $receivablesPrice
  3570. );
  3571. if ($receivablesCategory != 'PUBLIC') {
  3572. $receivablesCategory = explode ( ":", $receivablesCategory );
  3573. $item += array (
  3574. 'cid' => $receivablesCategory [0]
  3575. );
  3576. }
  3577. if ($receivablesStaff2 != 'PUBLIC') {
  3578. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  3579. $item += array (
  3580. 'staff' => $receivablesStaff [0]
  3581. );
  3582. }
  3583. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3584. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  3585. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  3586. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  3587. if ($toparty != 0)
  3588. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  3589. // 公司流水记录
  3590. Doo::loadModel ( 'wasteBook' );
  3591. $wasteBook = new wasteBook ();
  3592. $abDetail = $wasteBook->getAccountBookByAid ( 1, 7, $irid );
  3593. $accountBank = '';
  3594. if ($receivablesBank == '纵横广发') {
  3595. $accountBank = 'CGBDeposit';
  3596. } elseif ($receivablesBank == '纵横工行') {
  3597. $accountBank = 'ICBCDeposit';
  3598. } elseif ($receivablesBank == '华润银行') {
  3599. $accountBank = 'HUADeposit';
  3600. } elseif ($receivablesBank == '个人广发') {
  3601. $accountBank = 'PersonalDeposit';
  3602. }
  3603. $item = array (
  3604. 'dataID' => $irid,
  3605. 'expensesType' => 1,
  3606. 'accountType' => 7,
  3607. 'accountPriceShow' => $receivablesPrice,
  3608. 'accountPrice' => $receivablesPrice,
  3609. 'accountBank' => $accountBank,
  3610. 'category' => $this->staff [0] ['category'],
  3611. 'cid' => $this->staff [0] ['cid'],
  3612. 'name' => $this->staff [0] ['username'],
  3613. 'sid' => $this->staff [0] ['sid'],
  3614. 'inputDate' => date ( "Y-m-d H:i:s" )
  3615. );
  3616. $wasteBook->setAccountBookStatistics ( $item );
  3617. }
  3618. return "/invoiceReceivables";
  3619. }
  3620. /**
  3621. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  3622. */
  3623. function invoiceReceivablesClaim() {
  3624. Doo::loadModel ( 'invoiceReceivables' );
  3625. $invoiceReceivables = new invoiceReceivables ();
  3626. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3627. $this->data ['receivablesList'] = $receivablesList;
  3628. $this->data ['memu'] = "invoice";
  3629. $this->data ['staff'] = $this->staff;
  3630. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  3631. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  3632. }
  3633. function invoiceReceivablesTitleMarkSet() {
  3634. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  3635. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3636. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  3637. die ( 'illegal request' );
  3638. Doo::loadModel ( 'invoiceReceivables' );
  3639. $invoiceReceivables = new invoiceReceivables ();
  3640. Doo::loadClass ( 'XDeode' );
  3641. $XDeode = new XDeode ( 5 );
  3642. $irid = $XDeode->decode ( $iridKey );
  3643. if (! is_numeric ( $irid ))
  3644. die ( 'illegal request' );
  3645. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  3646. $invoiceReceivables->update ( array (
  3647. 'where' => 'irid = ' . $irid
  3648. ) );
  3649. return '/invoiceReceivablesClaim';
  3650. }
  3651. /**
  3652. * 更新收款相关数据
  3653. */
  3654. function invoiceReceivablesUpdateClaim() {
  3655. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3656. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  3657. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  3658. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  3659. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  3660. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  3661. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3662. if (empty ( $claimKey ))
  3663. die ( 'illegal request' );
  3664. Doo::loadModel ( 'invoiceReceivables' );
  3665. $invoiceReceivables = new invoiceReceivables ();
  3666. Doo::loadModel ( 'invoiceROLog' );
  3667. $invoiceROLog = new invoiceROLog ();
  3668. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  3669. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3670. if (empty ( $detail ))
  3671. die ( 'illegal request' );
  3672. $invoiceReceivables = new invoiceReceivables ();
  3673. $item = array (
  3674. 'irid' => $detail ['irid']
  3675. );
  3676. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3677. $item += array (
  3678. 'confirmTime' => date ( "Y-m-d H:i:s" )
  3679. );
  3680. }
  3681. if (! empty ( $receivablesCategory ))
  3682. $item += array (
  3683. 'receivablesCategory' => $receivablesCategory
  3684. );
  3685. if (! empty ( $receivablesStaff ))
  3686. $item += array (
  3687. 'receivablesStaff' => $receivablesStaff
  3688. );
  3689. if (! empty ( $receivablesPrice ))
  3690. $item += array (
  3691. 'receivablesPrice' => $receivablesPrice
  3692. );
  3693. if (! empty ( $receivablesMessage ))
  3694. $item += array (
  3695. 'receivablesMessage' => $receivablesMessage
  3696. );
  3697. if (! empty ( $receivablesBank ))
  3698. $item += array (
  3699. 'receivablesBank' => $receivablesBank
  3700. );
  3701. if (! empty ( $receivablesDate ))
  3702. $item += array (
  3703. 'receivablesDate' => $receivablesDate
  3704. );
  3705. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3706. // 收款操作日志
  3707. $item = array ();
  3708. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3709. $item = array (
  3710. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  3711. );
  3712. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  3713. $item = array (
  3714. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  3715. );
  3716. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  3717. $receivablesStaff = explode ( '-', $receivablesStaff );
  3718. $item = array (
  3719. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  3720. );
  3721. }
  3722. $item += array (
  3723. 'date' => date ( "Y-m-d" ),
  3724. 'status' => 1,
  3725. 'img' => $this->staff [0] ['avatar'],
  3726. 'username' => $this->staff [0] ['username'],
  3727. 'uid' => $this->staff [0] ['sid'],
  3728. 'category' => $this->staff [0] ['category'],
  3729. 'irid' => $detail ['irid']
  3730. );
  3731. $invoiceROLog->setInvoiceROLog ( $item );
  3732. return '/invoiceReceivablesAS';
  3733. }
  3734. function invoiceReceivablesDelete() {
  3735. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  3736. $skll = $this->get_args ( 'skll' ) ? $this->get_args ( 'skll' ) : "";
  3737. if ($skll != '删除到款')
  3738. die ( 'illegal request' );
  3739. if (empty ( $claimKey ))
  3740. die ( 'illegal request' );
  3741. Doo::loadModel ( 'invoiceReceivables' );
  3742. $invoiceReceivables = new invoiceReceivables ();
  3743. $con = ' and bindStatus=0 ';
  3744. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  3745. if (empty ( $detail ))
  3746. die ( 'illegal request' );
  3747. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  3748. // 扣除收款汇总信息 汇总
  3749. Doo::loadModel ( 'invoiceStatistics' );
  3750. $invoiceStatistics = new invoiceStatistics ();
  3751. $item = array (
  3752. 'date' => $detail ['receivablesDate'],
  3753. 'priceClass' => 2,
  3754. 'irid' => $detail ['irid'],
  3755. 'receivablesPrice' => - $detail ['receivablesPrice']
  3756. );
  3757. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  3758. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  3759. $item += array (
  3760. 'cid' => $receivablesCategory [0]
  3761. );
  3762. }
  3763. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  3764. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  3765. $item += array (
  3766. 'staff' => $receivablesStaff [0]
  3767. );
  3768. }
  3769. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3770. // 公司流水-删除时删除流水
  3771. Doo::loadModel ( 'wasteBook' );
  3772. $wasteBook = new wasteBook ();
  3773. $wasteBook->delete ( array (
  3774. 'where' => 'dataID=' . $detail ['irid'] . ' and accountType=7',
  3775. 'limit' => 1
  3776. ) );
  3777. return '/invoiceReceivablesAS';
  3778. }
  3779. /**
  3780. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  3781. */
  3782. function invoiceReceivablesAscription() {
  3783. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3784. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  3785. Doo::loadModel ( 'invoiceReceivables' );
  3786. $invoiceReceivables = new invoiceReceivables ();
  3787. Doo::loadModel ( 'invoiceROLog' );
  3788. $invoiceROLog = new invoiceROLog ();
  3789. Doo::loadModel ( 'invoiceStatistics' );
  3790. $invoiceStatistics = new invoiceStatistics ();
  3791. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  3792. $irid = $invoiceReceivables->authcode ( $irid );
  3793. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  3794. $item = array (
  3795. 'irid' => $detail ['irid'],
  3796. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  3797. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  3798. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  3799. 'recepitTitleMark' => $recepitTitleMark,
  3800. 'source' => 1
  3801. );
  3802. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3803. $item = array (
  3804. 'date' => date ( "Y-m-d" ),
  3805. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  3806. 'status' => 2,
  3807. 'img' => $this->staff [0] ['avatar'],
  3808. 'username' => $this->staff [0] ['username'],
  3809. 'uid' => $this->staff [0] ['sid'],
  3810. 'category' => $this->staff [0] ['category'],
  3811. 'irid' => $irid
  3812. );
  3813. $invoiceROLog->setInvoiceROLog ( $item );
  3814. $item = array (
  3815. 'cid' => $this->staff [0] ['cid'],
  3816. 'staff' => $this->staff [0] ['sid']
  3817. );
  3818. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  3819. }
  3820. return "/invoiceReceivablesClaim";
  3821. }
  3822. /**
  3823. */
  3824. function invoiceMyReceivables() {
  3825. Doo::loadModel ( 'invoiceReceivables' );
  3826. $invoiceReceivables = new invoiceReceivables ();
  3827. Doo::loadModel ( 'invoiceStatistics' );
  3828. $invoiceStatistics = new invoiceStatistics ();
  3829. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3830. $year = date ( "Y" );
  3831. $tmp_date = date ( "Ym" );
  3832. $tmp_year = substr ( $tmp_date, 0, 4 );
  3833. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3834. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3835. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3836. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3837. $htm = $this->showCache ( $path );
  3838. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3839. $this->data ['isMonth'] = $isMonth;
  3840. $this->data ['htm'] = $htm;
  3841. $this->data ['list'] = $list;
  3842. $this->data ['memu'] = "invoice";
  3843. $this->data ['staff'] = $this->staff;
  3844. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3845. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3846. }
  3847. /**
  3848. * 纸票管理
  3849. */
  3850. function invoicePaper() {
  3851. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3852. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3853. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3854. $this->data ['dateString'] = $date;
  3855. $this->data ['status'] = $status;
  3856. $this->data ['invoiceType'] = $invoiceType;
  3857. $this->data ['memu'] = "invoice";
  3858. $this->data ['staff'] = $this->staff;
  3859. $this->data ['receiptMemu'] = 'invoicePaper';
  3860. $this->render ( "/admin/invoicePaper", $this->data );
  3861. }
  3862. /**
  3863. * 电子发票管理
  3864. */
  3865. function invoiceElectronic() {
  3866. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3867. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3868. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3869. $this->data ['dateString'] = $date;
  3870. $this->data ['status'] = $status;
  3871. $this->data ['invoiceType'] = $invoiceType;
  3872. $this->data ['memu'] = "invoice";
  3873. $this->data ['staff'] = $this->staff;
  3874. $this->data ['receiptMemu'] = 'invoicePaper';
  3875. $this->render ( "/invoice/invoiceElectronic", $this->data );
  3876. }
  3877. /**
  3878. * 获得纸票分页数据
  3879. */
  3880. function ajaxGetinvoicePaperAchieve() {
  3881. //include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  3882. Doo::loadModel ( 'invoicePaper' );
  3883. $invoicePaper = new invoicePaper ();
  3884. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3885. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3886. $invoiceForm = $this->get_args ( 'invoiceForm' )&&is_numeric($this->get_args ( 'invoiceForm' )) ? $this->get_args ( 'invoiceForm' ) : "0";
  3887. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3888. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3889. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3890. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3891. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3892. $MebSea = $this->get_args ( 'search' );
  3893. $MebSea = $MebSea ['value'];
  3894. $page_size = $length;
  3895. $con = '';
  3896. if ($status == 'ALL')
  3897. $con = ' where 1 ';
  3898. elseif ($status == 'PRINTED')
  3899. $con = ' where a.iid!=0 '; // $con = ' where b.isDelete=0 and a.iid!=0 and b.status=2 and b.untreadStatus=0 ';
  3900. elseif ($status == 'UNPRINT')
  3901. $con = ' where a.iid=0 '; // $con = ' where b.isDelete=0 and a.iid=0 and b.status=2 and b.untreadStatus=0 ';
  3902. elseif ($status == 'TICKET')
  3903. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3904. if ($invoiceType == 'ORDINARY')
  3905. $con .= ' and a.invoiceType=0 ';
  3906. elseif ($invoiceType == 'SPECIAL')
  3907. $con .= ' and a.invoiceType=1 ';
  3908. if($invoiceForm==0){
  3909. $con .= ' and a.invoiceForm=0 ';
  3910. }else{
  3911. $con .= ' and a.invoiceForm=1 ';
  3912. }
  3913. $dateArr = explode ( ':', $date );
  3914. $D1 = $dateString = '';
  3915. $D2 = '';
  3916. if (! empty ( $date )) {
  3917. $D1 = $dateArr [0];
  3918. if (isset ( $dateArr [1] ))
  3919. $D2 = $dateArr [1];
  3920. else
  3921. $D2 = '';
  3922. $dateString = $D1 . " : " . $D2;
  3923. }
  3924. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3925. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3926. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3927. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3928. if (! empty ( $MebSea ))
  3929. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3930. $invoiceTotal = $invoicePaper->getInvoicePaperCount ($invoiceForm);
  3931. $sql = ' ' . $con;
  3932. $limit = $page . ',' . $page_size;
  3933. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3934. $paperList = array ();
  3935. foreach ( $list as $key => $value ) {
  3936. $irDetail = array ();
  3937. if ($value ['iid'] == 0)
  3938. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3939. else
  3940. array_push ( $irDetail, '' );
  3941. array_push ( $irDetail, $value ['invoiceCode'] );
  3942. array_push ( $irDetail, $value ['invoiceNo'] );
  3943. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3944. if ($value ['invoiceType'] == 1)
  3945. array_push ( $irDetail, $value ['invoiceCompany'] );
  3946. else
  3947. array_push ( $irDetail, $value ['invoiceTitle'] );
  3948. if ($value ['invoiceType'] == 1)
  3949. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3950. else
  3951. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3952. array_push ( $irDetail, $value ['invoiceElement'] );
  3953. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3954. array_push ( $irDetail, $value ['printTime'] );
  3955. array_push ( $paperList, $irDetail );
  3956. }
  3957. // $approvalListJson = json_encode ( $approvalList );
  3958. $recordsFiltered = $invoiceTotal;
  3959. echo json_encode ( array (
  3960. "draw" => intval ( $draw ),
  3961. "recordsTotal" => intval ( $invoiceTotal ),
  3962. "recordsFiltered" => intval ( $recordsFiltered ),
  3963. "data" => $paperList
  3964. ), JSON_UNESCAPED_UNICODE );
  3965. }
  3966. function invoicePaperDel() {
  3967. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3968. $XDeode = new XDeode ( 5 );
  3969. $ipid = $XDeode->decode ( $ipidKey );
  3970. if (empty ( $ipid ))
  3971. die ( 'illegal request' );
  3972. Doo::loadModel ( 'invoicePaper' );
  3973. $invoicePaper = new invoicePaper ();
  3974. $ipdetail=$invoicePaper->getInvoicePaperByIpid($ipid);
  3975. $invoicePaper->delete ( array (
  3976. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3977. 'limit' => 1
  3978. ) );
  3979. if($ipdetail['invoiceForm']==1){
  3980. return '/invoiceElectronic';
  3981. }else{
  3982. return '/invoicePaper';
  3983. }
  3984. }
  3985. /**
  3986. * 添加纸质发票号
  3987. */
  3988. function invoicePaperAdd() {
  3989. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3990. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3991. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3992. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3993. $invoiceForm = $this->get_args ( 'invoiceForm' ) && is_numeric ( $this->get_args ( 'invoiceForm' ) ) ? $this->get_args ( 'invoiceForm' ) : 0;
  3994. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3995. $sum = $invoiceNoStart + $invoiceNoTotal;
  3996. if (empty ( $sum ))
  3997. die ( 'illegal request' );
  3998. // echo $invoiceNoStart;
  3999. // echo $sum;
  4000. // echo strlen((int)$invoiceNoStart);
  4001. $sumLenght = strlen ( $invoiceNoStart ) - strlen ( ( int ) $invoiceNoStart );
  4002. if($invoiceType==0||$invoiceType==1){
  4003. }else{
  4004. die ( 'illegal request invoiceType' );
  4005. }
  4006. if($invoiceForm==1){
  4007. $invoiceType=0;
  4008. }
  4009. Doo::db ()->beginTransaction ();
  4010. // 批量存储纸质发票
  4011. $date = date ( "Y-m-d H:i:s" );
  4012. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date,invoiceForm)
  4013. VALUES ';
  4014. $paperList = array ();
  4015. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  4016. // 数字前面自加0
  4017. $INLENGHT = strlen ( ( int ) $invoiceNoStart ) + $sumLenght;
  4018. $var = sprintf ( "%0" . $INLENGHT . "d", $invoiceNoStart );
  4019. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $var . '","' . $date . '","'.$invoiceForm.'")';
  4020. array_push ( $paperList, $paperSql );
  4021. }
  4022. if (empty ( $paperList ))
  4023. die ( 'illegal request' );
  4024. $sql = $sql . implode ( ',', $paperList );
  4025. Doo::db ()->query ( $sql );
  4026. Doo::db ()->commit ();
  4027. if($invoiceForm==1){
  4028. return 'invoiceElectronic';
  4029. }else{
  4030. return 'invoicePaper';
  4031. }
  4032. }
  4033. die ( 'illegal request' );
  4034. }
  4035. /**
  4036. * 收款绑定发票 ,//一个收款只能绑定一个发票
  4037. */
  4038. function invoiceBindReceivables() {
  4039. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  4040. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  4041. Doo::loadModel ( 'invoice' );
  4042. $invoice = new invoice ();
  4043. Doo::loadModel ( 'invoiceReceivables' );
  4044. $invoiceReceivables = new invoiceReceivables ();
  4045. Doo::loadModel ( 'invoiceOperationLog' );
  4046. $invoiceOperationLog = new invoiceOperationLog ();
  4047. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  4048. die ( 'illegal request' );
  4049. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  4050. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  4051. if (empty ( $detail ) && empty ( $detailM ))
  4052. die ( 'illegal request' );
  4053. if ($detail ['untreadStatus'] == 3)
  4054. die ( 'illegal request' );
  4055. // 修改 绑定状态改为 金额
  4056. $invoiceReceivables = new invoiceReceivables ();
  4057. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  4058. $billPrice=0;
  4059. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  4060. $item = array (
  4061. 'bindPrice' => $invoicePrice
  4062. );
  4063. $billPrice=$invoicePrice;
  4064. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) { //发票金额大于收款金额,绑定金额为收款金额
  4065. $item = array (
  4066. 'bindPrice' => $detailM ['receivablesPrice'],
  4067. 'bindStatus' => 1,
  4068. 'bindDate' => date ( "Y-m-d H:i:s" )
  4069. );
  4070. $billPrice=$detailM ['receivablesPrice'];
  4071. } else {
  4072. die ( 'illegal request' );
  4073. }
  4074. if ($detailM ['iid'] == 0) {
  4075. $item += array (
  4076. 'iid' => $detail ['iid']
  4077. );
  4078. } else {
  4079. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  4080. array_push ( $iidExtend, $detail ['iid'] );
  4081. $item += array (
  4082. 'iidExtend' => implode ( ',', $iidExtend )
  4083. );
  4084. }
  4085. $titleMark = $detail ['invoiceTitle'];
  4086. if (! empty ( $detail ['invoiceCompany'] ))
  4087. $titleMark = $detail ['invoiceCompany'];
  4088. $item += array (
  4089. 'irid' => $detailM ['irid'],
  4090. 'recepitTitleMark' => $titleMark,
  4091. 'accountClerk' => $this->staff [0] ['username']
  4092. );
  4093. // 如何没有人收款 则自动绑定收款
  4094. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  4095. $item += array (
  4096. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  4097. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  4098. );
  4099. }
  4100. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4101. $iridString = "";
  4102. if (empty ( $detail ['irid'] ))
  4103. $iridString = $detailM ['irid'];
  4104. else
  4105. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  4106. // $invoiceReceivables = new invoiceReceivables ();
  4107. // $sumBind = $invoiceReceivables->getSumOfReceivablesPrice ( $detail ['irid'] );
  4108. // //这个收款余额
  4109. // $sumBalance=$invoiceReceivables->balanceOfReceivablesPrice($detailM ['irid']);
  4110. // $sum=$sumBind+$sumBalance;
  4111. //这个收款余额
  4112. $sumBalance=$detailM ['receivablesPrice']-$detailM ['bindPrice'];
  4113. // echo $detailM ['irid'].'/'.$sumBalance.'/'.$detail ['invoicePrice'];
  4114. // die;
  4115. $invoice = new invoice ();
  4116. $item = array (
  4117. 'iid' => $detail ['iid'],
  4118. 'irid' => $iridString
  4119. );
  4120. if ($detail ['invoicePrice'] <= $sumBalance){
  4121. $item += array (
  4122. 'invoiceBalance'=>0,
  4123. 'untreadStatus' => 3,
  4124. 'bindTime' => date ( "Y-m-d H:i:s" )
  4125. );
  4126. }else{
  4127. $item += array (
  4128. 'invoiceBalance'=>$detail ['invoicePrice']-$sumBalance,
  4129. );
  4130. }
  4131. // print_r($item);
  4132. // echo $sum;die;
  4133. $invoice->setInvoiceByCondition ( $item );
  4134. //发票入账记录
  4135. Doo::loadModel ( 'bill' );
  4136. $bill = new bill ();
  4137. $bill->iid=$detail ['iid'];
  4138. $bill->trainId=$detail['trainId'];
  4139. $bill->irid=$detailM ['irid'];
  4140. $bill->create_time=date ( "Y-m-d H:i:s" );
  4141. $bill->price=$billPrice;
  4142. $bill->insert ();
  4143. // 操作日志
  4144. $item = array (
  4145. 'date' => date ( "Y-m-d H:i:s" ),
  4146. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  4147. 'status' => 8,
  4148. 'img' => $this->staff [0] ['avatar'],
  4149. 'username' => $this->staff [0] ['username'],
  4150. 'uid' => $this->staff [0] ['sid'],
  4151. 'category' => $this->staff [0] ['category'],
  4152. 'iid' => $detail ['iid']
  4153. );
  4154. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4155. Doo::loadModel ( 'invoiceStatistics' );
  4156. $invoiceStatistics = new invoiceStatistics ();
  4157. $item = array (
  4158. 'date' => $detailM ['receivablesDate'],
  4159. 'priceClass' => 3,
  4160. 'cid' => $detail ['cid'],
  4161. 'staff' => $detail ['sid'],
  4162. 'accountPrice' => $detailM ['receivablesPrice']
  4163. );
  4164. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4165. // 公司流水记录
  4166. // Doo::loadModel ( 'wasteBook' );
  4167. // $wasteBook = new wasteBook ();
  4168. // $abDetail = $wasteBook->getAccountBookByAid (1,8,$detail ['iid'] );
  4169. // $accountBank='';
  4170. // if ($detailM ['receivablesBank']=='纵横广发'){
  4171. // $accountBank='CGBDeposit';
  4172. // }elseif($detailM ['receivablesBank']=='纵横工行'){
  4173. // $accountBank='ICBCDeposit';
  4174. // }elseif($detailM ['receivablesBank']=='华润银行'){
  4175. // $accountBank='HUADeposit';
  4176. // }elseif($detailM ['receivablesBank']=='个人广发'){
  4177. // $accountBank='PersonalDeposit';
  4178. // }
  4179. // if (empty($abDetail)){
  4180. // $item = array (
  4181. // 'dataID' => $detail ['iid'],
  4182. // 'expensesType' => 1,
  4183. // 'accountType' => 8,
  4184. // 'accountPriceShow'=>$detail ['invoicePrice'],
  4185. // 'accountPrice'=>$detail ['invoicePrice'],
  4186. // 'accountBank'=>$accountBank,
  4187. // 'category'=>$this->staff[0]['category'],
  4188. // 'cid'=>$this->staff[0]['cid'],
  4189. // 'name'=>$this->staff[0]['username'],
  4190. // 'sid'=>$this->staff[0]['sid'],
  4191. // 'inputDate'=>date ( "Y-m-d H:i:s" )
  4192. // );
  4193. // $wasteBook->setAccountBookStatistics($item);
  4194. // }
  4195. return "/invoiceReceivables";
  4196. }
  4197. /**
  4198. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  4199. */
  4200. function invoiceAggregate() {
  4201. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4202. Doo::loadModel ( 'invoiceStatistics' );
  4203. $invoiceStatistics = new invoiceStatistics ();
  4204. Doo::loadModel ( 'L_category' );
  4205. $Lcategory = new L_category ();
  4206. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  4207. $LcategoryList = $Lcategory->getCategory ();
  4208. // print_r($isList);
  4209. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  4210. foreach ( $LcategoryList as $key => $value ) {
  4211. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  4212. $month = 1;
  4213. $invoicePriceYear = 0;
  4214. $receivablesPriceYear = 0;
  4215. $accountPriceYear = 0;
  4216. for(; $month <= 12; $month ++) {
  4217. $flag = true;
  4218. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  4219. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  4220. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  4221. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  4222. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  4223. ';
  4224. $invoicePriceYear += $v ['invoicePrice'];
  4225. $receivablesPriceYear += $v ['receivablesPrice'];
  4226. $accountPriceYear += $v ['accountPrice'];
  4227. $flag = false;
  4228. break;
  4229. }
  4230. }
  4231. if ($flag)
  4232. $html .= '<td class="taR"></td>
  4233. <td class="taR"></td>
  4234. <td class="taR"><b></b></td>
  4235. ';
  4236. }
  4237. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4238. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4239. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4240. ';
  4241. $html .= '</tr>';
  4242. }
  4243. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  4244. $invoicePriceYear = 0;
  4245. $receivablesPriceYear = 0;
  4246. $accountPriceYear = 0;
  4247. for($month = 1; $month <= 12; $month ++) {
  4248. $flag = true;
  4249. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  4250. if ($month == $v ['month']) {
  4251. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  4252. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  4253. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  4254. ';
  4255. $invoicePriceYear += $v ['invoicePrice'];
  4256. $receivablesPriceYear += $v ['receivablesPrice'];
  4257. $accountPriceYear += $v ['accountPrice'];
  4258. $flag = false;
  4259. break;
  4260. }
  4261. }
  4262. if ($flag) {
  4263. $html .= '<td class="taR"></td>
  4264. <td class="taR"></td>
  4265. <td class="taR"><b></b></td>
  4266. ';
  4267. }
  4268. }
  4269. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4270. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4271. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4272. ';
  4273. $html .= '</tr>';
  4274. // print_r($isList);
  4275. $this->data ['html'] = $html;
  4276. $this->data ['LcategoryList'] = $LcategoryList;
  4277. $this->data ['isList'] = $isList;
  4278. $this->data ['year'] = $year;
  4279. $this->data ['memu'] = "invoice";
  4280. $this->data ['staff'] = $this->staff;
  4281. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4282. $this->render ( "/admin/invoiceAggregate", $this->data );
  4283. }
  4284. function invoiceAggregateStaff() {
  4285. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4286. Doo::loadModel ( 'invoiceStatistics' );
  4287. $invoiceStatistics = new invoiceStatistics ();
  4288. Doo::loadModel ( 'L_category' );
  4289. $Lcategory = new L_category ();
  4290. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  4291. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  4292. $cStaff = $Lcategory->getCategoryStaff ();
  4293. $html = '';
  4294. foreach ( $cStaff as $key => $value ) {
  4295. $categoryFir = true;
  4296. foreach ( $value ['staff'] as $k => $v ) {
  4297. if ($categoryFir) {
  4298. $width = count ( $value ['staff'] ) + 1;
  4299. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  4300. $categoryFir = false;
  4301. } else
  4302. $html .= '<tr>';
  4303. $html .= '<th>' . $v ['username'] . '</th>';
  4304. $invoicePriceStaffYear = 0;
  4305. $receivablesPriceStaffYear = 0;
  4306. $accountPriceStaffYear = 0;
  4307. for($month = 1; $month <= 12; $month ++) {
  4308. $flag = true;
  4309. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  4310. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  4311. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  4312. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  4313. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  4314. ';
  4315. $invoicePriceStaffYear += $slv ['invoicePrice'];
  4316. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  4317. $accountPriceStaffYear += $slv ['accountPrice'];
  4318. $flag = false;
  4319. break;
  4320. }
  4321. }
  4322. if ($flag)
  4323. $html .= '<td class="taR"></td>
  4324. <td class="taR"></td>
  4325. <td class="taR"><b></b></td>
  4326. ';
  4327. }
  4328. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4329. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4330. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4331. ';
  4332. }
  4333. $html .= '</tr>';
  4334. // 小计
  4335. if (! empty ( $value ['staff'] )) {
  4336. $html .= '<tr><th class="taR">小计</th>';
  4337. $invoicePriceStaffYear = 0;
  4338. $receivablesPriceStaffYear = 0;
  4339. $accountPriceStaffYear = 0;
  4340. for($month = 1; $month <= 12; $month ++) {
  4341. $flag = true;
  4342. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  4343. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  4344. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  4345. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  4346. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  4347. ';
  4348. $invoicePriceStaffYear += $slv ['invoicePrice'];
  4349. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  4350. $accountPriceStaffYear += $slv ['accountPrice'];
  4351. $flag = false;
  4352. break;
  4353. }
  4354. }
  4355. if ($flag)
  4356. $html .= '<td class="taR"></td>
  4357. <td class="taR"></td>
  4358. <td class="taR"><b></b></td>
  4359. ';
  4360. }
  4361. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  4362. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  4363. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  4364. ';
  4365. $html .= '</tr>';
  4366. }
  4367. }
  4368. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  4369. $invoicePriceYear = 0;
  4370. $receivablesPriceYear = 0;
  4371. $accountPriceYear = 0;
  4372. for($month = 1; $month <= 12; $month ++) {
  4373. $flag = true;
  4374. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  4375. if ($month == $v ['month']) {
  4376. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  4377. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  4378. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  4379. ';
  4380. $invoicePriceYear += $v ['invoicePrice'];
  4381. $receivablesPriceYear += $v ['receivablesPrice'];
  4382. $accountPriceYear += $v ['accountPrice'];
  4383. $flag = false;
  4384. break;
  4385. }
  4386. }
  4387. if ($flag)
  4388. $html .= '<td class="taR"></td>
  4389. <td class="taR"></td>
  4390. <td class="taR"><b></b></td>
  4391. ';
  4392. }
  4393. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  4394. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  4395. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  4396. ';
  4397. $html .= '</tr>';
  4398. $this->data ['html'] = $html;
  4399. $this->data ['isList'] = $toteList;
  4400. $this->data ['year'] = $year;
  4401. $this->data ['memu'] = "invoice";
  4402. $this->data ['staff'] = $this->staff;
  4403. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4404. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  4405. }
  4406. function invoiceAggregateCategory() {
  4407. Doo::loadClass ( 'XDeode' );
  4408. $XDeode = new XDeode ( 5 );
  4409. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  4410. $cid = $XDeode->decode ( $cid );
  4411. if (! is_numeric ( $cid ))
  4412. die ( 'illegal request' );
  4413. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  4414. Doo::loadModel ( 'invoiceStatistics' );
  4415. $invoiceStatistics = new invoiceStatistics ();
  4416. Doo::loadModel ( 'staff' );
  4417. $staff = new staff ();
  4418. $list = $staff->getStaffByCid ( $cid );
  4419. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  4420. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  4421. if (empty ( $list ))
  4422. die ( '该办事处没有成员' );
  4423. $htmlA = $htmlB = $htmlC = $html = '';
  4424. foreach ( $list as $key => $value ) {
  4425. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  4426. $htmlB = '<tr><th class="taC">收款</th>';
  4427. $htmlC = '<tr><th class="taC">入账</th>';
  4428. $invoicePriceStaffYear = 0;
  4429. $receivablesPriceStaffYear = 0;
  4430. $accountPriceStaffYear = 0;
  4431. for($month = 1; $month <= 12; $month ++) {
  4432. $flag = true;
  4433. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  4434. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  4435. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  4436. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  4437. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4438. $invoicePriceStaffYear += $v ['invoicePrice'];
  4439. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4440. $accountPriceStaffYear += $v ['accountPrice'];
  4441. $flag = false;
  4442. break;
  4443. }
  4444. }
  4445. if ($flag) {
  4446. $htmlA .= '<td class="taR">-</td>';
  4447. $htmlB .= '<td class="taR">-</td>';
  4448. $htmlC .= '<td class="taR"><b>-</b></td>';
  4449. }
  4450. }
  4451. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4452. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4453. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4454. $htmlA .= '</tr>';
  4455. $htmlB .= '</tr>';
  4456. $htmlC .= '</tr>';
  4457. $html .= $htmlA . $htmlB . $htmlC;
  4458. }
  4459. $htmlA = $htmlB = $htmlC = "";
  4460. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  4461. $htmlB = '<tr><th class="taC">收款</th>';
  4462. $htmlC = '<tr><th class="taC">入账</th>';
  4463. $invoicePriceStaffYear = 0;
  4464. $receivablesPriceStaffYear = 0;
  4465. $accountPriceStaffYear = 0;
  4466. for($month = 1; $month <= 12; $month ++) {
  4467. $flag = true;
  4468. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  4469. if ($month == $v ['month']) {
  4470. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  4471. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  4472. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  4473. $invoicePriceStaffYear += $v ['invoicePrice'];
  4474. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  4475. $accountPriceStaffYear += $v ['accountPrice'];
  4476. $flag = false;
  4477. break;
  4478. }
  4479. }
  4480. if ($flag) {
  4481. $htmlA .= '<td class="taR">-</td>';
  4482. $htmlB .= '<td class="taR">-</td>';
  4483. $htmlC .= '<td class="taR"><b>-</b></td>';
  4484. }
  4485. }
  4486. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  4487. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  4488. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  4489. $htmlA .= '</tr>';
  4490. $htmlB .= '</tr>';
  4491. $htmlC .= '</tr>';
  4492. $html .= $htmlA . $htmlB . $htmlC;
  4493. $this->data ['html'] = $html;
  4494. $this->data ['cidKey'] = $cidKey;
  4495. $this->data ['slist'] = $list;
  4496. $this->data ['isList'] = $toteList;
  4497. $this->data ['year'] = $year;
  4498. $this->data ['memu'] = "invoice";
  4499. $this->data ['staff'] = $this->staff;
  4500. $this->data ['receiptMemu'] = 'invoiceAggregate';
  4501. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  4502. }
  4503. /**
  4504. * 办事处汇总信息
  4505. */
  4506. function invoiceAggregateCategoryDetail() {
  4507. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4508. Doo::loadClass ( 'XDeode' );
  4509. $XDeode = new XDeode ( 5 );
  4510. Doo::loadModel ( 'invoiceStatistics' );
  4511. $invoiceStatistics = new invoiceStatistics ();
  4512. Doo::loadModel ( 'L_category' );
  4513. $category = new L_category ();
  4514. Doo::loadModel ( 'invoice' );
  4515. $invoice = new invoice ();
  4516. Doo::loadModel ( 'staff' );
  4517. $staff = new staff ();
  4518. Doo::loadModel ( "invoiceCategoryManage" );
  4519. $invoiceCategoryManage = new invoiceCategoryManage ();
  4520. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4521. $cidList = array ();
  4522. foreach ( $imcStaff as $key => $value ) {
  4523. array_push ( $cidList, $value ['cid'] );
  4524. if (empty ( $cidKey ))
  4525. $cidKey = $XDeode->encode ( $value ['cid'] );
  4526. }
  4527. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4528. $cid = $XDeode->decode ( $cidKey );
  4529. $month = date ( "m", strtotime ( "-1 month" ) );
  4530. $YearMonth = date ( "Y-m", strtotime ( "-1 month" ) );
  4531. $redis = new Redis ();
  4532. $redis->connect ( '127.0.0.1', '6379' );
  4533. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  4534. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  4535. if (empty ( $redisValue )) {
  4536. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  4537. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  4538. // 获得办事处人员下的汇总
  4539. $slist = $staff->getStaffByCid ( $cid );
  4540. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $YearMonth ); // 上一个月的汇总
  4541. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  4542. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  4543. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  4544. foreach ( $slist as $key => $value ) {
  4545. $slist [$key] ['invoicePrice'] = 0;
  4546. $slist [$key] ['receivablesPrice'] = 0;
  4547. $slist [$key] ['accountPrice'] = 0;
  4548. $slist [$key] ['invoiceAllPrice'] = 0;
  4549. $slist [$key] ['receivablesAllPrice'] = 0;
  4550. $slist [$key] ['accountAllPrice'] = 0;
  4551. $slist [$key] ['schedule'] = 0;
  4552. $slist [$key] ['invoiceMonthPrice'] = 0;
  4553. $slist [$key] ['receivablesMonthPrice'] = 0;
  4554. $slist [$key] ['accountMonthPrice'] = 0;
  4555. foreach ( $ismsbMonth as $y => $l ) {
  4556. if ($value ['sid'] == $l ['staff']) {
  4557. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  4558. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  4559. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  4560. }
  4561. }
  4562. foreach ( $ismsb as $k => $v ) {
  4563. if ($value ['sid'] == $v ['staff']) {
  4564. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  4565. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  4566. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  4567. }
  4568. }
  4569. foreach ( $ISAS as $e => $a ) {
  4570. if ($value ['sid'] == $a ['staff']) {
  4571. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  4572. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  4573. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  4574. }
  4575. }
  4576. if (isset ( $scheduleStaff [$value ['sid']] ))
  4577. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  4578. }
  4579. $this->data ['cidKey'] = $cidKey;
  4580. $schedule = ( int ) ($schedule * 100);
  4581. $this->data ['slist'] = $slist;
  4582. $this->data ['isMC'] = $isMC;
  4583. $this->data ['schedule'] = $schedule;
  4584. $slist = json_encode ( $slist );
  4585. $isMC = json_encode ( $isMC );
  4586. $schedule = json_encode ( $schedule );
  4587. $redis->lpush ( $redisKey, $slist );
  4588. $redis->lpush ( $redisKey, $isMC );
  4589. $redis->lpush ( $redisKey, $schedule );
  4590. } else {
  4591. $this->data ['cidKey'] = $cidKey;
  4592. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  4593. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  4594. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  4595. }
  4596. $this->data ['month'] = $month;
  4597. $this->data ['categoryList'] = $categoryList;
  4598. $this->data ['memu'] = "invoice";
  4599. $this->data ['staff'] = $this->staff;
  4600. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4601. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  4602. }
  4603. /**
  4604. * 办事处人员汇总详情
  4605. */
  4606. function invoiceAggregateStaffDetail() {
  4607. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4608. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  4609. Doo::loadClass ( 'XDeode' );
  4610. $XDeode = new XDeode ( 5 );
  4611. Doo::loadModel ( 'invoice' );
  4612. $invoice = new invoice ();
  4613. Doo::loadModel ( 'staff' );
  4614. $staff = new staff ();
  4615. Doo::loadModel ( "invoiceCategoryManage" );
  4616. $invoiceCategoryManage = new invoiceCategoryManage ();
  4617. $sid = $XDeode->decode ( $sidKey );
  4618. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4619. $cidList = array ();
  4620. foreach ( $imcStaff as $key => $value ) {
  4621. array_push ( $cidList, $value ['cid'] );
  4622. if (empty ( $cidKey ))
  4623. $cidKey = $XDeode->encode ( $value ['cid'] );
  4624. }
  4625. $cidString = implode ( ',', $cidList );
  4626. $staffList = $staff->getStaffInCid ( $cidString );
  4627. $staffDetail = $staff->getStaffBySid ( $sid );
  4628. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4629. $page_size = 18;
  4630. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4631. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4632. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4633. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4634. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4635. $dateArr = explode ( ':', $date );
  4636. $D1 = '';
  4637. $D2 = '';
  4638. if (! empty ( $date )) {
  4639. $D1 = $dateArr [0] . " 00:00:00 ";
  4640. if (isset ( $dateArr [1] ))
  4641. $D2 = $dateArr [1] . " 23:59:59 ";
  4642. else
  4643. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4644. // $D2 = $dateArr [1];
  4645. }
  4646. $con = ' status=2 ';
  4647. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4648. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4649. if ($status == 'UNRECORD')
  4650. $con .= ' and printStatus=1 and untreadStatus=0';
  4651. elseif ($status == 'RECORD')
  4652. $con .= ' and printStatus=1 and untreadStatus=3';
  4653. elseif ($status == 'BOUNCED')
  4654. $con .= ' and untreadStatus=2';
  4655. elseif ($status == 'PARTRECORD')
  4656. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4657. elseif ($status == 'All') {
  4658. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4659. }
  4660. $con .= ' and sid=' . $sid;
  4661. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4662. if (! empty ( $MebSea )) {
  4663. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4664. }
  4665. $pageinfo ['page'] = array (
  4666. 'previous' => ''
  4667. );
  4668. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  4669. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4670. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4671. $this->data ['staffDetail'] = $staffDetail;
  4672. $this->data ['staffList'] = $staffList;
  4673. $this->data ['MebSeaEn'] = $MebSea;
  4674. $this->data ['MebSea'] = urlencode ( $MebSea );
  4675. $this->data ['date'] = $date;
  4676. $this->data ['page'] = $pageinfo;
  4677. $this->data ['get'] = $get;
  4678. $this->data ['list'] = $list;
  4679. $this->data ['status'] = $status;
  4680. $this->data ['sidKey'] = $sidKey;
  4681. $this->data ['memu'] = "invoice";
  4682. $this->data ['staff'] = $this->staff;
  4683. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4684. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  4685. }
  4686. /**
  4687. * 办事处人员汇总收款情
  4688. */
  4689. function invoiceAggregateStaffReceivablesDetail() {
  4690. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4691. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  4692. Doo::loadModel ( 'invoiceReceivables' );
  4693. $invoiceReceivables = new invoiceReceivables ();
  4694. Doo::loadModel ( 'staff' );
  4695. $staff = new staff ();
  4696. Doo::loadModel ( "invoiceCategoryManage" );
  4697. $invoiceCategoryManage = new invoiceCategoryManage ();
  4698. Doo::loadClass ( 'XDeode' );
  4699. $XDeode = new XDeode ( 5 );
  4700. $sid = $XDeode->decode ( $sidKey );
  4701. $staffDetail = $staff->getStaffBySid ( $sid );
  4702. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4703. $cidList = array ();
  4704. foreach ( $imcStaff as $key => $value ) {
  4705. array_push ( $cidList, $value ['cid'] );
  4706. if (empty ( $cidKey ))
  4707. $cidKey = $XDeode->encode ( $value ['cid'] );
  4708. }
  4709. $cidString = implode ( ',', $cidList );
  4710. $staffList = $staff->getStaffInCid ( $cidString );
  4711. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4712. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4713. $page_size = 10;
  4714. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4715. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4716. if ($timeType == "BINDOTP") {
  4717. $status = 'Credited';
  4718. }
  4719. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  4720. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  4721. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  4722. $dateArr = explode ( ':', $date );
  4723. $D1 = '';
  4724. $D2 = '';
  4725. if (! empty ( $date )) {
  4726. $D1 = $dateArr [0] . " 00:00:00 ";
  4727. if (isset ( $dateArr [1] ))
  4728. $D2 = $dateArr [1] . " 23:59:59 ";
  4729. else
  4730. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4731. }
  4732. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  4733. $descField = 'a.bindDate';
  4734. if ($timeType == 'CREATE')
  4735. $descField = 'a.date';
  4736. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4737. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4738. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4739. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4740. if ($status == 'Unclaimed')
  4741. $con .= ' and a.bindStatus=0';
  4742. elseif ($status == 'Credited')
  4743. $con .= ' and a.bindStatus=1';
  4744. elseif ($status == 'Claim')
  4745. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4746. elseif ($status == 'BBN')
  4747. $con .= ' and a.bindPrice>a.receivablesPrice';
  4748. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  4749. if (! empty ( $MebSea )) {
  4750. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4751. }
  4752. $pageinfo ['page'] = array (
  4753. 'previous' => ''
  4754. );
  4755. // $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4756. // from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4757. // find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4758. // where ' . $con . ' group by a.irid ';
  4759. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4760. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  4761. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4762. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField);
  4763. foreach ( $list as $key => $value ) {
  4764. $list [$key] ['category'] = '';
  4765. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4766. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4767. $list [$key] ['category'] = $receivablesCategory [1];
  4768. }
  4769. }
  4770. // print_r($list);
  4771. $this->data ['staffDetail'] = $staffDetail;
  4772. $this->data ['sidKey'] = $sidKey;
  4773. $this->data ['staffList'] = $staffList;
  4774. $this->data ['timeType'] = $timeType;
  4775. $this->data ['MebSeaEn'] = $MebSea;
  4776. $this->data ['MebSea'] = urlencode ( $MebSea );
  4777. $this->data ['date'] = $date;
  4778. $this->data ['page'] = $pageinfo;
  4779. $this->data ['get'] = $get;
  4780. $this->data ['list'] = $list;
  4781. $this->data ['status'] = $status;
  4782. $this->data ['memu'] = "invoice";
  4783. $this->data ['staff'] = $this->staff;
  4784. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  4785. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  4786. }
  4787. function invoiceAchieve() {
  4788. Doo::loadModel ( 'invoice' );
  4789. $invoice = new invoice ();
  4790. Doo::loadClass ( 'XDeode' );
  4791. $XDeode = new XDeode ( 5 );
  4792. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4793. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4794. $page_size = 18;
  4795. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4796. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4797. $get = "/" . $date;
  4798. $con = '';
  4799. if ($date == 'MONTHO')
  4800. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4801. elseif ($date == 'MONTHT')
  4802. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4803. elseif ($date == 'MONTHY')
  4804. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4805. if (! empty ( $MebSea )) {
  4806. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4807. $get .= "/" . $MebSea;
  4808. }
  4809. $pageinfo ['page'] = array (
  4810. 'previous' => ''
  4811. );
  4812. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  4813. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  4814. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4815. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4816. // print_r($pageinfo);
  4817. $this->data ['MebSeaEn'] = $MebSea;
  4818. $this->data ['MebSea'] = urlencode ( $MebSea );
  4819. $this->data ['get'] = $get;
  4820. $this->data ['page'] = $pageinfo;
  4821. $this->data ['list'] = $list;
  4822. $this->data ['date'] = $date;
  4823. $this->data ['memu'] = "invoice";
  4824. $this->data ['staff'] = $this->staff;
  4825. $this->data ['receiptMemu'] = 'invoice';
  4826. $this->render ( "/admin/invoiceAchieve", $this->data );
  4827. }
  4828. /**
  4829. */
  4830. function invoiceMyUnAccountAchieve() {
  4831. Doo::loadModel ( 'invoice' );
  4832. $invoice = new invoice ();
  4833. Doo::loadClass ( 'XDeode' );
  4834. $XDeode = new XDeode ( 5 );
  4835. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4836. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4837. $page_size = 18;
  4838. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4839. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4840. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4841. $dateArr = explode ( ':', $date );
  4842. $D1 = '';
  4843. $D2 = '';
  4844. if (! empty ( $date )) {
  4845. $D1 = $dateArr [0];
  4846. $D2 = $dateArr [1];
  4847. }
  4848. $con = '';
  4849. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4850. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4851. if (! empty ( $MebSea )) {
  4852. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4853. }
  4854. $pageinfo ['page'] = array (
  4855. 'previous' => ''
  4856. );
  4857. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  4858. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  4859. $action = "invoiceMyUnAccountAchieve";
  4860. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4861. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4862. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 'desc', 'printTime' );
  4863. Doo::loadModel ( 'express' );
  4864. $express = new express ();
  4865. $expressList = $express->getExpressByAll ();
  4866. $this->data ['expressList'] = $expressList;
  4867. // print_r($list);
  4868. $this->data ['MebSeaEn'] = $MebSea;
  4869. $this->data ['get'] = $get;
  4870. $this->data ['page'] = $pageinfo;
  4871. $this->data ['date'] = $date;
  4872. $this->data ['list'] = $list;
  4873. $this->data ['memu'] = "invoice";
  4874. $this->data ['staff'] = $this->staff;
  4875. $this->data ['receiptMemu'] = 'invoice';
  4876. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  4877. }
  4878. function invoiceReceivablesAchieve() {
  4879. Doo::loadModel ( 'invoiceReceivables' );
  4880. $invoiceReceivables = new invoiceReceivables ();
  4881. Doo::loadClass ( 'XDeode' );
  4882. $XDeode = new XDeode ( 5 );
  4883. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  4884. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4885. $page_size = 12;
  4886. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4887. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4888. $get = "/" . $date;
  4889. $con = '';
  4890. if ($date == 'MONTHO')
  4891. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4892. elseif ($date == 'MONTHT')
  4893. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4894. elseif ($date == 'MONTHY')
  4895. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4896. if (! empty ( $MebSea )) {
  4897. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  4898. $get .= "/" . $MebSea;
  4899. }
  4900. $pageinfo ['page'] = array (
  4901. 'previous' => ''
  4902. );
  4903. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "-%' " . $con;
  4904. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  4905. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4906. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  4907. // print_r($pageinfo);
  4908. $this->data ['MebSeaEn'] = $MebSea;
  4909. $this->data ['MebSea'] = urlencode ( $MebSea );
  4910. $this->data ['get'] = $get;
  4911. $this->data ['page'] = $pageinfo;
  4912. $this->data ['list'] = $list;
  4913. $this->data ['date'] = $date;
  4914. $this->data ['memu'] = "invoice";
  4915. $this->data ['staff'] = $this->staff;
  4916. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  4917. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  4918. }
  4919. /**
  4920. * 收款解绑
  4921. */
  4922. function invoiceUnBundLing() {
  4923. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  4924. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  4925. Doo::loadModel ( 'invoice' );
  4926. $invoice = new invoice ();
  4927. Doo::loadModel ( 'invoiceReceivables' );
  4928. $invoiceReceivables = new invoiceReceivables ();
  4929. Doo::loadModel ( 'invoiceOperationLog' );
  4930. $invoiceOperationLog = new invoiceOperationLog ();
  4931. Doo::loadModel ( 'invoiceROLog' );
  4932. $invoiceROLog = new invoiceROLog ();
  4933. Doo::loadModel ( 'invoiceStatistics' );
  4934. Doo::loadClass ( 'XDeode' );
  4935. $XDeode = new XDeode ( 5 );
  4936. if (empty ( $iidKey ) || empty ( $unBundKey ))
  4937. die ( 'illegal request' );
  4938. $iid = $XDeode->decode ( $iidKey );
  4939. $irid = $invoice->authcode ( $unBundKey );
  4940. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4941. die ( 'illegal request' );
  4942. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4943. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4944. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4945. die ( 'illegal request' );
  4946. // 收款
  4947. $item = array (
  4948. 'irid' => $irDetails ['irid'],
  4949. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4950. 'bindStatus' => 0
  4951. );
  4952. if ($irDetails ['iid'] == $iid)
  4953. $item += array (
  4954. 'iid' => 0
  4955. );
  4956. else {
  4957. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4958. foreach ( $iidExtend as $key => $value ) {
  4959. if ($value == $iid)
  4960. unset ( $iidExtend [$key] );
  4961. }
  4962. $iidExtend = implode ( ',', $iidExtend );
  4963. $item += array (
  4964. 'iidExtend' => $iidExtend
  4965. );
  4966. }
  4967. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4968. // 收款操作日志
  4969. $item = array (
  4970. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4971. 'date' => date ( "Y-m-d" ),
  4972. 'status' => 3,
  4973. 'img' => $this->staff [0] ['avatar'],
  4974. 'username' => $this->staff [0] ['username'],
  4975. 'uid' => $this->staff [0] ['sid'],
  4976. 'category' => $this->staff [0] ['category'],
  4977. 'irid' => $irid
  4978. );
  4979. $invoiceROLog->setInvoiceROLog ( $item );
  4980. // 扣除入账统计金额
  4981. $invoiceStatistics = new invoiceStatistics ();
  4982. $item = array (
  4983. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4984. 'priceClass' => 3,
  4985. 'cid' => $invoiceDetails ['cid'],
  4986. 'staff' => $invoiceDetails ['sid'],
  4987. 'accountPrice' => - $invoiceDetails ['invoicePrice']
  4988. );
  4989. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4990. // 扣除收款统计金额
  4991. $invoiceStatistics = new invoiceStatistics ();
  4992. $item = array (
  4993. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4994. 'priceClass' => 2,
  4995. 'cid' => $invoiceDetails ['cid'],
  4996. 'staff' => $invoiceDetails ['sid'],
  4997. 'irid' => $irDetails ['irid'],
  4998. 'receivablesPrice' => - $invoiceDetails ['invoicePrice']
  4999. );
  5000. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5001. // 发票解绑去收款ID
  5002. $iridString = $invoiceDetails ['irid'];
  5003. if (! empty ( $invoiceDetails ['irid'] )) {
  5004. $list = explode ( ',', $invoiceDetails ['irid'] );
  5005. foreach ( $list as $key => $value ) {
  5006. if ($value == $irDetails ['irid']) {
  5007. unset ( $list [$key] );
  5008. break;
  5009. }
  5010. }
  5011. $iridString = implode ( ",", $list );
  5012. }
  5013. $item = array (
  5014. 'iid' => $invoiceDetails ['iid'],
  5015. 'irid' => $iridString,
  5016. 'updateTime' => date ( "Y-m-d H:i:s" )
  5017. );
  5018. if ($invoiceDetails ['untreadStatus'] == 3)
  5019. $item += array (
  5020. 'untreadStatus' => 0
  5021. );
  5022. $invoice->setInvoiceByCondition ( $item );
  5023. Doo::loadModel ( 'bill' );
  5024. $bill = new bill ();
  5025. $bill->iid=$invoiceDetails ['iid'];
  5026. $bill->trainId=$invoiceDetails['trainId'];
  5027. $bill->irid=$irDetails ['irid'];
  5028. $bill->create_time=date ( "Y-m-d H:i:s" );
  5029. $bill->price=-$invoiceDetails ['invoicePrice'];
  5030. $bill->remark='解绑-扣除入账';
  5031. $bill->insert ();
  5032. $item = array (
  5033. 'date' => date ( "Y-m-d H:i:s" ),
  5034. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  5035. 'status' => 11,
  5036. 'img' => $this->staff [0] ['avatar'],
  5037. 'username' => $this->staff [0] ['username'],
  5038. 'uid' => $this->staff [0] ['sid'],
  5039. 'category' => $this->staff [0] ['category'],
  5040. 'iid' => $invoiceDetails ['iid']
  5041. );
  5042. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  5043. // 公司流水-解绑时删除流水
  5044. // Doo::loadModel ( 'wasteBook' );
  5045. // $wasteBook = new wasteBook ();
  5046. // $wasteBook->delete ( array (
  5047. // 'where' => 'dataID=' . $irDetails ['irid'] . ' and accountType=7',
  5048. // 'limit' => 1
  5049. // ) );
  5050. // 银行
  5051. /*
  5052. * $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); }
  5053. */
  5054. return "/invoiceReceivablesAS";
  5055. }
  5056. /**
  5057. * 或者该收款下的所以发票
  5058. */
  5059. function ajaxGetInvoiceReceivablesByInvoice() {
  5060. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  5061. Doo::loadModel ( 'invoice' );
  5062. $invoice = new invoice ();
  5063. Doo::loadModel ( 'invoiceReceivables' );
  5064. $invoiceReceivables = new invoiceReceivables ();
  5065. $irid = $invoice->authcode ( $irid );
  5066. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  5067. die ( 'illegal request' );
  5068. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5069. $iidString = $irDetails ['iid'];
  5070. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  5071. if (! empty ( $irDetails ['iidExtend'] ))
  5072. $iidString .= ',' . implode ( ',', $iidExtend );
  5073. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  5074. $html = "";
  5075. foreach ( $invoiceList as $key => $value ) {
  5076. $title = $value ['invoiceTitle'];
  5077. if (! empty ( $value ['invoiceCompany'] ))
  5078. $title = $value ['invoiceCompany'];
  5079. $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>';
  5080. }
  5081. echo json_encode ( array (
  5082. 'status' => 1,
  5083. 'html' => $html
  5084. ) );
  5085. }
  5086. /**
  5087. * 发票管理
  5088. */
  5089. function invoiceAS() {
  5090. Doo::loadModel ( 'invoice' );
  5091. $invoice = new invoice ();
  5092. Doo::loadModel ( 'invoiceReceivables' );
  5093. $invoiceReceivables = new invoiceReceivables ();
  5094. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5095. $page_size = 18;
  5096. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5097. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5098. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5099. $dateArr = explode ( ':', $date );
  5100. $D1 = '';
  5101. $D2 = '';
  5102. if (! empty ( $date )) {
  5103. $D1 = $dateArr [0] . " 00:00:00 ";
  5104. if (isset ( $dateArr [1] ))
  5105. $D2 = $dateArr [1] . " 23:59:59 ";
  5106. else
  5107. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  5108. // $D2 = $dateArr [1];
  5109. }
  5110. $con = ' status=2 ';
  5111. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5112. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5113. if ($status == 'UNRECORD')
  5114. $con .= ' and printStatus=1 and untreadStatus=0';
  5115. elseif ($status == 'RECORD')
  5116. $con .= ' and printStatus=1 and untreadStatus=3';
  5117. elseif ($status == 'BOUNCED')
  5118. $con .= ' and untreadStatus=2';
  5119. elseif ($status == 'PARTRECORD')
  5120. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5121. elseif ($status == 'All') {
  5122. $con .= ' and ( untreadStatus=2 or untreadStatus=1 or untreadStatus=0 or untreadStatus=3 )';
  5123. }
  5124. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  5125. if (! empty ( $MebSea )) {
  5126. $con .= ' and ( invoiceSerial like "%' . $MebSea . '%" or invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoiceNo like "%' . $MebSea . '%" )';
  5127. }
  5128. $pageinfo ['page'] = array (
  5129. 'previous' => ''
  5130. );
  5131. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  5132. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5133. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  5134. $this->data ['MebSeaEn'] = $MebSea;
  5135. $this->data ['MebSea'] = urlencode ( $MebSea );
  5136. $this->data ['date'] = $date;
  5137. $this->data ['page'] = $pageinfo;
  5138. $this->data ['get'] = $get;
  5139. $this->data ['list'] = $list;
  5140. $this->data ['status'] = $status;
  5141. $this->data ['memu'] = "invoice";
  5142. $this->data ['staff'] = $this->staff;
  5143. $this->data ['receiptMemu'] = 'invoiceReceivables';
  5144. $this->render ( "/admin/invoiceAS", $this->data );
  5145. }
  5146. /**
  5147. * 收款管理
  5148. */
  5149. function invoiceReceivablesAS() {
  5150. Doo::loadModel ( 'invoiceReceivables' );
  5151. $invoiceReceivables = new invoiceReceivables ();
  5152. Doo::loadModel ( 'L_category' );
  5153. $lCategory = new L_category ();
  5154. $category = $lCategory->getCategory ();
  5155. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5156. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  5157. $page_size = 10;
  5158. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5159. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5160. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5161. $dateArr = explode ( ':', $date );
  5162. $D1 = '';
  5163. $D2 = '';
  5164. if (! empty ( $date )) {
  5165. $D1 = $dateArr [0]; // ." 00:00:00 ";
  5166. if (isset ( $dateArr [1] ))
  5167. $D2 = $dateArr [1]; // ." 23:59:59 ";
  5168. else
  5169. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  5170. }
  5171. $descField = 'a.receivablesDate';
  5172. if ($timeType == 'CREATE')
  5173. $descField = 'a.date';
  5174. $con = ' 1 ';
  5175. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5176. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5177. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5178. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  5179. if ($status == 'Unclaimed')
  5180. $con .= ' and a.bindStatus=0';
  5181. elseif ($status == 'Credited')
  5182. $con .= ' and a.bindStatus=1';
  5183. elseif ($status == 'Claim')
  5184. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  5185. elseif ($status == 'BBN')
  5186. $con .= ' and a.bankBatchNumber!=""';
  5187. elseif ($status == 'REFUND')
  5188. $con .= ' and ( (a.bindStatus=0 and a.refundLog!="" ) or a.bindStatus=2)';
  5189. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  5190. if (! empty ( $MebSea )) {
  5191. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" or a.receivablesSerial like "%' . $MebSea . '%" )';
  5192. }
  5193. $pageinfo ['page'] = array (
  5194. 'previous' => ''
  5195. );
  5196. // if(!empty($con)){
  5197. // $con=' where 1 '.$con;
  5198. // }
  5199. // $sql = 'select a.iid from CLD_invoiceReceivables as a
  5200. // ' . $con ;
  5201. $pageinfo =$this->get_page ( "CLD_invoiceReceivables as a", $con, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  5202. //echo $sql;
  5203. //$pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  5204. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5205. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  5206. foreach ( $list as $key => $value ) {
  5207. $list [$key] ['category'] = '';
  5208. if ($value ['receivablesCategory'] != 'PUBLIC') {
  5209. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  5210. $list [$key] ['category'] = $receivablesCategory [1];
  5211. }
  5212. }
  5213. // print_r($list);
  5214. $this->data ['category'] = $category;
  5215. $this->data ['timeType'] = $timeType;
  5216. $this->data ['MebSeaEn'] = $MebSea;
  5217. $this->data ['MebSea'] = urlencode ( $MebSea );
  5218. $this->data ['date'] = $date;
  5219. $this->data ['page'] = $pageinfo;
  5220. $this->data ['get'] = $get;
  5221. $this->data ['list'] = $list;
  5222. $this->data ['status'] = $status;
  5223. $this->data ['memu'] = "invoice";
  5224. $this->data ['staff'] = $this->staff;
  5225. $this->data ['receiptMemu'] = 'invoiceReceivables';
  5226. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  5227. }
  5228. /**
  5229. * 删除一条收款
  5230. */
  5231. function delInvoiceReceivables() {
  5232. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  5233. if (empty ( $iridKey ))
  5234. die ( 'illegal request' );
  5235. Doo::loadClass ( 'XDeode' );
  5236. $XDeode = new XDeode ( 5 );
  5237. $irid = $XDeode->decode ( $iridKey );
  5238. Doo::loadModel ( 'invoiceReceivables' );
  5239. $invoiceReceivables = new invoiceReceivables ();
  5240. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5241. if (empty ( $detail ))
  5242. die ( 'illegal request' );
  5243. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  5244. // 扣除收款汇总信息 汇总
  5245. Doo::loadModel ( 'invoiceStatistics' );
  5246. $invoiceStatistics = new invoiceStatistics ();
  5247. $item = array (
  5248. 'date' => $detail ['receivablesDate'],
  5249. 'priceClass' => 2,
  5250. 'irid' => $detail ['irid'],
  5251. 'receivablesPrice' => - $detail ['receivablesPrice']
  5252. );
  5253. if ($detail ['receivablesCategory'] != 'PUBLIC') {
  5254. $receivablesCategory = explode ( ":", $detail ['receivablesCategory'] );
  5255. $item += array (
  5256. 'cid' => $receivablesCategory [0]
  5257. );
  5258. }
  5259. if ($detail ['receivablesStaff'] != 'PUBLIC') {
  5260. $receivablesStaff = explode ( "-", $detail ['receivablesStaff'] );
  5261. $item += array (
  5262. 'staff' => $receivablesStaff [0]
  5263. );
  5264. }
  5265. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5266. return '/invoiceReceivablesAS';
  5267. }
  5268. /**
  5269. * 添加退款信息
  5270. */
  5271. function setInvoiceReceivablesRefund() {
  5272. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5273. $refundType = $this->get_args ( 'refundType' ) && is_numeric ( $this->get_args ( 'refundType' ) ) ? $this->get_args ( 'refundType' ) : '0';
  5274. $refundCompany = $this->get_args ( 'refundCompany' ) ? $this->get_args ( 'refundCompany' ) : "";
  5275. $refundNumber = $this->get_args ( 'refundNumber' ) ? $this->get_args ( 'refundNumber' ) : "";
  5276. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  5277. $refundRemarks = $this->get_args ( 'refundRemarks' ) ? $this->get_args ( 'refundRemarks' ) : "";
  5278. if ($refundPrice < 0)
  5279. die ( 'illegal request' );
  5280. if (! empty ( $iridKey ) && ! empty ( $refundCompany ) && ! empty ( $refundNumber ) && ! empty ( $refundPrice )) {
  5281. Doo::loadModel ( 'invoiceReceivables' );
  5282. $invoiceReceivables = new invoiceReceivables ();
  5283. Doo::loadModel ( 'invoiceRefund' );
  5284. $invoiceRefund = new invoiceRefund ();
  5285. $irid = $invoiceReceivables->authcode ( $iridKey );
  5286. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5287. if ($irDetail ['receivablesPrice'] < $refundPrice)
  5288. die ( 'illegal request' );
  5289. $invoiceReceivables = new invoiceReceivables ();
  5290. $refundLog = $this->staff [0] ['username'] . ' 退款 <b class="colRed">¥' . $refundPrice . '</b>
  5291. <br/><a href="#refunded" onclick="getRefundByDetail(\'' . $iridKey . '\')" data-toggle="modal">退款信息</a> <br/>' . date ( "Y-m-d H:i:s" ) . '
  5292. ';
  5293. $item = array (
  5294. 'irid' => $irid,
  5295. 'refundCompany' => $refundCompany,
  5296. 'refundNumber' => $refundNumber,
  5297. 'refundPrice' => $refundPrice,
  5298. 'refundRemarks' => $refundRemarks,
  5299. 'refundLog' => $refundLog
  5300. );
  5301. if ($refundType == 1) {
  5302. $item += array (
  5303. 'refundType' => $refundType,
  5304. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  5305. 'bindStatus' => 2
  5306. );
  5307. } elseif ($refundType == 0 && $irDetail ['receivablesPrice'] <= $refundPrice) {
  5308. $item += array (
  5309. 'refundType' => 1,
  5310. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice,
  5311. 'bindStatus' => 2
  5312. );
  5313. } else {
  5314. $item += array (
  5315. 'refundType' => $refundType,
  5316. 'receivablesPrice' => $irDetail ['receivablesPrice'] - $refundPrice
  5317. );
  5318. }
  5319. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5320. // 添加退款记录
  5321. $item = array (
  5322. 'irid' => $irid,
  5323. 'refundType' => $refundType,
  5324. 'refundCompany' => $refundCompany,
  5325. 'refundNumber' => $refundNumber,
  5326. 'refundPrice' => $refundPrice,
  5327. 'refundLog' => $refundLog,
  5328. 'refundRemarks' => $refundRemarks,
  5329. 'date' => date ( "Y-m-d H:i:s" )
  5330. );
  5331. $invoiceRefund->addInvoiceRefund ( $item );
  5332. // 扣除收款汇总信息 汇总
  5333. Doo::loadModel ( 'invoiceStatistics' );
  5334. $invoiceStatistics = new invoiceStatistics ();
  5335. $item = array (
  5336. 'date' => $irDetail ['receivablesDate'],
  5337. 'priceClass' => 2,
  5338. 'irid' => $irDetail ['irid'],
  5339. 'receivablesPrice' => - $refundPrice
  5340. );
  5341. if ($irDetail ['receivablesCategory'] != 'PUBLIC') {
  5342. $receivablesCategory = explode ( ":", $irDetail ['receivablesCategory'] );
  5343. $item += array (
  5344. 'cid' => $receivablesCategory [0]
  5345. );
  5346. }
  5347. if ($irDetail ['receivablesStaff'] != 'PUBLIC') {
  5348. $receivablesStaff = explode ( "-", $irDetail ['receivablesStaff'] );
  5349. $item += array (
  5350. 'staff' => $receivablesStaff [0]
  5351. );
  5352. }
  5353. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5354. // 公司日常支出流水
  5355. Doo::loadModel ( 'wasteBook' );
  5356. $wasteBook = new wasteBook ();
  5357. $accountBank = '';
  5358. if ($irDetail ['receivablesBank'] == '纵横广发') {
  5359. $accountBank = 'CGBDeposit';
  5360. } elseif ($irDetail ['receivablesBank'] == '纵横工行') {
  5361. $accountBank = 'ICBCDeposit';
  5362. } elseif ($irDetail ['receivablesBank'] == '华润银行') {
  5363. $accountBank = 'HUADeposit';
  5364. } elseif ($irDetail ['receivablesBank'] == '个人广发') {
  5365. $accountBank = 'PersonalDeposit';
  5366. }
  5367. $itemWaste = array (
  5368. 'accountPrice' => - $refundPrice,
  5369. 'expensesType' => 2,
  5370. 'accountType' => 11,
  5371. 'accountPriceShow' => $refundPrice,
  5372. 'dataID' => $irid,
  5373. 'accountBank' => $accountBank,
  5374. 'category' => $this->staff [0] ['category'],
  5375. 'cid' => $this->staff [0] ['cid'],
  5376. 'name' => $this->staff [0] ['username'],
  5377. 'sid' => $this->staff [0] ['sid'],
  5378. 'inputDate' => date ( "Y-m-d H:i:s" )
  5379. );
  5380. $wasteBook->setAccountBookStatistics ( $itemWaste );
  5381. return '/invoiceReceivablesAS';
  5382. }
  5383. die ( 'illegal request' );
  5384. }
  5385. function ajaxCheckInvoiceReceivablesRefund() {
  5386. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5387. $refundPrice = $this->get_args ( 'refundPrice' ) ? $this->get_args ( 'refundPrice' ) : "";
  5388. if ($refundPrice < 0) {
  5389. echo json_encode ( array (
  5390. 'error' => '金额不能为负'
  5391. ) );
  5392. die ();
  5393. }
  5394. if (! empty ( $refundPrice ) && ! empty ( $iridKey )) {
  5395. Doo::loadModel ( 'invoiceReceivables' );
  5396. $invoiceReceivables = new invoiceReceivables ();
  5397. $irid = $invoiceReceivables->authcode ( $iridKey );
  5398. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5399. if ($irDetail ['receivablesPrice'] < $refundPrice) {
  5400. echo json_encode ( array (
  5401. 'error' => '退款金额不能超过收款金额'
  5402. ) );
  5403. die ();
  5404. }
  5405. echo json_encode ( array (
  5406. 'ok' => '可以使用!'
  5407. ) );
  5408. die ();
  5409. }
  5410. }
  5411. /**
  5412. * 获得收款退款信息
  5413. */
  5414. function getRefundByDetail() {
  5415. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5416. Doo::loadModel ( 'invoiceReceivables' );
  5417. $invoiceReceivables = new invoiceReceivables ();
  5418. if (! empty ( $iridKey )) {
  5419. $irid = $invoiceReceivables->authcode ( $iridKey );
  5420. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5421. echo json_encode ( array (
  5422. 'status' => 1,
  5423. 'irDetail' => $irDetail
  5424. ) );
  5425. die ();
  5426. }
  5427. echo json_encode ( array (
  5428. 'status' => 2
  5429. ) );
  5430. }
  5431. /**
  5432. * 根据收款序列号获得收款退款信息
  5433. */
  5434. function ajaxGetInvoiceReceivablesBySerial() {
  5435. $receivablesSerial = $this->get_args ( 'receivablesSerial' ) ? $this->get_args ( 'receivablesSerial' ) : '';
  5436. if (! empty ( $receivablesSerial )) {
  5437. Doo::loadModel ( 'invoiceReceivables' );
  5438. $invoiceReceivables = new invoiceReceivables ();
  5439. // , ' and refundLog=""'
  5440. $irDetail = $invoiceReceivables->getInvoiceReceivablesBySerial ( $receivablesSerial );
  5441. $html = '';
  5442. if (! empty ( $irDetail ))
  5443. $html = '<td><b>¥' . $irDetail ['receivablesPrice'] . '</b></td>
  5444. <td>' . $irDetail ['receivablesMessage'] . '</td>
  5445. <td>' . $irDetail ['receivablesBank'] . '<br>' . $irDetail ['receivablesDate'] . '</td>
  5446. <td>' . $irDetail ['title'] . '-' . $irDetail ['username'] . '<br>' . $irDetail ['confirmTime'] . '</td>
  5447. <td>' . $irDetail ['recepitTitleMark'] . '
  5448. <input type="hidden" name="iridKey" id="iridKey" value="' . $irDetail ['iridKey'] . '">
  5449. </td>';
  5450. echo json_encode ( array (
  5451. 'status' => 1,
  5452. 'html' => $html,
  5453. 'irDetail' => $irDetail
  5454. ) );
  5455. die ();
  5456. }
  5457. echo json_encode ( array (
  5458. 'status' => 2
  5459. ) );
  5460. }
  5461. /**
  5462. * 绑定新收款
  5463. */
  5464. function relationNewInvoiceReceivables() {
  5465. $iridKeyOld = $this->get_args ( 'iridKeyOld' ) ? $this->get_args ( 'iridKeyOld' ) : '';
  5466. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : '';
  5467. if (! empty ( $iridKeyOld ) && ! empty ( $iridKey )) {
  5468. Doo::loadModel ( 'invoiceReceivables' );
  5469. $invoiceReceivables = new invoiceReceivables ();
  5470. Doo::loadClass ( 'XDeode' );
  5471. $XDeode = new XDeode ( 5 );
  5472. $irid = $XDeode->decode ( $iridKey );
  5473. $iridOld = $invoiceReceivables->authcode ( $iridKeyOld );
  5474. echo $irid . 'bbb' . $iridOld;
  5475. $oldIrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridOld );
  5476. $IrDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  5477. if (empty ( $oldIrDetail ) || empty ( $IrDetail ))
  5478. die ( 'illegal request' );
  5479. $relationLog = $this->staff [0] ['username'] . ' 关联新款 <a href="#billing" onclick="invoiceReceivblesDivShow(\'' . $iridKey . '\',\'receivables\')" data-toggle="modal">' . $IrDetail ['receivablesSerial'] . '</a>
  5480. <br/>' . date ( "Y-m-d H:i:s" ) . '
  5481. ';
  5482. $invoiceReceivables = new invoiceReceivables ();
  5483. $item = array (
  5484. 'irid' => $iridOld,
  5485. 'relationIrid' => $irid,
  5486. 'relationLog' => $relationLog
  5487. );
  5488. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  5489. return '/invoiceReceivablesAS';
  5490. }
  5491. die ( 'illegal request' );
  5492. }
  5493. // function invoiceApprovalAchieve() {
  5494. // Doo::loadModel ( 'invoice' );
  5495. // $invoice = new invoice ();
  5496. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5497. // $page_size = 12;
  5498. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5499. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5500. // $get = "/" . $date;
  5501. // $con = '';
  5502. // if ($date == 'MONTHO')
  5503. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5504. // elseif ($date == 'MONTHT')
  5505. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5506. // elseif ($date == 'MONTHY')
  5507. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5508. // if (! empty ( $MebSea )) {
  5509. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5510. // $get .= "/" . $MebSea;
  5511. // }
  5512. // $pageinfo ['page'] = array (
  5513. // 'previous' => ''
  5514. // );
  5515. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  5516. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  5517. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  5518. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5519. // // print_r($list);
  5520. // $this->data ['MebSeaEn'] = $MebSea;
  5521. // $this->data ['MebSea'] = urlencode ( $MebSea );
  5522. // $this->data ['get'] = $get;
  5523. // $this->data ['page'] = $pageinfo;
  5524. // $this->data ['list'] = $list;
  5525. // $this->data ['date'] = $date;
  5526. // $this->data ['memu'] = "invoice";
  5527. // $this->data ['staff'] = $this->staff;
  5528. // $this->data ['receiptMemu'] = 'invoiceApproval';
  5529. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5530. // }
  5531. /**
  5532. * 获得审批发票的信息以及审批页面
  5533. */
  5534. function ajaxGetInvoiceApprovalDetail() {
  5535. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5536. if (empty ( $serial )) {
  5537. echo json_encode ( array (
  5538. 'status' => 2,
  5539. 'msg' => 'illegal request'
  5540. ) );
  5541. die ();
  5542. }
  5543. Doo::loadModel ( 'invoice' );
  5544. $invoice = new invoice ();
  5545. Doo::loadModel ( 'invoiceOperationLog' );
  5546. $invoiceOperationLog = new invoiceOperationLog ();
  5547. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5548. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5549. if (empty ( $detail ))
  5550. $html = '';
  5551. else {
  5552. $html = '
  5553. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  5554. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  5555. <input type="hidden" name="status" value="">
  5556. <input type="hidden" name="divApproval" value="divApproval">
  5557. <div class="modal-dialog modal-lg">
  5558. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  5559. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5560. <tr>
  5561. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  5562. </tr>
  5563. <tr>
  5564. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5565. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5566. </tr>
  5567. <tr>
  5568. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5569. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5570. </tr>
  5571. <tr>
  5572. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5573. </td>
  5574. </tr>
  5575. <tr>
  5576. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5577. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5578. </tr>
  5579. <tr>
  5580. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5581. </tr></tbody></table>';
  5582. if ($detail ['invoiceType'] == 0)
  5583. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5584. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5585. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5586. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5587. </tr>';
  5588. else
  5589. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5590. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5591. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5592. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5593. ';
  5594. $html .= '<tr>
  5595. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5596. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5597. </tr>
  5598. <tr>
  5599. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5600. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5601. </tr></tbody></table>';
  5602. if ($detail ['doPost'] == 1) {
  5603. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5604. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5605. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5606. </tr><tr>
  5607. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5608. </tr><tr>
  5609. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5610. </tr>
  5611. ';
  5612. if ($detail ['expressCom'] == 'SF')
  5613. $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>';
  5614. else
  5615. $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>';
  5616. $html .= '</tbody></table>';
  5617. }
  5618. if (! empty ( $invoiceOperationLogList )) {
  5619. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5620. foreach ( $invoiceOperationLogList as $key => $value ) {
  5621. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5622. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5623. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5624. if ($value ['status'] == 2) {
  5625. $html .= '<span class="colGreen">同意</span>';
  5626. } elseif ($value ['status'] == 3) {
  5627. $html .= '<span class="colOrange">退回</span>';
  5628. } elseif ($value ['status'] == 5) {
  5629. $html .= '<span class="colGreen">打印</span>';
  5630. } elseif ($value ['status'] == 4) {
  5631. $html .= '<span class="colRed">终止</span>';
  5632. }
  5633. $html .= $value ['operation'] . '</p></blockquote>';
  5634. }
  5635. }
  5636. $html .= '</td></tr></tbody></table>';
  5637. }
  5638. $html .= '</div><div class="modal-footer">
  5639. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  5640. <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>
  5641. <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>
  5642. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  5643. </form>
  5644. <script type="text/javascript">
  5645. $("a[node-approval^=\'approval\']").click(function() {
  5646. $("input[name=\'status\']").val($(this).attr("diss-data"));
  5647. $("form[name=\'invoiceApproval\']").submit();
  5648. });
  5649. </script>
  5650. ';
  5651. }
  5652. echo json_encode ( array (
  5653. 'status' => 1,
  5654. 'html' => $html
  5655. ) );
  5656. die ();
  5657. }
  5658. /**
  5659. * 获得审批发票分页数据
  5660. */
  5661. function ajaxGetinvoiceApprovalAchieve() {
  5662. Doo::loadModel ( 'invoice' );
  5663. $invoice = new invoice ();
  5664. Doo::loadModel ( 'staff' );
  5665. $staff = new staff ();
  5666. Doo::loadClass ( 'XDeode' );
  5667. $XDeode = new XDeode ( 5 );
  5668. Doo::loadModel ( 'invoiceTraining' );
  5669. $invoiceTraining = new invoiceTraining ();
  5670. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  5671. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5672. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5673. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5674. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5675. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  5676. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  5677. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  5678. $MebSea = $this->get_args ( 'search' );
  5679. $MebSea = $MebSea ['value'];
  5680. $page_size = $length;
  5681. $con = '';
  5682. if ($status == 'ALL')
  5683. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  5684. elseif ($status == 'PEND')
  5685. $con = ' isDelete=0 and status=1';
  5686. elseif ($status == 'APPROVED')
  5687. $con = ' isDelete=0 and status=2';
  5688. if ($invoiceType == 'ORDINARY')
  5689. $con .= ' and invoiceType=0 ';
  5690. elseif ($invoiceType == 'SPECIAL')
  5691. $con .= ' and invoiceType=1 ';
  5692. if ($invoiceTrain == 'ORDINARY')
  5693. $con .= ' and trainId=0 ';
  5694. elseif ($invoiceTrain == 'TRAIN')
  5695. $con .= ' and trainId!=0 ';
  5696. if ($invoiceTrainName != 'ALL') {
  5697. $trainId = $XDeode->decode ( $invoiceTrainName );
  5698. if (is_numeric ( $trainId ))
  5699. $con .= ' and trainId =' . $trainId;
  5700. }
  5701. $dateArr = explode ( ':', $date );
  5702. $D1 = $dateString = '';
  5703. $D2 = '';
  5704. if (! empty ( $date )) {
  5705. $D1 = $dateArr [0];
  5706. if (isset ( $dateArr [1] ))
  5707. $D2 = $dateArr [1];
  5708. else
  5709. $D2 = '';
  5710. $dateString = $D1 . " : " . $D2;
  5711. }
  5712. if (! empty ( $D1 ) && ! empty ( $D2 ))
  5713. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  5714. elseif (! empty ( $D1 ) && empty ( $D2 ))
  5715. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  5716. if (! empty ( $MebSea ))
  5717. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  5718. // /
  5719. $pageinfo ['page'] = array (
  5720. 'previous' => ''
  5721. );
  5722. $sql = ' ' . $con;
  5723. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  5724. $limit = $page . ',' . $page_size;
  5725. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  5726. $approvalList = array ();
  5727. $html = '<script type="text/javascript">
  5728. </script>';
  5729. // 结算结束不能修改方式
  5730. Doo::loadModel ( 'receipt' );
  5731. $receipt = new receipt ();
  5732. foreach ( $list as $key => $value ) {
  5733. $irDetail = array ();
  5734. // 结算方式
  5735. $receiptDetail = array ();
  5736. if ($value ['trainId'] != 0) {
  5737. $receiptDetail = $receipt->getReceiptByinvoiceTrainId ( $value ['trainId'] );
  5738. }
  5739. if (! empty ( $receiptDetail )) {
  5740. if ($receiptDetail ['status'] == 8 || $receiptDetail ['status'] == 9) {
  5741. array_push ( $irDetail, '' );
  5742. } else {
  5743. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  5744. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  5745. } elseif ($value ['status'] == 2) {
  5746. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5747. } else
  5748. array_push ( $irDetail, '' );
  5749. }
  5750. } else {
  5751. if ($value ['status'] == 2) {
  5752. array_push ( $irDetail, '<a href="#editPay" class="fnSettlementType" data-iidKey="' . $value ['iidKeyK'] . '" data-toggle="modal">结算方式</a>' );
  5753. } else
  5754. array_push ( $irDetail, '' );
  5755. }
  5756. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  5757. if ($value ['invoiceType'] == 1)
  5758. array_push ( $irDetail, $value ['invoiceCompany'] );
  5759. else
  5760. array_push ( $irDetail, $value ['invoiceTitle'] );
  5761. array_push ( $irDetail, $value ['TIN'] );
  5762. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  5763. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  5764. array_push ( $irDetail, $value ['remark'] );
  5765. array_push ( $irDetail, $value ['invoiceElement'] );
  5766. array_push ( $irDetail, $value ['invoiceQuantity'] );
  5767. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  5768. if ($value ['invoiceType'] == 1) {
  5769. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  5770. } else {
  5771. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  5772. }
  5773. if ($value ['settlementType'] == 0) {
  5774. array_push ( $irDetail, '软件销售' );
  5775. } else {
  5776. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $value ['trainId'] );
  5777. array_push ( $irDetail, $itDetail ['trainName'] );
  5778. }
  5779. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  5780. array_push ( $irDetail, $value ['recipientsAddress'] );
  5781. array_push ( $irDetail, $value ['mailItems'] );
  5782. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  5783. $fchtml = $value ['OL'] ['operation'];
  5784. if (count ( $list ) == $page_size)
  5785. $fchtml = $value ['OL'] ['operation'] . $html;
  5786. // 最后的审批意见
  5787. array_push ( $irDetail, $fchtml );
  5788. if ($value ['status'] == 2)
  5789. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5790. elseif ($value ['status'] == 3)
  5791. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5792. elseif ($value ['status'] == 4)
  5793. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  5794. else
  5795. array_push ( $irDetail, '' );
  5796. array_push ( $approvalList, $irDetail );
  5797. }
  5798. // $approvalListJson = json_encode ( $approvalList );
  5799. $recordsFiltered = $pageinfo ['total_data'];
  5800. echo json_encode ( array (
  5801. "draw" => intval ( $draw ),
  5802. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  5803. "recordsFiltered" => intval ( $recordsFiltered ),
  5804. "data" => $approvalList
  5805. ), JSON_UNESCAPED_UNICODE );
  5806. }
  5807. /**
  5808. * 审批发票查看更多--重构
  5809. */
  5810. function invoiceApprovalAchieve() {
  5811. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  5812. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5813. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5814. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5815. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  5816. Doo::loadModel ( 'invoiceTraining' );
  5817. $invoiceTraining = new invoiceTraining ();
  5818. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5819. $this->data ['trainList'] = $trainList;
  5820. $this->data ['dateString'] = $date;
  5821. $this->data ['status'] = $status;
  5822. $this->data ['invoiceType'] = $invoiceType;
  5823. $this->data ['invoiceTrain'] = $invoiceTrain;
  5824. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5825. $this->data ['memu'] = "invoice";
  5826. $this->data ['staff'] = $this->staff;
  5827. $this->data ['receiptMemu'] = 'invoiceApproval';
  5828. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  5829. }
  5830. function invoiceTAchieve() {
  5831. Doo::loadModel ( 'invoice' );
  5832. $invoice = new invoice ();
  5833. Doo::loadClass ( 'XDeode' );
  5834. $XDeode = new XDeode ( 5 );
  5835. Doo::loadModel ( 'staff' );
  5836. $staff = new staff ();
  5837. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  5838. $page_size = 12;
  5839. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5840. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  5841. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  5842. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  5843. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  5844. Doo::loadModel ( 'invoiceTraining' );
  5845. $invoiceTraining = new invoiceTraining ();
  5846. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  5847. $get = "/" . $date;
  5848. $con = '';
  5849. if ($date == 'MONTHO')
  5850. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  5851. elseif ($date == 'MONTHT')
  5852. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  5853. elseif ($date == 'MONTHY')
  5854. $con = ' and YEAR(updateTime) = YEAR(NOW())'; // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  5855. if ($invoiceType == 'ORDINARY')
  5856. $con .= ' and invoiceType=0 ';
  5857. elseif ($invoiceType == 'SPECIAL')
  5858. $con .= ' and invoiceType=1 ';
  5859. if ($invoiceTrain == 'ORDINARY')
  5860. $con .= ' and trainId=0 ';
  5861. elseif ($invoiceTrain == 'TRAIN')
  5862. $con .= ' and trainId!=0 ';
  5863. if ($invoiceTrainName != 'ALL') {
  5864. $trainId = $XDeode->decode ( $invoiceTrainName );
  5865. if (is_numeric ( $trainId ))
  5866. $con .= ' and trainId =' . $trainId;
  5867. }
  5868. if (! empty ( $MebSea )) {
  5869. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  5870. $get .= "/" . $MebSea;
  5871. }
  5872. $pageinfo ['page'] = array (
  5873. 'previous' => ''
  5874. );
  5875. $sql = "";
  5876. $action = "";
  5877. if ($this->ACTION == 'invoicePrintAchieve') {
  5878. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  5879. $action = "invoicePrintAchieve";
  5880. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5881. // and untreadStatus=0
  5882. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  5883. $action = "invoicePostAchieve";
  5884. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  5885. $sql = " untreadStatus=2 and status=2 " . $con;
  5886. $action = "invoiceUntreadAchieve";
  5887. }
  5888. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  5889. $limit = $pageinfo ['lower'] . ',' . $page_size;
  5890. $this->data ['MebSeaEn'] = $MebSea;
  5891. $this->data ['MebSea'] = urlencode ( $MebSea );
  5892. $this->data ['get'] = $get;
  5893. $this->data ['page'] = $pageinfo;
  5894. $this->data ['trainList'] = $trainList;
  5895. $this->data ['invoiceType'] = $invoiceType;
  5896. $this->data ['invoiceTrain'] = $invoiceTrain;
  5897. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  5898. $this->data ['date'] = $date;
  5899. $this->data ['memu'] = "invoice";
  5900. $this->data ['staff'] = $this->staff;
  5901. if ($this->ACTION == 'invoicePrintAchieve') {
  5902. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  5903. $this->data ['receiptMemu'] = 'invoicePrint';
  5904. $this->data ['list'] = $list;
  5905. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  5906. } elseif ($this->ACTION == 'invoicePostAchieve') {
  5907. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  5908. Doo::loadModel ( 'express' );
  5909. $express = new express ();
  5910. $expressList = $express->getExpressByAll ();
  5911. $this->data ['expressList'] = $expressList;
  5912. $this->data ['receiptMemu'] = 'invoicePost';
  5913. $this->data ['list'] = $list;
  5914. $this->render ( "/admin/invoicePostAchieve", $this->data );
  5915. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  5916. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql,'desc','desc','untreadTime' );
  5917. $this->data ['receiptMemu'] = 'invoiceUntread';
  5918. $this->data ['list'] = $list;
  5919. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  5920. }
  5921. }
  5922. /**
  5923. * 公司应收款
  5924. */
  5925. function invoiceAggregateCompanyDetail() {
  5926. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  5927. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  5928. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : 'ALL';
  5929. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  5930. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  5931. $titleORno = $this->get_args ( 'titleORno' ) ? $this->get_args ( 'titleORno' ) : "";
  5932. Doo::loadClass ( 'XDeode' );
  5933. $XDeode = new XDeode ( 5 );
  5934. Doo::loadModel ( 'invoice' );
  5935. $invoice = new invoice ();
  5936. Doo::loadModel ( 'staff' );
  5937. $staff = new staff ();
  5938. Doo::loadModel ( "invoiceCompanyManage" );
  5939. $invoiceCompanyManage = new invoiceCompanyManage ();
  5940. Doo::loadModel ( 'L_category' );
  5941. $category = new L_category ();
  5942. $sid = '';
  5943. if (! empty ( $sidKey )) {
  5944. $sid = $XDeode->decode ( $sidKey );
  5945. }
  5946. $staffDetail = $staff->getStaffBySid ( $sid );
  5947. $cid = '';
  5948. if (! empty ( $cidKey )) {
  5949. $cid = $XDeode->decode ( $cidKey );
  5950. }
  5951. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  5952. $cidList = array ();
  5953. foreach ( $imcStaff as $key => $value ) {
  5954. array_push ( $cidList, $value ['cid'] );
  5955. }
  5956. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  5957. $cidString = implode ( ',', $cidList );
  5958. if (empty ( $cid ))
  5959. $staffList = $staff->getStaffInCid ( $cidString );
  5960. else
  5961. $staffList = $staff->getStaffByCidAll ( $cid ); //
  5962. //$MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  5963. $page_size = 25;
  5964. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  5965. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  5966. $con = ' status=2 and untreadStatus!=2 and invalid=0 and isDelete=0 and badDebt=0 ';
  5967. $statisticsCon = '';
  5968. if (! empty ( $year ) && is_numeric ( $year ))
  5969. $con .= ' and Year(printTime)=' . $year . '';
  5970. if (! empty ( $month ) && is_numeric ( $month ))
  5971. $con .= ' and Month(printTime)="' . $month . '" ';
  5972. if ($status == 'UNRECORD')
  5973. $con .= ' and printStatus=1 and untreadStatus=0';
  5974. elseif ($status == 'RECORD')
  5975. $con .= ' and printStatus=1 and untreadStatus=3';
  5976. elseif ($status == 'BOUNCED')
  5977. $con .= ' and untreadStatus=2';
  5978. elseif ($status == 'PARTRECORD')
  5979. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  5980. elseif ($status == 'All') {
  5981. $con .= ' and printStatus=1 and ( untreadStatus=0 or untreadStatus=3 )';
  5982. }
  5983. if (! empty ( $sid ) && is_numeric ( $sid ))
  5984. $con .= ' and sid=' . $sid;
  5985. if (! empty ( $cid ) && is_numeric ( $cid ))
  5986. $con .= ' and cid=' . $cid;
  5987. else
  5988. $con .= ' and cid in (' . $cidString . ')';
  5989. // 开票内容筛选
  5990. if (! empty ( $invoiceElement ) && $invoiceElement != 'ALL') {
  5991. $con .= ' and invoiceElement="' . $invoiceElement . '"';
  5992. }
  5993. $get = "/" . $status . "?cidKey=" . $cidKey . "&sidKey=" . $sidKey . "&year=" . $year . "&month=" . $month
  5994. . "&invoiceElement=" . $invoiceElement."&titleORno=".urlencode ( $titleORno );
  5995. if (! empty ( $titleORno )) {
  5996. $con .= ' and ( invoiceTitle like "%' . $titleORno . '%" or invoiceCompany like "%' . $titleORno . '%" or invoiceNo like "%'.$titleORno.'%" )';
  5997. }
  5998. $pageinfo ['page'] = array (
  5999. 'previous' => ''
  6000. );
  6001. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  6002. $limit = $pageinfo ['lower'] . ',' . $page_size;
  6003. // 应收款合计
  6004. $ics = $invoice->getInvoiceCompanyStatistics ( $con );
  6005. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  6006. $monthHtml = "";
  6007. if ($year != "ALL") {
  6008. for($i = 1; $i <= 12; $i ++) {
  6009. if ($i == $month)
  6010. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  6011. else
  6012. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  6013. }
  6014. }
  6015. $this->data ['monthHtml'] = $monthHtml;
  6016. $this->data ['year'] = $year;
  6017. $this->data ['month'] = $month;
  6018. $this->data ['ics'] = $ics;
  6019. $this->data ['cidKey'] = $cidKey;
  6020. $this->data ['sid'] = $sid;
  6021. $this->data ['staffDetail'] = $staffDetail;
  6022. $this->data ['staffList'] = $staffList;
  6023. $this->data ['titleORnoEn'] = $titleORno;
  6024. $this->data ['titleORno'] = urlencode ( $titleORno );
  6025. $this->data ['invoiceDetail'] = array (
  6026. 'invoiceElement' => $invoiceElement
  6027. );
  6028. $this->data ['page'] = $pageinfo;
  6029. $this->data ['get'] = $get;
  6030. $this->data ['list'] = $list;
  6031. $this->data ['status'] = $status;
  6032. $this->data ['categoryList'] = $categoryList;
  6033. $this->data ['memu'] = "invoice";
  6034. $this->data ['staff'] = $this->staff;
  6035. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  6036. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  6037. }
  6038. /**
  6039. * 获取一条收款信息
  6040. */
  6041. function ajaxGetInvoiceReceivables() {
  6042. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  6043. Doo::loadModel ( 'invoiceReceivables' );
  6044. $invoiceReceivables = new invoiceReceivables ();
  6045. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  6046. echo json_encode ( array (
  6047. 'status' => 1,
  6048. 'detail' => $detail
  6049. ) );
  6050. }
  6051. /**
  6052. * 异步获取办事处用户
  6053. */
  6054. function ajaxGetStaffByCategory() {
  6055. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  6056. Doo::loadModel ( 'staff' );
  6057. $staff = new staff ();
  6058. if ($cid == "PUBLIC") {
  6059. echo json_encode ( array (
  6060. 'status' => 1,
  6061. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  6062. ) );
  6063. die ();
  6064. }
  6065. if (! is_numeric ( $cid )) {
  6066. echo json_encode ( array (
  6067. 'status' => 0,
  6068. 'msg' => 'illegal request'
  6069. ) );
  6070. die ();
  6071. }
  6072. $staffList = $staff->getStaffByCid ( $cid );
  6073. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  6074. foreach ( $staffList as $key => $value ) {
  6075. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6076. }
  6077. echo json_encode ( array (
  6078. 'status' => 1,
  6079. 'html' => $html
  6080. ) );
  6081. }
  6082. /**
  6083. * 异步获取一条发票的邮寄信息
  6084. */
  6085. function ajaxGetInvoicePostDetail() {
  6086. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6087. Doo::loadModel ( 'invoice' );
  6088. $invoice = new invoice ();
  6089. $iid = $invoice->authcode ( $iid );
  6090. Doo::loadModel ( 'express' );
  6091. $express = new express ();
  6092. $expressList = $express->getExpressByAll ();
  6093. if (! is_numeric ( $iid )) {
  6094. echo json_encode ( array (
  6095. 'status' => 0,
  6096. 'msg' => 'illegal request'
  6097. ) );
  6098. die ();
  6099. }
  6100. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  6101. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  6102. $html = "";
  6103. foreach ( $expressList as $key => $value ) {
  6104. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  6105. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  6106. else
  6107. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  6108. }
  6109. $invoiceDetail ['eaHtml'] = $html;
  6110. echo json_encode ( array (
  6111. 'status' => 1,
  6112. 'invoiceDetail' => $invoiceDetail
  6113. ) );
  6114. }
  6115. /**
  6116. *
  6117. * @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 ) ); }
  6118. */
  6119. /**
  6120. *
  6121. * @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 ) ); }
  6122. */
  6123. /**
  6124. * 我的收款中 选择哪个发票入账,进行金额判断
  6125. */
  6126. function ajaxCompareInvoicePrice() {
  6127. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  6128. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  6129. Doo::loadModel ( 'invoice' );
  6130. $invoice = new invoice ();
  6131. Doo::loadModel ( 'invoiceReceivables' );
  6132. $invoiceReceivables = new invoiceReceivables ();
  6133. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  6134. $keyList = explode ( ';', $claimKey );
  6135. $receivablesPrice = 0;
  6136. foreach ( $keyList as $key => $value ) {
  6137. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  6138. $receivablesPrice += $detailM ['receivablesPrice'];
  6139. }
  6140. if ($receivablesPrice > $detail ['invoicePrice']) {
  6141. $price = $receivablesPrice - $detail ['invoicePrice'];
  6142. echo json_encode ( array (
  6143. 'status' => 1,
  6144. 'price' => $price
  6145. ) );
  6146. } else
  6147. echo json_encode ( array (
  6148. 'status' => 2
  6149. ) );
  6150. }
  6151. /**
  6152. * 获得打印发票
  6153. */
  6154. function ajaxGetInvoiceInfoByPrint() {
  6155. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  6156. if (empty ( $serial )) {
  6157. echo json_encode ( array (
  6158. 'status' => 2,
  6159. 'msg' => 'illegal request'
  6160. ) );
  6161. die ();
  6162. }
  6163. Doo::loadModel ( 'invoice' );
  6164. $invoice = new invoice ();
  6165. Doo::loadModel ( 'invoiceOperationLog' );
  6166. $invoiceOperationLog = new invoiceOperationLog ();
  6167. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6168. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6169. Doo::loadModel ( 'invoicePaper' );
  6170. $invoicePaper = new invoicePaper ();
  6171. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  6172. if (empty ( $detail ))
  6173. $html = '';
  6174. else {
  6175. $html = '
  6176. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  6177. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  6178. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  6179. <div class="modal-dialog modal-lg">
  6180. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  6181. <div class="modal-body saeaList">
  6182. <table class="table table-bordered table-condensed"><tbody>
  6183. <tr>
  6184. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6185. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6186. </tr>
  6187. <tr>
  6188. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6189. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6190. </tr>
  6191. <tr>
  6192. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  6193. </td>
  6194. </tr>
  6195. <tr>
  6196. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6197. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6198. </tr>
  6199. <tr>
  6200. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6201. </tr></tbody></table>';
  6202. if ($detail ['invoiceType'] == 0)
  6203. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6204. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6205. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6206. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6207. </tr>';
  6208. else
  6209. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6210. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6211. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6212. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6213. ';
  6214. $html .= '<tr>
  6215. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6216. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6217. </tr>
  6218. <tr>
  6219. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  6220. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  6221. </tr></tbody></table>';
  6222. if ($detail ['doPost'] == 1)
  6223. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6224. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6225. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6226. </tr><tr>
  6227. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6228. </tr><tr>
  6229. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6230. </tr></tbody></table>';
  6231. if (! empty ( $invoiceOperationLogList )) {
  6232. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  6233. foreach ( $invoiceOperationLogList as $key => $value ) {
  6234. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6235. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6236. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6237. if ($value ['status'] == 2) {
  6238. $html .= '<span class="colGreen">同意</span>';
  6239. } elseif ($value ['status'] == 3) {
  6240. $html .= '<span class="colOrange">退回</span>';
  6241. } elseif ($value ['status'] == 5) {
  6242. $html .= '<span class="colGreen">打印</span>';
  6243. } elseif ($value ['status'] == 4) {
  6244. $html .= '<span class="colRed">终止</span>';
  6245. }
  6246. $html .= $value ['operation'] . '</p></blockquote>';
  6247. }
  6248. }
  6249. $html .= '</td>
  6250. <td><span class="colRed">*</span>
  6251. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  6252. foreach ( $invoicePaperList as $key => $value ) {
  6253. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  6254. }
  6255. $html .= '</select>
  6256. <span class="red" id="p-msg"></span>
  6257. </td>
  6258. </tr></tbody></table>';
  6259. }
  6260. $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>
  6261. </div></div></form>
  6262. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  6263. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  6264. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  6265. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  6266. ';
  6267. }
  6268. echo json_encode ( array (
  6269. 'status' => 1,
  6270. 'html' => $html
  6271. ) );
  6272. die ();
  6273. }
  6274. /**
  6275. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  6276. */
  6277. function ajaxGetInvoiceInfoByType() {
  6278. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  6279. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  6280. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  6281. if (empty ( $serial )) {
  6282. echo json_encode ( array (
  6283. 'status' => 2,
  6284. 'msg' => 'illegal request'
  6285. ) );
  6286. die ();
  6287. }
  6288. if ($type == 'INVOICE') {
  6289. Doo::loadModel ( 'invoice' );
  6290. $invoice = new invoice ();
  6291. Doo::loadModel ( 'invoiceOperationLog' );
  6292. $invoiceOperationLog = new invoiceOperationLog ();
  6293. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6294. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6295. if (empty ( $detail ))
  6296. $html = '';
  6297. else {
  6298. $html = '
  6299. <div class="modal-dialog modal-lg">
  6300. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  6301. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  6302. <tr>
  6303. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6304. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6305. </tr>
  6306. <tr>
  6307. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6308. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6309. </tr>
  6310. <tr>
  6311. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  6312. </td>
  6313. </tr>
  6314. <tr>
  6315. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6316. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6317. </tr>
  6318. <tr>
  6319. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6320. </tr>';
  6321. if ($detail ['settlementType'] == 1)
  6322. $html .= '<tr>
  6323. <th class="taC" width="150">结算方式</th><td colspan="3">培训班(<a href="/invoiceTrainingDetail/' . $detail ['invoiceTraining'] ['trainingKey'] . '.html" target="_blank">' . $detail ['invoiceTraining'] ['trainName'] . '</a>)</td>
  6324. </tr>';
  6325. else
  6326. $html .= '<tr>
  6327. <th class="taC" width="150">结算方式</th><td colspan="3">软件销售</td>
  6328. </tr>';
  6329. $html .= ' </tbody></table>';
  6330. if ($detail ['invoiceType'] == 0){
  6331. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6332. <tr><th colspan="4" class="taC">增值税普通发票';
  6333. if($detail ['invoiceForm']==1){
  6334. $html .= '( <span class="colRed">电子发票</span> )';
  6335. }
  6336. $html .= '</th></tr><tr>
  6337. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6338. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6339. </tr>';
  6340. }else{
  6341. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6342. <tr><th colspan="4" class="taC">增值税专用发票';
  6343. if($detail ['invoiceForm']==1){
  6344. $html .= '( <span class="colRed">电子发票</span> )';
  6345. }
  6346. $html .= '</th></tr><tr>
  6347. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6348. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6349. ';
  6350. }
  6351. $html .= '<tr>
  6352. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6353. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6354. </tr>
  6355. <tr>
  6356. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  6357. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  6358. </tr></tbody></table>';
  6359. if ($detail ['doPost'] == 1) {
  6360. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6361. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6362. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6363. </tr><tr>
  6364. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6365. </tr><tr>
  6366. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6367. </tr>
  6368. ';
  6369. if ($detail ['expressCom'] == 'SF')
  6370. $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>';
  6371. else
  6372. $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>';
  6373. $html .= '</tbody></table>';
  6374. }
  6375. if ($detail ['invoiceForm'] == 1) {
  6376. $html .= '<table class="table table-bordered table-condensed">
  6377. <tbody><tr><th colspan="4" class="taC">电子发票发送方式</th></tr>
  6378. <tr>
  6379. <th class="taC" width="150">收件人手机</th><td>'.$detail ['electronicPhone'].'</td>
  6380. <th class="taC" width="150">收件人邮箱</th><td>'.$detail ['electronicEmail'].'</td>
  6381. </tr></tbody></table>';
  6382. }
  6383. if (! empty ( $invoiceOperationLogList )) {
  6384. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6385. foreach ( $invoiceOperationLogList as $key => $value ) {
  6386. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6387. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6388. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6389. if ($value ['status'] == 2) {
  6390. $html .= '<span class="colGreen">同意</span>';
  6391. } elseif ($value ['status'] == 3) {
  6392. $html .= '<span class="colOrange">退回</span>';
  6393. } elseif ($value ['status'] == 5) {
  6394. $html .= '<span class="colGreen">打印</span>';
  6395. } elseif ($value ['status'] == 4) {
  6396. $html .= '<span class="colRed">终止</span>';
  6397. }
  6398. $html .= $value ['operation'] . '</p></blockquote>';
  6399. }
  6400. }
  6401. $html .= '</td></tr></tbody></table>';
  6402. }
  6403. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6404. }
  6405. echo json_encode ( array (
  6406. 'status' => 1,
  6407. 'html' => $html
  6408. ) );
  6409. die ();
  6410. } elseif ($type == 'RECEIVABLES') {
  6411. Doo::loadModel ( 'invoiceReceivables' );
  6412. $invoiceReceivables = new invoiceReceivables ();
  6413. Doo::loadModel ( 'invoiceRefund' );
  6414. $invoiceRefund = new invoiceRefund ();
  6415. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  6416. $ireList = $invoiceRefund->getInvoiceRefundIrid ( $detail ['irid'] );
  6417. if (empty ( $detail ))
  6418. $html = '';
  6419. else {
  6420. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList">
  6421. <table class="table table-bordered table-condensed">
  6422. <tbody><tr>
  6423. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  6424. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  6425. </tr><tr>
  6426. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6427. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  6428. </tr>
  6429. <tr>
  6430. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  6431. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  6432. </tr>
  6433. <tr>
  6434. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  6435. </tr>
  6436. </tbody></table>';
  6437. if (! empty ( $ireList )) {
  6438. $html .= '
  6439. <table class="table table-bordered table-condensed"><tbody><tr><th class="taC" colspan="5">退款记录</th></tr>
  6440. <tr>
  6441. <th class="taC">退款单位名称</th>
  6442. <th class="taC">退款的账号</th>
  6443. <th class="taC">退款金额</th>
  6444. <th class="taC">退款</th>
  6445. <th class="taC">备注</th>
  6446. </tr>
  6447. ';
  6448. foreach ( $ireList as $key => $value ) {
  6449. $refundLogList = explode ( "<br/>", $value ['refundLog'] );
  6450. $html .= '<tr>
  6451. <td>' . $value ['refundCompany'] . '</td>
  6452. <td>' . $value ['refundNumber'] . '</td>
  6453. <td><b class="colRed">¥' . $value ['refundPrice'] . '</b></td>
  6454. <td>' . $refundLogList [0] . $refundLogList [2] . '</td>
  6455. <td>' . $value ['refundRemarks'] . '</td>
  6456. </tr>
  6457. ';
  6458. }
  6459. }
  6460. $html .= '</tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  6461. }
  6462. echo json_encode ( array (
  6463. 'status' => 1,
  6464. 'html' => $html
  6465. ) );
  6466. die ();
  6467. } elseif ($type == 'IRTC') {
  6468. Doo::loadModel ( 'invoice' );
  6469. $invoice = new invoice ();
  6470. Doo::loadModel ( 'invoiceOperationLog' );
  6471. $invoiceOperationLog = new invoiceOperationLog ();
  6472. // Doo::loadModel ( 'invoiceReceivables' );
  6473. // $invoiceReceivables = new invoiceReceivables ();
  6474. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  6475. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  6476. if (empty ( $detail ))
  6477. $html = '';
  6478. else {
  6479. $receivablesPriceedHtml = '';
  6480. $receivablesPrice = $detail ['invoicePrice'];
  6481. if (! empty ( $detail ['irid'] )) {
  6482. // $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  6483. // if (empty ( $irList ))
  6484. // $irList [0] ['sumPrice'] = 0;
  6485. // $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  6486. $enteredPrice=$detail ['invoicePrice']-$detail ['invoiceBalance'];
  6487. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  6488. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $enteredPrice . '</b></td>
  6489. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $detail ['invoiceBalance'] . '</b></td>
  6490. </tr></tbody></table>';
  6491. $receivablesPrice = $detail ['invoiceBalance'];
  6492. }
  6493. if ($loss)
  6494. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  6495. $html = $receivablesPriceedHtml . '
  6496. <table class="table table-bordered table-condensed"><tbody>
  6497. <tr>
  6498. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  6499. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  6500. </tr>
  6501. <tr>
  6502. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  6503. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  6504. </tr>
  6505. <tr>
  6506. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  6507. </tr>
  6508. <tr>
  6509. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  6510. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  6511. </tr>
  6512. <tr>
  6513. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  6514. </tr></tbody></table>';
  6515. if ($detail ['invoiceType'] == 0) {
  6516. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6517. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  6518. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  6519. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  6520. </tr>';
  6521. $receivablesMessage = $detail ['invoiceTitle'];
  6522. } else {
  6523. $html .= '<table class="table table-bordered table-condensed"><tbody>
  6524. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  6525. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  6526. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  6527. ';
  6528. $receivablesMessage = $detail ['invoiceCompany'];
  6529. }
  6530. $html .= '<tr>
  6531. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  6532. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  6533. </tr>
  6534. <tr>
  6535. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  6536. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  6537. </tr></tbody></table>';
  6538. if ($detail ['doPost'] == 1)
  6539. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  6540. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  6541. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  6542. </tr><tr>
  6543. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  6544. </tr><tr>
  6545. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  6546. </tr></tbody></table>';
  6547. if (! empty ( $invoiceOperationLogList )) {
  6548. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  6549. foreach ( $invoiceOperationLogList as $key => $value ) {
  6550. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  6551. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  6552. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  6553. if ($value ['status'] == 2) {
  6554. $html .= '<span class="colGreen">同意</span>';
  6555. } elseif ($value ['status'] == 3) {
  6556. $html .= '<span class="colOrange">退回</span>';
  6557. } elseif ($value ['status'] == 5) {
  6558. $html .= '<span class="colGreen">打印</span>';
  6559. }
  6560. $html .= $value ['operation'] . '</p></blockquote>';
  6561. }
  6562. }
  6563. $html .= '</td></tr></tbody></table>';
  6564. }
  6565. }
  6566. echo json_encode ( array (
  6567. 'status' => 1,
  6568. 'html' => $html,
  6569. 'receivablesPrice' => $receivablesPrice,
  6570. 'receivablesMessage' => $receivablesMessage,
  6571. 'receivablesDate' => date ( "Y-m-d" ),
  6572. 'iidKey' => $serial
  6573. ) );
  6574. die ();
  6575. }
  6576. }
  6577. function ajaxGetInvoiceReceivablesByStaff() {
  6578. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  6579. if (empty ( $postData )) {
  6580. echo json_encode ( array (
  6581. 'status' => 2,
  6582. 'msg' => 'illegal request'
  6583. ) );
  6584. die ();
  6585. }
  6586. Doo::loadModel ( 'invoiceReceivables' );
  6587. $invoiceReceivables = new invoiceReceivables ();
  6588. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  6589. if (empty ( $detail )) {
  6590. echo json_encode ( array (
  6591. 'status' => 2,
  6592. 'msg' => 'illegal request'
  6593. ) );
  6594. die ();
  6595. }
  6596. Doo::loadModel ( 'L_category' );
  6597. $lCategory = new L_category ();
  6598. Doo::loadModel ( 'staff' );
  6599. $staff = new staff ();
  6600. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  6601. $category = $lCategory->getCategory ();
  6602. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  6603. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  6604. foreach ( $category as $key => $value ) {
  6605. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6606. if ($value ['cid'] == $detail ['cid'])
  6607. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  6608. }
  6609. foreach ( $staffList as $key => $value ) {
  6610. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6611. if ($value ['sid'] == $detail ['sid'])
  6612. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  6613. }
  6614. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  6615. echo json_encode ( array (
  6616. 'status' => 1,
  6617. 'categoryHtml' => $categoryHtml,
  6618. 'staffHtml' => $staffHtml,
  6619. 'rbankHtml' => $rbankHtml,
  6620. 'detail' => $detail
  6621. ) );
  6622. }
  6623. function ajaxGetInvoiceReceivablesByIrid() {
  6624. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  6625. if (empty ( $irid )) {
  6626. echo json_encode ( array (
  6627. 'status' => 2,
  6628. 'msg' => 'illegal request'
  6629. ) );
  6630. die ();
  6631. }
  6632. Doo::loadModel ( 'invoiceReceivables' );
  6633. $invoiceReceivables = new invoiceReceivables ();
  6634. Doo::loadModel ( 'invoice' );
  6635. $invoice = new invoice ();
  6636. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  6637. $flag = true;
  6638. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  6639. $bakDetail = array ();
  6640. if ($flag === false) {
  6641. array_push ( $bakDetail, $invoiceDetail );
  6642. $invoiceDetail = $bakDetail;
  6643. }
  6644. $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>
  6645. <tr>
  6646. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  6647. <td>' . $detail ['receivablesMessage'] . '</td>
  6648. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  6649. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  6650. <td>' . $detail ['recepitTitleMark'] . '</td>
  6651. </tr></tbody></table>';
  6652. $isInvoice = false;
  6653. $invoiceHtml = '';
  6654. if (empty ( $invoiceDetail )) {
  6655. $isInvoice = true;
  6656. } else {
  6657. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6658. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  6659. foreach ( $invoiceDetail as $key => $value ) {
  6660. $invoiceHtml .= '<tr>';
  6661. if (! empty ( $value ['invoiceType'] )) {
  6662. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6663. } else {
  6664. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6665. }
  6666. if (! empty ( $value ['invoiceType'] )) {
  6667. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6668. } else {
  6669. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6670. }
  6671. $invoiceHtml .= '
  6672. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6673. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6674. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  6675. </tr>
  6676. ';
  6677. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  6678. if (empty ( $irList ))
  6679. $irList [0] ['sumPrice'] = 0;
  6680. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  6681. $priceString = '';
  6682. if ($balance < $detail ['receivablesPrice']) {
  6683. $priceString = '收款金额超过开票金额,';
  6684. }
  6685. if ($balance > $detail ['receivablesPrice']) {
  6686. $priceString = '收款金额低于开票金额,';
  6687. }
  6688. }
  6689. $invoiceHtml .= '
  6690. <script>
  6691. $(\'a[bind-receivables^="ir"]\').click(function() {
  6692. var data = $(this).attr("data-ikey");
  6693. $("input[name=\'invoiceKey\']").val(data);
  6694. var invoiceKey=data;
  6695. if(invoiceKey==""){
  6696. alert("入账错误,请重新刷新页面");
  6697. return false;
  6698. }
  6699. if(window.confirm("' . $priceString . '确定入账吗?")){
  6700. $("#IBR").submit();
  6701. }else{
  6702. return false;
  6703. }
  6704. });
  6705. </script>
  6706. ';
  6707. $invoiceHtml .= '</tbody></table>';
  6708. }
  6709. echo json_encode ( array (
  6710. 'status' => 1,
  6711. 'irkey' => $detail ['iridEn'],
  6712. 'receivablesHtml' => $receivablesHtml,
  6713. 'isInvoice' => $isInvoice,
  6714. 'invoiceHtml' => $invoiceHtml
  6715. ) );
  6716. }
  6717. function ajaxGetInvoiceReceivablesByTitle() {
  6718. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  6719. if (empty ( $title )) {
  6720. echo json_encode ( array (
  6721. 'status' => 2,
  6722. 'msg' => 'illegal request'
  6723. ) );
  6724. die ();
  6725. }
  6726. Doo::loadModel ( 'invoice' );
  6727. $invoice = new invoice ();
  6728. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and (irid='' or irid is null) ", true );
  6729. $invoiceHtml = '';
  6730. if (! empty ( $invoiceDetail )) {
  6731. $invoiceHtml = '<table class="table table-bordered table-condensed">
  6732. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  6733. foreach ( $invoiceDetail as $key => $value ) {
  6734. if (! empty ( $value ['invoiceType'] )) {
  6735. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  6736. } else {
  6737. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  6738. }
  6739. if (! empty ( $value ['invoiceType'] )) {
  6740. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  6741. } else {
  6742. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  6743. }
  6744. $invoiceHtml .= '
  6745. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  6746. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  6747. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  6748. </tr>
  6749. ';
  6750. }
  6751. $invoiceHtml .= '</tbody></table>
  6752. <script>
  6753. $(\'a[bind-receivables^="ir"]\').click(function() {
  6754. var data = $(this).attr("data-ikey");
  6755. $("input[name=\'invoiceKey\']").val(data);
  6756. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  6757. if(invoiceKey==""){
  6758. alert("入账错误,请重新刷新页面");
  6759. return false;
  6760. }
  6761. if(window.confirm("确定入账吗?")){
  6762. $("#IBR").submit();
  6763. }else{
  6764. return false;
  6765. }
  6766. });
  6767. </script>
  6768. ';
  6769. }
  6770. echo json_encode ( array (
  6771. 'status' => 1,
  6772. 'invoiceHtml' => $invoiceHtml
  6773. ) );
  6774. }
  6775. function ajaxInvoicePushNotice() {
  6776. Doo::loadModel ( 'invoice' );
  6777. $invoice = new invoice ();
  6778. $approval = $invoice->getOne ( array (
  6779. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  6780. 'desc' => 'iid',
  6781. 'asArray' => true
  6782. ) );
  6783. $isNotice = false;
  6784. if (! empty ( $approval ))
  6785. $isNotice = true;
  6786. $response = array (
  6787. 'error' => 0,
  6788. 'isNotice' => $isNotice
  6789. );
  6790. echo json_encode ( $response );
  6791. exit ();
  6792. }
  6793. public function ajaxCheckInvoiceNoUniqueness() {
  6794. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  6795. Doo::loadModel ( 'invoice' );
  6796. $invoice = new invoice ();
  6797. if (! empty ( $invoiceNo )) {
  6798. Doo::loadModel ( 'invoicePaper' );
  6799. $invoicePaper = new invoicePaper ();
  6800. Doo::loadClass ( 'XDeode' );
  6801. $XDeode = new XDeode ( 5 );
  6802. $ipid = $XDeode->decode ( $invoiceNo );
  6803. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  6804. $info = $invoice->getOne ( array (
  6805. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  6806. 'asArray' => TRUE
  6807. ) );
  6808. if (! empty ( $info )) {
  6809. echo json_encode ( array (
  6810. 'error' => '发票号已存在'
  6811. ) );
  6812. die ();
  6813. } else
  6814. echo json_encode ( array (
  6815. 'ok' => '可以使用!'
  6816. ) );
  6817. die ();
  6818. }
  6819. }
  6820. function ajaxCheckInvoicePrice() {
  6821. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  6822. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  6823. Doo::loadModel ( 'invoice' );
  6824. $invoice = new invoice ();
  6825. Doo::loadModel ( 'invoiceReceivables' );
  6826. $invoiceReceivables = new invoiceReceivables ();
  6827. Doo::loadClass ( 'XDeode' );
  6828. $XDeode = new XDeode ( 5 );
  6829. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  6830. $iidKey = $XDeode->decode ( $iidKey );
  6831. $info = $invoice->getInvoiceByIid ( $iidKey );
  6832. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  6833. if (empty ( $irList ))
  6834. $irList [0] ['sumPrice'] = 0;
  6835. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  6836. if ($balance < $receivablesPrice) {
  6837. echo json_encode ( array (
  6838. 'error' => '收款金额超过开票金额。'
  6839. ) );
  6840. die ();
  6841. }
  6842. if ($balance > $receivablesPrice) {
  6843. echo json_encode ( array (
  6844. 'error' => '收款金额低于开票金额。'
  6845. ) );
  6846. die ();
  6847. }
  6848. }
  6849. }
  6850. function ajaxGetInvoiceByNew() {
  6851. Doo::loadModel ( 'invoice' );
  6852. $invoice = new invoice ();
  6853. $detail = $invoice->getInvoiceByNew ( $this->staff [0] ['sid'] );
  6854. echo json_encode ( array (
  6855. 'status' => 1,
  6856. 'detail' => $detail
  6857. ) );
  6858. }
  6859. /**
  6860. * 旧输入导入
  6861. */
  6862. function importInvoice() {
  6863. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6864. $data ['emsg'] = "";
  6865. if ($emsg != "")
  6866. $data ['emsg'] = "请填写完整的数据";
  6867. $data ['time'] = time ();
  6868. $this->render ( "/admin/invoiceImport", $data );
  6869. }
  6870. function uploadInvoice() {
  6871. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  6872. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  6873. $file = $_FILES ['Filedata'] ['tmp_name'];
  6874. $error = false;
  6875. if (! is_uploaded_file ( $file )) {
  6876. $error = '400 Bad Request';
  6877. }
  6878. if ($error) {
  6879. header ( 'HTTP/1.0 ' . $error );
  6880. die ( 'Error ' . $error );
  6881. } else {
  6882. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  6883. $this->IoHandler = new IoHandler ();
  6884. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  6885. // $filedir=$_POST['time'];
  6886. // 调用定义物理路径
  6887. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  6888. $this->IoHandler->MakeDir ( $t );
  6889. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  6890. if ($filename != 'xlsx')
  6891. return "";
  6892. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  6893. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  6894. $upload_dir = $t . "/" . $upload_file;
  6895. $k = move_uploaded_file ( $file, $upload_dir );
  6896. if ($k) {
  6897. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  6898. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  6899. }
  6900. }
  6901. }
  6902. }
  6903. function importInvoiceDo() {
  6904. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6905. if ($path != "") {
  6906. Doo::loadModel ( 'invoice' );
  6907. Doo::loadModel ( 'staff' );
  6908. $staff = new staff ();
  6909. Doo::loadModel ( 'invoiceStatistics' );
  6910. Doo::loadModel ( 'invoiceOperationLog' );
  6911. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6912. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  6913. // print_r ( $exlArray );
  6914. // die ();
  6915. // echo json_encode($exlArray);die;
  6916. foreach ( $exlArray as $key => $value ) {
  6917. // 开票
  6918. $invoice = new invoice ();
  6919. $invoice->invoiceNo = $value ['invoiceNo'];
  6920. $invoice->invoiceType = 0;
  6921. if ($value ['invoiceType'] == '专')
  6922. $invoice->invoiceType = 1;
  6923. $invoice->invoicePrice = $value ['invoicePrice'];
  6924. $invoice->invoiceQuantity = 1;
  6925. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  6926. $invoice->invoiceTitle = $value ['invoiceTitle'];
  6927. if ($value ['invoiceType'] == '专')
  6928. $invoice->invoiceCompany = $value ['invoiceTitle'];
  6929. $invoice->userName = $value ['userName'];
  6930. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  6931. $invoice->sid = $sDetail ['sid'];
  6932. $invoice->cid = $sDetail ['cid'];
  6933. $invoice->categoryName = $sDetail ['category'];
  6934. $invoice->invoiceElement = $value ['invoiceElement'];
  6935. $invoice->remark = $value ['remark'];
  6936. $invoice->date = $value ['date'];
  6937. $invoice->printTime = $value ['date'];
  6938. $invoice->ipSource = 1;
  6939. $invoice->printStatus = 1;
  6940. $invoice->status = 2;
  6941. $invoice->postStatus = 1;
  6942. $invoice->untreadStatus = 0;
  6943. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  6944. $iid = $invoice->insert ();
  6945. // 汇总
  6946. $invoiceStatistics = new invoiceStatistics ();
  6947. //
  6948. $item = array (
  6949. 'date' => $value ['date'],
  6950. 'priceClass' => 1,
  6951. 'cid' => $sDetail ['cid'],
  6952. 'staff' => $sDetail ['sid'],
  6953. 'invoicePrice' => $value ['invoicePrice']
  6954. );
  6955. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  6956. $invoiceOperationLog = new invoiceOperationLog ();
  6957. $item = array (
  6958. 'date' => date ( "Y-m-d H:i:s" ),
  6959. 'operation' => date ( "Y-m-d" ) . " 导入",
  6960. 'status' => 1,
  6961. 'img' => $sDetail ['avatar'],
  6962. 'username' => $sDetail ['username'],
  6963. 'uid' => $sDetail ['sid'],
  6964. 'category' => $sDetail ['category'],
  6965. 'iid' => $iid
  6966. );
  6967. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  6968. }
  6969. return '/importInvoice?count=' . count ( $exlArray );
  6970. // return "/keyonline";
  6971. }
  6972. echo 'no file';
  6973. }
  6974. function importInvoiceReceivables() {
  6975. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  6976. $data ['emsg'] = "";
  6977. if ($emsg != "")
  6978. $data ['emsg'] = "请填写完整的数据";
  6979. $data ['time'] = time ();
  6980. $this->render ( "/admin/invoiceReceivablesImport", $data );
  6981. }
  6982. // 导入入账数据
  6983. function importInvoiceReceivablesDo() {
  6984. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  6985. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  6986. if ($path != "") {
  6987. Doo::loadModel ( 'invoiceReceivables' );
  6988. Doo::loadModel ( 'invoice' );
  6989. Doo::loadModel ( 'staff' );
  6990. $staff = new staff ();
  6991. Doo::loadModel ( 'invoiceStatistics' );
  6992. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  6993. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  6994. // print_r ( $exlArray );
  6995. // die ();
  6996. // echo json_encode($exlArray);die;
  6997. foreach ( $exlArray as $key => $value ) {
  6998. // 收款
  6999. $invoiceReceivables = new invoiceReceivables ();
  7000. $invoice = new invoice ();
  7001. $invoiceReceivables->bindStatus = 1;
  7002. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  7003. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  7004. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  7005. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  7006. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  7007. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  7008. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  7009. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  7010. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  7011. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  7012. $invoiceReceivables->iid = $iDetail ['iid'];
  7013. $irid = $invoiceReceivables->insert ();
  7014. // 发票绑定收款
  7015. $detail = $iDetail;
  7016. $iridString = "";
  7017. if (empty ( $detail ['irid'] ))
  7018. $iridString = $irid;
  7019. else
  7020. $iridString = $detail ['irid'] . ',' . $irid;
  7021. $item = array (
  7022. 'irid' => $iridString,
  7023. 'iid' => $detail ['iid']
  7024. );
  7025. $invoice->setInvoiceByCondition ( $item );
  7026. // 汇总
  7027. $invoiceStatistics = new invoiceStatistics ();
  7028. // 扣除入账统计金额
  7029. $item = array (
  7030. 'date' => $value ['receivablesDate'],
  7031. 'priceClass' => 3,
  7032. 'cid' => $sDetail ['cid'],
  7033. 'staff' => $sDetail ['sid'],
  7034. // 'irid' => $irid,
  7035. 'accountPrice' => $value ['receivablesPrice']
  7036. );
  7037. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  7038. }
  7039. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  7040. echo 'data count ' . count ( $exlArray );
  7041. die ();
  7042. // return "/keyonline";
  7043. }
  7044. echo 'no file';
  7045. }
  7046. function formatExcelToArrayTrain($file_url = "") {
  7047. if (! file_exists ( $file_url )) {
  7048. return array ();
  7049. }
  7050. // Doo::loadClass ( 'PHPExcel' );
  7051. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  7052. $PHPExcel = new PHPExcel ();
  7053. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  7054. if (! $PHPReader->canRead ( $file_url )) {
  7055. $PHPReader = new PHPExcel_Reader_Excel5 ();
  7056. if (! $PHPReader->canRead ( $file_url )) {
  7057. echo 'no Excel';
  7058. return;
  7059. }
  7060. }
  7061. $PHPExcel = $PHPReader->load ( $file_url );
  7062. /* * 读取excel文件中的第一个工作表 */
  7063. $currentSheet = $PHPExcel->getSheet ( 0 );
  7064. /* * 取得最大的列号 */
  7065. $allColumn = $currentSheet->getHighestColumn ();
  7066. /* * 取得一共有多少行 */
  7067. $allRow = $currentSheet->getHighestRow ();
  7068. $excel_array = array ();
  7069. // die($file_url);
  7070. $conk = 2;
  7071. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  7072. $excel_column = array ();
  7073. // 后期改进
  7074. if ($allColumn == 'AM')
  7075. $allColumn = 'Z';
  7076. /* * 从第A列开始输出 */
  7077. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  7078. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  7079. if ($val instanceof PHPExcel_RichText)
  7080. $val = $val->__toString ();
  7081. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  7082. // $val = "'" . addslashes ( $val ) . "'";
  7083. if ($currentColumn == 'A') {
  7084. $excel_column ['invoiceTitle'] = $val;
  7085. } elseif ($currentColumn == 'B')
  7086. $excel_column ['invoiceType'] = $val;
  7087. elseif ($currentColumn == 'C') {
  7088. $excel_column ['TIN'] = $val;
  7089. } elseif ($currentColumn == 'D') {
  7090. $excel_column ['address'] = $val;
  7091. } elseif ($currentColumn == 'E') {
  7092. $excel_column ['phone'] = $val;
  7093. } elseif ($currentColumn == 'F') {
  7094. $excel_column ['bank'] = $val;
  7095. } elseif ($currentColumn == 'G') {
  7096. $excel_column ['bankAccount'] = $val;
  7097. } elseif ($currentColumn == 'H') {
  7098. $excel_column ['invoiceElement'] = $val;
  7099. } elseif ($currentColumn == 'I') {
  7100. $excel_column ['invoiceQuantity'] = $val;
  7101. } elseif ($currentColumn == 'J') {
  7102. $excel_column ['invoiceUnitPrice'] = $val;
  7103. } elseif ($currentColumn == 'K') {
  7104. $excel_column ['remark'] = $val;
  7105. } elseif ($currentColumn == 'L') {
  7106. $excel_column ['recipientsAddress'] = $val;
  7107. } elseif ($currentColumn == 'M') {
  7108. $excel_column ['recipients'] = $val;
  7109. } elseif ($currentColumn == 'N') {
  7110. $excel_column ['recipientsPhone'] = $val;
  7111. }elseif ($currentColumn == 'O') {
  7112. $excel_column ['electronicPhone'] = $val;
  7113. } elseif ($currentColumn == 'P') {
  7114. $excel_column ['electronicEmail'] = $val;
  7115. }
  7116. }
  7117. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  7118. array_push ( $excel_array, $excel_column );
  7119. }
  7120. return $excel_array;
  7121. }
  7122. /**
  7123. * 格式化excel文件为数组
  7124. * @param unknown_type $file_url
  7125. * @param unknown_type $mcid
  7126. */
  7127. function _format_excel_to_array($file_url = "", $sType = "") {
  7128. if (! file_exists ( $file_url )) {
  7129. return array ();
  7130. }
  7131. Doo::loadClass ( 'PHPExcel' );
  7132. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  7133. $PHPExcel = new PHPExcel ();
  7134. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  7135. if (! $PHPReader->canRead ( $file_url )) {
  7136. $PHPReader = new PHPExcel_Reader_Excel5 ();
  7137. if (! $PHPReader->canRead ( $file_url )) {
  7138. echo 'no Excel';
  7139. return;
  7140. }
  7141. }
  7142. $PHPExcel = $PHPReader->load ( $file_url );
  7143. /* * 读取excel文件中的第一个工作表 */
  7144. $currentSheet = $PHPExcel->getSheet ( 0 );
  7145. /* * 取得最大的列号 */
  7146. $allColumn = $currentSheet->getHighestColumn ();
  7147. /* * 取得一共有多少行 */
  7148. $allRow = $currentSheet->getHighestRow ();
  7149. $excel_array = array ();
  7150. // die($file_url);
  7151. $conk = 2;
  7152. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  7153. $excel_column = array ();
  7154. // 后期改进
  7155. if ($allColumn == 'AM')
  7156. $allColumn = 'Z';
  7157. /* * 从第A列开始输出 */
  7158. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  7159. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  7160. if ($val instanceof PHPExcel_RichText)
  7161. $val = $val->__toString ();
  7162. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  7163. // $val = "'" . addslashes ( $val ) . "'";
  7164. if ($sType == 'invoiceReceivables') {
  7165. if ($currentColumn == 'A')
  7166. $excel_column ['invoiceNo'] = $val;
  7167. elseif ($currentColumn == 'B')
  7168. $excel_column ['receivablesPrice'] = $val;
  7169. elseif ($currentColumn == 'C') {
  7170. $excel_column ['receivablesMessage'] = $val;
  7171. } elseif ($currentColumn == 'D') {
  7172. $excel_column ['receivablesBank'] = $val;
  7173. } elseif ($currentColumn == 'E') {
  7174. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  7175. } elseif ($currentColumn == 'F') {
  7176. $excel_column ['receivablesStaff'] = $val;
  7177. } elseif ($currentColumn == 'G') {
  7178. $excel_column ['sourcePrice'] = $val;
  7179. }
  7180. } elseif ($sType == "invoiceTrain") {
  7181. if ($currentColumn == 'A') {
  7182. $excel_column ['invoiceTitle'] = $val;
  7183. } elseif ($currentColumn == 'B')
  7184. $excel_column ['invoiceType'] = $val;
  7185. elseif ($currentColumn == 'C') {
  7186. $excel_column ['TIN'] = $val;
  7187. } elseif ($currentColumn == 'D') {
  7188. $excel_column ['address'] = $val;
  7189. } elseif ($currentColumn == 'E') {
  7190. $excel_column ['phone'] = $val;
  7191. } elseif ($currentColumn == 'F') {
  7192. $excel_column ['bank'] = $val;
  7193. } elseif ($currentColumn == 'G') {
  7194. $excel_column ['bankAccount'] = $val;
  7195. } elseif ($currentColumn == 'H') {
  7196. $excel_column ['invoiceElement'] = $val;
  7197. } elseif ($currentColumn == 'I') {
  7198. $excel_column ['invoiceQuantity'] = $val;
  7199. } elseif ($currentColumn == 'J') {
  7200. $excel_column ['invoiceUnitPrice'] = $val;
  7201. } elseif ($currentColumn == 'K') {
  7202. $excel_column ['remark'] = $val;
  7203. } elseif ($currentColumn == 'L') {
  7204. $excel_column ['recipientsAddress'] = $val;
  7205. } elseif ($currentColumn == 'M') {
  7206. $excel_column ['recipients'] = $val;
  7207. } elseif ($currentColumn == 'N') {
  7208. $excel_column ['recipientsPhone'] = $val;
  7209. }
  7210. } else {
  7211. if ($currentColumn == 'A')
  7212. $excel_column ['invoiceNo'] = $val;
  7213. elseif ($currentColumn == 'B')
  7214. $excel_column ['invoiceType'] = $val;
  7215. elseif ($currentColumn == 'C') {
  7216. $excel_column ['invoicePrice'] = $val;
  7217. } elseif ($currentColumn == 'D') {
  7218. $excel_column ['invoiceTitle'] = $val;
  7219. } elseif ($currentColumn == 'E') {
  7220. $excel_column ['userName'] = $val;
  7221. } elseif ($currentColumn == 'F') {
  7222. $excel_column ['categoryName'] = $val;
  7223. } elseif ($currentColumn == 'G') {
  7224. $excel_column ['invoiceElement'] = $val;
  7225. } elseif ($currentColumn == 'H') {
  7226. $excel_column ['remark'] = $val;
  7227. } elseif ($currentColumn == 'I') {
  7228. $excel_column ['date'] = $this->excelTime ( $val );
  7229. }
  7230. }
  7231. }
  7232. array_push ( $excel_array, $excel_column );
  7233. }
  7234. return $excel_array;
  7235. }
  7236. function excelTime($date, $time = false) {
  7237. if (function_exists ( 'GregorianToJD' )) {
  7238. if (is_numeric ( $date )) {
  7239. $jd = GregorianToJD ( 1, 1, 1970 );
  7240. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  7241. $date = explode ( '/', $gregorian );
  7242. $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" : '');
  7243. return $date_str;
  7244. }
  7245. } else {
  7246. $date = $date > 25568 ? $date + 1 : 25569;
  7247. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  7248. $ofs = (70 * 365 + 17 + 2) * 86400;
  7249. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  7250. }
  7251. return $date;
  7252. }
  7253. /**
  7254. * 旧输入导入
  7255. */
  7256. function _GetFileEXT($filename) {
  7257. $pics = explode ( '.', $filename );
  7258. $num = count ( $pics );
  7259. return $pics [$num - 1];
  7260. }
  7261. function showCache($path = "", $sid = 0) {
  7262. // if (file_exists ( $path )) {
  7263. // $htm = file_get_contents ( $path );
  7264. // } else {
  7265. Doo::loadModel ( 'invoiceStatistics' );
  7266. $invoiceStatistics = new invoiceStatistics ();
  7267. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  7268. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  7269. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  7270. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  7271. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  7272. /*
  7273. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  7274. */
  7275. file_put_contents ( $path, $htm );
  7276. // }
  7277. return $htm;
  7278. }
  7279. /**
  7280. * 生成token
  7281. * @return string
  7282. */
  7283. function set_token() {
  7284. $str = md5 ( uniqid ( md5 ( microtime ( true ) ), true ) ); // 生成一个不会重复的字符串
  7285. $str = sha1 ( $str ); // 加密
  7286. return $str;
  7287. }
  7288. /**
  7289. * 获取get或者POST值
  7290. *
  7291. * @param string $name 属性名称
  7292. * @return fixed 值
  7293. */
  7294. function get_args($name) {
  7295. if (isset ( $_GET [$name] )) {
  7296. if (is_array ( $_GET [$name] ))
  7297. return $_GET [$name];
  7298. else
  7299. return addslashes ( $_GET [$name] );
  7300. } elseif (isset ( $_POST [$name] )) {
  7301. if (is_array ( $_POST [$name] ))
  7302. return $_POST [$name];
  7303. else
  7304. return addslashes ( $_POST [$name] );
  7305. } else
  7306. return false;
  7307. }
  7308. function SafeFilter(&$arr) {
  7309. $ra = Array (
  7310. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  7311. '/script/',
  7312. '/javascript/',
  7313. '/vbscript/',
  7314. '/expression/',
  7315. '/applet/',
  7316. '/meta/',
  7317. '/xml/',
  7318. '/blink/',
  7319. '/link/',
  7320. '/style/',
  7321. '/embed/',
  7322. '/object/',
  7323. '/frame/',
  7324. '/layer/',
  7325. '/title/',
  7326. '/bgsound/',
  7327. '/base/',
  7328. '/onload/',
  7329. '/onunload/',
  7330. '/onchange/',
  7331. '/onsubmit/',
  7332. '/onreset/',
  7333. '/onselect/',
  7334. '/onblur/',
  7335. '/onfocus/',
  7336. '/onabort/',
  7337. '/onkeydown/',
  7338. '/onkeypress/',
  7339. '/onkeyup/',
  7340. '/onclick/',
  7341. '/ondblclick/',
  7342. '/onmousedown/',
  7343. '/onmousemove/',
  7344. '/onmouseout/',
  7345. '/onmouseover/',
  7346. '/onmouseup/',
  7347. '/onunload/'
  7348. );
  7349. if (is_array ( $arr )) {
  7350. foreach ( $arr as $key => $value ) {
  7351. if (! is_array ( $value )) {
  7352. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  7353. {
  7354. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  7355. }
  7356. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  7357. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  7358. } else {
  7359. SafeFilter ( $arr [$key] );
  7360. }
  7361. }
  7362. }
  7363. }
  7364. /**
  7365. * Escape String
  7366. *
  7367. * @access public
  7368. * @param string
  7369. * @param bool whether or not the string will be used in a LIKE condition
  7370. * @return string
  7371. */
  7372. function escape_str($str, $like = FALSE) {
  7373. if (is_array ( $str )) {
  7374. foreach ( $str as $key => $val ) {
  7375. $str [$key] = $this->escape_str ( $val, $like );
  7376. }
  7377. return $str;
  7378. }
  7379. var_dump ( Doo::db ()->getDbObject () );
  7380. die ();
  7381. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  7382. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  7383. } elseif (function_exists ( 'mysql_escape_string' )) {
  7384. $str = mysql_escape_string ( $str );
  7385. } else {
  7386. $str = addslashes ( $str );
  7387. }
  7388. // escape LIKE condition wildcards
  7389. if ($like === TRUE) {
  7390. $str = str_replace ( array (
  7391. '%',
  7392. '_'
  7393. ), array (
  7394. '\\%',
  7395. '\\_'
  7396. ), $str );
  7397. }
  7398. return $str;
  7399. }
  7400. /**
  7401. * 获得分页数据
  7402. * @param unknown_type $table
  7403. * @param unknown_type $condition
  7404. * @param unknown_type $on_page
  7405. * @param unknown_type $page_size
  7406. */
  7407. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  7408. $page_c = "";
  7409. $page ['previous'] = $this->get_previous ( $on_page );
  7410. $page ['on_page'] = $on_page;
  7411. $total_count = $this->get_table_count ( $table, $condition );
  7412. $total = intval ( $total_count / $page_size );
  7413. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  7414. $page ['total_data'] = $total_count;
  7415. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  7416. $i = 1;
  7417. $page_max = 1;
  7418. $page_width = 3;
  7419. if ($on_page >= $page_width) {
  7420. $page_max = intval ( $on_page / $page_width ) + 1;
  7421. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  7422. }
  7423. for(; $i <= $page ['total_page']; $i ++) {
  7424. if ($i == $on_page)
  7425. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  7426. else
  7427. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  7428. if ($i == ($page_width * $page_max))
  7429. break;
  7430. }
  7431. $page ['page'] = $page_c;
  7432. $page ['lower'] = (-- $on_page) * $page_size;
  7433. return $page;
  7434. }
  7435. /**
  7436. * 获取上一页
  7437. * @param unknown_type $on_page
  7438. */
  7439. function get_previous($on_page = 1) {
  7440. return $on_page != 0 ? $on_page - 1 : $on_page;
  7441. }
  7442. /**
  7443. * 获取总页数
  7444. * @param unknown_type $table
  7445. * @param unknown_type $condition
  7446. */
  7447. public function get_table_count($table = "", $condition = "") {
  7448. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  7449. $sql = "select count(*) as count from " . $table . " where " . $condition;
  7450. // echo $sql;die;
  7451. $query = Doo::db ()->query ( $sql );
  7452. $result = $query->fetch ();
  7453. return $result ['count'];
  7454. }
  7455. function isInvoiceNew($type = "GLOBAL") {
  7456. Doo::loadModel ( 'invoice' );
  7457. $invoice = new invoice ();
  7458. Doo::loadModel ( 'invoiceReceivables' );
  7459. $invoiceReceivables = new invoiceReceivables ();
  7460. Doo::loadModel ( 'staff' );
  7461. $staff = new staff ();
  7462. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  7463. // 我的发票待处理
  7464. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  7465. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  7466. 'desc' => 'iid',
  7467. 'asArray' => TRUE
  7468. ) );
  7469. // 我的收款待入账
  7470. /*
  7471. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  7472. */
  7473. // 发票审批
  7474. $approval = $invoice->getOne ( array (
  7475. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  7476. 'desc' => 'iid',
  7477. 'asArray' => true
  7478. ) );
  7479. // 发票邮寄
  7480. $post = $invoice->getOne ( array (
  7481. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  7482. 'asArray' => TRUE
  7483. ) );
  7484. // 发票打印
  7485. $print = $invoice->getOne ( array (
  7486. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  7487. 'desc' => 'iid',
  7488. 'asArray' => TRUE
  7489. ) );
  7490. // 发票退票 printStatus=1 and
  7491. $untread = $invoice->getOne ( array (
  7492. 'where' => " untreadStatus=1 and status=2 ",
  7493. 'asArray' => TRUE
  7494. ) );
  7495. $new = array (
  7496. 'GLOBAL' => FALSE,
  7497. 'pendingInvoice' => FALSE,
  7498. // 'myClaim' => FALSE,
  7499. 'approval' => FALSE,
  7500. 'post' => FALSE,
  7501. 'print' => FALSE,
  7502. 'untread' => FALSE
  7503. );
  7504. // || ! empty ( $myClaim )
  7505. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  7506. $new ['GLOBAL'] = TRUE;
  7507. if (! empty ( $pendingInvoice ))
  7508. $new ['pendingInvoice'] = TRUE;
  7509. // if (! empty ( $myClaim ))
  7510. // $new ['myClaim'] = TRUE;
  7511. if (! empty ( $approval ))
  7512. $new ['approval'] = TRUE;
  7513. if (! empty ( $post ))
  7514. $new ['post'] = TRUE;
  7515. if (! empty ( $print ))
  7516. $new ['print'] = TRUE;
  7517. if (! empty ( $untread ))
  7518. $new ['untread'] = TRUE;
  7519. return $new;
  7520. }
  7521. function setWXMsg($rid, $typeMsg = '') {
  7522. Doo::loadModel ( 'invoice' );
  7523. $invoice = new invoice ();
  7524. $invoiceDetail = $invoice->getOne ( array (
  7525. 'where' => 'iid=' . $rid,
  7526. 'asArray' => true
  7527. ) );
  7528. if (! empty ( $invoiceDetail )) {
  7529. Doo::loadModel ( 'staff' );
  7530. $staff = new staff ();
  7531. $staffmsg = $staff->getOne ( array (
  7532. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  7533. 'asArray' => TRUE
  7534. ) );
  7535. if (! empty ( $staffmsg ['wxid'] )) {
  7536. require_once (SITE_PATH . '/protected/class/client.php');
  7537. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  7538. $user = $staffmsg ['wxid'];
  7539. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  7540. if (empty ( $expCom ))
  7541. $expCom [0] = '';
  7542. $msg = "";
  7543. if (empty ( $typeMsg ))
  7544. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  7545. elseif ($typeMsg == "PRINT")
  7546. $msg = '太好了,您的发票已打印完成。';
  7547. $result = $client->SendMsg ( $user, $msg, 'text' );
  7548. }
  7549. }
  7550. }
  7551. /**
  7552. * 获取微信部门
  7553. * @param string $category
  7554. * @return number|mixed
  7555. */
  7556. function getToparty($category = '') {
  7557. $token = $this->getAccessToken (); //
  7558. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  7559. $toparty = 0;
  7560. foreach ( $result ['department'] as $key => $value ) {
  7561. if ($value ['name'] == $category)
  7562. $toparty = $value ['id'];
  7563. }
  7564. return $toparty;
  7565. }
  7566. /**
  7567. * 获得某部门下的用户
  7568. * @param string $toparty
  7569. */
  7570. function getUserByToparty($toparty = '') {
  7571. $token = $this->getAccessToken (); //
  7572. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  7573. $userList = array ();
  7574. foreach ( $result ['userlist'] as $key => $value ) {
  7575. array_push ( $userList, "'" . $value ['userid'] . "'" );
  7576. }
  7577. return $userList;
  7578. }
  7579. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  7580. $token = $this->getAccessToken ();
  7581. if ($text == 'text') {
  7582. $data = '{
  7583. "touser": "' . $toparty . '",
  7584. "toparty": "",
  7585. "totag": "",
  7586. "msgtype": "text",
  7587. "agentid": 1000002,
  7588. "text": {
  7589. "content": "' . $msg . '"
  7590. },
  7591. "safe":0
  7592. }';
  7593. }
  7594. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7595. if ($result->errmsg != 'ok') {
  7596. return 0;
  7597. } else {
  7598. return 1;
  7599. }
  7600. }
  7601. /**
  7602. * 获得可以发送微信用户列表
  7603. * @param string $category
  7604. * @return string
  7605. */
  7606. function getWxidByCategory($category = "") {
  7607. if (empty ( $category ))
  7608. return "";
  7609. Doo::loadModel ( 'staff' );
  7610. $staff = new staff ();
  7611. $toparty = $this->getToparty ( $category );
  7612. $wxList = array ();
  7613. $wxString = "";
  7614. if (! empty ( $toparty )) {
  7615. $userList = $this->getUserByToparty ( $toparty );
  7616. $userCon = implode ( ',', $userList );
  7617. // echo $userCon;
  7618. $sidList = $staff->getStaffByWxid ( $userCon );
  7619. foreach ( $sidList as $key => $value ) {
  7620. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  7621. if ($falg) {
  7622. array_push ( $wxList, $value ['wxid'] );
  7623. }
  7624. }
  7625. $wxString = implode ( '|', $wxList );
  7626. }
  7627. return $wxString;
  7628. }
  7629. /**
  7630. * 读取发送信息规则判断是否需要发送
  7631. * @param number $sid
  7632. * @param string $sendType
  7633. * @return boolean
  7634. */
  7635. function isSendNotification($sid = 0, $sendType = '') {
  7636. Doo::loadModel ( "notificationConf" );
  7637. $notificationConf = new notificationConf ();
  7638. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  7639. $conf = array ();
  7640. $sendFlag = true;
  7641. if (! empty ( $detail )) {
  7642. $conf = json_decode ( $detail ['conf'], true );
  7643. if (! empty ( $sendType )) {
  7644. if (isset ( $conf [$sendType] )) {
  7645. if ($conf [$sendType] == "CLOSE")
  7646. $sendFlag = false;
  7647. elseif ($conf [$sendType] == "Weekend") {
  7648. $day = date ( "w" );
  7649. if (1 <= $day && 5 >= $day)
  7650. $sendFlag = false;
  7651. } elseif ($conf [$sendType] == "OneToFriday") {
  7652. $day = date ( "w" );
  7653. if (0 == $day || 6 == $day)
  7654. $sendFlag = false;
  7655. }
  7656. }
  7657. } else
  7658. $sendFlag = false;
  7659. }
  7660. return $sendFlag;
  7661. }
  7662. /**
  7663. * 根据规则发送信息
  7664. * @param unknown $msg
  7665. * @param unknown $title
  7666. * @param unknown $url
  7667. * @param unknown $user
  7668. * @param string $text
  7669. * @return number
  7670. */
  7671. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  7672. $token = $this->getAccessToken ();
  7673. $falg = $this->isSendNotification ( $sid, $sendType );
  7674. // if ($text == 'text') {
  7675. // $data = '{
  7676. // "touser": "' . $user . '",
  7677. // "toparty": "",
  7678. // "totag": "",
  7679. // "msgtype": "text",
  7680. // "agentid": 1000002,
  7681. // "text": {
  7682. // "content": "' . $msg . '"
  7683. // },
  7684. // "safe":0
  7685. // }';
  7686. // } else {
  7687. $data = '{
  7688. "touser": "' . $user . '",
  7689. "toparty": "",
  7690. "totag": "",
  7691. "msgtype": "news",
  7692. "agentid": 1000002,
  7693. "news": {
  7694. "articles":[
  7695. {
  7696. "title": "' . $title . '",
  7697. "description": "' . $msg . '",
  7698. "url": "' . $url . '",
  7699. "picurl": ""
  7700. }
  7701. ]
  7702. }
  7703. }';
  7704. // }
  7705. if ($falg) {
  7706. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  7707. if ($result->errmsg != 'ok') {
  7708. return 0;
  7709. } else {
  7710. return 1;
  7711. }
  7712. } else
  7713. return 0;
  7714. }
  7715. private function getAccessToken() {
  7716. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  7717. // $file = './access_token.txt';
  7718. // $data = json_decode ( file_get_contents ( $file ) );
  7719. // if ($data->expire_time < time () or ! $data->expire_time) {
  7720. // 如果是企业号用以下URL获取access_token
  7721. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  7722. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  7723. $res = json_decode ( $this->httpGet ( $url ) );
  7724. $access_token = $res->access_token;
  7725. // echo $access_token;
  7726. // if ($access_token) {
  7727. // $data->expire_time = time () + 7000;
  7728. // $data->access_token = $access_token;
  7729. // $fp = fopen ( $file, "w" );
  7730. // fwrite ( $fp, json_encode ( $data ) );
  7731. // fclose ( $fp );
  7732. // }
  7733. // } else {
  7734. // $access_token = $data->access_token;
  7735. // }
  7736. return $access_token;
  7737. }
  7738. private function httpGet($url) {
  7739. $curl = curl_init ();
  7740. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7741. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7742. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7743. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7744. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7745. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7746. curl_setopt ( $curl, CURLOPT_URL, $url );
  7747. $res = curl_exec ( $curl );
  7748. curl_close ( $curl );
  7749. return $res;
  7750. }
  7751. private function httpPost($url, $data) {
  7752. $curl = curl_init ();
  7753. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  7754. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  7755. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  7756. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  7757. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  7758. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  7759. curl_setopt ( $curl, CURLOPT_URL, $url );
  7760. curl_setopt ( $curl, CURLOPT_POST, 1 );
  7761. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  7762. $res = curl_exec ( $curl );
  7763. curl_close ( $curl );
  7764. return $res;
  7765. }
  7766. }
  7767. ?>