InvoiceController.php 274 KB

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