InvoiceController.php 57 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739
  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. Doo::loadModel ( 'invoiceReceivables' );
  38. $invoiceReceivables = new invoiceReceivables ();
  39. $expressList = $express->getExpressByAll ();
  40. $invoiceList = $invoice->getMyInvoice ( $_COOKIE ["staff"] );
  41. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  42. // print_r($list);
  43. $data ['expressList'] = $expressList;
  44. $data ['invoiceList'] = $invoiceList;
  45. $data ['receivablesList'] = $list;
  46. $data ['memu'] = "invoice";
  47. $data ['staff'] = $this->staff;
  48. $data ['receiptMemu'] = 'invoice';
  49. $this->render ( "/admin/invoice", $data );
  50. }
  51. function invoiceAdd() {
  52. Doo::loadModel ( 'L_category' );
  53. $lCategory = new L_category ();
  54. $category = $lCategory->find ( array (
  55. 'asArray' => true
  56. ) );
  57. $data ['category'] = $category;
  58. $data ['memu'] = "invoice";
  59. $data ['staff'] = $this->staff;
  60. $data ['receiptMemu'] = 'invoice';
  61. $this->render ( "/admin/invoiceAdd", $data );
  62. }
  63. /**
  64. * 提交一份开票申请,并记录下操作日志
  65. *
  66. * @since 1.0.0
  67. * @var integer cid 办事处ID
  68. * @var integer invoiceType 发票类型
  69. * @var integer doPost 是否邮寄
  70. * @var integer invoicePrice 开票金额
  71. * @var string invoiceElement 开票内容
  72. * @var string invoiceTitle 发票抬头
  73. * @var string invoiceCompany 单位名称
  74. * @var string TIN 纳税人识别码
  75. * @var string address 注册地址
  76. * @var string phone 注册电话
  77. * @var string bank 开户银行
  78. * @var string bankAccount 银行账户
  79. * @var string recipients 收件人
  80. * @var string recipientsPhone 收件人手机/电话
  81. * @var string recipientsAddress 收件地址
  82. * @var string mailItems 邮寄物品
  83. * @var string remark 备注
  84. * @return string 返回跳转开票主页路径
  85. */
  86. function invoiceAddDo() {
  87. $cid = $this->get_args ( 'cid' ) && is_numeric ( $this->get_args ( 'cid' ) ) ? $this->get_args ( 'cid' ) : 0;
  88. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  89. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  90. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  91. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  92. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  93. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  94. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  95. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  96. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  97. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  98. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  99. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  100. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  101. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  102. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  103. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  104. if (! empty ( $cid ) && ! empty ( $invoicePrice ) && ! empty ( $invoiceElement )) {
  105. Doo::loadModel ( 'invoice' );
  106. $invoice = new invoice ();
  107. Doo::loadModel ( 'L_category' );
  108. $lCategory = new L_category ();
  109. Doo::loadModel ( 'invoiceManage' );
  110. $invoiceManage = new invoiceManage ();
  111. Doo::loadModel ( 'invoiceOperationLog' );
  112. $invoiceOperationLog = new invoiceOperationLog ();
  113. $categoryDetil = $lCategory->getOne ( array (
  114. 'SELECT' => 'title',
  115. 'where' => 'cid=' . $cid,
  116. 'asArray' => true
  117. ) );
  118. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  119. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  120. $moldManage = array ();
  121. foreach ( $invoiceManageList as $key => $value ) {
  122. if ($value ['mold'] == '发票打印')
  123. $moldManage [$value ['mold']] = $value ['staffList'];
  124. elseif ($value ['mold'] == '发票邮寄')
  125. $moldManage [$value ['mold']] = $value ['staffList'];
  126. elseif ($value ['mold'] == '发票退票')
  127. $moldManage [$value ['mold']] = $value ['staffList'];
  128. }
  129. $item = array (
  130. 'cid' => $cid,
  131. 'categoryName' => $categoryDetil ['title'],
  132. 'invoiceElement' => $invoiceElement,
  133. 'invoicePrice' => $invoicePrice,
  134. 'invoiceType' => $invoiceType,
  135. 'doPost' => $doPost,
  136. 'status' => 1,
  137. 'invoiceSerial' => "#F" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  138. 'date' => date ( "Y-m-d H:i:s" ),
  139. 'updateTime' => date ( "Y-m-d H:i:s" ),
  140. 'sid' => $this->staff [0] ['sid'],
  141. 'userName' => $this->staff [0] ['username'],
  142. 'invoiceManage' => $invoiceManageDetail ['staff'],
  143. 'pendingApprovals' => $invoiceManageDetail ['staffList'] [0] [0],
  144. 'moldManage' => json_encode ( $moldManage ),
  145. 'remark' => $remark
  146. );
  147. if ($invoiceType == 0)
  148. $item += array (
  149. 'invoiceTitle' => $invoiceTitle
  150. );
  151. else {
  152. $item += array (
  153. 'invoiceCompany' => $invoiceCompany,
  154. 'TIN' => $TIN,
  155. 'address' => $address,
  156. 'phone' => $phone,
  157. 'bank' => $bank,
  158. 'bankAccount' => $bankAccount
  159. );
  160. }
  161. if ($doPost == 1) {
  162. $item += array (
  163. 'recipients' => $recipients,
  164. 'recipientsPhone' => $recipientsPhone,
  165. 'recipientsAddress' => $recipientsAddress,
  166. 'mailItems' => $mailItems
  167. );
  168. }
  169. $iid = $invoice->addInvoice ( $item );
  170. $item = array (
  171. 'date' => date ( "Y-m-d H:i:s" ),
  172. 'operation' => "创建",
  173. 'status' => 1,
  174. 'img' => $this->staff [0] ['avatar'],
  175. 'username' => $this->staff [0] ['username'],
  176. 'uid' => $this->staff [0] ['sid'],
  177. 'category' => $this->staff [0] ['category'],
  178. 'iid' => $iid
  179. );
  180. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  181. $item = array (
  182. 'date' => date ( "Y-m-d H:i:s" ),
  183. 'operation' => "提交审批",
  184. 'status' => 1,
  185. 'img' => $this->staff [0] ['avatar'],
  186. 'username' => $this->staff [0] ['username'],
  187. 'uid' => $this->staff [0] ['sid'],
  188. 'category' => $this->staff [0] ['category'],
  189. 'iid' => $iid
  190. );
  191. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  192. }
  193. return "/invoice";
  194. }
  195. function invoiceEdit() {
  196. Doo::loadClass ( 'XDeode' );
  197. $XDeode = new XDeode ( 5 );
  198. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  199. $iid = $XDeode->decode ( $iid );
  200. if (! is_numeric ( $iid ))
  201. die ( 'illegal request' );
  202. Doo::loadModel ( 'invoice' );
  203. $invoice = new invoice ();
  204. Doo::loadModel ( 'invoiceOperationLog' );
  205. $invoiceOperationLog = new invoiceOperationLog ();
  206. $invoiceDetail = $invoice->getInvoiceByIid ( $iid );
  207. $operation = $invoiceOperationLog->getInvoiceOperationByDropped ( $iid );
  208. $data ['operation'] = $operation;
  209. $data ['invoiceDetail'] = $invoiceDetail;
  210. $data ['memu'] = "invoice";
  211. $data ['staff'] = $this->staff;
  212. $data ['receiptMemu'] = 'invoiceApproval';
  213. $this->render ( "/admin/invoiceEdit", $data );
  214. }
  215. /**
  216. * 重新编辑退回的发票
  217. * @return string
  218. */
  219. function invoiceEditDo() {
  220. $iidKey = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : '';
  221. Doo::loadModel ( 'invoice' );
  222. $invoice = new invoice ();
  223. $iid = $invoice->authcode ( $iidKey );
  224. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  225. die ( 'illegal request' );
  226. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : 0;
  227. $invoiceType = $this->get_args ( 'invoiceType' ) && is_numeric ( $this->get_args ( 'invoiceType' ) ) ? $this->get_args ( 'invoiceType' ) : 0;
  228. $doPost = $this->get_args ( 'doPost' ) && is_numeric ( $this->get_args ( 'doPost' ) ) ? $this->get_args ( 'doPost' ) : 0;
  229. $invoicePrice = $this->get_args ( 'invoicePrice' ) ? $this->get_args ( 'invoicePrice' ) : "";
  230. $invoiceElement = $this->get_args ( 'invoiceElement' ) ? $this->get_args ( 'invoiceElement' ) : "";
  231. $invoiceTitle = $this->get_args ( 'invoiceTitle' ) ? $this->get_args ( 'invoiceTitle' ) : "";
  232. $invoiceCompany = $this->get_args ( 'invoiceCompany' ) ? $this->get_args ( 'invoiceCompany' ) : "";
  233. $TIN = $this->get_args ( 'TIN' ) ? $this->get_args ( 'TIN' ) : "";
  234. $address = $this->get_args ( 'address' ) ? $this->get_args ( 'address' ) : "";
  235. $phone = $this->get_args ( 'phone' ) ? $this->get_args ( 'phone' ) : "";
  236. $bank = $this->get_args ( 'bank' ) ? $this->get_args ( 'bank' ) : "";
  237. $bankAccount = $this->get_args ( 'bankAccount' ) ? $this->get_args ( 'bankAccount' ) : "";
  238. $recipients = $this->get_args ( 'recipients' ) ? $this->get_args ( 'recipients' ) : "";
  239. $recipientsPhone = $this->get_args ( 'recipientsPhone' ) ? $this->get_args ( 'recipientsPhone' ) : "";
  240. $recipientsAddress = $this->get_args ( 'recipientsAddress' ) ? $this->get_args ( 'recipientsAddress' ) : "";
  241. $mailItems = $this->get_args ( 'mailItems' ) ? $this->get_args ( 'mailItems' ) : "";
  242. $remark = $this->get_args ( 'remark' ) ? $this->get_args ( 'remark' ) : "";
  243. if (! empty ( $cid ) && ! empty ( $invoicePrice ) && ! empty ( $invoiceElement ) && ! empty ( $iid )) {
  244. Doo::loadModel ( 'invoiceManage' );
  245. $invoiceManage = new invoiceManage ();
  246. Doo::loadModel ( 'invoiceOperationLog' );
  247. $invoiceOperationLog = new invoiceOperationLog ();
  248. $cid = explode ( ':', $cid );
  249. $invoiceManageList = $invoiceManage->getInvoiceByAll ();
  250. $invoiceManageDetail = $invoiceManage->getInvoiceByMold ( "发票审批" );
  251. $moldManage = array ();
  252. foreach ( $invoiceManageList as $key => $value ) {
  253. if ($value ['mold'] == '发票打印')
  254. $moldManage [$value ['mold']] = $value ['staffList'];
  255. elseif ($value ['mold'] == '发票邮寄')
  256. $moldManage [$value ['mold']] = $value ['staffList'];
  257. elseif ($value ['mold'] == '发票打印')
  258. $moldManage [$value ['mold']] = $value ['staffList'];
  259. }
  260. $item = array (
  261. 'iid' => $iid,
  262. 'cid' => $cid [0],
  263. 'categoryName' => $cid [1],
  264. 'invoiceElement' => $invoiceElement,
  265. 'invoicePrice' => $invoicePrice,
  266. 'invoiceType' => $invoiceType,
  267. 'doPost' => $doPost,
  268. 'status' => 1,
  269. 'updateTime' => date ( "Y-m-d H:i:s" ),
  270. 'remark' => $remark
  271. );
  272. if ($invoiceType == 0)
  273. $item += array (
  274. 'invoiceTitle' => $invoiceTitle
  275. );
  276. else {
  277. $item += array (
  278. 'invoiceCompany' => $invoiceCompany,
  279. 'TIN' => $TIN,
  280. 'address' => $address,
  281. 'phone' => $phone,
  282. 'bank' => $bank,
  283. 'bankAccount' => $bankAccount
  284. );
  285. }
  286. if ($doPost == 1) {
  287. $item += array (
  288. 'recipients' => $recipients,
  289. 'recipientsPhone' => $recipientsPhone,
  290. 'recipientsAddress' => $recipientsAddress,
  291. 'mailItems' => $mailItems
  292. );
  293. }
  294. $invoice->setInvoiceByCondition ( $item );
  295. $item = array (
  296. 'date' => date ( "Y-m-d H:i:s" ),
  297. 'operation' => "重新提交审批",
  298. 'status' => 1,
  299. 'img' => $this->staff [0] ['avatar'],
  300. 'username' => $this->staff [0] ['username'],
  301. 'uid' => $this->staff [0] ['sid'],
  302. 'category' => $this->staff [0] ['category'],
  303. 'iid' => $iid
  304. );
  305. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  306. }
  307. return "/invoice";
  308. }
  309. /**
  310. * 终止开票
  311. */
  312. function invoiceDroppedDo() {
  313. $droppedIidKey = $this->get_args ( 'droppedIidKey' ) ? $this->get_args ( 'droppedIidKey' ) : '';
  314. Doo::loadModel ( 'invoice' );
  315. $invoice = new invoice ();
  316. Doo::loadModel ( 'invoiceOperationLog' );
  317. $invoiceOperationLog = new invoiceOperationLog ();
  318. $iid = $invoice->authcode ( $droppedIidKey );
  319. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  320. die ( 'illegal request' );
  321. $item = array (
  322. 'iid' => $iid,
  323. 'status' => 4,
  324. 'updateTime' => date ( "Y-m-d H:i:s" )
  325. );
  326. $invoice->setInvoiceByCondition ( $item );
  327. $item = array (
  328. 'date' => date ( "Y-m-d H:i:s" ),
  329. 'operation' => '终止了开票',
  330. 'status' => 4,
  331. 'img' => $this->staff [0] ['avatar'],
  332. 'username' => $this->staff [0] ['username'],
  333. 'uid' => $this->staff [0] ['sid'],
  334. 'category' => $this->staff [0] ['category'],
  335. 'iid' => $iid
  336. );
  337. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  338. return "/invoice";
  339. }
  340. /**
  341. * 申请退票
  342. */
  343. function invoiceUntreadDo() {
  344. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  345. $untreadReason = $this->get_args ( 'untreadReason' ) ? $this->get_args ( 'untreadReason' ) : "";
  346. $untreadPost = $this->get_args ( 'untreadPost' ) ? $this->get_args ( 'untreadPost' ) : "";
  347. $untreadCompany = $this->get_args ( 'untreadCompany' ) ? $this->get_args ( 'untreadCompany' ) : "";
  348. $untreadNumber = $this->get_args ( 'untreadNumber' ) ? $this->get_args ( 'untreadNumber' ) : "";
  349. $untreadItems = $this->get_args ( 'untreadItems' ) ? $this->get_args ( 'untreadItems' ) : "";
  350. Doo::loadModel ( 'invoice' );
  351. $invoice = new invoice ();
  352. Doo::loadModel ( 'invoiceOperationLog' );
  353. $invoiceOperationLog = new invoiceOperationLog ();
  354. $iid = $invoice->authcode ( $untreadIidKey );
  355. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  356. die ( 'illegal request' );
  357. $item = array (
  358. 'iid' => $iid,
  359. 'untreadStatus' => 1,
  360. 'untreadReason' => $untreadReason,
  361. 'untreadPost' => $untreadPost,
  362. 'updateTime' => date ( "Y-m-d H:i:s" )
  363. );
  364. if ($untreadPost == 1) {
  365. $item += array (
  366. 'untreadCompany' => $untreadCompany,
  367. 'untreadNumber' => $untreadNumber,
  368. 'untreadItems' => $untreadItems
  369. );
  370. }
  371. $invoice->setInvoiceByCondition ( $item );
  372. $item = array (
  373. 'date' => date ( "Y-m-d H:i:s" ),
  374. 'operation' => '申请退票',
  375. 'status' => 7,
  376. 'img' => $this->staff [0] ['avatar'],
  377. 'username' => $this->staff [0] ['username'],
  378. 'uid' => $this->staff [0] ['sid'],
  379. 'category' => $this->staff [0] ['category'],
  380. 'iid' => $iid
  381. );
  382. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  383. return "/invoice";
  384. }
  385. /**
  386. * 删除已终止的开票
  387. */
  388. function invoiceDelDo() {
  389. Doo::loadClass ( 'XDeode' );
  390. $XDeode = new XDeode ( 5 );
  391. Doo::loadModel ( 'invoice' );
  392. $invoice = new invoice ();
  393. Doo::loadModel ( 'invoiceOperationLog' );
  394. $invoiceOperationLog = new invoiceOperationLog ();
  395. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  396. $iid = $XDeode->decode ( $iid );
  397. if (! is_numeric ( $iid ))
  398. die ( 'illegal request' );
  399. $invoiceDetail = $invoice->getMyInvoice ( $_COOKIE ["staff"], $iid );
  400. if (empty ( $invoiceDetail ))
  401. die ( 'illegal request' );
  402. $item = array (
  403. 'iid' => $iid,
  404. 'isDelete' => 1,
  405. 'updateTime' => date ( "Y-m-d H:i:s" )
  406. );
  407. $invoice->setInvoiceByCondition ( $item );
  408. $item = array (
  409. 'date' => date ( "Y-m-d H:i:s" ),
  410. 'operation' => '删除了已终止的发票',
  411. 'status' => 4,
  412. 'img' => $this->staff [0] ['avatar'],
  413. 'username' => $this->staff [0] ['username'],
  414. 'uid' => $this->staff [0] ['sid'],
  415. 'category' => $this->staff [0] ['category'],
  416. 'iid' => $iid
  417. );
  418. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  419. return "/invoice";
  420. }
  421. function invoiceApproval() {
  422. Doo::loadModel ( 'invoice' );
  423. $invoice = new invoice ();
  424. Doo::loadClass ( 'XDeode' );
  425. $XDeode = new XDeode ( 5 );
  426. Doo::loadModel ( 'staff' );
  427. $staff = new staff ();
  428. $invoiceList = $invoice->find ( array (
  429. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'],
  430. 'desc' => 'iid',
  431. 'asArray' => true
  432. ) );
  433. foreach ( $invoiceList as $key => $value ) {
  434. $invoiceList [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  435. $lastApprover = json_decode ( $value ['processApprovals'], true );
  436. if (! empty ( $lastApprover )) {
  437. $lastApproverKey = array_keys ( $lastApprover );
  438. $lastApprover = end ( $lastApprover );
  439. $staffDetail = $staff->getOne ( array (
  440. 'where' => 'sid=' . end ( $lastApproverKey ),
  441. 'asArray' => true
  442. ) );
  443. $lastApprover ['username'] = $staffDetail ['username'];
  444. }
  445. $invoiceList [$key] ['lastApprover'] = $lastApprover;
  446. }
  447. $data ['invoiceList'] = $invoiceList;
  448. $data ['memu'] = "invoice";
  449. $data ['staff'] = $this->staff;
  450. $data ['receiptMemu'] = 'invoiceApproval';
  451. $this->render ( "/admin/invoiceApproval", $data );
  452. }
  453. function invoiceDetail() {
  454. Doo::loadClass ( 'XDeode' );
  455. $XDeode = new XDeode ( 5 );
  456. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  457. $iid = $XDeode->decode ( $iid );
  458. if (! is_numeric ( $iid ))
  459. die ( 'illegal request' );
  460. Doo::loadModel ( 'invoice' );
  461. $invoice = new invoice ();
  462. Doo::loadModel ( 'invoiceOperationLog' );
  463. $invoiceOperationLog = new invoiceOperationLog ();
  464. $invoiceDetail = $invoice->getOne ( array (
  465. 'where' => 'status=1 and pendingApprovals=' . $this->staff [0] ['sid'] . ' and iid=' . $iid,
  466. 'asArray' => true
  467. ) );
  468. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  469. $data ['invoiceDetail'] = $invoiceDetail;
  470. $data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  471. $data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  472. $data ['memu'] = "invoice";
  473. $data ['staff'] = $this->staff;
  474. $data ['receiptMemu'] = 'invoiceApproval';
  475. $this->render ( "/admin/invoiceApprovalDetail", $data );
  476. }
  477. /**
  478. * 对发票进行审批,其中操作有终止,退回,同意动作。操作成功并记录下操作日志
  479. *
  480. * @since 1.0.0
  481. * @var integer iid 开票ID 已加密
  482. * @var integer status 发票审批状态
  483. * @var integer opintion 审批发票的意见
  484. * @return string 如操作成功返回审批首页
  485. */
  486. function invoiceApprovalDo() {
  487. Doo::loadModel ( 'invoice' );
  488. $invoice = new invoice ();
  489. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  490. $status = $this->get_args ( 'status' ) && is_numeric ( $this->get_args ( 'status' ) ) ? $this->get_args ( 'status' ) : 0;
  491. $opinion = $this->get_args ( 'opinion' ) ? $this->get_args ( 'opinion' ) : "";
  492. $iid = $invoice->authcode ( $iid );
  493. if (! is_numeric ( $iid ))
  494. die ( 'illegal request' );
  495. if (! empty ( $iid ) && ! empty ( $status ) && ! empty ( $opinion )) {
  496. if (! ($status == 2 || $status == 3 || $status == 4))
  497. die ( 'illegal request' );
  498. Doo::loadModel ( 'invoiceOperationLog' );
  499. $invoiceOperationLog = new invoiceOperationLog ();
  500. $invoiceDetail = $invoice->getOne ( array (
  501. 'where' => 'status=1 and iid=' . $iid . ' and pendingApprovals=' . $this->staff [0] ['sid'],
  502. 'asArray' => true
  503. ) );
  504. if (empty ( $invoiceDetail ))
  505. die ( 'illegal request' );
  506. $processApprovals = json_decode ( $invoiceDetail ['processApprovals'], true );
  507. $invoiceManage = json_decode ( $invoiceDetail ['invoiceManage'], true );
  508. if ($status == 3) {
  509. $invoice->status = $status;
  510. $item = array (
  511. 'operation' => $opinion
  512. );
  513. } else {
  514. if (empty ( $processApprovals )) {
  515. $processApprovals = array (
  516. $this->staff [0] ['sid'] => array (
  517. 'date' => date ( "Y-m-d H:i:s" ),
  518. 'opinion' => $opinion,
  519. 'status' => $status
  520. )
  521. );
  522. if ($status != 4 && isset ( $invoiceManage [1] ))
  523. $invoice->pendingApprovals = $invoiceManage [1] [0];
  524. $invoice->processApprovals = json_encode ( $processApprovals );
  525. } else {
  526. $processApprovals [$this->staff [0] ['sid']] = array (
  527. 'date' => date ( "Y-m-d H:i:s" ),
  528. 'opinion' => $opinion,
  529. 'status' => $status
  530. );
  531. $pendingApprovals = 0;
  532. foreach ( $invoiceManage as $key => $value ) {
  533. if ($value [0] == $this->staff [0] ['sid']) {
  534. if (isset ( $invoiceManage [$key + 1] ))
  535. $pendingApprovals = $invoiceManage [$key + 1] [0];
  536. break;
  537. }
  538. }
  539. if ($status != 4 && ! empty ( $pendingApprovals ))
  540. $invoice->pendingApprovals = $pendingApprovals;
  541. $invoice->processApprovals = json_encode ( $processApprovals );
  542. }
  543. $item = array (
  544. 'operation' => $opinion
  545. );
  546. if (count ( $processApprovals ) == count ( $invoiceManage ) && $status != 4) {
  547. $invoice->status = $status;
  548. $invoice->pendingApprovals = 0;
  549. } elseif ($status == 4) {
  550. $invoice->status = $status;
  551. $item = array (
  552. 'operation' => $opinion
  553. );
  554. }
  555. }
  556. $invoice->updateTime = date ( "Y-m-d H:i:s" );
  557. $invoice->update ( array (
  558. 'where' => 'iid=' . $iid
  559. ) );
  560. $item += array (
  561. 'date' => date ( "Y-m-d H:i:s" ),
  562. 'img' => $this->staff [0] ['avatar'],
  563. 'username' => $this->staff [0] ['username'],
  564. 'uid' => $this->staff [0] ['sid'],
  565. 'category' => $this->staff [0] ['category'],
  566. 'status' => $status,
  567. 'iid' => $iid
  568. );
  569. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  570. return '/invoiceApproval';
  571. }
  572. die ( 'illegal request' );
  573. }
  574. /**
  575. * 展示需要打印的发票数据
  576. *
  577. * @since 1.0.0
  578. */
  579. function invoicePrint() {
  580. Doo::loadModel ( 'invoice' );
  581. $invoice = new invoice ();
  582. Doo::loadClass ( 'XDeode' );
  583. $XDeode = new XDeode ( 5 );
  584. Doo::loadModel ( 'staff' );
  585. $staff = new staff ();
  586. $toPrint = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0 );
  587. $printed = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 1 );
  588. foreach ( $toPrint as $key => $value ) {
  589. $toPrint [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  590. $lastApprover = json_decode ( $value ['processApprovals'], true );
  591. if (! empty ( $lastApprover )) {
  592. $lastApproverKey = array_keys ( $lastApprover );
  593. $lastApprover = end ( $lastApprover );
  594. $staffDetail = $staff->getOne ( array (
  595. 'where' => 'sid=' . end ( $lastApproverKey ),
  596. 'asArray' => true
  597. ) );
  598. $lastApprover ['username'] = $staffDetail ['username'];
  599. }
  600. $toPrint [$key] ['lastApprover'] = $lastApprover;
  601. }
  602. foreach ( $printed as $key => $value ) {
  603. $printed [$key] ['iidKey'] = $XDeode->encode ( $value ['iid'] );
  604. $lastApprover = json_decode ( $value ['processApprovals'], true );
  605. if (! empty ( $lastApprover )) {
  606. $lastApproverKey = array_keys ( $lastApprover );
  607. $lastApprover = end ( $lastApprover );
  608. $staffDetail = $staff->getOne ( array (
  609. 'where' => 'sid=' . end ( $lastApproverKey ),
  610. 'asArray' => true
  611. ) );
  612. $lastApprover ['username'] = $staffDetail ['username'];
  613. }
  614. $printed [$key] ['lastApprover'] = $lastApprover;
  615. }
  616. $data ['printed'] = $printed;
  617. $data ['toPrint'] = $toPrint;
  618. $data ['memu'] = "invoice";
  619. $data ['staff'] = $this->staff;
  620. $data ['receiptMemu'] = 'invoicePrint';
  621. $this->render ( "/admin/invoicePrint", $data );
  622. }
  623. /**
  624. * 展示发票打印的详情页面
  625. *
  626. * @since 1.0.0
  627. */
  628. function invoicePrintDetail() {
  629. Doo::loadClass ( 'XDeode' );
  630. $XDeode = new XDeode ( 5 );
  631. $iid = isset ( $this->params ['iid'] ) ? $this->params ['iid'] : "";
  632. $iid = $XDeode->decode ( $iid );
  633. if (! is_numeric ( $iid ))
  634. die ( 'illegal request' );
  635. Doo::loadModel ( 'invoice' );
  636. $invoice = new invoice ();
  637. Doo::loadModel ( 'invoiceOperationLog' );
  638. $invoiceOperationLog = new invoiceOperationLog ();
  639. $invoiceDetail = $invoice->getPrintInvoiceByManage ( $this->staff [0] ['sid'], 0, $iid );
  640. // if (empty ( $invoiceDetail ))
  641. // die ( 'illegal request' );
  642. $invoiceOperationLogList = $invoiceOperationLog->getInvoiceOperationLogByIid ( $iid );
  643. $data ['invoiceDetail'] = $invoiceDetail;
  644. $data ['invoiceOperationLogList'] = $invoiceOperationLogList;
  645. $data ['INVOICEKEY'] = $invoice->authcode ( $invoiceDetail ['iid'], '' );
  646. $data ['memu'] = "invoice";
  647. $data ['staff'] = $this->staff;
  648. $data ['receiptMemu'] = 'invoicePrint';
  649. $this->render ( "/admin/invoicePrintDetail", $data );
  650. }
  651. /**
  652. * 填写票号并完成打印
  653. * @since 1.0.0
  654. */
  655. function invoicePrintDo() {
  656. Doo::loadModel ( 'invoice' );
  657. $invoice = new invoice ();
  658. $iid = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  659. $invoiceNo = $this->get_args ( 'invoiceNo' ) ? $this->get_args ( 'invoiceNo' ) : "";
  660. $iid = $invoice->authcode ( $iid );
  661. if (! is_numeric ( $iid ))
  662. die ( 'illegal request' );
  663. if (! empty ( $iid ) && ! empty ( $invoiceNo )) {
  664. Doo::loadModel ( 'invoiceOperationLog' );
  665. $invoiceOperationLog = new invoiceOperationLog ();
  666. $invoicePrintDetail = $invoice->getInvoiceByPrint ( $iid );
  667. if (empty ( $invoicePrintDetail ))
  668. die ( 'illegal request' );
  669. $item = array (
  670. 'iid' => $iid,
  671. 'printStatus' => 1,
  672. 'updateTime' => date ( "Y-m-d H:i:s" ),
  673. 'printTime' => date ( "Y-m-d H:i:s" ),
  674. 'invoiceNo' => $invoiceNo
  675. );
  676. $invoice->setInvoiceByCondition ( $item );
  677. $item = array (
  678. 'date' => date ( "Y-m-d H:i:s" ),
  679. 'operation' => $invoiceNo,
  680. 'status' => 5,
  681. 'img' => $this->staff [0] ['avatar'],
  682. 'username' => $this->staff [0] ['username'],
  683. 'uid' => $this->staff [0] ['sid'],
  684. 'category' => $this->staff [0] ['category'],
  685. 'iid' => $iid
  686. );
  687. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  688. return "/invoicePrint";
  689. }
  690. }
  691. /**
  692. * 需要邮寄的发票
  693. * @since 1.0.0
  694. */
  695. function invoicePost() {
  696. Doo::loadModel ( 'invoice' );
  697. $invoice = new invoice ();
  698. Doo::loadModel ( 'express' );
  699. $express = new express ();
  700. $invoicePost = $invoice->getPostByInvoice ();
  701. $invoicePosted = $invoice->getPostByInvoice ( 1 );
  702. $expressList = $express->getExpressByAll ();
  703. $data ['expressList'] = $expressList;
  704. $data ['invoicePost'] = $invoicePost;
  705. $data ['invoicePosted'] = $invoicePosted;
  706. $data ['memu'] = "invoice";
  707. $data ['staff'] = $this->staff;
  708. $data ['receiptMemu'] = 'invoicePost';
  709. $this->render ( "/admin/invoicePost", $data );
  710. }
  711. /**
  712. * 添加发票邮寄信息
  713. */
  714. function invoiceExpressAddDo() {
  715. Doo::loadModel ( 'invoice' );
  716. $invoice = new invoice ();
  717. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  718. $expressCompany = $this->get_args ( 'express' ) ? $this->get_args ( 'express' ) : "";
  719. $expressNumber = $this->get_args ( 'nu' ) ? $this->get_args ( 'nu' ) : "";
  720. $actualItems = $this->get_args ( 'actualItems' ) ? $this->get_args ( 'actualItems' ) : "";
  721. $iid = $iid = $invoice->authcode ( $iid );
  722. if (! is_numeric ( $iid ) && empty ( $expressCompany ) && empty ( $expressNumber ) && empty ( $actualItems ))
  723. die ( 'illegal request' );
  724. $item = array (
  725. 'iid' => $iid,
  726. 'postStatus' => 1,
  727. 'updateTime' => date ( "Y-m-d H:i:s" ),
  728. 'postTime' => date ( "Y-m-d H:i:s" ),
  729. 'expressCompany' => $expressCompany,
  730. 'expressNumber' => $expressNumber,
  731. 'actualItems' => $actualItems,
  732. 'poster' => $this->staff [0] ['username']
  733. );
  734. $invoice->setInvoiceByCondition ( $item );
  735. return '/invoicePost';
  736. }
  737. /**
  738. * 退票处理页面
  739. */
  740. function invoiceUntread() {
  741. Doo::loadModel ( 'invoice' );
  742. $invoice = new invoice ();
  743. $untreadInvoice = $invoice->getInvoiceByUntreadStatus ( 1 );
  744. $establishedInvoice = $invoice->getInvoiceByUntreadStatus ( 2 );
  745. $data ['untreadInvoice'] = $untreadInvoice;
  746. $data ['establishedInvoice'] = $establishedInvoice;
  747. $data ['memu'] = "invoice";
  748. $data ['staff'] = $this->staff;
  749. $data ['receiptMemu'] = 'invoiceUntread';
  750. $this->render ( "/admin/invoiceUntread", $data );
  751. }
  752. /**
  753. * 确认收到退回的发票,开票状态为退回
  754. */
  755. function invoiceUntreadEstablishedDo() {
  756. $untreadIidKey = $this->get_args ( 'untreadIidKey' ) ? $this->get_args ( 'untreadIidKey' ) : '';
  757. Doo::loadModel ( 'invoice' );
  758. $invoice = new invoice ();
  759. Doo::loadModel ( 'invoiceOperationLog' );
  760. $invoiceOperationLog = new invoiceOperationLog ();
  761. $iid = $invoice->authcode ( $untreadIidKey );
  762. if (! empty ( $iid ) && ! is_numeric ( $iid ))
  763. die ( 'illegal request' );
  764. $item = array (
  765. 'iid' => $iid,
  766. 'untreadStatus' => 2,
  767. 'updateTime' => date ( "Y-m-d H:i:s" )
  768. );
  769. $invoice->setInvoiceByCondition ( $item );
  770. $item = array (
  771. 'date' => date ( "Y-m-d H:i:s" ),
  772. 'operation' => '已确认退票',
  773. 'status' => 6,
  774. 'img' => $this->staff [0] ['avatar'],
  775. 'username' => $this->staff [0] ['username'],
  776. 'uid' => $this->staff [0] ['sid'],
  777. 'category' => $this->staff [0] ['category'],
  778. 'iid' => $iid
  779. );
  780. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  781. return "/invoiceUntread";
  782. }
  783. function invoiceReceivables() {
  784. Doo::loadModel ( 'L_category' );
  785. $lCategory = new L_category ();
  786. Doo::loadModel ( 'staff' );
  787. $staff = new staff ();
  788. Doo::loadModel ( 'invoiceReceivables' );
  789. $invoiceReceivables = new invoiceReceivables ();
  790. $category = $lCategory->getCategory ();
  791. $staffList = $staff->getStaffByCid ( $this->staff [0] ['cid'] );
  792. $receivablesList=$invoiceReceivables->getInvoiceReceivablesByNew();
  793. //print_r($receivablesList);
  794. $data ['receivablesList'] =$receivablesList;
  795. $data ['staffList'] = $staffList;
  796. $data ['category'] = $category;
  797. $data ['memu'] = "invoice";
  798. $data ['staff'] = $this->staff;
  799. $data ['receiptMemu'] = 'invoiceReceivables';
  800. $this->render ( "/admin/invoiceReceivables", $data );
  801. }
  802. /**
  803. * 录入收款数据
  804. * @return string
  805. */
  806. function invoiceReceivablesDo() {
  807. $receivablesPrice = $this->get_args ( 'receivablesPrice' ) ? $this->get_args ( 'receivablesPrice' ) : "";
  808. $receivablesMessage = $this->get_args ( 'receivablesMessage' ) ? $this->get_args ( 'receivablesMessage' ) : "";
  809. $receivablesBank = $this->get_args ( 'receivablesBank' ) ? $this->get_args ( 'receivablesBank' ) : "";
  810. $receivablesDate = $this->get_args ( 'receivablesDate' ) ? $this->get_args ( 'receivablesDate' ) : "";
  811. $receivablesCategory = $this->get_args ( 'receivablesCategory' ) ? $this->get_args ( 'receivablesCategory' ) : "";
  812. $receivablesStaff = $this->get_args ( 'receivablesStaff' ) ? $this->get_args ( 'receivablesStaff' ) : "";
  813. Doo::loadModel ( 'invoiceReceivables' );
  814. $invoiceReceivables = new invoiceReceivables ();
  815. Doo::loadModel ( 'invoiceROLog' );
  816. $invoiceROLog = new invoiceROLog ();
  817. if (! empty ( $receivablesPrice ) && ! empty ( $receivablesMessage ) && ! empty ( $receivablesBank ) && ! empty ( $receivablesDate ) && ! empty ( $receivablesCategory ) && ! empty ( $receivablesStaff )) {
  818. $item = array (
  819. 'receivablesPrice' => $receivablesPrice,
  820. 'receivablesMessage' => $receivablesMessage,
  821. 'receivablesSerial' => "#SK" . date ( "Ymd" ) . mt_rand ( 1000, 9999 ),
  822. 'receivablesBank' => $receivablesBank,
  823. 'receivablesDate' => $receivablesDate,
  824. 'inputStaff' => $this->staff [0] ['username'],
  825. 'date' => date ( "Y-m-d" ),
  826. 'receivablesCategory' => $receivablesCategory,
  827. 'receivablesStaff' => $receivablesStaff
  828. );
  829. $irid = $invoiceReceivables->addInvoiceReceivables ( $item );
  830. // 收款操作日志
  831. if ($receivablesCategory == 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  832. $item = array (
  833. 'operation' => $this->staff [0] ['username'] . " 转入 公共待认领款项 "
  834. );
  835. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff == 'PUBLIC')
  836. $item = array (
  837. 'operation' => $this->staff [0] ['username'] . "转入 办事处待认领款项"
  838. );
  839. elseif ($receivablesCategory != 'PUBLIC' && $receivablesStaff != 'PUBLIC') {
  840. $receivablesStaff = explode ( '-', $receivablesStaff );
  841. $item = array (
  842. 'operation' => $this->staff [0] ['username'] . " 转入 " . $receivablesStaff [1]
  843. );
  844. }
  845. $item += array (
  846. 'date' => date ( "Y-m-d" ),
  847. 'status' => 1,
  848. 'img' => $this->staff [0] ['avatar'],
  849. 'username' => $this->staff [0] ['username'],
  850. 'uid' => $this->staff [0] ['sid'],
  851. 'category' => $this->staff [0] ['category'],
  852. 'irid' => $irid
  853. );
  854. $invoiceROLog->setInvoiceROLog ( $item );
  855. }
  856. return "/invoiceReceivables";
  857. }
  858. /**
  859. * 收款认领页面-包括公共认领 办事处认领 最近已认领数据
  860. */
  861. function invoiceReceivablesClaim() {
  862. Doo::loadModel ( 'invoiceReceivables' );
  863. $invoiceReceivables = new invoiceReceivables ();
  864. $receivablesList = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'] );
  865. $data ['receivablesList'] = $receivablesList;
  866. $data ['memu'] = "invoice";
  867. $data ['staff'] = $this->staff;
  868. $data ['receiptMemu'] = 'invoiceReceivablesClaim';
  869. $this->render ( "/admin/invoiceReceivablesClaim", $data );
  870. }
  871. /**
  872. * 管理员录入的收款 ,确认认领到谁的名下
  873. */
  874. function invoiceReceivablesAscription() {
  875. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  876. Doo::loadModel ( 'invoiceReceivables' );
  877. $invoiceReceivables = new invoiceReceivables ();
  878. Doo::loadModel ( 'invoiceROLog' );
  879. $invoiceROLog = new invoiceROLog ();
  880. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  881. if (! empty ( $detail ) && $detail ['receivablesStaff'] == 'PUBLIC') {
  882. $item = array (
  883. 'irid' => $detail ['irid'],
  884. 'receivablesCategory' => $this->staff [0] ['cid'] . ":" . $this->staff [0] ['category'],
  885. 'receivablesStaff' => $this->staff [0] ['sid'] . "-" . $this->staff [0] ['username'],
  886. 'confirmTime' => date ( "Y-m-d H:i:s" ),
  887. 'source' => 1
  888. );
  889. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  890. $item = array (
  891. 'date' => date ( "Y-m-d" ),
  892. 'operation' => $this->staff [0] ['username'] . " 认领 ",
  893. 'status' => 2,
  894. 'img' => $this->staff [0] ['avatar'],
  895. 'username' => $this->staff [0] ['username'],
  896. 'uid' => $this->staff [0] ['sid'],
  897. 'category' => $this->staff [0] ['category'],
  898. 'irid' => $irid
  899. );
  900. $invoiceROLog->setInvoiceROLog ( $item );
  901. }
  902. return "/invoiceReceivablesClaim";
  903. }
  904. /**
  905. */
  906. function invoiceMyReceivables() {
  907. Doo::loadModel ( 'invoiceReceivables' );
  908. $invoiceReceivables = new invoiceReceivables ();
  909. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  910. $data ['list'] = $list;
  911. $data ['memu'] = "invoice";
  912. $data ['staff'] = $this->staff;
  913. $data ['receiptMemu'] = 'invoiceMyReceivables';
  914. $this->render ( "/admin/invoiceMyReceivables", $data );
  915. }
  916. /**
  917. * 收款绑定发票 ,一个收款只能绑定一个发票
  918. */
  919. function invoiceBindReceivables() {
  920. $claimKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  921. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  922. Doo::loadModel ( 'invoice' );
  923. $invoice = new invoice ();
  924. Doo::loadModel ( 'invoiceReceivables' );
  925. $invoiceReceivables = new invoiceReceivables ();
  926. Doo::loadModel ( 'invoiceOperationLog' );
  927. $invoiceOperationLog = new invoiceOperationLog ();
  928. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  929. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $claimKey );
  930. if (empty ( $detail ) && empty ( $detailM ))
  931. die ( 'illegal request' );
  932. if ($detailM ['receivablesPrice'] >= $detail ['invoicePrice']) {
  933. $price = $detailM ['receivablesPrice'] - $detail ['invoicePrice'];
  934. die ( '<p>收款金额超出开票金额 ¥' . $price . '元,请谨慎操作</p><a href="/invoiceMyReceivables">返回</a>' );
  935. }
  936. $item = array (
  937. 'irid' => $detailM ['irid'],
  938. 'bindStatus' => 1,
  939. 'iid' => $detail ['iid'],
  940. 'bindDate' => date ( "Y-m-d H:i:s" )
  941. );
  942. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  943. $iridString = "";
  944. if (empty ( $detail ['irid'] ))
  945. $iridString = $detailM ['irid'];
  946. else
  947. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  948. $item = array (
  949. 'iid' => $detail ['iid'],
  950. 'irid' => $iridString
  951. );
  952. $invoice->setInvoiceByCondition ( $item );
  953. // 操作日志
  954. $item = array (
  955. 'date' => date ( "Y-m-d H:i:s" ),
  956. 'operation' => "收款" . $detailM ['receivablesSerial'] . "入账到发票" . $detail ['invoiceSerial'],
  957. 'status' => 8,
  958. 'img' => $this->staff [0] ['avatar'],
  959. 'username' => $this->staff [0] ['username'],
  960. 'uid' => $this->staff [0] ['sid'],
  961. 'category' => $this->staff [0] ['category'],
  962. 'iid' => $detail ['iid']
  963. );
  964. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  965. return "/invoiceMyReceivables";
  966. }
  967. /**
  968. * 发票收款完成
  969. */
  970. function invoiceEnterReceivables() {
  971. $invoiceKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  972. // $invoiceClaim = $this->get_args ( 'invoiceClaim' ) ? $this->get_args ( 'invoiceClaim' ) : "";
  973. Doo::loadModel ( 'invoice' );
  974. $invoice = new invoice ();
  975. Doo::loadModel ( 'invoiceOperationLog' );
  976. $invoiceOperationLog = new invoiceOperationLog ();
  977. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  978. if (empty ( $detail ))
  979. die ( 'illegal request' );
  980. /*
  981. * $receivablesPrice=0;$iridString=$detail['irid'];$iridList=array(); foreach ($invoiceClaim as $key=>$value){ $detailM=$invoiceReceivables->getInvoiceReceivablesByIrid($value); $receivablesPrice+=$detailM['receivablesPrice']; if (empty($iridString)) $iridString=$detailM['irid']; else $iridString.=",".$detailM['irid']; array_push($iridList, $detailM['irid']); } if ($receivablesPrice>=$detail['invoicePrice']){ $price=$receivablesPrice-$detail['invoicePrice']; die('<p>收款金额超出开票金额 ¥'.$price.'元,请谨慎操作</p><a href="/invoice">返回</a>'); }
  982. */
  983. $item = array (
  984. 'untreadStatus' => 3,
  985. 'updateTime' => date ( "Y-m-d H:i:s" ),
  986. 'iid' => $detail ['iid']
  987. );
  988. $invoice->setInvoiceByCondition ( $item );
  989. // 操作日志
  990. $item = array (
  991. 'date' => date ( "Y-m-d H:i:s" ),
  992. 'operation' => "发票" . $detail ['invoiceSerial'] . "收款完成",
  993. 'status' => 9,
  994. 'img' => $this->staff [0] ['avatar'],
  995. 'username' => $this->staff [0] ['username'],
  996. 'uid' => $this->staff [0] ['sid'],
  997. 'category' => $this->staff [0] ['category'],
  998. 'iid' => $detail ['iid']
  999. );
  1000. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1001. /*
  1002. * foreach ($iridList as $key=>$value){ $item = array ( 'iid' => $detail['iid'], 'irid' => $value, 'bindDate'=>date ( "Y-m-d H:i:s" ), 'bindStatus' => 1 ); $invoiceReceivables->setInvoiceReceivablesByCondition($item); }
  1003. */
  1004. return "/invoice";
  1005. }
  1006. function invoiceAggregate(){
  1007. $data ['memu'] = "invoice";
  1008. $data ['staff'] = $this->staff;
  1009. $data ['receiptMemu'] = 'invoiceAggregate';
  1010. $this->render ( "/admin/invoiceAggregate", $data );
  1011. }
  1012. /**
  1013. * 获得与我有关可收款的发票
  1014. */
  1015. function ajaxGetInvoiceByStaff() {
  1016. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  1017. Doo::loadModel ( 'invoice' );
  1018. $invoice = new invoice ();
  1019. $list = $invoice->getInvoiceByReceivables ( $this->staff [0] ['sid'] );
  1020. $html = "";
  1021. $i = 1;
  1022. foreach ( $list as $key => $value ) {
  1023. $html .= '<tr>
  1024. <td>' . $value ['invoiceElement'] . '</td>
  1025. <td>¥' . $value ['invoicePrice'] . '</td>';
  1026. if (! empty ( $value ['invoiceType'] )) {
  1027. $html .= '<td>增值税专用发票</td>
  1028. <td>' . $value ['invoiceCompany'] . '</td>';
  1029. } else {
  1030. $html .= '<td>增值税普通发票</td>
  1031. <td>' . $value ['invoiceTitle'] . '</td>';
  1032. }
  1033. $html .= '<td><label><input type="radio" node-Claim="true_' . $i . '" p-data="' . $value ['iidKey'] . '" name="invoiceClaim"> 使用Ta</label></td></tr>
  1034. <script>
  1035. $(\'input[node-Claim="true_' . $i . '"]\').click(function() {
  1036. var invoiceKey= $(this).attr("p-data");
  1037. var claimKey=$("input[name=\'key\']").val();
  1038. $("p[node-msg=\"true\"]").hide();
  1039. var url = "/ajaxCompareInvoicePrice";
  1040. $.ajax({
  1041. url : url,
  1042. type : "post",
  1043. cache : false,
  1044. dataType : "json",
  1045. data : {
  1046. claimKey : claimKey,
  1047. invoiceKey:invoiceKey
  1048. },
  1049. global : true,
  1050. success : function(data) {
  1051. $("input[name=\'invoiceKey\']").val("' . $value ['iidKey'] . '");
  1052. if (data.status == 1) {
  1053. $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。");
  1054. $("p[node-msg=\"true\"]").show();
  1055. }
  1056. },
  1057. error : function(err) {
  1058. }
  1059. });
  1060. });
  1061. </script>
  1062. ';
  1063. $i ++;
  1064. }
  1065. echo json_encode ( array (
  1066. 'status' => 1,
  1067. 'html' => $html
  1068. ) );
  1069. }
  1070. /**
  1071. * 获取一条收款信息
  1072. */
  1073. function ajaxGetInvoiceReceivables() {
  1074. $irid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  1075. Doo::loadModel ( 'invoiceReceivables' );
  1076. $invoiceReceivables = new invoiceReceivables ();
  1077. $detail = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  1078. echo json_encode ( array (
  1079. 'status' => 1,
  1080. 'detail' => $detail
  1081. ) );
  1082. }
  1083. /**
  1084. * 异步获取办事处用户
  1085. */
  1086. function ajaxGetStaffByCategory() {
  1087. $cid = $this->get_args ( 'cid' ) ? $this->get_args ( 'cid' ) : "";
  1088. Doo::loadModel ( 'staff' );
  1089. $staff = new staff ();
  1090. if ($cid == "PUBLIC") {
  1091. echo json_encode ( array (
  1092. 'status' => 1,
  1093. 'html' => '<option value="PUBLIC">办事处待认领款项</option>'
  1094. ) );
  1095. die ();
  1096. }
  1097. if (! is_numeric ( $cid )) {
  1098. echo json_encode ( array (
  1099. 'status' => 0,
  1100. 'msg' => 'illegal request'
  1101. ) );
  1102. die ();
  1103. }
  1104. $staffList = $staff->getStaffByCid ( $cid );
  1105. $html = '<option value="PUBLIC">办事处待认领款项</option>';
  1106. foreach ( $staffList as $key => $value ) {
  1107. $html .= '<option value="' . $value ['sid'] . '-' . $value ['username'] . '">' . $value ['category'] . '-' . $value ['username'] . '</option>';
  1108. }
  1109. echo json_encode ( array (
  1110. 'status' => 1,
  1111. 'html' => $html
  1112. ) );
  1113. }
  1114. /**
  1115. * 异步获取一条发票的邮寄信息
  1116. */
  1117. function ajaxGetInvoicePostDetail() {
  1118. $iid = $this->get_args ( 'iidKey' ) ? $this->get_args ( 'iidKey' ) : "";
  1119. Doo::loadModel ( 'invoice' );
  1120. $invoice = new invoice ();
  1121. $iid = $invoice->authcode ( $iid );
  1122. if (! is_numeric ( $iid )) {
  1123. echo json_encode ( array (
  1124. 'status' => 0,
  1125. 'msg' => 'illegal request'
  1126. ) );
  1127. die ();
  1128. }
  1129. $select = "iid,recipients,recipientsPhone,recipientsAddress,mailItems,expressCompany,expressNumber,actualItems";
  1130. $invoiceDetail = $invoice->getInvoiceByIid ( $iid, $select );
  1131. echo json_encode ( array (
  1132. 'status' => 1,
  1133. 'invoiceDetail' => $invoiceDetail
  1134. ) );
  1135. }
  1136. function ajaxCompareClaimPrice() {
  1137. $irid = $this->get_args ( 'irid' ) ? $this->get_args ( 'irid' ) : "";
  1138. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1139. Doo::loadModel ( 'invoice' );
  1140. $invoice = new invoice ();
  1141. Doo::loadModel ( 'invoiceReceivables' );
  1142. $invoiceReceivables = new invoiceReceivables ();
  1143. Doo::loadModel ( 'invoiceOperationLog' );
  1144. $invoiceOperationLog = new invoiceOperationLog ();
  1145. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  1146. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $irid );
  1147. if (empty ( $detail ) || empty ( $detailM )) {
  1148. echo json_encode ( array (
  1149. 'status' => 2,
  1150. 'msg' => '非法请求,请重新登录'
  1151. ) );
  1152. die ();
  1153. }
  1154. $iridString = "";
  1155. if (empty ( $detail ['irid'] ))
  1156. $iridString = $detailM ['irid'];
  1157. else
  1158. $iridString = $detail ['irid'] . ',' . $detailM ['irid'];
  1159. $item = array (
  1160. 'irid' => $iridString,
  1161. 'bindTime' => date ( "Y-m-d H:i:s" ),
  1162. 'updateTime' => date ( "Y-m-d H:i:s" ),
  1163. 'iid' => $detail ['iid']
  1164. );
  1165. $invoice->setInvoiceByCondition ( $item );
  1166. // 操作日志
  1167. $item = array (
  1168. 'date' => date ( "Y-m-d H:i:s" ),
  1169. 'operation' => "收款入账" . $detailM ['receivablesSerial'] . "到发票" . $detail ['invoiceSerial'],
  1170. 'status' => 8,
  1171. 'img' => $this->staff [0] ['avatar'],
  1172. 'username' => $this->staff [0] ['username'],
  1173. 'uid' => $this->staff [0] ['sid'],
  1174. 'category' => $this->staff [0] ['category'],
  1175. 'iid' => $detail ['iid']
  1176. );
  1177. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1178. $item = array (
  1179. 'iid' => $detail ['iid'],
  1180. 'irid' => $detailM ['irid'],
  1181. 'bindDate' => date ( "Y-m-d H:i:s" ),
  1182. 'bindStatus' => 1
  1183. )
  1184. ;
  1185. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  1186. $price = 0;
  1187. $priceStatus = 0;
  1188. $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $iridString );
  1189. $receivablesPrice = 0;
  1190. foreach ( $list as $key => $value ) {
  1191. $receivablesPrice += $value ['receivablesPrice'];
  1192. }
  1193. if ($receivablesPrice >= $detail ['invoicePrice']) {
  1194. $price = $receivablesPrice - $detail ['invoicePrice'];
  1195. $priceStatus = 1;
  1196. }
  1197. echo json_encode ( array (
  1198. 'status' => 1,
  1199. 'html' => '<tr><td>¥' . $detailM ['receivablesPrice'] . '</td><td>' . $detailM ['receivablesMessage'] . '</td><td>' . $detailM ['receivablesBank'] . '</td>
  1200. <td>' . $detailM ['receivablesDate'] . '</td><td><a node-remove="Da' . $detailM ['iridKey'] . '" href="javascript:void(0);">移除</a></td></tr>
  1201. <script>
  1202. $(\'a[node-remove="Da' . $detailM ['iridKey'] . '"]\').click(function() {
  1203. var invoiceKey=$("input[name=\'key\']").val();
  1204. var irid= $(this).attr("p-data");
  1205. var iridKey="' . $detailM ["iridEn"] . '";
  1206. var element=($(this));
  1207. $("p[node-loading=\"true\"]").show();
  1208. $("p[node-loading=\"true\"]").html("移除处理中...");
  1209. $("p[node-msg=\"true\"]").hide();
  1210. var url = "/ajaxReceivablesRemove";
  1211. $.ajax({
  1212. url : url,
  1213. type : "post",
  1214. cache : false,
  1215. dataType : "json",
  1216. data : {
  1217. key : iridKey,
  1218. invoiceKey:invoiceKey
  1219. },
  1220. global : true,
  1221. success : function(data) {
  1222. $("input[name=\'invoiceKey\']").val("' . $detailM ['iridEn'] . '");
  1223. if (data.status == 1) {
  1224. $(element).parent().parent().remove();
  1225. $("tbody[data-invoice=\"myReceivables\"]").append(data.html);
  1226. $("p[node-loading=\"true\"]").hide();
  1227. if(data.priceStatus == 1){
  1228. $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。");
  1229. $("p[node-msg=\"true\"]").show();
  1230. }
  1231. }else if(data.status == 2){
  1232. $("p[node-loading=\"true\"]").html(data.msg);
  1233. }
  1234. },
  1235. error : function(err) {
  1236. }
  1237. });
  1238. });
  1239. </script>
  1240. ',
  1241. 'price' => $price,
  1242. 'priceStatus' => $priceStatus
  1243. ) );
  1244. }
  1245. /**
  1246. * 从发票中移除已经入账的收款
  1247. */
  1248. function ajaxReceivablesRemove() {
  1249. $iridKey = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  1250. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1251. Doo::loadModel ( 'invoice' );
  1252. $invoice = new invoice ();
  1253. Doo::loadModel ( 'invoiceReceivables' );
  1254. $invoiceReceivables = new invoiceReceivables ();
  1255. Doo::loadModel ( 'invoiceOperationLog' );
  1256. $invoiceOperationLog = new invoiceOperationLog ();
  1257. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  1258. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $iridKey );
  1259. // echo $detail['irid']."<br/>";
  1260. $invoiceIrid = explode ( ",", $detail ['irid'] );
  1261. foreach ( $invoiceIrid as $key => $value ) {
  1262. if ($value == $detailM ['irid'])
  1263. unset ( $invoiceIrid [$key] );
  1264. }
  1265. $invoiceIrid = implode ( ",", $invoiceIrid );
  1266. // echo $invoiceIrid."ddd";
  1267. // print_r($invoiceIrid);
  1268. $item = array (
  1269. 'irid' => $invoiceIrid,
  1270. 'iid' => $detail ['iid']
  1271. );
  1272. $invoice->setInvoiceByCondition ( $item );
  1273. $item = array (
  1274. 'iid' => 0,
  1275. 'irid' => $detailM ['irid'],
  1276. 'bindDate' => '',
  1277. 'bindStatus' => 0
  1278. )
  1279. ;
  1280. $invoiceReceivables->setInvoiceReceivablesByCondition ( $item );
  1281. // 操作日志
  1282. $item = array (
  1283. 'date' => date ( "Y-m-d H:i:s" ),
  1284. 'operation' => "收款移除" . $detailM ['receivablesSerial'],
  1285. 'status' => 10,
  1286. 'img' => $this->staff [0] ['avatar'],
  1287. 'username' => $this->staff [0] ['username'],
  1288. 'uid' => $this->staff [0] ['sid'],
  1289. 'category' => $this->staff [0] ['category'],
  1290. 'iid' => $detail ['iid']
  1291. );
  1292. $invoiceOperationLog->setInvoiceOperationLog ( $item );
  1293. $price = 0;
  1294. $priceStatus = 0;
  1295. $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $invoiceIrid );
  1296. $receivablesPrice = 0;
  1297. foreach ( $list as $key => $value ) {
  1298. $receivablesPrice += $value ['receivablesPrice'];
  1299. }
  1300. if ($receivablesPrice >= $detail ['invoicePrice']) {
  1301. $price = $receivablesPrice - $detail ['invoicePrice'];
  1302. $priceStatus = 1;
  1303. }
  1304. echo json_encode ( array (
  1305. 'status' => 1,
  1306. 'html' => '<tr id="' . $detailM ['receivablesSerial'] . '" >
  1307. <td>¥' . $detailM ['receivablesPrice'] . '</td>
  1308. <td>' . $detailM ['receivablesMessage'] . '</td>
  1309. <td>' . $detailM ['receivablesBank'] . '</td>
  1310. <td>' . $detailM ['receivablesDate'] . '</td><td>
  1311. <a href="javascript:void(0)" node-Claim="true_' . $detailM ['iridKey'] . '" p-data="' . $detailM ['iridEn'] . '" name="invoiceClaim" class="button">入账</a>
  1312. </td></tr>
  1313. <script>
  1314. $(\'a[node-Claim="true_' . $detailM ['iridKey'] . '"]\').click(function() {
  1315. var invoiceKey=$("input[name=\'key\']").val();
  1316. var irid= $(this).attr("p-data");
  1317. var element=($(this));
  1318. $("p[node-loading=\"true\"]").show();
  1319. $("p[node-loading=\"true\"]").html("入账处理中...");
  1320. $("p[node-msg=\"true\"]").hide();
  1321. var url = "/ajaxCompareClaimPrice";
  1322. $.ajax({
  1323. url : url,
  1324. type : "post",
  1325. cache : false,
  1326. dataType : "json",
  1327. data : {
  1328. irid : irid,
  1329. invoiceKey:invoiceKey
  1330. },
  1331. global : true,
  1332. success : function(data) {
  1333. $("input[name=\'invoiceKey\']").val("' . $detailM ['iridEn'] . '");
  1334. if (data.status == 1) {
  1335. $(element).parent().parent().remove();
  1336. $("tbody[box-enter=\"true\"]").append(data.html);
  1337. $("p[node-loading=\"true\"]").hide();
  1338. if(data.priceStatus == 1){
  1339. $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。");
  1340. $("p[node-msg=\"true\"]").show();
  1341. }
  1342. }else if(data.status == 2){
  1343. $("p[node-loading=\"true\"]").html(data.msg);
  1344. }
  1345. },
  1346. error : function(err) {
  1347. }
  1348. });
  1349. });
  1350. </script>
  1351. ',
  1352. 'price' => $price,
  1353. 'priceStatus' => $priceStatus
  1354. ) );
  1355. }
  1356. /**
  1357. * 我的收款中 选择哪个发票入账,进行金额判断
  1358. */
  1359. function ajaxCompareInvoicePrice() {
  1360. $claimKey = $this->get_args ( 'claimKey' ) ? $this->get_args ( 'claimKey' ) : "";
  1361. $invoiceKey = $this->get_args ( 'invoiceKey' ) ? $this->get_args ( 'invoiceKey' ) : "";
  1362. Doo::loadModel ( 'invoice' );
  1363. $invoice = new invoice ();
  1364. Doo::loadModel ( 'invoiceReceivables' );
  1365. $invoiceReceivables = new invoiceReceivables ();
  1366. $detail = $invoice->getInvoiceByIid ( $invoiceKey );
  1367. $keyList = explode ( ';', $claimKey );
  1368. $receivablesPrice = 0;
  1369. foreach ( $keyList as $key => $value ) {
  1370. $detailM = $invoiceReceivables->getInvoiceReceivablesByIrid ( $value );
  1371. $receivablesPrice += $detailM ['receivablesPrice'];
  1372. }
  1373. if ($receivablesPrice >= $detail ['invoicePrice']) {
  1374. $price = $receivablesPrice - $detail ['invoicePrice'];
  1375. echo json_encode ( array (
  1376. 'status' => 1,
  1377. 'price' => $price
  1378. ) );
  1379. } else
  1380. echo json_encode ( array (
  1381. 'status' => 2
  1382. ) );
  1383. }
  1384. /*
  1385. * 获得与我有关收款数据
  1386. */
  1387. function ajaxGetReceivalblesByStaff() {
  1388. $iid = $this->get_args ( 'key' ) ? $this->get_args ( 'key' ) : "";
  1389. Doo::loadModel ( 'invoiceReceivables' );
  1390. $invoiceReceivables = new invoiceReceivables ();
  1391. Doo::loadModel ( 'invoice' );
  1392. $invoice = new invoice ();
  1393. $detail = $invoice->getInvoiceByIid ( $iid );
  1394. $list = $invoiceReceivables->getInvoiceReceivablesByClaim ( $this->staff [0] ['cid'], $this->staff [0] ['sid'] );
  1395. $html = "";
  1396. $i = 1;
  1397. foreach ( $list ['myClaim'] as $key => $value ) {
  1398. $html .= '<tr id="' . $value ['receivablesSerial'] . '" >
  1399. <td>¥' . $value ['receivablesPrice'] . '</td>
  1400. <td>' . $value ['receivablesMessage'] . '</td>
  1401. <td>' . $value ['receivablesBank'] . '</td>
  1402. <td>' . $value ['receivablesDate'] . '</td>';
  1403. $html .= '<td>
  1404. <a href="javascript:void(0)" node-Claim="true_' . $i . '" p-data="' . $value ['iidKey'] . '" name="invoiceClaim" class="button">入账</a>
  1405. </td></tr>
  1406. <script>
  1407. $(\'a[node-Claim="true_' . $i . '"]\').click(function() {
  1408. var invoiceKey=$("input[name=\'key\']").val();
  1409. var irid= $(this).attr("p-data");
  1410. var element=($(this));
  1411. $("p[node-loading=\"true\"]").show();
  1412. $("p[node-loading=\"true\"]").html("入账处理中...");
  1413. $("p[node-msg=\"true\"]").hide();
  1414. var url = "/ajaxCompareClaimPrice";
  1415. $.ajax({
  1416. url : url,
  1417. type : "post",
  1418. cache : false,
  1419. dataType : "json",
  1420. data : {
  1421. irid : irid,
  1422. invoiceKey:invoiceKey
  1423. },
  1424. global : true,
  1425. success : function(data) {
  1426. $("input[name=\'invoiceKey\']").val("' . $value ['iidKey'] . '");
  1427. if (data.status == 1) {
  1428. $(element).parent().parent().remove();
  1429. $("tbody[box-enter=\"true\"]").append(data.html);
  1430. $("p[node-loading=\"true\"]").hide();
  1431. if(data.priceStatus == 1){
  1432. $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。");
  1433. $("p[node-msg=\"true\"]").show();
  1434. }
  1435. }else if(data.status == 2){
  1436. $("p[node-loading=\"true\"]").html(data.msg);
  1437. }
  1438. },
  1439. error : function(err) {
  1440. }
  1441. });
  1442. });
  1443. </script>
  1444. ';
  1445. $i ++;
  1446. }
  1447. $html2 = "";
  1448. $list2 = $invoiceReceivables->getInvoiceReceivablesByIid ( $iid, 1 );
  1449. foreach ( $list2 as $key => $value ) {
  1450. $html2 .= '<tr id="' . $value ['receivablesSerial'] . '" >
  1451. <td>¥' . $value ['receivablesPrice'] . '</td>
  1452. <td>' . $value ['receivablesMessage'] . '</td>
  1453. <td>' . $value ['receivablesBank'] . '</td>
  1454. <td>' . $value ['receivablesDate'] . '</td>';
  1455. $html2 .= '<td>
  1456. <a href="javascript:void(0)" node-remove="Da' . $value ['iridKey'] . '" >移除</a>
  1457. </td></tr>
  1458. <script>
  1459. $(\'a[node-remove="Da' . $value ['iridKey'] . '"]\').click(function() {
  1460. var invoiceKey=$("input[name=\'key\']").val();
  1461. var irid= $(this).attr("p-data");
  1462. var iridKey="' . $value ["iidKey"] . '";
  1463. var element=($(this));
  1464. $("p[node-loading=\"true\"]").show();
  1465. $("p[node-loading=\"true\"]").html("移除处理中...");
  1466. $("p[node-msg=\"true\"]").hide();
  1467. var url = "/ajaxReceivablesRemove";
  1468. $.ajax({
  1469. url : url,
  1470. type : "post",
  1471. cache : false,
  1472. dataType : "json",
  1473. data : {
  1474. key : iridKey,
  1475. invoiceKey:invoiceKey
  1476. },
  1477. global : true,
  1478. success : function(data) {
  1479. $("input[name=\'invoiceKey\']").val("' . $value ['iidKey'] . '");
  1480. if (data.status == 1) {
  1481. $(element).parent().parent().remove();
  1482. $("tbody[data-invoice=\"myReceivables\"]").append(data.html);
  1483. $("p[node-loading=\"true\"]").hide();
  1484. if(data.priceStatus == 1){
  1485. $("p[node-msg=\"true\"]").html("收款金额超出开票金额 ¥"+data.price+"元,请谨慎操作。");
  1486. $("p[node-msg=\"true\"]").show();
  1487. }
  1488. }else if(data.status == 2){
  1489. $("p[node-loading=\"true\"]").html(data.msg);
  1490. }
  1491. },
  1492. error : function(err) {
  1493. }
  1494. });
  1495. });
  1496. </script>
  1497. ';
  1498. $i ++;
  1499. }
  1500. $price = 0;
  1501. $priceStatus = 0;
  1502. $list = $invoiceReceivables->getInvoiceReceivablesInIridString ( $detail ['irid'] );
  1503. $receivablesPrice = 0;
  1504. foreach ( $list as $key => $value ) {
  1505. $receivablesPrice += $value ['receivablesPrice'];
  1506. }
  1507. if ($receivablesPrice >= $detail ['invoicePrice']) {
  1508. $price = $receivablesPrice - $detail ['invoicePrice'];
  1509. $priceStatus = 1;
  1510. }
  1511. echo json_encode ( array (
  1512. 'status' => 1,
  1513. 'html' => $html,
  1514. 'html2' => $html2,
  1515. 'price' => $price,
  1516. 'priceStatus' => $priceStatus
  1517. ) );
  1518. }
  1519. function _GetFileEXT($filename) {
  1520. $pics = explode ( '.', $filename );
  1521. $num = count ( $pics );
  1522. return $pics [$num - 1];
  1523. }
  1524. /**
  1525. * 获取get或者POST值
  1526. *
  1527. * @param string $name 属性名称
  1528. * @return fixed 值
  1529. */
  1530. function get_args($name) {
  1531. if (isset ( $_GET [$name] )) {
  1532. if (is_array ( $_GET [$name] ))
  1533. return $_GET [$name];
  1534. else
  1535. return addslashes ( $_GET [$name] );
  1536. } elseif (isset ( $_POST [$name] )) {
  1537. if (is_array ( $_POST [$name] ))
  1538. return $_POST [$name];
  1539. else
  1540. return addslashes ( $_POST [$name] );
  1541. } else
  1542. return false;
  1543. }
  1544. }
  1545. ?>