InvoiceController.php 82 KB

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