InvoiceController.php 251 KB

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