InvoiceController.php 78 KB

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