InvoiceController.php 167 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417
  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. // foreach ($fiML as $key=>$value){
  41. // $sidList=explode(',',$value);
  42. // foreach ($sidList as $k=>$v){
  43. // if ($v==$sid){
  44. // array_push ( $moldList, array (
  45. // 'mold' => $key
  46. // ) );
  47. // break;
  48. // }
  49. // }
  50. // }
  51. foreach ( $moldList as $value ) {
  52. if (Doo::acl ()->isAllowed ( $value ['mold'], $resource, $action )) {
  53. $flag = true;
  54. break;
  55. }
  56. }
  57. }
  58. /*
  59. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  60. */
  61. // var_dump($flag) ;
  62. if (! $flag)
  63. die ( 'illegal request' );
  64. }
  65. function __construct() {
  66. if (isset ( $_COOKIE ["staff"] )) {
  67. if (! empty ( $_COOKIE ["staff"] )) {
  68. Doo::loadModel ( 'staff' );
  69. $staff = new staff ();
  70. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  71. $this->ACTION = $uriPartsOrig [1];
  72. $this->data ['new'] = $this->isInvoiceNew ();
  73. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  74. return "/";
  75. }
  76. }
  77. Doo::loadCore ( 'uri/DooUriRouter' );
  78. $router = new DooUriRouter ();
  79. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  80. if ($routeRs ['1'] != "login") {
  81. header ( 'Content-Type:text/html;charset=utf-8' );
  82. @header ( "Location: /login" );
  83. }
  84. }
  85. function testSend(){
  86. // $msTouser='caipin|outaozhen';
  87. // $toparty= $this->getToparty('广东办');
  88. $msg = '[测试]你有一笔待认领款项,请及时领取';
  89. $toparty=26;
  90. //$msg = '';
  91. //$url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/1.html';
  92. // $hfreult = $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  93. }
  94. function invoice() {
  95. Doo::loadModel ( 'invoice' );
  96. $invoice = new invoice ();
  97. Doo::loadModel ( 'express' );
  98. $express = new express ();
  99. $expressList = $express->getExpressByAll ();
  100. $this->data ['expressList'] = $expressList;
  101. // Doo::loadModel ( 'invoiceReceivables' );
  102. // $invoiceReceivables = new invoiceReceivables ();
  103. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  104. Doo::loadModel ( 'invoiceStatistics' );
  105. $invoiceStatistics = new invoiceStatistics ();
  106. $isMonth = $invoiceStatistics->getStatisticsByMonth ();
  107. $year = date ( "Y" );
  108. $tmp_date = date ( "Ym" );
  109. $tmp_year = substr ( $tmp_date, 0, 4 );
  110. $tmp_mon = substr ( $tmp_date, 4, 2 );
  111. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  112. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  113. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  114. $htm = $this->showCache ( $path );
  115. Doo::loadClass ( 'XDeode' );
  116. $XDeode = new XDeode ( 5 );
  117. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  118. $invoiceList = $invoice->getMyInvoice ( $sid );
  119. $sql = 'status=2 and printStatus=1 and irid!="" and sid=' . $sid;
  120. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  121. // 我的待入账发票 and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  122. $sql = "status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid=" . $sid;
  123. $myInvoiceUnAccount = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  124. // print_r($myInvoiceUnAccount);
  125. $this->data ['isMonth'] = $isMonth;
  126. $this->data ['htm'] = $htm;
  127. $this->data ['invoiceList'] = $invoiceList;
  128. $this->data ['receivablesList'] = $list;
  129. $this->data ['myInvoiceUnAccount'] = $myInvoiceUnAccount;
  130. $this->data ['memu'] = "invoice";
  131. $this->data ['staff'] = $this->staff;
  132. $this->data ['receiptMemu'] = 'invoice';
  133. $this->render ( "/admin/invoice", $this->data );
  134. }
  135. function invoiceAdd() {
  136. Doo::loadModel ( 'L_category' );
  137. $lCategory = new L_category ();
  138. $category = $lCategory->find ( array (
  139. 'asArray' => true
  140. ) );
  141. $this->data ['category'] = $category;
  142. $this->data ['memu'] = "invoice";
  143. $this->data ['staff'] = $this->staff;
  144. $this->data ['receiptMemu'] = 'invoice';
  145. $this->render ( "/admin/invoiceAdd", $this->data );
  146. }
  147. /**
  148. * 提交一份开票申请,并记录下操作日志
  149. *
  150. * @since 1.0.0
  151. * @var integer cid 办事处ID
  152. * @var integer invoiceType 发票类型
  153. * @var integer doPost 是否邮寄
  154. * @var integer invoicePrice 开票金额
  155. * @var string invoiceElement 开票内容
  156. * @var string invoiceTitle 发票抬头
  157. * @var string invoiceCompany 单位名称
  158. * @var string TIN 纳税人识别码
  159. * @var string address 注册地址
  160. * @var string phone 注册电话
  161. * @var string bank 开户银行
  162. * @var string bankAccount 银行账户
  163. * @var string recipients 收件人
  164. * @var string recipientsPhone 收件人手机/电话
  165. * @var string recipientsAddress 收件地址
  166. * @var string mailItems 邮寄物品
  167. * @var string remark 备注
  168. * @return string 返回跳转开票主页路径
  169. */
  170. function invoiceAddDo() {
  171. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  172. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  173. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  174. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  175. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  176. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  177. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  178. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  179. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  180. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  181. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  182. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  183. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  184. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  185. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  186. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  187. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  188. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  189. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  190. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  191. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  192. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  193. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  194. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  195. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  196. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  197. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  198. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  199. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  200. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  201. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  202. /*
  203. * $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;
  204. */
  205. if(empty($this->staff [0]))
  206. die ( 'illegal request' );
  207. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement )) {
  208. Doo::loadModel ( 'invoice' );
  209. $invoice = new invoice ();
  210. Doo::loadModel ( 'L_category' );
  211. $lCategory = new L_category ();
  212. Doo::loadModel ( 'invoiceManage' );
  213. $invoiceManage = new invoiceManage ();
  214. Doo::loadModel ( 'invoiceOperationLog' );
  215. $invoiceOperationLog = new invoiceOperationLog ();
  216. $categoryDetil = $lCategory->getOne ( array (
  217. 'SELECT' => 'title',
  218. 'where' => 'cid=' . $cid,
  219. 'asArray' => true
  220. ) );
  221. $invoicePrice=$invoiceQuantity*$invoiceUnitPrice;
  222. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  223. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  224. // print_r(current($invoiceManageDetail ['staffList']));
  225. // die;
  226. $moldManage = array ();
  227. foreach ( $invoiceManageList as $key => $value ) {
  228. if ($value ['mold'] == '发票打印')
  229. $moldManage [$value ['mold']] = $value ['staffList'];
  230. elseif ($value ['mold'] == '发票邮寄')
  231. $moldManage [$value ['mold']] = $value ['staffList'];
  232. elseif ($value ['mold'] == '发票退票')
  233. $moldManage [$value ['mold']] = $value ['staffList'];
  234. }
  235. $item = array (
  236. 'cid' => $cid,
  237. 'categoryName' => $categoryDetil ['title'],
  238. 'invoiceElement' => $invoiceElement,
  239. 'invoiceQuantity' => $invoiceQuantity,
  240. 'invoiceUnitPrice' => $invoiceUnitPrice,
  241. 'invoicePrice' => $invoicePrice,
  242. 'invoiceType' => $invoiceType,
  243. 'doPost' => $doPost,
  244. 'status' => 1,
  245. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  246. 'date' => date ( "Y-m-d H:i:s" ),
  247. 'updateTime' => date ( "Y-m-d H:i:s" ),
  248. 'sid' => $this->staff [0] ['sid'],
  249. 'userName' => $this->staff [0] ['username'],
  250. 'invoiceManage' => $invoiceManageDetail ['staff'],
  251. 'pendingApprovals' => current ( $invoiceManageDetail ['staffList'] ) [0],
  252. 'moldManage' => json_encode ( $moldManage ),
  253. 'remark' => $remark
  254. );
  255. if ($invoiceType == 0)
  256. $item += array (
  257. 'invoiceTitle' => $invoiceTitle,
  258. 'TIN' => $TINT,
  259. 'address' => $addressT,
  260. 'phone' => $phoneT,
  261. 'bank' => $bankT,
  262. 'bankAccount' => $bankAccountT
  263. );
  264. else {
  265. $item += array (
  266. 'invoiceCompany' => $invoiceCompany,
  267. 'TIN' => $TIN,
  268. 'address' => $address,
  269. 'phone' => $phone,
  270. 'bank' => $bank,
  271. 'bankAccount' => $bankAccount
  272. );
  273. }
  274. if ($doPost == 1) {
  275. $mailList = array (
  276. 'invoice' => 1,
  277. 'mailItems' => $mailItems
  278. );
  279. if (! empty ( $softLock ))
  280. $mailList += array (
  281. 'softLock' => $softLockNum
  282. );
  283. else
  284. $mailList += array (
  285. 'softLock' => 0
  286. );
  287. if (! empty ( $contract ))
  288. $mailList += array (
  289. 'contract' => $contractNum
  290. );
  291. else
  292. $mailList += array (
  293. 'contract' => 0
  294. );
  295. if (! empty ( $instructions ))
  296. $mailList += array (
  297. 'instructions' => $instructionsNum
  298. );
  299. else
  300. $mailList += array (
  301. 'instructions' => 0
  302. );
  303. if (! empty ( $remittance ))
  304. $mailList += array (
  305. 'remittance' => $remittance
  306. );
  307. else
  308. $mailList += array (
  309. 'remittance' => ''
  310. );
  311. $mailString = '发票x1,备注:' . $mailItems;
  312. if (! empty ( $softLock ))
  313. $mailString .= ',软件锁x' . $softLockNum;
  314. if (! empty ( $contract ))
  315. $mailString .= ',合同x' . $contractNum;
  316. if (! empty ( $instructions ))
  317. $mailString .= ',说明书x' . $instructionsNum;
  318. if (! empty ( $remittance ))
  319. $mailString .= ',汇款账号单';
  320. $item += array (
  321. 'recipients' => $recipients,
  322. 'recipientsPhone' => $recipientsPhone,
  323. 'recipientsAddress' => $recipientsAddress,
  324. 'mailItems' => $mailString,
  325. 'mailItemsJson' => json_encode ( $mailList )
  326. );
  327. }
  328. $iid = $invoice->addInvoice ( $item );
  329. $item = array (
  330. 'date' => date ( "Y-m-d H:i:s" ),
  331. 'operation' => "创建",
  332. 'status' => 1,
  333. 'img' => $this->staff [0] ['avatar'],
  334. 'username' => $this->staff [0] ['username'],
  335. 'uid' => $this->staff [0] ['sid'],
  336. 'category' => $this->staff [0] ['category'],
  337. 'iid' => $iid
  338. );
  339. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  340. $item = array (
  341. 'date' => date ( "Y-m-d H:i:s" ),
  342. 'operation' => "提交审批",
  343. 'status' => 1,
  344. 'img' => $this->staff [0] ['avatar'],
  345. 'username' => $this->staff [0] ['username'],
  346. 'uid' => $this->staff [0] ['sid'],
  347. 'category' => $this->staff [0] ['category'],
  348. 'iid' => $iid
  349. );
  350. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  351. }
  352. return "/invoice";
  353. }
  354. function invoiceEdit() {
  355. Doo::loadClass ( 'XDeode' );
  356. $XDeode = new XDeode ( 5 );
  357. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  358. $iid = $XDeode->decode ( $iid );
  359. if (! is_numeric ( $iid ))
  360. die ( 'illegal request' );
  361. Doo::loadModel ( 'invoice' );
  362. $invoice = new invoice ();
  363. Doo::loadModel ( 'invoiceOperationLog' );
  364. $invoiceOperationLog = new invoiceOperationLog ();
  365. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  366. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  367. $invoiceDetail ['mailItemsJson'] = json_decode ( $invoiceDetail ['mailItemsJson'], true );
  368. $this->data ['operation'] = $operation;
  369. $this->data ['invoiceDetail'] = $invoiceDetail;
  370. $this->data ['memu'] = "invoice";
  371. $this->data ['staff'] = $this->staff;
  372. $this->data ['receiptMemu'] = 'invoice';
  373. $this->render ( "/admin/invoiceEdit", $this->data );
  374. }
  375. /**
  376. * 重新编辑退回的发票
  377. * @return string
  378. */
  379. function invoiceEditDo() {
  380. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  381. Doo::loadModel ( 'invoice' );
  382. $invoice = new invoice ();
  383. $iid = $invoice->authcode ( $iidKey );
  384. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  385. die ( 'illegal request' );
  386. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  387. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  388. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  389. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  390. $invoiceQuantity = $this->get_args ( 'invoiceQuantity' ) && is_numeric ( $this->get_args ( 'invoiceQuantity' ) ) ? $this->get_args ( 'invoiceQuantity' ) : 0;
  391. $invoiceUnitPrice = $this->get_args ( 'invoiceUnitPrice' ) && is_numeric ( $this->get_args ( 'invoiceUnitPrice' ) ) ? $this->get_args ( 'invoiceUnitPrice' ) : 0;
  392. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  393. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  394. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  395. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  396. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  397. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  398. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  399. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  400. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  401. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  402. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  403. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  404. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  405. $TINT = $this->get_args ( 'TINT' ) ? $this->get_args ( 'TINT' ) : "";
  406. $addressT = $this->get_args ( 'addressT' ) ? $this->get_args ( 'addressT' ) : "";
  407. $phoneT = $this->get_args ( 'phoneT' ) ? $this->get_args ( 'phoneT' ) : "";
  408. $bankT = $this->get_args ( 'bankT' ) ? $this->get_args ( 'bankT' ) : "";
  409. $bankAccountT = $this->get_args ( 'bankAccountT' ) ? $this->get_args ( 'bankAccountT' ) : "";
  410. $softLock = $this->get_args ( 'softLock' ) ? $this->get_args ( 'softLock' ) : 0;
  411. $softLockNum = $this->get_args ( 'softLockNum' ) ? $this->get_args ( 'softLockNum' ) : 0;
  412. $contract = $this->get_args ( 'contract' ) ? $this->get_args ( 'contract' ) : 0;
  413. $contractNum = $this->get_args ( 'contractNum' ) ? $this->get_args ( 'contractNum' ) : 0;
  414. $instructions = $this->get_args ( 'instructions' ) ? $this->get_args ( 'instructions' ) : 0;
  415. $instructionsNum = $this->get_args ( 'instructionsNum' ) ? $this->get_args ( 'instructionsNum' ) : 0;
  416. $remittance = $this->get_args ( 'remittance' ) ? $this->get_args ( 'remittance' ) : 0;
  417. if (! empty ( $cid ) && ! empty ( $invoiceQuantity ) && ! empty ( $invoiceUnitPrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  418. Doo::loadModel ( 'invoiceManage' );
  419. $invoiceManage = new invoiceManage ();
  420. Doo::loadModel ( 'invoiceOperationLog' );
  421. $invoiceOperationLog = new invoiceOperationLog ();
  422. $cid = explode ( ':', $cid );
  423. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  424. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  425. $moldManage = array ();
  426. foreach ( $invoiceManageList as $key => $value ) {
  427. if ($value ['mold'] == '发票打印')
  428. $moldManage [$value ['mold']] = $value ['staffList'];
  429. elseif ($value ['mold'] == '发票邮寄')
  430. $moldManage [$value ['mold']] = $value ['staffList'];
  431. elseif ($value ['mold'] == '发票打印')
  432. $moldManage [$value ['mold']] = $value ['staffList'];
  433. }
  434. $invoicePrice=$invoiceQuantity*$invoiceUnitPrice;
  435. $item = array (
  436. 'iid' => $iid,
  437. 'cid' => $cid [0],
  438. 'categoryName' => $cid [1],
  439. 'invoiceElement' => $invoiceElement,
  440. 'invoiceQuantity' => $invoiceQuantity,
  441. 'invoiceUnitPrice' => $invoiceUnitPrice,
  442. 'invoicePrice' => $invoicePrice,
  443. 'invoiceType' => $invoiceType,
  444. 'doPost' => $doPost,
  445. 'status' => 1,
  446. 'updateTime' => date ( "Y-m-d H:i:s" ),
  447. 'remark' => $remark
  448. );
  449. if ($invoiceType == 0)
  450. $item += array (
  451. 'invoiceTitle' => $invoiceTitle,
  452. 'TIN' => $TINT,
  453. 'address' => $addressT,
  454. 'phone' => $phoneT,
  455. 'bank' => $bankT,
  456. 'bankAccount' => $bankAccountT
  457. );
  458. else {
  459. $item += array (
  460. 'invoiceCompany' => $invoiceCompany,
  461. 'TIN' => $TIN,
  462. 'address' => $address,
  463. 'phone' => $phone,
  464. 'bank' => $bank,
  465. 'bankAccount' => $bankAccount
  466. );
  467. }
  468. if ($doPost == 1) {
  469. $mailList = array (
  470. 'invoice' => 1,
  471. 'mailItems' => $mailItems
  472. );
  473. if (! empty ( $softLock ))
  474. $mailList += array (
  475. 'softLock' => $softLockNum
  476. );
  477. else
  478. $mailList += array (
  479. 'softLock' => '0'
  480. );
  481. if (! empty ( $contract ))
  482. $mailList += array (
  483. 'contract' => $contractNum
  484. );
  485. else
  486. $mailList += array (
  487. 'contract' => '0'
  488. );
  489. if (! empty ( $instructions ))
  490. $mailList += array (
  491. 'instructions' => $instructionsNum
  492. );
  493. else
  494. $mailList += array (
  495. 'instructions' => '0'
  496. );
  497. if (! empty ( $remittance ))
  498. $mailList += array (
  499. 'remittance' => $remittance
  500. );
  501. else
  502. $mailList += array (
  503. 'remittance' => ''
  504. );
  505. $mailString = '发票x1,备注:' . $mailItems;
  506. if (! empty ( $softLock ))
  507. $mailString .= ',软件锁x' . $softLockNum;
  508. if (! empty ( $contract ))
  509. $mailString .= ',合同x' . $contractNum;
  510. if (! empty ( $instructions ))
  511. $mailString .= ',说明书x' . $instructionsNum;
  512. if (! empty ( $remittance ))
  513. $mailString .= ',汇款账号单';
  514. $item += array (
  515. 'recipients' => $recipients,
  516. 'recipientsPhone' => $recipientsPhone,
  517. 'recipientsAddress' => $recipientsAddress,
  518. 'mailItems' => $mailString,
  519. 'mailItemsJson' => json_encode ( $mailList )
  520. );
  521. }
  522. $invoice->setInvoiceByCondition ( $item );
  523. $item = array (
  524. 'date' => date ( "Y-m-d H:i:s" ),
  525. 'operation' => "重新提交审批",
  526. 'status' => 1,
  527. 'img' => $this->staff [0] ['avatar'],
  528. 'username' => $this->staff [0] ['username'],
  529. 'uid' => $this->staff [0] ['sid'],
  530. 'category' => $this->staff [0] ['category'],
  531. 'iid' => $iid
  532. );
  533. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  534. }
  535. return "/invoice";
  536. }
  537. /**
  538. * 培训班
  539. */
  540. function invoiceTraining(){
  541. $this->data ['memu'] = "invoice";
  542. $this->data ['staff'] = $this->staff;
  543. $this->data ['receiptMemu'] = 'invoice';
  544. $this->render ( "/admin/invoiceTraining", $this->data );
  545. }
  546. /**
  547. * 终止开票
  548. */
  549. function invoiceDroppedDo() {
  550. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  551. Doo::loadModel ( 'invoice' );
  552. $invoice = new invoice ();
  553. Doo::loadModel ( 'invoiceOperationLog' );
  554. $invoiceOperationLog = new invoiceOperationLog ();
  555. $iid = $invoice->authcode ( $droppedIidKey );
  556. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  557. die ( 'illegal request' );
  558. $item = array (
  559. 'iid' => $iid,
  560. 'status' => 4,
  561. 'updateTime' => date ( "Y-m-d H:i:s" )
  562. );
  563. $invoice->setInvoiceByCondition ( $item );
  564. $item = array (
  565. 'date' => date ( "Y-m-d H:i:s" ),
  566. 'operation' => '终止了开票',
  567. 'status' => 4,
  568. 'img' => $this->staff [0] ['avatar'],
  569. 'username' => $this->staff [0] ['username'],
  570. 'uid' => $this->staff [0] ['sid'],
  571. 'category' => $this->staff [0] ['category'],
  572. 'iid' => $iid
  573. );
  574. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  575. return "/invoice";
  576. }
  577. /**
  578. * 更新退票的邮寄信息
  579. */
  580. function invoiceUntreadMailDo() {
  581. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  582. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  583. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  584. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  585. Doo::loadModel ( 'invoice' );
  586. $invoice = new invoice ();
  587. $iid = $invoice->authcode ( $untreadIidKey );
  588. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  589. die ( 'illegal request' );
  590. $item = array (
  591. 'iid' => $iid,
  592. 'untreadCompany' => $untreadCompany,
  593. 'untreadNumber' => $untreadNumber,
  594. 'untreadItems' => $untreadItems
  595. );
  596. $invoice->setInvoiceByCondition ( $item );
  597. return "/invoice";
  598. }
  599. /**
  600. * 申请退票 --
  601. */
  602. function invoiceUntreadDo() {
  603. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  604. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  605. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  606. Doo::loadModel ( 'invoice' );
  607. $invoice = new invoice ();
  608. Doo::loadModel ( 'invoiceOperationLog' );
  609. $invoiceOperationLog = new invoiceOperationLog ();
  610. Doo::loadModel ( 'invoiceReceivables' );
  611. $invoiceReceivables = new invoiceReceivables ();
  612. $iid = $invoice->authcode ( $untreadIidKey );
  613. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  614. die ( 'illegal request' );
  615. /*
  616. * 需求变革 有绑定收款也可以退票 $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey ); if (! empty ( $lt )) { header ( 'Content-Type:text/html;charset=utf-8' ); die ( '该发票有收款绑定,请先移除!' ); }
  617. */
  618. $item = array (
  619. 'iid' => $iid,
  620. 'untreadStatus' => 1,
  621. 'untreadReason' => $untreadReason,
  622. 'untreadPost' => $untreadPost,
  623. 'updateTime' => date ( "Y-m-d H:i:s" )
  624. );
  625. $invoice->setInvoiceByCondition ( $item );
  626. $item = array (
  627. 'date' => date ( "Y-m-d H:i:s" ),
  628. 'operation' => '申请退票',
  629. 'status' => 7,
  630. 'img' => $this->staff [0] ['avatar'],
  631. 'username' => $this->staff [0] ['username'],
  632. 'uid' => $this->staff [0] ['sid'],
  633. 'category' => $this->staff [0] ['category'],
  634. 'iid' => $iid
  635. );
  636. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  637. return "/invoice";
  638. }
  639. /**
  640. * 删除已终止的开票
  641. */
  642. function invoiceDelDo() {
  643. Doo::loadClass ( 'XDeode' );
  644. $XDeode = new XDeode ( 5 );
  645. Doo::loadModel ( 'invoice' );
  646. $invoice = new invoice ();
  647. Doo::loadModel ( 'invoiceOperationLog' );
  648. $invoiceOperationLog = new invoiceOperationLog ();
  649. Doo::loadClass ( 'XDeode' );
  650. $XDeode = new XDeode ( 5 );
  651. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  652. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  653. $iid = $XDeode->decode ( $iid );
  654. if (! is_numeric ( $iid ))
  655. die ( 'illegal request' );
  656. $invoiceDetail = $invoice->getMyInvoice ( $sid, $iid );
  657. if (empty ( $invoiceDetail ))
  658. die ( 'illegal request' );
  659. $item = array (
  660. 'iid' => $iid,
  661. 'isDelete' => 1,
  662. 'updateTime' => date ( "Y-m-d H:i:s" )
  663. );
  664. $invoice->setInvoiceByCondition ( $item );
  665. $item = array (
  666. 'date' => date ( "Y-m-d H:i:s" ),
  667. 'operation' => '删除了已终止的发票',
  668. 'status' => 4,
  669. 'img' => $this->staff [0] ['avatar'],
  670. 'username' => $this->staff [0] ['username'],
  671. 'uid' => $this->staff [0] ['sid'],
  672. 'category' => $this->staff [0] ['category'],
  673. 'iid' => $iid
  674. );
  675. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  676. return "/invoice";
  677. }
  678. function invoiceApproval() {
  679. Doo::loadModel ( 'invoice' );
  680. $invoice = new invoice ();
  681. Doo::loadClass ( 'XDeode' );
  682. $XDeode = new XDeode ( 5 );
  683. Doo::loadModel ( 'staff' );
  684. $staff = new staff ();
  685. $invoiceList = $invoice->find ( array (
  686. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  687. 'desc' => 'iid',
  688. 'asArray' => true
  689. ) );
  690. foreach ( $invoiceList as $key => $value ) {
  691. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  692. $lastApprover = json_decode ( $value ['processApprovals'], true );
  693. if (! empty ( $lastApprover )) {
  694. $lastApproverKey = array_keys ( $lastApprover );
  695. $lastApprover = end ( $lastApprover );
  696. $staffDetail = $staff->getOne ( array (
  697. 'where' => 'sid=' . end ( $lastApproverKey ),
  698. 'asArray' => true
  699. ) );
  700. $lastApprover ['username'] = $staffDetail ['username'];
  701. }
  702. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  703. }
  704. $ilist = $invoice->getInvoiceByProcessStatus ();
  705. // print_r($ilist);
  706. $this->data ['invoiceList'] = $invoiceList;
  707. $this->data ['ilist'] = $ilist;
  708. $this->data ['memu'] = "invoice";
  709. $this->data ['staff'] = $this->staff;
  710. $this->data ['receiptMemu'] = 'invoiceApproval';
  711. $this->render ( "/admin/invoiceApproval", $this->data );
  712. }
  713. function invoiceDetail() {
  714. Doo::loadClass ( 'XDeode' );
  715. $XDeode = new XDeode ( 5 );
  716. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  717. $iid = $XDeode->decode ( $iid );
  718. if (! is_numeric ( $iid ))
  719. die ( 'illegal request' );
  720. Doo::loadModel ( 'invoice' );
  721. $invoice = new invoice ();
  722. Doo::loadModel ( 'invoiceOperationLog' );
  723. $invoiceOperationLog = new invoiceOperationLog ();
  724. $invoiceDetail = $invoice->getOne ( array (
  725. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  726. 'asArray' => true
  727. ) );
  728. if (empty ( $invoiceDetail ))
  729. die ( 'illegal request' );
  730. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  731. $this->data ['invoiceDetail'] = $invoiceDetail;
  732. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  733. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  734. $this->data ['memu'] = "invoice";
  735. $this->data ['staff'] = $this->staff;
  736. $this->data ['receiptMemu'] = 'invoiceApproval';
  737. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  738. }
  739. /**
  740. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  741. *
  742. * @since 1.0.0
  743. * @var integer iid 开票ID 已加密
  744. * @var integer status 发票审批状态
  745. * @var integer opintion 审批发票的意见
  746. * @return string 如操作成功返回审批首页
  747. */
  748. function invoiceApprovalDo() {
  749. Doo::loadModel ( 'invoice' );
  750. $invoice = new invoice ();
  751. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  752. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  753. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  754. $iid = $invoice->authcode ( $iid );
  755. if (! is_numeric ( $iid ))
  756. die ( 'illegal request' );
  757. // && ! empty ( $opinion )
  758. if (! empty ( $iid ) && ! empty ( $status )) {
  759. if (! ($status == 2 || $status == 3 || $status == 4))
  760. die ( 'illegal request' );
  761. Doo::loadModel ( 'invoiceOperationLog' );
  762. $invoiceOperationLog = new invoiceOperationLog ();
  763. $invoiceDetail = $invoice->getOne ( array (
  764. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  765. 'asArray' => true
  766. ) );
  767. if (empty ( $invoiceDetail ))
  768. die ( 'illegal request' );
  769. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  770. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  771. if ($status == 3) {
  772. $invoice->status = $status;
  773. $item = array (
  774. 'operation' => $opinion
  775. );
  776. } else {
  777. if (empty ( $processApprovals )) {
  778. $processApprovals = array (
  779. $this->staff [0] ['sid'] => array (
  780. 'date' => date ( "Y-m-d H:i:s" ),
  781. 'opinion' => $opinion,
  782. 'status' => $status
  783. )
  784. );
  785. // var_dump(next($invoiceManage));
  786. $nextInvoiceManage = next ( $invoiceManage );
  787. // print_r($nextInvoiceManage);
  788. if ($status != 4 && $nextInvoiceManage !== false)
  789. $invoice->pendingApprovals = $nextInvoiceManage [0];
  790. $invoice->processApprovals = json_encode ( $processApprovals );
  791. // var_dump($invoice);
  792. // print_r($invoiceManage);
  793. } else {
  794. $processApprovals [$this->staff [0] ['sid']] = array (
  795. 'date' => date ( "Y-m-d H:i:s" ),
  796. 'opinion' => $opinion,
  797. 'status' => $status
  798. );
  799. $pendingApprovals = 0;
  800. foreach ( $invoiceManage as $key => $value ) {
  801. if ($value [0] == $this->staff [0] ['sid']) {
  802. if (isset ( $invoiceManage [$key + 1] ))
  803. $pendingApprovals = $invoiceManage [$key + 1] [0];
  804. break;
  805. }
  806. }
  807. if ($status != 4 && ! empty ( $pendingApprovals ))
  808. $invoice->pendingApprovals = $pendingApprovals;
  809. $invoice->processApprovals = json_encode ( $processApprovals );
  810. }
  811. $item = array (
  812. 'operation' => $opinion
  813. );
  814. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  815. $invoice->status = $status;
  816. $invoice->pendingApprovals = 0;
  817. } elseif ($status == 4) {
  818. $invoice->status = $status;
  819. $item = array (
  820. 'operation' => $opinion
  821. );
  822. }
  823. }
  824. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  825. $invoice->update ( array (
  826. 'where' => 'iid=' . $iid
  827. ) );
  828. $item += array (
  829. 'date' => date ( "Y-m-d H:i:s" ),
  830. 'img' => $this->staff [0] ['avatar'],
  831. 'username' => $this->staff [0] ['username'],
  832. 'uid' => $this->staff [0] ['sid'],
  833. 'category' => $this->staff [0] ['category'],
  834. 'status' => $status,
  835. 'iid' => $iid
  836. );
  837. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  838. return '/invoiceApproval';
  839. }
  840. die ( 'illegal request' );
  841. }
  842. /**
  843. * 展示需要打印的发票数据
  844. *
  845. * @since 1.0.0
  846. */
  847. function invoicePrint() {
  848. Doo::loadModel ( 'invoice' );
  849. $invoice = new invoice ();
  850. Doo::loadClass ( 'XDeode' );
  851. $XDeode = new XDeode ( 5 );
  852. Doo::loadModel ( 'staff' );
  853. $staff = new staff ();
  854. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  855. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  856. foreach ( $toPrint as $key => $value ) {
  857. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  858. $lastApprover = json_decode ( $value ['processApprovals'], true );
  859. if (! empty ( $lastApprover )) {
  860. $lastApproverKey = array_keys ( $lastApprover );
  861. $lastApprover = end ( $lastApprover );
  862. $staffDetail = $staff->getOne ( array (
  863. 'where' => 'sid=' . end ( $lastApproverKey ),
  864. 'asArray' => true
  865. ) );
  866. $lastApprover ['username'] = $staffDetail ['username'];
  867. }
  868. $toPrint [$key] ['lastApprover'] = $lastApprover;
  869. }
  870. foreach ( $printed as $key => $value ) {
  871. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  872. $lastApprover = json_decode ( $value ['processApprovals'], true );
  873. if (! empty ( $lastApprover )) {
  874. $lastApproverKey = array_keys ( $lastApprover );
  875. $lastApprover = end ( $lastApprover );
  876. $staffDetail = $staff->getOne ( array (
  877. 'where' => 'sid=' . end ( $lastApproverKey ),
  878. 'asArray' => true
  879. ) );
  880. $lastApprover ['username'] = $staffDetail ['username'];
  881. }
  882. $printed [$key] ['lastApprover'] = $lastApprover;
  883. }
  884. $this->data ['printed'] = $printed;
  885. $this->data ['toPrint'] = $toPrint;
  886. $this->data ['memu'] = "invoice";
  887. $this->data ['staff'] = $this->staff;
  888. $this->data ['receiptMemu'] = 'invoicePrint';
  889. $this->render ( "/admin/invoicePrint", $this->data );
  890. }
  891. /**
  892. * 展示发票打印的详情页面
  893. *
  894. * @since 1.0.0
  895. */
  896. function invoicePrintDetail() {
  897. Doo::loadClass ( 'XDeode' );
  898. $XDeode = new XDeode ( 5 );
  899. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  900. $iid = $XDeode->decode ( $iid );
  901. if (! is_numeric ( $iid ))
  902. die ( 'illegal request' );
  903. Doo::loadModel ( 'invoice' );
  904. $invoice = new invoice ();
  905. Doo::loadModel ( 'invoiceOperationLog' );
  906. $invoiceOperationLog = new invoiceOperationLog ();
  907. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  908. if (empty ( $invoiceDetail ))
  909. die ( 'illegal request' );
  910. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  911. $this->data ['invoiceDetail'] = $invoiceDetail;
  912. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  913. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  914. $this->data ['memu'] = "invoice";
  915. $this->data ['staff'] = $this->staff;
  916. $this->data ['receiptMemu'] = 'invoicePrint';
  917. $this->render ( "/admin/invoicePrintDetail", $this->data );
  918. }
  919. /**
  920. * 填写票号并完成打印
  921. * @since 1.0.0
  922. */
  923. function invoicePrintDo() {
  924. Doo::loadModel ( 'invoice' );
  925. $invoice = new invoice ();
  926. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  927. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  928. $iid = $invoice->authcode ( $iid );
  929. if (! is_numeric ( $iid ))
  930. die ( 'illegal request' );
  931. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  932. Doo::loadModel ( 'invoiceOperationLog' );
  933. $invoiceOperationLog = new invoiceOperationLog ();
  934. Doo::loadModel ( 'invoiceStatistics' );
  935. $invoiceStatistics = new invoiceStatistics ();
  936. // $info=$invoice->getOne(array('where'=>"invoiceNo = '".$invoiceNo."'",'asArray' => TRUE));
  937. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  938. if (empty ( $invoicePrintDetail ))
  939. die ( 'illegal request' );
  940. $item = array (
  941. 'iid' => $iid,
  942. 'printStatus' => 1,
  943. 'updateTime' => date ( "Y-m-d H:i:s" ),
  944. 'printer' => $this->staff [0] ['username'],
  945. 'printTime' => date ( "Y-m-d H:i:s" ),
  946. 'invoiceNo' => $invoiceNo
  947. );
  948. $invoice->setInvoiceByCondition ( $item );
  949. $item = array (
  950. 'date' => date ( "Y-m-d H:i:s" ),
  951. 'operation' => $invoiceNo,
  952. 'status' => 5,
  953. 'img' => $this->staff [0] ['avatar'],
  954. 'username' => $this->staff [0] ['username'],
  955. 'uid' => $this->staff [0] ['sid'],
  956. 'category' => $this->staff [0] ['category'],
  957. 'iid' => $iid
  958. );
  959. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  960. // 去统计--负票不汇总
  961. if($invoicePrintDetail['untreadStatus']!=4){
  962. $item = array (
  963. 'date' => date ( "Y-m-d H:i:s" ),
  964. 'priceClass' => 1,
  965. 'cid' => $invoicePrintDetail ['cid'],
  966. 'staff' => $invoicePrintDetail ['sid'],
  967. 'invoicePrice' => $invoicePrintDetail ['invoicePrice']
  968. );
  969. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  970. }
  971. // 发送通知信息到微信-去除
  972. // $this->setWXMsg($iid,'PRINT');
  973. // 申请人获取微信通知
  974. Doo::loadModel ( 'staff' );
  975. $staff = new staff ();
  976. Doo::loadClass ( 'XDeode' );
  977. $XDeode = new XDeode ( 5 );
  978. $username2 = $staff->getOne ( array (
  979. 'select' => 'wxid',
  980. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  981. 'asArray' => TRUE
  982. ) );
  983. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '完成打印';
  984. $msg = '';
  985. $url = 'http://m.cld.smartcost.com.cn/invoicePrintDetail/' . $XDeode->encode ( $invoicePrintDetail ['iid'] ) . '.html';
  986. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'] );
  987. return "/invoicePrint";
  988. }
  989. }
  990. /**
  991. * 需要邮寄的发票
  992. * @since 1.0.0
  993. */
  994. function invoicePost() {
  995. Doo::loadModel ( 'invoice' );
  996. $invoice = new invoice ();
  997. Doo::loadModel ( 'express' );
  998. $express = new express ();
  999. $invoicePost = $invoice->getPostByInvoice ();
  1000. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  1001. $expressList = $express->getExpressByAll ();
  1002. $this->data ['expressList'] = $expressList;
  1003. $this->data ['invoicePost'] = $invoicePost;
  1004. $this->data ['invoicePosted'] = $invoicePosted;
  1005. $this->data ['memu'] = "invoice";
  1006. $this->data ['staff'] = $this->staff;
  1007. $this->data ['receiptMemu'] = 'invoicePost';
  1008. $this->render ( "/admin/invoicePost", $this->data );
  1009. }
  1010. /**
  1011. * 添加发票邮寄信息
  1012. */
  1013. function invoiceExpressAddDo() {
  1014. Doo::loadModel ( 'invoice' );
  1015. $invoice = new invoice ();
  1016. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  1017. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  1018. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  1019. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  1020. $iid = $iid = $invoice->authcode ( $iid );
  1021. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  1022. die ( 'illegal request' );
  1023. $invoicePrintDetail = $invoice->getInvoiceByIid ( $iid );
  1024. $item = array (
  1025. 'iid' => $iid,
  1026. 'postStatus' => 1,
  1027. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1028. 'postTime' => date ( "Y-m-d H:i:s" ),
  1029. 'expressCompany' => $expressCompany,
  1030. 'expressNumber' => $expressNumber,
  1031. 'actualItems' => $actualItems,
  1032. 'poster' => $this->staff [0] ['username']
  1033. );
  1034. $invoice->setInvoiceByCondition ( $item );
  1035. // 微信通知-去掉
  1036. // $this->setWXMsg ( $iid );
  1037. Doo::loadModel ( 'staff' );
  1038. $staff = new staff ();
  1039. Doo::loadClass ( 'XDeode' );
  1040. $XDeode = new XDeode ( 5 );
  1041. $username2 = $staff->getOne ( array (
  1042. 'select' => 'wxid',
  1043. 'where' => 'sid=' . $invoicePrintDetail ['sid'],
  1044. 'asArray' => TRUE
  1045. ) );
  1046. $title2 = '[结果]您的发票' . $invoicePrintDetail ['invoiceSerial'] . '已邮寄';
  1047. $expCom = explode ( ":", $invoicePrintDetail ['expressCompany'] );
  1048. if (empty ( $expCom ))
  1049. $expCom [0] = '';
  1050. $msg = $expCom [0] . ':' . $invoicePrintDetail ['expressNumber'] . '';
  1051. $url = 'https://m.kuaidi100.com/result.jsp?nu=' . $invoicePrintDetail ['expressNumber'];
  1052. $hfreult = $this->msgSend ( $msg, $title2, $url, $username2 ['wxid'] );
  1053. return '/invoicePost';
  1054. }
  1055. function invoiceExpressUpdateDo() {
  1056. Doo::loadModel ( 'invoice' );
  1057. $invoice = new invoice ();
  1058. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  1059. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  1060. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  1061. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  1062. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  1063. $iid = $invoice->authcode ( $iid );
  1064. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  1065. die ( 'illegal request' );
  1066. $item = array (
  1067. 'iid' => $iid,
  1068. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1069. 'expressCompany' => $expressCompany,
  1070. 'expressNumber' => $expressNumber,
  1071. 'actualItems' => $actualItems,
  1072. 'poster' => $this->staff [0] ['username']
  1073. );
  1074. $invoice->setInvoiceByCondition ( $item );
  1075. return $action;
  1076. }
  1077. /**
  1078. * 可退票管理
  1079. */
  1080. function invoiceUntreadIsAchieve() {
  1081. Doo::loadModel ( 'invoice' );
  1082. $invoice = new invoice ();
  1083. Doo::loadClass ( 'XDeode' );
  1084. $XDeode = new XDeode ( 5 );
  1085. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  1086. $page_size = 18;
  1087. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1088. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  1089. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  1090. $dateArr = explode ( ':', $date );
  1091. $D1 = '';
  1092. $D2 = '';
  1093. if (! empty ( $date )) {
  1094. $D1 = $dateArr [0];
  1095. $D2 = $dateArr [1];
  1096. }
  1097. $con = '';
  1098. if (! empty ( $D1 ) && ! empty ( $D2 ))
  1099. $con = ' and bindTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  1100. // if ($date == 'MONTHO')
  1101. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  1102. // elseif ($date == 'MONTHT')
  1103. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  1104. // elseif ($date == 'MONTHY')
  1105. // $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  1106. if (! empty ( $MebSea )) {
  1107. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  1108. }
  1109. $pageinfo ['page'] = array (
  1110. 'previous' => ''
  1111. );
  1112. // printStatus=1 and
  1113. $sql = " (untreadStatus=0 or untreadStatus=3) and status=2 and sid=" . $this->staff [0] ['sid'] . $con;
  1114. $action = "invoiceUntreadIsAchieve";
  1115. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  1116. $limit = $pageinfo ['lower'] . ',' . $page_size;
  1117. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  1118. // print_r($list);
  1119. $this->data ['MebSeaEn'] = $MebSea;
  1120. // $this->data ['MebSea'] = urlencode ( $MebSea );
  1121. $this->data ['get'] = $get;
  1122. $this->data ['page'] = $pageinfo;
  1123. $this->data ['date'] = $date;
  1124. $this->data ['list'] = $list;
  1125. $this->data ['memu'] = "invoice";
  1126. $this->data ['staff'] = $this->staff;
  1127. $this->data ['receiptMemu'] = 'invoice';
  1128. $this->render ( "/admin/invoiceUntreadIsAchieve", $this->data );
  1129. }
  1130. /**
  1131. * 退票处理页面
  1132. */
  1133. function invoiceUntread() {
  1134. Doo::loadModel ( 'invoice' );
  1135. $invoice = new invoice ();
  1136. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1 );
  1137. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  1138. foreach ( $establishedInvoice as $key => $value ) {
  1139. // months
  1140. $lossDate = strtotime ( "+1 month", strtotime ( $value ['OperationLog'] ['date'] ) );
  1141. $nowDate = strtotime ( 'now' );
  1142. $establishedInvoice [$key] ['lossShow'] = false;
  1143. if ($lossDate < $nowDate)
  1144. $establishedInvoice [$key] ['lossShow'] = true;
  1145. }
  1146. $this->data ['untreadInvoice'] = $untreadInvoice;
  1147. $this->data ['establishedInvoice'] = $establishedInvoice;
  1148. $this->data ['memu'] = "invoice";
  1149. $this->data ['staff'] = $this->staff;
  1150. $this->data ['receiptMemu'] = 'invoiceUntread';
  1151. $this->render ( "/admin/invoiceUntread", $this->data );
  1152. }
  1153. /**
  1154. * 确认收到退回的发票,开票状态为退回 //收款状态解绑,公司统计扣除入账额度
  1155. */
  1156. function invoiceUntreadEstablishedDo() {
  1157. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  1158. Doo::loadModel ( 'invoice' );
  1159. $invoice = new invoice ();
  1160. Doo::loadModel ( 'invoiceOperationLog' );
  1161. $invoiceOperationLog = new invoiceOperationLog ();
  1162. Doo::loadModel ( 'invoiceReceivables' );
  1163. $invoiceReceivables = new invoiceReceivables ();
  1164. Doo::loadModel ( 'invoiceStatistics' );
  1165. $invoiceStatistics = new invoiceStatistics ();
  1166. $iid = $invoice->authcode ( $untreadIidKey );
  1167. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  1168. die ( 'illegal request' );
  1169. $invoiceDetails = $invoice->getInvoiceByIid ( $iid );
  1170. if ($invoiceDetails ['untreadStatus'] != 1)
  1171. die ( 'illegal request' );
  1172. $item = array (
  1173. 'iid' => $iid,
  1174. // 'irid'=>'',
  1175. 'untreadStatus' => 2,
  1176. 'updateTime' => date ( "Y-m-d H:i:s" )
  1177. );
  1178. $invoice->setInvoiceByCondition ( $item );
  1179. $item = array (
  1180. 'date' => date ( "Y-m-d H:i:s" ),
  1181. 'operation' => '已确认退票',
  1182. 'status' => 6,
  1183. 'img' => $this->staff [0] ['avatar'],
  1184. 'username' => $this->staff [0] ['username'],
  1185. 'uid' => $this->staff [0] ['sid'],
  1186. 'category' => $this->staff [0] ['category'],
  1187. 'iid' => $iid
  1188. );
  1189. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1190. // 收款解绑以及入账扣除
  1191. if (! empty ( $invoiceDetails ['irid'] )) {
  1192. $iridList = explode ( ',', $invoiceDetails ['irid'] );
  1193. foreach ( $iridList as $value ) {
  1194. $irDetails = $invoiceReceivables->getOne ( array (
  1195. 'where' => " irid=" . $value . ' and bindStatus=1',
  1196. 'asArray' => TRUE
  1197. ) );
  1198. $item = array (
  1199. 'irid' => $value,
  1200. 'bindStatus' => 0,
  1201. 'untreadStatus' => 1,
  1202. 'untreadStaff' => $invoiceDetails ['userName'],
  1203. 'unbundlingTime' => date ( "Y-m-d H:i:s" ),
  1204. 'iid' => 0
  1205. );
  1206. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  1207. if (! empty ( $irDetails )) {
  1208. $item = array (
  1209. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['bindDate'] ) ),
  1210. 'priceClass' => 3,
  1211. 'cid' => $invoiceDetails ['cid'],
  1212. 'staff' => $invoiceDetails ['sid'],
  1213. 'accountPrice' => - $irDetails ['receivablesPrice']
  1214. );
  1215. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  1216. }
  1217. }
  1218. }
  1219. return "/invoiceUntread";
  1220. }
  1221. /**
  1222. * 建立负票,关联原来发票
  1223. */
  1224. function invoiceLossDo() {
  1225. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  1226. if ( ! empty ( $iidKey )) {
  1227. Doo::loadClass ( 'XDeode' );
  1228. $XDeode = new XDeode ( 5 );
  1229. Doo::loadModel ( 'invoice' );
  1230. $invoice = new invoice ();
  1231. Doo::loadModel ( 'invoiceOperationLog' );
  1232. $invoiceOperationLog = new invoiceOperationLog ();
  1233. $iidKey = $XDeode->decode ( $iidKey );
  1234. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  1235. //拷贝插入一条发票数据
  1236. $iid=$invoice->setInvoiceLoss($iidKey);
  1237. //更新负票
  1238. $invoiceSerial="#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1239. $invoice = new invoice ();
  1240. $item = array (
  1241. 'iid' => $iid,
  1242. 'sid' => $this->staff [0] ['sid'],
  1243. 'userName' => $this->staff [0] ['username'],
  1244. 'cid' => $this->staff [0] ['cid'],
  1245. 'categoryName' => $this->staff [0] ['category'],
  1246. 'invoiceQuantity'=>-$invoiceDetail['invoiceQuantity'],
  1247. 'invoicePrice' => -$invoiceDetail['invoicePrice'],
  1248. 'invoiceSerial' => $invoiceSerial,
  1249. 'invoiceNo'=>'',
  1250. 'printStatus' => 0,
  1251. 'untreadStatus' => 4,
  1252. //关联发票号
  1253. 'lossIid'=>$invoiceDetail['iid'],
  1254. );
  1255. $invoice->setInvoiceByCondition ( $item );
  1256. //更新原发票
  1257. $invoice = new invoice ();
  1258. $item = array (
  1259. 'iid' => $invoiceDetail['iid'],
  1260. 'lossIid'=>$iid,
  1261. );
  1262. $invoice->setInvoiceByCondition ( $item );
  1263. // 操作日志
  1264. $item = array (
  1265. 'date' => date ( "Y-m-d H:i:s" ),
  1266. 'operation' => "创建负票" . $invoiceSerial ,
  1267. 'status' => 12,
  1268. 'img' => $this->staff [0] ['avatar'],
  1269. 'username' => $this->staff [0] ['username'],
  1270. 'uid' => $this->staff [0] ['sid'],
  1271. 'category' => $this->staff [0] ['category'],
  1272. 'iid' => $iid
  1273. );
  1274. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1275. //print_r($invoiceDetail);
  1276. //echo $iid;die;
  1277. }
  1278. return '/invoiceUntread';
  1279. }
  1280. function invoiceReceivables() {
  1281. $invoiceTC = $this->get_args ( 'invoiceTC' ) ? $this->get_args ( 'invoiceTC' ) : '';
  1282. Doo::loadModel ( 'L_category' );
  1283. $lCategory = new L_category ();
  1284. Doo::loadModel ( 'staff' );
  1285. $staff = new staff ();
  1286. Doo::loadModel ( 'invoiceReceivables' );
  1287. $invoiceReceivables = new invoiceReceivables ();
  1288. Doo::loadModel ( 'invoice' );
  1289. $invoice = new invoice ();
  1290. Doo::loadClass ( 'XDeode' );
  1291. $XDeode = new XDeode ( 5 );
  1292. $category = $lCategory->getCategory ();
  1293. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  1294. $sql = 'bindStatus=1 and iid!=0';
  1295. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ( 4, $sql );
  1296. // 获取未入账发票
  1297. $invoiceUnAccount = $invoice->getInvoiceByUnAccount ();
  1298. $invoiceExistAccount = $invoice->getInvoiceByUnAccount ( '', true );
  1299. foreach ( $invoiceUnAccount as $key => $value ) {
  1300. $invoiceUnAccount [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1301. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1302. if (! empty ( $lastApprover )) {
  1303. $lastApproverKey = array_keys ( $lastApprover );
  1304. $lastApprover = end ( $lastApprover );
  1305. $staffDetail = $staff->getOne ( array (
  1306. 'where' => 'sid=' . end ( $lastApproverKey ),
  1307. 'asArray' => true
  1308. ) );
  1309. $lastApprover ['username'] = $staffDetail ['username'];
  1310. }
  1311. $invoiceUnAccount [$key] ['lastApprover'] = $lastApprover;
  1312. }
  1313. foreach ( $invoiceExistAccount as $key => $value ) {
  1314. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $value ['irid'] );
  1315. if (empty ( $irList ))
  1316. $irList [0] ['sumPrice'] = 0;
  1317. $balance = $value ['invoicePrice'] - $irList [0] ['sumPrice'];
  1318. $invoiceExistAccount [$key] ['existAccount'] = $irList [0] ['sumPrice'];
  1319. $invoiceExistAccount [$key] ['balance'] = $balance;
  1320. }
  1321. $receivablesInput = $invoiceReceivables->getInvoiceReceivablesByInput ();
  1322. // print_r($receivablesList);
  1323. $this->data ['receivablesDate'] = date ( "Y-m-d" );
  1324. $this->data ['ieaCount'] = count ( $invoiceExistAccount );
  1325. $this->data ['invoiceExistAccount'] = $invoiceExistAccount;
  1326. $this->data ['receivablesInput'] = $receivablesInput;
  1327. $this->data ['year'] = date ( 'Y' );
  1328. $this->data ['invoiceUnAccount'] = $invoiceUnAccount;
  1329. $this->data ['receivablesList'] = $receivablesList;
  1330. $this->data ['staffList'] = $staffList;
  1331. $this->data ['category'] = $category;
  1332. $this->data ['memu'] = "invoice";
  1333. $this->data ['staff'] = $this->staff;
  1334. $this->data ['receiptMemu'] = 'invoiceReceivables';
  1335. $this->render ( "/admin/invoiceReceivables", $this->data );
  1336. }
  1337. /**
  1338. * 新添加收款直接入账发票
  1339. */
  1340. function invoiceCompareClaimPrice() {
  1341. // 收款录入
  1342. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  1343. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  1344. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  1345. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  1346. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  1347. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $iidKey )) {
  1348. Doo::loadModel ( 'invoiceReceivables' );
  1349. $invoiceReceivables = new invoiceReceivables ();
  1350. Doo::loadModel ( 'invoiceROLog' );
  1351. $invoiceROLog = new invoiceROLog ();
  1352. Doo::loadModel ( 'invoiceStatistics' );
  1353. $invoiceStatistics = new invoiceStatistics ();
  1354. Doo::loadModel ( 'invoice' );
  1355. $invoice = new invoice ();
  1356. Doo::loadClass ( 'XDeode' );
  1357. $XDeode = new XDeode ( 5 );
  1358. Doo::loadModel ( 'invoiceOperationLog' );
  1359. $invoiceOperationLog = new invoiceOperationLog ();
  1360. $iidKey = $XDeode->decode ( $iidKey );
  1361. $invoiceDetail = $invoice->getInvoiceByIid ( $iidKey );
  1362. if (!($invoiceDetail['status']==2&&$invoiceDetail['printStatus']==1&&$invoiceDetail['untreadStatus']==0))
  1363. die ( 'illegal request' );
  1364. $receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  1365. // 收款录入 并绑定发票
  1366. Doo::db ()->beginTransaction ();
  1367. $item = array (
  1368. 'bindStatus' => 1,
  1369. 'iid' => $invoiceDetail ['iid'],
  1370. 'bindDate' => date ( "Y-m-d H:i:s" ),
  1371. 'receivablesPrice' => $receivablesPrice,
  1372. 'receivablesMessage' => $receivablesMessage,
  1373. 'receivablesSerial' => $receivablesSerial,
  1374. 'receivablesBank' => $receivablesBank,
  1375. 'receivablesDate' => $receivablesDate,
  1376. 'inputStaff' => $this->staff [0] ['username'],
  1377. 'accountClerk' => $this->staff [0] ['username'],
  1378. 'date' => date ( "Y-m-d" ),
  1379. 'receivablesCategory' => $invoiceDetail ['cid'] . ':' . $invoiceDetail ['categoryName'],
  1380. 'receivablesStaff' => $invoiceDetail ['sid'] . '-' . $invoiceDetail ['userName'],
  1381. 'confirmTime' => date ( "Y-m-d H:i:s" )
  1382. );
  1383. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  1384. $item = array ();
  1385. // 收款操作日志
  1386. $item = array (
  1387. 'operation' => $this->staff [0] ['username'] . " 转入 " . $invoiceDetail ['userName']
  1388. );
  1389. $item += array (
  1390. 'date' => date ( "Y-m-d" ),
  1391. 'status' => 1,
  1392. 'img' => $this->staff [0] ['avatar'],
  1393. 'username' => $this->staff [0] ['username'],
  1394. 'uid' => $this->staff [0] ['sid'],
  1395. 'category' => $this->staff [0] ['category'],
  1396. 'irid' => $irid
  1397. );
  1398. $invoiceROLog->setInvoiceROLog ( $item );
  1399. // 收款统计
  1400. $item = array (
  1401. 'date' => date ( "Y-m-d H:i:s" ),
  1402. 'priceClass' => 2,
  1403. 'irid' => $irid,
  1404. 'cid' => $invoiceDetail ['cid'],
  1405. 'staff' => $invoiceDetail ['sid'],
  1406. 'receivablesPrice' => $receivablesPrice
  1407. );
  1408. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  1409. // 收款 入 发票
  1410. $detail = $invoiceDetail;
  1411. $iridString = "";
  1412. if (empty ( $detail ['irid'] ))
  1413. $iridString = $irid;
  1414. else
  1415. $iridString = $detail ['irid'] . ',' . $irid;
  1416. $item = array (
  1417. 'irid' => $iridString,
  1418. 'bindTime' => date ( "Y-m-d H:i:s" ),
  1419. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1420. 'iid' => $detail ['iid']
  1421. );
  1422. $invoiceReceivables = new invoiceReceivables ();
  1423. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  1424. if ($detail ['invoicePrice'] <= $sum)
  1425. $item += array (
  1426. 'untreadStatus' => 3
  1427. );
  1428. $invoice->setInvoiceByCondition ( $item );
  1429. // 操作日志
  1430. $item = array (
  1431. 'date' => date ( "Y-m-d H:i:s" ),
  1432. 'operation' => "收款入账" . $receivablesSerial . "到发票" . $detail ['invoiceSerial'],
  1433. 'status' => 8,
  1434. 'img' => $this->staff [0] ['avatar'],
  1435. 'username' => $this->staff [0] ['username'],
  1436. 'uid' => $this->staff [0] ['sid'],
  1437. 'category' => $this->staff [0] ['category'],
  1438. 'iid' => $detail ['iid']
  1439. );
  1440. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1441. $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  1442. $accountPrice = 0;
  1443. foreach ( $list as $key => $value ) {
  1444. $accountPrice += $value ['receivablesPrice'];
  1445. }
  1446. $item = array (
  1447. 'date' => date ( "Y-m-d H:i:s" ),
  1448. 'priceClass' => 3,
  1449. 'cid' => $invoiceDetail ['cid'],
  1450. 'staff' => $invoiceDetail ['sid'],
  1451. 'accountPrice' => $accountPrice
  1452. );
  1453. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  1454. Doo::db ()->commit ();
  1455. }
  1456. return '/invoiceReceivables';
  1457. }
  1458. /**
  1459. * 检索未入账发票数据 function sir() { }
  1460. */
  1461. /**
  1462. * 录入收款数据
  1463. * @return string
  1464. */
  1465. function invoiceReceivablesDo() {
  1466. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  1467. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  1468. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  1469. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  1470. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  1471. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  1472. Doo::loadModel ( 'invoiceReceivables' );
  1473. $invoiceReceivables = new invoiceReceivables ();
  1474. Doo::loadModel ( 'invoiceROLog' );
  1475. $invoiceROLog = new invoiceROLog ();
  1476. Doo::loadModel ( 'invoiceStatistics' );
  1477. $invoiceStatistics = new invoiceStatistics ();
  1478. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  1479. $item = array (
  1480. 'receivablesPrice' => $receivablesPrice,
  1481. 'receivablesMessage' => $receivablesMessage,
  1482. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  1483. 'receivablesBank' => $receivablesBank,
  1484. 'receivablesDate' => $receivablesDate,
  1485. 'inputStaff' => $this->staff [0] ['username'],
  1486. 'date' => date ( "Y-m-d" ),
  1487. 'receivablesCategory' => $receivablesCategory,
  1488. 'receivablesStaff' => $receivablesStaff
  1489. );
  1490. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  1491. $item += array (
  1492. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  1493. 'inputType' => 1
  1494. );
  1495. }
  1496. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  1497. $item = array ();
  1498. // 收款操作日志
  1499. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  1500. $item = array (
  1501. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  1502. );
  1503. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  1504. $item = array (
  1505. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  1506. );
  1507. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  1508. $receivablesStaff = explode ( '-', $receivablesStaff );
  1509. $item = array (
  1510. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  1511. );
  1512. }
  1513. $item += array (
  1514. 'date' => date ( "Y-m-d" ),
  1515. 'status' => 1,
  1516. 'img' => $this->staff [0] ['avatar'],
  1517. 'username' => $this->staff [0] ['username'],
  1518. 'uid' => $this->staff [0] ['sid'],
  1519. 'category' => $this->staff [0] ['category'],
  1520. 'irid' => $irid
  1521. );
  1522. $invoiceROLog->setInvoiceROLog ( $item );
  1523. $item = array (
  1524. 'date' => date ( "Y-m-d H:i:s" ),
  1525. 'priceClass' => 2,
  1526. 'irid' => $irid,
  1527. 'receivablesPrice' => $receivablesPrice
  1528. );
  1529. if ($receivablesCategory != 'PUBLIC') {
  1530. $receivablesCategory = explode ( ":", $receivablesCategory );
  1531. $item += array (
  1532. 'cid' => $receivablesCategory [0]
  1533. );
  1534. }
  1535. if ($receivablesStaff2 != 'PUBLIC') {
  1536. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  1537. $item += array (
  1538. 'staff' => $receivablesStaff [0]
  1539. );
  1540. }
  1541. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  1542. $toparty= $this->getToparty($receivablesCategory[1]);
  1543. $msg = '[通知]你有一笔待认领款项,请及时领取';
  1544. if ($toparty!=0)
  1545. $this->msgSendToparty ( $msg, '', '', $toparty,'text' );
  1546. }
  1547. return "/invoiceReceivables";
  1548. }
  1549. /**
  1550. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  1551. */
  1552. function invoiceReceivablesClaim() {
  1553. Doo::loadModel ( 'invoiceReceivables' );
  1554. $invoiceReceivables = new invoiceReceivables ();
  1555. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  1556. $this->data ['receivablesList'] = $receivablesList;
  1557. $this->data ['memu'] = "invoice";
  1558. $this->data ['staff'] = $this->staff;
  1559. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  1560. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  1561. }
  1562. /**
  1563. * 更新收款相关数据
  1564. */
  1565. function invoiceReceivablesUpdateClaim() {
  1566. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  1567. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  1568. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  1569. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  1570. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  1571. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  1572. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  1573. if (empty ( $claimKey ))
  1574. die ( 'illegal request' );
  1575. Doo::loadModel ( 'invoiceReceivables' );
  1576. $invoiceReceivables = new invoiceReceivables ();
  1577. Doo::loadModel ( 'invoiceROLog' );
  1578. $invoiceROLog = new invoiceROLog ();
  1579. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  1580. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  1581. if (empty ( $detail ))
  1582. die ( 'illegal request' );
  1583. $invoiceReceivables = new invoiceReceivables ();
  1584. $item = array (
  1585. 'irid' => $detail ['irid']
  1586. );
  1587. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  1588. $item += array (
  1589. 'confirmTime' => date ( "Y-m-d H:i:s" )
  1590. );
  1591. }
  1592. if (! empty ( $receivablesCategory ))
  1593. $item += array (
  1594. 'receivablesCategory' => $receivablesCategory
  1595. );
  1596. if (! empty ( $receivablesStaff ))
  1597. $item += array (
  1598. 'receivablesStaff' => $receivablesStaff
  1599. );
  1600. if (! empty ( $receivablesPrice ))
  1601. $item += array (
  1602. 'receivablesPrice' => $receivablesPrice
  1603. );
  1604. if (! empty ( $receivablesMessage ))
  1605. $item += array (
  1606. 'receivablesMessage' => $receivablesMessage
  1607. );
  1608. if (! empty ( $receivablesBank ))
  1609. $item += array (
  1610. 'receivablesBank' => $receivablesBank
  1611. );
  1612. if (! empty ( $receivablesDate ))
  1613. $item += array (
  1614. 'receivablesDate' => $receivablesDate
  1615. );
  1616. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  1617. // 收款操作日志
  1618. $item = array ();
  1619. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  1620. $item = array (
  1621. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  1622. );
  1623. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  1624. $item = array (
  1625. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  1626. );
  1627. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  1628. $receivablesStaff = explode ( '-', $receivablesStaff );
  1629. $item = array (
  1630. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  1631. );
  1632. }
  1633. $item += array (
  1634. 'date' => date ( "Y-m-d" ),
  1635. 'status' => 1,
  1636. 'img' => $this->staff [0] ['avatar'],
  1637. 'username' => $this->staff [0] ['username'],
  1638. 'uid' => $this->staff [0] ['sid'],
  1639. 'category' => $this->staff [0] ['category'],
  1640. 'irid' => $detail ['irid']
  1641. );
  1642. $invoiceROLog->setInvoiceROLog ( $item );
  1643. return '/invoiceReceivablesAS';
  1644. }
  1645. function invoiceReceivablesDelete() {
  1646. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  1647. if (empty ( $claimKey ))
  1648. die ( 'illegal request' );
  1649. Doo::loadModel ( 'invoiceReceivables' );
  1650. $invoiceReceivables = new invoiceReceivables ();
  1651. $con = ' and iid=0 and bindStatus=0 and receivablesStaff="PUBLIC"';
  1652. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  1653. if (empty ( $detail ))
  1654. die ( 'illegal request' );
  1655. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  1656. return '/invoiceReceivablesAS';
  1657. }
  1658. /**
  1659. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  1660. */
  1661. function invoiceReceivablesAscription() {
  1662. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  1663. $recepitTitleMark = $this->get_args ( 'recepitTitleMark' ) ? $this->get_args ( 'recepitTitleMark' ) : "";
  1664. Doo::loadModel ( 'invoiceReceivables' );
  1665. $invoiceReceivables = new invoiceReceivables ();
  1666. Doo::loadModel ( 'invoiceROLog' );
  1667. $invoiceROLog = new invoiceROLog ();
  1668. Doo::loadModel ( 'invoiceStatistics' );
  1669. $invoiceStatistics = new invoiceStatistics ();
  1670. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  1671. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC' && ! empty ( $recepitTitleMark )) {
  1672. $item = array (
  1673. 'irid' => $detail ['irid'],
  1674. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  1675. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  1676. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  1677. 'recepitTitleMark' => $recepitTitleMark,
  1678. 'source' => 1
  1679. );
  1680. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  1681. $item = array (
  1682. 'date' => date ( "Y-m-d" ),
  1683. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  1684. 'status' => 2,
  1685. 'img' => $this->staff [0] ['avatar'],
  1686. 'username' => $this->staff [0] ['username'],
  1687. 'uid' => $this->staff [0] ['sid'],
  1688. 'category' => $this->staff [0] ['category'],
  1689. 'irid' => $irid
  1690. );
  1691. $invoiceROLog->setInvoiceROLog ( $item );
  1692. $item = array (
  1693. 'cid' => $this->staff [0] ['cid'],
  1694. 'staff' => $this->staff [0] ['sid']
  1695. );
  1696. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'] );
  1697. }
  1698. return "/invoiceReceivablesClaim";
  1699. }
  1700. /**
  1701. */
  1702. function invoiceMyReceivables() {
  1703. Doo::loadModel ( 'invoiceReceivables' );
  1704. $invoiceReceivables = new invoiceReceivables ();
  1705. Doo::loadModel ( 'invoiceStatistics' );
  1706. $invoiceStatistics = new invoiceStatistics ();
  1707. $isMonth = $invoiceStatistics->getStatisticsByMonth ();
  1708. $year = date ( "Y" );
  1709. $tmp_date = date ( "Ym" );
  1710. $tmp_year = substr ( $tmp_date, 0, 4 );
  1711. $tmp_mon = substr ( $tmp_date, 4, 2 );
  1712. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  1713. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  1714. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  1715. $htm = $this->showCache ( $path );
  1716. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  1717. $this->data ['isMonth'] = $isMonth;
  1718. $this->data ['htm'] = $htm;
  1719. $this->data ['list'] = $list;
  1720. $this->data ['memu'] = "invoice";
  1721. $this->data ['staff'] = $this->staff;
  1722. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  1723. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  1724. }
  1725. /**
  1726. * 收款绑定发票 ,一个收款只能绑定一个发票
  1727. */
  1728. function invoiceBindReceivables() {
  1729. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  1730. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1731. Doo::loadModel ( 'invoice' );
  1732. $invoice = new invoice ();
  1733. Doo::loadModel ( 'invoiceReceivables' );
  1734. $invoiceReceivables = new invoiceReceivables ();
  1735. Doo::loadModel ( 'invoiceOperationLog' );
  1736. $invoiceOperationLog = new invoiceOperationLog ();
  1737. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  1738. die ( 'illegal request' );
  1739. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  1740. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  1741. if (empty ( $detail ) && empty ( $detailM ))
  1742. die ( 'illegal request' );
  1743. if ($detail ['untreadStatus'] == 3)
  1744. die ( 'illegal request' );
  1745. // if ($detailM ['receivablesPrice'] >= $detail ['invoicePrice']) {
  1746. // $price = $detailM ['receivablesPrice'] - $detail ['invoicePrice'];
  1747. // die ( '<p>收款金额超出开票金额 ¥' . $price . '元,请谨慎操作</p><a href="/invoiceMyReceivables">返回</a>' );
  1748. // }
  1749. $item = array (
  1750. 'irid' => $detailM ['irid'],
  1751. 'bindStatus' => 1,
  1752. 'iid' => $detail ['iid'],
  1753. 'accountClerk' => $this->staff [0] ['username'],
  1754. 'bindDate' => date ( "Y-m-d H:i:s" )
  1755. );
  1756. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  1757. $iridString = "";
  1758. if (empty ( $detail ['irid'] ))
  1759. $iridString = $detailM ['irid'];
  1760. else
  1761. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  1762. $item = array (
  1763. 'iid' => $detail ['iid'],
  1764. 'irid' => $iridString
  1765. );
  1766. $sum = $invoiceReceivables->getSumOfReceivablesPrice ( $iridString );
  1767. if ($detail ['invoicePrice'] <= $sum)
  1768. $item += array (
  1769. 'untreadStatus' => 3
  1770. );
  1771. $invoice->setInvoiceByCondition ( $item );
  1772. // 操作日志
  1773. $item = array (
  1774. 'date' => date ( "Y-m-d H:i:s" ),
  1775. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  1776. 'status' => 8,
  1777. 'img' => $this->staff [0] ['avatar'],
  1778. 'username' => $this->staff [0] ['username'],
  1779. 'uid' => $this->staff [0] ['sid'],
  1780. 'category' => $this->staff [0] ['category'],
  1781. 'iid' => $detail ['iid']
  1782. );
  1783. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1784. Doo::loadModel ( 'invoiceStatistics' );
  1785. $invoiceStatistics = new invoiceStatistics ();
  1786. $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  1787. $accountPrice = 0;
  1788. foreach ( $list as $key => $value ) {
  1789. $accountPrice += $value ['receivablesPrice'];
  1790. }
  1791. $item = array (
  1792. 'date' => date ( "Y-m-d H:i:s" ),
  1793. 'priceClass' => 3,
  1794. 'cid' => $detail ['cid'],
  1795. 'staff' => $detail ['sid'],
  1796. 'accountPrice' => $accountPrice
  1797. );
  1798. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  1799. return "/invoiceReceivables";
  1800. }
  1801. /**
  1802. * 核销 动作,确认入账统计 发票收款完成--需求更变 废弃 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"; }
  1803. */
  1804. function invoiceAggregate() {
  1805. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  1806. Doo::loadModel ( 'invoiceStatistics' );
  1807. $invoiceStatistics = new invoiceStatistics ();
  1808. Doo::loadModel ( 'L_category' );
  1809. $Lcategory = new L_category ();
  1810. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  1811. $LcategoryList = $Lcategory->getCategory ();
  1812. // print_r($isList);
  1813. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  1814. foreach ( $LcategoryList as $key => $value ) {
  1815. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  1816. $month = 1;
  1817. $invoicePriceYear = 0;
  1818. $receivablesPriceYear = 0;
  1819. $accountPriceYear = 0;
  1820. for(; $month <= 12; $month ++) {
  1821. $flag = true;
  1822. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  1823. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  1824. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  1825. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  1826. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  1827. ';
  1828. $invoicePriceYear += $v ['invoicePrice'];
  1829. $receivablesPriceYear += $v ['receivablesPrice'];
  1830. $accountPriceYear += $v ['accountPrice'];
  1831. $flag = false;
  1832. break;
  1833. }
  1834. }
  1835. if ($flag)
  1836. $html .= '<td class="taR"></td>
  1837. <td class="taR"></td>
  1838. <td class="taR"><b></b></td>
  1839. ';
  1840. }
  1841. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  1842. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  1843. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  1844. ';
  1845. $html .= '</tr>';
  1846. }
  1847. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  1848. $invoicePriceYear = 0;
  1849. $receivablesPriceYear = 0;
  1850. $accountPriceYear = 0;
  1851. for($month = 1; $month <= 12; $month ++) {
  1852. $flag = true;
  1853. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  1854. if ($month == $v ['month']) {
  1855. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  1856. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  1857. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  1858. ';
  1859. $invoicePriceYear += $v ['invoicePrice'];
  1860. $receivablesPriceYear += $v ['receivablesPrice'];
  1861. $accountPriceYear += $v ['accountPrice'];
  1862. $flag = false;
  1863. break;
  1864. }
  1865. }
  1866. if ($flag) {
  1867. $html .= '<td class="taR"></td>
  1868. <td class="taR"></td>
  1869. <td class="taR"><b></b></td>
  1870. ';
  1871. }
  1872. }
  1873. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  1874. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  1875. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  1876. ';
  1877. $html .= '</tr>';
  1878. // print_r($isList);
  1879. $this->data ['html'] = $html;
  1880. $this->data ['LcategoryList'] = $LcategoryList;
  1881. $this->data ['isList'] = $isList;
  1882. $this->data ['year'] = $year;
  1883. $this->data ['memu'] = "invoice";
  1884. $this->data ['staff'] = $this->staff;
  1885. $this->data ['receiptMemu'] = 'invoiceAggregate';
  1886. $this->render ( "/admin/invoiceAggregate", $this->data );
  1887. }
  1888. function invoiceAggregateStaff() {
  1889. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  1890. Doo::loadModel ( 'invoiceStatistics' );
  1891. $invoiceStatistics = new invoiceStatistics ();
  1892. Doo::loadModel ( 'L_category' );
  1893. $Lcategory = new L_category ();
  1894. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  1895. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  1896. $cStaff = $Lcategory->getCategoryStaff ();
  1897. $html = '';
  1898. foreach ( $cStaff as $key => $value ) {
  1899. $categoryFir = true;
  1900. foreach ( $value ['staff'] as $k => $v ) {
  1901. if ($categoryFir) {
  1902. $width = count ( $value ['staff'] ) + 1;
  1903. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  1904. $categoryFir = false;
  1905. } else
  1906. $html .= '<tr>';
  1907. $html .= '<th>' . $v ['username'] . '</th>';
  1908. $invoicePriceStaffYear = 0;
  1909. $receivablesPriceStaffYear = 0;
  1910. $accountPriceStaffYear = 0;
  1911. for($month = 1; $month <= 12; $month ++) {
  1912. $flag = true;
  1913. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  1914. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  1915. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  1916. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  1917. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  1918. ';
  1919. $invoicePriceStaffYear += $slv ['invoicePrice'];
  1920. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  1921. $accountPriceStaffYear += $slv ['accountPrice'];
  1922. $flag = false;
  1923. break;
  1924. }
  1925. }
  1926. if ($flag)
  1927. $html .= '<td class="taR"></td>
  1928. <td class="taR"></td>
  1929. <td class="taR"><b></b></td>
  1930. ';
  1931. }
  1932. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  1933. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  1934. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  1935. ';
  1936. }
  1937. $html .= '</tr>';
  1938. // 小计
  1939. if (! empty ( $value ['staff'] )) {
  1940. $html .= '<tr><th class="taR">小计</th>';
  1941. $invoicePriceStaffYear = 0;
  1942. $receivablesPriceStaffYear = 0;
  1943. $accountPriceStaffYear = 0;
  1944. for($month = 1; $month <= 12; $month ++) {
  1945. $flag = true;
  1946. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  1947. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  1948. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  1949. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  1950. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  1951. ';
  1952. $invoicePriceStaffYear += $slv ['invoicePrice'];
  1953. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  1954. $accountPriceStaffYear += $slv ['accountPrice'];
  1955. $flag = false;
  1956. break;
  1957. }
  1958. }
  1959. if ($flag)
  1960. $html .= '<td class="taR"></td>
  1961. <td class="taR"></td>
  1962. <td class="taR"><b></b></td>
  1963. ';
  1964. }
  1965. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  1966. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  1967. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  1968. ';
  1969. $html .= '</tr>';
  1970. }
  1971. }
  1972. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  1973. $invoicePriceYear = 0;
  1974. $receivablesPriceYear = 0;
  1975. $accountPriceYear = 0;
  1976. for($month = 1; $month <= 12; $month ++) {
  1977. $flag = true;
  1978. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  1979. if ($month == $v ['month']) {
  1980. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  1981. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  1982. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  1983. ';
  1984. $invoicePriceYear += $v ['invoicePrice'];
  1985. $receivablesPriceYear += $v ['receivablesPrice'];
  1986. $accountPriceYear += $v ['accountPrice'];
  1987. $flag = false;
  1988. break;
  1989. }
  1990. }
  1991. if ($flag)
  1992. $html .= '<td class="taR"></td>
  1993. <td class="taR"></td>
  1994. <td class="taR"><b></b></td>
  1995. ';
  1996. }
  1997. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  1998. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  1999. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  2000. ';
  2001. $html .= '</tr>';
  2002. $this->data ['html'] = $html;
  2003. $this->data ['isList'] = $toteList;
  2004. $this->data ['year'] = $year;
  2005. $this->data ['memu'] = "invoice";
  2006. $this->data ['staff'] = $this->staff;
  2007. $this->data ['receiptMemu'] = 'invoiceAggregate';
  2008. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  2009. }
  2010. function invoiceAggregateCategory() {
  2011. Doo::loadClass ( 'XDeode' );
  2012. $XDeode = new XDeode ( 5 );
  2013. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  2014. $cid = $XDeode->decode ( $cid );
  2015. if (! is_numeric ( $cid ))
  2016. die ( 'illegal request' );
  2017. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  2018. Doo::loadModel ( 'invoiceStatistics' );
  2019. $invoiceStatistics = new invoiceStatistics ();
  2020. Doo::loadModel ( 'staff' );
  2021. $staff = new staff ();
  2022. $list = $staff->getStaffByCid ( $cid );
  2023. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  2024. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  2025. if (empty ( $list ))
  2026. die ( '该办事处没有成员' );
  2027. $htmlA = $htmlB = $htmlC = $html = '';
  2028. foreach ( $list as $key => $value ) {
  2029. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  2030. $htmlB = '<tr><th class="taC">收款</th>';
  2031. $htmlC = '<tr><th class="taC">入账</th>';
  2032. $invoicePriceStaffYear = 0;
  2033. $receivablesPriceStaffYear = 0;
  2034. $accountPriceStaffYear = 0;
  2035. for($month = 1; $month <= 12; $month ++) {
  2036. $flag = true;
  2037. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  2038. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  2039. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  2040. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  2041. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  2042. $invoicePriceStaffYear += $v ['invoicePrice'];
  2043. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  2044. $accountPriceStaffYear += $v ['accountPrice'];
  2045. $flag = false;
  2046. break;
  2047. }
  2048. }
  2049. if ($flag) {
  2050. $htmlA .= '<td class="taR">-</td>';
  2051. $htmlB .= '<td class="taR">-</td>';
  2052. $htmlC .= '<td class="taR"><b>-</b></td>';
  2053. }
  2054. }
  2055. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  2056. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  2057. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  2058. $htmlA .= '</tr>';
  2059. $htmlB .= '</tr>';
  2060. $htmlC .= '</tr>';
  2061. $html .= $htmlA . $htmlB . $htmlC;
  2062. }
  2063. $htmlA = $htmlB = $htmlC = "";
  2064. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  2065. $htmlB = '<tr><th class="taC">收款</th>';
  2066. $htmlC = '<tr><th class="taC">入账</th>';
  2067. $invoicePriceStaffYear = 0;
  2068. $receivablesPriceStaffYear = 0;
  2069. $accountPriceStaffYear = 0;
  2070. for($month = 1; $month <= 12; $month ++) {
  2071. $flag = true;
  2072. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  2073. if ($month == $v ['month']) {
  2074. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  2075. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  2076. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  2077. $invoicePriceStaffYear += $v ['invoicePrice'];
  2078. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  2079. $accountPriceStaffYear += $v ['accountPrice'];
  2080. $flag = false;
  2081. break;
  2082. }
  2083. }
  2084. if ($flag) {
  2085. $htmlA .= '<td class="taR">-</td>';
  2086. $htmlB .= '<td class="taR">-</td>';
  2087. $htmlC .= '<td class="taR"><b>-</b></td>';
  2088. }
  2089. }
  2090. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  2091. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  2092. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  2093. $htmlA .= '</tr>';
  2094. $htmlB .= '</tr>';
  2095. $htmlC .= '</tr>';
  2096. $html .= $htmlA . $htmlB . $htmlC;
  2097. $this->data ['html'] = $html;
  2098. $this->data ['cidKey'] = $cidKey;
  2099. $this->data ['slist'] = $list;
  2100. $this->data ['isList'] = $toteList;
  2101. $this->data ['year'] = $year;
  2102. $this->data ['memu'] = "invoice";
  2103. $this->data ['staff'] = $this->staff;
  2104. $this->data ['receiptMemu'] = 'invoiceAggregate';
  2105. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  2106. }
  2107. function invoiceAchieve() {
  2108. Doo::loadModel ( 'invoice' );
  2109. $invoice = new invoice ();
  2110. Doo::loadClass ( 'XDeode' );
  2111. $XDeode = new XDeode ( 5 );
  2112. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  2113. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  2114. $page_size = 18;
  2115. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2116. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  2117. $get = "/" . $date;
  2118. $con = '';
  2119. if ($date == 'MONTHO')
  2120. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2121. elseif ($date == 'MONTHT')
  2122. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2123. elseif ($date == 'MONTHY')
  2124. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2125. if (! empty ( $MebSea )) {
  2126. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  2127. $get .= "/" . $MebSea;
  2128. }
  2129. $pageinfo ['page'] = array (
  2130. 'previous' => ''
  2131. );
  2132. $sql = 'status=2 and printStatus=1 and ( untreadStatus=3 or untreadStatus=0 ) and sid=' . $sid . $con;
  2133. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  2134. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2135. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2136. // print_r($pageinfo);
  2137. $this->data ['MebSeaEn'] = $MebSea;
  2138. $this->data ['MebSea'] = urlencode ( $MebSea );
  2139. $this->data ['get'] = $get;
  2140. $this->data ['page'] = $pageinfo;
  2141. $this->data ['list'] = $list;
  2142. $this->data ['date'] = $date;
  2143. $this->data ['memu'] = "invoice";
  2144. $this->data ['staff'] = $this->staff;
  2145. $this->data ['receiptMemu'] = 'invoice';
  2146. $this->render ( "/admin/invoiceAchieve", $this->data );
  2147. }
  2148. function invoiceMyUnAccountAchieve() {
  2149. Doo::loadModel ( 'invoice' );
  2150. $invoice = new invoice ();
  2151. Doo::loadClass ( 'XDeode' );
  2152. $XDeode = new XDeode ( 5 );
  2153. Doo::loadModel ( 'staff' );
  2154. $staff = new staff ();
  2155. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  2156. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2157. $page_size = 18;
  2158. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2159. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2160. $get = "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2161. $dateArr = explode ( ':', $date );
  2162. $D1 = '';
  2163. $D2 = '';
  2164. if (! empty ( $date )) {
  2165. $D1 = $dateArr [0];
  2166. $D2 = $dateArr [1];
  2167. }
  2168. $con = '';
  2169. if (! empty ( $D1 ) && ! empty ( $D2 ))
  2170. $con = ' and printTime BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2171. if (! empty ( $MebSea )) {
  2172. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  2173. }
  2174. $pageinfo ['page'] = array (
  2175. 'previous' => ''
  2176. );
  2177. // and irid='' and ( (doPost=1 and postStatus=1) or doPost=0 )
  2178. $sql = " status=2 and printStatus=1 and untreadStatus=0 and isDelete=0 and sid= " . $sid . $con;
  2179. $action = "invoiceMyUnAccountAchieve";
  2180. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2181. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2182. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2183. Doo::loadModel ( 'express' );
  2184. $express = new express ();
  2185. $expressList = $express->getExpressByAll ();
  2186. $this->data ['expressList'] = $expressList;
  2187. // print_r($list);
  2188. $this->data ['MebSeaEn'] = $MebSea;
  2189. $this->data ['get'] = $get;
  2190. $this->data ['page'] = $pageinfo;
  2191. $this->data ['date'] = $date;
  2192. $this->data ['list'] = $list;
  2193. $this->data ['memu'] = "invoice";
  2194. $this->data ['staff'] = $this->staff;
  2195. $this->data ['receiptMemu'] = 'invoice';
  2196. $this->render ( "/admin/invoiceMyUnAccountAchieve", $this->data );
  2197. }
  2198. function invoiceReceivablesAchieve() {
  2199. Doo::loadModel ( 'invoiceReceivables' );
  2200. $invoiceReceivables = new invoiceReceivables ();
  2201. Doo::loadClass ( 'XDeode' );
  2202. $XDeode = new XDeode ( 5 );
  2203. $sid = $XDeode->decode ( $_COOKIE ["staff"] );
  2204. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  2205. $page_size = 1;
  2206. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2207. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  2208. $get = "/" . $date;
  2209. $con = '';
  2210. if ($date == 'MONTHO')
  2211. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2212. elseif ($date == 'MONTHT')
  2213. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2214. elseif ($date == 'MONTHY')
  2215. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2216. if (! empty ( $MebSea )) {
  2217. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  2218. $get .= "/" . $MebSea;
  2219. }
  2220. $pageinfo ['page'] = array (
  2221. 'previous' => ''
  2222. );
  2223. $sql = " bindStatus=1 and receivablesStaff like '" . $sid . "_%' " . $con;
  2224. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  2225. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2226. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  2227. // print_r($pageinfo);
  2228. $this->data ['MebSeaEn'] = $MebSea;
  2229. $this->data ['MebSea'] = urlencode ( $MebSea );
  2230. $this->data ['get'] = $get;
  2231. $this->data ['page'] = $pageinfo;
  2232. $this->data ['list'] = $list;
  2233. $this->data ['date'] = $date;
  2234. $this->data ['memu'] = "invoice";
  2235. $this->data ['staff'] = $this->staff;
  2236. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  2237. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  2238. }
  2239. /**
  2240. * 收款解绑
  2241. */
  2242. function invoiceUnBundLing() {
  2243. $unBundKey = $this->get_args ( 'unBundKey' ) ? $this->get_args ( 'unBundKey' ) : '';
  2244. Doo::loadModel ( 'invoice' );
  2245. $invoice = new invoice ();
  2246. Doo::loadModel ( 'invoiceReceivables' );
  2247. $invoiceReceivables = new invoiceReceivables ();
  2248. Doo::loadModel ( 'invoiceOperationLog' );
  2249. $invoiceOperationLog = new invoiceOperationLog ();
  2250. Doo::loadModel ( 'invoiceROLog' );
  2251. $invoiceROLog = new invoiceROLog ();
  2252. Doo::loadModel ( 'invoiceStatistics' );
  2253. $invoiceStatistics = new invoiceStatistics ();
  2254. $irid = $invoice->authcode ( $unBundKey );
  2255. if (! empty ( $irid ) && ! is_numeric ( $irid ))
  2256. die ( 'illegal request' );
  2257. $irDetails = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2258. $invoiceDetails = $invoice->getInvoiceByIid ( $irDetails ['iid'] );
  2259. if (empty ( $irDetails ) || $irDetails ['bindStatus'] == 0 || $invoiceDetails ['untreadStatus'] == 2)
  2260. die ( 'illegal request' );
  2261. // 收款
  2262. $item = array (
  2263. 'irid' => $irDetails ['irid'],
  2264. 'bindStatus' => 0,
  2265. 'iid' => 0
  2266. );
  2267. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2268. // 收款操作日志
  2269. $item = array (
  2270. 'operation' => $this->staff [0] ['username'] . " 解绑 " . $irDetails ['receivablesSerial'],
  2271. 'date' => date ( "Y-m-d" ),
  2272. 'status' => 3,
  2273. 'img' => $this->staff [0] ['avatar'],
  2274. 'username' => $this->staff [0] ['username'],
  2275. 'uid' => $this->staff [0] ['sid'],
  2276. 'category' => $this->staff [0] ['category'],
  2277. 'irid' => $irid
  2278. );
  2279. $invoiceROLog->setInvoiceROLog ( $item );
  2280. // 扣除入账统计金额
  2281. $item = array (
  2282. 'date' => date ( 'Y-m-d', strtotime ( $irDetails ['bindDate'] ) ),
  2283. 'priceClass' => 3,
  2284. 'cid' => $invoiceDetails ['cid'],
  2285. 'staff' => $invoiceDetails ['sid'],
  2286. 'accountPrice' => - $irDetails ['receivablesPrice']
  2287. );
  2288. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  2289. // 发票解绑去收款ID
  2290. $iridString = $invoiceDetails ['irid'];
  2291. if (! empty ( $invoiceDetails ['irid'] )) {
  2292. $list = explode ( ',', $invoiceDetails ['irid'] );
  2293. foreach ( $list as $key => $value ) {
  2294. if ($value == $irDetails ['irid']) {
  2295. unset ( $list [$key] );
  2296. break;
  2297. }
  2298. }
  2299. $iridString = implode ( ",", $list );
  2300. }
  2301. $item = array (
  2302. 'iid' => $invoiceDetails ['iid'],
  2303. 'irid' => $iridString,
  2304. 'updateTime' => date ( "Y-m-d H:i:s" )
  2305. );
  2306. if ($invoiceDetails ['untreadStatus'] == 3)
  2307. $item += array (
  2308. 'untreadStatus' => 0
  2309. );
  2310. $invoice->setInvoiceByCondition ( $item );
  2311. $item = array (
  2312. 'date' => date ( "Y-m-d H:i:s" ),
  2313. 'operation' => '解绑 收款 ' . $irDetails ['receivablesSerial'],
  2314. 'status' => 11,
  2315. 'img' => $this->staff [0] ['avatar'],
  2316. 'username' => $this->staff [0] ['username'],
  2317. 'uid' => $this->staff [0] ['sid'],
  2318. 'category' => $this->staff [0] ['category'],
  2319. 'iid' => $invoiceDetails ['iid']
  2320. );
  2321. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2322. return "/invoiceReceivablesAS";
  2323. }
  2324. /**
  2325. * 发票管理
  2326. */
  2327. function invoiceAS() {
  2328. Doo::loadModel ( 'invoice' );
  2329. $invoice = new invoice ();
  2330. Doo::loadModel ( 'invoiceReceivables' );
  2331. $invoiceReceivables = new invoiceReceivables ();
  2332. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2333. $page_size = 18;
  2334. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2335. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  2336. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2337. $dateArr = explode ( ':', $date );
  2338. $D1 = '';
  2339. $D2 = '';
  2340. if (! empty ( $date )) {
  2341. $D1 = $dateArr [0];
  2342. $D2 = $dateArr [1];
  2343. }
  2344. $con = ' status=2 ';
  2345. if (! empty ( $D1 ) && ! empty ( $D2 ))
  2346. $con .= ' and date BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2347. if ($status == 'UNRECORD')
  2348. $con .= ' and printStatus=1 and untreadStatus=0';
  2349. elseif ($status == 'RECORD')
  2350. $con .= ' and printStatus=1 and untreadStatus=3';
  2351. elseif ($status == 'BOUNCED')
  2352. $con .= ' and untreadStatus=2';
  2353. elseif($status == 'All'){
  2354. $con .= ' and ( untreadStatus=2 or untreadStatus=0 or untreadStatus=3 )';
  2355. }
  2356. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2357. if (! empty ( $MebSea )) {
  2358. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" )';
  2359. }
  2360. $pageinfo ['page'] = array (
  2361. 'previous' => ''
  2362. );
  2363. $pageinfo = $this->get_page ( "CLD_invoice", $con, $page, $page_size, "invoiceAS", $get, "" );
  2364. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2365. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $con );
  2366. // print_r($list);
  2367. // foreach ($list as $key=>$value){
  2368. // $list[$key]['rpSum']=0;
  2369. // if (!empty($value['irid']))
  2370. // $list[$key]['rpSum']=$invoiceReceivables->getSumOfReceivablesPrice($value['irid']);
  2371. // }
  2372. $this->data ['MebSeaEn'] = $MebSea;
  2373. $this->data ['MebSea'] = urlencode ( $MebSea );
  2374. $this->data ['date'] = $date;
  2375. $this->data ['page'] = $pageinfo;
  2376. $this->data ['get'] = $get;
  2377. $this->data ['list'] = $list;
  2378. $this->data ['status'] = $status;
  2379. $this->data ['memu'] = "invoice";
  2380. $this->data ['staff'] = $this->staff;
  2381. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2382. $this->render ( "/admin/invoiceAS", $this->data );
  2383. }
  2384. /**
  2385. * 收款管理
  2386. */
  2387. function invoiceReceivablesAS() {
  2388. Doo::loadModel ( 'invoiceReceivables' );
  2389. $invoiceReceivables = new invoiceReceivables ();
  2390. $MebSea = $this->get_args ( 'MebSea' ) ? $this->get_args ( 'MebSea' ) : "";
  2391. $timeType = $this->get_args ( 'timeType' ) ? $this->get_args ( 'timeType' ) : "CREATE";
  2392. $page_size = 6;
  2393. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2394. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  2395. $date = $this->get_args ( 'date' ) ? $this->get_args ( 'date' ) : "";
  2396. $dateArr = explode ( ':', $date );
  2397. $D1 = '';
  2398. $D2 = '';
  2399. if (! empty ( $date )) {
  2400. $D1 = $dateArr [0];
  2401. $D2 = $dateArr [1];
  2402. }
  2403. $con = '1';
  2404. if (! empty ( $D1 ) && ! empty ( $D2 ))
  2405. $con .= ' and date BETWEEN "' . $D1 . '" AND "' . $D2 . '" ';
  2406. $descField = 'bindDate';
  2407. if ($timeType == 'CREATE')
  2408. $descField = 'date';
  2409. if ($status == 'Unclaimed')
  2410. $con .= ' and bindStatus=0';
  2411. elseif ($status == 'Credited')
  2412. $con .= ' and bindStatus=1';
  2413. elseif ($status == 'Claim')
  2414. $con .= ' and bindStatus=0 and receivablesStaff="PUBLIC"';
  2415. $get = "/" . $status . "?date=" . urlencode ( $date ) . "&MebSea=" . urlencode ( $MebSea );
  2416. if (! empty ( $MebSea )) {
  2417. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  2418. }
  2419. $pageinfo ['page'] = array (
  2420. 'previous' => ''
  2421. );
  2422. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $con, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  2423. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2424. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $con, 'desc', $descField );
  2425. // print_r($list);
  2426. $this->data ['timeType'] = $timeType;
  2427. $this->data ['MebSeaEn'] = $MebSea;
  2428. $this->data ['MebSea'] = urlencode ( $MebSea );
  2429. $this->data ['date'] = $date;
  2430. $this->data ['page'] = $pageinfo;
  2431. $this->data ['get'] = $get;
  2432. $this->data ['list'] = $list;
  2433. $this->data ['status'] = $status;
  2434. $this->data ['memu'] = "invoice";
  2435. $this->data ['staff'] = $this->staff;
  2436. $this->data ['receiptMemu'] = 'invoiceReceivables';
  2437. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  2438. }
  2439. function invoiceApprovalAchieve() {
  2440. Doo::loadModel ( 'invoice' );
  2441. $invoice = new invoice ();
  2442. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  2443. $page_size = 12;
  2444. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2445. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  2446. $get = "/" . $date;
  2447. $con = '';
  2448. if ($date == 'MONTHO')
  2449. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2450. elseif ($date == 'MONTHT')
  2451. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2452. elseif ($date == 'MONTHY')
  2453. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2454. if (! empty ( $MebSea )) {
  2455. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  2456. $get .= "/" . $MebSea;
  2457. }
  2458. $pageinfo ['page'] = array (
  2459. 'previous' => ''
  2460. );
  2461. $sql = '(status=1 or status=2 or status=3 or status=4) and processApprovals!=""' . $con; //echo $sql;
  2462. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  2463. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2464. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2465. // print_r($list);
  2466. $this->data ['MebSeaEn'] = $MebSea;
  2467. $this->data ['MebSea'] = urlencode ( $MebSea );
  2468. $this->data ['get'] = $get;
  2469. $this->data ['page'] = $pageinfo;
  2470. $this->data ['list'] = $list;
  2471. $this->data ['date'] = $date;
  2472. $this->data ['memu'] = "invoice";
  2473. $this->data ['staff'] = $this->staff;
  2474. $this->data ['receiptMemu'] = 'invoiceApproval';
  2475. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  2476. }
  2477. function invoiceTAchieve() {
  2478. Doo::loadModel ( 'invoice' );
  2479. $invoice = new invoice ();
  2480. Doo::loadClass ( 'XDeode' );
  2481. $XDeode = new XDeode ( 5 );
  2482. Doo::loadModel ( 'staff' );
  2483. $staff = new staff ();
  2484. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  2485. $page_size = 2;
  2486. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  2487. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  2488. $get = "/" . $date;
  2489. $con = '';
  2490. if ($date == 'MONTHO')
  2491. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  2492. elseif ($date == 'MONTHT')
  2493. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  2494. elseif ($date == 'MONTHY')
  2495. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  2496. if (! empty ( $MebSea )) {
  2497. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  2498. $get .= "/" . $MebSea;
  2499. }
  2500. $pageinfo ['page'] = array (
  2501. 'previous' => ''
  2502. );
  2503. $sql = "";
  2504. $action = "";
  2505. if ($this->ACTION == 'invoicePrintAchieve') {
  2506. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  2507. $action = "invoicePrintAchieve";
  2508. } elseif ($this->ACTION == 'invoicePostAchieve') {
  2509. // and untreadStatus=0
  2510. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  2511. $action = "invoicePostAchieve";
  2512. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {//printStatus=1 and
  2513. $sql = " untreadStatus=2 and status=2 " . $con;
  2514. $action = "invoiceUntreadAchieve";
  2515. }
  2516. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  2517. $limit = $pageinfo ['lower'] . ',' . $page_size;
  2518. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  2519. $this->data ['MebSeaEn'] = $MebSea;
  2520. $this->data ['MebSea'] = urlencode ( $MebSea );
  2521. $this->data ['get'] = $get;
  2522. $this->data ['page'] = $pageinfo;
  2523. $this->data ['date'] = $date;
  2524. $this->data ['memu'] = "invoice";
  2525. $this->data ['staff'] = $this->staff;
  2526. if ($this->ACTION == 'invoicePrintAchieve') {
  2527. foreach ( $list as $key => $value ) {
  2528. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  2529. $lastApprover = json_decode ( $value ['processApprovals'], true );
  2530. if (! empty ( $lastApprover )) {
  2531. $lastApproverKey = array_keys ( $lastApprover );
  2532. $lastApprover = end ( $lastApprover );
  2533. $staffDetail = $staff->getOne ( array (
  2534. 'where' => 'sid=' . end ( $lastApproverKey ),
  2535. 'asArray' => true
  2536. ) );
  2537. $lastApprover ['username'] = $staffDetail ['username'];
  2538. }
  2539. $list [$key] ['lastApprover'] = $lastApprover;
  2540. }
  2541. $this->data ['receiptMemu'] = 'invoicePrint';
  2542. $this->data ['list'] = $list;
  2543. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  2544. } elseif ($this->ACTION == 'invoicePostAchieve') {
  2545. Doo::loadModel ( 'express' );
  2546. $express = new express ();
  2547. $expressList = $express->getExpressByAll ();
  2548. $this->data ['expressList'] = $expressList;
  2549. $this->data ['receiptMemu'] = 'invoicePost';
  2550. $this->data ['list'] = $list;
  2551. $this->render ( "/admin/invoicePostAchieve", $this->data );
  2552. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  2553. $this->data ['receiptMemu'] = 'invoiceUntread';
  2554. $this->data ['list'] = $list;
  2555. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  2556. }
  2557. }
  2558. /**
  2559. *
  2560. * @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 ) ); }
  2561. */
  2562. /**
  2563. * 获取一条收款信息
  2564. */
  2565. function ajaxGetInvoiceReceivables() {
  2566. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  2567. Doo::loadModel ( 'invoiceReceivables' );
  2568. $invoiceReceivables = new invoiceReceivables ();
  2569. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  2570. echo json_encode ( array (
  2571. 'status' => 1,
  2572. 'detail' => $detail
  2573. ) );
  2574. }
  2575. /**
  2576. * 异步获取办事处用户
  2577. */
  2578. function ajaxGetStaffByCategory() {
  2579. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  2580. Doo::loadModel ( 'staff' );
  2581. $staff = new staff ();
  2582. if ($cid == "PUBLIC") {
  2583. echo json_encode ( array (
  2584. 'status' => 1,
  2585. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  2586. ) );
  2587. die ();
  2588. }
  2589. if (! is_numeric ( $cid )) {
  2590. echo json_encode ( array (
  2591. 'status' => 0,
  2592. 'msg' => 'illegal request'
  2593. ) );
  2594. die ();
  2595. }
  2596. $staffList = $staff->getStaffByCid ( $cid );
  2597. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  2598. foreach ( $staffList as $key => $value ) {
  2599. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  2600. }
  2601. echo json_encode ( array (
  2602. 'status' => 1,
  2603. 'html' => $html
  2604. ) );
  2605. }
  2606. /**
  2607. * 异步获取一条发票的邮寄信息
  2608. */
  2609. function ajaxGetInvoicePostDetail() {
  2610. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  2611. Doo::loadModel ( 'invoice' );
  2612. $invoice = new invoice ();
  2613. $iid = $invoice->authcode ( $iid );
  2614. Doo::loadModel ( 'express' );
  2615. $express = new express ();
  2616. $expressList = $express->getExpressByAll ();
  2617. if (! is_numeric ( $iid )) {
  2618. echo json_encode ( array (
  2619. 'status' => 0,
  2620. 'msg' => 'illegal request'
  2621. ) );
  2622. die ();
  2623. }
  2624. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  2625. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  2626. $html = "";
  2627. foreach ( $expressList as $key => $value ) {
  2628. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  2629. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  2630. else
  2631. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  2632. }
  2633. $invoiceDetail ['eaHtml'] = $html;
  2634. echo json_encode ( array (
  2635. 'status' => 1,
  2636. 'invoiceDetail' => $invoiceDetail
  2637. ) );
  2638. }
  2639. /**
  2640. *
  2641. * @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 ) ); }
  2642. */
  2643. /**
  2644. *
  2645. * @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 ) ); }
  2646. */
  2647. /**
  2648. * 我的收款中 选择哪个发票入账,进行金额判断
  2649. */
  2650. function ajaxCompareInvoicePrice() {
  2651. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  2652. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2653. Doo::loadModel ( 'invoice' );
  2654. $invoice = new invoice ();
  2655. Doo::loadModel ( 'invoiceReceivables' );
  2656. $invoiceReceivables = new invoiceReceivables ();
  2657. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  2658. $keyList = explode ( ';', $claimKey );
  2659. $receivablesPrice = 0;
  2660. foreach ( $keyList as $key => $value ) {
  2661. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  2662. $receivablesPrice += $detailM ['receivablesPrice'];
  2663. }
  2664. if ($receivablesPrice > $detail ['invoicePrice']) {
  2665. $price = $receivablesPrice - $detail ['invoicePrice'];
  2666. echo json_encode ( array (
  2667. 'status' => 1,
  2668. 'price' => $price
  2669. ) );
  2670. } else
  2671. echo json_encode ( array (
  2672. 'status' => 2
  2673. ) );
  2674. }
  2675. /**
  2676. * @ 获得与我有关收款数据 --需求变更 废弃 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 ) ); }
  2677. */
  2678. function ajaxGetInvoiceInfoByType() {
  2679. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  2680. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  2681. $loss = $this->get_args ( 'loss' ) ? $this->get_args ( 'loss' ) : false;
  2682. if (empty ( $serial )) {
  2683. echo json_encode ( array (
  2684. 'status' => 2,
  2685. 'msg' => 'illegal request'
  2686. ) );
  2687. die ();
  2688. }
  2689. if ($type == 'INVOICE') {
  2690. Doo::loadModel ( 'invoice' );
  2691. $invoice = new invoice ();
  2692. Doo::loadModel ( 'invoiceOperationLog' );
  2693. $invoiceOperationLog = new invoiceOperationLog ();
  2694. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  2695. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  2696. if (empty ( $detail ))
  2697. $html = '';
  2698. else {
  2699. $html = '
  2700. <div class="modal-dialog modal-lg">
  2701. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  2702. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  2703. <tr>
  2704. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  2705. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  2706. </tr>
  2707. <tr>
  2708. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  2709. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  2710. </tr>
  2711. <tr>
  2712. <th class="taC">发票备注</th><td colspan="3">' . $detail ['remark'] . '
  2713. </td>
  2714. </tr>
  2715. <tr>
  2716. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  2717. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  2718. </tr>
  2719. <tr>
  2720. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  2721. </tr></tbody></table>';
  2722. if ($detail ['invoiceType'] == 0)
  2723. $html .= '<table class="table table-bordered table-condensed"><tbody>
  2724. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  2725. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  2726. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  2727. </tr>';
  2728. else
  2729. $html .= '<table class="table table-bordered table-condensed"><tbody>
  2730. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  2731. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  2732. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  2733. ';
  2734. $html .= '<tr>
  2735. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  2736. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  2737. </tr>
  2738. <tr>
  2739. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  2740. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  2741. </tr></tbody></table>';
  2742. if ($detail ['doPost'] == 1)
  2743. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  2744. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  2745. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  2746. </tr><tr>
  2747. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  2748. </tr><tr>
  2749. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  2750. </tr></tbody></table>';
  2751. if (! empty ( $invoiceOperationLogList )) {
  2752. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  2753. foreach ( $invoiceOperationLogList as $key => $value ) {
  2754. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  2755. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  2756. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  2757. if ($value ['status'] == 2) {
  2758. $html .= '<span class="colGreen">同意</span>';
  2759. } elseif ($value ['status'] == 3) {
  2760. $html .= '<span class="colOrange">退回</span>';
  2761. } elseif ($value ['status'] == 5) {
  2762. $html .= '<span class="colGreen">打印</span>';
  2763. } elseif ($value ['status'] == 4) {
  2764. $html .= '<span class="colRed">终止</span>';
  2765. }
  2766. $html .= $value ['operation'] . '</p></blockquote>';
  2767. }
  2768. }
  2769. $html .= '</td></tr></tbody></table>';
  2770. }
  2771. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  2772. }
  2773. echo json_encode ( array (
  2774. 'status' => 1,
  2775. 'html' => $html
  2776. ) );
  2777. die ();
  2778. } elseif ($type == 'RECEIVABLES') {
  2779. Doo::loadModel ( 'invoiceReceivables' );
  2780. $invoiceReceivables = new invoiceReceivables ();
  2781. //
  2782. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial );
  2783. if (empty ( $detail ))
  2784. $html = '';
  2785. else {
  2786. $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">
  2787. <tbody><tr>
  2788. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  2789. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  2790. </tr><tr>
  2791. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  2792. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  2793. </tr>
  2794. <tr>
  2795. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  2796. <th class="taC">银行到帐</th><td>' . $detail ['receivablesDate'] . '</td>
  2797. </tr>
  2798. <tr>
  2799. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['bindDate'] . '</td>
  2800. </tr>
  2801. </tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  2802. }
  2803. echo json_encode ( array (
  2804. 'status' => 1,
  2805. 'html' => $html
  2806. ) );
  2807. die ();
  2808. } elseif ($type == 'IRTC') {
  2809. Doo::loadModel ( 'invoice' );
  2810. $invoice = new invoice ();
  2811. Doo::loadModel ( 'invoiceOperationLog' );
  2812. $invoiceOperationLog = new invoiceOperationLog ();
  2813. Doo::loadModel ( 'invoiceReceivables' );
  2814. $invoiceReceivables = new invoiceReceivables ();
  2815. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  2816. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  2817. if (empty ( $detail ))
  2818. $html = '';
  2819. else {
  2820. $receivablesPriceedHtml = '';
  2821. $receivablesPrice = $detail ['invoicePrice'];
  2822. if (! empty ( $detail ['irid'] )) {
  2823. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  2824. if (empty ( $irList ))
  2825. $irList [0] ['sumPrice'] = 0;
  2826. $balance = $detail ['invoicePrice'] - $irList [0] ['sumPrice'];
  2827. $receivablesPriceedHtml = '<table class="table table-bordered table-condensed"><tbody><tr>
  2828. <th class="taC">已入账金额</th><td><b class="colGreen" style="font-size:18px">¥' . $irList [0] ['sumPrice'] . '</b></td>
  2829. <th class="taC">剩余入账金额</th><td><b class="colRed" style="font-size:18px">¥' . $balance . '</b></td>
  2830. </tr></tbody></table>';
  2831. $receivablesPrice = $balance;
  2832. }
  2833. if ($loss)
  2834. $detail ['invoicePrice'] = - $detail ['invoicePrice'];
  2835. $html = $receivablesPriceedHtml . '
  2836. <table class="table table-bordered table-condensed"><tbody>
  2837. <tr>
  2838. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  2839. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  2840. </tr>
  2841. <tr>
  2842. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  2843. <th class="taC" width="150">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  2844. </tr>
  2845. <tr>
  2846. <th class="taC" width="150">发票备注</th><td colspan="3">' . $detail ['remark'] . '</td>
  2847. </tr>
  2848. <tr>
  2849. <th class="taC" width="150">数量</th><td><b>' . $detail ['invoiceQuantity'] . '</b></td>
  2850. <th class="taC">单价</th><td><b>¥' . $detail ['invoiceUnitPrice'] . '</b></td>
  2851. </tr>
  2852. <tr>
  2853. <th class="taC">开票金额</th><td colspan="3"><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  2854. </tr></tbody></table>';
  2855. if ($detail ['invoiceType'] == 0) {
  2856. $html .= '<table class="table table-bordered table-condensed"><tbody>
  2857. <tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  2858. <th class="taC" width="150">发票抬头</th><td >' . $detail ['invoiceTitle'] . '</td>
  2859. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td>
  2860. </tr>';
  2861. $receivablesMessage = $detail ['invoiceTitle'];
  2862. } else {
  2863. $html .= '<table class="table table-bordered table-condensed"><tbody>
  2864. <tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  2865. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  2866. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr>
  2867. ';
  2868. $receivablesMessage = $detail ['invoiceCompany'];
  2869. }
  2870. $html .= '<tr>
  2871. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  2872. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  2873. </tr>
  2874. <tr>
  2875. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  2876. <th class="taC">银行账号</th><td>' . $detail ['bank'] . '</td>
  2877. </tr></tbody></table>';
  2878. if ($detail ['doPost'] == 1)
  2879. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  2880. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  2881. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  2882. </tr><tr>
  2883. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  2884. </tr><tr>
  2885. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  2886. </tr></tbody></table>';
  2887. if (! empty ( $invoiceOperationLogList )) {
  2888. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  2889. foreach ( $invoiceOperationLogList as $key => $value ) {
  2890. if ($value ['status'] == 1 || $value ['status'] == 2 || $value ['status'] == 3 || $value ['status'] == 4) {
  2891. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  2892. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  2893. if ($value ['status'] == 2) {
  2894. $html .= '<span class="colGreen">同意</span>';
  2895. } elseif ($value ['status'] == 3) {
  2896. $html .= '<span class="colOrange">退回</span>';
  2897. } elseif ($value ['status'] == 5) {
  2898. $html .= '<span class="colGreen">打印</span>';
  2899. }
  2900. $html .= $value ['operation'] . '</p></blockquote>';
  2901. }
  2902. }
  2903. $html .= '</td></tr></tbody></table>';
  2904. }
  2905. }
  2906. echo json_encode ( array (
  2907. 'status' => 1,
  2908. 'html' => $html,
  2909. 'receivablesPrice' => $receivablesPrice,
  2910. 'receivablesMessage' => $receivablesMessage,
  2911. 'receivablesDate' => date ( "Y-m-d" ),
  2912. 'iidKey' => $serial
  2913. ) );
  2914. die ();
  2915. }
  2916. }
  2917. function ajaxGetInvoiceReceivablesByStaff() {
  2918. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  2919. if (empty ( $postData )) {
  2920. echo json_encode ( array (
  2921. 'status' => 2,
  2922. 'msg' => 'illegal request'
  2923. ) );
  2924. die ();
  2925. }
  2926. Doo::loadModel ( 'invoiceReceivables' );
  2927. $invoiceReceivables = new invoiceReceivables ();
  2928. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  2929. if (empty ( $detail )) {
  2930. echo json_encode ( array (
  2931. 'status' => 2,
  2932. 'msg' => 'illegal request'
  2933. ) );
  2934. die ();
  2935. }
  2936. Doo::loadModel ( 'L_category' );
  2937. $lCategory = new L_category ();
  2938. Doo::loadModel ( 'staff' );
  2939. $staff = new staff ();
  2940. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  2941. $category = $lCategory->getCategory ();
  2942. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  2943. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  2944. foreach ( $category as $key => $value ) {
  2945. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  2946. if ($value ['cid'] == $detail ['cid'])
  2947. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  2948. }
  2949. foreach ( $staffList as $key => $value ) {
  2950. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  2951. if ($value ['sid'] == $detail ['sid'])
  2952. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  2953. }
  2954. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  2955. echo json_encode ( array (
  2956. 'status' => 1,
  2957. 'categoryHtml' => $categoryHtml,
  2958. 'staffHtml' => $staffHtml,
  2959. 'rbankHtml' => $rbankHtml,
  2960. 'detail' => $detail
  2961. ) );
  2962. }
  2963. function ajaxGetInvoiceReceivablesByIrid() {
  2964. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  2965. if (empty ( $irid )) {
  2966. echo json_encode ( array (
  2967. 'status' => 2,
  2968. 'msg' => 'illegal request'
  2969. ) );
  2970. die ();
  2971. }
  2972. Doo::loadModel ( 'invoiceReceivables' );
  2973. $invoiceReceivables = new invoiceReceivables ();
  2974. Doo::loadModel ( 'invoice' );
  2975. $invoice = new invoice ();
  2976. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid ); // 入账完成 待定 and postStatus=1
  2977. $invoiceDetail = $invoice->getInvoiceByTitle ( $detail ['recepitTitleMark'], 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 " ); //
  2978. $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>
  2979. <tr>
  2980. <td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  2981. <td>' . $detail ['receivablesMessage'] . '</td>
  2982. <td>' . $detail ['receivablesBank'] . '<br>' . $detail ['receivablesDate'] . '</td>
  2983. <td>' . $detail ['title'] . '-' . $detail ['username'] . '<br>' . $detail ['confirmTime'] . '</td>
  2984. <td>' . $detail ['recepitTitleMark'] . '</td>
  2985. </tr></tbody></table>';
  2986. $isInvoice = false;
  2987. $invoiceHtml = '';
  2988. if (empty ( $invoiceDetail )) {
  2989. $isInvoice = true;
  2990. } else {
  2991. $invoiceHtml = '<table class="table table-bordered table-condensed">
  2992. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  2993. if (! empty ( $invoiceDetail ['invoiceType'] )) {
  2994. $invoiceHtml .= '<td>' . $invoiceDetail ['invoiceCompany'] . '</td>';
  2995. } else {
  2996. $invoiceHtml .= '<td>' . $invoiceDetail ['invoiceTitle'] . '</td>';
  2997. }
  2998. if (! empty ( $invoiceDetail ['invoiceType'] )) {
  2999. $invoiceHtml .= '<td>' . $invoiceDetail ['invoicePrice'] . '专</td>';
  3000. } else {
  3001. $invoiceHtml .= '<td>' . $invoiceDetail ['invoicePrice'] . '</td>';
  3002. }
  3003. $invoiceHtml .= '
  3004. <td>' . $invoiceDetail ['categoryName'] . $invoiceDetail ['userName'] . ' ' . $invoiceDetail ['date'] . '</td>
  3005. <td>' . $invoiceDetail ['printer'] . ' ' . $invoiceDetail ['printTime'] . '</td>
  3006. <td>' . $invoiceDetail ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $invoiceDetail ['iidKeyXD'] . '" data-ikey="' . $invoiceDetail ['iidKey'] . '" href="javascript:void(0)">入账</a></td>
  3007. </tr>
  3008. ';
  3009. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $invoiceDetail ['irid'] );
  3010. $balance = $invoiceDetail ['invoicePrice'] - $irList [0] ['sumPrice'];
  3011. $priceString = '';
  3012. if ($balance < $detail ['receivablesPrice']) {
  3013. $priceString = '收款金额超过开票金额,';
  3014. }
  3015. if ($balance > $detail ['receivablesPrice']) {
  3016. $priceString = '收款金额低于开票金额,';
  3017. }
  3018. $invoiceHtml .= '</tbody></table>
  3019. <script>
  3020. $(\'a[bind-receivables="ir' . $invoiceDetail ['iidKeyXD'] . '"]\').click(function() {
  3021. $("input[name=\'invoiceKey\']").val("' . $invoiceDetail ['iidKey'] . '");
  3022. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  3023. if(invoiceKey==""){
  3024. alert("入账错误,请重新刷新页面");
  3025. return false;
  3026. }
  3027. if(window.confirm("' . $priceString . '确定入账吗?")){
  3028. $("#IBR").submit();
  3029. }else{
  3030. return false;
  3031. }
  3032. });
  3033. </script>
  3034. ';
  3035. }
  3036. echo json_encode ( array (
  3037. 'status' => 1,
  3038. 'irkey' => $detail ['iridEn'],
  3039. 'receivablesHtml' => $receivablesHtml,
  3040. 'isInvoice' => $isInvoice,
  3041. 'invoiceHtml' => $invoiceHtml
  3042. ) );
  3043. }
  3044. function ajaxGetInvoiceReceivablesByTitle() {
  3045. $title = $this->get_args ( 'title' ) ? $this->get_args ( 'title' ) : "";
  3046. if (empty ( $title )) {
  3047. echo json_encode ( array (
  3048. 'status' => 2,
  3049. 'msg' => 'illegal request'
  3050. ) );
  3051. die ();
  3052. }
  3053. Doo::loadModel ( 'invoice' );
  3054. $invoice = new invoice ();
  3055. $invoiceDetail = $invoice->getInvoiceByTitle ( $title, 'EXACTLY', " and status=2 and printStatus=1 and untreadStatus=0 " );
  3056. $invoiceHtml = '';
  3057. if (! empty ( $invoiceDetail )) {
  3058. $invoiceHtml = '<table class="table table-bordered table-condensed">
  3059. <thead><tr><th>开票单位(抬头)</th><th>开票金额</th><th>提交开票</th><th>出票</th><th>开票流水号</th><th width="80">入账</th></tr></thead><tbody><tr>';
  3060. if (! empty ( $invoiceDetail ['invoiceType'] )) {
  3061. $invoiceHtml .= '<td>' . $invoiceDetail ['invoiceCompany'] . '</td>';
  3062. } else {
  3063. $invoiceHtml .= '<td>' . $invoiceDetail ['invoiceTitle'] . '</td>';
  3064. }
  3065. if (! empty ( $invoiceDetail ['invoiceType'] )) {
  3066. $invoiceHtml .= '<td>' . $invoiceDetail ['invoicePrice'] . '专</td>';
  3067. } else {
  3068. $invoiceHtml .= '<td>' . $invoiceDetail ['invoicePrice'] . '</td>';
  3069. }
  3070. $invoiceHtml .= '
  3071. <td>' . $invoiceDetail ['categoryName'] . $invoiceDetail ['userName'] . ' ' . $invoiceDetail ['date'] . '</td>
  3072. <td>' . $invoiceDetail ['printer'] . ' ' . $invoiceDetail ['printTime'] . '</td>
  3073. <td>' . $invoiceDetail ['invoiceSerial'] . '</td><td><a class="button btn-block" bind-receivables="ir' . $invoiceDetail ['iidKeyXD'] . '" data-ikey="' . $invoiceDetail ['iidKey'] . '" href="#">入账</a></td>
  3074. </tr>
  3075. ';
  3076. $invoiceHtml .= '</tbody></table>
  3077. <script>
  3078. $(\'a[bind-receivables="ir' . $invoiceDetail ['iidKeyXD'] . '"]\').click(function() {
  3079. $("input[name=\'invoiceKey\']").val("' . $invoiceDetail ['iidKey'] . '");
  3080. var invoiceKey=$("input[name=\'invoiceKey\']").val();
  3081. if(invoiceKey==""){
  3082. alert("入账错误,请重新刷新页面");
  3083. return false;
  3084. }
  3085. if(window.confirm("确定入账吗?")){
  3086. $("#IBR").submit();
  3087. }else{
  3088. return false;
  3089. }
  3090. });
  3091. </script>
  3092. ';
  3093. }
  3094. echo json_encode ( array (
  3095. 'status' => 1,
  3096. 'invoiceHtml' => $invoiceHtml
  3097. ) );
  3098. }
  3099. function ajaxInvoicePushNotice() {
  3100. Doo::loadModel ( 'invoice' );
  3101. $invoice = new invoice ();
  3102. $approval = $invoice->getOne ( array (
  3103. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  3104. 'desc' => 'iid',
  3105. 'asArray' => true
  3106. ) );
  3107. $isNotice = false;
  3108. if (! empty ( $approval ))
  3109. $isNotice = true;
  3110. $response = array (
  3111. 'error' => 0,
  3112. 'isNotice' => $isNotice
  3113. );
  3114. echo json_encode ( $response );
  3115. exit ();
  3116. }
  3117. public function ajaxCheckInvoiceNoUniqueness() {
  3118. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  3119. Doo::loadModel ( 'invoice' );
  3120. $invoice = new invoice ();
  3121. if (! empty ( $invoiceNo )) {
  3122. $info = $invoice->getOne ( array (
  3123. 'where' => "invoiceNo = '" . $invoiceNo . "'",
  3124. 'asArray' => TRUE
  3125. ) );
  3126. if (! empty ( $info )) {
  3127. echo json_encode ( array (
  3128. 'error' => '发票号已存在'
  3129. ) );
  3130. die ();
  3131. } else
  3132. echo json_encode ( array (
  3133. 'ok' => '可以使用!'
  3134. ) );
  3135. die ();
  3136. }
  3137. }
  3138. function ajaxCheckInvoicePrice() {
  3139. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) && is_numeric ( $this->get_args ( 'receivablesPrice' ) ) ? $this->get_args ( 'receivablesPrice' ) : "";
  3140. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  3141. Doo::loadModel ( 'invoice' );
  3142. $invoice = new invoice ();
  3143. Doo::loadModel ( 'invoiceReceivables' );
  3144. $invoiceReceivables = new invoiceReceivables ();
  3145. Doo::loadClass ( 'XDeode' );
  3146. $XDeode = new XDeode ( 5 );
  3147. if (! empty ( $receivablesPrice ) && ! empty ( $iidKey )) {
  3148. $iidKey = $XDeode->decode ( $iidKey );
  3149. $info = $invoice->getInvoiceByIid ( $iidKey );
  3150. $irList = $invoiceReceivables->getInvoiceReceivablesInIridString ( $info ['irid'] );
  3151. if (empty ( $irList ))
  3152. $irList [0] ['sumPrice'] = 0;
  3153. $balance = $info ['invoicePrice'] - $irList [0] ['sumPrice'];
  3154. if ($balance < $receivablesPrice) {
  3155. echo json_encode ( array (
  3156. 'error' => '收款金额超过开票金额。'
  3157. ) );
  3158. die ();
  3159. }
  3160. if ($balance > $receivablesPrice) {
  3161. echo json_encode ( array (
  3162. 'error' => '收款金额低于开票金额。'
  3163. ) );
  3164. die ();
  3165. }
  3166. }
  3167. }
  3168. /**
  3169. * 旧输入导入
  3170. */
  3171. function importInvoice() {
  3172. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  3173. $data ['emsg'] = "";
  3174. if ($emsg != "")
  3175. $data ['emsg'] = "请填写完整的数据";
  3176. $data ['time'] = time ();
  3177. $this->render ( "/admin/invoiceImport", $data );
  3178. }
  3179. function uploadInvoice() {
  3180. // move_uploaded_file($_FILES['Filedata']['tmp_name'], "/upload/".$_FILES['Filedata']['name']);
  3181. if (isset ( $_FILES ['Filedata'] ['name'] )) {
  3182. $file = $_FILES ['Filedata'] ['tmp_name'];
  3183. $error = false;
  3184. if (! is_uploaded_file ( $file )) {
  3185. $error = '400 Bad Request';
  3186. }
  3187. if ($error) {
  3188. header ( 'HTTP/1.0 ' . $error );
  3189. die ( 'Error ' . $error );
  3190. } else {
  3191. include (DOO::conf ()->SITE_PATH . 'protected/plugin/io.han.php');
  3192. $this->IoHandler = new IoHandler ();
  3193. $pics = explode ( '.', $_FILES ['Filedata'] ['name'] );
  3194. // $filedir=$_POST['time'];
  3195. // 调用定义物理路径
  3196. $t = DOO::conf ()->SITE_PATH . "upload/invoice/";
  3197. $this->IoHandler->MakeDir ( $t );
  3198. $filename = $this->_GetFileEXT ( $_FILES ['Filedata'] ['name'] );
  3199. if ($filename != 'xlsx')
  3200. return "";
  3201. // $upload_dir = $t."/".time().rand(10,100).".".$filename;
  3202. $upload_file = iconv ( "UTF-8", "GB2312", $_FILES ["Filedata"] ["name"] );
  3203. $upload_dir = $t . "/" . $upload_file;
  3204. $k = move_uploaded_file ( $file, $upload_dir );
  3205. if ($k) {
  3206. $m = round ( $_FILES ['Filedata'] ['size'] / 1024 / 1024, 2 );
  3207. echo $pics [0] . "." . $filename . "#" . $m . "#" . $_FILES ['Filedata'] ['size'];
  3208. }
  3209. }
  3210. }
  3211. }
  3212. function importInvoiceDo() {
  3213. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  3214. if ($path != "") {
  3215. Doo::loadModel ( 'invoice' );
  3216. Doo::loadModel ( 'staff' );
  3217. $staff = new staff ();
  3218. Doo::loadModel ( 'invoiceStatistics' );
  3219. echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  3220. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . $path );
  3221. // print_r ( $exlArray );
  3222. // die ();
  3223. // echo json_encode($exlArray);die;
  3224. foreach ( $exlArray as $key => $value ) {
  3225. // 开票
  3226. $invoice = new invoice ();
  3227. $invoice->invoiceNo = $value ['invoiceNo'];
  3228. $invoice->invoiceType = 0;
  3229. if ($value ['invoiceNo'] == '专')
  3230. $invoice->invoiceType = 1;
  3231. $invoice->invoicePrice = $value ['invoicePrice'];
  3232. $invoice->invoiceTitle = $value ['invoiceTitle'];
  3233. if ($value ['invoiceNo'] == '专')
  3234. $invoice->invoiceCompany = $value ['invoiceTitle'];
  3235. $invoice->userName = $value ['userName'];
  3236. $sDetail = $staff->getStaffByName ( $value ['userName'] );
  3237. $invoice->sid = $sDetail ['sid'];
  3238. $invoice->cid = $sDetail ['cid'];
  3239. $invoice->categoryName = $sDetail ['category'];
  3240. $invoice->invoiceElement = $value ['invoiceElement'];
  3241. $invoice->remark = $value ['remark'];
  3242. $invoice->date = $value ['date'];
  3243. $invoice->printStatus = 1;
  3244. $invoice->status = 2;
  3245. $invoice->postStatus = 1;
  3246. $invoice->untreadStatus = 0;
  3247. $invoice->invoiceSerial = "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3248. $invoice->insert ();
  3249. // 汇总
  3250. $invoiceStatistics = new invoiceStatistics ();
  3251. // 扣除入账统计金额
  3252. $item = array (
  3253. 'date' => $value ['date'],
  3254. 'priceClass' => 1,
  3255. 'cid' => $sDetail ['cid'],
  3256. 'staff' => $sDetail ['sid'],
  3257. 'invoicePrice' => $value ['invoicePrice']
  3258. );
  3259. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3260. }
  3261. return '/importInvoice?count=' . count ( $exlArray );
  3262. // return "/keyonline";
  3263. }
  3264. echo 'no file';
  3265. }
  3266. function importInvoiceReceivables() {
  3267. $emsg = isset ( $this->params ['emsg'] ) ? $this->params ['emsg'] : "";
  3268. $data ['emsg'] = "";
  3269. if ($emsg != "")
  3270. $data ['emsg'] = "请填写完整的数据";
  3271. $data ['time'] = time ();
  3272. $this->render ( "/admin/invoiceReceivablesImport", $data );
  3273. }
  3274. // 导入入账数据
  3275. function importInvoiceReceivablesDo() {
  3276. $path = $this->get_args ( 'path' ) ? $this->get_args ( 'path' ) : "";
  3277. include Doo::conf ()->BASE_PATH . 'diagnostic/debug.php';
  3278. if ($path != "") {
  3279. Doo::loadModel ( 'invoiceReceivables' );
  3280. Doo::loadModel ( 'invoice' );
  3281. Doo::loadModel ( 'staff' );
  3282. $staff = new staff ();
  3283. Doo::loadModel ( 'invoiceStatistics' );
  3284. // echo DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path );
  3285. $exlArray = $this->_format_excel_to_array ( DOO::conf ()->SITE_PATH . "upload/invoice/" . iconv ( "UTF-8", "GB2312", $path ), 'invoiceReceivables' );
  3286. // print_r ( $exlArray );
  3287. // die ();
  3288. // echo json_encode($exlArray);die;
  3289. foreach ( $exlArray as $key => $value ) {
  3290. // 收款
  3291. $invoiceReceivables = new invoiceReceivables ();
  3292. $invoice = new invoice ();
  3293. $invoiceReceivables->bindStatus = 1;
  3294. $invoiceReceivables->receivablesPrice = $value ['receivablesPrice'];
  3295. $invoiceReceivables->receivablesMessage = $value ['receivablesMessage'];
  3296. $invoiceReceivables->receivablesBank = $value ['receivablesBank'];
  3297. $invoiceReceivables->receivablesDate = $value ['receivablesDate'];
  3298. $sDetail = $staff->getStaffByName ( $value ['receivablesStaff'] );
  3299. $invoiceReceivables->receivablesCategory = $sDetail ['cid'] . ':' . $sDetail ['category'];
  3300. $invoiceReceivables->receivablesStaff = $sDetail ['sid'] . '-' . $sDetail ['username'];
  3301. $invoiceReceivables->receivablesSerial = "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 );
  3302. $invoiceReceivables->sourcePrice = $value ['sourcePrice'];
  3303. $iDetail = $invoice->getInvoiceByInvoiceNo ( $value ['invoiceNo'] );
  3304. $invoiceReceivables->iid = $iDetail ['iid'];
  3305. $irid = $invoiceReceivables->insert ();
  3306. // 发票绑定收款
  3307. $detail = $iDetail;
  3308. $iridString = "";
  3309. if (empty ( $detail ['irid'] ))
  3310. $iridString = $irid;
  3311. else
  3312. $iridString = $detail ['irid'] . ',' . $irid;
  3313. $item = array (
  3314. 'irid' => $iridString,
  3315. 'iid' => $detail ['iid']
  3316. );
  3317. $invoice->setInvoiceByCondition ( $item );
  3318. // 汇总
  3319. $invoiceStatistics = new invoiceStatistics ();
  3320. // 扣除入账统计金额
  3321. $item = array (
  3322. 'date' => $value ['receivablesDate'],
  3323. 'priceClass' => 3,
  3324. 'cid' => $sDetail ['cid'],
  3325. 'staff' => $sDetail ['sid'],
  3326. 'irid' => $irid,
  3327. 'accountPrice' => $value ['receivablesPrice']
  3328. );
  3329. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  3330. }
  3331. return '/importInvoiceReceivables?count=' . count ( $exlArray );
  3332. echo 'data count ' . count ( $exlArray );
  3333. die ();
  3334. // return "/keyonline";
  3335. }
  3336. echo 'no file';
  3337. }
  3338. /**
  3339. * 格式化excel文件为数组
  3340. * @param unknown_type $file_url
  3341. * @param unknown_type $mcid
  3342. */
  3343. function _format_excel_to_array($file_url = "", $sType = "") {
  3344. if (! file_exists ( $file_url )) {
  3345. return array ();
  3346. }
  3347. Doo::loadClass ( 'PHPExcel' );
  3348. $PHPExcel = new PHPExcel ();
  3349. $PHPReader = new PHPExcel_Reader_Excel2007 ();
  3350. if (! $PHPReader->canRead ( $file_url )) {
  3351. $PHPReader = new PHPExcel_Reader_Excel5 ();
  3352. if (! $PHPReader->canRead ( $file_url )) {
  3353. echo 'no Excel';
  3354. return;
  3355. }
  3356. }
  3357. $PHPExcel = $PHPReader->load ( $file_url );
  3358. /* * 读取excel文件中的第一个工作表 */
  3359. $currentSheet = $PHPExcel->getSheet ( 0 );
  3360. /* * 取得最大的列号 */
  3361. $allColumn = $currentSheet->getHighestColumn ();
  3362. /* * 取得一共有多少行 */
  3363. $allRow = $currentSheet->getHighestRow ();
  3364. $excel_array = array ();
  3365. $conk = 2;
  3366. for($currentRow = $conk; $currentRow <= $allRow; $currentRow ++) {
  3367. $excel_column = array ();
  3368. // 后期改进
  3369. if ($allColumn == 'AM')
  3370. $allColumn = 'Z';
  3371. /* * 从第A列开始输出 */
  3372. for($currentColumn = 'A'; $currentColumn <= $allColumn; $currentColumn ++) {
  3373. $val = $currentSheet->getCellByColumnAndRow ( ord ( $currentColumn ) - 65, $currentRow )->getValue ();
  3374. if ($val instanceof PHPExcel_RichText)
  3375. $val = $val->__toString ();
  3376. /* * ord()将字符转为十进制数 iconv ( 'utf-8', 'gb2312', */
  3377. // $val = "'" . addslashes ( $val ) . "'";
  3378. if ($sType == 'invoiceReceivables') {
  3379. if ($currentColumn == 'A')
  3380. $excel_column ['invoiceNo'] = $val;
  3381. elseif ($currentColumn == 'B')
  3382. $excel_column ['receivablesPrice'] = $val;
  3383. elseif ($currentColumn == 'C') {
  3384. $excel_column ['receivablesMessage'] = $val;
  3385. } elseif ($currentColumn == 'D') {
  3386. $excel_column ['receivablesBank'] = $val;
  3387. } elseif ($currentColumn == 'E') {
  3388. $excel_column ['receivablesDate'] = $this->excelTime ( $val );
  3389. } elseif ($currentColumn == 'F') {
  3390. $excel_column ['receivablesStaff'] = $val;
  3391. } elseif ($currentColumn == 'G') {
  3392. $excel_column ['sourcePrice'] = $val;
  3393. }
  3394. } else {
  3395. if ($currentColumn == 'A')
  3396. $excel_column ['invoiceNo'] = $val;
  3397. elseif ($currentColumn == 'B')
  3398. $excel_column ['invoiceType'] = $val;
  3399. elseif ($currentColumn == 'C') {
  3400. $excel_column ['invoicePrice'] = $val;
  3401. } elseif ($currentColumn == 'D') {
  3402. $excel_column ['invoiceTitle'] = $val;
  3403. } elseif ($currentColumn == 'E') {
  3404. $excel_column ['userName'] = $val;
  3405. } elseif ($currentColumn == 'F') {
  3406. $excel_column ['categoryName'] = $val;
  3407. } elseif ($currentColumn == 'G') {
  3408. $excel_column ['invoiceElement'] = $val;
  3409. } elseif ($currentColumn == 'H') {
  3410. $excel_column ['remark'] = $val;
  3411. } elseif ($currentColumn == 'I') {
  3412. $excel_column ['date'] = $this->excelTime ( $val );
  3413. }
  3414. }
  3415. }
  3416. array_push ( $excel_array, $excel_column );
  3417. }
  3418. return $excel_array;
  3419. }
  3420. function excelTime($date, $time = false) {
  3421. if (function_exists ( 'GregorianToJD' )) {
  3422. if (is_numeric ( $date )) {
  3423. $jd = GregorianToJD ( 1, 1, 1970 );
  3424. $gregorian = JDToGregorian ( $jd + intval ( $date ) - 25569 );
  3425. $date = explode ( '/', $gregorian );
  3426. $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" : '');
  3427. return $date_str;
  3428. }
  3429. } else {
  3430. $date = $date > 25568 ? $date + 1 : 25569;
  3431. /* There was a bug if Converting date before 1-1-1970 (tstamp 0) */
  3432. $ofs = (70 * 365 + 17 + 2) * 86400;
  3433. $date = date ( "Y-m-d", ($date * 86400) - $ofs ) . ($time ? " 00:00:00" : '');
  3434. }
  3435. return $date;
  3436. }
  3437. /**
  3438. * 旧输入导入
  3439. */
  3440. function _GetFileEXT($filename) {
  3441. $pics = explode ( '.', $filename );
  3442. $num = count ( $pics );
  3443. return $pics [$num - 1];
  3444. }
  3445. function showCache($path = "") {
  3446. // if (file_exists ( $path )) {
  3447. // $htm = file_get_contents ( $path );
  3448. // } else {
  3449. Doo::loadModel ( 'invoiceStatistics' );
  3450. $invoiceStatistics = new invoiceStatistics ();
  3451. $isBriefly = $invoiceStatistics->getBrieflyStatistics ();
  3452. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  3453. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  3454. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  3455. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  3456. /*
  3457. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  3458. */
  3459. file_put_contents ( $path, $htm, FILE_APPEND );
  3460. // }
  3461. return $htm;
  3462. }
  3463. /**
  3464. * 获取get或者POST值
  3465. *
  3466. * @param string $name 属性名称
  3467. * @return fixed 值
  3468. */
  3469. function get_args($name) {
  3470. if (isset ( $_GET [$name] )) {
  3471. if (is_array ( $_GET [$name] ))
  3472. return $_GET [$name];
  3473. else
  3474. return addslashes ( $_GET [$name] );
  3475. } elseif (isset ( $_POST [$name] )) {
  3476. if (is_array ( $_POST [$name] ))
  3477. return $_POST [$name];
  3478. else
  3479. return addslashes ( $_POST [$name] );
  3480. } else
  3481. return false;
  3482. }
  3483. function SafeFilter(&$arr) {
  3484. $ra = Array (
  3485. '/([\x00-\x08,\x0b-\x0c,\x0e-\x19])/',
  3486. '/script/',
  3487. '/javascript/',
  3488. '/vbscript/',
  3489. '/expression/',
  3490. '/applet/',
  3491. '/meta/',
  3492. '/xml/',
  3493. '/blink/',
  3494. '/link/',
  3495. '/style/',
  3496. '/embed/',
  3497. '/object/',
  3498. '/frame/',
  3499. '/layer/',
  3500. '/title/',
  3501. '/bgsound/',
  3502. '/base/',
  3503. '/onload/',
  3504. '/onunload/',
  3505. '/onchange/',
  3506. '/onsubmit/',
  3507. '/onreset/',
  3508. '/onselect/',
  3509. '/onblur/',
  3510. '/onfocus/',
  3511. '/onabort/',
  3512. '/onkeydown/',
  3513. '/onkeypress/',
  3514. '/onkeyup/',
  3515. '/onclick/',
  3516. '/ondblclick/',
  3517. '/onmousedown/',
  3518. '/onmousemove/',
  3519. '/onmouseout/',
  3520. '/onmouseover/',
  3521. '/onmouseup/',
  3522. '/onunload/'
  3523. );
  3524. if (is_array ( $arr )) {
  3525. foreach ( $arr as $key => $value ) {
  3526. if (! is_array ( $value )) {
  3527. if (! get_magic_quotes_gpc ()) // 不对magic_quotes_gpc转义过的字符使用addslashes(),避免双重转义。
  3528. {
  3529. $value = addslashes ( $value ); // 给单引号(')、双引号(")、反斜线(\)与 NUL(NULL 字符)加上反斜线转义
  3530. }
  3531. $value = preg_replace ( $ra, '', $value ); // 删除非打印字符,粗暴式过滤xss可疑字符串
  3532. $arr [$key] = htmlentities ( strip_tags ( $value ) ); // 去除 HTML 和 PHP 标记并转换为 HTML 实体
  3533. } else {
  3534. SafeFilter ( $arr [$key] );
  3535. }
  3536. }
  3537. }
  3538. }
  3539. /**
  3540. * Escape String
  3541. *
  3542. * @access public
  3543. * @param string
  3544. * @param bool whether or not the string will be used in a LIKE condition
  3545. * @return string
  3546. */
  3547. function escape_str($str, $like = FALSE) {
  3548. if (is_array ( $str )) {
  3549. foreach ( $str as $key => $val ) {
  3550. $str [$key] = $this->escape_str ( $val, $like );
  3551. }
  3552. return $str;
  3553. }
  3554. var_dump ( Doo::db ()->getDbObject () );
  3555. die ();
  3556. if (function_exists ( 'mysql_real_escape_string' ) and is_resource ( Doo::db ()->getDbObject () )) { // Doo::db ()->getDbObject()
  3557. $str = mysql_real_escape_string ( $str, Doo::db ()->getDbObject () );
  3558. } elseif (function_exists ( 'mysql_escape_string' )) {
  3559. $str = mysql_escape_string ( $str );
  3560. } else {
  3561. $str = addslashes ( $str );
  3562. }
  3563. // escape LIKE condition wildcards
  3564. if ($like === TRUE) {
  3565. $str = str_replace ( array (
  3566. '%',
  3567. '_'
  3568. ), array (
  3569. '\\%',
  3570. '\\_'
  3571. ), $str );
  3572. }
  3573. return $str;
  3574. }
  3575. /**
  3576. * 获得分页数据
  3577. * @param unknown_type $table
  3578. * @param unknown_type $condition
  3579. * @param unknown_type $on_page
  3580. * @param unknown_type $page_size
  3581. */
  3582. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  3583. $page_c = "";
  3584. $page ['previous'] = $this->get_previous ( $on_page );
  3585. $page ['on_page'] = $on_page;
  3586. $total_count = $this->get_table_count ( $table, $condition );
  3587. $total = intval ( $total_count / $page_size );
  3588. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  3589. $page ['total_data'] = $total_count;
  3590. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  3591. $i = 1;
  3592. $page_max = 1;
  3593. $page_width = 3;
  3594. if ($on_page >= $page_width) {
  3595. $page_max = intval ( $on_page / $page_width ) + 1;
  3596. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  3597. }
  3598. for(; $i <= $page ['total_page']; $i ++) {
  3599. if ($i == $on_page)
  3600. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  3601. else
  3602. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  3603. if ($i == ($page_width * $page_max))
  3604. break;
  3605. }
  3606. $page ['page'] = $page_c;
  3607. $page ['lower'] = (-- $on_page) * $page_size;
  3608. return $page;
  3609. }
  3610. /**
  3611. * 获取上一页
  3612. * @param unknown_type $on_page
  3613. */
  3614. function get_previous($on_page = 1) {
  3615. return $on_page != 0 ? $on_page - 1 : $on_page;
  3616. }
  3617. /**
  3618. * 获取总页数
  3619. * @param unknown_type $table
  3620. * @param unknown_type $condition
  3621. */
  3622. public function get_table_count($table = "", $condition = "") {
  3623. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  3624. $sql = "select count(*) as count from " . $table . " where " . $condition;
  3625. // echo $sql;die;
  3626. $query = Doo::db ()->query ( $sql );
  3627. $result = $query->fetch ();
  3628. return $result ['count'];
  3629. }
  3630. function isInvoiceNew($type = "GLOBAL") {
  3631. Doo::loadModel ( 'invoice' );
  3632. $invoice = new invoice ();
  3633. Doo::loadModel ( 'invoiceReceivables' );
  3634. $invoiceReceivables = new invoiceReceivables ();
  3635. Doo::loadModel ( 'staff' );
  3636. $staff = new staff ();
  3637. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  3638. // 我的发票待处理
  3639. $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  3640. 'where' => "(status=3 or status=4) and isDelete=0 and sid=" . $st [0] ['sid'],
  3641. 'desc' => 'iid',
  3642. 'asArray' => TRUE
  3643. ) );
  3644. // 我的收款待入账
  3645. /*
  3646. * $myClaim = $invoiceReceivables->getOne ( array ( 'where' => " receivablesStaff like '" . $st [0] ['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0", 'desc' => 'irid', 'asArray' => TRUE ) );
  3647. */
  3648. // 发票审批
  3649. $approval = $invoice->getOne ( array (
  3650. 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
  3651. 'desc' => 'iid',
  3652. 'asArray' => true
  3653. ) );
  3654. // 发票邮寄
  3655. $post = $invoice->getOne ( array (
  3656. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  3657. 'asArray' => TRUE
  3658. ) );
  3659. // 发票打印
  3660. $print = $invoice->getOne ( array (
  3661. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
  3662. 'desc' => 'iid',
  3663. 'asArray' => TRUE
  3664. ) );
  3665. // 发票退票 printStatus=1 and
  3666. $untread = $invoice->getOne ( array (
  3667. 'where' => " untreadStatus=1 and status=2 ",
  3668. 'asArray' => TRUE
  3669. ) );
  3670. $new = array (
  3671. 'GLOBAL' => FALSE,
  3672. 'pendingInvoice' => FALSE,
  3673. // 'myClaim' => FALSE,
  3674. 'approval' => FALSE,
  3675. 'post' => FALSE,
  3676. 'print' => FALSE,
  3677. 'untread' => FALSE
  3678. );
  3679. // || ! empty ( $myClaim )
  3680. if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  3681. $new ['GLOBAL'] = TRUE;
  3682. if (! empty ( $pendingInvoice ))
  3683. $new ['pendingInvoice'] = TRUE;
  3684. // if (! empty ( $myClaim ))
  3685. // $new ['myClaim'] = TRUE;
  3686. if (! empty ( $approval ))
  3687. $new ['approval'] = TRUE;
  3688. if (! empty ( $post ))
  3689. $new ['post'] = TRUE;
  3690. if (! empty ( $print ))
  3691. $new ['print'] = TRUE;
  3692. if (! empty ( $untread ))
  3693. $new ['untread'] = TRUE;
  3694. return $new;
  3695. }
  3696. function setWXMsg($rid, $typeMsg = '') {
  3697. Doo::loadModel ( 'invoice' );
  3698. $invoice = new invoice ();
  3699. $invoiceDetail = $invoice->getOne ( array (
  3700. 'where' => 'iid=' . $rid,
  3701. 'asArray' => true
  3702. ) );
  3703. if (! empty ( $invoiceDetail )) {
  3704. Doo::loadModel ( 'staff' );
  3705. $staff = new staff ();
  3706. $staffmsg = $staff->getOne ( array (
  3707. 'where' => "sid='" . $invoiceDetail ['sid'] . "'",
  3708. 'asArray' => TRUE
  3709. ) );
  3710. if (! empty ( $staffmsg ['wxid'] )) {
  3711. require_once (SITE_PATH . '/protected/class/client.php');
  3712. $client = new client ( 'http://m.cld.smartcost.com.cn/' );
  3713. $user = $staffmsg ['wxid'];
  3714. $expCom = explode ( ":", $invoiceDetail ['expressCompany'] );
  3715. if (empty ( $expCom ))
  3716. $expCom [0] = '';
  3717. $msg = "";
  3718. if (empty ( $typeMsg ))
  3719. $msg = '太好了,您的发票' . $invoiceDetail ['invoiceSerial'] . ' 已邮寄 ' . $expCom [0] . ' ,快递号: <a href="https://m.kuaidi100.com/result.jsp?nu=' . $invoiceDetail ['expressNumber'] . '" >' . $invoiceDetail ['expressNumber'] . '</a>';
  3720. elseif ($typeMsg == "PRINT")
  3721. $msg = '太好了,您的发票已打印完成。';
  3722. $result = $client->SendMsg ( $user, $msg, 'text' );
  3723. }
  3724. }
  3725. }
  3726. function getToparty($category=''){
  3727. $token = $this->getAccessToken ();//
  3728. $result = json_decode ( $this->httpGet ( "https://qyapi.weixin.qq.com/cgi-bin/department/list?access_token={$token}&id=5" ),true );
  3729. $toparty=0;
  3730. foreach ($result['department'] as $key=>$value){
  3731. if ($value['name']==$category)
  3732. $toparty=$value['id'];
  3733. }
  3734. return $toparty;
  3735. }
  3736. function msgSendToparty($msg, $title, $url, $toparty, $text = '') {
  3737. $token = $this->getAccessToken ();
  3738. if ($text == 'text') {
  3739. $data = '{
  3740. "touser": "",
  3741. "toparty": "' . $toparty . '",
  3742. "totag": "",
  3743. "msgtype": "text",
  3744. "agentid": 1000002,
  3745. "text": {
  3746. "content": "' . $msg . '"
  3747. },
  3748. "safe":0
  3749. }';
  3750. }
  3751. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  3752. if ($result->errmsg != 'ok') {
  3753. return 0;
  3754. } else {
  3755. return 1;
  3756. }
  3757. }
  3758. private function msgSend($msg, $title, $url, $user, $text = '') {
  3759. $token = $this->getAccessToken ();
  3760. if ($text == 'text') {
  3761. $data = '{
  3762. "touser": "' . $user . '",
  3763. "toparty": "",
  3764. "totag": "",
  3765. "msgtype": "text",
  3766. "agentid": 1000002,
  3767. "text": {
  3768. "content": "' . $msg . '"
  3769. },
  3770. "safe":0
  3771. }';
  3772. } else {
  3773. $data = '{
  3774. "touser": "' . $user . '",
  3775. "toparty": "",
  3776. "totag": "",
  3777. "msgtype": "news",
  3778. "agentid": 1000002,
  3779. "news": {
  3780. "articles":[
  3781. {
  3782. "title": "' . $title . '",
  3783. "description": "' . $msg . '",
  3784. "url": "' . $url . '",
  3785. "picurl": ""
  3786. }
  3787. ]
  3788. }
  3789. }';
  3790. }
  3791. $result = json_decode ( $this->httpPOST ( "https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token={$token}", $data ) );
  3792. if ($result->errmsg != 'ok') {
  3793. return 0;
  3794. } else {
  3795. return 1;
  3796. }
  3797. }
  3798. private function getAccessToken() {
  3799. // access_token 应该全局存储与更新,以下代码以写入到文件中做示例
  3800. //$file = './access_token.txt';
  3801. //$data = json_decode ( file_get_contents ( $file ) );
  3802. //if ($data->expire_time < time () or ! $data->expire_time) {
  3803. // 如果是企业号用以下URL获取access_token
  3804. $url = "https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid=$this->appId&corpsecret=$this->appSecret";
  3805. // $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$this->appId&secret=$this->appSecret";
  3806. $res = json_decode ( $this->httpGet ( $url ) );
  3807. $access_token = $res->access_token;
  3808. //echo $access_token;
  3809. // if ($access_token) {
  3810. // $data->expire_time = time () + 7000;
  3811. // $data->access_token = $access_token;
  3812. // $fp = fopen ( $file, "w" );
  3813. // fwrite ( $fp, json_encode ( $data ) );
  3814. // fclose ( $fp );
  3815. // }
  3816. // } else {
  3817. // $access_token = $data->access_token;
  3818. // }
  3819. return $access_token;
  3820. }
  3821. private function httpGet($url) {
  3822. $curl = curl_init ();
  3823. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  3824. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  3825. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  3826. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  3827. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  3828. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  3829. curl_setopt ( $curl, CURLOPT_URL, $url );
  3830. $res = curl_exec ( $curl );
  3831. curl_close ( $curl );
  3832. return $res;
  3833. }
  3834. private function httpPost($url, $data) {
  3835. $curl = curl_init ();
  3836. curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, true );
  3837. curl_setopt ( $curl, CURLOPT_TIMEOUT, 500 );
  3838. // 为保证第三方服务器与微信服务器之间数据传输的安全性,所有微信接口采用https方式调用,必须使用下面2行代码打开ssl安全校验。
  3839. // 如果在部署过程中代码在此处验证失败,请到 http://curl.haxx.se/ca/cacert.pem 下载新的证书判别文件。
  3840. curl_setopt ( $curl, CURLOPT_SSL_VERIFYPEER, true );
  3841. curl_setopt ( $curl, CURLOPT_SSL_VERIFYHOST, false );
  3842. curl_setopt ( $curl, CURLOPT_URL, $url );
  3843. curl_setopt ( $curl, CURLOPT_POST, 1 );
  3844. curl_setopt ( $curl, CURLOPT_POSTFIELDS, $data );
  3845. $res = curl_exec ( $curl );
  3846. curl_close ( $curl );
  3847. return $res;
  3848. }
  3849. }
  3850. ?>