InvoiceController.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  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. private $INVOICEKEY = "APPROVAL";
  12. function __construct() {
  13. if (isset ( $_COOKIE ["staff"] )) {
  14. if (! empty ( $_COOKIE ["staff"] )) {
  15. Doo::loadModel ( 'staff' );
  16. $staff = new staff ();
  17. Doo::loadModel ( "invoiceManage" );
  18. $invoiceManage = new invoiceManage ();
  19. // $invoiceManage
  20. $this->staff = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  21. return "/";
  22. }
  23. }
  24. Doo::loadCore ( 'uri/DooUriRouter' );
  25. $router = new DooUriRouter ();
  26. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  27. if ($routeRs ['1'] != "login") {
  28. header ( 'Content-Type:text/html;charset=utf-8' );
  29. @header ( "Location: /login" );
  30. }
  31. }
  32. function invoice() {
  33. Doo::loadModel ( 'invoice' );
  34. $invoice = new invoice ();
  35. Doo::loadModel ( 'express' );
  36. $express = new express ();
  37. $expressList = $express->getExpressByAll ();
  38. $invoiceList = $invoice->getMyInvoice ( $_COOKIE ["staff"] );
  39. $data ['expressList'] = $expressList;
  40. $data ['invoiceList'] = $invoiceList;
  41. $data ['memu'] = "invoice";
  42. $data ['staff'] = $this->staff;
  43. $data ['receiptMemu'] = 'invoice';
  44. $this->render ( "/admin/invoice", $data );
  45. }
  46. function invoiceAdd() {
  47. Doo::loadModel ( 'L_category' );
  48. $lCategory = new L_category ();
  49. $category = $lCategory->find ( array (
  50. 'asArray' => true
  51. ) );
  52. $data ['category'] = $category;
  53. $data ['memu'] = "invoice";
  54. $data ['staff'] = $this->staff;
  55. $data ['receiptMemu'] = 'invoice';
  56. $this->render ( "/admin/invoiceAdd", $data );
  57. }
  58. /**
  59. * 提交一份开票申请,并记录下操作日志
  60. *
  61. * @since 1.0.0
  62. * @var integer cid 办事处ID
  63. * @var integer invoiceType 发票类型
  64. * @var integer doPost 是否邮寄
  65. * @var integer invoicePrice 开票金额
  66. * @var string invoiceElement 开票内容
  67. * @var string invoiceTitle 发票抬头
  68. * @var string invoiceCompany 单位名称
  69. * @var string TIN 纳税人识别码
  70. * @var string address 注册地址
  71. * @var string phone 注册电话
  72. * @var string bank 开户银行
  73. * @var string bankAccount 银行账户
  74. * @var string recipients 收件人
  75. * @var string recipientsPhone 收件人手机/电话
  76. * @var string recipientsAddress 收件地址
  77. * @var string mailItems 邮寄物品
  78. * @var string remark 备注
  79. * @return string 返回跳转开票主页路径
  80. */
  81. function invoiceAddDo() {
  82. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  83. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  84. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  85. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  86. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  87. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  88. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  89. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  90. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  91. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  92. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  93. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  94. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  95. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  96. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  97. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  98. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  99. if (! empty ( $cid ) && ! empty ( $invoicePrice ) && ! empty ( $invoiceElement )) {
  100. Doo::loadModel ( 'invoice' );
  101. $invoice = new invoice ();
  102. Doo::loadModel ( 'L_category' );
  103. $lCategory = new L_category ();
  104. Doo::loadModel ( 'invoiceManage' );
  105. $invoiceManage = new invoiceManage ();
  106. Doo::loadModel ( 'invoiceOperationLog' );
  107. $invoiceOperationLog = new invoiceOperationLog ();
  108. $categoryDetil = $lCategory->getOne ( array (
  109. 'SELECT' => 'title',
  110. 'where' => 'cid=' . $cid,
  111. 'asArray' => true
  112. ) );
  113. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  114. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  115. $moldManage = array ();
  116. foreach ( $invoiceManageList as $key => $value ) {
  117. if ($value ['mold'] == '发票打印')
  118. $moldManage [$value ['mold']] = $value ['staffList'];
  119. elseif ($value ['mold'] == '发票邮寄')
  120. $moldManage [$value ['mold']] = $value ['staffList'];
  121. elseif ($value ['mold'] == '发票退票')
  122. $moldManage [$value ['mold']] = $value ['staffList'];
  123. }
  124. $item = array (
  125. 'cid' => $cid,
  126. 'categoryName' => $categoryDetil ['title'],
  127. 'invoiceElement' => $invoiceElement,
  128. 'invoicePrice' => $invoicePrice,
  129. 'invoiceType' => $invoiceType,
  130. 'doPost' => $doPost,
  131. 'status' => 1,
  132. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  133. 'date' => date ( "Y-m-d H:i:s" ),
  134. 'updateTime' => date ( "Y-m-d H:i:s" ),
  135. 'sid' => $this->staff [0] ['sid'],
  136. 'userName' => $this->staff [0] ['username'],
  137. 'invoiceManage' => $invoiceManageDetail ['staff'],
  138. 'pendingApprovals' => $invoiceManageDetail ['staffList'] [0] [0],
  139. 'moldManage' => json_encode ( $moldManage ),
  140. 'remark' => $remark
  141. );
  142. if ($invoiceType == 0)
  143. $item += array (
  144. 'invoiceTitle' => $invoiceTitle
  145. );
  146. else {
  147. $item += array (
  148. 'invoiceCompany' => $invoiceCompany,
  149. 'TIN' => $TIN,
  150. 'address' => $address,
  151. 'phone' => $phone,
  152. 'bank' => $bank,
  153. 'bankAccount' => $bankAccount
  154. );
  155. }
  156. if ($doPost == 1) {
  157. $item += array (
  158. 'recipients' => $recipients,
  159. 'recipientsPhone' => $recipientsPhone,
  160. 'recipientsAddress' => $recipientsAddress,
  161. 'mailItems' => $mailItems
  162. );
  163. }
  164. $iid = $invoice->addInvoice ( $item );
  165. $item = array (
  166. 'date' => date ( "Y-m-d H:i:s" ),
  167. 'operation' => "创建",
  168. 'status' => 1,
  169. 'img' => $this->staff [0] ['avatar'],
  170. 'username' => $this->staff [0] ['username'],
  171. 'uid' => $this->staff [0] ['sid'],
  172. 'category' => $this->staff [0] ['category'],
  173. 'iid' => $iid
  174. );
  175. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  176. $item = array (
  177. 'date' => date ( "Y-m-d H:i:s" ),
  178. 'operation' => "提交审批",
  179. 'status' => 1,
  180. 'img' => $this->staff [0] ['avatar'],
  181. 'username' => $this->staff [0] ['username'],
  182. 'uid' => $this->staff [0] ['sid'],
  183. 'category' => $this->staff [0] ['category'],
  184. 'iid' => $iid
  185. );
  186. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  187. }
  188. return "/invoice";
  189. }
  190. function invoiceEdit() {
  191. Doo::loadClass ( 'XDeode' );
  192. $XDeode = new XDeode ( 5 );
  193. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  194. $iid = $XDeode->decode ( $iid );
  195. if (! is_numeric ( $iid ))
  196. die ( 'illegal request' );
  197. Doo::loadModel ( 'invoice' );
  198. $invoice = new invoice ();
  199. Doo::loadModel ( 'invoiceOperationLog' );
  200. $invoiceOperationLog = new invoiceOperationLog ();
  201. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  202. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  203. $data ['operation'] = $operation;
  204. $data ['invoiceDetail'] = $invoiceDetail;
  205. $data ['memu'] = "invoice";
  206. $data ['staff'] = $this->staff;
  207. $data ['receiptMemu'] = 'invoiceApproval';
  208. $this->render ( "/admin/invoiceEdit", $data );
  209. }
  210. /**
  211. * 重新编辑退回的发票
  212. * @return string
  213. */
  214. function invoiceEditDo() {
  215. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  216. Doo::loadModel ( 'invoice' );
  217. $invoice = new invoice ();
  218. $iid = $invoice->authcode ( $iidKey );
  219. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  220. die ( 'illegal request' );
  221. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  222. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  223. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  224. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  225. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  226. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  227. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  228. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  229. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  230. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  231. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  232. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  233. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  234. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  235. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  236. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  237. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  238. if (! empty ( $cid ) && ! empty ( $invoicePrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  239. Doo::loadModel ( 'invoiceManage' );
  240. $invoiceManage = new invoiceManage ();
  241. Doo::loadModel ( 'invoiceOperationLog' );
  242. $invoiceOperationLog = new invoiceOperationLog ();
  243. $cid = explode ( ':', $cid );
  244. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  245. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  246. $moldManage = array ();
  247. foreach ( $invoiceManageList as $key => $value ) {
  248. if ($value ['mold'] == '发票打印')
  249. $moldManage [$value ['mold']] = $value ['staffList'];
  250. elseif ($value ['mold'] == '发票邮寄')
  251. $moldManage [$value ['mold']] = $value ['staffList'];
  252. elseif ($value ['mold'] == '发票打印')
  253. $moldManage [$value ['mold']] = $value ['staffList'];
  254. }
  255. $item = array (
  256. 'iid' => $iid,
  257. 'cid' => $cid [0],
  258. 'categoryName' => $cid [1],
  259. 'invoiceElement' => $invoiceElement,
  260. 'invoicePrice' => $invoicePrice,
  261. 'invoiceType' => $invoiceType,
  262. 'doPost' => $doPost,
  263. 'status' => 1,
  264. 'updateTime' => date ( "Y-m-d H:i:s" ),
  265. 'remark' => $remark
  266. );
  267. if ($invoiceType == 0)
  268. $item += array (
  269. 'invoiceTitle' => $invoiceTitle
  270. );
  271. else {
  272. $item += array (
  273. 'invoiceCompany' => $invoiceCompany,
  274. 'TIN' => $TIN,
  275. 'address' => $address,
  276. 'phone' => $phone,
  277. 'bank' => $bank,
  278. 'bankAccount' => $bankAccount
  279. );
  280. }
  281. if ($doPost == 1) {
  282. $item += array (
  283. 'recipients' => $recipients,
  284. 'recipientsPhone' => $recipientsPhone,
  285. 'recipientsAddress' => $recipientsAddress,
  286. 'mailItems' => $mailItems
  287. );
  288. }
  289. $invoice->setInvoiceByCondition ( $item );
  290. $item = array (
  291. 'date' => date ( "Y-m-d H:i:s" ),
  292. 'operation' => "重新提交审批",
  293. 'status' => 1,
  294. 'img' => $this->staff [0] ['avatar'],
  295. 'username' => $this->staff [0] ['username'],
  296. 'uid' => $this->staff [0] ['sid'],
  297. 'category' => $this->staff [0] ['category'],
  298. 'iid' => $iid
  299. );
  300. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  301. }
  302. return "/invoice";
  303. }
  304. /**
  305. * 终止开票
  306. */
  307. function invoiceDroppedDo() {
  308. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  309. Doo::loadModel ( 'invoice' );
  310. $invoice = new invoice ();
  311. Doo::loadModel ( 'invoiceOperationLog' );
  312. $invoiceOperationLog = new invoiceOperationLog ();
  313. $iid = $invoice->authcode ( $droppedIidKey );
  314. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  315. die ( 'illegal request' );
  316. $item = array (
  317. 'iid' => $iid,
  318. 'status' => 4,
  319. 'updateTime' => date ( "Y-m-d H:i:s" )
  320. );
  321. $invoice->setInvoiceByCondition ( $item );
  322. $item = array (
  323. 'date' => date ( "Y-m-d H:i:s" ),
  324. 'operation' => '终止了开票',
  325. 'status' => 4,
  326. 'img' => $this->staff [0] ['avatar'],
  327. 'username' => $this->staff [0] ['username'],
  328. 'uid' => $this->staff [0] ['sid'],
  329. 'category' => $this->staff [0] ['category'],
  330. 'iid' => $iid
  331. );
  332. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  333. return "/invoice";
  334. }
  335. /**
  336. * 申请退票
  337. */
  338. function invoiceUntreadDo(){
  339. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  340. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  341. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  342. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  343. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  344. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  345. Doo::loadModel ( 'invoice' );
  346. $invoice = new invoice ();
  347. Doo::loadModel ( 'invoiceOperationLog' );
  348. $invoiceOperationLog = new invoiceOperationLog ();
  349. $iid = $invoice->authcode ( $untreadIidKey );
  350. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  351. die ( 'illegal request' );
  352. $item = array (
  353. 'iid' => $iid,
  354. 'untreadStatus' => 1,
  355. 'untreadReason' => $untreadReason,
  356. 'untreadPost' => $untreadPost,
  357. 'updateTime' => date ( "Y-m-d H:i:s" )
  358. );
  359. if($untreadPost==1){
  360. $item += array (
  361. 'untreadCompany' => $untreadCompany,
  362. 'untreadNumber' => $untreadNumber,
  363. 'untreadItems' => $untreadItems
  364. );
  365. }
  366. $invoice->setInvoiceByCondition ( $item );
  367. $item = array (
  368. 'date' => date ( "Y-m-d H:i:s" ),
  369. 'operation' => '申请退票',
  370. 'status' => 7,
  371. 'img' => $this->staff [0] ['avatar'],
  372. 'username' => $this->staff [0] ['username'],
  373. 'uid' => $this->staff [0] ['sid'],
  374. 'category' => $this->staff [0] ['category'],
  375. 'iid' => $iid
  376. );
  377. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  378. return "/invoice";
  379. }
  380. /**
  381. * 删除已终止的开票
  382. */
  383. function invoiceDelDo() {
  384. Doo::loadClass ( 'XDeode' );
  385. $XDeode = new XDeode ( 5 );
  386. Doo::loadModel ( 'invoice' );
  387. $invoice = new invoice ();
  388. Doo::loadModel ( 'invoiceOperationLog' );
  389. $invoiceOperationLog = new invoiceOperationLog ();
  390. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  391. $iid = $XDeode->decode ( $iid );
  392. if (! is_numeric ( $iid ))
  393. die ( 'illegal request' );
  394. $invoiceDetail = $invoice->getMyInvoice ( $_COOKIE ["staff"], $iid );
  395. if (empty ( $invoiceDetail ))
  396. die ( 'illegal request' );
  397. $item = array (
  398. 'iid' => $iid,
  399. 'isDelete' => 1,
  400. 'updateTime' => date ( "Y-m-d H:i:s" )
  401. );
  402. $invoice->setInvoiceByCondition ( $item );
  403. $item = array (
  404. 'date' => date ( "Y-m-d H:i:s" ),
  405. 'operation' => '删除了已终止的发票',
  406. 'status' => 4,
  407. 'img' => $this->staff [0] ['avatar'],
  408. 'username' => $this->staff [0] ['username'],
  409. 'uid' => $this->staff [0] ['sid'],
  410. 'category' => $this->staff [0] ['category'],
  411. 'iid' => $iid
  412. );
  413. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  414. return "/invoice";
  415. }
  416. function invoiceApproval() {
  417. Doo::loadModel ( 'invoice' );
  418. $invoice = new invoice ();
  419. Doo::loadClass ( 'XDeode' );
  420. $XDeode = new XDeode ( 5 );
  421. Doo::loadModel ( 'staff' );
  422. $staff = new staff ();
  423. $invoiceList = $invoice->find ( array (
  424. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  425. 'desc' => 'iid',
  426. 'asArray' => true
  427. ) );
  428. foreach ( $invoiceList as $key => $value ) {
  429. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  430. $lastApprover = json_decode ( $value ['processApprovals'], true );
  431. if (! empty ( $lastApprover )) {
  432. $lastApproverKey = array_keys ( $lastApprover );
  433. $lastApprover = end ( $lastApprover );
  434. $staffDetail = $staff->getOne ( array (
  435. 'where' => 'sid=' . end ( $lastApproverKey ),
  436. 'asArray' => true
  437. ) );
  438. $lastApprover ['username'] = $staffDetail ['username'];
  439. }
  440. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  441. }
  442. $data ['invoiceList'] = $invoiceList;
  443. $data ['memu'] = "invoice";
  444. $data ['staff'] = $this->staff;
  445. $data ['receiptMemu'] = 'invoiceApproval';
  446. $this->render ( "/admin/invoiceApproval", $data );
  447. }
  448. function invoiceDetail() {
  449. Doo::loadClass ( 'XDeode' );
  450. $XDeode = new XDeode ( 5 );
  451. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  452. $iid = $XDeode->decode ( $iid );
  453. if (! is_numeric ( $iid ))
  454. die ( 'illegal request' );
  455. Doo::loadModel ( 'invoice' );
  456. $invoice = new invoice ();
  457. Doo::loadModel ( 'invoiceOperationLog' );
  458. $invoiceOperationLog = new invoiceOperationLog ();
  459. $invoiceDetail = $invoice->getOne ( array (
  460. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  461. 'asArray' => true
  462. ) );
  463. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  464. $data ['invoiceDetail'] = $invoiceDetail;
  465. $data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  466. $data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  467. $data ['memu'] = "invoice";
  468. $data ['staff'] = $this->staff;
  469. $data ['receiptMemu'] = 'invoiceApproval';
  470. $this->render ( "/admin/invoiceApprovalDetail", $data );
  471. }
  472. /**
  473. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  474. *
  475. * @since 1.0.0
  476. * @var integer iid 开票ID 已加密
  477. * @var integer status 发票审批状态
  478. * @var integer opintion 审批发票的意见
  479. * @return string 如操作成功返回审批首页
  480. */
  481. function invoiceApprovalDo() {
  482. Doo::loadModel ( 'invoice' );
  483. $invoice = new invoice ();
  484. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  485. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  486. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  487. $iid = $invoice->authcode ( $iid );
  488. if (! is_numeric ( $iid ))
  489. die ( 'illegal request' );
  490. if (! empty ( $iid ) && ! empty ( $status ) && ! empty ( $opinion )) {
  491. if (! ($status == 2 || $status == 3 || $status == 4))
  492. die ( 'illegal request' );
  493. Doo::loadModel ( 'invoiceOperationLog' );
  494. $invoiceOperationLog = new invoiceOperationLog ();
  495. $invoiceDetail = $invoice->getOne ( array (
  496. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  497. 'asArray' => true
  498. ) );
  499. if (empty ( $invoiceDetail ))
  500. die ( 'illegal request' );
  501. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  502. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  503. if ($status == 3) {
  504. $invoice->status = $status;
  505. $item = array (
  506. 'operation' => $opinion
  507. );
  508. } else {
  509. if (empty ( $processApprovals )) {
  510. $processApprovals = array (
  511. $this->staff [0] ['sid'] => array (
  512. 'date' => date ( "Y-m-d H:i:s" ),
  513. 'opinion' => $opinion,
  514. 'status' => $status
  515. )
  516. );
  517. if ($status != 4 && isset ( $invoiceManage [1] ))
  518. $invoice->pendingApprovals = $invoiceManage [1] [0];
  519. $invoice->processApprovals = json_encode ( $processApprovals );
  520. } else {
  521. $processApprovals [$this->staff [0] ['sid']] = array (
  522. 'date' => date ( "Y-m-d H:i:s" ),
  523. 'opinion' => $opinion,
  524. 'status' => $status
  525. );
  526. $pendingApprovals = 0;
  527. foreach ( $invoiceManage as $key => $value ) {
  528. if ($value [0] == $this->staff [0] ['sid']) {
  529. if (isset ( $invoiceManage [$key + 1] ))
  530. $pendingApprovals = $invoiceManage [$key + 1] [0];
  531. break;
  532. }
  533. }
  534. if ($status != 4 && ! empty ( $pendingApprovals ))
  535. $invoice->pendingApprovals = $pendingApprovals;
  536. $invoice->processApprovals = json_encode ( $processApprovals );
  537. }
  538. $item = array (
  539. 'operation' => $opinion
  540. );
  541. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  542. $invoice->status = $status;
  543. $invoice->pendingApprovals = 0;
  544. } elseif ($status == 4) {
  545. $invoice->status = $status;
  546. $item = array (
  547. 'operation' => $opinion
  548. );
  549. }
  550. }
  551. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  552. $invoice->update ( array (
  553. 'where' => 'iid=' . $iid
  554. ) );
  555. $item += array (
  556. 'date' => date ( "Y-m-d H:i:s" ),
  557. 'img' => $this->staff [0] ['avatar'],
  558. 'username' => $this->staff [0] ['username'],
  559. 'uid' => $this->staff [0] ['sid'],
  560. 'category' => $this->staff [0] ['category'],
  561. 'status' => $status,
  562. 'iid' => $iid
  563. );
  564. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  565. return '/invoiceApproval';
  566. }
  567. die ( 'illegal request' );
  568. }
  569. /**
  570. * 展示需要打印的发票数据
  571. *
  572. * @since 1.0.0
  573. */
  574. function invoicePrint() {
  575. Doo::loadModel ( 'invoice' );
  576. $invoice = new invoice ();
  577. Doo::loadClass ( 'XDeode' );
  578. $XDeode = new XDeode ( 5 );
  579. Doo::loadModel ( 'staff' );
  580. $staff = new staff ();
  581. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  582. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  583. foreach ( $toPrint as $key => $value ) {
  584. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  585. $lastApprover = json_decode ( $value ['processApprovals'], true );
  586. if (! empty ( $lastApprover )) {
  587. $lastApproverKey = array_keys ( $lastApprover );
  588. $lastApprover = end ( $lastApprover );
  589. $staffDetail = $staff->getOne ( array (
  590. 'where' => 'sid=' . end ( $lastApproverKey ),
  591. 'asArray' => true
  592. ) );
  593. $lastApprover ['username'] = $staffDetail ['username'];
  594. }
  595. $toPrint [$key] ['lastApprover'] = $lastApprover;
  596. }
  597. foreach ( $printed as $key => $value ) {
  598. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  599. $lastApprover = json_decode ( $value ['processApprovals'], true );
  600. if (! empty ( $lastApprover )) {
  601. $lastApproverKey = array_keys ( $lastApprover );
  602. $lastApprover = end ( $lastApprover );
  603. $staffDetail = $staff->getOne ( array (
  604. 'where' => 'sid=' . end ( $lastApproverKey ),
  605. 'asArray' => true
  606. ) );
  607. $lastApprover ['username'] = $staffDetail ['username'];
  608. }
  609. $printed [$key] ['lastApprover'] = $lastApprover;
  610. }
  611. $data ['printed'] = $printed;
  612. $data ['toPrint'] = $toPrint;
  613. $data ['memu'] = "invoice";
  614. $data ['staff'] = $this->staff;
  615. $data ['receiptMemu'] = 'invoicePrint';
  616. $this->render ( "/admin/invoicePrint", $data );
  617. }
  618. /**
  619. * 展示发票打印的详情页面
  620. *
  621. * @since 1.0.0
  622. */
  623. function invoicePrintDetail() {
  624. Doo::loadClass ( 'XDeode' );
  625. $XDeode = new XDeode ( 5 );
  626. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  627. $iid = $XDeode->decode ( $iid );
  628. if (! is_numeric ( $iid ))
  629. die ( 'illegal request' );
  630. Doo::loadModel ( 'invoice' );
  631. $invoice = new invoice ();
  632. Doo::loadModel ( 'invoiceOperationLog' );
  633. $invoiceOperationLog = new invoiceOperationLog ();
  634. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  635. // if (empty ( $invoiceDetail ))
  636. // die ( 'illegal request' );
  637. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  638. $data ['invoiceDetail'] = $invoiceDetail;
  639. $data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  640. $data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  641. $data ['memu'] = "invoice";
  642. $data ['staff'] = $this->staff;
  643. $data ['receiptMemu'] = 'invoicePrint';
  644. $this->render ( "/admin/invoicePrintDetail", $data );
  645. }
  646. /**
  647. * 填写票号并完成打印
  648. * @since 1.0.0
  649. */
  650. function invoicePrintDo() {
  651. Doo::loadModel ( 'invoice' );
  652. $invoice = new invoice ();
  653. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  654. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  655. $iid = $invoice->authcode ( $iid );
  656. if (! is_numeric ( $iid ))
  657. die ( 'illegal request' );
  658. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  659. Doo::loadModel ( 'invoiceOperationLog' );
  660. $invoiceOperationLog = new invoiceOperationLog ();
  661. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  662. if (empty ( $invoicePrintDetail ))
  663. die ( 'illegal request' );
  664. $item = array (
  665. 'iid' => $iid,
  666. 'printStatus' => 1,
  667. 'updateTime' => date ( "Y-m-d H:i:s" ),
  668. 'printTime' => date ( "Y-m-d H:i:s" ),
  669. 'invoiceNo' => $invoiceNo
  670. );
  671. $invoice->setInvoiceByCondition ( $item );
  672. $item = array (
  673. 'date' => date ( "Y-m-d H:i:s" ),
  674. 'operation' => $invoiceNo,
  675. 'status' => 5,
  676. 'img' => $this->staff [0] ['avatar'],
  677. 'username' => $this->staff [0] ['username'],
  678. 'uid' => $this->staff [0] ['sid'],
  679. 'category' => $this->staff [0] ['category'],
  680. 'iid' => $iid
  681. );
  682. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  683. return "/invoicePrint";
  684. }
  685. }
  686. /**
  687. * 需要邮寄的发票
  688. * @since 1.0.0
  689. */
  690. function invoicePost() {
  691. Doo::loadModel ( 'invoice' );
  692. $invoice = new invoice ();
  693. Doo::loadModel ( 'express' );
  694. $express = new express ();
  695. $invoicePost = $invoice->getPostByInvoice ();
  696. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  697. $expressList = $express->getExpressByAll ();
  698. $data ['expressList'] = $expressList;
  699. $data ['invoicePost'] = $invoicePost;
  700. $data ['invoicePosted'] = $invoicePosted;
  701. $data ['memu'] = "invoice";
  702. $data ['staff'] = $this->staff;
  703. $data ['receiptMemu'] = 'invoicePost';
  704. $this->render ( "/admin/invoicePost", $data );
  705. }
  706. /**
  707. * 添加发票邮寄信息
  708. */
  709. function invoiceExpressAddDo() {
  710. Doo::loadModel ( 'invoice' );
  711. $invoice = new invoice ();
  712. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  713. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  714. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  715. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  716. $iid = $iid = $invoice->authcode ( $iid );
  717. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  718. die ( 'illegal request' );
  719. $item = array (
  720. 'iid' => $iid,
  721. 'postStatus' => 1,
  722. 'updateTime' => date ( "Y-m-d H:i:s" ),
  723. 'postTime' => date ( "Y-m-d H:i:s" ),
  724. 'expressCompany' => $expressCompany,
  725. 'expressNumber' => $expressNumber,
  726. 'actualItems' => $actualItems,
  727. 'poster' => $staff [0] ['username']
  728. );
  729. $invoice->setInvoiceByCondition ( $item );
  730. return '/invoicePost';
  731. }
  732. /**
  733. * 退票处理页面
  734. */
  735. function invoiceUntread(){
  736. Doo::loadModel ( 'invoice' );
  737. $invoice = new invoice ();
  738. $untreadInvoice=$invoice->getInvoiceByUntreadStatus(1);
  739. $establishedInvoice=$invoice->getInvoiceByUntreadStatus(2);
  740. $data ['untreadInvoice'] = $untreadInvoice;
  741. $data ['establishedInvoice'] = $establishedInvoice;
  742. $data ['memu'] = "invoice";
  743. $data ['staff'] = $this->staff;
  744. $data ['receiptMemu'] = 'invoiceUntread';
  745. $this->render ( "/admin/invoiceUntread", $data );
  746. }
  747. /**
  748. * 确认收到退回的发票,开票状态为退回
  749. */
  750. function invoiceUntreadEstablishedDo(){
  751. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  752. Doo::loadModel ( 'invoice' );
  753. $invoice = new invoice ();
  754. Doo::loadModel ( 'invoiceOperationLog' );
  755. $invoiceOperationLog = new invoiceOperationLog ();
  756. $iid = $invoice->authcode ( $untreadIidKey );
  757. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  758. die ( 'illegal request' );
  759. $item = array (
  760. 'iid' => $iid,
  761. 'untreadStatus' => 2,
  762. 'updateTime' => date ( "Y-m-d H:i:s" )
  763. );
  764. $invoice->setInvoiceByCondition ( $item );
  765. $item = array (
  766. 'date' => date ( "Y-m-d H:i:s" ),
  767. 'operation' => '已确认退票',
  768. 'status' => 6,
  769. 'img' => $this->staff [0] ['avatar'],
  770. 'username' => $this->staff [0] ['username'],
  771. 'uid' => $this->staff [0] ['sid'],
  772. 'category' => $this->staff [0] ['category'],
  773. 'iid' => $iid
  774. );
  775. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  776. return "/invoiceUntread";
  777. }
  778. function invoiceReceivables(){
  779. $data ['memu'] = "invoice";
  780. $data ['staff'] = $this->staff;
  781. $data ['receiptMemu'] = 'invoiceReceivables';
  782. $this->render ( "/admin/invoiceReceivables", $data );
  783. }
  784. /**
  785. * 异步获取一条发票的邮寄信息
  786. */
  787. function ajaxGetInvoicePostDetail() {
  788. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  789. Doo::loadModel ( 'invoice' );
  790. $invoice = new invoice ();
  791. $iid = $invoice->authcode ( $iid );
  792. if (! is_numeric ( $iid )) {
  793. echo json_encode ( array (
  794. 'status' => 0,
  795. 'msg' => 'illegal request'
  796. ) );
  797. die ();
  798. }
  799. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  800. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  801. echo json_encode ( array (
  802. 'status' => 1,
  803. 'invoiceDetail' => $invoiceDetail
  804. ) );
  805. }
  806. function _GetFileEXT($filename) {
  807. $pics = explode ( '.', $filename );
  808. $num = count ( $pics );
  809. return $pics [$num - 1];
  810. }
  811. /**
  812. * 获取get或者POST值
  813. *
  814. * @param string $name 属性名称
  815. * @return fixed 值
  816. */
  817. function get_args($name) {
  818. if (isset ( $_GET [$name] )) {
  819. if (is_array ( $_GET [$name] ))
  820. return $_GET [$name];
  821. else
  822. return addslashes ( $_GET [$name] );
  823. } elseif (isset ( $_POST [$name] )) {
  824. if (is_array ( $_POST [$name] ))
  825. return $_POST [$name];
  826. else
  827. return addslashes ( $_POST [$name] );
  828. } else
  829. return false;
  830. }
  831. }
  832. ?>