InvoiceController.php 104 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013
  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. public function beforeRun($resource, $action) {
  17. Doo::loadModel ( "invoiceManage" );
  18. $invoiceManage = new invoiceManage ();
  19. header ( 'Content-Type:text/html;charset=utf-8' );
  20. $moldList = $invoiceManage->getInvoiceByStaff ( $_COOKIE ["staff"] );
  21. // print_r($moldList);
  22. if (empty ( $moldList )) {
  23. $flag = false;
  24. $uGroups = 'ordinary';
  25. if (Doo::acl ()->isAllowed ( $uGroups, $resource, $action )) {
  26. $flag = true;
  27. }
  28. } else {
  29. $flag = false;
  30. array_push ( $moldList, array (
  31. 'mold' => 'ordinary'
  32. ) );
  33. foreach ( $moldList as $value ) {
  34. // echo $value['mold'];
  35. // echo $action;
  36. if (Doo::acl ()->isAllowed ( $value ['mold'], $resource, $action )) {
  37. $flag = true;
  38. break;
  39. }
  40. }
  41. }
  42. /*
  43. * Doo::acl()->isAllowed($uGroups['groups'], $resource, $action);
  44. */
  45. // var_dump($flag) ;
  46. if (! $flag)
  47. die ( 'illegal request' );
  48. }
  49. function __construct() {
  50. if (isset ( $_COOKIE ["staff"] )) {
  51. if (! empty ( $_COOKIE ["staff"] )) {
  52. Doo::loadModel ( 'staff' );
  53. $staff = new staff ();
  54. $uriPartsOrig = explode ( '/', $_SERVER ['REQUEST_URI'] );
  55. $this->ACTION = $uriPartsOrig [1];
  56. $this->data ['new'] = $this->isInvoiceNew ();
  57. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  58. return "/";
  59. }
  60. }
  61. Doo::loadCore ( 'uri/DooUriRouter' );
  62. $router = new DooUriRouter ();
  63. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  64. if ($routeRs ['1'] != "login") {
  65. header ( 'Content-Type:text/html;charset=utf-8' );
  66. @header ( "Location: /login" );
  67. }
  68. }
  69. function invoice() {
  70. Doo::loadModel ( 'invoice' );
  71. $invoice = new invoice ();
  72. Doo::loadModel ( 'express' );
  73. $express = new express ();
  74. Doo::loadModel ( 'invoiceReceivables' );
  75. $invoiceReceivables = new invoiceReceivables ();
  76. Doo::loadModel ( 'invoiceStatistics' );
  77. $invoiceStatistics = new invoiceStatistics ();
  78. $isMonth = $invoiceStatistics->getStatisticsByMonth ();
  79. $year = date ( "Y" );
  80. $tmp_date = date ( "Ym" );
  81. $tmp_year = substr ( $tmp_date, 0, 4 );
  82. $tmp_mon = substr ( $tmp_date, 4, 2 );
  83. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  84. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  85. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  86. $htm = $this->showCache ( $path );
  87. $expressList = $express->getExpressByAll ();
  88. $invoiceList = $invoice->getMyInvoice ( $_COOKIE ["staff"] );
  89. // $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  90. $sql = 'status=2 and untreadStatus=3 and sid=' . $_COOKIE ["staff"];
  91. $list = $invoice->getInvoiceByUntreadStatusPage ( 4, $sql );
  92. // print_r($list);
  93. $this->data ['isMonth'] = $isMonth;
  94. $this->data ['htm'] = $htm;
  95. $this->data ['expressList'] = $expressList;
  96. $this->data ['invoiceList'] = $invoiceList;
  97. $this->data ['receivablesList'] = $list;
  98. $this->data ['memu'] = "invoice";
  99. $this->data ['staff'] = $this->staff;
  100. $this->data ['receiptMemu'] = 'invoice';
  101. $this->render ( "/admin/invoice", $this->data );
  102. }
  103. function invoiceAdd() {
  104. Doo::loadModel ( 'L_category' );
  105. $lCategory = new L_category ();
  106. $category = $lCategory->find ( array (
  107. 'asArray' => true
  108. ) );
  109. $this->data ['category'] = $category;
  110. $this->data ['memu'] = "invoice";
  111. $this->data ['staff'] = $this->staff;
  112. $this->data ['receiptMemu'] = 'invoice';
  113. $this->render ( "/admin/invoiceAdd", $this->data );
  114. }
  115. /**
  116. * 提交一份开票申请,并记录下操作日志
  117. *
  118. * @since 1.0.0
  119. * @var integer cid 办事处ID
  120. * @var integer invoiceType 发票类型
  121. * @var integer doPost 是否邮寄
  122. * @var integer invoicePrice 开票金额
  123. * @var string invoiceElement 开票内容
  124. * @var string invoiceTitle 发票抬头
  125. * @var string invoiceCompany 单位名称
  126. * @var string TIN 纳税人识别码
  127. * @var string address 注册地址
  128. * @var string phone 注册电话
  129. * @var string bank 开户银行
  130. * @var string bankAccount 银行账户
  131. * @var string recipients 收件人
  132. * @var string recipientsPhone 收件人手机/电话
  133. * @var string recipientsAddress 收件地址
  134. * @var string mailItems 邮寄物品
  135. * @var string remark 备注
  136. * @return string 返回跳转开票主页路径
  137. */
  138. function invoiceAddDo() {
  139. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  140. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  141. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  142. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  143. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  144. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  145. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  146. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  147. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  148. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  149. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  150. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  151. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  152. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  153. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  154. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  155. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  156. if (! empty ( $cid ) && ! empty ( $invoicePrice ) && ! empty ( $invoiceElement )) {
  157. Doo::loadModel ( 'invoice' );
  158. $invoice = new invoice ();
  159. Doo::loadModel ( 'L_category' );
  160. $lCategory = new L_category ();
  161. Doo::loadModel ( 'invoiceManage' );
  162. $invoiceManage = new invoiceManage ();
  163. Doo::loadModel ( 'invoiceOperationLog' );
  164. $invoiceOperationLog = new invoiceOperationLog ();
  165. Doo::loadModel ( 'invoiceStatistics' );
  166. $invoiceStatistics = new invoiceStatistics ();
  167. $categoryDetil = $lCategory->getOne ( array (
  168. 'SELECT' => 'title',
  169. 'where' => 'cid=' . $cid,
  170. 'asArray' => true
  171. ) );
  172. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  173. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  174. $moldManage = array ();
  175. foreach ( $invoiceManageList as $key => $value ) {
  176. if ($value ['mold'] == '发票打印')
  177. $moldManage [$value ['mold']] = $value ['staffList'];
  178. elseif ($value ['mold'] == '发票邮寄')
  179. $moldManage [$value ['mold']] = $value ['staffList'];
  180. elseif ($value ['mold'] == '发票退票')
  181. $moldManage [$value ['mold']] = $value ['staffList'];
  182. }
  183. $item = array (
  184. 'cid' => $cid,
  185. 'categoryName' => $categoryDetil ['title'],
  186. 'invoiceElement' => $invoiceElement,
  187. 'invoicePrice' => $invoicePrice,
  188. 'invoiceType' => $invoiceType,
  189. 'doPost' => $doPost,
  190. 'status' => 1,
  191. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  192. 'date' => date ( "Y-m-d H:i:s" ),
  193. 'updateTime' => date ( "Y-m-d H:i:s" ),
  194. 'sid' => $this->staff [0] ['sid'],
  195. 'userName' => $this->staff [0] ['username'],
  196. 'invoiceManage' => $invoiceManageDetail ['staff'],
  197. 'pendingApprovals' => $invoiceManageDetail ['staffList'] [0] [0],
  198. 'moldManage' => json_encode ( $moldManage ),
  199. 'remark' => $remark
  200. );
  201. if ($invoiceType == 0)
  202. $item += array (
  203. 'invoiceTitle' => $invoiceTitle
  204. );
  205. else {
  206. $item += array (
  207. 'invoiceCompany' => $invoiceCompany,
  208. 'TIN' => $TIN,
  209. 'address' => $address,
  210. 'phone' => $phone,
  211. 'bank' => $bank,
  212. 'bankAccount' => $bankAccount
  213. );
  214. }
  215. if ($doPost == 1) {
  216. $item += array (
  217. 'recipients' => $recipients,
  218. 'recipientsPhone' => $recipientsPhone,
  219. 'recipientsAddress' => $recipientsAddress,
  220. 'mailItems' => $mailItems
  221. );
  222. }
  223. $iid = $invoice->addInvoice ( $item );
  224. $item = array (
  225. 'date' => date ( "Y-m-d H:i:s" ),
  226. 'operation' => "创建",
  227. 'status' => 1,
  228. 'img' => $this->staff [0] ['avatar'],
  229. 'username' => $this->staff [0] ['username'],
  230. 'uid' => $this->staff [0] ['sid'],
  231. 'category' => $this->staff [0] ['category'],
  232. 'iid' => $iid
  233. );
  234. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  235. $item = array (
  236. 'date' => date ( "Y-m-d H:i:s" ),
  237. 'operation' => "提交审批",
  238. 'status' => 1,
  239. 'img' => $this->staff [0] ['avatar'],
  240. 'username' => $this->staff [0] ['username'],
  241. 'uid' => $this->staff [0] ['sid'],
  242. 'category' => $this->staff [0] ['category'],
  243. 'iid' => $iid
  244. );
  245. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  246. $item = array (
  247. 'date' => date ( "Y-m-d H:i:s" ),
  248. 'priceClass' => 1,
  249. 'cid' => $this->staff [0] ['cid'],
  250. 'staff' => $this->staff [0] ['sid'],
  251. 'invoicePrice' => $invoicePrice
  252. );
  253. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  254. }
  255. return "/invoice";
  256. }
  257. function invoiceEdit() {
  258. Doo::loadClass ( 'XDeode' );
  259. $XDeode = new XDeode ( 5 );
  260. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  261. $iid = $XDeode->decode ( $iid );
  262. if (! is_numeric ( $iid ))
  263. die ( 'illegal request' );
  264. Doo::loadModel ( 'invoice' );
  265. $invoice = new invoice ();
  266. Doo::loadModel ( 'invoiceOperationLog' );
  267. $invoiceOperationLog = new invoiceOperationLog ();
  268. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  269. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  270. $this->data ['operation'] = $operation;
  271. $this->data ['invoiceDetail'] = $invoiceDetail;
  272. $this->data ['memu'] = "invoice";
  273. $this->data ['staff'] = $this->staff;
  274. $this->data ['receiptMemu'] = 'invoice';
  275. $this->render ( "/admin/invoiceEdit", $this->data );
  276. }
  277. /**
  278. * 重新编辑退回的发票
  279. * @return string
  280. */
  281. function invoiceEditDo() {
  282. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  283. Doo::loadModel ( 'invoice' );
  284. $invoice = new invoice ();
  285. $iid = $invoice->authcode ( $iidKey );
  286. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  287. die ( 'illegal request' );
  288. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  289. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  290. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  291. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  292. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  293. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  294. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  295. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  296. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  297. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  298. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  299. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  300. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  301. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  302. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  303. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  304. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  305. if (! empty ( $cid ) && ! empty ( $invoicePrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  306. Doo::loadModel ( 'invoiceManage' );
  307. $invoiceManage = new invoiceManage ();
  308. Doo::loadModel ( 'invoiceOperationLog' );
  309. $invoiceOperationLog = new invoiceOperationLog ();
  310. $cid = explode ( ':', $cid );
  311. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  312. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  313. $moldManage = array ();
  314. foreach ( $invoiceManageList as $key => $value ) {
  315. if ($value ['mold'] == '发票打印')
  316. $moldManage [$value ['mold']] = $value ['staffList'];
  317. elseif ($value ['mold'] == '发票邮寄')
  318. $moldManage [$value ['mold']] = $value ['staffList'];
  319. elseif ($value ['mold'] == '发票打印')
  320. $moldManage [$value ['mold']] = $value ['staffList'];
  321. }
  322. $item = array (
  323. 'iid' => $iid,
  324. 'cid' => $cid [0],
  325. 'categoryName' => $cid [1],
  326. 'invoiceElement' => $invoiceElement,
  327. 'invoicePrice' => $invoicePrice,
  328. 'invoiceType' => $invoiceType,
  329. 'doPost' => $doPost,
  330. 'status' => 1,
  331. 'updateTime' => date ( "Y-m-d H:i:s" ),
  332. 'remark' => $remark
  333. );
  334. if ($invoiceType == 0)
  335. $item += array (
  336. 'invoiceTitle' => $invoiceTitle
  337. );
  338. else {
  339. $item += array (
  340. 'invoiceCompany' => $invoiceCompany,
  341. 'TIN' => $TIN,
  342. 'address' => $address,
  343. 'phone' => $phone,
  344. 'bank' => $bank,
  345. 'bankAccount' => $bankAccount
  346. );
  347. }
  348. if ($doPost == 1) {
  349. $item += array (
  350. 'recipients' => $recipients,
  351. 'recipientsPhone' => $recipientsPhone,
  352. 'recipientsAddress' => $recipientsAddress,
  353. 'mailItems' => $mailItems
  354. );
  355. }
  356. $invoice->setInvoiceByCondition ( $item );
  357. $item = array (
  358. 'date' => date ( "Y-m-d H:i:s" ),
  359. 'operation' => "重新提交审批",
  360. 'status' => 1,
  361. 'img' => $this->staff [0] ['avatar'],
  362. 'username' => $this->staff [0] ['username'],
  363. 'uid' => $this->staff [0] ['sid'],
  364. 'category' => $this->staff [0] ['category'],
  365. 'iid' => $iid
  366. );
  367. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  368. }
  369. return "/invoice";
  370. }
  371. /**
  372. * 终止开票
  373. */
  374. function invoiceDroppedDo() {
  375. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  376. Doo::loadModel ( 'invoice' );
  377. $invoice = new invoice ();
  378. Doo::loadModel ( 'invoiceOperationLog' );
  379. $invoiceOperationLog = new invoiceOperationLog ();
  380. $iid = $invoice->authcode ( $droppedIidKey );
  381. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  382. die ( 'illegal request' );
  383. $item = array (
  384. 'iid' => $iid,
  385. 'status' => 4,
  386. 'updateTime' => date ( "Y-m-d H:i:s" )
  387. );
  388. $invoice->setInvoiceByCondition ( $item );
  389. $item = array (
  390. 'date' => date ( "Y-m-d H:i:s" ),
  391. 'operation' => '终止了开票',
  392. 'status' => 4,
  393. 'img' => $this->staff [0] ['avatar'],
  394. 'username' => $this->staff [0] ['username'],
  395. 'uid' => $this->staff [0] ['sid'],
  396. 'category' => $this->staff [0] ['category'],
  397. 'iid' => $iid
  398. );
  399. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  400. return "/invoice";
  401. }
  402. /**
  403. * 申请退票
  404. */
  405. function invoiceUntreadDo() {
  406. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  407. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  408. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  409. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  410. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  411. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  412. Doo::loadModel ( 'invoice' );
  413. $invoice = new invoice ();
  414. Doo::loadModel ( 'invoiceOperationLog' );
  415. $invoiceOperationLog = new invoiceOperationLog ();
  416. Doo::loadModel ( 'invoiceReceivables' );
  417. $invoiceReceivables = new invoiceReceivables ();
  418. $iid = $invoice->authcode ( $untreadIidKey );
  419. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  420. die ( 'illegal request' );
  421. $lt = $invoiceReceivables->getInvoiceReceivablesByIid ( $untreadIidKey );
  422. if (! empty ( $lt )) {
  423. header ( 'Content-Type:text/html;charset=utf-8' );
  424. die ( '该发票有收款绑定,请先移除!' );
  425. }
  426. $item = array (
  427. 'iid' => $iid,
  428. 'untreadStatus' => 1,
  429. 'untreadReason' => $untreadReason,
  430. 'untreadPost' => $untreadPost,
  431. 'updateTime' => date ( "Y-m-d H:i:s" )
  432. );
  433. if ($untreadPost == 1) {
  434. $item += array (
  435. 'untreadCompany' => $untreadCompany,
  436. 'untreadNumber' => $untreadNumber,
  437. 'untreadItems' => $untreadItems
  438. );
  439. }
  440. $invoice->setInvoiceByCondition ( $item );
  441. $item = array (
  442. 'date' => date ( "Y-m-d H:i:s" ),
  443. 'operation' => '申请退票',
  444. 'status' => 7,
  445. 'img' => $this->staff [0] ['avatar'],
  446. 'username' => $this->staff [0] ['username'],
  447. 'uid' => $this->staff [0] ['sid'],
  448. 'category' => $this->staff [0] ['category'],
  449. 'iid' => $iid
  450. );
  451. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  452. return "/invoice";
  453. }
  454. /**
  455. * 删除已终止的开票
  456. */
  457. function invoiceDelDo() {
  458. Doo::loadClass ( 'XDeode' );
  459. $XDeode = new XDeode ( 5 );
  460. Doo::loadModel ( 'invoice' );
  461. $invoice = new invoice ();
  462. Doo::loadModel ( 'invoiceOperationLog' );
  463. $invoiceOperationLog = new invoiceOperationLog ();
  464. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  465. $iid = $XDeode->decode ( $iid );
  466. if (! is_numeric ( $iid ))
  467. die ( 'illegal request' );
  468. $invoiceDetail = $invoice->getMyInvoice ( $_COOKIE ["staff"], $iid );
  469. if (empty ( $invoiceDetail ))
  470. die ( 'illegal request' );
  471. $item = array (
  472. 'iid' => $iid,
  473. 'isDelete' => 1,
  474. 'updateTime' => date ( "Y-m-d H:i:s" )
  475. );
  476. $invoice->setInvoiceByCondition ( $item );
  477. $item = array (
  478. 'date' => date ( "Y-m-d H:i:s" ),
  479. 'operation' => '删除了已终止的发票',
  480. 'status' => 4,
  481. 'img' => $this->staff [0] ['avatar'],
  482. 'username' => $this->staff [0] ['username'],
  483. 'uid' => $this->staff [0] ['sid'],
  484. 'category' => $this->staff [0] ['category'],
  485. 'iid' => $iid
  486. );
  487. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  488. return "/invoice";
  489. }
  490. function invoiceApproval() {
  491. Doo::loadModel ( 'invoice' );
  492. $invoice = new invoice ();
  493. Doo::loadClass ( 'XDeode' );
  494. $XDeode = new XDeode ( 5 );
  495. Doo::loadModel ( 'staff' );
  496. $staff = new staff ();
  497. $invoiceList = $invoice->find ( array (
  498. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  499. 'desc' => 'iid',
  500. 'asArray' => true
  501. ) );
  502. foreach ( $invoiceList as $key => $value ) {
  503. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  504. $lastApprover = json_decode ( $value ['processApprovals'], true );
  505. if (! empty ( $lastApprover )) {
  506. $lastApproverKey = array_keys ( $lastApprover );
  507. $lastApprover = end ( $lastApprover );
  508. $staffDetail = $staff->getOne ( array (
  509. 'where' => 'sid=' . end ( $lastApproverKey ),
  510. 'asArray' => true
  511. ) );
  512. $lastApprover ['username'] = $staffDetail ['username'];
  513. }
  514. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  515. }
  516. $ilist = $invoice->getInvoiceByProcessStatus ();
  517. // print_r($ilist);
  518. $this->data ['invoiceList'] = $invoiceList;
  519. $this->data ['ilist'] = $ilist;
  520. $this->data ['memu'] = "invoice";
  521. $this->data ['staff'] = $this->staff;
  522. $this->data ['receiptMemu'] = 'invoiceApproval';
  523. $this->render ( "/admin/invoiceApproval", $this->data );
  524. }
  525. function invoiceDetail() {
  526. Doo::loadClass ( 'XDeode' );
  527. $XDeode = new XDeode ( 5 );
  528. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  529. $iid = $XDeode->decode ( $iid );
  530. if (! is_numeric ( $iid ))
  531. die ( 'illegal request' );
  532. Doo::loadModel ( 'invoice' );
  533. $invoice = new invoice ();
  534. Doo::loadModel ( 'invoiceOperationLog' );
  535. $invoiceOperationLog = new invoiceOperationLog ();
  536. $invoiceDetail = $invoice->getOne ( array (
  537. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  538. 'asArray' => true
  539. ) );
  540. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  541. $this->data ['invoiceDetail'] = $invoiceDetail;
  542. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  543. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  544. $this->data ['memu'] = "invoice";
  545. $this->data ['staff'] = $this->staff;
  546. $this->data ['receiptMemu'] = 'invoiceApproval';
  547. $this->render ( "/admin/invoiceApprovalDetail", $this->data );
  548. }
  549. /**
  550. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  551. *
  552. * @since 1.0.0
  553. * @var integer iid 开票ID 已加密
  554. * @var integer status 发票审批状态
  555. * @var integer opintion 审批发票的意见
  556. * @return string 如操作成功返回审批首页
  557. */
  558. function invoiceApprovalDo() {
  559. Doo::loadModel ( 'invoice' );
  560. $invoice = new invoice ();
  561. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  562. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  563. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  564. $iid = $invoice->authcode ( $iid );
  565. if (! is_numeric ( $iid ))
  566. die ( 'illegal request' );
  567. if (! empty ( $iid ) && ! empty ( $status ) && ! empty ( $opinion )) {
  568. if (! ($status == 2 || $status == 3 || $status == 4))
  569. die ( 'illegal request' );
  570. Doo::loadModel ( 'invoiceOperationLog' );
  571. $invoiceOperationLog = new invoiceOperationLog ();
  572. $invoiceDetail = $invoice->getOne ( array (
  573. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  574. 'asArray' => true
  575. ) );
  576. if (empty ( $invoiceDetail ))
  577. die ( 'illegal request' );
  578. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  579. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  580. if ($status == 3) {
  581. $invoice->status = $status;
  582. $item = array (
  583. 'operation' => $opinion
  584. );
  585. } else {
  586. if (empty ( $processApprovals )) {
  587. $processApprovals = array (
  588. $this->staff [0] ['sid'] => array (
  589. 'date' => date ( "Y-m-d H:i:s" ),
  590. 'opinion' => $opinion,
  591. 'status' => $status
  592. )
  593. );
  594. if ($status != 4 && isset ( $invoiceManage [1] ))
  595. $invoice->pendingApprovals = $invoiceManage [1] [0];
  596. $invoice->processApprovals = json_encode ( $processApprovals );
  597. } else {
  598. $processApprovals [$this->staff [0] ['sid']] = array (
  599. 'date' => date ( "Y-m-d H:i:s" ),
  600. 'opinion' => $opinion,
  601. 'status' => $status
  602. );
  603. $pendingApprovals = 0;
  604. foreach ( $invoiceManage as $key => $value ) {
  605. if ($value [0] == $this->staff [0] ['sid']) {
  606. if (isset ( $invoiceManage [$key + 1] ))
  607. $pendingApprovals = $invoiceManage [$key + 1] [0];
  608. break;
  609. }
  610. }
  611. if ($status != 4 && ! empty ( $pendingApprovals ))
  612. $invoice->pendingApprovals = $pendingApprovals;
  613. $invoice->processApprovals = json_encode ( $processApprovals );
  614. }
  615. $item = array (
  616. 'operation' => $opinion
  617. );
  618. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  619. $invoice->status = $status;
  620. $invoice->pendingApprovals = 0;
  621. } elseif ($status == 4) {
  622. $invoice->status = $status;
  623. $item = array (
  624. 'operation' => $opinion
  625. );
  626. }
  627. }
  628. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  629. $invoice->update ( array (
  630. 'where' => 'iid=' . $iid
  631. ) );
  632. $item += array (
  633. 'date' => date ( "Y-m-d H:i:s" ),
  634. 'img' => $this->staff [0] ['avatar'],
  635. 'username' => $this->staff [0] ['username'],
  636. 'uid' => $this->staff [0] ['sid'],
  637. 'category' => $this->staff [0] ['category'],
  638. 'status' => $status,
  639. 'iid' => $iid
  640. );
  641. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  642. return '/invoiceApproval';
  643. }
  644. die ( 'illegal request' );
  645. }
  646. /**
  647. * 展示需要打印的发票数据
  648. *
  649. * @since 1.0.0
  650. */
  651. function invoicePrint() {
  652. Doo::loadModel ( 'invoice' );
  653. $invoice = new invoice ();
  654. Doo::loadClass ( 'XDeode' );
  655. $XDeode = new XDeode ( 5 );
  656. Doo::loadModel ( 'staff' );
  657. $staff = new staff ();
  658. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  659. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  660. foreach ( $toPrint as $key => $value ) {
  661. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  662. $lastApprover = json_decode ( $value ['processApprovals'], true );
  663. if (! empty ( $lastApprover )) {
  664. $lastApproverKey = array_keys ( $lastApprover );
  665. $lastApprover = end ( $lastApprover );
  666. $staffDetail = $staff->getOne ( array (
  667. 'where' => 'sid=' . end ( $lastApproverKey ),
  668. 'asArray' => true
  669. ) );
  670. $lastApprover ['username'] = $staffDetail ['username'];
  671. }
  672. $toPrint [$key] ['lastApprover'] = $lastApprover;
  673. }
  674. foreach ( $printed as $key => $value ) {
  675. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  676. $lastApprover = json_decode ( $value ['processApprovals'], true );
  677. if (! empty ( $lastApprover )) {
  678. $lastApproverKey = array_keys ( $lastApprover );
  679. $lastApprover = end ( $lastApprover );
  680. $staffDetail = $staff->getOne ( array (
  681. 'where' => 'sid=' . end ( $lastApproverKey ),
  682. 'asArray' => true
  683. ) );
  684. $lastApprover ['username'] = $staffDetail ['username'];
  685. }
  686. $printed [$key] ['lastApprover'] = $lastApprover;
  687. }
  688. $this->data ['printed'] = $printed;
  689. $this->data ['toPrint'] = $toPrint;
  690. $this->data ['memu'] = "invoice";
  691. $this->data ['staff'] = $this->staff;
  692. $this->data ['receiptMemu'] = 'invoicePrint';
  693. $this->render ( "/admin/invoicePrint", $this->data );
  694. }
  695. /**
  696. * 展示发票打印的详情页面
  697. *
  698. * @since 1.0.0
  699. */
  700. function invoicePrintDetail() {
  701. Doo::loadClass ( 'XDeode' );
  702. $XDeode = new XDeode ( 5 );
  703. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  704. $iid = $XDeode->decode ( $iid );
  705. if (! is_numeric ( $iid ))
  706. die ( 'illegal request' );
  707. Doo::loadModel ( 'invoice' );
  708. $invoice = new invoice ();
  709. Doo::loadModel ( 'invoiceOperationLog' );
  710. $invoiceOperationLog = new invoiceOperationLog ();
  711. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  712. // if (empty ( $invoiceDetail ))
  713. // die ( 'illegal request' );
  714. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  715. $this->data ['invoiceDetail'] = $invoiceDetail;
  716. $this->data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  717. $this->data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  718. $this->data ['memu'] = "invoice";
  719. $this->data ['staff'] = $this->staff;
  720. $this->data ['receiptMemu'] = 'invoicePrint';
  721. $this->render ( "/admin/invoicePrintDetail", $this->data );
  722. }
  723. /**
  724. * 填写票号并完成打印
  725. * @since 1.0.0
  726. */
  727. function invoicePrintDo() {
  728. Doo::loadModel ( 'invoice' );
  729. $invoice = new invoice ();
  730. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  731. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  732. $iid = $invoice->authcode ( $iid );
  733. if (! is_numeric ( $iid ))
  734. die ( 'illegal request' );
  735. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  736. Doo::loadModel ( 'invoiceOperationLog' );
  737. $invoiceOperationLog = new invoiceOperationLog ();
  738. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  739. if (empty ( $invoicePrintDetail ))
  740. die ( 'illegal request' );
  741. $item = array (
  742. 'iid' => $iid,
  743. 'printStatus' => 1,
  744. 'updateTime' => date ( "Y-m-d H:i:s" ),
  745. 'printTime' => date ( "Y-m-d H:i:s" ),
  746. 'invoiceNo' => $invoiceNo
  747. );
  748. $invoice->setInvoiceByCondition ( $item );
  749. $item = array (
  750. 'date' => date ( "Y-m-d H:i:s" ),
  751. 'operation' => $invoiceNo,
  752. 'status' => 5,
  753. 'img' => $this->staff [0] ['avatar'],
  754. 'username' => $this->staff [0] ['username'],
  755. 'uid' => $this->staff [0] ['sid'],
  756. 'category' => $this->staff [0] ['category'],
  757. 'iid' => $iid
  758. );
  759. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  760. return "/invoicePrint";
  761. }
  762. }
  763. /**
  764. * 需要邮寄的发票
  765. * @since 1.0.0
  766. */
  767. function invoicePost() {
  768. Doo::loadModel ( 'invoice' );
  769. $invoice = new invoice ();
  770. Doo::loadModel ( 'express' );
  771. $express = new express ();
  772. $invoicePost = $invoice->getPostByInvoice ();
  773. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  774. $expressList = $express->getExpressByAll ();
  775. $this->data ['expressList'] = $expressList;
  776. $this->data ['invoicePost'] = $invoicePost;
  777. $this->data ['invoicePosted'] = $invoicePosted;
  778. $this->data ['memu'] = "invoice";
  779. $this->data ['staff'] = $this->staff;
  780. $this->data ['receiptMemu'] = 'invoicePost';
  781. $this->render ( "/admin/invoicePost", $this->data );
  782. }
  783. /**
  784. * 添加发票邮寄信息
  785. */
  786. function invoiceExpressAddDo() {
  787. Doo::loadModel ( 'invoice' );
  788. $invoice = new invoice ();
  789. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  790. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  791. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  792. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  793. $iid = $iid = $invoice->authcode ( $iid );
  794. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  795. die ( 'illegal request' );
  796. $item = array (
  797. 'iid' => $iid,
  798. 'postStatus' => 1,
  799. 'updateTime' => date ( "Y-m-d H:i:s" ),
  800. 'postTime' => date ( "Y-m-d H:i:s" ),
  801. 'expressCompany' => $expressCompany,
  802. 'expressNumber' => $expressNumber,
  803. 'actualItems' => $actualItems,
  804. 'poster' => $this->staff [0] ['username']
  805. );
  806. $invoice->setInvoiceByCondition ( $item );
  807. return '/invoicePost';
  808. }
  809. function invoiceExpressUpdateDo() {
  810. Doo::loadModel ( 'invoice' );
  811. $invoice = new invoice ();
  812. $action = $this->get_args ( 'action' ) ? $this->get_args ( 'action' ) : "";
  813. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  814. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  815. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  816. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  817. $iid = $invoice->authcode ( $iid );
  818. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  819. die ( 'illegal request' );
  820. $item = array (
  821. 'iid' => $iid,
  822. 'updateTime' => date ( "Y-m-d H:i:s" ),
  823. 'expressCompany' => $expressCompany,
  824. 'expressNumber' => $expressNumber,
  825. 'actualItems' => $actualItems,
  826. 'poster' => $this->staff [0] ['username']
  827. );
  828. $invoice->setInvoiceByCondition ( $item );
  829. return $action;
  830. }
  831. /**
  832. * 退票处理页面
  833. */
  834. function invoiceUntread() {
  835. Doo::loadModel ( 'invoice' );
  836. $invoice = new invoice ();
  837. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1 );
  838. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  839. $this->data ['untreadInvoice'] = $untreadInvoice;
  840. $this->data ['establishedInvoice'] = $establishedInvoice;
  841. $this->data ['memu'] = "invoice";
  842. $this->data ['staff'] = $this->staff;
  843. $this->data ['receiptMemu'] = 'invoiceUntread';
  844. $this->render ( "/admin/invoiceUntread", $this->data );
  845. }
  846. /**
  847. * 确认收到退回的发票,开票状态为退回
  848. */
  849. function invoiceUntreadEstablishedDo() {
  850. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  851. Doo::loadModel ( 'invoice' );
  852. $invoice = new invoice ();
  853. Doo::loadModel ( 'invoiceOperationLog' );
  854. $invoiceOperationLog = new invoiceOperationLog ();
  855. $iid = $invoice->authcode ( $untreadIidKey );
  856. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  857. die ( 'illegal request' );
  858. $item = array (
  859. 'iid' => $iid,
  860. 'untreadStatus' => 2,
  861. 'updateTime' => date ( "Y-m-d H:i:s" )
  862. );
  863. $invoice->setInvoiceByCondition ( $item );
  864. $item = array (
  865. 'date' => date ( "Y-m-d H:i:s" ),
  866. 'operation' => '已确认退票',
  867. 'status' => 6,
  868. 'img' => $this->staff [0] ['avatar'],
  869. 'username' => $this->staff [0] ['username'],
  870. 'uid' => $this->staff [0] ['sid'],
  871. 'category' => $this->staff [0] ['category'],
  872. 'iid' => $iid
  873. );
  874. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  875. return "/invoiceUntread";
  876. }
  877. function invoiceReceivables() {
  878. Doo::loadModel ( 'L_category' );
  879. $lCategory = new L_category ();
  880. Doo::loadModel ( 'staff' );
  881. $staff = new staff ();
  882. Doo::loadModel ( 'invoiceReceivables' );
  883. $invoiceReceivables = new invoiceReceivables ();
  884. $category = $lCategory->getCategory ();
  885. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  886. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByNew ();
  887. // print_r($receivablesList);
  888. $this->data ['receivablesList'] = $receivablesList;
  889. $this->data ['staffList'] = $staffList;
  890. $this->data ['category'] = $category;
  891. $this->data ['memu'] = "invoice";
  892. $this->data ['staff'] = $this->staff;
  893. $this->data ['receiptMemu'] = 'invoiceReceivables';
  894. $this->render ( "/admin/invoiceReceivables", $this->data );
  895. }
  896. /**
  897. * 录入收款数据
  898. * @return string
  899. */
  900. function invoiceReceivablesDo() {
  901. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  902. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  903. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  904. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  905. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  906. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  907. Doo::loadModel ( 'invoiceReceivables' );
  908. $invoiceReceivables = new invoiceReceivables ();
  909. Doo::loadModel ( 'invoiceROLog' );
  910. $invoiceROLog = new invoiceROLog ();
  911. Doo::loadModel ( 'invoiceStatistics' );
  912. $invoiceStatistics = new invoiceStatistics ();
  913. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  914. $item = array (
  915. 'receivablesPrice' => $receivablesPrice,
  916. 'receivablesMessage' => $receivablesMessage,
  917. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  918. 'receivablesBank' => $receivablesBank,
  919. 'receivablesDate' => $receivablesDate,
  920. 'inputStaff' => $this->staff [0] ['username'],
  921. 'date' => date ( "Y-m-d" ),
  922. 'receivablesCategory' => $receivablesCategory,
  923. 'receivablesStaff' => $receivablesStaff
  924. );
  925. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  926. $item += array (
  927. 'confirmTime' => date ( "Y-m-d H:i:s" )
  928. );
  929. }
  930. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  931. $item = array ();
  932. // 收款操作日志
  933. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  934. $item = array (
  935. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  936. );
  937. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  938. $item = array (
  939. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  940. );
  941. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  942. $receivablesStaff = explode ( '-', $receivablesStaff );
  943. $item = array (
  944. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  945. );
  946. }
  947. $item += array (
  948. 'date' => date ( "Y-m-d" ),
  949. 'status' => 1,
  950. 'img' => $this->staff [0] ['avatar'],
  951. 'username' => $this->staff [0] ['username'],
  952. 'uid' => $this->staff [0] ['sid'],
  953. 'category' => $this->staff [0] ['category'],
  954. 'irid' => $irid
  955. );
  956. $invoiceROLog->setInvoiceROLog ( $item );
  957. $item = array (
  958. 'date' => date ( "Y-m-d H:i:s" ),
  959. 'priceClass' => 2,
  960. 'irid' => $irid,
  961. 'receivablesPrice' => $receivablesPrice
  962. );
  963. if ($receivablesCategory != 'PUBLIC') {
  964. $receivablesCategory = explode ( ":", $receivablesCategory );
  965. $item += array (
  966. 'cid' => $receivablesCategory [0]
  967. );
  968. }
  969. if ($receivablesStaff2 != 'PUBLIC') {
  970. $receivablesStaff = explode ( "-", $receivablesStaff2 );
  971. $item += array (
  972. 'staff' => $receivablesStaff [0]
  973. );
  974. }
  975. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  976. }
  977. return "/invoiceReceivables";
  978. }
  979. /**
  980. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  981. */
  982. function invoiceReceivablesClaim() {
  983. Doo::loadModel ( 'invoiceReceivables' );
  984. $invoiceReceivables = new invoiceReceivables ();
  985. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'] );
  986. $this->data ['receivablesList'] = $receivablesList;
  987. $this->data ['memu'] = "invoice";
  988. $this->data ['staff'] = $this->staff;
  989. $this->data ['receiptMemu'] = 'invoiceReceivablesClaim';
  990. $this->render ( "/admin/invoiceReceivablesClaim", $this->data );
  991. }
  992. /**
  993. * 更新收款相关数据
  994. */
  995. function invoiceReceivablesUpdateClaim() {
  996. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  997. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  998. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  999. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  1000. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  1001. $receivablesStaff = $receivablesStaff2 = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  1002. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  1003. if (empty ( $claimKey ))
  1004. die ( 'illegal request' );
  1005. Doo::loadModel ( 'invoiceReceivables' );
  1006. $invoiceReceivables = new invoiceReceivables ();
  1007. Doo::loadModel ( 'invoiceROLog' );
  1008. $invoiceROLog = new invoiceROLog ();
  1009. $con = ' and iid=0 and bindStatus=0'; // and receivablesCategory!="PUBLIC" and receivablesStaff!="PUBLIC"
  1010. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  1011. if (empty ( $detail ))
  1012. die ( 'illegal request' );
  1013. $invoiceReceivables = new invoiceReceivables ();
  1014. $item = array (
  1015. 'irid' => $detail ['irid']
  1016. );
  1017. if ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  1018. $item += array (
  1019. 'confirmTime' => date ( "Y-m-d H:i:s" )
  1020. );
  1021. }
  1022. if (! empty ( $receivablesCategory ))
  1023. $item += array (
  1024. 'receivablesCategory' => $receivablesCategory
  1025. );
  1026. if (! empty ( $receivablesStaff ))
  1027. $item += array (
  1028. 'receivablesStaff' => $receivablesStaff
  1029. );
  1030. if (! empty ( $receivablesPrice ))
  1031. $item += array (
  1032. 'receivablesPrice' => $receivablesPrice
  1033. );
  1034. if (! empty ( $receivablesMessage ))
  1035. $item += array (
  1036. 'receivablesMessage' => $receivablesMessage
  1037. );
  1038. if (! empty ( $receivablesBank ))
  1039. $item += array (
  1040. 'receivablesBank' => $receivablesBank
  1041. );
  1042. if (! empty ( $receivablesDate ))
  1043. $item += array (
  1044. 'receivablesDate' => $receivablesDate
  1045. );
  1046. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  1047. // 收款操作日志
  1048. $item = array ();
  1049. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  1050. $item = array (
  1051. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  1052. );
  1053. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  1054. $item = array (
  1055. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  1056. );
  1057. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  1058. $receivablesStaff = explode ( '-', $receivablesStaff );
  1059. $item = array (
  1060. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  1061. );
  1062. }
  1063. $item += array (
  1064. 'date' => date ( "Y-m-d" ),
  1065. 'status' => 1,
  1066. 'img' => $this->staff [0] ['avatar'],
  1067. 'username' => $this->staff [0] ['username'],
  1068. 'uid' => $this->staff [0] ['sid'],
  1069. 'category' => $this->staff [0] ['category'],
  1070. 'irid' => $detail ['irid']
  1071. );
  1072. $invoiceROLog->setInvoiceROLog ( $item );
  1073. return '/invoiceReceivablesAS';
  1074. }
  1075. function invoiceReceivablesDelete() {
  1076. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  1077. if (empty ( $claimKey ))
  1078. die ( 'illegal request' );
  1079. Doo::loadModel ( 'invoiceReceivables' );
  1080. $invoiceReceivables = new invoiceReceivables ();
  1081. $con = ' and iid=0 and bindStatus=0 and receivablesStaff="PUBLIC"';
  1082. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey, $con );
  1083. if (empty ( $detail ))
  1084. die ( 'illegal request' );
  1085. $invoiceReceivables->delInvoiceReceivablesByIrid ( $detail ['irid'] );
  1086. return '/invoiceReceivablesAS';
  1087. }
  1088. /**
  1089. * 管理员录入的收款 ,确认认领到谁的名下.统计收款金额
  1090. */
  1091. function invoiceReceivablesAscription() {
  1092. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  1093. Doo::loadModel ( 'invoiceReceivables' );
  1094. $invoiceReceivables = new invoiceReceivables ();
  1095. Doo::loadModel ( 'invoiceROLog' );
  1096. $invoiceROLog = new invoiceROLog ();
  1097. Doo::loadModel ( 'invoiceStatistics' );
  1098. $invoiceStatistics = new invoiceStatistics ();
  1099. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  1100. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC') {
  1101. $item = array (
  1102. 'irid' => $detail ['irid'],
  1103. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  1104. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  1105. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  1106. 'source' => 1
  1107. );
  1108. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  1109. $item = array (
  1110. 'date' => date ( "Y-m-d" ),
  1111. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  1112. 'status' => 2,
  1113. 'img' => $this->staff [0] ['avatar'],
  1114. 'username' => $this->staff [0] ['username'],
  1115. 'uid' => $this->staff [0] ['sid'],
  1116. 'category' => $this->staff [0] ['category'],
  1117. 'irid' => $irid
  1118. );
  1119. $invoiceROLog->setInvoiceROLog ( $item );
  1120. $item = array (
  1121. 'cid' => $this->staff [0] ['cid'],
  1122. 'staff' => $this->staff [0] ['sid']
  1123. );
  1124. $invoiceStatistics->updateInvoiceStatisticsByIrid ( $item, $detail ['irid'] );
  1125. }
  1126. return "/invoiceReceivablesClaim";
  1127. }
  1128. /**
  1129. */
  1130. function invoiceMyReceivables() {
  1131. Doo::loadModel ( 'invoiceReceivables' );
  1132. $invoiceReceivables = new invoiceReceivables ();
  1133. Doo::loadModel ( 'invoiceStatistics' );
  1134. $invoiceStatistics = new invoiceStatistics ();
  1135. $isMonth = $invoiceStatistics->getStatisticsByMonth ();
  1136. $year = date ( "Y" );
  1137. $tmp_date = date ( "Ym" );
  1138. $tmp_year = substr ( $tmp_date, 0, 4 );
  1139. $tmp_mon = substr ( $tmp_date, 4, 2 );
  1140. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  1141. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  1142. $path = SITE_PATH . $this->INVOICECOLLECTPATH . "invoiceCollect_" . $year . "_" . $fm_forward_month . ".htm";
  1143. $htm = $this->showCache ( $path );
  1144. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  1145. $this->data ['isMonth'] = $isMonth;
  1146. $this->data ['htm'] = $htm;
  1147. $this->data ['list'] = $list;
  1148. $this->data ['memu'] = "invoice";
  1149. $this->data ['staff'] = $this->staff;
  1150. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  1151. $this->render ( "/admin/invoiceMyReceivables", $this->data );
  1152. }
  1153. /**
  1154. * 收款绑定发票 ,一个收款只能绑定一个发票
  1155. */
  1156. function invoiceBindReceivables() {
  1157. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  1158. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1159. Doo::loadModel ( 'invoice' );
  1160. $invoice = new invoice ();
  1161. Doo::loadModel ( 'invoiceReceivables' );
  1162. $invoiceReceivables = new invoiceReceivables ();
  1163. Doo::loadModel ( 'invoiceOperationLog' );
  1164. $invoiceOperationLog = new invoiceOperationLog ();
  1165. if (empty ( $invoiceKey ) || empty ( $claimKey ))
  1166. die ( 'illegal request' );
  1167. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  1168. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  1169. if (empty ( $detail ) && empty ( $detailM ))
  1170. die ( 'illegal request' );
  1171. // if ($detailM ['receivablesPrice'] >= $detail ['invoicePrice']) {
  1172. // $price = $detailM ['receivablesPrice'] - $detail ['invoicePrice'];
  1173. // die ( '<p>收款金额超出开票金额 ¥' . $price . '元,请谨慎操作</p><a href="/invoiceMyReceivables">返回</a>' );
  1174. // }
  1175. $item = array (
  1176. 'irid' => $detailM ['irid'],
  1177. 'bindStatus' => 1,
  1178. 'iid' => $detail ['iid'],
  1179. 'bindDate' => date ( "Y-m-d H:i:s" )
  1180. );
  1181. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  1182. $iridString = "";
  1183. if (empty ( $detail ['irid'] ))
  1184. $iridString = $detailM ['irid'];
  1185. else
  1186. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  1187. $item = array (
  1188. 'iid' => $detail ['iid'],
  1189. 'irid' => $iridString
  1190. );
  1191. $invoice->setInvoiceByCondition ( $item );
  1192. // 操作日志
  1193. $item = array (
  1194. 'date' => date ( "Y-m-d H:i:s" ),
  1195. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  1196. 'status' => 8,
  1197. 'img' => $this->staff [0] ['avatar'],
  1198. 'username' => $this->staff [0] ['username'],
  1199. 'uid' => $this->staff [0] ['sid'],
  1200. 'category' => $this->staff [0] ['category'],
  1201. 'iid' => $detail ['iid']
  1202. );
  1203. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1204. return "/invoiceMyReceivables";
  1205. }
  1206. /**
  1207. * 发票收款完成
  1208. */
  1209. function invoiceEnterReceivables() {
  1210. $invoiceKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  1211. // $invoiceClaim = $this->get_args ( 'invoiceClaim' ) ? $this->get_args ( 'invoiceClaim' ) : "";
  1212. Doo::loadModel ( 'invoice' );
  1213. $invoice = new invoice ();
  1214. Doo::loadModel ( 'invoiceOperationLog' );
  1215. $invoiceOperationLog = new invoiceOperationLog ();
  1216. Doo::loadModel ( 'invoiceStatistics' );
  1217. $invoiceStatistics = new invoiceStatistics ();
  1218. Doo::loadModel ( 'invoiceReceivables' );
  1219. $invoiceReceivables = new invoiceReceivables ();
  1220. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  1221. if (empty ( $detail ))
  1222. die ( 'illegal request' );
  1223. if (empty ( $detail ['irid'] ))
  1224. die ( 'illegal request' );
  1225. $item = array (
  1226. 'untreadStatus' => 3,
  1227. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1228. 'iid' => $detail ['iid']
  1229. );
  1230. $invoice->setInvoiceByCondition ( $item );
  1231. // 操作日志
  1232. $item = array (
  1233. 'date' => date ( "Y-m-d H:i:s" ),
  1234. 'operation' => "发票" . $detail ['invoiceSerial'] . "收款完成",
  1235. 'status' => 9,
  1236. 'img' => $this->staff [0] ['avatar'],
  1237. 'username' => $this->staff [0] ['username'],
  1238. 'uid' => $this->staff [0] ['sid'],
  1239. 'category' => $this->staff [0] ['category'],
  1240. 'iid' => $detail ['iid']
  1241. );
  1242. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1243. $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  1244. $accountPrice = 0;
  1245. foreach ( $list as $key => $value ) {
  1246. $accountPrice += $value ['receivablesPrice'];
  1247. }
  1248. $item = array (
  1249. 'date' => date ( "Y-m-d H:i:s" ),
  1250. 'priceClass' => 3,
  1251. 'cid' => $this->staff [0] ['cid'],
  1252. 'staff' => $this->staff [0] ['sid'],
  1253. 'accountPrice' => $accountPrice
  1254. );
  1255. $invoiceStatistics->setInvoiceStatisticsByCondition ( $item );
  1256. return "/invoice";
  1257. }
  1258. function invoiceAggregate() {
  1259. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  1260. Doo::loadModel ( 'invoiceStatistics' );
  1261. $invoiceStatistics = new invoiceStatistics ();
  1262. Doo::loadModel ( 'L_category' );
  1263. $Lcategory = new L_category ();
  1264. $isList = $invoiceStatistics->getInvoiceStatisticsByYear ( $year );
  1265. $LcategoryList = $Lcategory->getCategory ();
  1266. // print_r($isList);
  1267. $html = ""; // $invoicePriceCategory=0;$receivablesPriceCategory=0;$accountPriceCategory=0;
  1268. foreach ( $LcategoryList as $key => $value ) {
  1269. $html .= '<tr><th><a href="/invoiceAggregateCategory/' . $value ['cidKey'] . '">' . $value ['title'] . '</a></th>';
  1270. $month = 1;
  1271. $invoicePriceYear = 0;
  1272. $receivablesPriceYear = 0;
  1273. $accountPriceYear = 0;
  1274. for(; $month <= 12; $month ++) {
  1275. $flag = true;
  1276. foreach ( $isList ['statisticsMonthCid'] as $k => $v ) {
  1277. if ($value ['cid'] == $v ['cid'] && $month == $v ['month']) {
  1278. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  1279. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  1280. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  1281. ';
  1282. $invoicePriceYear += $v ['invoicePrice'];
  1283. $receivablesPriceYear += $v ['receivablesPrice'];
  1284. $accountPriceYear += $v ['accountPrice'];
  1285. $flag = false;
  1286. break;
  1287. }
  1288. }
  1289. if ($flag)
  1290. $html .= '<td class="taR"></td>
  1291. <td class="taR"></td>
  1292. <td class="taR"><b></b></td>
  1293. ';
  1294. }
  1295. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  1296. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  1297. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  1298. ';
  1299. $html .= '</tr>';
  1300. }
  1301. $html .= '<tr><th><b class="colGreen">月合计</b></th>';
  1302. $invoicePriceYear = 0;
  1303. $receivablesPriceYear = 0;
  1304. $accountPriceYear = 0;
  1305. for($month = 1; $month <= 12; $month ++) {
  1306. $flag = true;
  1307. foreach ( $isList ['statisticsMonth'] as $k => $v ) {
  1308. if ($month == $v ['month']) {
  1309. $html .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>
  1310. <td class="taR">¥' . $v ['receivablesPrice'] . '</td>
  1311. <td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>
  1312. ';
  1313. $invoicePriceYear += $v ['invoicePrice'];
  1314. $receivablesPriceYear += $v ['receivablesPrice'];
  1315. $accountPriceYear += $v ['accountPrice'];
  1316. $flag = false;
  1317. break;
  1318. }
  1319. if ($flag)
  1320. $html .= '<td class="taR"></td>
  1321. <td class="taR"></td>
  1322. <td class="taR"><b></b></td>
  1323. ';
  1324. }
  1325. }
  1326. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  1327. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  1328. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  1329. ';
  1330. $html .= '</tr>';
  1331. $this->data ['html'] = $html;
  1332. $this->data ['LcategoryList'] = $LcategoryList;
  1333. $this->data ['isList'] = $isList;
  1334. $this->data ['year'] = $year;
  1335. $this->data ['memu'] = "invoice";
  1336. $this->data ['staff'] = $this->staff;
  1337. $this->data ['receiptMemu'] = 'invoiceAggregate';
  1338. $this->render ( "/admin/invoiceAggregate", $this->data );
  1339. }
  1340. function invoiceAggregateStaff() {
  1341. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  1342. Doo::loadModel ( 'invoiceStatistics' );
  1343. $invoiceStatistics = new invoiceStatistics ();
  1344. Doo::loadModel ( 'L_category' );
  1345. $Lcategory = new L_category ();
  1346. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year );
  1347. $staffList = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year );
  1348. $cStaff = $Lcategory->getCategoryStaff ();
  1349. $html = '';
  1350. foreach ( $cStaff as $key => $value ) {
  1351. $categoryFir = true;
  1352. foreach ( $value ['staff'] as $k => $v ) {
  1353. if ($categoryFir) {
  1354. $width = count ( $value ['staff'] ) + 1;
  1355. $html .= '<tr><th rowspan="' . $width . '">' . $value ['title'] . ' </th>';
  1356. $categoryFir = false;
  1357. } else
  1358. $html .= '<tr>';
  1359. $html .= '<th>' . $v ['username'] . '</th>';
  1360. $invoicePriceStaffYear = 0;
  1361. $receivablesPriceStaffYear = 0;
  1362. $accountPriceStaffYear = 0;
  1363. for($month = 1; $month <= 12; $month ++) {
  1364. $flag = true;
  1365. foreach ( $staffList ['statisticsMonthStaff'] as $sl => $slv ) {
  1366. if ($v ['sid'] == $slv ['staff'] && $month == $slv ['month']) {
  1367. $html .= '<td class="taR">¥' . $slv ['invoicePrice'] . '</td>
  1368. <td class="taR">¥' . $slv ['receivablesPrice'] . '</td>
  1369. <td class="taR"><b>¥' . $slv ['accountPrice'] . '</b></td>
  1370. ';
  1371. $invoicePriceStaffYear += $slv ['invoicePrice'];
  1372. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  1373. $accountPriceStaffYear += $slv ['accountPrice'];
  1374. $flag = false;
  1375. break;
  1376. }
  1377. }
  1378. if ($flag)
  1379. $html .= '<td class="taR"></td>
  1380. <td class="taR"></td>
  1381. <td class="taR"><b></b></td>
  1382. ';
  1383. }
  1384. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  1385. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  1386. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  1387. ';
  1388. }
  1389. $html .= '</tr>';
  1390. // 小计
  1391. if (! empty ( $value ['staff'] )) {
  1392. $html .= '<tr><th class="taR">小计</th>';
  1393. $invoicePriceStaffYear = 0;
  1394. $receivablesPriceStaffYear = 0;
  1395. $accountPriceStaffYear = 0;
  1396. for($month = 1; $month <= 12; $month ++) {
  1397. $flag = true;
  1398. foreach ( $staffList ['statisticsMonthCid'] as $smc => $smcv ) {
  1399. if ($value ['cid'] == $smcv ['cid'] && $month == $slv ['month']) {
  1400. $html .= '<td class="taR">¥' . $smcv ['invoicePrice'] . '</td>
  1401. <td class="taR">¥' . $smcv ['receivablesPrice'] . '</td>
  1402. <td class="taR"><b>¥' . $smcv ['accountPrice'] . '</b></td>
  1403. ';
  1404. $invoicePriceStaffYear += $slv ['invoicePrice'];
  1405. $receivablesPriceStaffYear += $slv ['receivablesPrice'];
  1406. $accountPriceStaffYear += $slv ['accountPrice'];
  1407. $flag = false;
  1408. break;
  1409. }
  1410. }
  1411. if ($flag)
  1412. $html .= '<td class="taR"></td>
  1413. <td class="taR"></td>
  1414. <td class="taR"><b></b></td>
  1415. ';
  1416. }
  1417. $html .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>
  1418. <td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>
  1419. <td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>
  1420. ';
  1421. $html .= '</tr>';
  1422. }
  1423. }
  1424. $html .= '<tr class="warning"><th colspan="2"><b class="colGreen" >月合计</b></th>';
  1425. $invoicePriceYear = 0;
  1426. $receivablesPriceYear = 0;
  1427. $accountPriceYear = 0;
  1428. for($month = 1; $month <= 12; $month ++) {
  1429. $flag = true;
  1430. foreach ( $staffList ['statisticsMonth'] as $k => $v ) {
  1431. if ($month == $v ['month']) {
  1432. $html .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>
  1433. <td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>
  1434. <td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>
  1435. ';
  1436. $invoicePriceYear += $v ['invoicePrice'];
  1437. $receivablesPriceYear += $v ['receivablesPrice'];
  1438. $accountPriceYear += $v ['accountPrice'];
  1439. $flag = false;
  1440. break;
  1441. }
  1442. if ($flag)
  1443. $html .= '<td class="taR"></td>
  1444. <td class="taR"></td>
  1445. <td class="taR"><b></b></td>
  1446. ';
  1447. }
  1448. }
  1449. $html .= '<td class="taR colRed">' . $invoicePriceYear . '</td>
  1450. <td class="taR colOrange">' . $receivablesPriceYear . '</td>
  1451. <td class="taR colGreen"><b>' . $accountPriceYear . '</b></td>
  1452. ';
  1453. $html .= '</tr>';
  1454. $this->data ['html'] = $html;
  1455. $this->data ['isList'] = $toteList;
  1456. $this->data ['year'] = $year;
  1457. $this->data ['memu'] = "invoice";
  1458. $this->data ['staff'] = $this->staff;
  1459. $this->data ['receiptMemu'] = 'invoiceAggregate';
  1460. $this->render ( "/admin/invoiceAggregateStaff", $this->data );
  1461. }
  1462. function invoiceAggregateCategory() {
  1463. Doo::loadClass ( 'XDeode' );
  1464. $XDeode = new XDeode ( 5 );
  1465. $cid = $cidKey = isset ( $this->params ['cid'] ) ? $this->params ['cid'] : "";
  1466. $cid = $XDeode->decode ( $cid );
  1467. if (! is_numeric ( $cid ))
  1468. die ( 'illegal request' );
  1469. $year = $this->get_args ( 'year' ) ? $this->get_args ( 'year' ) : date ( "Y" );
  1470. Doo::loadModel ( 'invoiceStatistics' );
  1471. $invoiceStatistics = new invoiceStatistics ();
  1472. Doo::loadModel ( 'staff' );
  1473. $staff = new staff ();
  1474. $list = $staff->getStaffByCid ( $cid );
  1475. $isCategory = $invoiceStatistics->getInvoiceStatisticsByStaff ( $year, $cid );
  1476. $toteList = $invoiceStatistics->getInvoiceStatisticsByTote ( $year, $cid );
  1477. if (empty ( $list ))
  1478. die ( '该办事处没有成员' );
  1479. $htmlA = $htmlB = $htmlC = $html = '';
  1480. foreach ( $list as $key => $value ) {
  1481. $htmlA = '<tr><th rowspan="3">' . $value ['username'] . '</th><th class="taC">开票</th>';
  1482. $htmlB = '<tr><th class="taC">收款</th>';
  1483. $htmlC = '<tr><th class="taC">入账</th>';
  1484. $invoicePriceStaffYear = 0;
  1485. $receivablesPriceStaffYear = 0;
  1486. $accountPriceStaffYear = 0;
  1487. for($month = 1; $month <= 12; $month ++) {
  1488. $flag = true;
  1489. foreach ( $isCategory ['statisticsMonthStaff'] as $k => $v ) {
  1490. if ($value ['sid'] == $v ['staff'] && $month == $v ['month']) {
  1491. $htmlA .= '<td class="taR">¥' . $v ['invoicePrice'] . '</td>';
  1492. $htmlB .= '<td class="taR">¥' . $v ['receivablesPrice'] . '</td>';
  1493. $htmlC .= '<td class="taR"><b>¥' . $v ['accountPrice'] . '</b></td>';
  1494. $invoicePriceStaffYear += $v ['invoicePrice'];
  1495. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  1496. $accountPriceStaffYear += $v ['accountPrice'];
  1497. $flag = false;
  1498. break;
  1499. }
  1500. }
  1501. if ($flag) {
  1502. $htmlA .= '<td class="taR">-</td>';
  1503. $htmlB .= '<td class="taR">-</td>';
  1504. $htmlC .= '<td class="taR"><b>-</b></td>';
  1505. }
  1506. }
  1507. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  1508. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  1509. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  1510. $htmlA .= '</tr>';
  1511. $htmlB .= '</tr>';
  1512. $htmlC .= '</tr>';
  1513. $html .= $htmlA . $htmlB . $htmlC;
  1514. }
  1515. $htmlA = $htmlB = $htmlC = "";
  1516. $htmlA = '<tr><th rowspan="3">月合计</th><th class="taC">开票</th>';
  1517. $htmlB = '<tr><th class="taC">收款</th>';
  1518. $htmlC = '<tr><th class="taC">入账</th>';
  1519. $invoicePriceStaffYear = 0;
  1520. $receivablesPriceStaffYear = 0;
  1521. $accountPriceStaffYear = 0;
  1522. for($month = 1; $month <= 12; $month ++) {
  1523. $flag = true;
  1524. foreach ( $isCategory ['statisticsMonth'] as $k => $v ) {
  1525. if ($month == $v ['month']) {
  1526. $htmlA .= '<td class="taR colRed">¥' . $v ['invoicePrice'] . '</td>';
  1527. $htmlB .= '<td class="taR colOrange">¥' . $v ['receivablesPrice'] . '</td>';
  1528. $htmlC .= '<td class="taR colGreen"><b>¥' . $v ['accountPrice'] . '</b></td>';
  1529. $invoicePriceStaffYear += $v ['invoicePrice'];
  1530. $receivablesPriceStaffYear += $v ['receivablesPrice'];
  1531. $accountPriceStaffYear += $v ['accountPrice'];
  1532. $flag = false;
  1533. break;
  1534. }
  1535. }
  1536. if ($flag) {
  1537. $htmlA .= '<td class="taR">-</td>';
  1538. $htmlB .= '<td class="taR">-</td>';
  1539. $htmlC .= '<td class="taR"><b>-</b></td>';
  1540. }
  1541. }
  1542. $htmlA .= '<td class="taR colRed">' . $invoicePriceStaffYear . '</td>';
  1543. $htmlB .= '<td class="taR colOrange">' . $receivablesPriceStaffYear . '</td>';
  1544. $htmlC .= '<td class="taR colGreen"><b>' . $accountPriceStaffYear . '</b></td>';
  1545. $htmlA .= '</tr>';
  1546. $htmlB .= '</tr>';
  1547. $htmlC .= '</tr>';
  1548. $html .= $htmlA . $htmlB . $htmlC;
  1549. $this->data ['html'] = $html;
  1550. $this->data ['cidKey'] = $cidKey;
  1551. $this->data ['slist'] = $list;
  1552. $this->data ['isList'] = $toteList;
  1553. $this->data ['year'] = $year;
  1554. $this->data ['memu'] = "invoice";
  1555. $this->data ['staff'] = $this->staff;
  1556. $this->data ['receiptMemu'] = 'invoiceAggregate';
  1557. $this->render ( "/admin/invoiceAggregateCategory", $this->data );
  1558. }
  1559. function invoiceAchieve() {
  1560. Doo::loadModel ( 'invoice' );
  1561. $invoice = new invoice ();
  1562. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  1563. $page_size = 1;
  1564. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1565. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  1566. $get = "/" . $date;
  1567. $con = '';
  1568. if ($date == 'MONTHO')
  1569. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  1570. elseif ($date == 'MONTHT')
  1571. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  1572. elseif ($date == 'MONTHY')
  1573. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  1574. if (! empty ( $MebSea )) {
  1575. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  1576. $get .= "/" . $MebSea;
  1577. }
  1578. $pageinfo ['page'] = array (
  1579. 'previous' => ''
  1580. );
  1581. $sql = 'status=2 and untreadStatus=3 and sid=' . $_COOKIE ["staff"] . $con;
  1582. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceAchieve", $get, "" );
  1583. $limit = $pageinfo ['lower'] . ',' . $page_size;
  1584. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  1585. // print_r($pageinfo);
  1586. $this->data ['MebSeaEn'] = $MebSea;
  1587. $this->data ['MebSea'] = urlencode ( $MebSea );
  1588. $this->data ['get'] = $get;
  1589. $this->data ['page'] = $pageinfo;
  1590. $this->data ['list'] = $list;
  1591. $this->data ['date'] = $date;
  1592. $this->data ['memu'] = "invoice";
  1593. $this->data ['staff'] = $this->staff;
  1594. $this->data ['receiptMemu'] = 'invoice';
  1595. $this->render ( "/admin/invoiceAchieve", $this->data );
  1596. }
  1597. function invoiceReceivablesAchieve() {
  1598. Doo::loadModel ( 'invoiceReceivables' );
  1599. $invoiceReceivables = new invoiceReceivables ();
  1600. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  1601. $page_size = 1;
  1602. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1603. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  1604. $get = "/" . $date;
  1605. $con = '';
  1606. if ($date == 'MONTHO')
  1607. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  1608. elseif ($date == 'MONTHT')
  1609. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  1610. elseif ($date == 'MONTHY')
  1611. $con = ' and bindDate>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  1612. if (! empty ( $MebSea )) {
  1613. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  1614. $get .= "/" . $MebSea;
  1615. }
  1616. $pageinfo ['page'] = array (
  1617. 'previous' => ''
  1618. );
  1619. $sql = " bindStatus=1 and receivablesStaff like '" . $_COOKIE ["staff"] . "_%' " . $con;
  1620. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $sql, $page, $page_size, "invoiceReceivablesAchieve", $get, "" );
  1621. $limit = $pageinfo ['lower'] . ',' . $page_size;
  1622. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $sql );
  1623. // print_r($pageinfo);
  1624. $this->data ['MebSeaEn'] = $MebSea;
  1625. $this->data ['MebSea'] = urlencode ( $MebSea );
  1626. $this->data ['get'] = $get;
  1627. $this->data ['page'] = $pageinfo;
  1628. $this->data ['list'] = $list;
  1629. $this->data ['date'] = $date;
  1630. $this->data ['memu'] = "invoice";
  1631. $this->data ['staff'] = $this->staff;
  1632. $this->data ['receiptMemu'] = 'invoiceMyReceivables';
  1633. $this->render ( "/admin/invoiceReceivablesAchieve", $this->data );
  1634. }
  1635. function invoiceReceivablesAS() {
  1636. Doo::loadModel ( 'invoiceReceivables' );
  1637. $invoiceReceivables = new invoiceReceivables ();
  1638. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  1639. $page_size = 12;
  1640. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1641. $status = isset ( $this->params ['status'] ) ? $this->params ['status'] : 'All';
  1642. $year = isset ( $this->params ['year'] ) && is_numeric ( $this->params ['year'] ) ? $this->params ['year'] : date ( 'Y' );
  1643. $month = isset ( $this->params ['month'] ) && is_numeric ( $this->params ['month'] ) ? $this->params ['month'] : "All";
  1644. $con = "Year(date) =" . $year;
  1645. if ($month != "All")
  1646. $con = "Year(date) =" . $year . " and Month(date) = " . $month;
  1647. if ($status == 'Unclaimed')
  1648. $con .= ' and bindStatus=0';
  1649. elseif ($status == 'Credited')
  1650. $con .= ' and bindStatus=1';
  1651. $get = "/" . $status . "/" . $year . "/" . $month;
  1652. if (! empty ( $MebSea )) {
  1653. $con .= ' and ( receivablesMessage like "%' . $MebSea . '%" or receivablesPrice like "%' . $MebSea . '%" )';
  1654. $get .= "/" . $MebSea;
  1655. }
  1656. $pageinfo ['page'] = array (
  1657. 'previous' => ''
  1658. );
  1659. $pageinfo = $this->get_page ( "CLD_invoiceReceivables", $con, $page, $page_size, "invoiceReceivablesAS", $get, "" );
  1660. $limit = $pageinfo ['lower'] . ',' . $page_size;
  1661. $list = $invoiceReceivables->getReceivablesByUntreadStatusPage ( $limit, $con );
  1662. // print_r($pageinfo);
  1663. $mothHtml = "";
  1664. for($i = 1; $i <= 12; $i ++) {
  1665. if ($month == $i)
  1666. $mothHtml .= '<option selected value="' . $i . '">' . $i . '月</option>';
  1667. else
  1668. $mothHtml .= '<option value="' . $i . '">' . $i . '月</option>';
  1669. }
  1670. $this->data ['MebSeaEn'] = $MebSea;
  1671. $this->data ['MebSea'] = urlencode ( $MebSea );
  1672. $this->data ['mothHtml'] = $mothHtml;
  1673. $this->data ['year'] = $year;
  1674. $this->data ['month'] = $month;
  1675. $this->data ['page'] = $pageinfo;
  1676. $this->data ['get'] = $get;
  1677. $this->data ['list'] = $list;
  1678. $this->data ['status'] = $status;
  1679. $this->data ['memu'] = "invoice";
  1680. $this->data ['staff'] = $this->staff;
  1681. $this->data ['receiptMemu'] = 'invoiceReceivables';
  1682. $this->render ( "/admin/invoiceReceivablesAS", $this->data );
  1683. }
  1684. function invoiceApprovalAchieve() {
  1685. Doo::loadModel ( 'invoice' );
  1686. $invoice = new invoice ();
  1687. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  1688. $page_size = 2;
  1689. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1690. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  1691. $get = "/" . $date;
  1692. $con = '';
  1693. if ($date == 'MONTHO')
  1694. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  1695. elseif ($date == 'MONTHT')
  1696. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  1697. elseif ($date == 'MONTHY')
  1698. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  1699. if (! empty ( $MebSea )) {
  1700. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  1701. $get .= "/" . $MebSea;
  1702. }
  1703. $pageinfo ['page'] = array (
  1704. 'previous' => ''
  1705. );
  1706. $sql = '(status=1 or status=3 or status=4) and processApprovals!=""' . $con;
  1707. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, "invoiceApprovalAchieve", $get, "" );
  1708. $limit = $pageinfo ['lower'] . ',' . $page_size;
  1709. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  1710. // print_r($list);
  1711. $this->data ['MebSeaEn'] = $MebSea;
  1712. $this->data ['MebSea'] = urlencode ( $MebSea );
  1713. $this->data ['get'] = $get;
  1714. $this->data ['page'] = $pageinfo;
  1715. $this->data ['list'] = $list;
  1716. $this->data ['date'] = $date;
  1717. $this->data ['memu'] = "invoice";
  1718. $this->data ['staff'] = $this->staff;
  1719. $this->data ['receiptMemu'] = 'invoiceApproval';
  1720. $this->render ( "/admin/invoiceApprovalAchieve", $this->data );
  1721. }
  1722. function invoiceTAchieve() {
  1723. Doo::loadModel ( 'invoice' );
  1724. $invoice = new invoice ();
  1725. Doo::loadClass ( 'XDeode' );
  1726. $XDeode = new XDeode ( 5 );
  1727. Doo::loadModel ( 'staff' );
  1728. $staff = new staff ();
  1729. $MebSea = isset ( $this->params ['MebSea'] ) ? urldecode ( $this->params ['MebSea'] ) : '';
  1730. $page_size = 2;
  1731. $page = isset ( $this->params ['page'] ) && is_numeric ( $this->params ['page'] ) ? $this->params ['page'] : 1;
  1732. $date = isset ( $this->params ['date'] ) ? $this->params ['date'] : 'MONTHO';
  1733. $get = "/" . $date;
  1734. $con = '';
  1735. if ($date == 'MONTHO')
  1736. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 MONTH)';
  1737. elseif ($date == 'MONTHT')
  1738. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 3 MONTH)';
  1739. elseif ($date == 'MONTHY')
  1740. $con = ' and updateTime>DATE_SUB(CURDATE(), INTERVAL 1 YEAR)';
  1741. if (! empty ( $MebSea )) {
  1742. $con .= ' and ( invoiceTitle like "%' . $MebSea . '%" or invoiceCompany like "%' . $MebSea . '%" or invoicePrice like "%' . $MebSea . '%" )';
  1743. $get .= "/" . $MebSea;
  1744. }
  1745. $pageinfo ['page'] = array (
  1746. 'previous' => ''
  1747. );
  1748. $sql = "";
  1749. $action = "";
  1750. if ($this->ACTION == 'invoicePrintAchieve') {
  1751. $sql = "status=2 and printStatus=1 and moldManage like '%[\"" . $this->staff [0] ['sid'] . "\",%'" . $con;
  1752. $action = "invoicePrintAchieve";
  1753. } elseif ($this->ACTION == 'invoicePostAchieve') {
  1754. // and untreadStatus=0
  1755. $sql = "postStatus=1 and doPost=1 and status=2 and isDelete=0" . $con;
  1756. $action = "invoicePostAchieve";
  1757. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  1758. $sql = " printStatus=1 and untreadStatus=2 and status=2 " . $con;
  1759. $action = "invoiceUntreadAchieve";
  1760. }
  1761. $pageinfo = $this->get_page ( "CLD_invoice", $sql, $page, $page_size, $action, $get, "" );
  1762. $limit = $pageinfo ['lower'] . ',' . $page_size;
  1763. $list = $invoice->getInvoiceByUntreadStatusPage ( $limit, $sql );
  1764. $this->data ['MebSeaEn'] = $MebSea;
  1765. $this->data ['MebSea'] = urlencode ( $MebSea );
  1766. $this->data ['get'] = $get;
  1767. $this->data ['page'] = $pageinfo;
  1768. $this->data ['date'] = $date;
  1769. $this->data ['memu'] = "invoice";
  1770. $this->data ['staff'] = $this->staff;
  1771. if ($this->ACTION == 'invoicePrintAchieve') {
  1772. foreach ( $list as $key => $value ) {
  1773. $list [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  1774. $lastApprover = json_decode ( $value ['processApprovals'], true );
  1775. if (! empty ( $lastApprover )) {
  1776. $lastApproverKey = array_keys ( $lastApprover );
  1777. $lastApprover = end ( $lastApprover );
  1778. $staffDetail = $staff->getOne ( array (
  1779. 'where' => 'sid=' . end ( $lastApproverKey ),
  1780. 'asArray' => true
  1781. ) );
  1782. $lastApprover ['username'] = $staffDetail ['username'];
  1783. }
  1784. $list [$key] ['lastApprover'] = $lastApprover;
  1785. }
  1786. $this->data ['receiptMemu'] = 'invoicePrint';
  1787. $this->data ['list'] = $list;
  1788. $this->render ( "/admin/invoicePrintAchieve", $this->data );
  1789. } elseif ($this->ACTION == 'invoicePostAchieve') {
  1790. Doo::loadModel ( 'express' );
  1791. $express = new express ();
  1792. $expressList = $express->getExpressByAll ();
  1793. $this->data ['expressList'] = $expressList;
  1794. $this->data ['receiptMemu'] = 'invoicePost';
  1795. $this->data ['list'] = $list;
  1796. $this->render ( "/admin/invoicePostAchieve", $this->data );
  1797. } elseif ($this->ACTION == 'invoiceUntreadAchieve') {
  1798. $this->data ['receiptMemu'] = 'invoiceUntread';
  1799. $this->data ['list'] = $list;
  1800. $this->render ( "/admin/invoiceUntreadAchieve", $this->data );
  1801. }
  1802. }
  1803. /**
  1804. * 获得与我有关可收款的发票
  1805. */
  1806. function ajaxGetInvoiceByStaff() {
  1807. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  1808. Doo::loadModel ( 'invoice' );
  1809. $invoice = new invoice ();
  1810. $list = $invoice->getInvoiceByReceivables ( $this->staff [0] ['sid'] );
  1811. $html = "";
  1812. $i = 1;
  1813. foreach ( $list as $key => $value ) {
  1814. $html .= '<tr>
  1815. <td>' . $value ['invoiceElement'] . '</td>
  1816. <td>¥' . $value ['invoicePrice'] . '</td>';
  1817. if (! empty ( $value ['invoiceType'] )) {
  1818. $html .= '<td>增值税专用发票</td>
  1819. <td>' . $value ['invoiceCompany'] . '</td>';
  1820. } else {
  1821. $html .= '<td>增值税普通发票</td>
  1822. <td>' . $value ['invoiceTitle'] . '</td>';
  1823. }
  1824. $html .= '<td><label><input type="radio" node-Claim="true_' . $i . '" p-data="' . $value ['iidKey'] . '" name="invoiceClaim"> 使用Ta</label></td></tr>
  1825. <script>
  1826. $(\'input[node-Claim="true_' . $i . '"]\').click(function() {
  1827. var invoiceKey= $(this).attr("p-data");
  1828. var claimKey=$("input[name=\'key\']").val();
  1829. $("p[node-msg=\"true\"]").hide();
  1830. var url = "/ajaxCompareInvoicePrice";
  1831. $.ajax({
  1832. url : url,
  1833. type : "post",
  1834. cache : false,
  1835. dataType : "json",
  1836. data : {
  1837. claimKey : claimKey,
  1838. invoiceKey:invoiceKey
  1839. },
  1840. global : true,
  1841. success : function(data) {
  1842. $("input[name=\'invoiceKey\']").val("' . $value ['iidKey'] . '");
  1843. if (data.status == 1) {
  1844. $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。");
  1845. $("p[node-msg=\"true\"]").show();
  1846. }
  1847. },
  1848. error : function(err) {
  1849. }
  1850. });
  1851. });
  1852. </script>
  1853. ';
  1854. $i ++;
  1855. }
  1856. echo json_encode ( array (
  1857. 'status' => 1,
  1858. 'html' => $html
  1859. ) );
  1860. }
  1861. /**
  1862. * 获取一条收款信息
  1863. */
  1864. function ajaxGetInvoiceReceivables() {
  1865. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  1866. Doo::loadModel ( 'invoiceReceivables' );
  1867. $invoiceReceivables = new invoiceReceivables ();
  1868. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  1869. echo json_encode ( array (
  1870. 'status' => 1,
  1871. 'detail' => $detail
  1872. ) );
  1873. }
  1874. /**
  1875. * 异步获取办事处用户
  1876. */
  1877. function ajaxGetStaffByCategory() {
  1878. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  1879. Doo::loadModel ( 'staff' );
  1880. $staff = new staff ();
  1881. if ($cid == "PUBLIC") {
  1882. echo json_encode ( array (
  1883. 'status' => 1,
  1884. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  1885. ) );
  1886. die ();
  1887. }
  1888. if (! is_numeric ( $cid )) {
  1889. echo json_encode ( array (
  1890. 'status' => 0,
  1891. 'msg' => 'illegal request'
  1892. ) );
  1893. die ();
  1894. }
  1895. $staffList = $staff->getStaffByCid ( $cid );
  1896. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  1897. foreach ( $staffList as $key => $value ) {
  1898. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  1899. }
  1900. echo json_encode ( array (
  1901. 'status' => 1,
  1902. 'html' => $html
  1903. ) );
  1904. }
  1905. /**
  1906. * 异步获取一条发票的邮寄信息
  1907. */
  1908. function ajaxGetInvoicePostDetail() {
  1909. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  1910. Doo::loadModel ( 'invoice' );
  1911. $invoice = new invoice ();
  1912. $iid = $invoice->authcode ( $iid );
  1913. Doo::loadModel ( 'express' );
  1914. $express = new express ();
  1915. $expressList = $express->getExpressByAll ();
  1916. if (! is_numeric ( $iid )) {
  1917. echo json_encode ( array (
  1918. 'status' => 0,
  1919. 'msg' => 'illegal request'
  1920. ) );
  1921. die ();
  1922. }
  1923. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  1924. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  1925. $html = "";
  1926. foreach ( $expressList as $key => $value ) {
  1927. if ($value ['company'] == $invoiceDetail ['expressCompany'])
  1928. $html .= '<option selected value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  1929. else
  1930. $html .= '<option value="' . $value ['company'] . ':' . $value ['com'] . '">' . $value ['company'] . '</option>';
  1931. }
  1932. $invoiceDetail ['eaHtml'] = $html;
  1933. echo json_encode ( array (
  1934. 'status' => 1,
  1935. 'invoiceDetail' => $invoiceDetail
  1936. ) );
  1937. }
  1938. function ajaxCompareClaimPrice() {
  1939. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  1940. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1941. Doo::loadModel ( 'invoice' );
  1942. $invoice = new invoice ();
  1943. Doo::loadModel ( 'invoiceReceivables' );
  1944. $invoiceReceivables = new invoiceReceivables ();
  1945. Doo::loadModel ( 'invoiceOperationLog' );
  1946. $invoiceOperationLog = new invoiceOperationLog ();
  1947. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  1948. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  1949. if (empty ( $detail ) || empty ( $detailM )) {
  1950. echo json_encode ( array (
  1951. 'status' => 2,
  1952. 'msg' => '非法请求,请重新登录'
  1953. ) );
  1954. die ();
  1955. }
  1956. $iridString = "";
  1957. if (empty ( $detail ['irid'] ))
  1958. $iridString = $detailM ['irid'];
  1959. else
  1960. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  1961. $item = array (
  1962. 'irid' => $iridString,
  1963. 'bindTime' => date ( "Y-m-d H:i:s" ),
  1964. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1965. 'iid' => $detail ['iid']
  1966. );
  1967. $invoice->setInvoiceByCondition ( $item );
  1968. // 操作日志
  1969. $item = array (
  1970. 'date' => date ( "Y-m-d H:i:s" ),
  1971. 'operation' => "收款入账" . $detailM ['receivablesSerial'] . "到发票" . $detail ['invoiceSerial'],
  1972. 'status' => 8,
  1973. 'img' => $this->staff [0] ['avatar'],
  1974. 'username' => $this->staff [0] ['username'],
  1975. 'uid' => $this->staff [0] ['sid'],
  1976. 'category' => $this->staff [0] ['category'],
  1977. 'iid' => $detail ['iid']
  1978. );
  1979. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1980. $item = array (
  1981. 'iid' => $detail ['iid'],
  1982. 'irid' => $detailM ['irid'],
  1983. 'bindDate' => date ( "Y-m-d H:i:s" ),
  1984. 'bindStatus' => 1
  1985. );
  1986. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  1987. $price = 0;
  1988. $priceStatus = 0;
  1989. $isReceivables = 0;
  1990. $invoiceReceivables = new invoiceReceivables ();
  1991. $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  1992. if (! empty ( $list ))
  1993. $isReceivables = 1;
  1994. $receivablesPrice = 0;
  1995. foreach ( $list as $key => $value ) {
  1996. $receivablesPrice += $value ['receivablesPrice'];
  1997. }
  1998. if ($receivablesPrice > $detail ['invoicePrice']) {
  1999. $price = $receivablesPrice - $detail ['invoicePrice'];
  2000. $priceStatus = 1;
  2001. } elseif ($receivablesPrice < $detail ['invoicePrice']) {
  2002. $price = $detail ['invoicePrice'] - $receivablesPrice;
  2003. $priceStatus = 2;
  2004. }
  2005. echo json_encode ( array (
  2006. 'status' => 1,
  2007. 'html' => '<tr><td>¥' . $detailM ['receivablesPrice'] . '</td><td>' . $detailM ['receivablesMessage'] . '</td><td>' . $detailM ['receivablesBank'] . '</td>
  2008. <td>' . $detailM ['receivablesDate'] . '</td><td><a node-remove="Da' . $detailM ['iridKey'] . '" href="javascript:void(0);">移除</a></td></tr>
  2009. <script>
  2010. $(\'a[node-remove="Da' . $detailM ['iridKey'] . '"]\').click(function() {
  2011. var invoiceKey=$("input[name=\'key\']").val();
  2012. var irid= $(this).attr("p-data");
  2013. var iridKey="' . $detailM ["iridEn"] . '";
  2014. var element=($(this));
  2015. $("p[node-loading=\"true\"]").show();
  2016. $("p[node-loading=\"true\"]").html("移除处理中...");
  2017. $("p[node-msg=\"true2\"]").hide();
  2018. $("p[node-msg=\"true\"]").hide();
  2019. var url = "/ajaxReceivablesRemove";
  2020. $.ajax({
  2021. url : url,
  2022. type : "post",
  2023. cache : false,
  2024. dataType : "json",
  2025. data : {
  2026. key : iridKey,
  2027. invoiceKey:invoiceKey
  2028. },
  2029. global : true,
  2030. success : function(data) {
  2031. $("input[name=\'invoiceKey\']").val("' . $detailM ['iridEn'] . '");
  2032. if (data.status == 1) {
  2033. $(element).parent().parent().remove();
  2034. $("tbody[data-invoice=\"myReceivables\"]").append(data.html);
  2035. $("p[node-loading=\"true\"]").hide();
  2036. if(data.priceStatus == 1){
  2037. $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。");
  2038. $("p[node-msg=\"true\"]").show();
  2039. }else if(data.priceStatus == 2&& data.isReceivables != 0){
  2040. $("p[node-msg=\"true\"]").html("收款金额少于开票金额 ¥"+data.price+"元,请谨慎操作。");
  2041. $("p[node-msg=\"true\"]").show();
  2042. }
  2043. }else if(data.status == 2){
  2044. $("p[node-loading=\"true\"]").html(data.msg);
  2045. }
  2046. },
  2047. error : function(err) {
  2048. }
  2049. });
  2050. });
  2051. </script>
  2052. ',
  2053. 'price' => $price,
  2054. 'priceStatus' => $priceStatus,
  2055. 'isReceivables' => $isReceivables
  2056. ) );
  2057. }
  2058. /**
  2059. * 从发票中移除已经入账的收款
  2060. */
  2061. function ajaxReceivablesRemove() {
  2062. $iridKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  2063. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2064. Doo::loadModel ( 'invoice' );
  2065. $invoice = new invoice ();
  2066. Doo::loadModel ( 'invoiceReceivables' );
  2067. $invoiceReceivables = new invoiceReceivables ();
  2068. Doo::loadModel ( 'invoiceOperationLog' );
  2069. $invoiceOperationLog = new invoiceOperationLog ();
  2070. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  2071. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridKey );
  2072. // echo $detail['irid']."<br/>";
  2073. $invoiceIrid = explode ( ",", $detail ['irid'] );
  2074. foreach ( $invoiceIrid as $key => $value ) {
  2075. if ($value == $detailM ['irid'])
  2076. unset ( $invoiceIrid [$key] );
  2077. }
  2078. $invoiceIrid = implode ( ",", $invoiceIrid );
  2079. // echo $invoiceIrid."ddd";
  2080. // print_r($invoiceIrid);
  2081. $item = array (
  2082. 'irid' => $invoiceIrid,
  2083. 'iid' => $detail ['iid']
  2084. );
  2085. $invoice->setInvoiceByCondition ( $item );
  2086. $item = array (
  2087. 'iid' => 0,
  2088. 'irid' => $detailM ['irid'],
  2089. 'bindDate' => '',
  2090. 'bindStatus' => 0
  2091. );
  2092. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  2093. // 操作日志
  2094. $item = array (
  2095. 'date' => date ( "Y-m-d H:i:s" ),
  2096. 'operation' => "收款移除" . $detailM ['receivablesSerial'],
  2097. 'status' => 10,
  2098. 'img' => $this->staff [0] ['avatar'],
  2099. 'username' => $this->staff [0] ['username'],
  2100. 'uid' => $this->staff [0] ['sid'],
  2101. 'category' => $this->staff [0] ['category'],
  2102. 'iid' => $detail ['iid']
  2103. );
  2104. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  2105. $price = 0;
  2106. $priceStatus = 0;
  2107. $isReceivables = 0;
  2108. $invoiceReceivables = new invoiceReceivables ();
  2109. $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $invoiceIrid );
  2110. if (! empty ( $list ))
  2111. $isReceivables = 1;
  2112. $receivablesPrice = 0;
  2113. foreach ( $list as $key => $value ) {
  2114. $receivablesPrice += $value ['receivablesPrice'];
  2115. }
  2116. if ($receivablesPrice > $detail ['invoicePrice']) {
  2117. $price = $receivablesPrice - $detail ['invoicePrice'];
  2118. $priceStatus = 1;
  2119. } elseif ($receivablesPrice < $detail ['invoicePrice']) {
  2120. $price = $detail ['invoicePrice'] - $receivablesPrice;
  2121. $priceStatus = 2;
  2122. }
  2123. echo json_encode ( array (
  2124. 'status' => 1,
  2125. 'html' => '<tr id="' . $detailM ['receivablesSerial'] . '" >
  2126. <td>¥' . $detailM ['receivablesPrice'] . '</td>
  2127. <td>' . $detailM ['receivablesMessage'] . '</td>
  2128. <td>' . $detailM ['receivablesBank'] . '</td>
  2129. <td>' . $detailM ['receivablesDate'] . '</td><td>
  2130. <a href="javascript:void(0)" node-Claim="true_' . $detailM ['iridKey'] . '" p-data="' . $detailM ['iridEn'] . '" name="invoiceClaim" class="button">入账</a>
  2131. </td></tr>
  2132. <script>
  2133. $(\'a[node-Claim="true_' . $detailM ['iridKey'] . '"]\').click(function() {
  2134. var invoiceKey=$("input[name=\'key\']").val();
  2135. var irid= $(this).attr("p-data");
  2136. var element=($(this));
  2137. $("p[node-loading=\"true\"]").show();
  2138. $("p[node-loading=\"true\"]").html("入账处理中...");
  2139. $("p[node-msg=\"true2\"]").hide();
  2140. $("p[node-msg=\"true\"]").hide();
  2141. var url = "/ajaxCompareClaimPrice";
  2142. $.ajax({
  2143. url : url,
  2144. type : "post",
  2145. cache : false,
  2146. dataType : "json",
  2147. data : {
  2148. irid : irid,
  2149. invoiceKey:invoiceKey
  2150. },
  2151. global : true,
  2152. success : function(data) {
  2153. $("input[name=\'invoiceKey\']").val("' . $detailM ['iridEn'] . '");
  2154. if (data.status == 1) {
  2155. $(element).parent().parent().remove();
  2156. $("tbody[box-enter=\"true\"]").append(data.html);
  2157. $("p[node-loading=\"true\"]").hide();
  2158. if(data.priceStatus == 1){
  2159. $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。");
  2160. $("p[node-msg=\"true\"]").show();
  2161. }else if(data.priceStatus == 2&& data.isReceivables != 0){
  2162. $("p[node-msg=\"true\"]").html("收款金额少于开票金额 ¥"+data.price+"元,请谨慎操作。");
  2163. $("p[node-msg=\"true\"]").show();
  2164. }
  2165. }else if(data.status == 2){
  2166. $("p[node-loading=\"true\"]").html(data.msg);
  2167. }
  2168. },
  2169. error : function(err) {
  2170. }
  2171. });
  2172. });
  2173. </script>
  2174. ',
  2175. 'price' => $price,
  2176. 'priceStatus' => $priceStatus,
  2177. 'isReceivables' => $isReceivables
  2178. ) );
  2179. }
  2180. /**
  2181. * 我的收款中 选择哪个发票入账,进行金额判断
  2182. */
  2183. function ajaxCompareInvoicePrice() {
  2184. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  2185. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  2186. Doo::loadModel ( 'invoice' );
  2187. $invoice = new invoice ();
  2188. Doo::loadModel ( 'invoiceReceivables' );
  2189. $invoiceReceivables = new invoiceReceivables ();
  2190. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  2191. $keyList = explode ( ';', $claimKey );
  2192. $receivablesPrice = 0;
  2193. foreach ( $keyList as $key => $value ) {
  2194. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  2195. $receivablesPrice += $detailM ['receivablesPrice'];
  2196. }
  2197. if ($receivablesPrice > $detail ['invoicePrice']) {
  2198. $price = $receivablesPrice - $detail ['invoicePrice'];
  2199. echo json_encode ( array (
  2200. 'status' => 1,
  2201. 'price' => $price
  2202. ) );
  2203. } else
  2204. echo json_encode ( array (
  2205. 'status' => 2
  2206. ) );
  2207. }
  2208. /*
  2209. * 获得与我有关收款数据
  2210. */
  2211. function ajaxGetReceivalblesByStaff() {
  2212. $iid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  2213. Doo::loadModel ( 'invoiceReceivables' );
  2214. $invoiceReceivables = new invoiceReceivables ();
  2215. Doo::loadModel ( 'invoice' );
  2216. $invoice = new invoice ();
  2217. $detail = $invoice->getInvoiceByIid ( $iid );
  2218. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  2219. $html = "";
  2220. $i = 1;
  2221. foreach ( $list ['myClaim'] as $key => $value ) {
  2222. $html .= '<tr id="' . $value ['receivablesSerial'] . '" >
  2223. <td>¥' . $value ['receivablesPrice'] . '</td>
  2224. <td>' . $value ['receivablesMessage'] . '</td>
  2225. <td>' . $value ['receivablesBank'] . '</td>
  2226. <td>' . $value ['receivablesDate'] . '</td>';
  2227. $html .= '<td>
  2228. <a href="javascript:void(0)" node-Claim="true_' . $i . '" p-data="' . $value ['iidKey'] . '" name="invoiceClaim" class="button">入账</a>
  2229. </td></tr>
  2230. <script>
  2231. $(\'a[node-Claim="true_' . $i . '"]\').click(function() {
  2232. var invoiceKey=$("input[name=\'key\']").val();
  2233. var irid= $(this).attr("p-data");
  2234. var element=($(this));
  2235. $("p[node-loading=\"true\"]").show();
  2236. $("p[node-loading=\"true\"]").html("入账处理中...");
  2237. $("p[node-msg=\"true2\"]").hide();
  2238. $("p[node-msg=\"true\"]").hide();
  2239. var url = "/ajaxCompareClaimPrice";
  2240. $.ajax({
  2241. url : url,
  2242. type : "post",
  2243. cache : false,
  2244. dataType : "json",
  2245. data : {
  2246. irid : irid,
  2247. invoiceKey:invoiceKey
  2248. },
  2249. global : true,
  2250. success : function(data) {
  2251. $("input[name=\'invoiceKey\']").val("' . $value ['iidKey'] . '");
  2252. if (data.status == 1) {
  2253. $(element).parent().parent().remove();
  2254. $("tbody[box-enter=\"true\"]").append(data.html);
  2255. $("p[node-loading=\"true\"]").hide();
  2256. if(data.priceStatus == 1){
  2257. $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。");
  2258. $("p[node-msg=\"true\"]").show();
  2259. }else if(data.priceStatus == 2&& data.isReceivables != 0){
  2260. $("p[node-msg=\"true\"]").html("收款金额少于开票金额 ¥"+data.price+"元,请谨慎操作。");
  2261. $("p[node-msg=\"true\"]").show();
  2262. }
  2263. }else if(data.status == 2){
  2264. $("p[node-loading=\"true\"]").html(data.msg);
  2265. }
  2266. },
  2267. error : function(err) {
  2268. }
  2269. });
  2270. });
  2271. </script>
  2272. ';
  2273. $i ++;
  2274. }
  2275. $html2 = "";
  2276. $list2 = $invoiceReceivables->getInvoiceReceivablesByIid ( $iid, 1 );
  2277. foreach ( $list2 as $key => $value ) {
  2278. $html2 .= '<tr id="' . $value ['receivablesSerial'] . '" >
  2279. <td>¥' . $value ['receivablesPrice'] . '</td>
  2280. <td>' . $value ['receivablesMessage'] . '</td>
  2281. <td>' . $value ['receivablesBank'] . '</td>
  2282. <td>' . $value ['receivablesDate'] . '</td>';
  2283. $html2 .= '<td>
  2284. <a href="javascript:void(0)" node-remove="Da' . $value ['iridKey'] . '" >移除</a>
  2285. </td></tr>
  2286. <script>
  2287. $(\'a[node-remove="Da' . $value ['iridKey'] . '"]\').click(function() {
  2288. var invoiceKey=$("input[name=\'key\']").val();
  2289. var irid= $(this).attr("p-data");
  2290. var iridKey="' . $value ["iidKey"] . '";
  2291. var element=($(this));
  2292. $("p[node-loading=\"true\"]").show();
  2293. $("p[node-loading=\"true\"]").html("移除处理中...");
  2294. $("p[node-msg=\"true2\"]").hide();
  2295. $("p[node-msg=\"true\"]").hide();
  2296. var url = "/ajaxReceivablesRemove";
  2297. $.ajax({
  2298. url : url,
  2299. type : "post",
  2300. cache : false,
  2301. dataType : "json",
  2302. data : {
  2303. key : iridKey,
  2304. invoiceKey:invoiceKey
  2305. },
  2306. global : true,
  2307. success : function(data) {
  2308. $("input[name=\'invoiceKey\']").val("' . $value ['iidKey'] . '");
  2309. if (data.status == 1) {
  2310. $(element).parent().parent().remove();
  2311. $("tbody[data-invoice=\"myReceivables\"]").append(data.html);
  2312. $("p[node-loading=\"true\"]").hide();
  2313. if(data.priceStatus == 1){
  2314. $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。");
  2315. $("p[node-msg=\"true\"]").show();
  2316. }else if(data.priceStatus == 2&& data.isReceivables != 0){
  2317. $("p[node-msg=\"true\"]").html("收款金额少于开票金额 ¥"+data.price+"元,请谨慎操作。");
  2318. $("p[node-msg=\"true\"]").show();
  2319. }
  2320. }else if(data.status == 2){
  2321. $("p[node-loading=\"true\"]").html(data.msg);
  2322. }
  2323. },
  2324. error : function(err) {
  2325. }
  2326. });
  2327. });
  2328. </script>
  2329. ';
  2330. $i ++;
  2331. }
  2332. $price = 0;
  2333. $priceStatus = 0;
  2334. $isReceivables = 0;
  2335. $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  2336. if (! empty ( $list ))
  2337. $isReceivables = 1;
  2338. $receivablesPrice = 0;
  2339. foreach ( $list as $key => $value ) {
  2340. $receivablesPrice += $value ['receivablesPrice'];
  2341. }
  2342. if ($receivablesPrice > $detail ['invoicePrice']) {
  2343. $price = $receivablesPrice - $detail ['invoicePrice'];
  2344. $priceStatus = 1;
  2345. } elseif ($receivablesPrice < $detail ['invoicePrice']) {
  2346. $price = $detail ['invoicePrice'] - $receivablesPrice;
  2347. $priceStatus = 2;
  2348. }
  2349. echo json_encode ( array (
  2350. 'status' => 1,
  2351. 'html' => $html,
  2352. 'html2' => $html2,
  2353. 'price' => $price,
  2354. 'priceStatus' => $priceStatus,
  2355. 'isReceivables' => $isReceivables
  2356. ) );
  2357. }
  2358. function ajaxGetInvoiceInfoByType() {
  2359. $type = $this->get_args ( 'type' ) ? $this->get_args ( 'type' ) : "";
  2360. $serial = $this->get_args ( 'serial' ) ? $this->get_args ( 'serial' ) : "";
  2361. if (empty ( $serial )) {
  2362. echo json_encode ( array (
  2363. 'status' => 2,
  2364. 'msg' => 'illegal request'
  2365. ) );
  2366. die ();
  2367. }
  2368. if ($type == 'INVOICE') {
  2369. Doo::loadModel ( 'invoice' );
  2370. $invoice = new invoice ();
  2371. Doo::loadModel ( 'invoiceOperationLog' );
  2372. $invoiceOperationLog = new invoiceOperationLog ();
  2373. $detail = $invoice->getInvoiceByIsid ( $serial, $this->staff [0] ['sid'] );
  2374. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $detail ['iid'] );
  2375. if (empty ( $detail ))
  2376. $html = '';
  2377. else {
  2378. $html = '
  2379. <div class="modal-dialog modal-lg">
  2380. <div class="modal-content"><div class="modal-header"><h3>发票单详情</h3></div>
  2381. <div class="modal-body saeaList"><table class="table table-bordered table-condensed"><tbody>
  2382. <tr>
  2383. <th class="taC" width="150">开票流水号</th><td>' . $detail ['invoiceSerial'] . '</td>
  2384. <th class="taC" width="150">提交时间</th><td>' . $detail ['date'] . '</td>
  2385. </tr>
  2386. <tr>
  2387. <th class="taC" width="150">所在办事处</th><td>' . $detail ['categoryName'] . '(' . $detail ['userName'] . ')</td>
  2388. <th class="taC" width="150">备注</th><td>' . $detail ['remark'] . '</td>
  2389. </tr>
  2390. <tr>
  2391. <th class="taC">开票金额</th><td><b class="colOrange" style="font-size:18px">¥' . $detail ['invoicePrice'] . '</b></td>
  2392. <th class="taC">开票内容</th><td>' . $detail ['invoiceElement'] . '</td>
  2393. </tr></tbody></table>';
  2394. if ($detail ['invoiceType'] == 0)
  2395. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">增值税普通发票</th></tr><tr>
  2396. <th class="taC" width="150">发票抬头</th><td colspan="3">' . $detail ['invoiceTitle'] . '</td></tr></tbody></table>';
  2397. else
  2398. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">增值税专用发票</th></tr><tr>
  2399. <th class="taC" width="150">单位名称</th><td>' . $detail ['invoiceCompany'] . '</td>
  2400. <th class="taC" width="150">纳税人识别码</th><td>' . $detail ['TIN'] . '</td></tr><tr>
  2401. <th class="taC">注册地址</th><td>' . $detail ['address'] . '</td>
  2402. <th class="taC">注册电话</th><td>' . $detail ['phone'] . '</td>
  2403. </tr><tr>
  2404. <th class="taC">开户银行</th><td>' . $detail ['bankAccount'] . '</td>
  2405. <th class="taC">银行账户</th><td>' . $detail ['bank'] . '</td>
  2406. </tr></tbody></table>';
  2407. if ($detail ['doPost'] == 1)
  2408. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th colspan="4" class="taC">邮寄信息</th></tr><tr>
  2409. <th class="taC" width="150">收件人</th><td>' . $detail ['recipients'] . '</td>
  2410. <th class="taC" width="150">收件人手机/电话</th><td>' . $detail ['recipientsPhone'] . '</td>
  2411. </tr><tr>
  2412. <th class="taC" width="150">收件地址</th><td colspan="3">' . $detail ['recipientsAddress'] . '</td>
  2413. </tr><tr>
  2414. <th class="taC" width="150">邮寄物品</th><td colspan="3">' . $detail ['mailItems'] . '</td>
  2415. </tr></tbody></table>';
  2416. if (! empty ( $invoiceOperationLogList )) {
  2417. $html .= '<table class="table table-bordered table-condensed"><tbody><tr><th width="60%" class="taC">审批流程</th></tr><tr><td>';
  2418. foreach ( $invoiceOperationLogList as $key => $value ) {
  2419. $html .= '<blockquote><p><span class="colGray">' . $value ['date'] . '</span>&nbsp;
  2420. ' . $value ['category'] . '-' . $value ['username'] . '&nbsp;';
  2421. if ($value ['status'] == 2) {
  2422. $html .= '<span class="colGreen">同意</span>';
  2423. } elseif ($value ['status'] == 3) {
  2424. $html .= '<span class="colOrange">退回</span>';
  2425. } elseif ($value ['status'] == 5) {
  2426. $html .= '<span class="colGreen">打印</span>';
  2427. }
  2428. $html .= $value ['operation'] . '</p></blockquote>';
  2429. }
  2430. $html .= '</td></tr></tbody></table>';
  2431. }
  2432. $html .= '</div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  2433. }
  2434. echo json_encode ( array (
  2435. 'status' => 1,
  2436. 'html' => $html
  2437. ) );
  2438. die ();
  2439. } elseif ($type == 'RECEIVABLES') {
  2440. Doo::loadModel ( 'invoiceReceivables' );
  2441. $invoiceReceivables = new invoiceReceivables ();
  2442. $detail = $invoiceReceivables->getInvoiceReceivablesByIrsid ( $serial, $this->staff [0] ['sid'] );
  2443. if (empty ( $detail ))
  2444. $html = '';
  2445. else {
  2446. $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">
  2447. <tbody><tr>
  2448. <th class="taC">收款流水号</th><td>' . $detail ['receivablesSerial'] . '</td>
  2449. <th class="taC">录入收款</th><td>' . $detail ['inputStaff'] . ' ' . $detail ['date'] . '</td>
  2450. </tr><tr>
  2451. <th class="taC">收款金额</th><td><b>¥' . $detail ['receivablesPrice'] . '</b></td>
  2452. <th class="taC">收款信息</th><td>' . $detail ['receivablesMessage'] . '</td>
  2453. </tr>
  2454. <tr>
  2455. <th class="taC">收款银行</th><td>' . $detail ['receivablesBank'] . '</td>
  2456. <th class="taC">银行到帐</th><td>' . $detail ['receivablesDate'] . '</td>
  2457. </tr>
  2458. <tr>
  2459. <th class="taC">认领收款</th><td colspan="3">' . $detail ['inputStaff'] . ' 转入 ' . $detail ['username'] . ' ' . $detail ['bindDate'] . '</td>
  2460. </tr>
  2461. </tbody></table></div><div class="modal-footer"><a href="#" class="button btn-gray" data-dismiss="modal" aria-hidden="true">关闭</a></div></div></div>';
  2462. }
  2463. echo json_encode ( array (
  2464. 'status' => 1,
  2465. 'html' => $html
  2466. ) );
  2467. die ();
  2468. }
  2469. }
  2470. function ajaxGetInvoiceReceivablesByStaff() {
  2471. $postData = $this->get_args ( 'postData' ) ? $this->get_args ( 'postData' ) : "";
  2472. if (empty ( $postData )) {
  2473. echo json_encode ( array (
  2474. 'status' => 2,
  2475. 'msg' => 'illegal request'
  2476. ) );
  2477. die ();
  2478. }
  2479. Doo::loadModel ( 'invoiceReceivables' );
  2480. $invoiceReceivables = new invoiceReceivables ();
  2481. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $postData );
  2482. if (empty ( $detail )) {
  2483. echo json_encode ( array (
  2484. 'status' => 2,
  2485. 'msg' => 'illegal request'
  2486. ) );
  2487. die ();
  2488. }
  2489. Doo::loadModel ( 'L_category' );
  2490. $lCategory = new L_category ();
  2491. Doo::loadModel ( 'staff' );
  2492. $staff = new staff ();
  2493. $staffList = $staff->getStaffByCid ( $detail ['cid'] );
  2494. $category = $lCategory->getCategory ();
  2495. $categoryHtml = '<option post-data="PUBLIC" value="PUBLIC" >公共待认领款项</option>';
  2496. $staffHtml = '<option value="PUBLIC">办事处待认领款项</option>';
  2497. foreach ( $category as $key => $value ) {
  2498. $categoryHtml .= '<option post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  2499. if ($value ['cid'] == $detail ['cid'])
  2500. $categoryHtml .= '<option selected post-data="' . $value ['cid'] . '" value="' . $value ['cid'] . ':' . $value ['title'] . '" >' . $value ['title'] . '</option>';
  2501. }
  2502. foreach ( $staffList as $key => $value ) {
  2503. $staffHtml .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  2504. if ($value ['sid'] == $detail ['sid'])
  2505. $staffHtml .= '<option selected value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  2506. }
  2507. $rbankHtml = '<option value="广发银行珠海分行柠溪支行">广发银行珠海分行柠溪支行</option>';
  2508. echo json_encode ( array (
  2509. 'status' => 1,
  2510. 'categoryHtml' => $categoryHtml,
  2511. 'staffHtml' => $staffHtml,
  2512. 'rbankHtml' => $rbankHtml,
  2513. 'detail' => $detail
  2514. ) );
  2515. }
  2516. function _GetFileEXT($filename) {
  2517. $pics = explode ( '.', $filename );
  2518. $num = count ( $pics );
  2519. return $pics [$num - 1];
  2520. }
  2521. function showCache($path = "") {
  2522. if (file_exists ( $path )) {
  2523. $htm = file_get_contents ( $path );
  2524. } else {
  2525. Doo::loadModel ( 'invoiceStatistics' );
  2526. $invoiceStatistics = new invoiceStatistics ();
  2527. $isBriefly = $invoiceStatistics->getBrieflyStatistics ();
  2528. $htm = '<tr><th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计开票</th>
  2529. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['invoicePrice'] . '</td>
  2530. <th class="taC">' . $isBriefly ['statisticsMonth'] [0] ['month'] . '月累计入账</th>
  2531. <td>¥' . $isBriefly ['statisticsMonth'] [0] ['accountPrice'] . '</td></tr>';
  2532. /*
  2533. * '<tr><th class="taC">今年累计开票</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['invoicePrice'] . '</td> <th class="taC">今年累计入账</th><td>¥' . $isBriefly ['statisticsYear'] [0] ['accountPrice'] . '</td></tr>';
  2534. */
  2535. file_put_contents ( $path, $htm, FILE_APPEND );
  2536. }
  2537. return $htm;
  2538. }
  2539. /**
  2540. * 获取get或者POST值
  2541. *
  2542. * @param string $name 属性名称
  2543. * @return fixed 值
  2544. */
  2545. function get_args($name) {
  2546. if (isset ( $_GET [$name] )) {
  2547. if (is_array ( $_GET [$name] ))
  2548. return $_GET [$name];
  2549. else
  2550. return addslashes ( $_GET [$name] );
  2551. } elseif (isset ( $_POST [$name] )) {
  2552. if (is_array ( $_POST [$name] ))
  2553. return $_POST [$name];
  2554. else
  2555. return addslashes ( $_POST [$name] );
  2556. } else
  2557. return false;
  2558. }
  2559. /**
  2560. * 获得分页数据
  2561. * @param unknown_type $table
  2562. * @param unknown_type $condition
  2563. * @param unknown_type $on_page
  2564. * @param unknown_type $page_size
  2565. */
  2566. function get_page($table = "", $condition = "", $on_page = 1, $page_size = 20, $action = "", $get = "", $other = "page") {
  2567. $page_c = "";
  2568. $page ['previous'] = $this->get_previous ( $on_page );
  2569. $page ['on_page'] = $on_page;
  2570. $total_count = $this->get_table_count ( $table, $condition );
  2571. $total = intval ( $total_count / $page_size );
  2572. $page ['total_page'] = ($total_count % $page_size) == 0 ? $total : $total + 1;
  2573. $page ['total_data'] = $total_count;
  2574. $page ['next'] = $on_page == $page ['total_page'] ? $page ['total_page'] : $on_page + 1;
  2575. $i = 1;
  2576. $page_max = 1;
  2577. $page_width = 3;
  2578. if ($on_page >= $page_width) {
  2579. $page_max = intval ( $on_page / $page_width ) + 1;
  2580. $i = intval ( $on_page / $page_width ) * $page_width - 1;
  2581. }
  2582. for(; $i <= $page ['total_page']; $i ++) {
  2583. if ($i == $on_page)
  2584. $page_c .= '<li class="active"><a href="javascript:void(0)">' . $i . '</a></li>';
  2585. else
  2586. $page_c .= '<li><a href="/' . $action . '/' . $i . $get . '">' . $i . '</a></li>';
  2587. if ($i == ($page_width * $page_max))
  2588. break;
  2589. }
  2590. $page ['page'] = $page_c;
  2591. $page ['lower'] = (-- $on_page) * $page_size;
  2592. return $page;
  2593. }
  2594. /**
  2595. * 获取上一页
  2596. * @param unknown_type $on_page
  2597. */
  2598. function get_previous($on_page = 1) {
  2599. return $on_page != 0 ? $on_page - 1 : $on_page;
  2600. }
  2601. /**
  2602. * 获取总页数
  2603. * @param unknown_type $table
  2604. * @param unknown_type $condition
  2605. */
  2606. public function get_table_count($table = "", $condition = "") {
  2607. // $sql = "select count(*) as count from " . $table . " where 1 " . $condition;
  2608. $sql = "select count(*) as count from " . $table . " where " . $condition;
  2609. // echo $sql;die;
  2610. $query = Doo::db ()->query ( $sql );
  2611. $result = $query->fetch ();
  2612. return $result ['count'];
  2613. }
  2614. function isInvoiceNew($type = "GLOBAL") {
  2615. Doo::loadModel ( 'invoice' );
  2616. $invoice = new invoice ();
  2617. Doo::loadModel ( 'invoiceReceivables' );
  2618. $invoiceReceivables = new invoiceReceivables ();
  2619. Doo::loadModel ( 'staff' );
  2620. $staff = new staff ();
  2621. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  2622. // 我的发票待处理
  2623. $pendingInvoice = $invoice->getOne ( array (
  2624. 'where' => "(status=3 or status=4 or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 ) ) and isDelete=0 and sid=" . $_COOKIE ["staff"],
  2625. 'desc' => 'iid',
  2626. 'asArray' => TRUE
  2627. ) );
  2628. // 我的收款待入账
  2629. $myClaim = $invoiceReceivables->getOne ( array (
  2630. 'where' => " receivablesStaff like '" . $_COOKIE ["staff"] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0",
  2631. 'desc' => 'irid',
  2632. 'asArray' => TRUE
  2633. ) );
  2634. // 发票审批
  2635. $approval = $invoice->getOne ( array (
  2636. 'where' => 'status=1 and pendingApprovals=' . $_COOKIE ["staff"],
  2637. 'desc' => 'iid',
  2638. 'asArray' => true
  2639. ) );
  2640. // 发票邮寄
  2641. $post = $invoice->getOne ( array (
  2642. 'where' => "postStatus=0 and doPost=1 and status=2",
  2643. 'asArray' => TRUE
  2644. ) );
  2645. // 发票打印
  2646. $print = $invoice->getOne ( array (
  2647. 'where' => "status=2 and printStatus=0 and moldManage like '%[\"" . $_COOKIE ["staff"] . "\",%'",
  2648. 'desc' => 'iid',
  2649. 'asArray' => TRUE
  2650. ) );
  2651. // 发票退票
  2652. $untread = $invoice->getOne ( array (
  2653. 'where' => " printStatus=1 and untreadStatus=1 and status=2 ",
  2654. 'asArray' => TRUE
  2655. ) );
  2656. $new = array (
  2657. 'GLOBAL' => FALSE,
  2658. 'pendingInvoice' => FALSE,
  2659. 'myClaim' => FALSE,
  2660. 'approval' => FALSE,
  2661. 'post' => FALSE,
  2662. 'print' => FALSE,
  2663. 'untread' => FALSE
  2664. );
  2665. if (! empty ( $pendingInvoice ) || ! empty ( $myClaim ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  2666. $new ['GLOBAL'] = TRUE;
  2667. if (! empty ( $pendingInvoice ))
  2668. $new ['pendingInvoice'] = TRUE;
  2669. if (! empty ( $myClaim ))
  2670. $new ['myClaim'] = TRUE;
  2671. if (! empty ( $approval ))
  2672. $new ['approval'] = TRUE;
  2673. if (! empty ( $post ))
  2674. $new ['post'] = TRUE;
  2675. if (! empty ( $print ))
  2676. $new ['print'] = TRUE;
  2677. if (! empty ( $untread ))
  2678. $new ['untread'] = TRUE;
  2679. return $new;
  2680. }
  2681. }
  2682. ?>