InvoiceController.php 277 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514
  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. // var_dump($flag) ;
  64. // 单独判断办事处汇总的访问权限 invoiceAggregateCategoryDetail,invoiceAggregateStaffDetail
  65. if ($action == 'invoiceAggregateCategoryDetail' || $action == 'invoiceAggregateStaffDetail') {
  66. Doo::loadModel ( "invoiceCategoryManage" );
  67. $invoiceCategoryManage = new invoiceCategoryManage ();
  68. $icm = $invoiceCategoryManage->getInvoiceCMByStaff ( $sid );
  69. if (empty ( $icm ))
  70. die ( 'illegal request' );
  71. }
  72. //单独判断应收款访问权限
  73. if ($action == 'invoiceAggregateCompanyDetail' ) {
  74. Doo::loadModel ( "invoiceCompanyManage" );
  75. $invoiceCompanyManage = new invoiceCompanyManage ();
  76. $icm = $invoiceCompanyManage->getInvoiceCMByStaff ( $sid );
  77. if (empty ( $icm ))
  78. die ( 'illegal request' );
  79. }
  80. if (! $flag)
  81. die ( 'illegal request' );
  82. }
  83. function __construct() {
  84. if (isset ( $_COOKIE ["staff"] )) {
  85. if (! empty ( $_COOKIE ["staff"] )) {
  86. Doo::loadModel ( 'staff' );
  87. $staff = new staff ();
  88. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  89. $this->ACTION = $uriPartsOrig [1];
  90. $this->data ['new'] = $this->isInvoiceNew ();
  91. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  92. return "/";
  93. }
  94. }
  95. Doo::loadCore ( 'uri/DooUriRouter' );
  96. $router = new DooUriRouter ();
  97. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  98. if ($routeRs ['1'] != "login") {
  99. header ( 'Content-Type:text/html;charset=utf-8' );
  100. @header ( "Location: /login" );
  101. }
  102. }
  103. function testSend() {
  104. // 测试根据规则发送信息 普通发送
  105. // $pendingApprovalsSid = 41;
  106. // Doo::loadModel ( 'staff' );
  107. // $staff = new staff ();
  108. // $username2 = $staff->getOne ( array ( 'select' => 'wxid', 'where' => 'sid=' . $pendingApprovalsSid, 'asArray' => TRUE ) );
  109. // // 发送微信审批通知
  110. // $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  111. // $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  112. // Doo::loadModel ( 'staff' );
  113. // $staff = new staff ();
  114. // $toparty = $this->getToparty ( '广东办' );
  115. // $wxList = array ();
  116. // if (! empty ( $toparty )) {
  117. // $userList = $this->getUserByToparty ( $toparty );
  118. // $userCon = implode ( ',', $userList );
  119. // // echo $userCon;
  120. // $sidList = $staff->getStaffByWxid ( $userCon );
  121. // foreach ( $sidList as $key => $value ) {
  122. // $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  123. // if ($falg) {
  124. // array_push ( $wxList, $value ['wxid'] );
  125. // }
  126. // }
  127. // $wxString = implode ( '|', $wxList );
  128. // print_r ( $wxList );
  129. // echo $wxString;
  130. // }
  131. // 测试发送
  132. /*
  133. * //$toparty = $this->getWxidByCategory( $receivablesCategory [1] ); $toparty = $this->getToparty ( $receivablesCategory [1] ); $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。'; if ($toparty != 0) $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  134. */
  135. // print_r ( $userList );
  136. // $msTouser='caipin|outaozhen';
  137. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  138. // $title2 = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  139. // $hfreult = $this->msgSend ( '', $title2, '', 'outaozhen' );
  140. // $toparty= $this->getToparty('广东办');
  141. // $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  142. // $toparty = 26;
  143. // $msg = '';
  144. // $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  145. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  146. }
  147. function invoice() {
  148. Doo::loadModel ( 'invoice' );
  149. $invoice = new invoice ();
  150. Doo::loadModel ( 'express' );
  151. $express = new express ();
  152. $expressList = $express->getExpressByAll ();
  153. $this->data ['expressList'] = $expressList;
  154. // Doo::loadModel ( 'invoiceReceivables' );
  155. // $invoiceReceivables = new invoiceReceivables ();
  156. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  157. Doo::loadClass ( 'XDeode' );
  158. $XDeode = new XDeode ( 5 );
  159. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  160. Doo::loadModel ( 'invoiceStatistics' );
  161. $invoiceStatistics = new invoiceStatistics ();
  162. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $sid );
  163. // 缓存统计结果
  164. $year = date ( "Y" );
  165. $tmp_date = date ( "Ym" );
  166. $tmp_year = substr ( $tmp_date, 0, 4 );
  167. $tmp_mon = substr ( $tmp_date, 4, 2 );
  168. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  169. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  170. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . "_" . $sid . ".htm";
  171. if (is_file ( $path ))
  172. $htm = file_get_contents ( $path );
  173. else
  174. $htm = $this->showCache ( $path, $sid );
  175. $invoiceList = $invoice->getMyInvoice ( $sid );
  176. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  177. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  178. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  179. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  180. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  181. // print_r($myInvoiceUnAccount);
  182. $this->data ['isMonth'] = $isMonth;
  183. $this->data ['htm'] = $htm;
  184. $this->data ['invoiceList'] = $invoiceList;
  185. $this->data ['receivablesList'] = $list;
  186. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  187. $this->data ['memu'] = "invoice";
  188. $this->data ['staff'] = $this->staff;
  189. $this->data ['receiptMemu'] = 'invoice';
  190. $this->render ( "/admin/invoice", $this->data );
  191. }
  192. function invoiceExpress() {
  193. $expressCom = isset ( $this->params ['expressCom'] ) ? $this->params ['expressCom'] : "";
  194. $expressNumber = isset ( $this->params ['expressNumber'] ) ? $this->params ['expressNumber'] : "";
  195. $this->data ['expressCom'] = $expressCom;
  196. $this->data ['expressNumber'] = $expressNumber;
  197. $this->render ( "/admin/invoiceExpress", $this->data );
  198. }
  199. function invoiceAdd() {
  200. Doo::loadModel ( 'L_category' );
  201. $lCategory = new L_category ();
  202. $category = $lCategory->find ( array (
  203. 'asArray' => true
  204. ) );
  205. $this->data ['category'] = $category;
  206. $this->data ['memu'] = "invoice";
  207. $this->data ['staff'] = $this->staff;
  208. $this->data ['receiptMemu'] = 'invoice';
  209. $this->render ( "/admin/invoiceAdd", $this->data );
  210. }
  211. /**
  212. * 提交一份开票申请,并记录下操作日志
  213. *
  214. * @since 1.0.0
  215. * @var integer cid 办事处ID
  216. * @var integer invoiceType 发票类型
  217. * @var integer doPost 是否邮寄
  218. * @var integer invoicePrice 开票金额
  219. * @var string invoiceElement 开票内容
  220. * @var string invoiceTitle 发票抬头
  221. * @var string invoiceCompany 单位名称
  222. * @var string TIN 纳税人识别码
  223. * @var string address 注册地址
  224. * @var string phone 注册电话
  225. * @var string bank 开户银行
  226. * @var string bankAccount 银行账户
  227. * @var string recipients 收件人
  228. * @var string recipientsPhone 收件人手机/电话
  229. * @var string recipientsAddress 收件地址
  230. * @var string mailItems 邮寄物品
  231. * @var string remark 备注
  232. * @return string 返回跳转开票主页路径
  233. */
  234. function invoiceAddDo() {
  235. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  236. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  237. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  238. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  239. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  240. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  241. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  242. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  243. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  244. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  245. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  246. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  247. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  248. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  249. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  250. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  251. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  252. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  253. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  254. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  255. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  256. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  257. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  258. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  259. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  260. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  261. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  262. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  263. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  264. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  265. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  266. /*
  267. * $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;
  268. */
  269. if (empty ( $this->staff [0] ))
  270. die ( 'illegal request' );
  271. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement )) {
  272. Doo::loadModel ( 'invoice' );
  273. $invoice = new invoice ();
  274. Doo::loadModel ( 'L_category' );
  275. $lCategory = new L_category ();
  276. Doo::loadModel ( 'invoiceManage' );
  277. $invoiceManage = new invoiceManage ();
  278. Doo::loadModel ( 'invoiceOperationLog' );
  279. $invoiceOperationLog = new invoiceOperationLog ();
  280. $categoryDetil = $lCategory->getOne ( array (
  281. 'SELECT' => 'title',
  282. 'where' => 'cid=' . $cid,
  283. 'asArray' => true
  284. ) );
  285. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  286. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  287. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  288. // print_r(current($invoiceManageDetail ['staffList']));
  289. // die;
  290. $moldManage = array ();
  291. foreach ( $invoiceManageList as $key => $value ) {
  292. if ($value ['mold'] == '发票打印')
  293. $moldManage [$value ['mold']] = $value ['staffList'];
  294. elseif ($value ['mold'] == '发票邮寄')
  295. $moldManage [$value ['mold']] = $value ['staffList'];
  296. elseif ($value ['mold'] == '发票退票')
  297. $moldManage [$value ['mold']] = $value ['staffList'];
  298. }
  299. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  300. $item = array (
  301. 'cid' => $cid,
  302. 'categoryName' => $categoryDetil ['title'],
  303. 'invoiceElement' => $invoiceElement,
  304. 'invoiceQuantity' => $invoiceQuantity,
  305. 'invoiceUnitPrice' => $invoiceUnitPrice,
  306. 'invoicePrice' => $invoicePrice,
  307. 'invoiceType' => $invoiceType,
  308. 'doPost' => $doPost,
  309. 'status' => 1,
  310. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  311. 'date' => date ( "Y-m-d H:i:s" ),
  312. 'updateTime' => date ( "Y-m-d H:i:s" ),
  313. 'sid' => $this->staff [0] ['sid'],
  314. 'userName' => $this->staff [0] ['username'],
  315. 'invoiceManage' => $invoiceManageDetail ['staff'],
  316. 'pendingApprovals' => $pendingApprovalsSid,
  317. 'moldManage' => json_encode ( $moldManage ),
  318. 'remark' => $remark
  319. );
  320. if ($invoiceType == 0)
  321. $item += array (
  322. 'invoiceTitle' => $invoiceTitle,
  323. 'TIN' => $TINT,
  324. 'address' => $addressT,
  325. 'phone' => $phoneT,
  326. 'bank' => $bankT,
  327. 'bankAccount' => $bankAccountT
  328. );
  329. else {
  330. $item += array (
  331. 'invoiceCompany' => $invoiceCompany,
  332. 'TIN' => $TIN,
  333. 'address' => $address,
  334. 'phone' => $phone,
  335. 'bank' => $bank,
  336. 'bankAccount' => $bankAccount
  337. );
  338. }
  339. if ($doPost == 1) {
  340. $mailList = array (
  341. 'invoice' => 1,
  342. 'mailItems' => $mailItems
  343. );
  344. if (! empty ( $softLock ))
  345. $mailList += array (
  346. 'softLock' => $softLockNum
  347. );
  348. else
  349. $mailList += array (
  350. 'softLock' => 0
  351. );
  352. if (! empty ( $contract ))
  353. $mailList += array (
  354. 'contract' => $contractNum
  355. );
  356. else
  357. $mailList += array (
  358. 'contract' => 0
  359. );
  360. if (! empty ( $instructions ))
  361. $mailList += array (
  362. 'instructions' => $instructionsNum
  363. );
  364. else
  365. $mailList += array (
  366. 'instructions' => 0
  367. );
  368. if (! empty ( $remittance ))
  369. $mailList += array (
  370. 'remittance' => $remittance
  371. );
  372. else
  373. $mailList += array (
  374. 'remittance' => ''
  375. );
  376. $mailString = '发票x1,备注:' . $mailItems;
  377. if (! empty ( $softLock ))
  378. $mailString .= ',软件锁x' . $softLockNum;
  379. if (! empty ( $contract ))
  380. $mailString .= ',合同x' . $contractNum;
  381. if (! empty ( $instructions ))
  382. $mailString .= ',说明书x' . $instructionsNum;
  383. if (! empty ( $remittance ))
  384. $mailString .= ',汇款账号单';
  385. $item += array (
  386. 'recipients' => $recipients,
  387. 'recipientsPhone' => $recipientsPhone,
  388. 'recipientsAddress' => $recipientsAddress,
  389. 'mailItems' => $mailString,
  390. 'mailItemsJson' => json_encode ( $mailList )
  391. );
  392. }
  393. $iid = $invoice->addInvoice ( $item );
  394. $item = array (
  395. 'date' => date ( "Y-m-d H:i:s" ),
  396. 'operation' => "创建",
  397. 'status' => 1,
  398. 'img' => $this->staff [0] ['avatar'],
  399. 'username' => $this->staff [0] ['username'],
  400. 'uid' => $this->staff [0] ['sid'],
  401. 'category' => $this->staff [0] ['category'],
  402. 'iid' => $iid
  403. );
  404. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  405. $item = array (
  406. 'date' => date ( "Y-m-d H:i:s" ),
  407. 'operation' => "提交审批",
  408. 'status' => 1,
  409. 'img' => $this->staff [0] ['avatar'],
  410. 'username' => $this->staff [0] ['username'],
  411. 'uid' => $this->staff [0] ['sid'],
  412. 'category' => $this->staff [0] ['category'],
  413. 'iid' => $iid
  414. );
  415. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  416. Doo::loadModel ( 'staff' );
  417. $staff = new staff ();
  418. $username2 = $staff->getOne ( array (
  419. 'select' => 'wxid',
  420. 'where' => 'sid=' . $pendingApprovalsSid,
  421. 'asArray' => TRUE
  422. ) );
  423. // 发送微信审批通知
  424. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  425. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  426. }
  427. return "/invoice";
  428. }
  429. function invoiceEdit() {
  430. Doo::loadClass ( 'XDeode' );
  431. $XDeode = new XDeode ( 5 );
  432. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  433. $iid = $XDeode->decode ( $iid );
  434. if (! is_numeric ( $iid ))
  435. die ( 'illegal request' );
  436. Doo::loadModel ( 'invoice' );
  437. $invoice = new invoice ();
  438. Doo::loadModel ( 'invoiceOperationLog' );
  439. $invoiceOperationLog = new invoiceOperationLog ();
  440. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  441. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  442. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  443. $this->data ['operation'] = $operation;
  444. $this->data ['invoiceDetail'] = $invoiceDetail;
  445. $this->data ['memu'] = "invoice";
  446. $this->data ['staff'] = $this->staff;
  447. $this->data ['receiptMemu'] = 'invoice';
  448. $this->render ( "/admin/invoiceEdit", $this->data );
  449. }
  450. /**
  451. * 重新编辑退回的发票
  452. * @return string
  453. */
  454. function invoiceEditDo() {
  455. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  456. Doo::loadModel ( 'invoice' );
  457. $invoice = new invoice ();
  458. $iid = $invoice->authcode ( $iidKey );
  459. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  460. die ( 'illegal request' );
  461. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  462. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  463. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  464. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  465. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  466. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  467. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  468. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  469. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  470. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  471. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  472. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  473. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  474. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  475. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  476. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  477. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  478. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  479. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  480. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  481. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  482. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  483. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  484. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  485. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  486. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  487. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  488. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  489. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  490. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  491. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  492. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  493. Doo::loadModel ( 'invoiceManage' );
  494. $invoiceManage = new invoiceManage ();
  495. Doo::loadModel ( 'invoiceOperationLog' );
  496. $invoiceOperationLog = new invoiceOperationLog ();
  497. $cid = explode ( ':', $cid );
  498. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  499. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  500. $moldManage = array ();
  501. foreach ( $invoiceManageList as $key => $value ) {
  502. if ($value ['mold'] == '发票打印')
  503. $moldManage [$value ['mold']] = $value ['staffList'];
  504. elseif ($value ['mold'] == '发票邮寄')
  505. $moldManage [$value ['mold']] = $value ['staffList'];
  506. elseif ($value ['mold'] == '发票打印')
  507. $moldManage [$value ['mold']] = $value ['staffList'];
  508. }
  509. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  510. $item = array (
  511. 'iid' => $iid,
  512. 'cid' => $cid [0],
  513. 'categoryName' => $cid [1],
  514. 'invoiceElement' => $invoiceElement,
  515. 'invoiceQuantity' => $invoiceQuantity,
  516. 'invoiceUnitPrice' => $invoiceUnitPrice,
  517. 'invoicePrice' => $invoicePrice,
  518. 'invoiceType' => $invoiceType,
  519. 'doPost' => $doPost,
  520. 'status' => 1,
  521. 'updateTime' => date ( "Y-m-d H:i:s" ),
  522. 'remark' => $remark
  523. );
  524. if ($invoiceType == 0)
  525. $item += array (
  526. 'invoiceTitle' => $invoiceTitle,
  527. 'TIN' => $TINT,
  528. 'address' => $addressT,
  529. 'phone' => $phoneT,
  530. 'bank' => $bankT,
  531. 'bankAccount' => $bankAccountT
  532. );
  533. else {
  534. $item += array (
  535. 'invoiceCompany' => $invoiceCompany,
  536. 'TIN' => $TIN,
  537. 'address' => $address,
  538. 'phone' => $phone,
  539. 'bank' => $bank,
  540. 'bankAccount' => $bankAccount
  541. );
  542. }
  543. if ($doPost == 1) {
  544. $mailList = array (
  545. 'invoice' => 1,
  546. 'mailItems' => $mailItems
  547. );
  548. if (! empty ( $softLock ))
  549. $mailList += array (
  550. 'softLock' => $softLockNum
  551. );
  552. else
  553. $mailList += array (
  554. 'softLock' => '0'
  555. );
  556. if (! empty ( $contract ))
  557. $mailList += array (
  558. 'contract' => $contractNum
  559. );
  560. else
  561. $mailList += array (
  562. 'contract' => '0'
  563. );
  564. if (! empty ( $instructions ))
  565. $mailList += array (
  566. 'instructions' => $instructionsNum
  567. );
  568. else
  569. $mailList += array (
  570. 'instructions' => '0'
  571. );
  572. if (! empty ( $remittance ))
  573. $mailList += array (
  574. 'remittance' => $remittance
  575. );
  576. else
  577. $mailList += array (
  578. 'remittance' => ''
  579. );
  580. $mailString = '发票x1,备注:' . $mailItems;
  581. if (! empty ( $softLock ))
  582. $mailString .= ',软件锁x' . $softLockNum;
  583. if (! empty ( $contract ))
  584. $mailString .= ',合同x' . $contractNum;
  585. if (! empty ( $instructions ))
  586. $mailString .= ',说明书x' . $instructionsNum;
  587. if (! empty ( $remittance ))
  588. $mailString .= ',汇款账号单';
  589. $item += array (
  590. 'recipients' => $recipients,
  591. 'recipientsPhone' => $recipientsPhone,
  592. 'recipientsAddress' => $recipientsAddress,
  593. 'mailItems' => $mailString,
  594. 'mailItemsJson' => json_encode ( $mailList )
  595. );
  596. }
  597. $invoice->setInvoiceByCondition ( $item );
  598. $item = array (
  599. 'date' => date ( "Y-m-d H:i:s" ),
  600. 'operation' => "重新提交审批",
  601. 'status' => 1,
  602. 'img' => $this->staff [0] ['avatar'],
  603. 'username' => $this->staff [0] ['username'],
  604. 'uid' => $this->staff [0] ['sid'],
  605. 'category' => $this->staff [0] ['category'],
  606. 'iid' => $iid
  607. );
  608. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  609. }
  610. return "/invoice";
  611. }
  612. /**
  613. * 培训班
  614. */
  615. function invoiceTraining() {
  616. Doo::loadModel ( 'L_category' );
  617. $lCategory = new L_category ();
  618. Doo::loadModel ( 'invoiceTraining' );
  619. $invoiceTraining = new invoiceTraining ();
  620. $itTodoList = $invoiceTraining->getInvoiceTrainingByTodo ( '', $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  621. $itedList = $invoiceTraining->getInvoiceTrainingByStatus ( 2, '', $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  622. $category = $lCategory->getCategory ();
  623. $itid = array ();
  624. foreach ( $itTodoList as $value ) {
  625. array_push ( $itid, $value ['itid'] );
  626. }
  627. foreach ( $itedList as $value ) {
  628. array_push ( $itid, $value ['itid'] );
  629. }
  630. $itid = implode ( ',', $itid );
  631. $this->data ['itStatist'] = $invoiceTraining->getInvoiceTrainStatistics ( $itid );
  632. // print_r($itTodoList);
  633. $this->data ['trainCount'] = count ( $itTodoList ) + count ( $itedList );
  634. $this->data ['itTodoList'] = $itTodoList;
  635. $this->data ['itedList'] = $itedList;
  636. $this->data ['category'] = $category;
  637. $this->data ['memu'] = "invoice";
  638. $this->data ['staff'] = $this->staff;
  639. $this->data ['receiptMemu'] = 'invoiceTraining';
  640. $this->render ( "/admin/invoiceTraining", $this->data );
  641. }
  642. /**
  643. * 创建培训班
  644. */
  645. function invoiceTrainingAdd() {
  646. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  647. $trainName = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  648. $trainDate = $this->get_args ( 'trainDate' ) ? $this->get_args ( 'trainDate' ) : "";
  649. if (empty ( $this->staff [0] ))
  650. die ( 'illegal request' );
  651. if (! empty ( $cid ) && ! empty ( $trainName ) && ! empty ( $trainDate )) {
  652. Doo::loadModel ( 'invoiceTraining' );
  653. $invoiceTraining = new invoiceTraining ();
  654. Doo::loadModel ( 'invoice' );
  655. $invoice = new invoice ();
  656. Doo::loadModel ( 'L_category' );
  657. $lCategory = new L_category ();
  658. Doo::loadModel ( 'invoiceManage' );
  659. $invoiceManage = new invoiceManage ();
  660. Doo::loadModel ( 'invoiceOperationLog' );
  661. $invoiceOperationLog = new invoiceOperationLog ();
  662. $item = array (
  663. 'cid' => $cid,
  664. 'trainName' => $trainName,
  665. 'trainDate' => $trainDate,
  666. 'creator' => $this->staff [0] ['sid'],
  667. 'creatorDate' => date ( "Y-m-d H:i:s" )
  668. );
  669. $itid = $invoiceTraining->addInvoiceTraining ( $item );
  670. }
  671. return "/invoiceTraining";
  672. }
  673. /**
  674. * 删除培训班
  675. */
  676. function invoiceTrainingDelDo() {
  677. $itid = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  678. if (! empty ( $itid )) {
  679. Doo::loadModel ( 'invoiceTraining' );
  680. $invoiceTraining = new invoiceTraining ();
  681. $invoiceTraining->delInvoiceTrainingByItid ( $itid );
  682. }
  683. return "/invoiceTraining";
  684. }
  685. /**
  686. * 培训班详情
  687. */
  688. function invoiceTrainingDetail() {
  689. $trainStatus = $this->get_args ( 'trainStatus' ) ? $this->get_args ( 'trainStatus' ) : "ALL";
  690. $itid = isset ( $this->params ['trainingKey'] ) ? $this->params ['trainingKey'] : "";
  691. Doo::loadModel ( 'invoiceTraining' );
  692. $invoiceTraining = new invoiceTraining ();
  693. Doo::loadModel ( 'invoiceStore' );
  694. $invoiceStore = new invoiceStore ();
  695. if (empty ( $itid ))
  696. die ( 'illegal request' );
  697. $detail = $invoiceTraining->getInvoiceTrainingByItid ( $itid );
  698. $isList = $invoiceStore->getinvoiceStoreByItid ( $itid );
  699. // print_r($isList);
  700. $trainlist = array ();
  701. foreach ( $isList as $key => $value ) {
  702. $irDetail = array ();
  703. if ($value ['apStatus'] == 1) {
  704. // array_push ( $irDetail, '' );
  705. array_push ( $irDetail, '<input class="hide" disabled type="checkbox" >' );
  706. } else {
  707. array_push ( $irDetail, '<input type="checkbox" class="hide" id="' . $value ['storeKey'] . '" name="isBox" value="' . $value ['storeKey'] . '" > <a href="/invoiceStoreEdit/' . $value ['storeKey'] . '.html">编辑</a>
  708. <a href="#confirm" onclick="invoiceStoreApproval(\'' . $value ['storeKey'] . '\')" data-toggle="modal">提交审批</a>
  709. <a href="#del" node-iStore="del" data-key="' . $value ['storeKey'] . '" onclick="invoiceStoreDel(\'' . $value ['storeKey'] . '\')" data-toggle="modal" class="colRed">移除</a>' );
  710. }
  711. array_push ( $irDetail, $value ['invoiceSerial'] );
  712. if ($value ['invoiceType'] == 1)
  713. array_push ( $irDetail, $value ['invoiceCompany'] );
  714. else
  715. array_push ( $irDetail, $value ['invoiceTitle'] );
  716. array_push ( $irDetail, $value ['TIN'] );
  717. array_push ( $irDetail, $value ['userName'] );
  718. if (empty ( $value ['mailItems'] ) && $value ['apStatus'] != 1) {
  719. array_push ( $irDetail, '<a href="#confirm-erro" onclick="invoiceStoreMail(\'' . $value ['storeKey'] . '\')" data-toggle="modal">设置邮寄物品</a>' );
  720. } else
  721. array_push ( $irDetail, $value ['mailItems'] );
  722. array_push ( $irDetail, $value ['recipientsAddress'] . $value ['recipients'] . $value ['recipientsPhone'] );
  723. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  724. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  725. array_push ( $irDetail, $value ['invoiceElement'] );
  726. array_push ( $irDetail, $value ['invoiceQuantity'] );
  727. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  728. if ($value ['invoiceType'] == 1)
  729. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  730. else
  731. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  732. array_push ( $irDetail, $value ['remark'] );
  733. if ($value ['status'] == 1)
  734. array_push ( $irDetail, '审批中' );
  735. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1)
  736. array_push ( $irDetail, '已出票' );
  737. elseif ($value ['status'] == 2 && $value ['printStatus'] == 1 && $value ['printStatus'] != 'irid' && ($value ['untreadStatus'] == 3 || $value ['untreadStatus'] == 0))
  738. array_push ( $irDetail, '已入账' );
  739. else
  740. array_push ( $irDetail, '' );
  741. array_push ( $irDetail, $value ['invoiceNo'] );
  742. array_push ( $irDetail, $value ['printTime'] );
  743. $html = '';
  744. foreach ( $value ['invoiceReceivables'] as $value ) {
  745. $html .= '&nbsp;<a href="#billing" node-invoice="INFO" data-type="receivables" data-iskey="' . $value [2] . '" data-toggle="modal">' . $value [1] . '</a>';
  746. }
  747. array_push ( $irDetail, $html );
  748. array_push ( $trainlist, $irDetail );
  749. }
  750. $trainlistJson = json_encode ( $trainlist );
  751. if (empty ( $detail ))
  752. die ( 'illegal request' );
  753. $this->data ['trainStatus'] = $trainStatus;
  754. $this->data ['itid'] = $itid;
  755. $this->data ['trainlistJson'] = $trainlistJson;
  756. $this->data ['iTrainDetail'] = $detail;
  757. $this->data ['memu'] = "invoice";
  758. $this->data ['staff'] = $this->staff;
  759. $this->data ['receiptMemu'] = 'invoiceTraining';
  760. $this->render ( "/admin/invoiceTrainingDetail", $this->data );
  761. }
  762. /**
  763. * 上传培训班发票
  764. * @return string
  765. */
  766. function invoiceTrainingUpload() {
  767. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  768. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  769. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  770. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  771. header ( "HTTP/1.1 500 Internal Server Error" );
  772. echo "POST exceeded maximum allowed size.";
  773. exit ( 0 );
  774. }
  775. // Settings
  776. $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)
  777. $upload_name = "Filedata";
  778. $max_file_size_in_bytes = 2147483647; // 2GB in bytes
  779. $extension_whitelist = array (
  780. "doc",
  781. "txt",
  782. "jpg",
  783. "gif",
  784. "png"
  785. ); // Allowed file extensions
  786. $valid_chars_regex = '.A-Z0-9_ !@#$%^&()+={}\[\]\',~`-'; // Characters allowed in the file name (in a Regular Expression format)
  787. // Other variables
  788. $MAX_FILENAME_LENGTH = 260;
  789. $file_name = "";
  790. $file_extension = "";
  791. $uploadErrors = array (
  792. 0 => "文件上传成功",
  793. 1 => "上传的文件超过了 php.ini 文件中的 upload_max_filesize directive 里的设置",
  794. 2 => "上传的文件超过了 HTML form 文件中的 MAX_FILE_SIZE directive 里的设置",
  795. 3 => "上传的文件仅为部分文件",
  796. 4 => "没有文件上传",
  797. 6 => "缺少临时文件夹"
  798. );
  799. $nk = time ();
  800. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  801. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  802. echo "文件无法保存.";
  803. exit ( 0 );
  804. }
  805. // Return output to the browser (only supported by SWFUpload for Flash Player 9)
  806. echo json_encode ( array (
  807. 'filename' => $file_name,
  808. 'id' => $nk
  809. ) );
  810. exit ( 0 );
  811. }
  812. /**
  813. * 导入发票临时仓库
  814. */
  815. function invoiceStoreImport() {
  816. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  817. $trainingKey = $this->get_args ( 'trainingKey' ) ? $this->get_args ( 'trainingKey' ) : "";
  818. $path = $this->get_args ( 'trainName' ) ? $this->get_args ( 'trainName' ) : "";
  819. if ($path != "" && ! empty ( $trainingKey )) {
  820. Doo::loadModel ( 'invoiceStore' );
  821. Doo::loadModel ( 'staff' );
  822. $staff = new staff ();
  823. Doo::loadModel ( 'invoiceTraining' );
  824. $invoiceTraining = new invoiceTraining ();
  825. Doo::loadClass ( 'XDeode' );
  826. $XDeode = new XDeode ( 5 );
  827. $itid = $XDeode->decode ( $trainingKey );
  828. $exlArray = $this->formatExcelToArrayTrain ( DOO::conf ()->SITE_PATH . "upload/invoiceTraining/" . $path );
  829. $userName = $this->staff [0] ['username'];
  830. $sDetail = $staff->getStaffByName ( $userName );
  831. // die('sdd');
  832. // 可以优化
  833. foreach ( $exlArray as $key => $value ) {
  834. // 开票
  835. $invoice = new invoiceStore ();
  836. $invoice->trainId = $itid;
  837. $invoice->invoiceType = 0;
  838. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  839. $invoice->invoiceType = 1;
  840. $invoice->invoiceQuantity = $value ['invoiceQuantity'];
  841. $invoice->invoiceUnitPrice = $value ['invoiceUnitPrice'];
  842. $invoice->invoicePrice = $value ['invoiceQuantity'] * $value ['invoiceUnitPrice'];
  843. $invoice->invoiceTitle = $value ['invoiceTitle'];
  844. if ($value ['invoiceType'] == '专' || $value ['invoiceType'] == '专票')
  845. $invoice->invoiceCompany = $value ['invoiceTitle'];
  846. $invoice->userName = $userName;
  847. $invoice->sid = $sDetail ['sid'];
  848. $invoice->cid = $sDetail ['cid'];
  849. $invoice->categoryName = $sDetail ['category'];
  850. $invoice->invoiceElement = $value ['invoiceElement'];
  851. $invoice->remark = $value ['remark'];
  852. // $invoice->date = $value ['date'];
  853. // $invoice->printTime = $value ['date'];
  854. $invoice->ipSource = 1;
  855. $invoice->printStatus = 1;
  856. $invoice->status = 2;
  857. $invoice->postStatus = 1;
  858. $invoice->untreadStatus = 0;
  859. // $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  860. $invoice->TIN = $value ['TIN'];
  861. $invoice->address = $value ['address'];
  862. $invoice->phone = $value ['phone'];
  863. $invoice->bank = $value ['bank'];
  864. $invoice->bankAccount = $value ['bankAccount'];
  865. $invoice->recipientsAddress = $value ['recipientsAddress'];
  866. $invoice->recipients = $value ['recipients'];
  867. $invoice->recipientsPhone = $value ['recipientsPhone'];
  868. $iid = $invoice->insert ();
  869. }
  870. // 加入发票总数量
  871. $item = array (
  872. 'itid' => $itid,
  873. 'invoiceTotal' => count ( $exlArray )
  874. );
  875. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  876. return '/invoiceTrainingDetail/' . $trainingKey . ".html";
  877. }
  878. echo 'no file';
  879. }
  880. /**
  881. * 编辑仓库里的发票
  882. */
  883. function invoiceStoreEdit() {
  884. Doo::loadClass ( 'XDeode' );
  885. $XDeode = new XDeode ( 5 );
  886. $iid = isset ( $this->params ['storeKey'] ) ? $this->params ['storeKey'] : "";
  887. $iid = $XDeode->decode ( $iid );
  888. if (! is_numeric ( $iid ))
  889. die ( 'illegal request' );
  890. Doo::loadModel ( 'invoiceStore' );
  891. $invoiceStore = new invoiceStore ();
  892. $invoiceDetail = $invoiceStore->getInvoiceStoreByIsid ( $iid );
  893. // print_r($invoiceDetail);
  894. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  895. $this->data ['invoiceDetail'] = $invoiceDetail;
  896. $this->data ['memu'] = "invoice";
  897. $this->data ['staff'] = $this->staff;
  898. $this->data ['receiptMemu'] = 'invoiceTraining';
  899. $this->render ( "/admin/invoiceStoreEdit", $this->data );
  900. }
  901. function invoiceStoreEditDo() {
  902. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  903. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  904. Doo::loadModel ( 'invoiceStore' );
  905. $invoice = new invoiceStore ();
  906. Doo::loadClass ( 'XDeode' );
  907. $XDeode = new XDeode ( 5 );
  908. $iid = $XDeode->decode ( $storeKey );
  909. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  910. die ( 'illegal request' );
  911. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  912. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  913. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  914. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  915. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  916. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  917. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  918. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  919. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  920. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  921. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  922. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  923. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  924. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  925. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  926. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  927. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  928. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  929. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  930. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  931. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  932. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  933. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  934. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  935. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  936. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  937. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  938. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  939. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  940. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  941. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  942. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  943. $cid = explode ( ':', $cid );
  944. $invoicePrice = $invoiceQuantity * $invoiceUnitPrice;
  945. $item = array (
  946. 'isid' => $iid,
  947. 'cid' => $cid [0],
  948. 'categoryName' => $cid [1],
  949. 'invoiceElement' => $invoiceElement,
  950. 'invoiceQuantity' => $invoiceQuantity,
  951. 'invoiceUnitPrice' => $invoiceUnitPrice,
  952. 'invoicePrice' => $invoicePrice,
  953. 'invoiceType' => $invoiceType,
  954. 'doPost' => $doPost,
  955. 'status' => 1,
  956. 'updateTime' => date ( "Y-m-d H:i:s" ),
  957. 'remark' => $remark
  958. );
  959. if ($invoiceType == 0)
  960. $item += array (
  961. 'invoiceTitle' => $invoiceTitle,
  962. 'TIN' => $TINT,
  963. 'address' => $addressT,
  964. 'phone' => $phoneT,
  965. 'bank' => $bankT,
  966. 'bankAccount' => $bankAccountT
  967. );
  968. else {
  969. $item += array (
  970. 'invoiceCompany' => $invoiceCompany,
  971. 'TIN' => $TIN,
  972. 'address' => $address,
  973. 'phone' => $phone,
  974. 'bank' => $bank,
  975. 'bankAccount' => $bankAccount
  976. );
  977. }
  978. if ($doPost == 1) {
  979. $mailList = array (
  980. 'invoice' => 1,
  981. 'mailItems' => $mailItems
  982. );
  983. if (! empty ( $softLock ))
  984. $mailList += array (
  985. 'softLock' => $softLockNum
  986. );
  987. else
  988. $mailList += array (
  989. 'softLock' => '0'
  990. );
  991. if (! empty ( $contract ))
  992. $mailList += array (
  993. 'contract' => $contractNum
  994. );
  995. else
  996. $mailList += array (
  997. 'contract' => '0'
  998. );
  999. if (! empty ( $instructions ))
  1000. $mailList += array (
  1001. 'instructions' => $instructionsNum
  1002. );
  1003. else
  1004. $mailList += array (
  1005. 'instructions' => '0'
  1006. );
  1007. if (! empty ( $remittance ))
  1008. $mailList += array (
  1009. 'remittance' => $remittance
  1010. );
  1011. else
  1012. $mailList += array (
  1013. 'remittance' => ''
  1014. );
  1015. $mailString = '发票x1,备注:' . $mailItems;
  1016. if (! empty ( $softLock ))
  1017. $mailString .= ',软件锁x' . $softLockNum;
  1018. if (! empty ( $contract ))
  1019. $mailString .= ',合同x' . $contractNum;
  1020. if (! empty ( $instructions ))
  1021. $mailString .= ',说明书x' . $instructionsNum;
  1022. if (! empty ( $remittance ))
  1023. $mailString .= ',汇款账号单';
  1024. $item += array (
  1025. 'recipients' => $recipients,
  1026. 'recipientsPhone' => $recipientsPhone,
  1027. 'recipientsAddress' => $recipientsAddress,
  1028. 'mailItems' => $mailString,
  1029. 'mailItemsJson' => json_encode ( $mailList )
  1030. );
  1031. }
  1032. $invoice->setInvoiceStoreByCondition ( $item );
  1033. }
  1034. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1035. }
  1036. /**
  1037. *
  1038. * @return string
  1039. */
  1040. function invoiceStoreDelete() {
  1041. Doo::loadClass ( 'XDeode' );
  1042. $XDeode = new XDeode ( 5 );
  1043. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1044. $iStoreKey = $this->get_args ( 'iStoreKey' ) ? $this->get_args ( 'iStoreKey' ) : 0;
  1045. $isid = $XDeode->decode ( $iStoreKey );
  1046. $itid = $XDeode->decode ( $trainKey );
  1047. if (! is_numeric ( $isid ))
  1048. die ( 'illegal request' );
  1049. Doo::loadModel ( 'invoiceStore' );
  1050. $invoiceStore = new invoiceStore ();
  1051. $invoiceStore->delete ( array (
  1052. 'where' => 'isid=' . $isid,
  1053. 'limit' => 1
  1054. ) );
  1055. Doo::loadModel ( 'invoiceTraining' );
  1056. $invoiceTraining = new invoiceTraining ();
  1057. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1058. $item = array (
  1059. 'itid' => $itid,
  1060. 'invoiceTotal' => $itDetail ['invoiceTotal'] - 1
  1061. );
  1062. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1063. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1064. }
  1065. /**
  1066. * 批量删除库里发票
  1067. */
  1068. function invoiceStoreBatchDelete() {
  1069. Doo::loadClass ( 'XDeode' );
  1070. $XDeode = new XDeode ( 5 );
  1071. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1072. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1073. $tid = $XDeode->decode ( $trainKey );
  1074. if (! is_numeric ( $tid ) && ! empty ( $storeKey ))
  1075. die ( 'illegal request' );
  1076. Doo::loadModel ( 'invoiceStore' );
  1077. $isidKeyList = explode ( ',', $storeKey );
  1078. $isidList = array ();
  1079. foreach ( $isidKeyList as $value ) {
  1080. $isid = $XDeode->decode ( $value );
  1081. if (! empty ( $isid ) && is_numeric ( $isid ))
  1082. array_push ( $isidList, $isid );
  1083. }
  1084. $isidString = implode ( ',', $isidList );
  1085. $invoiceStore = new invoiceStore ();
  1086. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,apStatus' );
  1087. $isidList = array ();
  1088. foreach ( $isList as $key => $value ) {
  1089. if ($value ['apStatus'] == 0)
  1090. array_push ( $isidList, $value ['isid'] );
  1091. }
  1092. $isidString = implode ( ',', $isidList );
  1093. // print_r($isList);
  1094. // echo $isidString;
  1095. $invoiceStore = new invoiceStore ();
  1096. $invoiceStore->delete ( array (
  1097. 'where' => "isid in ( " . $isidString . ")",
  1098. 'asArray' => TRUE
  1099. ) );
  1100. Doo::loadModel ( 'invoiceTraining' );
  1101. $invoiceTraining = new invoiceTraining ();
  1102. $itDetail = $invoiceTraining->getInvoiceTrainingByItid ( $trainKey );
  1103. $item = array (
  1104. 'itid' => $tid,
  1105. 'invoiceTotal' => $itDetail ['invoiceTotal'] - count ( $isidList )
  1106. );
  1107. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1108. // echo $tid;
  1109. // echo $storeKey;
  1110. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1111. }
  1112. /**
  1113. * 仓库发票提交审批
  1114. * @return string
  1115. */
  1116. function invoiceStoreApproval() {
  1117. Doo::loadClass ( 'XDeode' );
  1118. $XDeode = new XDeode ( 5 );
  1119. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1120. $iStoreKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1121. $isid = $XDeode->decode ( $iStoreKey );
  1122. $trainId = $XDeode->decode ( $trainKey );
  1123. if (! is_numeric ( $isid ))
  1124. die ( 'illegal request' );
  1125. Doo::loadModel ( 'invoiceStore' );
  1126. Doo::loadModel ( 'invoice' );
  1127. $invoice = new invoice ();
  1128. // 加入限制必须填写入开票内容和邮寄物品
  1129. $invoiceStore = new invoiceStore ();
  1130. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1131. if (empty ( $isDetail ['invoiceElement'] ) || empty ( $isDetail ['mailItemsJson'] )) {
  1132. header ( 'Content-Type:text/html;charset=utf-8' );
  1133. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1134. }
  1135. // 拷贝插入一条发票数据
  1136. $invoiceStore = new invoiceStore ();
  1137. $iid = $invoiceStore->setInvoiceStoreToApproval ( $isid );
  1138. $invoiceStore = new invoiceStore ();
  1139. $item = array (
  1140. 'isid' => $isid,
  1141. 'iid' => $iid,
  1142. 'apStatus' => 1
  1143. );
  1144. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1145. Doo::loadModel ( 'invoiceManage' );
  1146. $invoiceManage = new invoiceManage ();
  1147. Doo::loadModel ( 'invoiceOperationLog' );
  1148. $invoiceOperationLog = new invoiceOperationLog ();
  1149. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1150. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1151. $moldManage = array ();
  1152. foreach ( $invoiceManageList as $key => $value ) {
  1153. if ($value ['mold'] == '发票打印')
  1154. $moldManage [$value ['mold']] = $value ['staffList'];
  1155. elseif ($value ['mold'] == '发票邮寄')
  1156. $moldManage [$value ['mold']] = $value ['staffList'];
  1157. elseif ($value ['mold'] == '发票退票')
  1158. $moldManage [$value ['mold']] = $value ['staffList'];
  1159. }
  1160. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1161. $item = array (
  1162. 'iid' => $iid,
  1163. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1164. 'date' => date ( "Y-m-d H:i:s" ),
  1165. 'status' => 1,
  1166. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1167. 'trainId' => $trainId,
  1168. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1169. 'moldManage' => json_encode ( $moldManage ),
  1170. 'pendingApprovals' => $pendingApprovalsSid
  1171. );
  1172. $invoice->setInvoiceByCondition ( $item );
  1173. Doo::loadModel ( 'invoiceTraining' );
  1174. $invoiceTraining = new invoiceTraining ();
  1175. $item = array (
  1176. 'itid' => $trainId,
  1177. 'submitStatus' => 1
  1178. );
  1179. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1180. $item = array (
  1181. 'date' => date ( "Y-m-d H:i:s" ),
  1182. 'operation' => "创建",
  1183. 'status' => 1,
  1184. 'img' => $this->staff [0] ['avatar'],
  1185. 'username' => $this->staff [0] ['username'],
  1186. 'uid' => $this->staff [0] ['sid'],
  1187. 'category' => $this->staff [0] ['category'],
  1188. 'iid' => $iid
  1189. );
  1190. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1191. $item = array (
  1192. 'date' => date ( "Y-m-d H:i:s" ),
  1193. 'operation' => "提交审批",
  1194. 'status' => 1,
  1195. 'img' => $this->staff [0] ['avatar'],
  1196. 'username' => $this->staff [0] ['username'],
  1197. 'uid' => $this->staff [0] ['sid'],
  1198. 'category' => $this->staff [0] ['category'],
  1199. 'iid' => $iid
  1200. );
  1201. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1202. Doo::loadModel ( 'staff' );
  1203. $staff = new staff ();
  1204. $username2 = $staff->getOne ( array (
  1205. 'select' => 'wxid',
  1206. 'where' => 'sid=' . $pendingApprovalsSid,
  1207. 'asArray' => TRUE
  1208. ) );
  1209. // 发送微信审批通知
  1210. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1211. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1212. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1213. }
  1214. /**
  1215. * 批量提交发票
  1216. * @return string
  1217. */
  1218. function invoiceStoreBatchApproval() {
  1219. Doo::loadClass ( 'XDeode' );
  1220. $XDeode = new XDeode ( 5 );
  1221. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1222. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : 0;
  1223. $trainId = $XDeode->decode ( $trainKey );
  1224. $isidKeyList = explode ( ',', $storeKey );
  1225. $isidList = array ();
  1226. foreach ( $isidKeyList as $value ) {
  1227. $isid = $XDeode->decode ( $value );
  1228. if (! empty ( $isid ) && is_numeric ( $isid ))
  1229. array_push ( $isidList, $isid );
  1230. }
  1231. $isidString = implode ( ',', $isidList );
  1232. if (! is_numeric ( $trainId ))
  1233. die ( 'illegal request' );
  1234. Doo::loadModel ( 'invoiceStore' );
  1235. Doo::loadModel ( 'invoice' );
  1236. // 判断哪些已经加入审批过
  1237. // 加入限制必须填写入开票内容和邮寄物品
  1238. $invoiceStore = new invoiceStore ();
  1239. $isList = $invoiceStore->getInvoiceStoreInIsid ( $isidString, 'isid,trainId ,invoiceElement,mailItemsJson' );
  1240. foreach ( $isList as $key => $value ) {
  1241. if (empty ( $value ['invoiceElement'] ) || empty ( $value ['mailItemsJson'] )) {
  1242. header ( 'Content-Type:text/html;charset=utf-8' );
  1243. die ( 'illegal request! 请设置开票内容或邮寄物品' );
  1244. }
  1245. }
  1246. // 拷贝插入一条发票数据
  1247. $invoiceStore = new invoiceStore ();
  1248. $invoiceStore->setInvoiceStoreBatchToApproval ( $isidString );
  1249. $invoiceStore = new invoiceStore ();
  1250. $item = array (
  1251. 'apStatus' => 1
  1252. );
  1253. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1254. // 获得正式发票ID
  1255. $invoice = new invoice ();
  1256. $iidList = $invoice->getInvoiceByIstoreid ( $isidString, 'iid,isid' );
  1257. $sqlList = array ();
  1258. $iidString = '';
  1259. $iida = array ();
  1260. foreach ( $iidList as $key => $value ) {
  1261. $sqlList [$value ['isid']] = $value ['iid'];
  1262. array_push ( $iida, $value ['iid'] );
  1263. }
  1264. $iidString = implode ( ',', $iida );
  1265. $ids = implode ( ',', array_keys ( $sqlList ) );
  1266. $sql = "UPDATE CLD_invoiceStore SET iid = CASE isid ";
  1267. foreach ( $sqlList as $id => $ordinal ) {
  1268. $sql .= sprintf ( "WHEN %d THEN %d ", $id, $ordinal );
  1269. }
  1270. $sql .= "END WHERE isid IN ($ids)";
  1271. $invoiceStore = new invoiceStore ();
  1272. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1273. Doo::loadModel ( 'invoiceManage' );
  1274. $invoiceManage = new invoiceManage ();
  1275. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  1276. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  1277. $moldManage = array ();
  1278. foreach ( $invoiceManageList as $key => $value ) {
  1279. if ($value ['mold'] == '发票打印')
  1280. $moldManage [$value ['mold']] = $value ['staffList'];
  1281. elseif ($value ['mold'] == '发票邮寄')
  1282. $moldManage [$value ['mold']] = $value ['staffList'];
  1283. elseif ($value ['mold'] == '发票退票')
  1284. $moldManage [$value ['mold']] = $value ['staffList'];
  1285. }
  1286. $pendingApprovalsSid = current ( $invoiceManageDetail ['staffList'] ) [0];
  1287. // 批量更新发票信息
  1288. $item = array (
  1289. 'date' => date ( "Y-m-d H:i:s" ),
  1290. 'status' => 1,
  1291. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1292. 'trainId' => $trainId,
  1293. 'invoiceManage' => $invoiceManageDetail ['staff'],
  1294. 'moldManage' => json_encode ( $moldManage ),
  1295. 'pendingApprovals' => $pendingApprovalsSid
  1296. );
  1297. $invoice = new invoice ();
  1298. $invoice->BatchInvoiceByCondition ( $item, $iidString );
  1299. // 批量更新发票序列号
  1300. $sqlList = array ();
  1301. foreach ( $iida as $value ) {
  1302. $sqlList [$value] = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1303. }
  1304. $ids = implode ( ',', array_keys ( $sqlList ) );
  1305. $sql = "UPDATE CLD_invoice SET invoiceSerial = CASE iid ";
  1306. foreach ( $sqlList as $id => $ordinal ) {
  1307. $sql .= sprintf ( "WHEN %d THEN '%s' ", $id, $ordinal );
  1308. }
  1309. $sql .= "END WHERE iid IN ($ids)";
  1310. $invoiceStore = new invoiceStore ();
  1311. $invoiceStore->UpdateBatchInvoiceStore ( $sql );
  1312. // 批量生产操作日志
  1313. Doo::loadModel ( 'invoiceOperationLog' );
  1314. $sqlList = array ();
  1315. foreach ( $iida as $key => $value ) {
  1316. $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 . '"),
  1317. ("' . 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 . '") ';
  1318. array_push ( $sqlList, $sql );
  1319. }
  1320. $iolSql = implode ( ',', $sqlList );
  1321. $sql = "INSERT INTO `CLD_invoiceOperationLog` (`date`, `operation`, `status`, `img`, `username`, `uid`, `category`, `iid`) VALUES " . $iolSql;
  1322. $invoiceOperationLog = new invoiceOperationLog ();
  1323. $invoiceOperationLog->setInvoiceOperationLogBySql ( $sql );
  1324. Doo::loadModel ( 'invoiceTraining' );
  1325. $invoiceTraining = new invoiceTraining ();
  1326. $item = array (
  1327. 'itid' => $trainId,
  1328. 'submitStatus' => 1
  1329. );
  1330. $invoiceTraining->setInvoiceTrainByCondition ( $item );
  1331. Doo::loadModel ( 'staff' );
  1332. $staff = new staff ();
  1333. $username2 = $staff->getOne ( array (
  1334. 'select' => 'wxid',
  1335. 'where' => 'sid=' . $pendingApprovalsSid,
  1336. 'asArray' => TRUE
  1337. ) );
  1338. // 发送微信审批通知
  1339. $title2 = '[通知]用户提交了一条开票申请,快到“我的发票”中查看,给用户确认审批。';
  1340. $this->msgSend ( '', $title2, '', $username2 ['wxid'], $pendingApprovalsSid, 'approval' );
  1341. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1342. }
  1343. /**
  1344. */
  1345. function invoiceStoreMailItemSet() {
  1346. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1347. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1348. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1349. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1350. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1351. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1352. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1353. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1354. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1355. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1356. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1357. Doo::loadClass ( 'XDeode' );
  1358. $XDeode = new XDeode ( 5 );
  1359. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1360. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1361. $isid = $XDeode->decode ( $storeKey );
  1362. $trainId = $XDeode->decode ( $trainKey );
  1363. if (! is_numeric ( $isid ))
  1364. die ( 'illegal request' );
  1365. Doo::loadModel ( 'invoiceStore' );
  1366. $invoiceStore = new invoiceStore ();
  1367. $mailList = array (
  1368. 'invoice' => 1,
  1369. 'mailItems' => $mailItems
  1370. );
  1371. if (! empty ( $softLock ))
  1372. $mailList += array (
  1373. 'softLock' => $softLockNum
  1374. );
  1375. else
  1376. $mailList += array (
  1377. 'softLock' => 0
  1378. );
  1379. if (! empty ( $contract ))
  1380. $mailList += array (
  1381. 'contract' => $contractNum
  1382. );
  1383. else
  1384. $mailList += array (
  1385. 'contract' => 0
  1386. );
  1387. if (! empty ( $instructions ))
  1388. $mailList += array (
  1389. 'instructions' => $instructionsNum
  1390. );
  1391. else
  1392. $mailList += array (
  1393. 'instructions' => 0
  1394. );
  1395. if (! empty ( $remittance ))
  1396. $mailList += array (
  1397. 'remittance' => $remittance
  1398. );
  1399. else
  1400. $mailList += array (
  1401. 'remittance' => ''
  1402. );
  1403. $mailString = '发票x1,备注:' . $mailItems;
  1404. if (! empty ( $softLock ))
  1405. $mailString .= ',软件锁x' . $softLockNum;
  1406. if (! empty ( $contract ))
  1407. $mailString .= ',合同x' . $contractNum;
  1408. if (! empty ( $instructions ))
  1409. $mailString .= ',说明书x' . $instructionsNum;
  1410. if (! empty ( $remittance ))
  1411. $mailString .= ',汇款账号单';
  1412. $item = array (
  1413. 'isid' => $isid,
  1414. 'doPost' => 1,
  1415. 'mailItems' => $mailString,
  1416. 'mailItemsJson' => json_encode ( $mailList )
  1417. );
  1418. $invoiceStore->setInvoiceStoreByCondition ( $item );
  1419. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1420. }
  1421. /**
  1422. * 批量设置邮寄物品
  1423. */
  1424. function invoiceStoreBatchMailItemSet() {
  1425. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  1426. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  1427. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  1428. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  1429. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  1430. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  1431. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  1432. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  1433. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  1434. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  1435. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  1436. Doo::loadClass ( 'XDeode' );
  1437. $XDeode = new XDeode ( 5 );
  1438. $trainKey = $this->get_args ( 'trainKey' ) ? $this->get_args ( 'trainKey' ) : '';
  1439. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1440. $isidKeyList = explode ( ',', $storeKey );
  1441. $isidList = array ();
  1442. foreach ( $isidKeyList as $value ) {
  1443. $isid = $XDeode->decode ( $value );
  1444. if (! empty ( $isid ) && is_numeric ( $isid ))
  1445. array_push ( $isidList, $isid );
  1446. }
  1447. $isidString = implode ( ',', $isidList );
  1448. $trainId = $XDeode->decode ( $trainKey );
  1449. if (! is_numeric ( $isid ))
  1450. die ( 'illegal request' );
  1451. Doo::loadModel ( 'invoiceStore' );
  1452. $invoiceStore = new invoiceStore ();
  1453. $mailList = array (
  1454. 'invoice' => 1,
  1455. 'mailItems' => $mailItems
  1456. );
  1457. if (! empty ( $softLock ))
  1458. $mailList += array (
  1459. 'softLock' => $softLockNum
  1460. );
  1461. else
  1462. $mailList += array (
  1463. 'softLock' => 0
  1464. );
  1465. if (! empty ( $contract ))
  1466. $mailList += array (
  1467. 'contract' => $contractNum
  1468. );
  1469. else
  1470. $mailList += array (
  1471. 'contract' => 0
  1472. );
  1473. if (! empty ( $instructions ))
  1474. $mailList += array (
  1475. 'instructions' => $instructionsNum
  1476. );
  1477. else
  1478. $mailList += array (
  1479. 'instructions' => 0
  1480. );
  1481. if (! empty ( $remittance ))
  1482. $mailList += array (
  1483. 'remittance' => $remittance
  1484. );
  1485. else
  1486. $mailList += array (
  1487. 'remittance' => ''
  1488. );
  1489. $mailString = '发票x1,备注:' . $mailItems;
  1490. if (! empty ( $softLock ))
  1491. $mailString .= ',软件锁x' . $softLockNum;
  1492. if (! empty ( $contract ))
  1493. $mailString .= ',合同x' . $contractNum;
  1494. if (! empty ( $instructions ))
  1495. $mailString .= ',说明书x' . $instructionsNum;
  1496. if (! empty ( $remittance ))
  1497. $mailString .= ',汇款账号单';
  1498. $item = array (
  1499. 'doPost' => 1,
  1500. 'mailItems' => $mailString,
  1501. 'mailItemsJson' => json_encode ( $mailList )
  1502. );
  1503. $invoiceStore->setInvoiceStoreByCondition ( $item, $isidString );
  1504. return "/invoiceTrainingDetail/" . $trainKey . ".html";
  1505. }
  1506. /**
  1507. * 废弃
  1508. */
  1509. function ajaxGetMailItemByIstore() {
  1510. Doo::loadClass ( 'XDeode' );
  1511. $XDeode = new XDeode ( 5 );
  1512. $storeKey = $this->get_args ( 'storeKey' ) ? $this->get_args ( 'storeKey' ) : '';
  1513. $isid = $XDeode->decode ( $storeKey );
  1514. if (! is_numeric ( $isid ))
  1515. die ( 'illegal request' );
  1516. Doo::loadModel ( 'invoiceStore' );
  1517. $invoiceStore = new invoiceStore ();
  1518. $isDetail = $invoiceStore->getInvoiceStoreByIsid ( $isid );
  1519. $isDetail ['mailItemsJson'] = json_decode ( $isDetail ['mailItemsJson'], true );
  1520. echo json_encode ( $isDetail ['mailItemsJson'] );
  1521. exit ();
  1522. }
  1523. /**
  1524. * 终止开票
  1525. */
  1526. function invoiceDroppedDo() {
  1527. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  1528. Doo::loadModel ( 'invoice' );
  1529. $invoice = new invoice ();
  1530. Doo::loadModel ( 'invoiceOperationLog' );
  1531. $invoiceOperationLog = new invoiceOperationLog ();
  1532. $iid = $invoice->authcode ( $droppedIidKey );
  1533. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1534. die ( 'illegal request' );
  1535. $item = array (
  1536. 'iid' => $iid,
  1537. 'status' => 4,
  1538. 'updateTime' => date ( "Y-m-d H:i:s" )
  1539. );
  1540. $invoice->setInvoiceByCondition ( $item );
  1541. $item = array (
  1542. 'date' => date ( "Y-m-d H:i:s" ),
  1543. 'operation' => '终止了开票',
  1544. 'status' => 4,
  1545. 'img' => $this->staff [0] ['avatar'],
  1546. 'username' => $this->staff [0] ['username'],
  1547. 'uid' => $this->staff [0] ['sid'],
  1548. 'category' => $this->staff [0] ['category'],
  1549. 'iid' => $iid
  1550. );
  1551. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1552. return "/invoice";
  1553. }
  1554. /**
  1555. * 更新退票的邮寄信息
  1556. */
  1557. function invoiceUntreadMailDo() {
  1558. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1559. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  1560. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  1561. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  1562. Doo::loadModel ( 'invoice' );
  1563. $invoice = new invoice ();
  1564. $iid = $invoice->authcode ( $untreadIidKey );
  1565. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1566. die ( 'illegal request' );
  1567. $item = array (
  1568. 'iid' => $iid,
  1569. 'untreadCompany' => $untreadCompany,
  1570. 'untreadNumber' => $untreadNumber,
  1571. 'untreadItems' => $untreadItems
  1572. );
  1573. $invoice->setInvoiceByCondition ( $item );
  1574. return "/invoice";
  1575. }
  1576. /**
  1577. * 申请退票 --
  1578. */
  1579. function invoiceUntreadDo() {
  1580. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1581. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  1582. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  1583. Doo::loadModel ( 'invoice' );
  1584. $invoice = new invoice ();
  1585. Doo::loadModel ( 'invoiceOperationLog' );
  1586. $invoiceOperationLog = new invoiceOperationLog ();
  1587. Doo::loadModel ( 'invoiceReceivables' );
  1588. $invoiceReceivables = new invoiceReceivables ();
  1589. $iid = $invoice->authcode ( $untreadIidKey );
  1590. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1591. die ( 'illegal request' );
  1592. /*
  1593. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  1594. */
  1595. $item = array (
  1596. 'iid' => $iid,
  1597. 'untreadStatus' => 1,
  1598. 'untreadReason' => $untreadReason,
  1599. 'untreadPost' => $untreadPost,
  1600. 'updateTime' => date ( "Y-m-d H:i:s" )
  1601. );
  1602. $invoice->setInvoiceByCondition ( $item );
  1603. $item = array (
  1604. 'date' => date ( "Y-m-d H:i:s" ),
  1605. 'operation' => '申请退票',
  1606. 'status' => 7,
  1607. 'img' => $this->staff [0] ['avatar'],
  1608. 'username' => $this->staff [0] ['username'],
  1609. 'uid' => $this->staff [0] ['sid'],
  1610. 'category' => $this->staff [0] ['category'],
  1611. 'iid' => $iid
  1612. );
  1613. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1614. return "/invoice";
  1615. }
  1616. /**
  1617. * 删除已终止的开票
  1618. */
  1619. function invoiceDelDo() {
  1620. Doo::loadModel ( 'invoice' );
  1621. $invoice = new invoice ();
  1622. Doo::loadModel ( 'invoiceOperationLog' );
  1623. $invoiceOperationLog = new invoiceOperationLog ();
  1624. Doo::loadClass ( 'XDeode' );
  1625. $XDeode = new XDeode ( 5 );
  1626. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  1627. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1628. $iid = $XDeode->decode ( $iid );
  1629. Doo::loadModel ( 'invoiceStore' );
  1630. $invoiceStore = new invoiceStore ();
  1631. if (! is_numeric ( $iid ))
  1632. die ( 'illegal request' );
  1633. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  1634. if (empty ( $invoiceDetail ))
  1635. die ( 'illegal request' );
  1636. $item = array (
  1637. 'iid' => $iid,
  1638. 'isDelete' => 1,
  1639. 'updateTime' => date ( "Y-m-d H:i:s" )
  1640. );
  1641. $invoice->setInvoiceByCondition ( $item );
  1642. $item = array (
  1643. 'date' => date ( "Y-m-d H:i:s" ),
  1644. 'operation' => '删除了已终止的发票',
  1645. 'status' => 4,
  1646. 'img' => $this->staff [0] ['avatar'],
  1647. 'username' => $this->staff [0] ['username'],
  1648. 'uid' => $this->staff [0] ['sid'],
  1649. 'category' => $this->staff [0] ['category'],
  1650. 'iid' => $iid
  1651. );
  1652. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1653. // 删除培训班发票仓库里的发票
  1654. $invoiceStore->delInvoiceStoreByIsid ( $invoiceDetail ['isid'] );
  1655. return "/invoice";
  1656. }
  1657. function invoiceApproval() {
  1658. Doo::loadModel ( 'invoice' );
  1659. $invoice = new invoice ();
  1660. Doo::loadClass ( 'XDeode' );
  1661. $XDeode = new XDeode ( 5 );
  1662. Doo::loadModel ( 'staff' );
  1663. $staff = new staff ();
  1664. $invoiceList = $invoice->find ( array (
  1665. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  1666. 'desc' => 'iid',
  1667. 'limit' => 10,
  1668. 'asArray' => true
  1669. ) );
  1670. foreach ( $invoiceList as $key => $value ) {
  1671. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1672. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1673. if (! empty ( $lastApprover )) {
  1674. $lastApproverKey = array_keys ( $lastApprover );
  1675. $lastApprover = end ( $lastApprover );
  1676. $staffDetail = $staff->getOne ( array (
  1677. 'where' => 'sid=' . end ( $lastApproverKey ),
  1678. 'asArray' => true
  1679. ) );
  1680. $lastApprover ['username'] = $staffDetail ['username'];
  1681. }
  1682. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  1683. }
  1684. $ilist = $invoice->getInvoiceByProcessStatus ();
  1685. foreach ( $ilist as $key => $value ) {
  1686. $ilist [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1687. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1688. if (! empty ( $lastApprover )) {
  1689. $lastApproverKey = array_keys ( $lastApprover );
  1690. $lastApprover = end ( $lastApprover );
  1691. $staffDetail = $staff->getOne ( array (
  1692. 'where' => 'sid=' . end ( $lastApproverKey ),
  1693. 'asArray' => true
  1694. ) );
  1695. $lastApprover ['username'] = $staffDetail ['username'];
  1696. }
  1697. $ilist [$key] ['lastApprover'] = $lastApprover;
  1698. }
  1699. // print_r($ilist);
  1700. $this->data ['invoiceList'] = $invoiceList;
  1701. $this->data ['ilist'] = $ilist;
  1702. $this->data ['memu'] = "invoice";
  1703. $this->data ['staff'] = $this->staff;
  1704. $this->data ['receiptMemu'] = 'invoiceApproval';
  1705. $this->render ( "/admin/invoiceApproval", $this->data );
  1706. }
  1707. function invoiceDetail() {
  1708. Doo::loadClass ( 'XDeode' );
  1709. $XDeode = new XDeode ( 5 );
  1710. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1711. $iid = $XDeode->decode ( $iid );
  1712. if (! is_numeric ( $iid ))
  1713. die ( 'illegal request' );
  1714. Doo::loadModel ( 'invoice' );
  1715. $invoice = new invoice ();
  1716. Doo::loadModel ( 'invoiceOperationLog' );
  1717. $invoiceOperationLog = new invoiceOperationLog ();
  1718. $invoiceDetail = $invoice->getOne ( array (
  1719. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  1720. 'asArray' => true
  1721. ) );
  1722. if (empty ( $invoiceDetail ))
  1723. die ( 'illegal request' );
  1724. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  1725. $this->data ['invoiceDetail'] = $invoiceDetail;
  1726. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  1727. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  1728. $this->data ['memu'] = "invoice";
  1729. $this->data ['staff'] = $this->staff;
  1730. $this->data ['receiptMemu'] = 'invoiceApproval';
  1731. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  1732. }
  1733. /**
  1734. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  1735. *
  1736. * @since 1.0.0
  1737. * @var integer iid 开票ID 已加密
  1738. * @var integer status 发票审批状态
  1739. * @var integer opintion 审批发票的意见
  1740. * @return string 如操作成功返回审批首页
  1741. */
  1742. function invoiceApprovalDo() {
  1743. Doo::loadModel ( 'invoice' );
  1744. $invoice = new invoice ();
  1745. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1746. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  1747. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  1748. $divApproval = $this->get_args ( 'divApproval' ) ? $this->get_args ( 'divApproval' ) : "";
  1749. $iid = $invoice->authcode ( $iid );
  1750. if (! is_numeric ( $iid ))
  1751. die ( 'illegal request' );
  1752. // && ! empty ( $opinion )
  1753. if (! empty ( $iid ) && ! empty ( $status )) {
  1754. if (! ($status == 2 || $status == 3 || $status == 4))
  1755. die ( 'illegal request' );
  1756. Doo::loadModel ( 'invoiceOperationLog' );
  1757. $invoiceOperationLog = new invoiceOperationLog ();
  1758. $invoiceDetail = $invoice->getOne ( array (
  1759. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  1760. 'asArray' => true
  1761. ) );
  1762. if (empty ( $invoiceDetail ))
  1763. die ( 'illegal request' );
  1764. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  1765. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  1766. if ($status == 3) {
  1767. $invoice->status = $status;
  1768. $item = array (
  1769. 'operation' => $opinion
  1770. );
  1771. } else {
  1772. if (empty ( $processApprovals )) {
  1773. $processApprovals = array (
  1774. $this->staff [0] ['sid'] => array (
  1775. 'date' => date ( "Y-m-d H:i:s" ),
  1776. 'opinion' => $opinion,
  1777. 'status' => $status
  1778. )
  1779. );
  1780. // var_dump(next($invoiceManage));
  1781. $nextInvoiceManage = next ( $invoiceManage );
  1782. // print_r($nextInvoiceManage);
  1783. if ($status != 4 && $nextInvoiceManage !== false)
  1784. $invoice->pendingApprovals = $nextInvoiceManage [0];
  1785. $invoice->processApprovals = json_encode ( $processApprovals );
  1786. // var_dump($invoice);
  1787. // print_r($invoiceManage);
  1788. } else {
  1789. $processApprovals [$this->staff [0] ['sid']] = array (
  1790. 'date' => date ( "Y-m-d H:i:s" ),
  1791. 'opinion' => $opinion,
  1792. 'status' => $status
  1793. );
  1794. $pendingApprovals = 0;
  1795. foreach ( $invoiceManage as $key => $value ) {
  1796. if ($value [0] == $this->staff [0] ['sid']) {
  1797. if (isset ( $invoiceManage [$key + 1] ))
  1798. $pendingApprovals = $invoiceManage [$key + 1] [0];
  1799. break;
  1800. }
  1801. }
  1802. if ($status != 4 && ! empty ( $pendingApprovals ))
  1803. $invoice->pendingApprovals = $pendingApprovals;
  1804. $invoice->processApprovals = json_encode ( $processApprovals );
  1805. }
  1806. $item = array (
  1807. 'operation' => $opinion
  1808. );
  1809. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  1810. $invoice->status = $status;
  1811. $invoice->pendingApprovals = 0;
  1812. $invoice->approvalTime = date ( "Y-m-d H:i:s" );
  1813. } elseif ($status == 4) {
  1814. $invoice->status = $status;
  1815. $item = array (
  1816. 'operation' => $opinion
  1817. );
  1818. }
  1819. }
  1820. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  1821. $invoice->update ( array (
  1822. 'where' => 'iid=' . $iid
  1823. ) );
  1824. $item += array (
  1825. 'date' => date ( "Y-m-d H:i:s" ),
  1826. 'img' => $this->staff [0] ['avatar'],
  1827. 'username' => $this->staff [0] ['username'],
  1828. 'uid' => $this->staff [0] ['sid'],
  1829. 'category' => $this->staff [0] ['category'],
  1830. 'status' => $status,
  1831. 'iid' => $iid
  1832. );
  1833. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1834. if (empty ( $divApproval ))
  1835. return '/invoiceApproval';
  1836. else
  1837. return '/invoiceApprovalAchieve';
  1838. }
  1839. die ( 'illegal request' );
  1840. }
  1841. /**
  1842. * 展示需要打印的发票数据
  1843. *
  1844. * @since 1.0.0
  1845. */
  1846. function invoicePrint() {
  1847. Doo::loadModel ( 'invoice' );
  1848. $invoice = new invoice ();
  1849. Doo::loadClass ( 'XDeode' );
  1850. $XDeode = new XDeode ( 5 );
  1851. Doo::loadModel ( 'staff' );
  1852. $staff = new staff ();
  1853. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  1854. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  1855. foreach ( $toPrint as $key => $value ) {
  1856. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1857. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1858. if (! empty ( $lastApprover )) {
  1859. $lastApproverKey = array_keys ( $lastApprover );
  1860. $lastApprover = end ( $lastApprover );
  1861. $staffDetail = $staff->getOne ( array (
  1862. 'where' => 'sid=' . end ( $lastApproverKey ),
  1863. 'asArray' => true
  1864. ) );
  1865. $lastApprover ['username'] = $staffDetail ['username'];
  1866. }
  1867. $toPrint [$key] ['lastApprover'] = $lastApprover;
  1868. }
  1869. foreach ( $printed as $key => $value ) {
  1870. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1871. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1872. if (! empty ( $lastApprover )) {
  1873. $lastApproverKey = array_keys ( $lastApprover );
  1874. $lastApprover = end ( $lastApprover );
  1875. $staffDetail = $staff->getOne ( array (
  1876. 'where' => 'sid=' . end ( $lastApproverKey ),
  1877. 'asArray' => true
  1878. ) );
  1879. $lastApprover ['username'] = $staffDetail ['username'];
  1880. }
  1881. $printed [$key] ['lastApprover'] = $lastApprover;
  1882. }
  1883. $this->data ['printed'] = $printed;
  1884. $this->data ['toPrint'] = $toPrint;
  1885. $this->data ['memu'] = "invoice";
  1886. $this->data ['staff'] = $this->staff;
  1887. $this->data ['receiptMemu'] = 'invoicePrint';
  1888. $this->render ( "/admin/invoicePrint", $this->data );
  1889. }
  1890. /**
  1891. * 展示发票打印的详情页面
  1892. *
  1893. * @since 1.0.0
  1894. */
  1895. function invoicePrintDetail() {
  1896. Doo::loadClass ( 'XDeode' );
  1897. $XDeode = new XDeode ( 5 );
  1898. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  1899. $iid = $XDeode->decode ( $iid );
  1900. if (! is_numeric ( $iid ))
  1901. die ( 'illegal request' );
  1902. Doo::loadModel ( 'invoice' );
  1903. $invoice = new invoice ();
  1904. Doo::loadModel ( 'invoiceOperationLog' );
  1905. $invoiceOperationLog = new invoiceOperationLog ();
  1906. Doo::loadModel ( 'invoicePaper' );
  1907. $invoicePaper = new invoicePaper ();
  1908. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  1909. if (empty ( $invoiceDetail ))
  1910. die ( 'illegal request' );
  1911. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $invoiceDetail ['invoiceType'] );
  1912. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  1913. $this->data ['invoicePaperList'] = $invoicePaperList;
  1914. $this->data ['invoiceDetail'] = $invoiceDetail;
  1915. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  1916. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  1917. $this->data ['memu'] = "invoice";
  1918. $this->data ['staff'] = $this->staff;
  1919. $this->data ['receiptMemu'] = 'invoicePrint';
  1920. $this->render ( "/admin/invoicePrintDetail", $this->data );
  1921. }
  1922. /**
  1923. * 所有待打印 发票
  1924. */
  1925. function invoicePrintStayAchieve() {
  1926. Doo::loadModel ( 'invoice' );
  1927. $invoice = new invoice ();
  1928. Doo::loadClass ( 'XDeode' );
  1929. $XDeode = new XDeode ( 5 );
  1930. Doo::loadModel ( 'staff' );
  1931. $staff = new staff ();
  1932. $MebSea = $this->get_args ( 'MebSea' ) ? urldecode ( $this->get_args ( 'MebSea' ) ) : "";
  1933. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  1934. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  1935. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  1936. Doo::loadModel ( 'invoiceTraining' );
  1937. $invoiceTraining = new invoiceTraining ();
  1938. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  1939. $page_size = 12;
  1940. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1941. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : "ALL";
  1942. // $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : "ALL";
  1943. $get = "/" . $status;
  1944. $con = ' and status=2 ';
  1945. if ($status == 'TOPRINT')
  1946. $con = ' and status=2 and printStatus=0 ';
  1947. elseif ($status == 'PRINTED')
  1948. $con = ' and status=2 and printStatus=1';
  1949. if ($invoiceType == 'ORDINARY')
  1950. $con .= ' and invoiceType=0 ';
  1951. elseif ($invoiceType == 'SPECIAL')
  1952. $con .= ' and invoiceType=1 ';
  1953. if ($invoiceTrain == 'ORDINARY')
  1954. $con .= ' and trainId=0 ';
  1955. elseif ($invoiceTrain == 'TRAIN')
  1956. $con .= ' and trainId!=0 ';
  1957. if ($invoiceTrainName != 'ALL') {
  1958. $trainId = $XDeode->decode ( $invoiceTrainName );
  1959. if (is_numeric ( $trainId ))
  1960. $con .= ' and trainId =' . $trainId;
  1961. }
  1962. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  1963. $dateArr = explode ( ':', $date );
  1964. $D1 = '';
  1965. $D2 = '';
  1966. if (! empty ( $date )) {
  1967. $D1 = $dateArr [0];
  1968. $D2 = $dateArr [1];
  1969. }
  1970. if (! empty ( $D1 ) && ! empty ( $D2 ) && ! empty ( $date ))
  1971. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  1972. if (! empty ( $MebSea )) {
  1973. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  1974. }
  1975. $pageinfo ['page'] = array (
  1976. 'previous' => ''
  1977. );
  1978. $get .= "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  1979. $sql = " (untreadStatus=0 or untreadStatus=3) and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  1980. $action = "invoicePrintStayAchieve";
  1981. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  1982. $limit = $pageinfo ['lower'] . ',' . $page_size;
  1983. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  1984. $this->data ['trainList'] = $trainList;
  1985. $this->data ['invoiceType'] = $invoiceType;
  1986. $this->data ['invoiceTrain'] = $invoiceTrain;
  1987. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  1988. $this->data ['MebSeaEn'] = $MebSea;
  1989. $this->data ['MebSea'] = urlencode ( $MebSea );
  1990. $this->data ['get'] = $get;
  1991. $this->data ['page'] = $pageinfo;
  1992. $this->data ['date'] = $date;
  1993. $this->data ['status'] = $status;
  1994. $this->data ['memu'] = "invoice";
  1995. $this->data ['staff'] = $this->staff;
  1996. foreach ( $list as $key => $value ) {
  1997. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1998. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1999. if (! empty ( $lastApprover )) {
  2000. $lastApproverKey = array_keys ( $lastApprover );
  2001. $lastApprover = end ( $lastApprover );
  2002. $staffDetail = $staff->getOne ( array (
  2003. 'where' => 'sid=' . end ( $lastApproverKey ),
  2004. 'asArray' => true
  2005. ) );
  2006. $lastApprover ['username'] = $staffDetail ['username'];
  2007. }
  2008. $list [$key] ['lastApprover'] = $lastApprover;
  2009. }
  2010. $this->data ['receiptMemu'] = 'invoicePrint';
  2011. $this->data ['list'] = $list;
  2012. $this->render ( "/admin/invoicePrintStayAchieve", $this->data );
  2013. }
  2014. /**
  2015. * 填写票号并完成打印
  2016. * @since 1.0.0
  2017. */
  2018. function invoicePrintDo() {
  2019. Doo::loadModel ( 'invoice' );
  2020. $invoice = new invoice ();
  2021. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2022. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  2023. $invoicePrintType = $this->get_args ( 'invoicePrintType' ) ? $this->get_args ( 'invoicePrintType' ) : "";
  2024. $iid = $invoice->authcode ( $iid );
  2025. if (! is_numeric ( $iid ))
  2026. die ( 'illegal request' );
  2027. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  2028. Doo::loadModel ( 'invoiceOperationLog' );
  2029. $invoiceOperationLog = new invoiceOperationLog ();
  2030. Doo::loadModel ( 'invoiceStatistics' );
  2031. $invoiceStatistics = new invoiceStatistics ();
  2032. $XDeode = new XDeode ( 5 );
  2033. Doo::loadModel ( 'invoicePaper' );
  2034. $invoicePaper = new invoicePaper ();
  2035. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  2036. if (empty ( $invoicePrintDetail ))
  2037. die ( 'illegal request' );
  2038. //
  2039. $ipid = $XDeode->decode ( $invoiceNo );
  2040. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  2041. if (empty ( $paperDetail ))
  2042. die ( 'illegal request' );
  2043. $invoicePaper = new invoicePaper ();
  2044. $item = array (
  2045. 'iid' => $iid,
  2046. 'ipid' => $ipid
  2047. );
  2048. $invoicePaper->setInvoicePaperByCondition ( $item );
  2049. $item = array (
  2050. 'iid' => $iid,
  2051. 'printStatus' => 1,
  2052. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2053. 'printer' => $this->staff [0] ['username'],
  2054. 'printTime' => date ( "Y-m-d H:i:s" ),
  2055. 'invoiceNo' => $paperDetail ['invoiceNo']
  2056. );
  2057. $invoice->setInvoiceByCondition ( $item );
  2058. $item = array (
  2059. 'date' => date ( "Y-m-d H:i:s" ),
  2060. 'operation' => '打印发票号:' . $paperDetail ['invoiceNo'],
  2061. 'status' => 5,
  2062. 'img' => $this->staff [0] ['avatar'],
  2063. 'username' => $this->staff [0] ['username'],
  2064. 'uid' => $this->staff [0] ['sid'],
  2065. 'category' => $this->staff [0] ['category'],
  2066. 'iid' => $iid
  2067. );
  2068. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2069. // 去统计--负票不汇总
  2070. if ($invoicePrintDetail ['untreadStatus'] != 4) {
  2071. $item = array (
  2072. 'date' => date ( "Y-m-d H:i:s" ),
  2073. 'priceClass' => 1,
  2074. 'cid' => $invoicePrintDetail ['cid'],
  2075. 'staff' => $invoicePrintDetail ['sid'],
  2076. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  2077. );
  2078. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2079. }
  2080. // 发送通知信息到微信-去除
  2081. // $this->setWXMsg($iid,'PRINT');
  2082. // 申请人获取微信通知
  2083. Doo::loadModel ( 'staff' );
  2084. $staff = new staff ();
  2085. Doo::loadClass ( 'XDeode' );
  2086. $XDeode = new XDeode ( 5 );
  2087. $username2 = $staff->getOne ( array (
  2088. 'select' => 'wxid',
  2089. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2090. 'asArray' => TRUE
  2091. ) );
  2092. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  2093. $msg = '';
  2094. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  2095. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2096. if (empty ( $invoicePrintType ))
  2097. return "/invoicePrint";
  2098. else
  2099. return "/invoicePrintStayAchieve";
  2100. }
  2101. }
  2102. /**
  2103. * 需要邮寄的发票
  2104. * @since 1.0.0
  2105. */
  2106. function invoicePost() {
  2107. Doo::loadModel ( 'invoice' );
  2108. $invoice = new invoice ();
  2109. Doo::loadModel ( 'express' );
  2110. $express = new express ();
  2111. $invoicePost = $invoice->getPostByInvoice ();
  2112. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  2113. $expressList = $express->getExpressByAll ();
  2114. $invoicePostExpress = "";
  2115. if (isset ( $_COOKIE ["invoicePostExpress"] ))
  2116. $invoicePostExpress = $_COOKIE ["invoicePostExpress"];
  2117. $this->data ['invoicePostExpress'] = $invoicePostExpress;
  2118. $this->data ['expressList'] = $expressList;
  2119. $this->data ['invoicePost'] = $invoicePost;
  2120. $this->data ['invoicePosted'] = $invoicePosted;
  2121. $this->data ['memu'] = "invoice";
  2122. $this->data ['staff'] = $this->staff;
  2123. $this->data ['receiptMemu'] = 'invoicePost';
  2124. $this->render ( "/admin/invoicePost", $this->data );
  2125. }
  2126. /**
  2127. * 添加发票邮寄信息
  2128. */
  2129. function invoiceExpressAddDo() {
  2130. Doo::loadModel ( 'invoice' );
  2131. $invoice = new invoice ();
  2132. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2133. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2134. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2135. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2136. $iid = $iid = $invoice->authcode ( $iid );
  2137. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2138. die ( 'illegal request' );
  2139. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  2140. setcookie ( 'invoicePostExpress', $expressNumber );
  2141. $item = array (
  2142. 'iid' => $iid,
  2143. 'postStatus' => 1,
  2144. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2145. 'postTime' => date ( "Y-m-d H:i:s" ),
  2146. 'expressCompany' => $expressCompany,
  2147. 'expressNumber' => $expressNumber,
  2148. 'actualItems' => $actualItems,
  2149. 'poster' => $this->staff [0] ['username']
  2150. );
  2151. $invoice->setInvoiceByCondition ( $item );
  2152. // 微信通知-去掉
  2153. // $this->setWXMsg ( $iid );
  2154. Doo::loadModel ( 'staff' );
  2155. $staff = new staff ();
  2156. Doo::loadClass ( 'XDeode' );
  2157. $XDeode = new XDeode ( 5 );
  2158. $username2 = $staff->getOne ( array (
  2159. 'select' => 'wxid',
  2160. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  2161. 'asArray' => TRUE
  2162. ) );
  2163. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  2164. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  2165. if (empty ( $expCom ))
  2166. $expCom [0] = '';
  2167. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  2168. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  2169. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'], $invoicePrintDetail ['sid'], 'print' );
  2170. return '/invoicePost';
  2171. }
  2172. function invoiceExpressUpdateDo() {
  2173. Doo::loadModel ( 'invoice' );
  2174. $invoice = new invoice ();
  2175. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2176. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2177. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  2178. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  2179. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  2180. $iid = $invoice->authcode ( $iid );
  2181. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  2182. die ( 'illegal request' );
  2183. $item = array (
  2184. 'iid' => $iid,
  2185. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2186. 'expressCompany' => $expressCompany,
  2187. 'expressNumber' => $expressNumber,
  2188. 'actualItems' => $actualItems,
  2189. 'poster' => $this->staff [0] ['username']
  2190. );
  2191. $invoice->setInvoiceByCondition ( $item );
  2192. return $action;
  2193. }
  2194. /**
  2195. * 可退票管理
  2196. */
  2197. function invoiceUntreadIsAchieve() {
  2198. Doo::loadModel ( 'invoice' );
  2199. $invoice = new invoice ();
  2200. Doo::loadClass ( 'XDeode' );
  2201. $XDeode = new XDeode ( 5 );
  2202. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2203. $page_size = 18;
  2204. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2205. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2206. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2207. $dateArr = explode ( ':', $date );
  2208. $D1 = '';
  2209. $D2 = '';
  2210. if (! empty ( $date )) {
  2211. $D1 = $dateArr [0];
  2212. $D2 = $dateArr [1];
  2213. }
  2214. $con = '';
  2215. if (! empty ( $D1 ) && ! empty ( $D2 ))
  2216. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2217. // if ($date == 'MONTHO')
  2218. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2219. // elseif ($date == 'MONTHT')
  2220. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2221. // elseif ($date == 'MONTHY')
  2222. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2223. if (! empty ( $MebSea )) {
  2224. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  2225. }
  2226. $pageinfo ['page'] = array (
  2227. 'previous' => ''
  2228. );
  2229. // printStatus=1 and
  2230. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  2231. $action = "invoiceUntreadIsAchieve";
  2232. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2233. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2234. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2235. // print_r($list);
  2236. $this->data ['MebSeaEn'] = $MebSea;
  2237. // $this->data ['MebSea'] = urlencode ( $MebSea );
  2238. $this->data ['get'] = $get;
  2239. $this->data ['page'] = $pageinfo;
  2240. $this->data ['date'] = $date;
  2241. $this->data ['list'] = $list;
  2242. $this->data ['memu'] = "invoice";
  2243. $this->data ['staff'] = $this->staff;
  2244. $this->data ['receiptMemu'] = 'invoice';
  2245. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  2246. }
  2247. /**
  2248. * 退票处理页面
  2249. */
  2250. function invoiceUntread() {
  2251. Doo::loadModel ( 'invoice' );
  2252. $invoice = new invoice ();
  2253. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1 );
  2254. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  2255. foreach ( $establishedInvoice as $key => $value ) {
  2256. // months
  2257. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  2258. $nowDate = strtotime ( 'now' );
  2259. $establishedInvoice [$key] ['lossShow'] = false;
  2260. if ($lossDate < $nowDate)
  2261. $establishedInvoice [$key] ['lossShow'] = true;
  2262. }
  2263. $this->data ['untreadInvoice'] = $untreadInvoice;
  2264. $this->data ['establishedInvoice'] = $establishedInvoice;
  2265. $this->data ['memu'] = "invoice";
  2266. $this->data ['staff'] = $this->staff;
  2267. $this->data ['receiptMemu'] = 'invoiceUntread';
  2268. $this->render ( "/admin/invoiceUntread", $this->data );
  2269. }
  2270. /**
  2271. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  2272. */
  2273. function invoiceUntreadEstablishedDo() {
  2274. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  2275. Doo::loadModel ( 'invoice' );
  2276. $invoice = new invoice ();
  2277. Doo::loadModel ( 'invoiceOperationLog' );
  2278. $invoiceOperationLog = new invoiceOperationLog ();
  2279. Doo::loadModel ( 'invoiceReceivables' );
  2280. Doo::loadModel ( 'invoiceStatistics' );
  2281. $iid = $invoice->authcode ( $untreadIidKey );
  2282. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  2283. die ( 'illegal request' );
  2284. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  2285. if ($invoiceDetails ['untreadStatus'] != 1)
  2286. die ( 'illegal request' );
  2287. $item = array (
  2288. 'iid' => $iid,
  2289. // 'irid'=>'',
  2290. 'untreadStatus' => 2,
  2291. 'updateTime' => date ( "Y-m-d H:i:s" )
  2292. );
  2293. $invoice->setInvoiceByCondition ( $item );
  2294. $item = array (
  2295. 'date' => date ( "Y-m-d H:i:s" ),
  2296. 'operation' => '已确认退票',
  2297. 'status' => 6,
  2298. 'img' => $this->staff [0] ['avatar'],
  2299. 'username' => $this->staff [0] ['username'],
  2300. 'uid' => $this->staff [0] ['sid'],
  2301. 'category' => $this->staff [0] ['category'],
  2302. 'iid' => $iid
  2303. );
  2304. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2305. // 收款解绑以及入账扣除 收款扣除
  2306. if (! empty ( $invoiceDetails ['irid'] )) {
  2307. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  2308. foreach ( $iridList as $value ) {
  2309. $invoiceReceivables = new invoiceReceivables ();
  2310. $irDetails = $invoiceReceivables->getOne ( array (
  2311. 'where' => " irid=" . $value . ' and bindStatus=1',
  2312. 'asArray' => TRUE
  2313. ) );
  2314. $item = array (
  2315. 'irid' => $value,
  2316. 'bindStatus' => 0,
  2317. 'untreadStatus' => 1,
  2318. 'untreadStaff' => $invoiceDetails ['userName'],
  2319. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  2320. 'iid' => 0
  2321. );
  2322. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2323. if (! empty ( $irDetails )) {
  2324. // 扣除入账
  2325. $invoiceStatistics = new invoiceStatistics ();
  2326. $item = array (
  2327. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2328. 'priceClass' => 3,
  2329. 'cid' => $invoiceDetails ['cid'],
  2330. 'staff' => $invoiceDetails ['sid'],
  2331. 'accountPrice' => - $irDetails ['receivablesPrice']
  2332. );
  2333. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2334. // 扣除收款
  2335. $invoiceStatistics = new invoiceStatistics ();
  2336. $item = array (
  2337. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  2338. 'priceClass' => 2,
  2339. 'cid' => $invoiceDetails ['cid'],
  2340. 'staff' => $invoiceDetails ['sid'],
  2341. 'irid' => $irDetails ['irid'],
  2342. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  2343. );
  2344. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2345. }
  2346. }
  2347. }
  2348. return "/invoiceUntread";
  2349. }
  2350. /**
  2351. * 建立负票,关联原来发票
  2352. */
  2353. function invoiceLossDo() {
  2354. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2355. if (! empty ( $iidKey )) {
  2356. Doo::loadClass ( 'XDeode' );
  2357. $XDeode = new XDeode ( 5 );
  2358. Doo::loadModel ( 'invoice' );
  2359. $invoice = new invoice ();
  2360. Doo::loadModel ( 'invoiceOperationLog' );
  2361. $invoiceOperationLog = new invoiceOperationLog ();
  2362. $iidKey = $XDeode->decode ( $iidKey );
  2363. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2364. // 拷贝插入一条发票数据
  2365. $iid = $invoice->setInvoiceLoss ( $iidKey );
  2366. // 更新负票
  2367. $invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2368. $invoice = new invoice ();
  2369. $item = array (
  2370. 'iid' => $iid,
  2371. 'sid' => $this->staff [0] ['sid'],
  2372. 'userName' => $this->staff [0] ['username'],
  2373. 'cid' => $this->staff [0] ['cid'],
  2374. 'categoryName' => $this->staff [0] ['category'],
  2375. 'invoiceQuantity' => - $invoiceDetail ['invoiceQuantity'],
  2376. 'invoicePrice' => - $invoiceDetail ['invoicePrice'],
  2377. 'invoiceSerial' => $invoiceSerial,
  2378. 'invoiceNo' => '',
  2379. 'printStatus' => 0,
  2380. 'untreadStatus' => 4,
  2381. // 关联发票号
  2382. 'lossIid' => $invoiceDetail ['iid']
  2383. );
  2384. $invoice->setInvoiceByCondition ( $item );
  2385. // 更新原发票
  2386. $invoice = new invoice ();
  2387. $item = array (
  2388. 'iid' => $invoiceDetail ['iid'],
  2389. 'lossIid' => $iid
  2390. );
  2391. $invoice->setInvoiceByCondition ( $item );
  2392. // 操作日志
  2393. $item = array (
  2394. 'date' => date ( "Y-m-d H:i:s" ),
  2395. 'operation' => "创建负票" . $invoiceSerial,
  2396. 'status' => 12,
  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. 'iid' => $iid
  2402. );
  2403. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2404. // print_r($invoiceDetail);
  2405. // echo $iid;die;
  2406. }
  2407. return '/invoiceUntread';
  2408. }
  2409. /**
  2410. * 上传银行到账 收款文件
  2411. */
  2412. function invoiceReceivablesBankUpload() {
  2413. $POST_MAX_SIZE = ini_get ( 'post_max_size' );
  2414. $unit = strtoupper ( substr ( $POST_MAX_SIZE, - 1 ) );
  2415. $multiplier = ($unit == 'M' ? 1048576 : ($unit == 'K' ? 1024 : ($unit == 'G' ? 1073741824 : 1)));
  2416. if (( int ) $_SERVER ['CONTENT_LENGTH'] > $multiplier * ( int ) $POST_MAX_SIZE && $POST_MAX_SIZE) {
  2417. header ( "HTTP/1.1 500 Internal Server Error" );
  2418. echo "POST exceeded maximum allowed size.";
  2419. exit ( 0 );
  2420. }
  2421. // Settings
  2422. $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)
  2423. $upload_name = "Filedata";
  2424. $file_name = "";
  2425. $nk = time ();
  2426. $file_name = $nk . '.' . $this->_GetFileEXT ( $_FILES [$upload_name] ['name'] ); // preg_replace('/[^'.$valid_chars_regex.']|\.+$/i', "", basename($_FILES[$upload_name]['name']));
  2427. if (! @move_uploaded_file ( $_FILES [$upload_name] ["tmp_name"], $save_path . $file_name )) {
  2428. echo "文件无法保存.";
  2429. exit ( 0 );
  2430. }
  2431. echo json_encode ( array (
  2432. 'filename' => $file_name,
  2433. 'id' => $nk
  2434. ) );
  2435. exit ( 0 );
  2436. }
  2437. /**
  2438. * 解析银行到账收款execl并导入库中
  2439. */
  2440. function invoiceReceivablesImport() {
  2441. $path = $this->get_args ( 'bankName' ) ? $this->get_args ( 'bankName' ) : "";
  2442. if ($path != "") {
  2443. Doo::loadModel ( 'invoiceReceivables' );
  2444. $invoiceReceivables = new invoiceReceivables ();
  2445. Doo::loadClass ( 'invoice.func' );
  2446. Doo::loadModel ( 'invoiceROLog' );
  2447. $invoiceROLog = new invoiceROLog ();
  2448. Doo::loadModel ( 'invoiceStatistics' );
  2449. $invoiceStatistics = new invoiceStatistics ();
  2450. $exlArray = formatExcelToArrayBank ( DOO::conf ()->SITE_PATH . "upload/invoiceReceivablesBank/" . $path );
  2451. $bankBatchNumber = 'BBN_' . time ();
  2452. Doo::db ()->beginTransaction ();
  2453. // 批量存储收款--由于必须获得收款ID,
  2454. $sql = 'INSERT INTO CLD_invoiceReceivables (receivablesPrice, receivablesMessage,receivablesSerial,receivablesBank,receivablesDate,inputStaff,date,receivablesCategory,receivablesStaff,bankBatchNumber,recepitTitleMark)
  2455. VALUES ';
  2456. $date = date ( "Y-m-d" );
  2457. $receivablesList = array ();
  2458. foreach ( $exlArray as $key => $value ) {
  2459. $receivablesSql = '(' . $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"] . '")';
  2460. array_push ( $receivablesList, $receivablesSql );
  2461. }
  2462. $sql = $sql . implode ( ',', $receivablesList );
  2463. // echo $sql;
  2464. Doo::db ()->query ( $sql );
  2465. // 批量存储收款统计
  2466. // 获得刚刚导入数据的irid组-缺少办事处和人员
  2467. $iridList = $invoiceReceivables->getInvoiceReceivablesByBBN ( $bankBatchNumber );
  2468. // 没有irid 回滚所有操作
  2469. if (empty ( $iridList )) {
  2470. Doo::db ()->rollBack ();
  2471. header ( 'Content-Type:text/html;charset=utf-8' );
  2472. die ( '文档或数据不正确,请重新<a href="/invoiceReceivables">上传</a>.' );
  2473. }
  2474. $sql = 'INSERT INTO CLD_invoiceStatistics (date, priceClass,irid,receivablesPrice)
  2475. VALUES ';
  2476. $statisticsList = array ();
  2477. foreach ( $iridList as $value ) {
  2478. $statisticsSql = '("' . $date . '",2,' . $value ['irid'] . ',' . $value ["receivablesPrice"] . ')';
  2479. array_push ( $statisticsList, $statisticsSql );
  2480. }
  2481. $sql = $sql . implode ( ',', $statisticsList );
  2482. Doo::db ()->query ( $sql );
  2483. // 批量存储操作日志
  2484. $sql = 'INSERT INTO CLD_invoiceROLog (operation, date,status,img, username,uid,category,irid)
  2485. VALUES ';
  2486. $ROLogList = array ();
  2487. foreach ( $iridList as $value ) {
  2488. $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'] . '")';
  2489. array_push ( $ROLogList, $ROLogSql );
  2490. }
  2491. $sql = $sql . implode ( ',', $ROLogList );
  2492. Doo::db ()->query ( $sql );
  2493. Doo::db ()->commit ();
  2494. return "/invoiceReceivables";
  2495. }
  2496. echo 'no file';
  2497. }
  2498. function invoiceReceivables() {
  2499. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  2500. Doo::loadModel ( 'L_category' );
  2501. $lCategory = new L_category ();
  2502. Doo::loadModel ( 'staff' );
  2503. $staff = new staff ();
  2504. Doo::loadModel ( 'invoiceReceivables' );
  2505. $invoiceReceivables = new invoiceReceivables ();
  2506. Doo::loadModel ( 'invoice' );
  2507. $invoice = new invoice ();
  2508. Doo::loadClass ( 'XDeode' );
  2509. $XDeode = new XDeode ( 5 );
  2510. $category = $lCategory->getCategory ();
  2511. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  2512. $sql = 'bindStatus=1 and iid!=0';
  2513. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  2514. // 获取未入账发票
  2515. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ( $invoiceTC );
  2516. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  2517. foreach ( $invoiceUnAccount as $key => $value ) {
  2518. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2519. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2520. if (! empty ( $lastApprover )) {
  2521. $lastApproverKey = array_keys ( $lastApprover );
  2522. $lastApprover = end ( $lastApprover );
  2523. $staffDetail = $staff->getOne ( array (
  2524. 'where' => 'sid=' . end ( $lastApproverKey ),
  2525. 'asArray' => true
  2526. ) );
  2527. $lastApprover ['username'] = $staffDetail ['username'];
  2528. }
  2529. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  2530. }
  2531. foreach ( $invoiceExistAccount as $key => $value ) {
  2532. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  2533. if (empty ( $irList ))
  2534. $irList [0] ['sumPrice'] = 0;
  2535. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  2536. $invoiceExistAccount [$key] ['existAccount'] = $irList [0] ['sumPrice'];
  2537. $invoiceExistAccount [$key] ['balance'] = $balance;
  2538. }
  2539. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  2540. $halfList = $invoiceReceivables->getInvoiceReceivablesByHalf ();
  2541. $this->data ['halfList'] = $halfList;
  2542. $this->data ['halfCount'] = count ( $halfList );
  2543. // print_r($receivablesList);
  2544. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  2545. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  2546. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  2547. $this->data ['receivablesInput'] = $receivablesInput;
  2548. $this->data ['year'] = date ( 'Y' );
  2549. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  2550. $this->data ['receivablesList'] = $receivablesList;
  2551. $this->data ['staffList'] = $staffList;
  2552. $this->data ['category'] = $category;
  2553. $this->data ['memu'] = "invoice";
  2554. $this->data ['staff'] = $this->staff;
  2555. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2556. $this->render ( "/admin/invoiceReceivables", $this->data );
  2557. }
  2558. /**
  2559. * 设置收款认领地区
  2560. */
  2561. function setInvoiceReceivablesClaim() {
  2562. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2563. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2564. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  2565. if (! empty ( $iridKey ) && ! empty ( $receivablesCategory )) {
  2566. Doo::loadModel ( 'invoiceReceivables' );
  2567. $invoiceReceivables = new invoiceReceivables ();
  2568. Doo::loadClass ( 'XDeode' );
  2569. $XDeode = new XDeode ( 5 );
  2570. Doo::loadModel ( 'invoiceROLog' );
  2571. $invoiceROLog = new invoiceROLog ();
  2572. $irid = $XDeode->decode ( $iridKey );
  2573. $irDetail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2574. if (empty ( $irDetail ))
  2575. die ( 'illegal request' );
  2576. $item = array (
  2577. 'irid' => $irid,
  2578. 'receivablesCategory' => $receivablesCategory
  2579. );
  2580. if ($receivablesCategory != 'PUBLIC') {
  2581. $item += array (
  2582. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2583. 'inputType' => 1
  2584. );
  2585. }
  2586. $invoiceReceivables = new invoiceReceivables ();
  2587. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2588. // 收款操作日志
  2589. $item = array (
  2590. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 ",
  2591. 'date' => date ( "Y-m-d" ),
  2592. 'status' => 1,
  2593. 'img' => $this->staff [0] ['avatar'],
  2594. 'username' => $this->staff [0] ['username'],
  2595. 'uid' => $this->staff [0] ['sid'],
  2596. 'category' => $this->staff [0] ['category'],
  2597. 'irid' => $irid
  2598. );
  2599. $invoiceROLog->setInvoiceROLog ( $item );
  2600. if (empty ( $action ))
  2601. return '/invoiceReceivables';
  2602. else
  2603. return "/invoiceReceivablesAS";
  2604. }
  2605. die ( 'illegal request' );
  2606. }
  2607. /**
  2608. * 新添加收款直接入账发票
  2609. */
  2610. function invoiceCompareClaimPrice() {
  2611. // 收款录入
  2612. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2613. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2614. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2615. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2616. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2617. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  2618. Doo::loadModel ( 'invoiceReceivables' );
  2619. $invoiceReceivables = new invoiceReceivables ();
  2620. Doo::loadModel ( 'invoiceROLog' );
  2621. $invoiceROLog = new invoiceROLog ();
  2622. Doo::loadModel ( 'invoiceStatistics' );
  2623. Doo::loadModel ( 'invoice' );
  2624. $invoice = new invoice ();
  2625. Doo::loadClass ( 'XDeode' );
  2626. $XDeode = new XDeode ( 5 );
  2627. Doo::loadModel ( 'invoiceOperationLog' );
  2628. $invoiceOperationLog = new invoiceOperationLog ();
  2629. $iidKey = $XDeode->decode ( $iidKey );
  2630. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  2631. if (! ($invoiceDetail ['status'] == 2 && $invoiceDetail ['printStatus'] == 1 && $invoiceDetail ['untreadStatus'] == 0))
  2632. die ( 'illegal request' );
  2633. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  2634. // 收款录入 并绑定发票
  2635. Doo::db ()->beginTransaction ();
  2636. $bindStatus = 0;
  2637. if ($receivablesPrice <= $invoiceDetail ['invoicePrice'])
  2638. $bindStatus = 1;
  2639. $item = array (
  2640. 'bindStatus' => $bindStatus,
  2641. 'iid' => $invoiceDetail ['iid'],
  2642. 'bindPrice' => $invoiceDetail ['invoicePrice'],
  2643. 'bindDate' => date ( "Y-m-d H:i:s" ),
  2644. 'receivablesPrice' => $receivablesPrice,
  2645. 'receivablesMessage' => $receivablesMessage,
  2646. 'receivablesSerial' => $receivablesSerial,
  2647. 'receivablesBank' => $receivablesBank,
  2648. 'receivablesDate' => $receivablesDate,
  2649. 'inputStaff' => $this->staff [0] ['username'],
  2650. 'accountClerk' => $this->staff [0] ['username'],
  2651. 'date' => date ( "Y-m-d" ),
  2652. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  2653. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  2654. 'confirmTime' => date ( "Y-m-d H:i:s" )
  2655. );
  2656. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  2657. $item = array ();
  2658. // 收款操作日志
  2659. $item = array (
  2660. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  2661. );
  2662. $item += array (
  2663. 'date' => date ( "Y-m-d" ),
  2664. 'status' => 1,
  2665. 'img' => $this->staff [0] ['avatar'],
  2666. 'username' => $this->staff [0] ['username'],
  2667. 'uid' => $this->staff [0] ['sid'],
  2668. 'category' => $this->staff [0] ['category'],
  2669. 'irid' => $irid
  2670. );
  2671. $invoiceROLog->setInvoiceROLog ( $item );
  2672. // 收款统计
  2673. $invoiceStatistics = new invoiceStatistics ();
  2674. $item = array (
  2675. 'date' => $receivablesDate,
  2676. 'priceClass' => 2,
  2677. 'irid' => $irid,
  2678. 'cid' => $invoiceDetail ['cid'],
  2679. 'staff' => $invoiceDetail ['sid'],
  2680. 'receivablesPrice' => $receivablesPrice
  2681. );
  2682. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2683. // 收款 入 发票
  2684. $detail = $invoiceDetail;
  2685. $iridString = "";
  2686. if (empty ( $detail ['irid'] ))
  2687. $iridString = $irid;
  2688. else
  2689. $iridString = $detail ['irid'] . ',' . $irid;
  2690. $item = array (
  2691. 'irid' => $iridString,
  2692. 'bindTime' => date ( "Y-m-d H:i:s" ),
  2693. 'updateTime' => date ( "Y-m-d H:i:s" ),
  2694. 'iid' => $detail ['iid']
  2695. );
  2696. $invoiceReceivables = new invoiceReceivables ();
  2697. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  2698. if ($detail ['invoicePrice'] <= $sum)
  2699. $item += array (
  2700. 'untreadStatus' => 3
  2701. );
  2702. $invoice->setInvoiceByCondition ( $item );
  2703. // 操作日志
  2704. $item = array (
  2705. 'date' => date ( "Y-m-d H:i:s" ),
  2706. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  2707. 'status' => 8,
  2708. 'img' => $this->staff [0] ['avatar'],
  2709. 'username' => $this->staff [0] ['username'],
  2710. 'uid' => $this->staff [0] ['sid'],
  2711. 'category' => $this->staff [0] ['category'],
  2712. 'iid' => $detail ['iid']
  2713. );
  2714. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2715. // 入账汇总
  2716. $invoiceStatistics = new invoiceStatistics ();
  2717. // $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  2718. // $accountPrice = 0;
  2719. // foreach ( $list as $key => $value ) {
  2720. // $accountPrice += $value ['receivablesPrice'];
  2721. // }
  2722. $item = array (
  2723. 'date' => $receivablesDate,
  2724. 'priceClass' => 3,
  2725. 'cid' => $invoiceDetail ['cid'],
  2726. 'staff' => $invoiceDetail ['sid'],
  2727. 'accountPrice' => $receivablesPrice
  2728. );
  2729. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2730. Doo::db ()->commit ();
  2731. }
  2732. return '/invoiceReceivables';
  2733. }
  2734. /**
  2735. * 检索未入账发票数据 function sir() { }
  2736. */
  2737. /**
  2738. * 录入收款数据
  2739. * @return string
  2740. */
  2741. function invoiceReceivablesDo() {
  2742. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2743. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2744. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2745. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2746. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2747. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  2748. Doo::loadModel ( 'invoiceReceivables' );
  2749. $invoiceReceivables = new invoiceReceivables ();
  2750. Doo::loadModel ( 'invoiceROLog' );
  2751. $invoiceROLog = new invoiceROLog ();
  2752. Doo::loadModel ( 'invoiceStatistics' );
  2753. $invoiceStatistics = new invoiceStatistics ();
  2754. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  2755. $item = array (
  2756. 'receivablesPrice' => $receivablesPrice,
  2757. 'receivablesMessage' => $receivablesMessage,
  2758. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  2759. 'receivablesBank' => $receivablesBank,
  2760. 'receivablesDate' => $receivablesDate,
  2761. 'inputStaff' => $this->staff [0] ['username'],
  2762. 'date' => date ( "Y-m-d" ),
  2763. 'receivablesCategory' => $receivablesCategory,
  2764. 'receivablesStaff' => $receivablesStaff
  2765. );
  2766. if ($receivablesCategory != 'PUBLIC') {
  2767. $item += array (
  2768. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2769. 'inputType' => 1
  2770. );
  2771. }
  2772. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  2773. $item = array ();
  2774. // 收款操作日志
  2775. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2776. $item = array (
  2777. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  2778. );
  2779. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2780. $item = array (
  2781. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  2782. );
  2783. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  2784. $receivablesStaff = explode ( '-', $receivablesStaff );
  2785. $item = array (
  2786. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  2787. );
  2788. }
  2789. $item += array (
  2790. 'date' => date ( "Y-m-d" ),
  2791. 'status' => 1,
  2792. 'img' => $this->staff [0] ['avatar'],
  2793. 'username' => $this->staff [0] ['username'],
  2794. 'uid' => $this->staff [0] ['sid'],
  2795. 'category' => $this->staff [0] ['category'],
  2796. 'irid' => $irid
  2797. );
  2798. $invoiceROLog->setInvoiceROLog ( $item );
  2799. $item = array (
  2800. 'date' => $receivablesDate,
  2801. 'priceClass' => 2,
  2802. 'irid' => $irid,
  2803. 'receivablesPrice' => $receivablesPrice
  2804. );
  2805. if ($receivablesCategory != 'PUBLIC') {
  2806. $receivablesCategory = explode ( ":", $receivablesCategory );
  2807. $item += array (
  2808. 'cid' => $receivablesCategory [0]
  2809. );
  2810. }
  2811. if ($receivablesStaff2 != 'PUBLIC') {
  2812. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  2813. $item += array (
  2814. 'staff' => $receivablesStaff [0]
  2815. );
  2816. }
  2817. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2818. $toparty = $this->getWxidByCategory ( $receivablesCategory [1] );
  2819. // $toparty = $this->getToparty ( $receivablesCategory [1] );
  2820. $msg = '[通知]财务录入了一笔待认领款项,快到“我的收款”中查看,确认是否是您的客户给您打款了。';
  2821. if ($toparty != 0)
  2822. $this->msgSendToparty ( $msg, '', '', $toparty, 'text' );
  2823. }
  2824. return "/invoiceReceivables";
  2825. }
  2826. /**
  2827. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  2828. */
  2829. function invoiceReceivablesClaim() {
  2830. Doo::loadModel ( 'invoiceReceivables' );
  2831. $invoiceReceivables = new invoiceReceivables ();
  2832. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  2833. $this->data ['receivablesList'] = $receivablesList;
  2834. $this->data ['memu'] = "invoice";
  2835. $this->data ['staff'] = $this->staff;
  2836. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  2837. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  2838. }
  2839. function invoiceReceivablesTitleMarkSet() {
  2840. $iridKey = $this->get_args ( 'iridKey' ) ? $this->get_args ( 'iridKey' ) : "";
  2841. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  2842. if (empty ( $iridKey ) || empty ( $recepitTitleMark ))
  2843. die ( 'illegal request' );
  2844. Doo::loadModel ( 'invoiceReceivables' );
  2845. $invoiceReceivables = new invoiceReceivables ();
  2846. Doo::loadClass ( 'XDeode' );
  2847. $XDeode = new XDeode ( 5 );
  2848. $irid = $XDeode->decode ( $iridKey );
  2849. if (! is_numeric ( $irid ))
  2850. die ( 'illegal request' );
  2851. $invoiceReceivables->recepitTitleMark = $recepitTitleMark;
  2852. $invoiceReceivables->update ( array (
  2853. 'where' => 'irid = ' . $irid
  2854. ) );
  2855. return '/invoiceReceivablesClaim';
  2856. }
  2857. /**
  2858. * 更新收款相关数据
  2859. */
  2860. function invoiceReceivablesUpdateClaim() {
  2861. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  2862. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  2863. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  2864. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  2865. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  2866. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  2867. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  2868. if (empty ( $claimKey ))
  2869. die ( 'illegal request' );
  2870. Doo::loadModel ( 'invoiceReceivables' );
  2871. $invoiceReceivables = new invoiceReceivables ();
  2872. Doo::loadModel ( 'invoiceROLog' );
  2873. $invoiceROLog = new invoiceROLog ();
  2874. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  2875. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  2876. if (empty ( $detail ))
  2877. die ( 'illegal request' );
  2878. $invoiceReceivables = new invoiceReceivables ();
  2879. $item = array (
  2880. 'irid' => $detail ['irid']
  2881. );
  2882. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  2883. $item += array (
  2884. 'confirmTime' => date ( "Y-m-d H:i:s" )
  2885. );
  2886. }
  2887. if (! empty ( $receivablesCategory ))
  2888. $item += array (
  2889. 'receivablesCategory' => $receivablesCategory
  2890. );
  2891. if (! empty ( $receivablesStaff ))
  2892. $item += array (
  2893. 'receivablesStaff' => $receivablesStaff
  2894. );
  2895. if (! empty ( $receivablesPrice ))
  2896. $item += array (
  2897. 'receivablesPrice' => $receivablesPrice
  2898. );
  2899. if (! empty ( $receivablesMessage ))
  2900. $item += array (
  2901. 'receivablesMessage' => $receivablesMessage
  2902. );
  2903. if (! empty ( $receivablesBank ))
  2904. $item += array (
  2905. 'receivablesBank' => $receivablesBank
  2906. );
  2907. if (! empty ( $receivablesDate ))
  2908. $item += array (
  2909. 'receivablesDate' => $receivablesDate
  2910. );
  2911. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2912. // 收款操作日志
  2913. $item = array ();
  2914. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2915. $item = array (
  2916. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  2917. );
  2918. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  2919. $item = array (
  2920. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  2921. );
  2922. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  2923. $receivablesStaff = explode ( '-', $receivablesStaff );
  2924. $item = array (
  2925. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  2926. );
  2927. }
  2928. $item += array (
  2929. 'date' => date ( "Y-m-d" ),
  2930. 'status' => 1,
  2931. 'img' => $this->staff [0] ['avatar'],
  2932. 'username' => $this->staff [0] ['username'],
  2933. 'uid' => $this->staff [0] ['sid'],
  2934. 'category' => $this->staff [0] ['category'],
  2935. 'irid' => $detail ['irid']
  2936. );
  2937. $invoiceROLog->setInvoiceROLog ( $item );
  2938. return '/invoiceReceivablesAS';
  2939. }
  2940. function invoiceReceivablesDelete() {
  2941. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  2942. if (empty ( $claimKey ))
  2943. die ( 'illegal request' );
  2944. Doo::loadModel ( 'invoiceReceivables' );
  2945. $invoiceReceivables = new invoiceReceivables ();
  2946. $con = ' and iid=0 and bindStatus=0 and receivablesStaff="PUBLIC"';
  2947. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  2948. if (empty ( $detail ))
  2949. die ( 'illegal request' );
  2950. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  2951. return '/invoiceReceivablesAS';
  2952. }
  2953. /**
  2954. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  2955. */
  2956. function invoiceReceivablesAscription() {
  2957. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  2958. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  2959. Doo::loadModel ( 'invoiceReceivables' );
  2960. $invoiceReceivables = new invoiceReceivables ();
  2961. Doo::loadModel ( 'invoiceROLog' );
  2962. $invoiceROLog = new invoiceROLog ();
  2963. Doo::loadModel ( 'invoiceStatistics' );
  2964. $invoiceStatistics = new invoiceStatistics ();
  2965. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2966. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  2967. $item = array (
  2968. 'irid' => $detail ['irid'],
  2969. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  2970. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  2971. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  2972. 'recepitTitleMark' => $recepitTitleMark,
  2973. 'source' => 1
  2974. );
  2975. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2976. $item = array (
  2977. 'date' => date ( "Y-m-d" ),
  2978. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  2979. 'status' => 2,
  2980. 'img' => $this->staff [0] ['avatar'],
  2981. 'username' => $this->staff [0] ['username'],
  2982. 'uid' => $this->staff [0] ['sid'],
  2983. 'category' => $this->staff [0] ['category'],
  2984. 'irid' => $irid
  2985. );
  2986. $invoiceROLog->setInvoiceROLog ( $item );
  2987. $item = array (
  2988. 'cid' => $this->staff [0] ['cid'],
  2989. 'staff' => $this->staff [0] ['sid']
  2990. );
  2991. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'], 2 );
  2992. }
  2993. return "/invoiceReceivablesClaim";
  2994. }
  2995. /**
  2996. */
  2997. function invoiceMyReceivables() {
  2998. Doo::loadModel ( 'invoiceReceivables' );
  2999. $invoiceReceivables = new invoiceReceivables ();
  3000. Doo::loadModel ( 'invoiceStatistics' );
  3001. $invoiceStatistics = new invoiceStatistics ();
  3002. $isMonth = $invoiceStatistics->getStatisticsByMonth ( $this->staff [0] ['sid'] );
  3003. $year = date ( "Y" );
  3004. $tmp_date = date ( "Ym" );
  3005. $tmp_year = substr ( $tmp_date, 0, 4 );
  3006. $tmp_mon = substr ( $tmp_date, 4, 2 );
  3007. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  3008. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  3009. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  3010. $htm = $this->showCache ( $path );
  3011. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  3012. $this->data ['isMonth'] = $isMonth;
  3013. $this->data ['htm'] = $htm;
  3014. $this->data ['list'] = $list;
  3015. $this->data ['memu'] = "invoice";
  3016. $this->data ['staff'] = $this->staff;
  3017. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3018. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  3019. }
  3020. /**
  3021. * 纸票管理
  3022. */
  3023. function invoicePaper() {
  3024. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3025. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3026. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3027. $this->data ['dateString'] = $date;
  3028. $this->data ['status'] = $status;
  3029. $this->data ['invoiceType'] = $invoiceType;
  3030. $this->data ['memu'] = "invoice";
  3031. $this->data ['staff'] = $this->staff;
  3032. $this->data ['receiptMemu'] = 'invoicePaper';
  3033. $this->render ( "/admin/invoicePaper", $this->data );
  3034. }
  3035. /**
  3036. * 获得纸票分页数据
  3037. */
  3038. function ajaxGetinvoicePaperAchieve() {
  3039. Doo::loadModel ( 'invoicePaper' );
  3040. $invoicePaper = new invoicePaper ();
  3041. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  3042. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  3043. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ORDINARY";
  3044. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3045. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  3046. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  3047. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  3048. $MebSea = $this->get_args ( 'search' );
  3049. $MebSea = $MebSea ['value'];
  3050. $page_size = $length;
  3051. $con = '';
  3052. if ($status == 'ALL')
  3053. $con = ' where 1 ';
  3054. elseif ($status == 'PRINTED')
  3055. $con = ' where b.isDelete=0 and b.status=2 and b.untreadStatus=0 and b.printStatus=1 ';
  3056. elseif ($status == 'UNPRINT')
  3057. $con = ' where b.isDelete=0 and b.status=2 and b.untreadStatus=0 and b.printStatus=0 ';
  3058. elseif ($status == 'TICKET')
  3059. $con = ' where b.isDelete=0 and b.untreadStatus=2';
  3060. if ($invoiceType == 'ORDINARY')
  3061. $con .= ' and a.invoiceType=0 ';
  3062. elseif ($invoiceType == 'SPECIAL')
  3063. $con .= ' and a.invoiceType=1 ';
  3064. $dateArr = explode ( ':', $date );
  3065. $D1 = $dateString = '';
  3066. $D2 = '';
  3067. if (! empty ( $date )) {
  3068. $D1 = $dateArr [0];
  3069. if (isset ( $dateArr [1] ))
  3070. $D2 = $dateArr [1];
  3071. else
  3072. $D2 = '';
  3073. $dateString = $D1 . " : " . $D2;
  3074. }
  3075. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3076. $con .= ' and b.printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3077. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3078. $con .= ' and b.printTime like "%' . $D1 . '%" ';
  3079. if (! empty ( $MebSea ))
  3080. $con .= ' and ( b.invoiceTitle like "%' . $MebSea . '%" or b.invoiceCompany like "%' . $MebSea . '%" or a.invoiceNo like "%' . $MebSea . '%" )';
  3081. $invoiceTotal = $invoicePaper->getInvoicePaperCount ();
  3082. $sql = ' ' . $con;
  3083. $limit = $page . ',' . $page_size;
  3084. $list = $invoicePaper->getInvoicePaper ( $limit, $sql, 'desc' );
  3085. $paperList = array ();
  3086. foreach ( $list as $key => $value ) {
  3087. $irDetail = array ();
  3088. if ($value ['iid'] == 0)
  3089. array_push ( $irDetail, '<a href="javascript:if(window.confirm(\'确认删除?\'))window.location=\'/invoicePaperDel/' . $value ['ipidKey'] . '\'" >删除</a>' );
  3090. else
  3091. array_push ( $irDetail, '' );
  3092. array_push ( $irDetail, $value ['invoiceCode'] );
  3093. array_push ( $irDetail, $value ['invoiceNo'] );
  3094. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKey'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  3095. if ($value ['invoiceType'] == 1)
  3096. array_push ( $irDetail, $value ['invoiceCompany'] );
  3097. else
  3098. array_push ( $irDetail, $value ['invoiceTitle'] );
  3099. if ($value ['invoiceType'] == 1)
  3100. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  3101. else
  3102. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  3103. array_push ( $irDetail, $value ['invoiceElement'] );
  3104. array_push ( $irDetail, $value ['categoryName'] . '-' . $value ['userName'] );
  3105. array_push ( $irDetail, $value ['printTime'] );
  3106. array_push ( $paperList, $irDetail );
  3107. }
  3108. // $approvalListJson = json_encode ( $approvalList );
  3109. $recordsFiltered = $invoiceTotal;
  3110. echo json_encode ( array (
  3111. "draw" => intval ( $draw ),
  3112. "recordsTotal" => intval ( $invoiceTotal ),
  3113. "recordsFiltered" => intval ( $recordsFiltered ),
  3114. "data" => $paperList
  3115. ), JSON_UNESCAPED_UNICODE );
  3116. }
  3117. function invoicePaperDel() {
  3118. $ipidKey = isset ( $this->params ['ipidKey'] ) ? $this->params ['ipidKey'] : "";
  3119. $XDeode = new XDeode ( 5 );
  3120. $ipid = $XDeode->decode ( $ipidKey );
  3121. if (empty ( $ipid ))
  3122. die ( 'illegal request' );
  3123. Doo::loadModel ( 'invoicePaper' );
  3124. $invoicePaper = new invoicePaper ();
  3125. $invoicePaper->delete ( array (
  3126. 'where' => 'ipid=' . $ipid . ' and iid=0',
  3127. 'limit' => 1
  3128. ) );
  3129. return '/invoicePaper';
  3130. }
  3131. /**
  3132. * 添加纸质发票号
  3133. */
  3134. function invoicePaperAdd() {
  3135. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : '0';
  3136. $invoiceCode = $this->get_args ( 'invoiceCode' ) ? $this->get_args ( 'invoiceCode' ) : "";
  3137. $invoiceNoStart = $this->get_args ( 'invoiceNoStart' ) && is_numeric ( $this->get_args ( 'invoiceNoStart' ) ) ? $this->get_args ( 'invoiceNoStart' ) : 0;
  3138. $invoiceNoTotal = $this->get_args ( 'invoiceNoTotal' ) && is_numeric ( $this->get_args ( 'invoiceNoTotal' ) ) ? $this->get_args ( 'invoiceNoTotal' ) : 0;
  3139. if ($invoiceType != '' && ! empty ( $invoiceCode ) && ! empty ( $invoiceNoStart ) && ! empty ( $invoiceNoTotal )) {
  3140. $sum = $invoiceNoStart + $invoiceNoTotal;
  3141. if (empty ( $sum ))
  3142. die ( 'illegal request' );
  3143. Doo::db ()->beginTransaction ();
  3144. // 批量存储纸质发票
  3145. $date = date ( "Y-m-d H:i:s" );
  3146. $sql = 'INSERT INTO CLD_invoicePaper (invoiceType, invoiceCode,invoiceNo,date)
  3147. VALUES ';
  3148. $paperList = array ();
  3149. for($invoiceNoStart; $invoiceNoStart <= $sum - 1; $invoiceNoStart ++) {
  3150. $paperSql = '(' . $invoiceType . ',"' . $invoiceCode . '","' . $invoiceNoStart . '","' . $date . '")';
  3151. array_push ( $paperList, $paperSql );
  3152. }
  3153. if (empty ( $paperList ))
  3154. die ( 'illegal request' );
  3155. $sql = $sql . implode ( ',', $paperList );
  3156. Doo::db ()->query ( $sql );
  3157. Doo::db ()->commit ();
  3158. return 'invoicePaper';
  3159. }
  3160. die ( 'illegal request' );
  3161. }
  3162. /**
  3163. * 收款绑定发票 ,一个收款只能绑定一个发票
  3164. */
  3165. function invoiceBindReceivables() {
  3166. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  3167. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  3168. Doo::loadModel ( 'invoice' );
  3169. $invoice = new invoice ();
  3170. Doo::loadModel ( 'invoiceReceivables' );
  3171. $invoiceReceivables = new invoiceReceivables ();
  3172. Doo::loadModel ( 'invoiceOperationLog' );
  3173. $invoiceOperationLog = new invoiceOperationLog ();
  3174. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  3175. die ( 'illegal request' );
  3176. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  3177. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  3178. if (empty ( $detail ) && empty ( $detailM ))
  3179. die ( 'illegal request' );
  3180. if ($detail ['untreadStatus'] == 3)
  3181. die ( 'illegal request' );
  3182. // 修改 绑定状态改为 金额
  3183. $invoiceReceivables = new invoiceReceivables ();
  3184. $invoicePrice = $detail ['invoicePrice'] + $detailM ['bindPrice'];
  3185. if ($detailM ['receivablesPrice'] > $invoicePrice) {
  3186. $item = array (
  3187. 'bindPrice' => $invoicePrice
  3188. );
  3189. } elseif ($detailM ['receivablesPrice'] <= $invoicePrice) {
  3190. $item = array (
  3191. 'bindPrice' => $invoicePrice,
  3192. 'bindStatus' => 1,
  3193. 'bindDate' => date ( "Y-m-d H:i:s" )
  3194. );
  3195. } else {
  3196. die ( 'illegal request' );
  3197. }
  3198. if ($detailM ['iid'] == 0) {
  3199. $item += array (
  3200. 'iid' => $detail ['iid']
  3201. );
  3202. } else {
  3203. $iidExtend = explode ( ',', $detailM ['iidExtend'] );
  3204. array_push ( $iidExtend, $detail ['iid'] );
  3205. $item += array (
  3206. 'iidExtend' => implode ( ',', $iidExtend )
  3207. );
  3208. }
  3209. $item += array (
  3210. 'irid' => $detailM ['irid'],
  3211. 'accountClerk' => $this->staff [0] ['username']
  3212. );
  3213. // 如何没有人收款 则自动绑定收款
  3214. if ($detailM ['receivablesCategory'] == 'PUBLIC' || $detailM ['receivablesStaff'] == 'PUBLIC') {
  3215. $item += array (
  3216. 'receivablesCategory' => $detail ['cid'] . ':' . $detail ['categoryName'],
  3217. 'receivablesStaff' => $detail ['sid'] . '-' . $detail ['userName']
  3218. );
  3219. }
  3220. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  3221. $iridString = "";
  3222. if (empty ( $detail ['irid'] ))
  3223. $iridString = $detailM ['irid'];
  3224. else
  3225. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  3226. $item = array (
  3227. 'iid' => $detail ['iid'],
  3228. 'irid' => $iridString
  3229. );
  3230. $invoiceReceivables = new invoiceReceivables ();
  3231. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  3232. if ($detail ['invoicePrice'] <= $sum)
  3233. $item += array (
  3234. 'untreadStatus' => 3,
  3235. 'bindTime' => date ( "Y-m-d H:i:s" )
  3236. );
  3237. // print_r($item);
  3238. // echo $sum;die;
  3239. $invoice->setInvoiceByCondition ( $item );
  3240. // 操作日志
  3241. $item = array (
  3242. 'date' => date ( "Y-m-d H:i:s" ),
  3243. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  3244. 'status' => 8,
  3245. 'img' => $this->staff [0] ['avatar'],
  3246. 'username' => $this->staff [0] ['username'],
  3247. 'uid' => $this->staff [0] ['sid'],
  3248. 'category' => $this->staff [0] ['category'],
  3249. 'iid' => $detail ['iid']
  3250. );
  3251. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  3252. Doo::loadModel ( 'invoiceStatistics' );
  3253. $invoiceStatistics = new invoiceStatistics ();
  3254. $item = array (
  3255. 'date' => $detailM ['receivablesDate'],
  3256. 'priceClass' => 3,
  3257. 'cid' => $detail ['cid'],
  3258. 'staff' => $detail ['sid'],
  3259. 'accountPrice' => $detailM ['receivablesPrice']
  3260. );
  3261. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3262. return "/invoiceReceivables";
  3263. }
  3264. /**
  3265. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  3266. */
  3267. function invoiceAggregate() {
  3268. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3269. Doo::loadModel ( 'invoiceStatistics' );
  3270. $invoiceStatistics = new invoiceStatistics ();
  3271. Doo::loadModel ( 'L_category' );
  3272. $Lcategory = new L_category ();
  3273. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  3274. $LcategoryList = $Lcategory->getCategory ();
  3275. // print_r($isList);
  3276. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  3277. foreach ( $LcategoryList as $key => $value ) {
  3278. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  3279. $month = 1;
  3280. $invoicePriceYear = 0;
  3281. $receivablesPriceYear = 0;
  3282. $accountPriceYear = 0;
  3283. for(; $month <= 12; $month ++) {
  3284. $flag = true;
  3285. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  3286. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  3287. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3288. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3289. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3290. ';
  3291. $invoicePriceYear += $v ['invoicePrice'];
  3292. $receivablesPriceYear += $v ['receivablesPrice'];
  3293. $accountPriceYear += $v ['accountPrice'];
  3294. $flag = false;
  3295. break;
  3296. }
  3297. }
  3298. if ($flag)
  3299. $html .= '<td class="taR"></td>
  3300. <td class="taR"></td>
  3301. <td class="taR"><b></b></td>
  3302. ';
  3303. }
  3304. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3305. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3306. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3307. ';
  3308. $html .= '</tr>';
  3309. }
  3310. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  3311. $invoicePriceYear = 0;
  3312. $receivablesPriceYear = 0;
  3313. $accountPriceYear = 0;
  3314. for($month = 1; $month <= 12; $month ++) {
  3315. $flag = true;
  3316. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  3317. if ($month == $v ['month']) {
  3318. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  3319. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  3320. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  3321. ';
  3322. $invoicePriceYear += $v ['invoicePrice'];
  3323. $receivablesPriceYear += $v ['receivablesPrice'];
  3324. $accountPriceYear += $v ['accountPrice'];
  3325. $flag = false;
  3326. break;
  3327. }
  3328. }
  3329. if ($flag) {
  3330. $html .= '<td class="taR"></td>
  3331. <td class="taR"></td>
  3332. <td class="taR"><b></b></td>
  3333. ';
  3334. }
  3335. }
  3336. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3337. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3338. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3339. ';
  3340. $html .= '</tr>';
  3341. // print_r($isList);
  3342. $this->data ['html'] = $html;
  3343. $this->data ['LcategoryList'] = $LcategoryList;
  3344. $this->data ['isList'] = $isList;
  3345. $this->data ['year'] = $year;
  3346. $this->data ['memu'] = "invoice";
  3347. $this->data ['staff'] = $this->staff;
  3348. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3349. $this->render ( "/admin/invoiceAggregate", $this->data );
  3350. }
  3351. function invoiceAggregateStaff() {
  3352. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3353. Doo::loadModel ( 'invoiceStatistics' );
  3354. $invoiceStatistics = new invoiceStatistics ();
  3355. Doo::loadModel ( 'L_category' );
  3356. $Lcategory = new L_category ();
  3357. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  3358. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  3359. $cStaff = $Lcategory->getCategoryStaff ();
  3360. $html = '';
  3361. foreach ( $cStaff as $key => $value ) {
  3362. $categoryFir = true;
  3363. foreach ( $value ['staff'] as $k => $v ) {
  3364. if ($categoryFir) {
  3365. $width = count ( $value ['staff'] ) + 1;
  3366. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  3367. $categoryFir = false;
  3368. } else
  3369. $html .= '<tr>';
  3370. $html .= '<th>' . $v ['username'] . '</th>';
  3371. $invoicePriceStaffYear = 0;
  3372. $receivablesPriceStaffYear = 0;
  3373. $accountPriceStaffYear = 0;
  3374. for($month = 1; $month <= 12; $month ++) {
  3375. $flag = true;
  3376. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  3377. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  3378. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  3379. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  3380. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  3381. ';
  3382. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3383. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3384. $accountPriceStaffYear += $slv ['accountPrice'];
  3385. $flag = false;
  3386. break;
  3387. }
  3388. }
  3389. if ($flag)
  3390. $html .= '<td class="taR"></td>
  3391. <td class="taR"></td>
  3392. <td class="taR"><b></b></td>
  3393. ';
  3394. }
  3395. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3396. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3397. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3398. ';
  3399. }
  3400. $html .= '</tr>';
  3401. // 小计
  3402. if (! empty ( $value ['staff'] )) {
  3403. $html .= '<tr><th class="taR">小计</th>';
  3404. $invoicePriceStaffYear = 0;
  3405. $receivablesPriceStaffYear = 0;
  3406. $accountPriceStaffYear = 0;
  3407. for($month = 1; $month <= 12; $month ++) {
  3408. $flag = true;
  3409. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  3410. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  3411. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  3412. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  3413. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  3414. ';
  3415. $invoicePriceStaffYear += $slv ['invoicePrice'];
  3416. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  3417. $accountPriceStaffYear += $slv ['accountPrice'];
  3418. $flag = false;
  3419. break;
  3420. }
  3421. }
  3422. if ($flag)
  3423. $html .= '<td class="taR"></td>
  3424. <td class="taR"></td>
  3425. <td class="taR"><b></b></td>
  3426. ';
  3427. }
  3428. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  3429. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  3430. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  3431. ';
  3432. $html .= '</tr>';
  3433. }
  3434. }
  3435. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  3436. $invoicePriceYear = 0;
  3437. $receivablesPriceYear = 0;
  3438. $accountPriceYear = 0;
  3439. for($month = 1; $month <= 12; $month ++) {
  3440. $flag = true;
  3441. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  3442. if ($month == $v ['month']) {
  3443. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  3444. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  3445. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  3446. ';
  3447. $invoicePriceYear += $v ['invoicePrice'];
  3448. $receivablesPriceYear += $v ['receivablesPrice'];
  3449. $accountPriceYear += $v ['accountPrice'];
  3450. $flag = false;
  3451. break;
  3452. }
  3453. }
  3454. if ($flag)
  3455. $html .= '<td class="taR"></td>
  3456. <td class="taR"></td>
  3457. <td class="taR"><b></b></td>
  3458. ';
  3459. }
  3460. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  3461. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  3462. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  3463. ';
  3464. $html .= '</tr>';
  3465. $this->data ['html'] = $html;
  3466. $this->data ['isList'] = $toteList;
  3467. $this->data ['year'] = $year;
  3468. $this->data ['memu'] = "invoice";
  3469. $this->data ['staff'] = $this->staff;
  3470. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3471. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  3472. }
  3473. function invoiceAggregateCategory() {
  3474. Doo::loadClass ( 'XDeode' );
  3475. $XDeode = new XDeode ( 5 );
  3476. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  3477. $cid = $XDeode->decode ( $cid );
  3478. if (! is_numeric ( $cid ))
  3479. die ( 'illegal request' );
  3480. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  3481. Doo::loadModel ( 'invoiceStatistics' );
  3482. $invoiceStatistics = new invoiceStatistics ();
  3483. Doo::loadModel ( 'staff' );
  3484. $staff = new staff ();
  3485. $list = $staff->getStaffByCid ( $cid );
  3486. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  3487. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  3488. if (empty ( $list ))
  3489. die ( '该办事处没有成员' );
  3490. $htmlA = $htmlB = $htmlC = $html = '';
  3491. foreach ( $list as $key => $value ) {
  3492. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  3493. $htmlB = '<tr><th class="taC">收款</th>';
  3494. $htmlC = '<tr><th class="taC">入账</th>';
  3495. $invoicePriceStaffYear = 0;
  3496. $receivablesPriceStaffYear = 0;
  3497. $accountPriceStaffYear = 0;
  3498. for($month = 1; $month <= 12; $month ++) {
  3499. $flag = true;
  3500. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  3501. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  3502. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  3503. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  3504. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  3505. $invoicePriceStaffYear += $v ['invoicePrice'];
  3506. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  3507. $accountPriceStaffYear += $v ['accountPrice'];
  3508. $flag = false;
  3509. break;
  3510. }
  3511. }
  3512. if ($flag) {
  3513. $htmlA .= '<td class="taR">-</td>';
  3514. $htmlB .= '<td class="taR">-</td>';
  3515. $htmlC .= '<td class="taR"><b>-</b></td>';
  3516. }
  3517. }
  3518. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  3519. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  3520. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  3521. $htmlA .= '</tr>';
  3522. $htmlB .= '</tr>';
  3523. $htmlC .= '</tr>';
  3524. $html .= $htmlA . $htmlB . $htmlC;
  3525. }
  3526. $htmlA = $htmlB = $htmlC = "";
  3527. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  3528. $htmlB = '<tr><th class="taC">收款</th>';
  3529. $htmlC = '<tr><th class="taC">入账</th>';
  3530. $invoicePriceStaffYear = 0;
  3531. $receivablesPriceStaffYear = 0;
  3532. $accountPriceStaffYear = 0;
  3533. for($month = 1; $month <= 12; $month ++) {
  3534. $flag = true;
  3535. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  3536. if ($month == $v ['month']) {
  3537. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  3538. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  3539. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  3540. $invoicePriceStaffYear += $v ['invoicePrice'];
  3541. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  3542. $accountPriceStaffYear += $v ['accountPrice'];
  3543. $flag = false;
  3544. break;
  3545. }
  3546. }
  3547. if ($flag) {
  3548. $htmlA .= '<td class="taR">-</td>';
  3549. $htmlB .= '<td class="taR">-</td>';
  3550. $htmlC .= '<td class="taR"><b>-</b></td>';
  3551. }
  3552. }
  3553. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  3554. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  3555. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  3556. $htmlA .= '</tr>';
  3557. $htmlB .= '</tr>';
  3558. $htmlC .= '</tr>';
  3559. $html .= $htmlA . $htmlB . $htmlC;
  3560. $this->data ['html'] = $html;
  3561. $this->data ['cidKey'] = $cidKey;
  3562. $this->data ['slist'] = $list;
  3563. $this->data ['isList'] = $toteList;
  3564. $this->data ['year'] = $year;
  3565. $this->data ['memu'] = "invoice";
  3566. $this->data ['staff'] = $this->staff;
  3567. $this->data ['receiptMemu'] = 'invoiceAggregate';
  3568. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  3569. }
  3570. /**
  3571. * 办事处汇总信息
  3572. */
  3573. function invoiceAggregateCategoryDetail() {
  3574. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  3575. Doo::loadClass ( 'XDeode' );
  3576. $XDeode = new XDeode ( 5 );
  3577. Doo::loadModel ( 'invoiceStatistics' );
  3578. $invoiceStatistics = new invoiceStatistics ();
  3579. Doo::loadModel ( 'L_category' );
  3580. $category = new L_category ();
  3581. Doo::loadModel ( 'invoice' );
  3582. $invoice = new invoice ();
  3583. Doo::loadModel ( 'staff' );
  3584. $staff = new staff ();
  3585. Doo::loadModel ( "invoiceCategoryManage" );
  3586. $invoiceCategoryManage = new invoiceCategoryManage ();
  3587. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  3588. $cidList = array ();
  3589. foreach ( $imcStaff as $key => $value ) {
  3590. array_push ( $cidList, $value ['cid'] );
  3591. if (empty ( $cidKey ))
  3592. $cidKey = $XDeode->encode ( $value ['cid'] );
  3593. }
  3594. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  3595. $cid = $XDeode->decode ( $cidKey );
  3596. $month = date ( "m", strtotime ( "-1 month" ) );
  3597. $redis = new Redis ();
  3598. $redis->connect ( '127.0.0.1', '6379' );
  3599. $redisKey = ''; // date('Y-m-d').'_iacd_'.$cid;
  3600. $redisValue = ''; // $redis->lrange($redisKey, 0, -1);
  3601. if (empty ( $redisValue )) {
  3602. $isMC = $invoiceStatistics->getInvoiceStatistiscsMothByCategory ( $cid );
  3603. $schedule = $invoice->getInvoiceScheduleByCid ( $cid );
  3604. // 获得办事处人员下的汇总
  3605. $slist = $staff->getStaffByCid ( $cid );
  3606. $ismsbMonth = $invoiceStatistics->getISMSByCategoryByMonth ( $cid, $month ); // 上一个月的汇总
  3607. $ismsb = $invoiceStatistics->getISMSByCategory ( $cid ); // 当月汇总
  3608. $ISAS = $invoiceStatistics->getISASByCategory ( $cid ); // 全部汇总
  3609. $scheduleStaff = $invoice->getInvoiceScheduleByCidGroupSid ( $cid ); // 完成度
  3610. foreach ( $slist as $key => $value ) {
  3611. $slist [$key] ['invoicePrice'] = 0;
  3612. $slist [$key] ['receivablesPrice'] = 0;
  3613. $slist [$key] ['accountPrice'] = 0;
  3614. $slist [$key] ['invoiceAllPrice'] = 0;
  3615. $slist [$key] ['receivablesAllPrice'] = 0;
  3616. $slist [$key] ['accountAllPrice'] = 0;
  3617. $slist [$key] ['schedule'] = 0;
  3618. $slist [$key] ['invoiceMonthPrice'] = 0;
  3619. $slist [$key] ['receivablesMonthPrice'] = 0;
  3620. $slist [$key] ['accountMonthPrice'] = 0;
  3621. foreach ( $ismsbMonth as $y => $l ) {
  3622. if ($value ['sid'] == $l ['staff']) {
  3623. $slist [$key] ['invoiceMonthPrice'] = $l ['invoicePrice'];
  3624. $slist [$key] ['receivablesMonthPrice'] = $l ['receivablesPrice'];
  3625. $slist [$key] ['accountMonthPrice'] = $l ['accountPrice'];
  3626. }
  3627. }
  3628. foreach ( $ismsb as $k => $v ) {
  3629. if ($value ['sid'] == $v ['staff']) {
  3630. $slist [$key] ['invoicePrice'] = $v ['invoicePrice'];
  3631. $slist [$key] ['receivablesPrice'] = $v ['receivablesPrice'];
  3632. $slist [$key] ['accountPrice'] = $v ['accountPrice'];
  3633. }
  3634. }
  3635. foreach ( $ISAS as $e => $a ) {
  3636. if ($value ['sid'] == $a ['staff']) {
  3637. $slist [$key] ['invoiceAllPrice'] = $a ['invoicePrice'];
  3638. $slist [$key] ['receivablesAllPrice'] = $a ['receivablesPrice'];
  3639. $slist [$key] ['accountAllPrice'] = $a ['accountPrice'];
  3640. }
  3641. }
  3642. if (isset ( $scheduleStaff [$value ['sid']] ))
  3643. $slist [$key] ['schedule'] = $scheduleStaff [$value ['sid']];
  3644. }
  3645. $this->data ['cidKey'] = $cidKey;
  3646. $schedule = ( int ) ($schedule * 100);
  3647. $this->data ['slist'] = $slist;
  3648. $this->data ['isMC'] = $isMC;
  3649. $this->data ['schedule'] = $schedule;
  3650. $slist = json_encode ( $slist );
  3651. $isMC = json_encode ( $isMC );
  3652. $schedule = json_encode ( $schedule );
  3653. $redis->lpush ( $redisKey, $slist );
  3654. $redis->lpush ( $redisKey, $isMC );
  3655. $redis->lpush ( $redisKey, $schedule );
  3656. } else {
  3657. $this->data ['cidKey'] = $cidKey;
  3658. $this->data ['slist'] = json_decode ( $redisValue [2], true );
  3659. $this->data ['isMC'] = json_decode ( $redisValue [1], true );
  3660. $this->data ['schedule'] = json_decode ( $redisValue [0], true );
  3661. }
  3662. $this->data ['month'] = $month;
  3663. $this->data ['categoryList'] = $categoryList;
  3664. $this->data ['memu'] = "invoice";
  3665. $this->data ['staff'] = $this->staff;
  3666. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  3667. $this->render ( "/admin/invoiceAggregateCategoryDetail", $this->data );
  3668. }
  3669. /**
  3670. * 办事处人员汇总详情
  3671. */
  3672. function invoiceAggregateStaffDetail() {
  3673. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  3674. // $sidKey = isset ( $this->params ['sidKey'] ) ? $this->params ['sidKey'] : '';
  3675. Doo::loadClass ( 'XDeode' );
  3676. $XDeode = new XDeode ( 5 );
  3677. Doo::loadModel ( 'invoice' );
  3678. $invoice = new invoice ();
  3679. Doo::loadModel ( 'staff' );
  3680. $staff = new staff ();
  3681. Doo::loadModel ( "invoiceCategoryManage" );
  3682. $invoiceCategoryManage = new invoiceCategoryManage ();
  3683. $sid = $XDeode->decode ( $sidKey );
  3684. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  3685. $cidList = array ();
  3686. foreach ( $imcStaff as $key => $value ) {
  3687. array_push ( $cidList, $value ['cid'] );
  3688. if (empty ( $cidKey ))
  3689. $cidKey = $XDeode->encode ( $value ['cid'] );
  3690. }
  3691. $cidString = implode ( ',', $cidList );
  3692. $staffList = $staff->getStaffInCid ( $cidString );
  3693. $staffDetail = $staff->getStaffBySid ( $sid );
  3694. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3695. $page_size = 18;
  3696. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3697. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  3698. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  3699. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  3700. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  3701. $dateArr = explode ( ':', $date );
  3702. $D1 = '';
  3703. $D2 = '';
  3704. if (! empty ( $date )) {
  3705. $D1 = $dateArr [0] . " 00:00:00 ";
  3706. if (isset ( $dateArr [1] ))
  3707. $D2 = $dateArr [1] . " 23:59:59 ";
  3708. else
  3709. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  3710. // $D2 = $dateArr [1];
  3711. }
  3712. $con = ' status=2 ';
  3713. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3714. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3715. if ($status == 'UNRECORD')
  3716. $con .= ' and printStatus=1 and untreadStatus=0';
  3717. elseif ($status == 'RECORD')
  3718. $con .= ' and printStatus=1 and untreadStatus=3';
  3719. elseif ($status == 'BOUNCED')
  3720. $con .= ' and untreadStatus=2';
  3721. elseif ($status == 'PARTRECORD')
  3722. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  3723. elseif ($status == 'All') {
  3724. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  3725. }
  3726. $con .= ' and sid=' . $sid;
  3727. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  3728. if (! empty ( $MebSea )) {
  3729. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  3730. }
  3731. $pageinfo ['page'] = array (
  3732. 'previous' => ''
  3733. );
  3734. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateStaffDetail", $get, "" );
  3735. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3736. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  3737. $this->data ['staffDetail'] = $staffDetail;
  3738. $this->data ['staffList'] = $staffList;
  3739. $this->data ['MebSeaEn'] = $MebSea;
  3740. $this->data ['MebSea'] = urlencode ( $MebSea );
  3741. $this->data ['date'] = $date;
  3742. $this->data ['page'] = $pageinfo;
  3743. $this->data ['get'] = $get;
  3744. $this->data ['list'] = $list;
  3745. $this->data ['status'] = $status;
  3746. $this->data ['sidKey'] = $sidKey;
  3747. $this->data ['memu'] = "invoice";
  3748. $this->data ['staff'] = $this->staff;
  3749. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  3750. $this->render ( "/admin/invoiceAggregateStaffDetail", $this->data );
  3751. }
  3752. /**
  3753. * 办事处人员汇总收款情
  3754. */
  3755. function invoiceAggregateStaffReceivablesDetail() {
  3756. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  3757. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  3758. Doo::loadModel ( 'invoiceReceivables' );
  3759. $invoiceReceivables = new invoiceReceivables ();
  3760. Doo::loadModel ( 'staff' );
  3761. $staff = new staff ();
  3762. Doo::loadModel ( "invoiceCategoryManage" );
  3763. $invoiceCategoryManage = new invoiceCategoryManage ();
  3764. Doo::loadClass ( 'XDeode' );
  3765. $XDeode = new XDeode ( 5 );
  3766. $sid = $XDeode->decode ( $sidKey );
  3767. $staffDetail = $staff->getStaffBySid ( $sid );
  3768. $imcStaff = $invoiceCategoryManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  3769. $cidList = array ();
  3770. foreach ( $imcStaff as $key => $value ) {
  3771. array_push ( $cidList, $value ['cid'] );
  3772. if (empty ( $cidKey ))
  3773. $cidKey = $XDeode->encode ( $value ['cid'] );
  3774. }
  3775. $cidString = implode ( ',', $cidList );
  3776. $staffList = $staff->getStaffInCid ( $cidString );
  3777. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3778. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  3779. $page_size = 10;
  3780. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3781. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  3782. if ($timeType == "BINDOTP") {
  3783. $status = 'Credited';
  3784. }
  3785. $BeginDate = date ( 'Y-m-01', strtotime ( date ( "Y-m-d" ) ) );
  3786. $endDate = date ( 'Y-m-d', strtotime ( "$BeginDate +1 month -1 day" ) );
  3787. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : $BeginDate . " : " . $endDate;
  3788. $dateArr = explode ( ':', $date );
  3789. $D1 = '';
  3790. $D2 = '';
  3791. if (! empty ( $date )) {
  3792. $D1 = $dateArr [0] . " 00:00:00 ";
  3793. if (isset ( $dateArr [1] ))
  3794. $D2 = $dateArr [1] . " 23:59:59 ";
  3795. else
  3796. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  3797. }
  3798. $con = ' a.receivablesStaff like "%' . $staffDetail ['username'] . '%" ';
  3799. $descField = 'a.bindDate';
  3800. if ($timeType == 'CREATE')
  3801. $descField = 'a.date';
  3802. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3803. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3804. elseif (! empty ( $D1 ) && empty ( $D2 ))
  3805. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  3806. if ($status == 'Unclaimed')
  3807. $con .= ' and a.bindStatus=0';
  3808. elseif ($status == 'Credited')
  3809. $con .= ' and a.bindStatus=1';
  3810. elseif ($status == 'Claim')
  3811. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  3812. elseif ($status == 'BBN')
  3813. $con .= ' and a.bindPrice>a.receivablesPrice';
  3814. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea ) . "&sidKey=" . urlencode ( $sidKey );
  3815. if (! empty ( $MebSea )) {
  3816. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  3817. }
  3818. $pageinfo ['page'] = array (
  3819. 'previous' => ''
  3820. );
  3821. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  3822. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  3823. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  3824. where ' . $con . ' group by a.irid ';
  3825. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceAggregateStaffReceivablesDetail", $get, "" );
  3826. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3827. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', 'printTime' );
  3828. foreach ( $list as $key => $value ) {
  3829. $list [$key] ['category'] = '';
  3830. if ($value ['receivablesCategory'] != 'PUBLIC') {
  3831. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  3832. $list [$key] ['category'] = $receivablesCategory [1];
  3833. }
  3834. }
  3835. // print_r($list);
  3836. $this->data ['staffDetail'] = $staffDetail;
  3837. $this->data ['sidKey'] = $sidKey;
  3838. $this->data ['staffList'] = $staffList;
  3839. $this->data ['timeType'] = $timeType;
  3840. $this->data ['MebSeaEn'] = $MebSea;
  3841. $this->data ['MebSea'] = urlencode ( $MebSea );
  3842. $this->data ['date'] = $date;
  3843. $this->data ['page'] = $pageinfo;
  3844. $this->data ['get'] = $get;
  3845. $this->data ['list'] = $list;
  3846. $this->data ['status'] = $status;
  3847. $this->data ['memu'] = "invoice";
  3848. $this->data ['staff'] = $this->staff;
  3849. $this->data ['receiptMemu'] = 'invoiceAggregateCategoryDetail';
  3850. $this->render ( "/admin/invoiceAggregateStaffReceivablesDetail", $this->data );
  3851. }
  3852. function invoiceAchieve() {
  3853. Doo::loadModel ( 'invoice' );
  3854. $invoice = new invoice ();
  3855. Doo::loadClass ( 'XDeode' );
  3856. $XDeode = new XDeode ( 5 );
  3857. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  3858. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  3859. $page_size = 18;
  3860. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3861. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  3862. $get = "/" . $date;
  3863. $con = '';
  3864. if ($date == 'MONTHO')
  3865. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  3866. elseif ($date == 'MONTHT')
  3867. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  3868. elseif ($date == 'MONTHY')
  3869. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  3870. if (! empty ( $MebSea )) {
  3871. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  3872. $get .= "/" . $MebSea;
  3873. }
  3874. $pageinfo ['page'] = array (
  3875. 'previous' => ''
  3876. );
  3877. $sql = 'status=2 and printStatus=1 and irid!="" and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  3878. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  3879. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3880. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  3881. // print_r($pageinfo);
  3882. $this->data ['MebSeaEn'] = $MebSea;
  3883. $this->data ['MebSea'] = urlencode ( $MebSea );
  3884. $this->data ['get'] = $get;
  3885. $this->data ['page'] = $pageinfo;
  3886. $this->data ['list'] = $list;
  3887. $this->data ['date'] = $date;
  3888. $this->data ['memu'] = "invoice";
  3889. $this->data ['staff'] = $this->staff;
  3890. $this->data ['receiptMemu'] = 'invoice';
  3891. $this->render ( "/admin/invoiceAchieve", $this->data );
  3892. }
  3893. function invoiceMyUnAccountAchieve() {
  3894. Doo::loadModel ( 'invoice' );
  3895. $invoice = new invoice ();
  3896. Doo::loadClass ( 'XDeode' );
  3897. $XDeode = new XDeode ( 5 );
  3898. Doo::loadModel ( 'staff' );
  3899. $staff = new staff ();
  3900. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  3901. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  3902. $page_size = 18;
  3903. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3904. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  3905. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  3906. $dateArr = explode ( ':', $date );
  3907. $D1 = '';
  3908. $D2 = '';
  3909. if (! empty ( $date )) {
  3910. $D1 = $dateArr [0];
  3911. $D2 = $dateArr [1];
  3912. }
  3913. $con = '';
  3914. if (! empty ( $D1 ) && ! empty ( $D2 ))
  3915. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  3916. if (! empty ( $MebSea )) {
  3917. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  3918. }
  3919. $pageinfo ['page'] = array (
  3920. 'previous' => ''
  3921. );
  3922. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  3923. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  3924. $action = "invoiceMyUnAccountAchieve";
  3925. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  3926. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3927. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  3928. Doo::loadModel ( 'express' );
  3929. $express = new express ();
  3930. $expressList = $express->getExpressByAll ();
  3931. $this->data ['expressList'] = $expressList;
  3932. // print_r($list);
  3933. $this->data ['MebSeaEn'] = $MebSea;
  3934. $this->data ['get'] = $get;
  3935. $this->data ['page'] = $pageinfo;
  3936. $this->data ['date'] = $date;
  3937. $this->data ['list'] = $list;
  3938. $this->data ['memu'] = "invoice";
  3939. $this->data ['staff'] = $this->staff;
  3940. $this->data ['receiptMemu'] = 'invoice';
  3941. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  3942. }
  3943. function invoiceReceivablesAchieve() {
  3944. Doo::loadModel ( 'invoiceReceivables' );
  3945. $invoiceReceivables = new invoiceReceivables ();
  3946. Doo::loadClass ( 'XDeode' );
  3947. $XDeode = new XDeode ( 5 );
  3948. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  3949. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  3950. $page_size = 12;
  3951. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  3952. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  3953. $get = "/" . $date;
  3954. $con = '';
  3955. if ($date == 'MONTHO')
  3956. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  3957. elseif ($date == 'MONTHT')
  3958. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  3959. elseif ($date == 'MONTHY')
  3960. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  3961. if (! empty ( $MebSea )) {
  3962. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  3963. $get .= "/" . $MebSea;
  3964. }
  3965. $pageinfo ['page'] = array (
  3966. 'previous' => ''
  3967. );
  3968. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "_%' " . $con;
  3969. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  3970. $limit = $pageinfo ['lower'] . ',' . $page_size;
  3971. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  3972. // print_r($pageinfo);
  3973. $this->data ['MebSeaEn'] = $MebSea;
  3974. $this->data ['MebSea'] = urlencode ( $MebSea );
  3975. $this->data ['get'] = $get;
  3976. $this->data ['page'] = $pageinfo;
  3977. $this->data ['list'] = $list;
  3978. $this->data ['date'] = $date;
  3979. $this->data ['memu'] = "invoice";
  3980. $this->data ['staff'] = $this->staff;
  3981. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  3982. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  3983. }
  3984. /**
  3985. * 收款解绑
  3986. */
  3987. function invoiceUnBundLing() {
  3988. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  3989. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  3990. Doo::loadModel ( 'invoice' );
  3991. $invoice = new invoice ();
  3992. Doo::loadModel ( 'invoiceReceivables' );
  3993. $invoiceReceivables = new invoiceReceivables ();
  3994. Doo::loadModel ( 'invoiceOperationLog' );
  3995. $invoiceOperationLog = new invoiceOperationLog ();
  3996. Doo::loadModel ( 'invoiceROLog' );
  3997. $invoiceROLog = new invoiceROLog ();
  3998. Doo::loadModel ( 'invoiceStatistics' );
  3999. Doo::loadClass ( 'XDeode' );
  4000. $XDeode = new XDeode ( 5 );
  4001. if (empty ( $iidKey ))
  4002. die ( 'illegal request' );
  4003. $iid = $XDeode->decode ( $iidKey );
  4004. $irid = $invoice->authcode ( $unBundKey );
  4005. if ((! empty ( $irid ) && ! is_numeric ( $irid )) || (! empty ( $iid ) && ! is_numeric ( $iid )))
  4006. die ( 'illegal request' );
  4007. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4008. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  4009. if (empty ( $irDetails ) || empty ( $invoiceDetails ) || (empty ( $irDetails ['iid'] ) && empty ( $irDetails ['iidExtend'] )) || $invoiceDetails ['untreadStatus'] == 2)
  4010. die ( 'illegal request' );
  4011. // 收款
  4012. $item = array (
  4013. 'irid' => $irDetails ['irid'],
  4014. 'bindPrice' => $irDetails ['bindPrice'] - $invoiceDetails ['invoicePrice'],
  4015. 'bindStatus' => 0
  4016. );
  4017. if ($irDetails ['iid'] == $iid)
  4018. $item += array (
  4019. 'iid' => 0
  4020. );
  4021. else {
  4022. $iidExtend = explode ( ',', $irDetails ['iidExtend'] );
  4023. foreach ( $iidExtend as $key => $value ) {
  4024. if ($value == $iid)
  4025. unset ( $iidExtend [$key] );
  4026. }
  4027. $iidExtend = implode ( ',', $iidExtend );
  4028. $item += array (
  4029. 'iidExtend' => $iidExtend
  4030. );
  4031. }
  4032. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  4033. // 收款操作日志
  4034. $item = array (
  4035. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  4036. 'date' => date ( "Y-m-d" ),
  4037. 'status' => 3,
  4038. 'img' => $this->staff [0] ['avatar'],
  4039. 'username' => $this->staff [0] ['username'],
  4040. 'uid' => $this->staff [0] ['sid'],
  4041. 'category' => $this->staff [0] ['category'],
  4042. 'irid' => $irid
  4043. );
  4044. $invoiceROLog->setInvoiceROLog ( $item );
  4045. // 扣除入账统计金额
  4046. $invoiceStatistics = new invoiceStatistics ();
  4047. $item = array (
  4048. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4049. 'priceClass' => 3,
  4050. 'cid' => $invoiceDetails ['cid'],
  4051. 'staff' => $invoiceDetails ['sid'],
  4052. 'accountPrice' => - $irDetails ['receivablesPrice']
  4053. );
  4054. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4055. // 扣除收款统计金额
  4056. $invoiceStatistics = new invoiceStatistics ();
  4057. $item = array (
  4058. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['receivablesDate'] ) ),
  4059. 'priceClass' => 2,
  4060. 'cid' => $invoiceDetails ['cid'],
  4061. 'staff' => $invoiceDetails ['sid'],
  4062. 'irid' => $irDetails ['irid'],
  4063. 'receivablesPrice' => - $irDetails ['receivablesPrice']
  4064. );
  4065. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  4066. // 发票解绑去收款ID
  4067. $iridString = $invoiceDetails ['irid'];
  4068. if (! empty ( $invoiceDetails ['irid'] )) {
  4069. $list = explode ( ',', $invoiceDetails ['irid'] );
  4070. foreach ( $list as $key => $value ) {
  4071. if ($value == $irDetails ['irid']) {
  4072. unset ( $list [$key] );
  4073. break;
  4074. }
  4075. }
  4076. $iridString = implode ( ",", $list );
  4077. }
  4078. $item = array (
  4079. 'iid' => $invoiceDetails ['iid'],
  4080. 'irid' => $iridString,
  4081. 'updateTime' => date ( "Y-m-d H:i:s" )
  4082. );
  4083. if ($invoiceDetails ['untreadStatus'] == 3)
  4084. $item += array (
  4085. 'untreadStatus' => 0
  4086. );
  4087. $invoice->setInvoiceByCondition ( $item );
  4088. $item = array (
  4089. 'date' => date ( "Y-m-d H:i:s" ),
  4090. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  4091. 'status' => 11,
  4092. 'img' => $this->staff [0] ['avatar'],
  4093. 'username' => $this->staff [0] ['username'],
  4094. 'uid' => $this->staff [0] ['sid'],
  4095. 'category' => $this->staff [0] ['category'],
  4096. 'iid' => $invoiceDetails ['iid']
  4097. );
  4098. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  4099. return "/invoiceReceivablesAS";
  4100. }
  4101. /**
  4102. * 或者该收款下的所以发票
  4103. */
  4104. function ajaxGetInvoiceReceivablesByInvoice() {
  4105. $irid = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : '';
  4106. Doo::loadModel ( 'invoice' );
  4107. $invoice = new invoice ();
  4108. Doo::loadModel ( 'invoiceReceivables' );
  4109. $invoiceReceivables = new invoiceReceivables ();
  4110. $irid = $invoice->authcode ( $irid );
  4111. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  4112. die ( 'illegal request' );
  4113. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4114. $iidString = $irDetails ['iid'];
  4115. $iidExtend = array_filter ( explode ( ',', $irDetails ['iidExtend'] ) );
  4116. if (! empty ( $irDetails ['iidExtend'] ))
  4117. $iidString .= ',' . implode ( ',', $iidExtend );
  4118. $invoiceList = $invoice->getInvoiceInIid ( $iidString, 'iid,invoiceSerial,invoicePrice,invoiceTitle,invoiceCompany,invoiceElement' );
  4119. $html = "";
  4120. foreach ( $invoiceList as $key => $value ) {
  4121. $title = $value ['invoiceTitle'];
  4122. if (! empty ( $value ['invoiceCompany'] ))
  4123. $title = $value ['invoiceCompany'];
  4124. $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>';
  4125. }
  4126. echo json_encode ( array (
  4127. 'status' => 1,
  4128. 'html' => $html
  4129. ) );
  4130. }
  4131. /**
  4132. * 发票管理
  4133. */
  4134. function invoiceAS() {
  4135. Doo::loadModel ( 'invoice' );
  4136. $invoice = new invoice ();
  4137. Doo::loadModel ( 'invoiceReceivables' );
  4138. $invoiceReceivables = new invoiceReceivables ();
  4139. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4140. $page_size = 18;
  4141. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4142. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4143. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4144. $dateArr = explode ( ':', $date );
  4145. $D1 = '';
  4146. $D2 = '';
  4147. if (! empty ( $date )) {
  4148. $D1 = $dateArr [0] . " 00:00:00 ";
  4149. if (isset ( $dateArr [1] ))
  4150. $D2 = $dateArr [1] . " 23:59:59 ";
  4151. else
  4152. $D2 = $dateArr [0] . " 23:59:59 "; // date ( "Y-m-d" );
  4153. // $D2 = $dateArr [1];
  4154. }
  4155. $con = ' status=2 ';
  4156. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4157. $con .= ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4158. if ($status == 'UNRECORD')
  4159. $con .= ' and printStatus=1 and untreadStatus=0';
  4160. elseif ($status == 'RECORD')
  4161. $con .= ' and printStatus=1 and untreadStatus=3';
  4162. elseif ($status == 'BOUNCED')
  4163. $con .= ' and untreadStatus=2';
  4164. elseif ($status == 'PARTRECORD')
  4165. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4166. elseif ($status == 'All') {
  4167. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4168. }
  4169. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4170. if (! empty ( $MebSea )) {
  4171. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4172. }
  4173. $pageinfo ['page'] = array (
  4174. 'previous' => ''
  4175. );
  4176. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  4177. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4178. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4179. $this->data ['MebSeaEn'] = $MebSea;
  4180. $this->data ['MebSea'] = urlencode ( $MebSea );
  4181. $this->data ['date'] = $date;
  4182. $this->data ['page'] = $pageinfo;
  4183. $this->data ['get'] = $get;
  4184. $this->data ['list'] = $list;
  4185. $this->data ['status'] = $status;
  4186. $this->data ['memu'] = "invoice";
  4187. $this->data ['staff'] = $this->staff;
  4188. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4189. $this->render ( "/admin/invoiceAS", $this->data );
  4190. }
  4191. /**
  4192. * 收款管理
  4193. */
  4194. function invoiceReceivablesAS() {
  4195. Doo::loadModel ( 'invoiceReceivables' );
  4196. $invoiceReceivables = new invoiceReceivables ();
  4197. Doo::loadModel ( 'L_category' );
  4198. $lCategory = new L_category ();
  4199. $category = $lCategory->getCategory ();
  4200. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4201. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  4202. $page_size = 10;
  4203. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4204. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4205. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4206. $dateArr = explode ( ':', $date );
  4207. $D1 = '';
  4208. $D2 = '';
  4209. if (! empty ( $date )) {
  4210. $D1 = $dateArr [0]; // ." 00:00:00 ";
  4211. if (isset ( $dateArr [1] ))
  4212. $D2 = $dateArr [1]; // ." 23:59:59 ";
  4213. else
  4214. $D2 = $dateArr [0]; // ." 23:59:59 ";//date ( "Y-m-d" );
  4215. }
  4216. $descField = 'a.receivablesDate';
  4217. if ($timeType == 'CREATE')
  4218. $descField = 'a.date';
  4219. $con = '1';
  4220. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4221. $con .= ' and ' . $descField . ' BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4222. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4223. $con .= ' and ' . $descField . ' like "%' . $D1 . '%" ';
  4224. if ($status == 'Unclaimed')
  4225. $con .= ' and a.bindStatus=0';
  4226. elseif ($status == 'Credited')
  4227. $con .= ' and a.bindStatus=1';
  4228. elseif ($status == 'Claim')
  4229. $con .= ' and a.bindStatus=0 and a.receivablesStaff="PUBLIC"';
  4230. elseif ($status == 'BBN')
  4231. $con .= ' and a.bankBatchNumber!=""';
  4232. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  4233. if (! empty ( $MebSea )) {
  4234. $con .= ' and ( a.receivablesMessage like "%' . $MebSea . '%" or a.receivablesPrice like "%' . $MebSea . '%" )';
  4235. }
  4236. $pageinfo ['page'] = array (
  4237. 'previous' => ''
  4238. );
  4239. $sql = 'select group_concat(b.invoiceSerial) as invoiceSerial ,group_concat(b.iid) as invoiceId
  4240. from CLD_invoiceReceivables as a left join CLD_invoice as b on
  4241. find_in_set(b.iid,a.iidExtend) or a.iid=b.iid
  4242. where ' . $con . ' group by a.irid ';
  4243. $pageinfo = $this->getPageBySql ( $sql, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  4244. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4245. $list = $invoiceReceivables->getInvoiceReceivablesByConditionPage ( $limit, $con, 'desc', $descField );
  4246. foreach ( $list as $key => $value ) {
  4247. $list [$key] ['category'] = '';
  4248. if ($value ['receivablesCategory'] != 'PUBLIC') {
  4249. $receivablesCategory = explode ( ":", $value ['receivablesCategory'] );
  4250. $list [$key] ['category'] = $receivablesCategory [1];
  4251. }
  4252. }
  4253. // print_r($list);
  4254. $this->data ['category'] = $category;
  4255. $this->data ['timeType'] = $timeType;
  4256. $this->data ['MebSeaEn'] = $MebSea;
  4257. $this->data ['MebSea'] = urlencode ( $MebSea );
  4258. $this->data ['date'] = $date;
  4259. $this->data ['page'] = $pageinfo;
  4260. $this->data ['get'] = $get;
  4261. $this->data ['list'] = $list;
  4262. $this->data ['status'] = $status;
  4263. $this->data ['memu'] = "invoice";
  4264. $this->data ['staff'] = $this->staff;
  4265. $this->data ['receiptMemu'] = 'invoiceReceivables';
  4266. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  4267. }
  4268. // function invoiceApprovalAchieve() {
  4269. // Doo::loadModel ( 'invoice' );
  4270. // $invoice = new invoice ();
  4271. // $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4272. // $page_size = 12;
  4273. // $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4274. // $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4275. // $get = "/" . $date;
  4276. // $con = '';
  4277. // if ($date == 'MONTHO')
  4278. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4279. // elseif ($date == 'MONTHT')
  4280. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4281. // elseif ($date == 'MONTHY')
  4282. // $con = ' and approvalTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4283. // if (! empty ( $MebSea )) {
  4284. // $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4285. // $get .= "/" . $MebSea;
  4286. // }
  4287. // $pageinfo ['page'] = array (
  4288. // 'previous' => ''
  4289. // );
  4290. // $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; // echo $sql;
  4291. // $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  4292. // $limit = $pageinfo ['lower'] . ',' . $page_size;
  4293. // $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  4294. // // print_r($list);
  4295. // $this->data ['MebSeaEn'] = $MebSea;
  4296. // $this->data ['MebSea'] = urlencode ( $MebSea );
  4297. // $this->data ['get'] = $get;
  4298. // $this->data ['page'] = $pageinfo;
  4299. // $this->data ['list'] = $list;
  4300. // $this->data ['date'] = $date;
  4301. // $this->data ['memu'] = "invoice";
  4302. // $this->data ['staff'] = $this->staff;
  4303. // $this->data ['receiptMemu'] = 'invoiceApproval';
  4304. // $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  4305. // }
  4306. /**
  4307. * 获得审批发票的信息以及审批页面
  4308. */
  4309. function ajaxGetInvoiceApprovalDetail() {
  4310. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  4311. if (empty ( $serial )) {
  4312. echo json_encode ( array (
  4313. 'status' => 2,
  4314. 'msg' => 'illegal request'
  4315. ) );
  4316. die ();
  4317. }
  4318. Doo::loadModel ( 'invoice' );
  4319. $invoice = new invoice ();
  4320. Doo::loadModel ( 'invoiceOperationLog' );
  4321. $invoiceOperationLog = new invoiceOperationLog ();
  4322. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  4323. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  4324. if (empty ( $detail ))
  4325. $html = '';
  4326. else {
  4327. $html = '
  4328. <form action="/invoiceApprovalDo" method="post" name="invoiceApproval" class="nice-validator n-yellow" novalidate="novalidate">
  4329. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  4330. <input type="hidden" name="status" value="">
  4331. <input type="hidden" name="divApproval" value="divApproval">
  4332. <div class="modal-dialog modal-lg">
  4333. <div class="modal-content"><div class="modal-header"><h3>发票审批详情</h3></div>
  4334. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  4335. <tr>
  4336. <th class="taC" width="150">发票审批</th><td><textarea name="opinion" style="width:98%" placeholder="在这写下您的审批意见,选填。"></textarea></td>
  4337. </tr>
  4338. <tr>
  4339. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  4340. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  4341. </tr>
  4342. <tr>
  4343. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  4344. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  4345. </tr>
  4346. <tr>
  4347. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  4348. </td>
  4349. </tr>
  4350. <tr>
  4351. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  4352. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  4353. </tr>
  4354. <tr>
  4355. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  4356. </tr></tbody></table>';
  4357. if ($detail ['invoiceType'] == 0)
  4358. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4359. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  4360. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  4361. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  4362. </tr>';
  4363. else
  4364. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4365. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  4366. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  4367. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  4368. ';
  4369. $html .= '<tr>
  4370. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  4371. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  4372. </tr>
  4373. <tr>
  4374. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  4375. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  4376. </tr></tbody></table>';
  4377. if ($detail ['doPost'] == 1) {
  4378. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  4379. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  4380. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  4381. </tr><tr>
  4382. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  4383. </tr><tr>
  4384. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  4385. </tr>
  4386. ';
  4387. if ($detail ['expressCom'] == 'SF')
  4388. $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>';
  4389. else
  4390. $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>';
  4391. $html .= '</tbody></table>';
  4392. }
  4393. if (! empty ( $invoiceOperationLogList )) {
  4394. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  4395. foreach ( $invoiceOperationLogList as $key => $value ) {
  4396. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  4397. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  4398. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  4399. if ($value ['status'] == 2) {
  4400. $html .= '<span class="colGreen">同意</span>';
  4401. } elseif ($value ['status'] == 3) {
  4402. $html .= '<span class="colOrange">退回</span>';
  4403. } elseif ($value ['status'] == 5) {
  4404. $html .= '<span class="colGreen">打印</span>';
  4405. } elseif ($value ['status'] == 4) {
  4406. $html .= '<span class="colRed">终止</span>';
  4407. }
  4408. $html .= $value ['operation'] . '</p></blockquote>';
  4409. }
  4410. }
  4411. $html .= '</td></tr></tbody></table>';
  4412. }
  4413. $html .= '</div><div class="modal-footer">
  4414. <a href="javascript:void(0)" node-approval="approval" diss-data="2" class="button btn-done" data-placement="top" data-toggle="ctooltip" >同意</a>
  4415. <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>
  4416. <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>
  4417. <a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>
  4418. </form>
  4419. <script type="text/javascript">
  4420. $("a[node-approval^=\'approval\']").click(function() {
  4421. $("input[name=\'status\']").val($(this).attr("diss-data"));
  4422. $("form[name=\'invoiceApproval\']").submit();
  4423. });
  4424. </script>
  4425. ';
  4426. }
  4427. echo json_encode ( array (
  4428. 'status' => 1,
  4429. 'html' => $html
  4430. ) );
  4431. die ();
  4432. }
  4433. /**
  4434. * 获得审批发票分页数据
  4435. */
  4436. function ajaxGetinvoiceApprovalAchieve() {
  4437. Doo::loadModel ( 'invoice' );
  4438. $invoice = new invoice ();
  4439. Doo::loadModel ( 'staff' );
  4440. $staff = new staff ();
  4441. Doo::loadClass ( 'XDeode' );
  4442. $XDeode = new XDeode ( 5 );
  4443. $status = $this->get_args ( 'status' ) ? $this->get_args ( 'status' ) : 'ALL';
  4444. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  4445. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  4446. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  4447. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4448. $page = $this->get_args ( 'start' ) && is_numeric ( $this->get_args ( 'start' ) ) ? $this->get_args ( 'start' ) : 0;
  4449. $draw = $this->get_args ( 'draw' ) && is_numeric ( $this->get_args ( 'draw' ) ) ? $this->get_args ( 'draw' ) : 1;
  4450. $length = $this->get_args ( 'length' ) && is_numeric ( $this->get_args ( 'length' ) ) ? $this->get_args ( 'length' ) : 10;
  4451. $MebSea = $this->get_args ( 'search' );
  4452. $MebSea = $MebSea ['value'];
  4453. $page_size = $length;
  4454. $con = '';
  4455. if ($status == 'ALL')
  4456. $con = ' (status=1 or status=2 or status=3 or status=4) and isDelete=0 ';
  4457. elseif ($status == 'PEND')
  4458. $con = ' isDelete=0 and status=1';
  4459. elseif ($status == 'APPROVED')
  4460. $con = ' isDelete=0 and status=2';
  4461. if ($invoiceType == 'ORDINARY')
  4462. $con .= ' and invoiceType=0 ';
  4463. elseif ($invoiceType == 'SPECIAL')
  4464. $con .= ' and invoiceType=1 ';
  4465. if ($invoiceTrain == 'ORDINARY')
  4466. $con .= ' and trainId=0 ';
  4467. elseif ($invoiceTrain == 'TRAIN')
  4468. $con .= ' and trainId!=0 ';
  4469. if ($invoiceTrainName != 'ALL') {
  4470. $trainId = $XDeode->decode ( $invoiceTrainName );
  4471. if (is_numeric ( $trainId ))
  4472. $con .= ' and trainId =' . $trainId;
  4473. }
  4474. $dateArr = explode ( ':', $date );
  4475. $D1 = $dateString = '';
  4476. $D2 = '';
  4477. if (! empty ( $date )) {
  4478. $D1 = $dateArr [0];
  4479. if (isset ( $dateArr [1] ))
  4480. $D2 = $dateArr [1];
  4481. else
  4482. $D2 = '';
  4483. $dateString = $D1 . " : " . $D2;
  4484. }
  4485. if (! empty ( $D1 ) && ! empty ( $D2 ))
  4486. $con .= ' and approvalTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  4487. elseif (! empty ( $D1 ) && empty ( $D2 ))
  4488. $con .= ' and approvalTime like "%' . $D1 . '%" ';
  4489. if (! empty ( $MebSea ))
  4490. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" or invoiceSerial like "%' . $MebSea . '%" )';
  4491. // /
  4492. $pageinfo ['page'] = array (
  4493. 'previous' => ''
  4494. );
  4495. $sql = ' ' . $con;
  4496. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", '', "" );
  4497. $limit = $page . ',' . $page_size;
  4498. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 2 );
  4499. $approvalList = array ();
  4500. $html = '
  4501. <script type="text/javascript">
  4502. </script>
  4503. ';
  4504. foreach ( $list as $key => $value ) {
  4505. $irDetail = array ();
  4506. if ($value ['status'] == 1 && $value ['pendingApprovals'] == $this->staff [0] ['sid']) {
  4507. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoiceApproval(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">审批发票</a>' );
  4508. } else
  4509. array_push ( $irDetail, '' );
  4510. array_push ( $irDetail, '<a href="#approvalInvice" onclick="nodeInvoice(\'' . $value ['iidKeyK'] . '\')" data-toggle="modal">' . $value ['invoiceSerial'] . '</a>' );
  4511. if ($value ['invoiceType'] == 1)
  4512. array_push ( $irDetail, $value ['invoiceCompany'] );
  4513. else
  4514. array_push ( $irDetail, $value ['invoiceTitle'] );
  4515. array_push ( $irDetail, $value ['TIN'] );
  4516. array_push ( $irDetail, $value ['address'] . $value ['phone'] );
  4517. array_push ( $irDetail, $value ['bank'] . $value ['bankAccount'] );
  4518. array_push ( $irDetail, $value ['remark'] );
  4519. array_push ( $irDetail, $value ['invoiceElement'] );
  4520. array_push ( $irDetail, $value ['invoiceQuantity'] );
  4521. array_push ( $irDetail, $value ['invoiceUnitPrice'] );
  4522. if ($value ['invoiceType'] == 1)
  4523. array_push ( $irDetail, '¥' . $value ['invoicePrice'] . '<sup>专</sup>' );
  4524. else
  4525. array_push ( $irDetail, '¥' . $value ['invoicePrice'] );
  4526. array_push ( $irDetail, $value ['recipients'] . $value ['recipientsPhone'] );
  4527. array_push ( $irDetail, $value ['recipientsAddress'] );
  4528. array_push ( $irDetail, $value ['mailItems'] );
  4529. array_push ( $irDetail, $value ['userName'] . '&nbsp;' . $value ['date'] );
  4530. $fchtml = $value ['OL'] ['operation'];
  4531. if (count ( $list ) == $page_size)
  4532. $fchtml = $value ['OL'] ['operation'] . $html;
  4533. // 最后的审批意见
  4534. array_push ( $irDetail, $fchtml );
  4535. if ($value ['status'] == 2)
  4536. array_push ( $irDetail, '<span class="colGreen">同意</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  4537. elseif ($value ['status'] == 3)
  4538. array_push ( $irDetail, '<span class="colOrange">退回</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  4539. elseif ($value ['status'] == 4)
  4540. array_push ( $irDetail, '<span class="colRed">终止</span>' . $value ['OL'] ['username'] . $value ['OL'] ['date'] );
  4541. else
  4542. array_push ( $irDetail, '' );
  4543. array_push ( $approvalList, $irDetail );
  4544. }
  4545. // $approvalListJson = json_encode ( $approvalList );
  4546. $recordsFiltered = $pageinfo ['total_data'];
  4547. echo json_encode ( array (
  4548. "draw" => intval ( $draw ),
  4549. "recordsTotal" => intval ( $pageinfo ['total_data'] ),
  4550. "recordsFiltered" => intval ( $recordsFiltered ),
  4551. "data" => $approvalList
  4552. ), JSON_UNESCAPED_UNICODE );
  4553. }
  4554. /**
  4555. * 审批发票查看更多--重构
  4556. */
  4557. function invoiceApprovalAchieve() {
  4558. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'ALL';
  4559. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  4560. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  4561. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  4562. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  4563. Doo::loadModel ( 'invoiceTraining' );
  4564. $invoiceTraining = new invoiceTraining ();
  4565. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  4566. $this->data ['trainList'] = $trainList;
  4567. $this->data ['dateString'] = $date;
  4568. $this->data ['status'] = $status;
  4569. $this->data ['invoiceType'] = $invoiceType;
  4570. $this->data ['invoiceTrain'] = $invoiceTrain;
  4571. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  4572. $this->data ['memu'] = "invoice";
  4573. $this->data ['staff'] = $this->staff;
  4574. $this->data ['receiptMemu'] = 'invoiceApproval';
  4575. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  4576. }
  4577. function invoiceTAchieve() {
  4578. Doo::loadModel ( 'invoice' );
  4579. $invoice = new invoice ();
  4580. Doo::loadClass ( 'XDeode' );
  4581. $XDeode = new XDeode ( 5 );
  4582. Doo::loadModel ( 'staff' );
  4583. $staff = new staff ();
  4584. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  4585. $page_size = 12;
  4586. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4587. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  4588. $invoiceType = $this->get_args ( 'invoiceType' ) ? $this->get_args ( 'invoiceType' ) : "ALL";
  4589. $invoiceTrain = $this->get_args ( 'invoiceTrain' ) ? $this->get_args ( 'invoiceTrain' ) : "ALL";
  4590. $invoiceTrainName = $this->get_args ( 'invoiceTrainName' ) ? $this->get_args ( 'invoiceTrainName' ) : "ALL";
  4591. Doo::loadModel ( 'invoiceTraining' );
  4592. $invoiceTraining = new invoiceTraining ();
  4593. $trainList = $invoiceTraining->getInvoiceTrainingBySubmitStatus ();
  4594. $get = "/" . $date;
  4595. $con = '';
  4596. if ($date == 'MONTHO')
  4597. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  4598. elseif ($date == 'MONTHT')
  4599. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  4600. elseif ($date == 'MONTHY')
  4601. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  4602. if ($invoiceType == 'ORDINARY')
  4603. $con .= ' and invoiceType=0 ';
  4604. elseif ($invoiceType == 'SPECIAL')
  4605. $con .= ' and invoiceType=1 ';
  4606. if ($invoiceTrain == 'ORDINARY')
  4607. $con .= ' and trainId=0 ';
  4608. elseif ($invoiceTrain == 'TRAIN')
  4609. $con .= ' and trainId!=0 ';
  4610. if ($invoiceTrainName != 'ALL') {
  4611. $trainId = $XDeode->decode ( $invoiceTrainName );
  4612. if (is_numeric ( $trainId ))
  4613. $con .= ' and trainId =' . $trainId;
  4614. }
  4615. if (! empty ( $MebSea )) {
  4616. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  4617. $get .= "/" . $MebSea;
  4618. }
  4619. $pageinfo ['page'] = array (
  4620. 'previous' => ''
  4621. );
  4622. $sql = "";
  4623. $action = "";
  4624. if ($this->ACTION == 'invoicePrintAchieve') {
  4625. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  4626. $action = "invoicePrintAchieve";
  4627. } elseif ($this->ACTION == 'invoicePostAchieve') {
  4628. // and untreadStatus=0
  4629. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  4630. $action = "invoicePostAchieve";
  4631. } elseif ($this->ACTION == 'invoiceUntreadAchieve') { // printStatus=1 and
  4632. $sql = " untreadStatus=2 and status=2 " . $con;
  4633. $action = "invoiceUntreadAchieve";
  4634. }
  4635. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  4636. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4637. $this->data ['MebSeaEn'] = $MebSea;
  4638. $this->data ['MebSea'] = urlencode ( $MebSea );
  4639. $this->data ['get'] = $get;
  4640. $this->data ['page'] = $pageinfo;
  4641. $this->data ['trainList'] = $trainList;
  4642. $this->data ['invoiceType'] = $invoiceType;
  4643. $this->data ['invoiceTrain'] = $invoiceTrain;
  4644. $this->data ['invoiceTrainName'] = $invoiceTrainName;
  4645. $this->data ['date'] = $date;
  4646. $this->data ['memu'] = "invoice";
  4647. $this->data ['staff'] = $this->staff;
  4648. if ($this->ACTION == 'invoicePrintAchieve') {
  4649. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql, 'desc', 5 );
  4650. $this->data ['receiptMemu'] = 'invoicePrint';
  4651. $this->data ['list'] = $list;
  4652. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  4653. } elseif ($this->ACTION == 'invoicePostAchieve') {
  4654. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4655. Doo::loadModel ( 'express' );
  4656. $express = new express ();
  4657. $expressList = $express->getExpressByAll ();
  4658. $this->data ['expressList'] = $expressList;
  4659. $this->data ['receiptMemu'] = 'invoicePost';
  4660. $this->data ['list'] = $list;
  4661. $this->render ( "/admin/invoicePostAchieve", $this->data );
  4662. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  4663. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  4664. $this->data ['receiptMemu'] = 'invoiceUntread';
  4665. $this->data ['list'] = $list;
  4666. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  4667. }
  4668. }
  4669. /**
  4670. * 公司应收款
  4671. */
  4672. function invoiceAggregateCompanyDetail() {
  4673. $sidKey = $this->get_args ( 'sidKey' ) ? $this->get_args ( 'sidKey' ) : '';
  4674. $cidKey = $this->get_args ( 'cidKey' ) ? $this->get_args ( 'cidKey' ) : '';
  4675. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date("Y");
  4676. $month = $this->get_args ( 'month' ) ? $this->get_args ( 'month' ) : "";
  4677. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  4678. Doo::loadClass ( 'XDeode' );
  4679. $XDeode = new XDeode ( 5 );
  4680. Doo::loadModel ( 'invoice' );
  4681. $invoice = new invoice ();
  4682. Doo::loadModel ( 'staff' );
  4683. $staff = new staff ();
  4684. Doo::loadModel ( "invoiceCompanyManage" );
  4685. $invoiceCompanyManage = new invoiceCompanyManage ();
  4686. Doo::loadModel ( 'L_category' );
  4687. $category = new L_category ();
  4688. $sid='';
  4689. if (!empty($sidKey))
  4690. $sid = $XDeode->decode ( $sidKey );
  4691. $staffDetail = $staff->getStaffBySid ( $sid );
  4692. $cid='';
  4693. if (!empty($cidKey))
  4694. $cid = $XDeode->decode ( $cidKey );
  4695. $imcStaff = $invoiceCompanyManage->getInvoiceCMByStaff ( $this->staff [0] ['sid'] );
  4696. $cidList = array ();
  4697. foreach ( $imcStaff as $key => $value ) {
  4698. array_push ( $cidList, $value ['cid'] );
  4699. }
  4700. $categoryList = $category->getCategoryInCid ( implode ( ',', $cidList ) );
  4701. $cidString = implode ( ',', $cidList );
  4702. $staffList = $staff->getStaffInCid ( $cidString );
  4703. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  4704. $page_size = 2;
  4705. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  4706. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  4707. $con = ' status=2 ';
  4708. if (! empty ( $year ))
  4709. $con .= ' and Year(printTime)=' . $year . '';
  4710. if ( ! empty ( $month )&&is_numeric($month))
  4711. $con .= ' and Month(printTime)="' . $month . '" ';
  4712. if ($status == 'UNRECORD')
  4713. $con .= ' and printStatus=1 and untreadStatus=0';
  4714. elseif ($status == 'RECORD')
  4715. $con .= ' and printStatus=1 and untreadStatus=3';
  4716. elseif ($status == 'BOUNCED')
  4717. $con .= ' and untreadStatus=2';
  4718. elseif ($status == 'PARTRECORD')
  4719. $con .= ' and untreadStatus=0 and printStatus=1 and irid!=""';
  4720. elseif ($status == 'All') {
  4721. $con .= ' and printStatus=1 and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  4722. }
  4723. if(!empty($sid)&&is_numeric($sid))
  4724. $con .= ' and sid=' . $sid;
  4725. if(!empty($cid)&&is_numeric($cid))
  4726. $con .= ' and cid=' . $cid;
  4727. //开票内容筛选
  4728. if(!empty($invoiceElement)&&$invoiceElement!='ALL'){
  4729. $con .= ' and invoiceElement="' . $invoiceElement.'"';
  4730. }
  4731. $get = "/" . $status . "?cidKey=".$cidKey."&sidKey=".$sidKey."&year=".$year."&month=".$month."&invoiceElement=".$invoiceElement ;
  4732. if (! empty ( $MebSea )) {
  4733. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  4734. }
  4735. $pageinfo ['page'] = array (
  4736. 'previous' => ''
  4737. );
  4738. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAggregateCompanyDetail", $get, "" );
  4739. $limit = $pageinfo ['lower'] . ',' . $page_size;
  4740. //应收款合计
  4741. $ics=$invoice->getInvoiceCompanyStatistics($con);
  4742. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  4743. $monthHtml = "";
  4744. for($i = 1; $i <= 12; $i ++) {
  4745. if ($i == $month)
  4746. $monthHtml .= '<option selected value="' . $i . '">' . $i . '</option>';
  4747. else
  4748. $monthHtml .= '<option value="' . $i . '">' . $i . '</option>';
  4749. }
  4750. $this->data ['monthHtml'] = $monthHtml;
  4751. $this->data ['year'] = $year;
  4752. $this->data ['month'] = $month;
  4753. $this->data['ics']=$ics;
  4754. $this->data ['cidKey']=$cidKey;
  4755. $this->data ['sid'] =$sid;
  4756. $this->data ['staffDetail'] = $staffDetail;
  4757. $this->data ['staffList'] = $staffList;
  4758. $this->data ['MebSeaEn'] = $MebSea;
  4759. $this->data ['MebSea'] = urlencode ( $MebSea );
  4760. $this->data ['invoiceDetail'] = array('invoiceElement'=>$invoiceElement);
  4761. $this->data ['page'] = $pageinfo;
  4762. $this->data ['get'] = $get;
  4763. $this->data ['list'] = $list;
  4764. $this->data ['status'] = $status;
  4765. $this->data ['categoryList'] =$categoryList;
  4766. $this->data ['memu'] = "invoice";
  4767. $this->data ['staff'] = $this->staff;
  4768. $this->data ['receiptMemu'] = 'invoiceAggregateCompanyDetail';
  4769. $this->render ( "/admin/invoiceAggregateCompanyDetail", $this->data );
  4770. }
  4771. /**
  4772. * 获取一条收款信息
  4773. */
  4774. function ajaxGetInvoiceReceivables() {
  4775. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  4776. Doo::loadModel ( 'invoiceReceivables' );
  4777. $invoiceReceivables = new invoiceReceivables ();
  4778. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  4779. echo json_encode ( array (
  4780. 'status' => 1,
  4781. 'detail' => $detail
  4782. ) );
  4783. }
  4784. /**
  4785. * 异步获取办事处用户
  4786. */
  4787. function ajaxGetStaffByCategory() {
  4788. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  4789. Doo::loadModel ( 'staff' );
  4790. $staff = new staff ();
  4791. if ($cid == "PUBLIC") {
  4792. echo json_encode ( array (
  4793. 'status' => 1,
  4794. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  4795. ) );
  4796. die ();
  4797. }
  4798. if (! is_numeric ( $cid )) {
  4799. echo json_encode ( array (
  4800. 'status' => 0,
  4801. 'msg' => 'illegal request'
  4802. ) );
  4803. die ();
  4804. }
  4805. $staffList = $staff->getStaffByCid ( $cid );
  4806. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  4807. foreach ( $staffList as $key => $value ) {
  4808. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  4809. }
  4810. echo json_encode ( array (
  4811. 'status' => 1,
  4812. 'html' => $html
  4813. ) );
  4814. }
  4815. /**
  4816. * 异步获取一条发票的邮寄信息
  4817. */
  4818. function ajaxGetInvoicePostDetail() {
  4819. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  4820. Doo::loadModel ( 'invoice' );
  4821. $invoice = new invoice ();
  4822. $iid = $invoice->authcode ( $iid );
  4823. Doo::loadModel ( 'express' );
  4824. $express = new express ();
  4825. $expressList = $express->getExpressByAll ();
  4826. if (! is_numeric ( $iid )) {
  4827. echo json_encode ( array (
  4828. 'status' => 0,
  4829. 'msg' => 'illegal request'
  4830. ) );
  4831. die ();
  4832. }
  4833. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  4834. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  4835. $html = "";
  4836. foreach ( $expressList as $key => $value ) {
  4837. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  4838. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  4839. else
  4840. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  4841. }
  4842. $invoiceDetail ['eaHtml'] = $html;
  4843. echo json_encode ( array (
  4844. 'status' => 1,
  4845. 'invoiceDetail' => $invoiceDetail
  4846. ) );
  4847. }
  4848. /**
  4849. *
  4850. * @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 ) ); }
  4851. */
  4852. /**
  4853. *
  4854. * @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 ) ); }
  4855. */
  4856. /**
  4857. * 我的收款中 选择哪个发票入账,进行金额判断
  4858. */
  4859. function ajaxCompareInvoicePrice() {
  4860. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  4861. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  4862. Doo::loadModel ( 'invoice' );
  4863. $invoice = new invoice ();
  4864. Doo::loadModel ( 'invoiceReceivables' );
  4865. $invoiceReceivables = new invoiceReceivables ();
  4866. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  4867. $keyList = explode ( ';', $claimKey );
  4868. $receivablesPrice = 0;
  4869. foreach ( $keyList as $key => $value ) {
  4870. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  4871. $receivablesPrice += $detailM ['receivablesPrice'];
  4872. }
  4873. if ($receivablesPrice > $detail ['invoicePrice']) {
  4874. $price = $receivablesPrice - $detail ['invoicePrice'];
  4875. echo json_encode ( array (
  4876. 'status' => 1,
  4877. 'price' => $price
  4878. ) );
  4879. } else
  4880. echo json_encode ( array (
  4881. 'status' => 2
  4882. ) );
  4883. }
  4884. /**
  4885. * 获得打印发票
  4886. */
  4887. function ajaxGetInvoiceInfoByPrint() {
  4888. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  4889. if (empty ( $serial )) {
  4890. echo json_encode ( array (
  4891. 'status' => 2,
  4892. 'msg' => 'illegal request'
  4893. ) );
  4894. die ();
  4895. }
  4896. Doo::loadModel ( 'invoice' );
  4897. $invoice = new invoice ();
  4898. Doo::loadModel ( 'invoiceOperationLog' );
  4899. $invoiceOperationLog = new invoiceOperationLog ();
  4900. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  4901. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  4902. Doo::loadModel ( 'invoicePaper' );
  4903. $invoicePaper = new invoicePaper ();
  4904. $invoicePaperList = $invoicePaper->getInvoicePaperByInvoiceType ( $detail ['invoiceType'] );
  4905. if (empty ( $detail ))
  4906. $html = '';
  4907. else {
  4908. $html = '
  4909. <form action="/invoicePrintDo" method="post" name="invoicePrint" class="nice-validator n-yellow" onSubmit="return checkPrintForm()" novalidate="novalidate">
  4910. <input type="hidden" name="invoiceKey" value="' . $detail ['iidKeyXD'] . '">
  4911. <input type="hidden" name="invoicePrintType" value="invoicePrintType">
  4912. <div class="modal-dialog modal-lg">
  4913. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  4914. <div class="modal-body saeaList">
  4915. <table class="table table-bordered table-condensed"><tbody>
  4916. <tr>
  4917. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  4918. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  4919. </tr>
  4920. <tr>
  4921. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  4922. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  4923. </tr>
  4924. <tr>
  4925. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  4926. </td>
  4927. </tr>
  4928. <tr>
  4929. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  4930. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  4931. </tr>
  4932. <tr>
  4933. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  4934. </tr></tbody></table>';
  4935. if ($detail ['invoiceType'] == 0)
  4936. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4937. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  4938. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  4939. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  4940. </tr>';
  4941. else
  4942. $html .= '<table class="table table-bordered table-condensed"><tbody>
  4943. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  4944. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  4945. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  4946. ';
  4947. $html .= '<tr>
  4948. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  4949. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  4950. </tr>
  4951. <tr>
  4952. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  4953. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  4954. </tr></tbody></table>';
  4955. if ($detail ['doPost'] == 1)
  4956. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  4957. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  4958. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  4959. </tr><tr>
  4960. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  4961. </tr><tr>
  4962. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  4963. </tr></tbody></table>';
  4964. if (! empty ( $invoiceOperationLogList )) {
  4965. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th><th class="taC">发票打印</th></tr><tr><td>';
  4966. foreach ( $invoiceOperationLogList as $key => $value ) {
  4967. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  4968. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  4969. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  4970. if ($value ['status'] == 2) {
  4971. $html .= '<span class="colGreen">同意</span>';
  4972. } elseif ($value ['status'] == 3) {
  4973. $html .= '<span class="colOrange">退回</span>';
  4974. } elseif ($value ['status'] == 5) {
  4975. $html .= '<span class="colGreen">打印</span>';
  4976. } elseif ($value ['status'] == 4) {
  4977. $html .= '<span class="colRed">终止</span>';
  4978. }
  4979. $html .= $value ['operation'] . '</p></blockquote>';
  4980. }
  4981. }
  4982. $html .= '</td>
  4983. <td><span class="colRed">*</span>
  4984. <select name="invoiceNo" id="invoiceNo" style="width:97%">';
  4985. foreach ( $invoicePaperList as $key => $value ) {
  4986. $html .= '<option value="' . $value ['ipidKey'] . '">No.' . $value ['invoiceNo'] . '</option>';
  4987. }
  4988. $html .= '</select>
  4989. <span class="red" id="p-msg"></span>
  4990. </td>
  4991. </tr></tbody></table>';
  4992. }
  4993. $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>
  4994. </div></div></form>
  4995. <link rel=stylesheet href="' . WEB_SITE_GLOBAL . 'css/jquery.validator.css">
  4996. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/jquery.validator.min.js"></script>
  4997. <script type="text/javascript" src="' . WEB_SITE_GLOBAL . 'js/zh-CN.js"></script>
  4998. <script src="' . WEB_SITE_GLOBAL . 'js/invoice.validator.js"></script>
  4999. ';
  5000. }
  5001. echo json_encode ( array (
  5002. 'status' => 1,
  5003. 'html' => $html
  5004. ) );
  5005. die ();
  5006. }
  5007. /**
  5008. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  5009. */
  5010. function ajaxGetInvoiceInfoByType() {
  5011. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  5012. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  5013. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  5014. if (empty ( $serial )) {
  5015. echo json_encode ( array (
  5016. 'status' => 2,
  5017. 'msg' => 'illegal request'
  5018. ) );
  5019. die ();
  5020. }
  5021. if ($type == 'INVOICE') {
  5022. Doo::loadModel ( 'invoice' );
  5023. $invoice = new invoice ();
  5024. Doo::loadModel ( 'invoiceOperationLog' );
  5025. $invoiceOperationLog = new invoiceOperationLog ();
  5026. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5027. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5028. if (empty ( $detail ))
  5029. $html = '';
  5030. else {
  5031. $html = '
  5032. <div class="modal-dialog modal-lg">
  5033. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  5034. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  5035. <tr>
  5036. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5037. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5038. </tr>
  5039. <tr>
  5040. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5041. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5042. </tr>
  5043. <tr>
  5044. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  5045. </td>
  5046. </tr>
  5047. <tr>
  5048. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5049. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5050. </tr>
  5051. <tr>
  5052. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5053. </tr></tbody></table>';
  5054. if ($detail ['invoiceType'] == 0)
  5055. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5056. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5057. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5058. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5059. </tr>';
  5060. else
  5061. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5062. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5063. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5064. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5065. ';
  5066. $html .= '<tr>
  5067. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5068. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5069. </tr>
  5070. <tr>
  5071. <th class="taC">开户银行</th><td>' . $detail ['bank'] . '</td>
  5072. <th class="taC">银行账号</th><td>' . $detail ['bankAccount'] . '</td>
  5073. </tr></tbody></table>';
  5074. if ($detail ['doPost'] == 1) {
  5075. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5076. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5077. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5078. </tr><tr>
  5079. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5080. </tr><tr>
  5081. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5082. </tr>
  5083. ';
  5084. if ($detail ['expressCom'] == 'SF')
  5085. $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>';
  5086. else
  5087. $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>';
  5088. $html .= '</tbody></table>';
  5089. }
  5090. if (! empty ( $invoiceOperationLogList )) {
  5091. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5092. foreach ( $invoiceOperationLogList as $key => $value ) {
  5093. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5094. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5095. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5096. if ($value ['status'] == 2) {
  5097. $html .= '<span class="colGreen">同意</span>';
  5098. } elseif ($value ['status'] == 3) {
  5099. $html .= '<span class="colOrange">退回</span>';
  5100. } elseif ($value ['status'] == 5) {
  5101. $html .= '<span class="colGreen">打印</span>';
  5102. } elseif ($value ['status'] == 4) {
  5103. $html .= '<span class="colRed">终止</span>';
  5104. }
  5105. $html .= $value ['operation'] . '</p></blockquote>';
  5106. }
  5107. }
  5108. $html .= '</td></tr></tbody></table>';
  5109. }
  5110. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5111. }
  5112. echo json_encode ( array (
  5113. 'status' => 1,
  5114. 'html' => $html
  5115. ) );
  5116. die ();
  5117. } elseif ($type == 'RECEIVABLES') {
  5118. Doo::loadModel ( 'invoiceReceivables' );
  5119. $invoiceReceivables = new invoiceReceivables ();
  5120. //
  5121. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  5122. if (empty ( $detail ))
  5123. $html = '';
  5124. else {
  5125. $html = '<div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><h3>收款单详情</h3></div><div class="modal-body saeaList"><table class="table table-bordered table-condensed">
  5126. <tbody><tr>
  5127. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  5128. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  5129. </tr><tr>
  5130. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  5131. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  5132. </tr>
  5133. <tr>
  5134. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  5135. <th class="taC">银行到账</th><td>' . $detail ['receivablesDate'] . '</td>
  5136. </tr>
  5137. <tr>
  5138. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['confirmTime'] . '</td>
  5139. </tr>
  5140. </tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  5141. }
  5142. echo json_encode ( array (
  5143. 'status' => 1,
  5144. 'html' => $html
  5145. ) );
  5146. die ();
  5147. } elseif ($type == 'IRTC') {
  5148. Doo::loadModel ( 'invoice' );
  5149. $invoice = new invoice ();
  5150. Doo::loadModel ( 'invoiceOperationLog' );
  5151. $invoiceOperationLog = new invoiceOperationLog ();
  5152. Doo::loadModel ( 'invoiceReceivables' );
  5153. $invoiceReceivables = new invoiceReceivables ();
  5154. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  5155. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  5156. if (empty ( $detail ))
  5157. $html = '';
  5158. else {
  5159. $receivablesPriceedHtml = '';
  5160. $receivablesPrice = $detail ['invoicePrice'];
  5161. if (! empty ( $detail ['irid'] )) {
  5162. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  5163. if (empty ( $irList ))
  5164. $irList [0] ['sumPrice'] = 0;
  5165. $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  5166. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  5167. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $irList [0] ['sumPrice'] . '</b></td>
  5168. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $balance . '</b></td>
  5169. </tr></tbody></table>';
  5170. $receivablesPrice = $balance;
  5171. }
  5172. if ($loss)
  5173. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  5174. $html = $receivablesPriceedHtml . '
  5175. <table class="table table-bordered table-condensed"><tbody>
  5176. <tr>
  5177. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  5178. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  5179. </tr>
  5180. <tr>
  5181. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  5182. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  5183. </tr>
  5184. <tr>
  5185. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  5186. </tr>
  5187. <tr>
  5188. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  5189. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  5190. </tr>
  5191. <tr>
  5192. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  5193. </tr></tbody></table>';
  5194. if ($detail ['invoiceType'] == 0) {
  5195. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5196. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  5197. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  5198. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  5199. </tr>';
  5200. $receivablesMessage = $detail ['invoiceTitle'];
  5201. } else {
  5202. $html .= '<table class="table table-bordered table-condensed"><tbody>
  5203. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  5204. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  5205. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  5206. ';
  5207. $receivablesMessage = $detail ['invoiceCompany'];
  5208. }
  5209. $html .= '<tr>
  5210. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  5211. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  5212. </tr>
  5213. <tr>
  5214. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  5215. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  5216. </tr></tbody></table>';
  5217. if ($detail ['doPost'] == 1)
  5218. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  5219. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  5220. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  5221. </tr><tr>
  5222. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  5223. </tr><tr>
  5224. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  5225. </tr></tbody></table>';
  5226. if (! empty ( $invoiceOperationLogList )) {
  5227. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  5228. foreach ( $invoiceOperationLogList as $key => $value ) {
  5229. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  5230. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  5231. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  5232. if ($value ['status'] == 2) {
  5233. $html .= '<span class="colGreen">同意</span>';
  5234. } elseif ($value ['status'] == 3) {
  5235. $html .= '<span class="colOrange">退回</span>';
  5236. } elseif ($value ['status'] == 5) {
  5237. $html .= '<span class="colGreen">打印</span>';
  5238. }
  5239. $html .= $value ['operation'] . '</p></blockquote>';
  5240. }
  5241. }
  5242. $html .= '</td></tr></tbody></table>';
  5243. }
  5244. }
  5245. echo json_encode ( array (
  5246. 'status' => 1,
  5247. 'html' => $html,
  5248. 'receivablesPrice' => $receivablesPrice,
  5249. 'receivablesMessage' => $receivablesMessage,
  5250. 'receivablesDate' => date ( "Y-m-d" ),
  5251. 'iidKey' => $serial
  5252. ) );
  5253. die ();
  5254. }
  5255. }
  5256. function ajaxGetInvoiceReceivablesByStaff() {
  5257. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  5258. if (empty ( $postData )) {
  5259. echo json_encode ( array (
  5260. 'status' => 2,
  5261. 'msg' => 'illegal request'
  5262. ) );
  5263. die ();
  5264. }
  5265. Doo::loadModel ( 'invoiceReceivables' );
  5266. $invoiceReceivables = new invoiceReceivables ();
  5267. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  5268. if (empty ( $detail )) {
  5269. echo json_encode ( array (
  5270. 'status' => 2,
  5271. 'msg' => 'illegal request'
  5272. ) );
  5273. die ();
  5274. }
  5275. Doo::loadModel ( 'L_category' );
  5276. $lCategory = new L_category ();
  5277. Doo::loadModel ( 'staff' );
  5278. $staff = new staff ();
  5279. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  5280. $category = $lCategory->getCategory ();
  5281. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  5282. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  5283. foreach ( $category as $key => $value ) {
  5284. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  5285. if ($value ['cid'] == $detail ['cid'])
  5286. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  5287. }
  5288. foreach ( $staffList as $key => $value ) {
  5289. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5290. if ($value ['sid'] == $detail ['sid'])
  5291. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  5292. }
  5293. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  5294. echo json_encode ( array (
  5295. 'status' => 1,
  5296. 'categoryHtml' => $categoryHtml,
  5297. 'staffHtml' => $staffHtml,
  5298. 'rbankHtml' => $rbankHtml,
  5299. 'detail' => $detail
  5300. ) );
  5301. }
  5302. function ajaxGetInvoiceReceivablesByIrid() {
  5303. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  5304. if (empty ( $irid )) {
  5305. echo json_encode ( array (
  5306. 'status' => 2,
  5307. 'msg' => 'illegal request'
  5308. ) );
  5309. die ();
  5310. }
  5311. Doo::loadModel ( 'invoiceReceivables' );
  5312. $invoiceReceivables = new invoiceReceivables ();
  5313. Doo::loadModel ( 'invoice' );
  5314. $invoice = new invoice ();
  5315. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  5316. $flag = true;
  5317. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 ", $flag ); //
  5318. $bakDetail = array ();
  5319. if ($flag === false) {
  5320. array_push ( $bakDetail, $invoiceDetail );
  5321. $invoiceDetail = $bakDetail;
  5322. }
  5323. $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>
  5324. <tr>
  5325. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  5326. <td>' . $detail ['receivablesMessage'] . '</td>
  5327. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  5328. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  5329. <td>' . $detail ['recepitTitleMark'] . '</td>
  5330. </tr></tbody></table>';
  5331. $isInvoice = false;
  5332. $invoiceHtml = '';
  5333. if (empty ( $invoiceDetail )) {
  5334. $isInvoice = true;
  5335. } else {
  5336. $invoiceHtml = '<table class="table table-bordered table-condensed">
  5337. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody>';
  5338. foreach ( $invoiceDetail as $key => $value ) {
  5339. $invoiceHtml .= '<tr>';
  5340. if (! empty ( $value ['invoiceType'] )) {
  5341. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  5342. } else {
  5343. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  5344. }
  5345. if (! empty ( $value ['invoiceType'] )) {
  5346. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  5347. } else {
  5348. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  5349. }
  5350. $invoiceHtml .= '
  5351. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  5352. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  5353. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir" data-ikey="' . $value ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  5354. </tr>
  5355. ';
  5356. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  5357. if (empty ( $irList ))
  5358. $irList [0] ['sumPrice'] = 0;
  5359. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  5360. $priceString = '';
  5361. if ($balance < $detail ['receivablesPrice']) {
  5362. $priceString = '收款金额超过开票金额,';
  5363. }
  5364. if ($balance > $detail ['receivablesPrice']) {
  5365. $priceString = '收款金额低于开票金额,';
  5366. }
  5367. }
  5368. $invoiceHtml .= '
  5369. <script>
  5370. $(\'a[bind-receivables^="ir"]\').click(function() {
  5371. var data = $(this).attr("data-ikey");
  5372. $("input[name=\'invoiceKey\']").val(data);
  5373. var invoiceKey=data;
  5374. if(invoiceKey==""){
  5375. alert("入账错误,请重新刷新页面");
  5376. return false;
  5377. }
  5378. if(window.confirm("' . $priceString . '确定入账吗?")){
  5379. $("#IBR").submit();
  5380. }else{
  5381. return false;
  5382. }
  5383. });
  5384. </script>
  5385. ';
  5386. $invoiceHtml .= '</tbody></table>';
  5387. }
  5388. echo json_encode ( array (
  5389. 'status' => 1,
  5390. 'irkey' => $detail ['iridEn'],
  5391. 'receivablesHtml' => $receivablesHtml,
  5392. 'isInvoice' => $isInvoice,
  5393. 'invoiceHtml' => $invoiceHtml
  5394. ) );
  5395. }
  5396. function ajaxGetInvoiceReceivablesByTitle() {
  5397. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  5398. if (empty ( $title )) {
  5399. echo json_encode ( array (
  5400. 'status' => 2,
  5401. 'msg' => 'illegal request'
  5402. ) );
  5403. die ();
  5404. }
  5405. Doo::loadModel ( 'invoice' );
  5406. $invoice = new invoice ();
  5407. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'FUZZY', " and status=2 and printStatus=1 and untreadStatus=0 and irid='' ", true );
  5408. $invoiceHtml = '';
  5409. if (! empty ( $invoiceDetail )) {
  5410. $invoiceHtml = '<table class="table table-bordered table-condensed">
  5411. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  5412. foreach ( $invoiceDetail as $key => $value ) {
  5413. if (! empty ( $value ['invoiceType'] )) {
  5414. $invoiceHtml .= '<td>' . $value ['invoiceCompany'] . '</td>';
  5415. } else {
  5416. $invoiceHtml .= '<td>' . $value ['invoiceTitle'] . '</td>';
  5417. }
  5418. if (! empty ( $value ['invoiceType'] )) {
  5419. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '专</td>';
  5420. } else {
  5421. $invoiceHtml .= '<td>' . $value ['invoicePrice'] . '</td>';
  5422. }
  5423. $invoiceHtml .= '
  5424. <td>' . $value ['categoryName'] . $value ['userName'] . ' ' . $value ['date'] . '</td>
  5425. <td>' . $value ['printer'] . ' ' . $value ['printTime'] . '</td>
  5426. <td>' . $value ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $value ['iidKeyXD'] . '" data-ikey="' . $value ['iidKey'] . '" href="#">入账</a></td>
  5427. </tr>
  5428. ';
  5429. }
  5430. $invoiceHtml .= '</tbody></table>
  5431. <script>
  5432. $(\'a[bind-receivables^="ir"]\').click(function() {
  5433. var data = $(this).attr("data-ikey");
  5434. $("input[name=\'invoiceKey\']").val(data);
  5435. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  5436. if(invoiceKey==""){
  5437. alert("入账错误,请重新刷新页面");
  5438. return false;
  5439. }
  5440. if(window.confirm("确定入账吗?")){
  5441. $("#IBR").submit();
  5442. }else{
  5443. return false;
  5444. }
  5445. });
  5446. </script>
  5447. ';
  5448. }
  5449. echo json_encode ( array (
  5450. 'status' => 1,
  5451. 'invoiceHtml' => $invoiceHtml
  5452. ) );
  5453. }
  5454. function ajaxInvoicePushNotice() {
  5455. Doo::loadModel ( 'invoice' );
  5456. $invoice = new invoice ();
  5457. $approval = $invoice->getOne ( array (
  5458. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  5459. 'desc' => 'iid',
  5460. 'asArray' => true
  5461. ) );
  5462. $isNotice = false;
  5463. if (! empty ( $approval ))
  5464. $isNotice = true;
  5465. $response = array (
  5466. 'error' => 0,
  5467. 'isNotice' => $isNotice
  5468. );
  5469. echo json_encode ( $response );
  5470. exit ();
  5471. }
  5472. public function ajaxCheckInvoiceNoUniqueness() {
  5473. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  5474. Doo::loadModel ( 'invoice' );
  5475. $invoice = new invoice ();
  5476. if (! empty ( $invoiceNo )) {
  5477. Doo::loadModel ( 'invoicePaper' );
  5478. $invoicePaper = new invoicePaper ();
  5479. Doo::loadClass ( 'XDeode' );
  5480. $XDeode = new XDeode ( 5 );
  5481. $ipid = $XDeode->decode ( $invoiceNo );
  5482. $paperDetail = $invoicePaper->getInvoicePaperByIpid ( $ipid );
  5483. $info = $invoice->getOne ( array (
  5484. 'where' => "invoiceNo = '" . $paperDetail ['invoiceNo'] . "'",
  5485. 'asArray' => TRUE
  5486. ) );
  5487. if (! empty ( $info )) {
  5488. echo json_encode ( array (
  5489. 'error' => '发票号已存在'
  5490. ) );
  5491. die ();
  5492. } else
  5493. echo json_encode ( array (
  5494. 'ok' => '可以使用!'
  5495. ) );
  5496. die ();
  5497. }
  5498. }
  5499. function ajaxCheckInvoicePrice() {
  5500. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  5501. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  5502. Doo::loadModel ( 'invoice' );
  5503. $invoice = new invoice ();
  5504. Doo::loadModel ( 'invoiceReceivables' );
  5505. $invoiceReceivables = new invoiceReceivables ();
  5506. Doo::loadClass ( 'XDeode' );
  5507. $XDeode = new XDeode ( 5 );
  5508. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  5509. $iidKey = $XDeode->decode ( $iidKey );
  5510. $info = $invoice->getInvoiceByIid ( $iidKey );
  5511. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  5512. if (empty ( $irList ))
  5513. $irList [0] ['sumPrice'] = 0;
  5514. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  5515. if ($balance < $receivablesPrice) {
  5516. echo json_encode ( array (
  5517. 'error' => '收款金额超过开票金额。'
  5518. ) );
  5519. die ();
  5520. }
  5521. if ($balance > $receivablesPrice) {
  5522. echo json_encode ( array (
  5523. 'error' => '收款金额低于开票金额。'
  5524. ) );
  5525. die ();
  5526. }
  5527. }
  5528. }
  5529. /**
  5530. * 旧输入导入
  5531. */
  5532. function importInvoice() {
  5533. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  5534. $data ['emsg'] = "";
  5535. if ($emsg != "")
  5536. $data ['emsg'] = "请填写完整的数据";
  5537. $data ['time'] = time ();
  5538. $this->render ( "/admin/invoiceImport", $data );
  5539. }
  5540. function uploadInvoice() {
  5541. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  5542. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  5543. $file = $_FILES ['Filedata'] ['tmp_name'];
  5544. $error = false;
  5545. if (! is_uploaded_file ( $file )) {
  5546. $error = '400 Bad Request';
  5547. }
  5548. if ($error) {
  5549. header ( 'HTTP/1.0 ' . $error );
  5550. die ( 'Error ' . $error );
  5551. } else {
  5552. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  5553. $this->IoHandler = new IoHandler ();
  5554. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  5555. // $filedir=$_POST['time'];
  5556. // 调用定义物理路径
  5557. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  5558. $this->IoHandler->MakeDir ( $t );
  5559. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  5560. if ($filename != 'xlsx')
  5561. return "";
  5562. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  5563. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  5564. $upload_dir = $t . "/" . $upload_file;
  5565. $k = move_uploaded_file ( $file, $upload_dir );
  5566. if ($k) {
  5567. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  5568. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  5569. }
  5570. }
  5571. }
  5572. }
  5573. function importInvoiceDo() {
  5574. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  5575. if ($path != "") {
  5576. Doo::loadModel ( 'invoice' );
  5577. Doo::loadModel ( 'staff' );
  5578. $staff = new staff ();
  5579. Doo::loadModel ( 'invoiceStatistics' );
  5580. Doo::loadModel ( 'invoiceOperationLog' );
  5581. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  5582. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  5583. // print_r ( $exlArray );
  5584. // die ();
  5585. // echo json_encode($exlArray);die;
  5586. foreach ( $exlArray as $key => $value ) {
  5587. // 开票
  5588. $invoice = new invoice ();
  5589. $invoice->invoiceNo = $value ['invoiceNo'];
  5590. $invoice->invoiceType = 0;
  5591. if ($value ['invoiceType'] == '专')
  5592. $invoice->invoiceType = 1;
  5593. $invoice->invoicePrice = $value ['invoicePrice'];
  5594. $invoice->invoiceQuantity = 1;
  5595. $invoice->invoiceUnitPrice = $value ['invoicePrice'];
  5596. $invoice->invoiceTitle = $value ['invoiceTitle'];
  5597. if ($value ['invoiceType'] == '专')
  5598. $invoice->invoiceCompany = $value ['invoiceTitle'];
  5599. $invoice->userName = $value ['userName'];
  5600. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  5601. $invoice->sid = $sDetail ['sid'];
  5602. $invoice->cid = $sDetail ['cid'];
  5603. $invoice->categoryName = $sDetail ['category'];
  5604. $invoice->invoiceElement = $value ['invoiceElement'];
  5605. $invoice->remark = $value ['remark'];
  5606. $invoice->date = $value ['date'];
  5607. $invoice->printTime = $value ['date'];
  5608. $invoice->ipSource = 1;
  5609. $invoice->printStatus = 1;
  5610. $invoice->status = 2;
  5611. $invoice->postStatus = 1;
  5612. $invoice->untreadStatus = 0;
  5613. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  5614. $iid = $invoice->insert ();
  5615. // 汇总
  5616. $invoiceStatistics = new invoiceStatistics ();
  5617. //
  5618. $item = array (
  5619. 'date' => $value ['date'],
  5620. 'priceClass' => 1,
  5621. 'cid' => $sDetail ['cid'],
  5622. 'staff' => $sDetail ['sid'],
  5623. 'invoicePrice' => $value ['invoicePrice']
  5624. );
  5625. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5626. $invoiceOperationLog = new invoiceOperationLog ();
  5627. $item = array (
  5628. 'date' => date ( "Y-m-d H:i:s" ),
  5629. 'operation' => date ( "Y-m-d" ) . " 导入",
  5630. 'status' => 1,
  5631. 'img' => $sDetail ['avatar'],
  5632. 'username' => $sDetail ['username'],
  5633. 'uid' => $sDetail ['sid'],
  5634. 'category' => $sDetail ['category'],
  5635. 'iid' => $iid
  5636. );
  5637. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  5638. }
  5639. return '/importInvoice?count=' . count ( $exlArray );
  5640. // return "/keyonline";
  5641. }
  5642. echo 'no file';
  5643. }
  5644. function importInvoiceReceivables() {
  5645. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  5646. $data ['emsg'] = "";
  5647. if ($emsg != "")
  5648. $data ['emsg'] = "请填写完整的数据";
  5649. $data ['time'] = time ();
  5650. $this->render ( "/admin/invoiceReceivablesImport", $data );
  5651. }
  5652. // 导入入账数据
  5653. function importInvoiceReceivablesDo() {
  5654. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  5655. // include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  5656. if ($path != "") {
  5657. Doo::loadModel ( 'invoiceReceivables' );
  5658. Doo::loadModel ( 'invoice' );
  5659. Doo::loadModel ( 'staff' );
  5660. $staff = new staff ();
  5661. Doo::loadModel ( 'invoiceStatistics' );
  5662. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  5663. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  5664. // print_r ( $exlArray );
  5665. // die ();
  5666. // echo json_encode($exlArray);die;
  5667. foreach ( $exlArray as $key => $value ) {
  5668. // 收款
  5669. $invoiceReceivables = new invoiceReceivables ();
  5670. $invoice = new invoice ();
  5671. $invoiceReceivables->bindStatus = 1;
  5672. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  5673. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  5674. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  5675. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  5676. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  5677. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  5678. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  5679. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  5680. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  5681. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  5682. $invoiceReceivables->iid = $iDetail ['iid'];
  5683. $irid = $invoiceReceivables->insert ();
  5684. // 发票绑定收款
  5685. $detail = $iDetail;
  5686. $iridString = "";
  5687. if (empty ( $detail ['irid'] ))
  5688. $iridString = $irid;
  5689. else
  5690. $iridString = $detail ['irid'] . ',' . $irid;
  5691. $item = array (
  5692. 'irid' => $iridString,
  5693. 'iid' => $detail ['iid']
  5694. );
  5695. $invoice->setInvoiceByCondition ( $item );
  5696. // 汇总
  5697. $invoiceStatistics = new invoiceStatistics ();
  5698. // 扣除入账统计金额
  5699. $item = array (
  5700. 'date' => $value ['receivablesDate'],
  5701. 'priceClass' => 3,
  5702. 'cid' => $sDetail ['cid'],
  5703. 'staff' => $sDetail ['sid'],
  5704. // 'irid' => $irid,
  5705. 'accountPrice' => $value ['receivablesPrice']
  5706. );
  5707. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  5708. }
  5709. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  5710. echo 'data count ' . count ( $exlArray );
  5711. die ();
  5712. // return "/keyonline";
  5713. }
  5714. echo 'no file';
  5715. }
  5716. function formatExcelToArrayTrain($file_url = "") {
  5717. if (! file_exists ( $file_url )) {
  5718. return array ();
  5719. }
  5720. // Doo::loadClass ( 'PHPExcel' );
  5721. Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  5722. $PHPExcel = new PHPExcel ();
  5723. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  5724. if (! $PHPReader->canRead ( $file_url )) {
  5725. $PHPReader = new PHPExcel_Reader_Excel5 ();
  5726. if (! $PHPReader->canRead ( $file_url )) {
  5727. echo 'no Excel';
  5728. return;
  5729. }
  5730. }
  5731. $PHPExcel = $PHPReader->load ( $file_url );
  5732. /* * 读取excel文件中的第一个工作表 */
  5733. $currentSheet = $PHPExcel->getSheet ( 0 );
  5734. /* * 取得最大的列号 */
  5735. $allColumn = $currentSheet->getHighestColumn ();
  5736. /* * 取得一共有多少行 */
  5737. $allRow = $currentSheet->getHighestRow ();
  5738. $excel_array = array ();
  5739. // die($file_url);
  5740. $conk = 2;
  5741. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  5742. $excel_column = array ();
  5743. // 后期改进
  5744. if ($allColumn == 'AM')
  5745. $allColumn = 'Z';
  5746. /* * 从第A列开始输出 */
  5747. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  5748. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  5749. if ($val instanceof PHPExcel_RichText)
  5750. $val = $val->__toString ();
  5751. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  5752. // $val = "'" . addslashes ( $val ) . "'";
  5753. if ($currentColumn == 'A') {
  5754. $excel_column ['invoiceTitle'] = $val;
  5755. } elseif ($currentColumn == 'B')
  5756. $excel_column ['invoiceType'] = $val;
  5757. elseif ($currentColumn == 'C') {
  5758. $excel_column ['TIN'] = $val;
  5759. } elseif ($currentColumn == 'D') {
  5760. $excel_column ['address'] = $val;
  5761. } elseif ($currentColumn == 'E') {
  5762. $excel_column ['phone'] = $val;
  5763. } elseif ($currentColumn == 'F') {
  5764. $excel_column ['bank'] = $val;
  5765. } elseif ($currentColumn == 'G') {
  5766. $excel_column ['bankAccount'] = $val;
  5767. } elseif ($currentColumn == 'H') {
  5768. $excel_column ['invoiceElement'] = $val;
  5769. } elseif ($currentColumn == 'I') {
  5770. $excel_column ['invoiceQuantity'] = $val;
  5771. } elseif ($currentColumn == 'J') {
  5772. $excel_column ['invoiceUnitPrice'] = $val;
  5773. } elseif ($currentColumn == 'K') {
  5774. $excel_column ['remark'] = $val;
  5775. } elseif ($currentColumn == 'L') {
  5776. $excel_column ['recipientsAddress'] = $val;
  5777. } elseif ($currentColumn == 'M') {
  5778. $excel_column ['recipients'] = $val;
  5779. } elseif ($currentColumn == 'N') {
  5780. $excel_column ['recipientsPhone'] = $val;
  5781. }
  5782. }
  5783. if (! empty ( $excel_column ['invoiceTitle'] ) && ! empty ( $excel_column ['invoiceQuantity'] ) && ! empty ( $excel_column ['invoiceUnitPrice'] ))
  5784. array_push ( $excel_array, $excel_column );
  5785. }
  5786. return $excel_array;
  5787. }
  5788. /**
  5789. * 格式化excel文件为数组
  5790. * @param unknown_type $file_url
  5791. * @param unknown_type $mcid
  5792. */
  5793. function _format_excel_to_array($file_url = "", $sType = "") {
  5794. if (! file_exists ( $file_url )) {
  5795. return array ();
  5796. }
  5797. Doo::loadClass ( 'PHPExcel' );
  5798. // Doo::loadClass ( 'PHPExcel1.7.9/PHPExcel' );
  5799. $PHPExcel = new PHPExcel ();
  5800. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  5801. if (! $PHPReader->canRead ( $file_url )) {
  5802. $PHPReader = new PHPExcel_Reader_Excel5 ();
  5803. if (! $PHPReader->canRead ( $file_url )) {
  5804. echo 'no Excel';
  5805. return;
  5806. }
  5807. }
  5808. $PHPExcel = $PHPReader->load ( $file_url );
  5809. /* * 读取excel文件中的第一个工作表 */
  5810. $currentSheet = $PHPExcel->getSheet ( 0 );
  5811. /* * 取得最大的列号 */
  5812. $allColumn = $currentSheet->getHighestColumn ();
  5813. /* * 取得一共有多少行 */
  5814. $allRow = $currentSheet->getHighestRow ();
  5815. $excel_array = array ();
  5816. // die($file_url);
  5817. $conk = 2;
  5818. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  5819. $excel_column = array ();
  5820. // 后期改进
  5821. if ($allColumn == 'AM')
  5822. $allColumn = 'Z';
  5823. /* * 从第A列开始输出 */
  5824. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  5825. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  5826. if ($val instanceof PHPExcel_RichText)
  5827. $val = $val->__toString ();
  5828. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  5829. // $val = "'" . addslashes ( $val ) . "'";
  5830. if ($sType == 'invoiceReceivables') {
  5831. if ($currentColumn == 'A')
  5832. $excel_column ['invoiceNo'] = $val;
  5833. elseif ($currentColumn == 'B')
  5834. $excel_column ['receivablesPrice'] = $val;
  5835. elseif ($currentColumn == 'C') {
  5836. $excel_column ['receivablesMessage'] = $val;
  5837. } elseif ($currentColumn == 'D') {
  5838. $excel_column ['receivablesBank'] = $val;
  5839. } elseif ($currentColumn == 'E') {
  5840. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  5841. } elseif ($currentColumn == 'F') {
  5842. $excel_column ['receivablesStaff'] = $val;
  5843. } elseif ($currentColumn == 'G') {
  5844. $excel_column ['sourcePrice'] = $val;
  5845. }
  5846. } elseif ($sType == "invoiceTrain") {
  5847. if ($currentColumn == 'A') {
  5848. $excel_column ['invoiceTitle'] = $val;
  5849. } elseif ($currentColumn == 'B')
  5850. $excel_column ['invoiceType'] = $val;
  5851. elseif ($currentColumn == 'C') {
  5852. $excel_column ['TIN'] = $val;
  5853. } elseif ($currentColumn == 'D') {
  5854. $excel_column ['address'] = $val;
  5855. } elseif ($currentColumn == 'E') {
  5856. $excel_column ['phone'] = $val;
  5857. } elseif ($currentColumn == 'F') {
  5858. $excel_column ['bank'] = $val;
  5859. } elseif ($currentColumn == 'G') {
  5860. $excel_column ['bankAccount'] = $val;
  5861. } elseif ($currentColumn == 'H') {
  5862. $excel_column ['invoiceElement'] = $val;
  5863. } elseif ($currentColumn == 'I') {
  5864. $excel_column ['invoiceQuantity'] = $val;
  5865. } elseif ($currentColumn == 'J') {
  5866. $excel_column ['invoiceUnitPrice'] = $val;
  5867. } elseif ($currentColumn == 'K') {
  5868. $excel_column ['remark'] = $val;
  5869. } elseif ($currentColumn == 'L') {
  5870. $excel_column ['recipientsAddress'] = $val;
  5871. } elseif ($currentColumn == 'M') {
  5872. $excel_column ['recipients'] = $val;
  5873. } elseif ($currentColumn == 'N') {
  5874. $excel_column ['recipientsPhone'] = $val;
  5875. }
  5876. } else {
  5877. if ($currentColumn == 'A')
  5878. $excel_column ['invoiceNo'] = $val;
  5879. elseif ($currentColumn == 'B')
  5880. $excel_column ['invoiceType'] = $val;
  5881. elseif ($currentColumn == 'C') {
  5882. $excel_column ['invoicePrice'] = $val;
  5883. } elseif ($currentColumn == 'D') {
  5884. $excel_column ['invoiceTitle'] = $val;
  5885. } elseif ($currentColumn == 'E') {
  5886. $excel_column ['userName'] = $val;
  5887. } elseif ($currentColumn == 'F') {
  5888. $excel_column ['categoryName'] = $val;
  5889. } elseif ($currentColumn == 'G') {
  5890. $excel_column ['invoiceElement'] = $val;
  5891. } elseif ($currentColumn == 'H') {
  5892. $excel_column ['remark'] = $val;
  5893. } elseif ($currentColumn == 'I') {
  5894. $excel_column ['date'] = $this->excelTime ( $val );
  5895. }
  5896. }
  5897. }
  5898. array_push ( $excel_array, $excel_column );
  5899. }
  5900. return $excel_array;
  5901. }
  5902. function excelTime($date, $time = false) {
  5903. if (function_exists ( 'GregorianToJD' )) {
  5904. if (is_numeric ( $date )) {
  5905. $jd = GregorianToJD ( 1, 1, 1970 );
  5906. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  5907. $date = explode ( '/', $gregorian );
  5908. $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" : '');
  5909. return $date_str;
  5910. }
  5911. } else {
  5912. $date = $date > 25568 ? $date + 1 : 25569;
  5913. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  5914. $ofs = (70 * 365 + 17 + 2) * 86400;
  5915. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  5916. }
  5917. return $date;
  5918. }
  5919. /**
  5920. * 旧输入导入
  5921. */
  5922. function _GetFileEXT($filename) {
  5923. $pics = explode ( '.', $filename );
  5924. $num = count ( $pics );
  5925. return $pics [$num - 1];
  5926. }
  5927. function showCache($path = "", $sid = 0) {
  5928. // if (file_exists ( $path )) {
  5929. // $htm = file_get_contents ( $path );
  5930. // } else {
  5931. Doo::loadModel ( 'invoiceStatistics' );
  5932. $invoiceStatistics = new invoiceStatistics ();
  5933. $isBriefly = $invoiceStatistics->getBrieflyStatistics ( $sid );
  5934. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  5935. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  5936. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  5937. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  5938. /*
  5939. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  5940. */
  5941. file_put_contents ( $path, $htm );
  5942. // }
  5943. return $htm;
  5944. }
  5945. /**
  5946. * 获取get或者POST值
  5947. *
  5948. * @param string $name 属性名称
  5949. * @return fixed 值
  5950. */
  5951. function get_args($name) {
  5952. if (isset ( $_GET [$name] )) {
  5953. if (is_array ( $_GET [$name] ))
  5954. return $_GET [$name];
  5955. else
  5956. return addslashes ( $_GET [$name] );
  5957. } elseif (isset ( $_POST [$name] )) {
  5958. if (is_array ( $_POST [$name] ))
  5959. return $_POST [$name];
  5960. else
  5961. return addslashes ( $_POST [$name] );
  5962. } else
  5963. return false;
  5964. }
  5965. function SafeFilter(&$arr) {
  5966. $ra = Array (
  5967. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  5968. '/script/',
  5969. '/javascript/',
  5970. '/vbscript/',
  5971. '/expression/',
  5972. '/applet/',
  5973. '/meta/',
  5974. '/xml/',
  5975. '/blink/',
  5976. '/link/',
  5977. '/style/',
  5978. '/embed/',
  5979. '/object/',
  5980. '/frame/',
  5981. '/layer/',
  5982. '/title/',
  5983. '/bgsound/',
  5984. '/base/',
  5985. '/onload/',
  5986. '/onunload/',
  5987. '/onchange/',
  5988. '/onsubmit/',
  5989. '/onreset/',
  5990. '/onselect/',
  5991. '/onblur/',
  5992. '/onfocus/',
  5993. '/onabort/',
  5994. '/onkeydown/',
  5995. '/onkeypress/',
  5996. '/onkeyup/',
  5997. '/onclick/',
  5998. '/ondblclick/',
  5999. '/onmousedown/',
  6000. '/onmousemove/',
  6001. '/onmouseout/',
  6002. '/onmouseover/',
  6003. '/onmouseup/',
  6004. '/onunload/'
  6005. );
  6006. if (is_array ( $arr )) {
  6007. foreach ( $arr as $key => $value ) {
  6008. if (! is_array ( $value )) {
  6009. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  6010. {
  6011. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  6012. }
  6013. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  6014. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  6015. } else {
  6016. SafeFilter ( $arr [$key] );
  6017. }
  6018. }
  6019. }
  6020. }
  6021. /**
  6022. * Escape String
  6023. *
  6024. * @access public
  6025. * @param string
  6026. * @param bool whether or not the string will be used in a LIKE condition
  6027. * @return string
  6028. */
  6029. function escape_str($str, $like = FALSE) {
  6030. if (is_array ( $str )) {
  6031. foreach ( $str as $key => $val ) {
  6032. $str [$key] = $this->escape_str ( $val, $like );
  6033. }
  6034. return $str;
  6035. }
  6036. var_dump ( Doo::db ()->getDbObject () );
  6037. die ();
  6038. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  6039. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  6040. } elseif (function_exists ( 'mysql_escape_string' )) {
  6041. $str = mysql_escape_string ( $str );
  6042. } else {
  6043. $str = addslashes ( $str );
  6044. }
  6045. // escape LIKE condition wildcards
  6046. if ($like === TRUE) {
  6047. $str = str_replace ( array (
  6048. '%',
  6049. '_'
  6050. ), array (
  6051. '\\%',
  6052. '\\_'
  6053. ), $str );
  6054. }
  6055. return $str;
  6056. }
  6057. /**
  6058. * 获得分页数据
  6059. * @param unknown_type $table
  6060. * @param unknown_type $condition
  6061. * @param unknown_type $on_page
  6062. * @param unknown_type $page_size
  6063. */
  6064. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6065. $page_c = "";
  6066. $page ['previous'] = $this->get_previous ( $on_page );
  6067. $page ['on_page'] = $on_page;
  6068. $total_count = $this->get_table_count ( $table, $condition );
  6069. $total = intval ( $total_count / $page_size );
  6070. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6071. $page ['total_data'] = $total_count;
  6072. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6073. $i = 1;
  6074. $page_max = 1;
  6075. $page_width = 3;
  6076. if ($on_page >= $page_width) {
  6077. $page_max = intval ( $on_page / $page_width ) + 1;
  6078. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  6079. }
  6080. for(; $i <= $page ['total_page']; $i ++) {
  6081. if ($i == $on_page)
  6082. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  6083. else
  6084. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  6085. if ($i == ($page_width * $page_max))
  6086. break;
  6087. }
  6088. $page ['page'] = $page_c;
  6089. $page ['lower'] = (-- $on_page) * $page_size;
  6090. return $page;
  6091. }
  6092. /**
  6093. * 获取上一页
  6094. * @param unknown_type $on_page
  6095. */
  6096. function get_previous($on_page = 1) {
  6097. return $on_page != 0 ? $on_page - 1 : $on_page;
  6098. }
  6099. /**
  6100. * 获取总页数
  6101. * @param unknown_type $table
  6102. * @param unknown_type $condition
  6103. */
  6104. public function get_table_count($table = "", $condition = "") {
  6105. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  6106. $sql = "select count(*) as count from " . $table . " where " . $condition;
  6107. // echo $sql;die;
  6108. $query = Doo::db ()->query ( $sql );
  6109. $result = $query->fetch ();
  6110. return $result ['count'];
  6111. }
  6112. /**
  6113. * 获得分页数据
  6114. * @param unknown_type $table
  6115. * @param unknown_type $condition
  6116. * @param unknown_type $on_page
  6117. * @param unknown_type $page_size
  6118. */
  6119. function getPageBySql($sql = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  6120. $page_c = "";
  6121. $page ['previous'] = $this->get_previous ( $on_page );
  6122. $page ['on_page'] = $on_page;
  6123. $total_count = $this->getTableCountBySql ( $sql );
  6124. $total = intval ( $total_count / $page_size );
  6125. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  6126. $page ['total_data'] = $total_count;
  6127. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  6128. $i = 1;
  6129. $page_max = 1;
  6130. $page_width = 3;
  6131. if ($on_page >= $page_width) {
  6132. $page_max = intval ( $on_page / $page_width ) + 1;
  6133. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  6134. }
  6135. for(; $i <= $page ['total_page']; $i ++) {
  6136. if ($i == $on_page)
  6137. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  6138. else
  6139. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  6140. if ($i == ($page_width * $page_max))
  6141. break;
  6142. }
  6143. $page ['page'] = $page_c;
  6144. $page ['lower'] = (-- $on_page) * $page_size;
  6145. return $page;
  6146. }
  6147. /**
  6148. * 获得总页数 sql
  6149. * @param string $type
  6150. * @return boolean[]
  6151. */
  6152. public function getTableCountBySql($sql = "") {
  6153. $query = Doo::db ()->query ( $sql );
  6154. $result = $query->fetchAll ();
  6155. return count ( $result );
  6156. }
  6157. function isInvoiceNew($type = "GLOBAL") {
  6158. Doo::loadModel ( 'invoice' );
  6159. $invoice = new invoice ();
  6160. Doo::loadModel ( 'invoiceReceivables' );
  6161. $invoiceReceivables = new invoiceReceivables ();
  6162. Doo::loadModel ( 'staff' );
  6163. $staff = new staff ();
  6164. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  6165. // 我的发票待处理
  6166. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  6167. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  6168. 'desc' => 'iid',
  6169. 'asArray' => TRUE
  6170. ) );
  6171. // 我的收款待入账
  6172. /*
  6173. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  6174. */
  6175. // 发票审批
  6176. $approval = $invoice->getOne ( array (
  6177. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  6178. 'desc' => 'iid',
  6179. 'asArray' => true
  6180. ) );
  6181. // 发票邮寄
  6182. $post = $invoice->getOne ( array (
  6183. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  6184. 'asArray' => TRUE
  6185. ) );
  6186. // 发票打印
  6187. $print = $invoice->getOne ( array (
  6188. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  6189. 'desc' => 'iid',
  6190. 'asArray' => TRUE
  6191. ) );
  6192. // 发票退票 printStatus=1 and
  6193. $untread = $invoice->getOne ( array (
  6194. 'where' => " untreadStatus=1 and status=2 ",
  6195. 'asArray' => TRUE
  6196. ) );
  6197. $new = array (
  6198. 'GLOBAL' => FALSE,
  6199. 'pendingInvoice' => FALSE,
  6200. // 'myClaim' => FALSE,
  6201. 'approval' => FALSE,
  6202. 'post' => FALSE,
  6203. 'print' => FALSE,
  6204. 'untread' => FALSE
  6205. );
  6206. // || ! empty ( $myClaim )
  6207. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  6208. $new ['GLOBAL'] = TRUE;
  6209. if (! empty ( $pendingInvoice ))
  6210. $new ['pendingInvoice'] = TRUE;
  6211. // if (! empty ( $myClaim ))
  6212. // $new ['myClaim'] = TRUE;
  6213. if (! empty ( $approval ))
  6214. $new ['approval'] = TRUE;
  6215. if (! empty ( $post ))
  6216. $new ['post'] = TRUE;
  6217. if (! empty ( $print ))
  6218. $new ['print'] = TRUE;
  6219. if (! empty ( $untread ))
  6220. $new ['untread'] = TRUE;
  6221. return $new;
  6222. }
  6223. function setWXMsg($rid, $typeMsg = '') {
  6224. Doo::loadModel ( 'invoice' );
  6225. $invoice = new invoice ();
  6226. $invoiceDetail = $invoice->getOne ( array (
  6227. 'where' => 'iid=' . $rid,
  6228. 'asArray' => true
  6229. ) );
  6230. if (! empty ( $invoiceDetail )) {
  6231. Doo::loadModel ( 'staff' );
  6232. $staff = new staff ();
  6233. $staffmsg = $staff->getOne ( array (
  6234. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  6235. 'asArray' => TRUE
  6236. ) );
  6237. if (! empty ( $staffmsg ['wxid'] )) {
  6238. require_once (SITE_PATH . '/protected/class/client.php');
  6239. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  6240. $user = $staffmsg ['wxid'];
  6241. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  6242. if (empty ( $expCom ))
  6243. $expCom [0] = '';
  6244. $msg = "";
  6245. if (empty ( $typeMsg ))
  6246. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  6247. elseif ($typeMsg == "PRINT")
  6248. $msg = '太好了,您的发票已打印完成。';
  6249. $result = $client->SendMsg ( $user, $msg, 'text' );
  6250. }
  6251. }
  6252. }
  6253. /**
  6254. * 获取微信部门
  6255. * @param string $category
  6256. * @return number|mixed
  6257. */
  6258. function getToparty($category = '') {
  6259. $token = $this->getAccessToken (); //
  6260. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ), true );
  6261. $toparty = 0;
  6262. foreach ( $result ['department'] as $key => $value ) {
  6263. if ($value ['name'] == $category)
  6264. $toparty = $value ['id'];
  6265. }
  6266. return $toparty;
  6267. }
  6268. /**
  6269. * 获得某部门下的用户
  6270. * @param string $toparty
  6271. */
  6272. function getUserByToparty($toparty = '') {
  6273. $token = $this->getAccessToken (); //
  6274. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?access_token={$token}&department_id={$toparty}" ), true );
  6275. $userList = array ();
  6276. foreach ( $result ['userlist'] as $key => $value ) {
  6277. array_push ( $userList, "'" . $value ['userid'] . "'" );
  6278. }
  6279. return $userList;
  6280. }
  6281. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  6282. $token = $this->getAccessToken ();
  6283. if ($text == 'text') {
  6284. $data = '{
  6285. "touser": "' . $toparty . '",
  6286. "toparty": "",
  6287. "totag": "",
  6288. "msgtype": "text",
  6289. "agentid": 1000002,
  6290. "text": {
  6291. "content": "' . $msg . '"
  6292. },
  6293. "safe":0
  6294. }';
  6295. }
  6296. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  6297. if ($result->errmsg != 'ok') {
  6298. return 0;
  6299. } else {
  6300. return 1;
  6301. }
  6302. }
  6303. /**
  6304. * 获得可以发送微信用户列表
  6305. * @param string $category
  6306. * @return string
  6307. */
  6308. function getWxidByCategory($category = "") {
  6309. if (empty ( $category ))
  6310. return "";
  6311. Doo::loadModel ( 'staff' );
  6312. $staff = new staff ();
  6313. $toparty = $this->getToparty ( $category );
  6314. $wxList = array ();
  6315. $wxString = "";
  6316. if (! empty ( $toparty )) {
  6317. $userList = $this->getUserByToparty ( $toparty );
  6318. $userCon = implode ( ',', $userList );
  6319. // echo $userCon;
  6320. $sidList = $staff->getStaffByWxid ( $userCon );
  6321. foreach ( $sidList as $key => $value ) {
  6322. $falg = $this->isSendNotification ( $value ['sid'], 'receivables' );
  6323. if ($falg) {
  6324. array_push ( $wxList, $value ['wxid'] );
  6325. }
  6326. }
  6327. $wxString = implode ( '|', $wxList );
  6328. }
  6329. return $wxString;
  6330. }
  6331. /**
  6332. * 读取发送信息规则判断是否需要发送
  6333. * @param number $sid
  6334. * @param string $sendType
  6335. * @return boolean
  6336. */
  6337. function isSendNotification($sid = 0, $sendType = '') {
  6338. Doo::loadModel ( "notificationConf" );
  6339. $notificationConf = new notificationConf ();
  6340. $detail = $notificationConf->getNotificationConfBySid ( $sid );
  6341. $conf = array ();
  6342. $sendFlag = true;
  6343. if (! empty ( $detail )) {
  6344. $conf = json_decode ( $detail ['conf'], true );
  6345. if (! empty ( $sendType )) {
  6346. if (isset ( $conf [$sendType] )) {
  6347. if ($conf [$sendType] == "CLOSE")
  6348. $sendFlag = false;
  6349. elseif ($conf [$sendType] == "Weekend") {
  6350. $day = date ( "w" );
  6351. if (1 <= $day && 5 >= $day)
  6352. $sendFlag = false;
  6353. } elseif ($conf [$sendType] == "OneToFriday") {
  6354. $day = date ( "w" );
  6355. if (0 == $day || 6 == $day)
  6356. $sendFlag = false;
  6357. }
  6358. }
  6359. } else
  6360. $sendFlag = false;
  6361. }
  6362. return $sendFlag;
  6363. }
  6364. /**
  6365. * 根据规则发送信息
  6366. * @param unknown $msg
  6367. * @param unknown $title
  6368. * @param unknown $url
  6369. * @param unknown $user
  6370. * @param string $text
  6371. * @return number
  6372. */
  6373. private function msgSend($msg, $title, $url, $user, $sid = 0, $sendType = '') {
  6374. $token = $this->getAccessToken ();
  6375. $falg = $this->isSendNotification ( $sid, $sendType );
  6376. // if ($text == 'text') {
  6377. // $data = '{
  6378. // "touser": "' . $user . '",
  6379. // "toparty": "",
  6380. // "totag": "",
  6381. // "msgtype": "text",
  6382. // "agentid": 1000002,
  6383. // "text": {
  6384. // "content": "' . $msg . '"
  6385. // },
  6386. // "safe":0
  6387. // }';
  6388. // } else {
  6389. $data = '{
  6390. "touser": "' . $user . '",
  6391. "toparty": "",
  6392. "totag": "",
  6393. "msgtype": "news",
  6394. "agentid": 1000002,
  6395. "news": {
  6396. "articles":[
  6397. {
  6398. "title": "' . $title . '",
  6399. "description": "' . $msg . '",
  6400. "url": "' . $url . '",
  6401. "picurl": ""
  6402. }
  6403. ]
  6404. }
  6405. }';
  6406. // }
  6407. if ($falg) {
  6408. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  6409. if ($result->errmsg != 'ok') {
  6410. return 0;
  6411. } else {
  6412. return 1;
  6413. }
  6414. } else
  6415. return 0;
  6416. }
  6417. private function getAccessToken() {
  6418. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  6419. // $file = './access_token.txt';
  6420. // $data = json_decode ( file_get_contents ( $file ) );
  6421. // if ($data->expire_time < time () or ! $data->expire_time) {
  6422. // 如果是企业号用以下URL获取access_token
  6423. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  6424. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  6425. $res = json_decode ( $this->httpGet ( $url ) );
  6426. $access_token = $res->access_token;
  6427. // echo $access_token;
  6428. // if ($access_token) {
  6429. // $data->expire_time = time () + 7000;
  6430. // $data->access_token = $access_token;
  6431. // $fp = fopen ( $file, "w" );
  6432. // fwrite ( $fp, json_encode ( $data ) );
  6433. // fclose ( $fp );
  6434. // }
  6435. // } else {
  6436. // $access_token = $data->access_token;
  6437. // }
  6438. return $access_token;
  6439. }
  6440. private function httpGet($url) {
  6441. $curl = curl_init ();
  6442. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  6443. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  6444. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  6445. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  6446. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  6447. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  6448. curl_setopt ( $curl, CURLOPT_URL, $url );
  6449. $res = curl_exec ( $curl );
  6450. curl_close ( $curl );
  6451. return $res;
  6452. }
  6453. private function httpPost($url, $data) {
  6454. $curl = curl_init ();
  6455. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  6456. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  6457. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  6458. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  6459. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  6460. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  6461. curl_setopt ( $curl, CURLOPT_URL, $url );
  6462. curl_setopt ( $curl, CURLOPT_POST, 1 );
  6463. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  6464. $res = curl_exec ( $curl );
  6465. curl_close ( $curl );
  6466. return $res;
  6467. }
  6468. }
  6469. ?>