InvoiceController.php 224 KB

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