InvoiceController.php 212 KB

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