InvoiceController.php 49 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535
  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' => $this->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. Doo::loadModel ( 'L_category' );
  780. $lCategory = new L_category ();
  781. Doo::loadModel ( 'staff' );
  782. $staff = new staff ();
  783. $category = $lCategory->getCategory ();
  784. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  785. $data ['staffList'] = $staffList;
  786. $data ['category'] = $category;
  787. $data ['memu'] = "invoice";
  788. $data ['staff'] = $this->staff;
  789. $data ['receiptMemu'] = 'invoiceReceivables';
  790. $this->render ( "/admin/invoiceReceivables", $data );
  791. }
  792. /**
  793. * 录入收款数据
  794. * @return string
  795. */
  796. function invoiceReceivablesDo() {
  797. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  798. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  799. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  800. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  801. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  802. $receivablesStaff = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  803. Doo::loadModel ( 'invoiceReceivables' );
  804. $invoiceReceivables = new invoiceReceivables ();
  805. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  806. $item = array (
  807. 'receivablesPrice' => $receivablesPrice,
  808. 'receivablesMessage' => $receivablesMessage,
  809. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  810. 'receivablesBank' => $receivablesBank,
  811. 'receivablesDate' => $receivablesDate,
  812. 'inputStaff' => $this->staff [0] ['username'],
  813. 'receivablesCategory' => $receivablesCategory,
  814. 'receivablesStaff' => $receivablesStaff
  815. );
  816. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  817. }
  818. return "/invoiceReceivables";
  819. }
  820. /**
  821. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  822. */
  823. function invoiceReceivablesClaim() {
  824. Doo::loadModel ( 'invoiceReceivables' );
  825. $invoiceReceivables = new invoiceReceivables ();
  826. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'] );
  827. $data ['receivablesList'] = $receivablesList;
  828. $data ['memu'] = "invoice";
  829. $data ['staff'] = $this->staff;
  830. $data ['receiptMemu'] = 'invoiceReceivablesClaim';
  831. $this->render ( "/admin/invoiceReceivablesClaim", $data );
  832. }
  833. /**
  834. * 管理员录入的收款 ,确认认领到谁的名下
  835. */
  836. function invoiceReceivablesAscription() {
  837. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  838. Doo::loadModel ( 'invoiceReceivables' );
  839. $invoiceReceivables = new invoiceReceivables ();
  840. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  841. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC') {
  842. $item = array (
  843. 'irid' => $detail ['irid'],
  844. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  845. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  846. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  847. 'source' => 1
  848. );
  849. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  850. }
  851. return "/invoiceReceivablesClaim";
  852. }
  853. /**
  854. */
  855. function invoiceMyReceivables() {
  856. Doo::loadModel ( 'invoiceReceivables' );
  857. $invoiceReceivables = new invoiceReceivables ();
  858. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  859. $data ['list'] = $list;
  860. $data ['memu'] = "invoice";
  861. $data ['staff'] = $this->staff;
  862. $data ['receiptMemu'] = 'invoiceMyReceivables';
  863. $this->render ( "/admin/invoiceMyReceivables", $data );
  864. }
  865. /**
  866. * 收款绑定发票 ,一个收款只能绑定一个发票
  867. */
  868. function invoiceBindReceivables(){
  869. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  870. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  871. Doo::loadModel ( 'invoice' );
  872. $invoice = new invoice ();
  873. Doo::loadModel ( 'invoiceReceivables' );
  874. $invoiceReceivables = new invoiceReceivables ();
  875. Doo::loadModel ( 'invoiceOperationLog' );
  876. $invoiceOperationLog = new invoiceOperationLog ();
  877. $detail=$invoice->getInvoiceByIid($invoiceKey);
  878. $detailM=$invoiceReceivables->getInvoiceReceivablesByIrid($claimKey);
  879. if (empty($detail)&&empty($detailM))
  880. die ( 'illegal request' );
  881. if ($detailM['receivablesPrice']>=$detail['invoicePrice']){
  882. $price=$detailM['receivablesPrice']-$detail['invoicePrice'];
  883. die('<p>收款金额超出开票金额 ¥'.$price.'元,请谨慎操作</p><a href="/invoiceMyReceivables">返回</a>');
  884. }
  885. $item = array (
  886. 'irid' => $detailM['irid'],
  887. 'bindStatus' => 1,
  888. 'iid' => $detail['iid'],
  889. 'bindDate'=>date ( "Y-m-d H:i:s" )
  890. );
  891. $invoiceReceivables->setInvoiceReceivablesByCondition($item);
  892. $iridString="";
  893. if (empty($detail['irid']))
  894. $iridString=$detailM['irid'];
  895. else
  896. $iridString=$detail['irid'].','.$detailM['irid'];
  897. $item = array (
  898. 'iid' => $detail['iid'],
  899. 'irid' => $iridString
  900. );
  901. $invoice->setInvoiceByCondition($item);
  902. //操作日志
  903. $item = array (
  904. 'date' => date ( "Y-m-d H:i:s" ),
  905. 'operation' => "收款".$detailM['receivablesSerial']."入账到发票".$detail['invoiceSerial'],
  906. 'status' => 8,
  907. 'img' => $this->staff [0] ['avatar'],
  908. 'username' => $this->staff [0] ['username'],
  909. 'uid' => $this->staff [0] ['sid'],
  910. 'category' => $this->staff [0] ['category'],
  911. 'iid' => $detail['iid']
  912. );
  913. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  914. return "/invoiceMyReceivables";
  915. }
  916. /**
  917. * 发票收款完成
  918. */
  919. function invoiceEnterReceivables(){
  920. $invoiceKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  921. //$invoiceClaim = $this->get_args ( 'invoiceClaim' ) ? $this->get_args ( 'invoiceClaim' ) : "";
  922. Doo::loadModel ( 'invoice' );
  923. $invoice = new invoice ();
  924. Doo::loadModel ( 'invoiceOperationLog' );
  925. $invoiceOperationLog = new invoiceOperationLog ();
  926. $detail=$invoice->getInvoiceByIid($invoiceKey);
  927. if (empty($detail))
  928. die ( 'illegal request' );
  929. /*
  930. $receivablesPrice=0;$iridString=$detail['irid'];$iridList=array();
  931. foreach ($invoiceClaim as $key=>$value){
  932. $detailM=$invoiceReceivables->getInvoiceReceivablesByIrid($value);
  933. $receivablesPrice+=$detailM['receivablesPrice'];
  934. if (empty($iridString))
  935. $iridString=$detailM['irid'];
  936. else
  937. $iridString.=",".$detailM['irid'];
  938. array_push($iridList, $detailM['irid']);
  939. }
  940. if ($receivablesPrice>=$detail['invoicePrice']){
  941. $price=$receivablesPrice-$detail['invoicePrice'];
  942. die('<p>收款金额超出开票金额 ¥'.$price.'元,请谨慎操作</p><a href="/invoice">返回</a>');
  943. }
  944. */
  945. $item = array (
  946. 'untreadStatus' => 3,
  947. 'updateTime'=> date ( "Y-m-d H:i:s" ),
  948. 'iid' => $detail['iid']
  949. );
  950. $invoice->setInvoiceByCondition($item);
  951. //操作日志
  952. $item = array (
  953. 'date' => date ( "Y-m-d H:i:s" ),
  954. 'operation' => "发票".$detail['invoiceSerial']."收款完成",
  955. 'status' => 9,
  956. 'img' => $this->staff [0] ['avatar'],
  957. 'username' => $this->staff [0] ['username'],
  958. 'uid' => $this->staff [0] ['sid'],
  959. 'category' => $this->staff [0] ['category'],
  960. 'iid' => $detail['iid']
  961. );
  962. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  963. /*
  964. foreach ($iridList as $key=>$value){
  965. $item = array (
  966. 'iid' => $detail['iid'],
  967. 'irid' => $value,
  968. 'bindDate'=>date ( "Y-m-d H:i:s" ),
  969. 'bindStatus' => 1
  970. );
  971. $invoiceReceivables->setInvoiceReceivablesByCondition($item);
  972. }
  973. */
  974. return "/invoice";
  975. }
  976. /**
  977. * 获得与我有关可收款的发票
  978. */
  979. function ajaxGetInvoiceByStaff() {
  980. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  981. Doo::loadModel ( 'invoice' );
  982. $invoice = new invoice ();
  983. $list = $invoice->getInvoiceByReceivables ( $this->staff [0] ['sid'] );
  984. $html = "";$i=1;
  985. foreach ( $list as $key => $value ) {
  986. $html .= '<tr>
  987. <td>' . $value ['invoiceElement'] . '</td>
  988. <td>¥' . $value ['invoicePrice'] . '</td>';
  989. if (! empty ( $value ['invoiceType'] )) {
  990. $html .= '<td>增值税专用发票</td>
  991. <td>' . $value ['invoiceCompany'] . '</td>';
  992. } else {
  993. $html .= '<td>增值税普通发票</td>
  994. <td>' . $value ['invoiceTitle'] . '</td>';
  995. }
  996. $html .= '<td><label><input type="radio" node-Claim="true_'.$i.'" p-data="'.$value ['iidKey'].'" name="invoiceClaim"> 使用Ta</label></td></tr>
  997. <script>
  998. $(\'input[node-Claim="true_'.$i.'"]\').click(function() {
  999. var invoiceKey= $(this).attr("p-data");
  1000. var claimKey=$("input[name=\'key\']").val();
  1001. $("p[node-msg=\"true\"]").hide();
  1002. var url = "/ajaxCompareInvoicePrice";
  1003. $.ajax({
  1004. url : url,
  1005. type : "post",
  1006. cache : false,
  1007. dataType : "json",
  1008. data : {
  1009. claimKey : claimKey,
  1010. invoiceKey:invoiceKey
  1011. },
  1012. global : true,
  1013. success : function(data) {
  1014. $("input[name=\'invoiceKey\']").val("'.$value ['iidKey'].'");
  1015. if (data.status == 1) {
  1016. $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。");
  1017. $("p[node-msg=\"true\"]").show();
  1018. }
  1019. },
  1020. error : function(err) {
  1021. }
  1022. });
  1023. });
  1024. </script>
  1025. ';
  1026. $i++;
  1027. }
  1028. echo json_encode ( array (
  1029. 'status' => 1,
  1030. 'html' => $html
  1031. ) );
  1032. }
  1033. /**
  1034. * 获取一条收款信息
  1035. */
  1036. function ajaxGetInvoiceReceivables() {
  1037. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  1038. Doo::loadModel ( 'invoiceReceivables' );
  1039. $invoiceReceivables = new invoiceReceivables ();
  1040. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  1041. echo json_encode ( array (
  1042. 'status' => 1,
  1043. 'detail' => $detail
  1044. ) );
  1045. }
  1046. /**
  1047. * 异步获取办事处用户
  1048. */
  1049. function ajaxGetStaffByCategory() {
  1050. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  1051. Doo::loadModel ( 'staff' );
  1052. $staff = new staff ();
  1053. if ($cid == "PUBLIC") {
  1054. echo json_encode ( array (
  1055. 'status' => 1,
  1056. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  1057. ) );
  1058. die ();
  1059. }
  1060. if (! is_numeric ( $cid )) {
  1061. echo json_encode ( array (
  1062. 'status' => 0,
  1063. 'msg' => 'illegal request'
  1064. ) );
  1065. die ();
  1066. }
  1067. $staffList = $staff->getStaffByCid ( $cid );
  1068. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  1069. foreach ( $staffList as $key => $value ) {
  1070. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  1071. }
  1072. echo json_encode ( array (
  1073. 'status' => 1,
  1074. 'html' => $html
  1075. ) );
  1076. }
  1077. /**
  1078. * 异步获取一条发票的邮寄信息
  1079. */
  1080. function ajaxGetInvoicePostDetail() {
  1081. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  1082. Doo::loadModel ( 'invoice' );
  1083. $invoice = new invoice ();
  1084. $iid = $invoice->authcode ( $iid );
  1085. if (! is_numeric ( $iid )) {
  1086. echo json_encode ( array (
  1087. 'status' => 0,
  1088. 'msg' => 'illegal request'
  1089. ) );
  1090. die ();
  1091. }
  1092. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  1093. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  1094. echo json_encode ( array (
  1095. 'status' => 1,
  1096. 'invoiceDetail' => $invoiceDetail
  1097. ) );
  1098. }
  1099. function ajaxCompareClaimPrice(){
  1100. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  1101. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1102. Doo::loadModel ( 'invoice' );
  1103. $invoice = new invoice ();
  1104. Doo::loadModel ( 'invoiceReceivables' );
  1105. $invoiceReceivables = new invoiceReceivables ();
  1106. Doo::loadModel ( 'invoiceOperationLog' );
  1107. $invoiceOperationLog = new invoiceOperationLog ();
  1108. $detail=$invoice->getInvoiceByIid($invoiceKey);
  1109. $detailM=$invoiceReceivables->getInvoiceReceivablesByIrid($irid);
  1110. if (empty($detail)||empty($detailM)){
  1111. echo json_encode ( array (
  1112. 'status' => 2,
  1113. 'msg'=>'非法请求,请重新登录'
  1114. ) );die;
  1115. }
  1116. $iridString="";
  1117. if (empty($detail['irid']))
  1118. $iridString=$detailM['irid'];
  1119. else
  1120. $iridString=$detail['irid'].','.$detailM['irid'];
  1121. $item = array (
  1122. 'irid' => $iridString,
  1123. 'bindTime' => date ( "Y-m-d H:i:s" ),
  1124. 'updateTime'=> date ( "Y-m-d H:i:s" ),
  1125. 'iid' => $detail['iid']
  1126. );
  1127. $invoice->setInvoiceByCondition($item);
  1128. //操作日志
  1129. $item = array (
  1130. 'date' => date ( "Y-m-d H:i:s" ),
  1131. 'operation' => "收款入账".$detailM['receivablesSerial']."到发票".$detail['invoiceSerial'],
  1132. 'status' => 8,
  1133. 'img' => $this->staff [0] ['avatar'],
  1134. 'username' => $this->staff [0] ['username'],
  1135. 'uid' => $this->staff [0] ['sid'],
  1136. 'category' => $this->staff [0] ['category'],
  1137. 'iid' => $detail['iid']
  1138. );
  1139. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1140. $item = array (
  1141. 'iid' => $detail['iid'],
  1142. 'irid' => $detailM['irid'],
  1143. 'bindDate'=>date ( "Y-m-d H:i:s" ),
  1144. 'bindStatus' => 1
  1145. );
  1146. $invoiceReceivables->setInvoiceReceivablesByCondition($item);
  1147. $price=0;$priceStatus=0;
  1148. $list=$invoiceReceivables->getInvoiceReceivablesInIridString($iridString);
  1149. $receivablesPrice=0;
  1150. foreach ($list as $key=>$value){
  1151. $receivablesPrice+=$value['receivablesPrice'];
  1152. }
  1153. if ($receivablesPrice>=$detail['invoicePrice']){
  1154. $price=$receivablesPrice-$detail['invoicePrice'];
  1155. $priceStatus=1;
  1156. }
  1157. echo json_encode ( array (
  1158. 'status' => 1,
  1159. 'html'=>'<tr><td>¥'.$detailM['receivablesPrice'].'</td><td>'.$detailM['receivablesMessage'].'</td><td>'.$detailM['receivablesBank'].'</td>
  1160. <td>'.$detailM['receivablesDate'].'</td><td><a href="">移除</a></td></tr>',
  1161. 'price'=>$price,
  1162. 'priceStatus'=>$priceStatus
  1163. ) );
  1164. }
  1165. /**
  1166. * 我的收款中 选择哪个发票入账,进行金额判断
  1167. */
  1168. function ajaxCompareInvoicePrice(){
  1169. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  1170. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1171. Doo::loadModel ( 'invoice' );
  1172. $invoice = new invoice ();
  1173. Doo::loadModel ( 'invoiceReceivables' );
  1174. $invoiceReceivables = new invoiceReceivables ();
  1175. $detail=$invoice->getInvoiceByIid($invoiceKey);
  1176. $keyList=explode(';', $claimKey);$receivablesPrice=0;
  1177. foreach ($keyList as $key=>$value){
  1178. $detailM=$invoiceReceivables->getInvoiceReceivablesByIrid($value);
  1179. $receivablesPrice+=$detailM['receivablesPrice'];
  1180. }
  1181. if ($receivablesPrice>=$detail['invoicePrice']){
  1182. $price=$receivablesPrice-$detail['invoicePrice'];
  1183. echo json_encode ( array (
  1184. 'status' => 1,
  1185. 'price'=>$price
  1186. ) );
  1187. }else
  1188. echo json_encode ( array (
  1189. 'status' => 2
  1190. ) );
  1191. }
  1192. /*
  1193. * 获得与我有关收款数据
  1194. */
  1195. function ajaxGetReceivalblesByStaff(){
  1196. $iid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  1197. Doo::loadModel ( 'invoiceReceivables' );
  1198. $invoiceReceivables = new invoiceReceivables ();
  1199. Doo::loadModel ( 'invoice' );
  1200. $invoice = new invoice ();
  1201. $detail=$invoice->getInvoiceByIid($iid);
  1202. $list =$invoiceReceivables->getInvoiceReceivablesByClaim($this->staff [0] ['cid'],$this->staff [0] ['sid']);
  1203. $html = "";
  1204. $i=1;
  1205. foreach ( $list['myClaim'] as $key => $value ) {
  1206. $html .= '<tr id="'.$value ['receivablesSerial'].'" >
  1207. <td>¥' . $value ['receivablesPrice'] . '</td>
  1208. <td>' . $value ['receivablesMessage'] . '</td>
  1209. <td>' . $value ['receivablesBank'] . '</td>
  1210. <td>' . $value ['receivablesDate'] . '</td>';
  1211. $html .= '<td>
  1212. <a href="javascript:void(0)" node-Claim="true_'.$i.'" p-data="'.$value ['iidKey'].'" name="invoiceClaim" class="button">入账</a>
  1213. </td></tr>
  1214. <script>
  1215. $(\'a[node-Claim="true_'.$i.'"]\').click(function() {
  1216. var invoiceKey=$("input[name=\'key\']").val();
  1217. var irid= $(this).attr("p-data");
  1218. var element=($(this));
  1219. $("p[node-loading=\"true\"]").show();
  1220. $("p[node-loading=\"true\"]").html("入账处理中...");
  1221. $("p[node-msg=\"true\"]").hide();
  1222. var url = "/ajaxCompareClaimPrice";
  1223. $.ajax({
  1224. url : url,
  1225. type : "post",
  1226. cache : false,
  1227. dataType : "json",
  1228. data : {
  1229. irid : irid,
  1230. invoiceKey:invoiceKey
  1231. },
  1232. global : true,
  1233. success : function(data) {
  1234. $("input[name=\'invoiceKey\']").val("'.$value ['iidKey'].'");
  1235. if (data.status == 1) {
  1236. $(element).parent().parent().remove();
  1237. $("tbody[box-enter=\"true\"]").append(data.html);
  1238. $("p[node-loading=\"true\"]").hide();
  1239. if(data.priceStatus == 1){
  1240. $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。");
  1241. $("p[node-msg=\"true\"]").show();
  1242. }
  1243. }else if(data.status == 2){
  1244. $("p[node-loading=\"true\"]").html(data.msg);
  1245. }
  1246. },
  1247. error : function(err) {
  1248. }
  1249. });
  1250. });
  1251. </script>
  1252. ';
  1253. $i++;
  1254. }
  1255. $html2="";
  1256. $list2 =$invoiceReceivables->getInvoiceReceivablesByIid($iid,1);
  1257. foreach ( $list2 as $key => $value ) {
  1258. $html2 .= '<tr id="'.$value ['receivablesSerial'].'" >
  1259. <td>¥' . $value ['receivablesPrice'] . '</td>
  1260. <td>' . $value ['receivablesMessage'] . '</td>
  1261. <td>' . $value ['receivablesBank'] . '</td>
  1262. <td>' . $value ['receivablesDate'] . '</td>';
  1263. $html2 .= '<td>
  1264. <a href="javascript:void(0)" node-Claim="true_'.$i.'" p-data="'.$value ['iidKey'].'" name="invoiceClaim" >移除</a>
  1265. </td></tr>
  1266. <script>
  1267. $(\'a[node-Claim="true_'.$i.'"]\').click(function() {
  1268. var invoiceKey=$("input[name=\'key\']").val();
  1269. var irid= $(this).attr("p-data");
  1270. var element=($(this));
  1271. $("p[node-loading=\"true\"]").show();
  1272. $("p[node-loading=\"true\"]").html("入账处理中...");
  1273. $("p[node-msg=\"true\"]").hide();
  1274. //var url = "/ajaxCompareClaimPrice";
  1275. $.ajax({
  1276. url : url,
  1277. type : "post",
  1278. cache : false,
  1279. dataType : "json",
  1280. data : {
  1281. irid : irid,
  1282. invoiceKey:invoiceKey
  1283. },
  1284. global : true,
  1285. success : function(data) {
  1286. $("input[name=\'invoiceKey\']").val("'.$value ['iidKey'].'");
  1287. if (data.status == 1) {
  1288. $(element).parent().parent().remove();
  1289. $("tbody[box-enter=\"true\"]").append(data.html);
  1290. $("p[node-loading=\"true\"]").hide();
  1291. if(data.priceStatus == 1){
  1292. $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。");
  1293. $("p[node-msg=\"true\"]").show();
  1294. }
  1295. }else if(data.status == 2){
  1296. $("p[node-loading=\"true\"]").html(data.msg);
  1297. }
  1298. },
  1299. error : function(err) {
  1300. }
  1301. });
  1302. });
  1303. </script>
  1304. ';
  1305. $i++;
  1306. }
  1307. $price=0;$priceStatus=0;
  1308. $list=$invoiceReceivables->getInvoiceReceivablesInIridString($detail['irid']);
  1309. $receivablesPrice=0;
  1310. foreach ($list as $key=>$value){
  1311. $receivablesPrice+=$value['receivablesPrice'];
  1312. }
  1313. if ($receivablesPrice>=$detail['invoicePrice']){
  1314. $price=$receivablesPrice-$detail['invoicePrice'];
  1315. $priceStatus=1;
  1316. }
  1317. echo json_encode ( array (
  1318. 'status' => 1,
  1319. 'html' => $html,
  1320. 'html2'=>$html2,
  1321. 'price'=>$price,
  1322. 'priceStatus'=>$priceStatus
  1323. ) );
  1324. }
  1325. function _GetFileEXT($filename) {
  1326. $pics = explode ( '.', $filename );
  1327. $num = count ( $pics );
  1328. return $pics [$num - 1];
  1329. }
  1330. /**
  1331. * 获取get或者POST值
  1332. *
  1333. * @param string $name 属性名称
  1334. * @return fixed 值
  1335. */
  1336. function get_args($name) {
  1337. if (isset ( $_GET [$name] )) {
  1338. if (is_array ( $_GET [$name] ))
  1339. return $_GET [$name];
  1340. else
  1341. return addslashes ( $_GET [$name] );
  1342. } elseif (isset ( $_POST [$name] )) {
  1343. if (is_array ( $_POST [$name] ))
  1344. return $_POST [$name];
  1345. else
  1346. return addslashes ( $_POST [$name] );
  1347. } else
  1348. return false;
  1349. }
  1350. }
  1351. ?>