InvoiceController.php 84 KB

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