invoiceTraining.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. <?php
  2. Doo::loadCore ( 'db/DooModel' );
  3. /**
  4. * 发票培训班相关信息及其操作业务逻辑
  5. * @author CP.
  6. * @version 1.0
  7. * @namespace invoice
  8. * @package invoiceModel
  9. */
  10. class invoiceTraining extends DooModel {
  11. public $itid;
  12. public $status;
  13. public $submitStatus;
  14. public $trainName;
  15. public $cid;
  16. public $categoryName;
  17. public $creator;
  18. public $trainDate;
  19. public $invoiceTotal;
  20. public $invoiceTotalAmount;
  21. public $invoiceArriveAmount;
  22. public $arriveSchedule;
  23. public $creatorDate;
  24. public $settlementStatus;
  25. public $_table = 'CLD_invoiceTraining';
  26. public $_primarykey = 'itid';
  27. public $_fields = array (
  28. 'itid',
  29. 'status',
  30. 'submitStatus',
  31. 'trainName',
  32. 'cid',
  33. 'categoryName',
  34. 'creator',
  35. 'trainDate',
  36. 'invoiceTotal',
  37. 'invoiceTotalAmount',
  38. 'invoiceArriveAmount',
  39. 'arriveSchedule',
  40. 'settlementStatus',
  41. 'creatorDate'
  42. );
  43. /**
  44. * 添加一个培训班
  45. * @param array $item 培训班相关数据
  46. * @return number 返回培训班ID
  47. */
  48. public function addInvoiceTraining($item = array()) {
  49. $itid = 0;
  50. if (is_array ( $item ) && ! empty ( $item )) {
  51. foreach ( $item as $key => $value ) {
  52. $this->$key = $value;
  53. }
  54. $itid = $this->insert ();
  55. }
  56. return $itid;
  57. }
  58. function getInvoiceTrainStatistics($itid = 0) {
  59. $itidCondition = ' and trainId=NULL ';
  60. if (! empty ( $itid ))
  61. $itidCondition = ' and trainId in (' . $itid . ') ';
  62. $sql = 'select sum(invoicePrice) as invoicePrice ,trainId
  63. from CLD_invoice
  64. where status=2 and printStatus=1 and (untreadStatus =0 or untreadStatus=3) ' . $itidCondition . '
  65. GROUP BY status';
  66. $query = Doo::db ()->query ( $sql );
  67. $result = $query->fetchAll ();
  68. if (! empty ( $result ))
  69. $detail = array (
  70. 'invoicePrice' => $result [0] ['invoicePrice']
  71. );
  72. else
  73. $detail = array (
  74. 'invoicePrice' => 0
  75. );
  76. // print_r($result);
  77. $itidCondition = ' and a.trainId=NULL ';
  78. if (! empty ( $itid ))
  79. $itidCondition = ' and a.trainId in (' . $itid . ') ';
  80. $sql = 'select sum(b.receivablesPrice) as receivablesPrice ,a.trainId,count(*) as count
  81. from CLD_invoice as a left join CLD_invoiceReceivables as b on find_in_set(b.irid,a.irid)
  82. where a.status=2 and a.printStatus=1 and (a.untreadStatus =0 or a.untreadStatus=3) and a.irid!="" ' . $itidCondition . '
  83. GROUP BY a.status';
  84. $query = Doo::db ()->query ( $sql );
  85. $result = $query->fetchAll ();
  86. if (! empty ( $result )) {
  87. $detail += array (
  88. 'receivablesPrice' => $result [0] ['receivablesPrice']
  89. );
  90. $detail += array (
  91. 'rPrice' => $detail ['invoicePrice'] - $result [0] ['receivablesPrice']
  92. );
  93. } else {
  94. $detail += array (
  95. 'receivablesPrice' => 0
  96. );
  97. $detail += array (
  98. 'rPrice' => $detail ['invoicePrice']
  99. );
  100. }
  101. return $detail;
  102. }
  103. /**
  104. * 根据办事处获得结算完成培训班
  105. * @param number $SStatus
  106. * @return string
  107. */
  108. function getInvoiceTrainBySettlementStatus($SStatus = 0, $cid = 0) {
  109. $condition = array (
  110. 'where' => " settlementStatus=" . $SStatus . ' and cid=' . $cid,
  111. 'asArray' => TRUE
  112. );
  113. $list = $this->find ( $condition );
  114. Doo::loadClass ( 'XDeode' );
  115. $XDeode = new XDeode ( 5 );
  116. foreach ( $list as $key => $value ) {
  117. $list [$key] ['itidKey'] = $XDeode->encode ( $value ['itid'] );
  118. }
  119. return $list;
  120. }
  121. /**
  122. * 获得办事处下的培训班
  123. */
  124. function getInvoiceTrainingByCid($cid = 0) {
  125. $condition = array (
  126. 'where' => " cid=" . $cid,
  127. 'asArray' => TRUE
  128. );
  129. $list = $this->find ( $condition );
  130. Doo::loadClass ( 'XDeode' );
  131. $XDeode = new XDeode ( 5 );
  132. foreach ( $list as $key => $value ) {
  133. $list [$key] ['itidKey'] = $XDeode->encode ( $value ['itid'] );
  134. }
  135. return $list;
  136. }
  137. function getInvoiceTrainingByTodo($select = "", $cid = 0, $sid = 0) {
  138. Doo::loadModel ( 'staff' );
  139. $staff = new staff ();
  140. Doo::loadModel ( 'L_category' );
  141. $lCategory = new L_category ();
  142. $condition = array (
  143. 'where' => "(status= 0 or status=1) and ( cid=" . $cid . " or creator=" . $sid . " )",
  144. // 'limit' => 8,
  145. 'asArray' => TRUE
  146. );
  147. if (! empty ( $select ))
  148. $condition += array (
  149. 'select' => $select
  150. );
  151. $list = $this->find ( $condition );
  152. Doo::loadClass ( 'XDeode' );
  153. $XDeode = new XDeode ( 5 );
  154. $itid = array ();
  155. foreach ( $list as $key => $value ) {
  156. $list [$key] ['trainingKey'] = $XDeode->encode ( $value ['itid'] );
  157. $detail = $staff->getStaffBySid ( $value ['creator'] );
  158. $list [$key] ['staff'] = $detail;
  159. $detail = $lCategory->getCategoryById ( $value ['cid'] );
  160. $list [$key] ['category'] = $detail;
  161. array_push ( $itid, $value ['itid'] );
  162. }
  163. // 获得开票金额合计 入账金额合计 入账完成度
  164. Doo::loadModel ( 'invoice' );
  165. $invoice = new invoice ();
  166. $invoiceList = $invoiceRecelvablesList = array ();
  167. if (! empty ( $itid )) {
  168. $itidSql = implode ( ',', $itid );
  169. $invoiceList = $invoice->sumOfinvoiceTrain ( $itidSql );
  170. $invoiceRecelvablesList = $invoice->sumOfInvoiceRecelvablesTrain ( $itidSql );
  171. }
  172. // print_r($invoiceRecelvablesList);
  173. foreach ( $list as $key => $value ) {
  174. $countInvoice = $invoice->getInvoiceByTrainingCount ( $value ['itid'] );
  175. $value ['invoiceTotal'] = $countInvoice;
  176. $list [$key] ['invoiceTotal'] = $countInvoice;
  177. foreach ( $invoiceList as $k => $v ) {
  178. if ($value ['itid'] == $v ['trainId']) {
  179. $list [$key] ['invoiceTotalAmount'] = $v ['invoicePrice'];
  180. break;
  181. }
  182. }
  183. foreach ( $invoiceRecelvablesList as $i => $o ) {
  184. if ($value ['itid'] == $o ['trainId']) {
  185. $list [$key] ['invoiceArriveAmount'] = $o ['receivablesPrice'];
  186. $list [$key] ['arriveSchedule'] = "0";
  187. if ($value ['invoiceTotal'] != 0) {
  188. $list [$key] ['arriveSchedule'] = round ( $list [$key] ['invoiceArriveAmount'] / $list [$key] ['invoiceTotalAmount'] * 100, 2 );
  189. // $list [$key] ['arriveSchedule'] = round ( $o ['count'] / $value ['invoiceTotal'] * 100, 2 );
  190. }
  191. break;
  192. }
  193. }
  194. }
  195. return $list;
  196. }
  197. /**
  198. * 根据参数字段更新相应字段(主键ID必须传)
  199. * @param array $item 相关需要更新的字段信息
  200. * @return number 返回发票ID
  201. */
  202. public function setInvoiceTrainByCondition($item = array(), $itid = "") {
  203. $lid = 0;
  204. if (is_array ( $item ) && ! empty ( $item )) {
  205. foreach ( $item as $key => $value ) {
  206. $this->$key = $value;
  207. }
  208. if (! empty ( $isid )) {
  209. $condition = array (
  210. 'where' => "itid in (" . $itid . ")",
  211. 'asArray' => TRUE
  212. );
  213. $this->update ( $condition );
  214. } else
  215. $lid = $this->update ();
  216. }
  217. return $lid;
  218. }
  219. /**
  220. * 根据状态获取培训班
  221. * @param number $status
  222. */
  223. function getInvoiceTrainingByStatus($status = 0, $select = "", $cid = 0, $sid = 0) {
  224. Doo::loadModel ( 'staff' );
  225. $staff = new staff ();
  226. Doo::loadModel ( 'L_category' );
  227. $lCategory = new L_category ();
  228. $condition = array (
  229. 'where' => "status= '" . $status . "' and (cid=" . $cid . " or creator=" . $sid . " )",
  230. // 'limit' => 8,
  231. 'asArray' => TRUE
  232. );
  233. if (! empty ( $select ))
  234. $condition += array (
  235. 'select' => $select
  236. );
  237. $list = $this->find ( $condition );
  238. Doo::loadClass ( 'XDeode' );
  239. $XDeode = new XDeode ( 5 );
  240. $itid = array ();
  241. foreach ( $list as $key => $value ) {
  242. $list [$key] ['trainingKey'] = $XDeode->encode ( $value ['itid'] );
  243. $detail = $staff->getStaffBySid ( $value ['creator'] );
  244. $list [$key] ['staff'] = $detail;
  245. $detail = $lCategory->getCategoryById ( $value ['cid'] );
  246. $list [$key] ['category'] = $detail;
  247. array_push ( $itid, $value ['itid'] );
  248. }
  249. // 获得开票金额合计 入账金额合计 入账完成度
  250. Doo::loadModel ( 'invoice' );
  251. $invoice = new invoice ();
  252. $invoiceList = $invoiceRecelvablesList = array ();
  253. if (! empty ( $itid )) {
  254. $itidSql = implode ( ',', $itid );
  255. $invoiceList = $invoice->sumOfinvoiceTrain ( $itidSql );
  256. $invoiceRecelvablesList = $invoice->sumOfInvoiceRecelvablesTrain ( $itidSql );
  257. }
  258. // print_r($invoiceRecelvablesList);
  259. foreach ( $list as $key => $value ) {
  260. $countInvoice = $invoice->getInvoiceByTrainingCount ( $value ['itid'] );
  261. $value ['invoiceTotal'] = $countInvoice;
  262. $list [$key] ['invoiceTotal'] = $countInvoice;
  263. foreach ( $invoiceList as $k => $v ) {
  264. if ($value ['itid'] == $v ['trainId']) {
  265. $list [$key] ['invoiceTotalAmount'] = $v ['invoicePrice'];
  266. break;
  267. }
  268. }
  269. foreach ( $invoiceRecelvablesList as $i => $o ) {
  270. if ($value ['itid'] == $o ['trainId']) {
  271. $list [$key] ['invoiceArriveAmount'] = $o ['receivablesPrice'];
  272. $list [$key] ['arriveSchedule'] = "0";
  273. if ($value ['invoiceTotal'] != 0) {
  274. $list [$key] ['arriveSchedule'] = round ( $list [$key] ['invoiceArriveAmount'] / $list [$key] ['invoiceTotalAmount'] * 100, 2 );
  275. // $list [$key] ['arriveSchedule'] = round ( $o ['count'] / $value ['invoiceTotal'] * 100, 2 );
  276. }
  277. break;
  278. }
  279. }
  280. }
  281. return $list;
  282. }
  283. /**
  284. * 根据ID获得培训班
  285. * @param number $itid
  286. */
  287. function getInvoiceTrainingByItid($itid = 0) {
  288. Doo::loadClass ( 'XDeode' );
  289. $XDeode = new XDeode ( 5 );
  290. if (! is_numeric ( $itid ))
  291. $itid = $XDeode->decode ( $itid );
  292. $detail = array ();
  293. if (! empty ( $itid ) && is_numeric ( $itid )) {
  294. $detail = $this->getOne ( array (
  295. 'where' => " itid=" . $itid,
  296. 'asArray' => TRUE
  297. ) );
  298. }
  299. $detail ['trainingKey'] = '';
  300. if (! empty ( $detail )) {
  301. Doo::loadModel ( 'L_category' );
  302. $lCategory = new L_category ();
  303. Doo::loadModel ( 'staff' );
  304. $staff = new staff ();
  305. $cateList = $lCategory->getCategoryById ( $detail ['cid'] );
  306. $itid = $detail ['itid'];
  307. $detail ['trainingKey'] = $XDeode->encode ( $detail ['itid'] );
  308. $staffdetail = $staff->getStaffBySid ( $detail ['creator'] );
  309. $detail ['staff'] = $staffdetail;
  310. $catedetail = $lCategory->getCategoryById ( $detail ['cid'] );
  311. $detail ['category'] = $catedetail;
  312. // 获得开票金额合计 入账金额合计 入账完成度
  313. Doo::loadModel ( 'invoice' );
  314. $invoice = new invoice ();
  315. $invoiceList = $invoiceRecelvablesList = array ();
  316. if (! empty ( $itid )) {
  317. $itidSql = $itid;
  318. $invoiceList = $invoice->sumOfinvoiceTrain ( $itidSql );
  319. $invoiceRecelvablesList = $invoice->sumOfInvoiceRecelvablesTrain ( $itidSql );
  320. //获得办事处已收款
  321. $RIList=$invoice->sumOfInvoiceByItid($itid);
  322. }
  323. //print_r($invoiceRecelvablesList);
  324. $countInvoice = $invoice->getInvoiceByTrainingCount ( $detail ['itid'] );
  325. $detail ['invoiceTotal'] = $countInvoice;
  326. foreach ( $invoiceList as $k => $v ) {
  327. if ($detail ['itid'] == $v ['trainId']) {
  328. $detail ['invoiceTotalAmount'] = $v ['invoicePrice'];
  329. break;
  330. }
  331. }
  332. foreach ( $invoiceRecelvablesList as $i => $o ) {
  333. if ($detail['itid'] == $o ['trainId']) {
  334. $detail ['invoiceArriveAmount'] = $o ['receivablesPrice'];
  335. $detail ['arriveSchedule'] = 0;
  336. if ($detail ['invoiceTotal'] != 0) {
  337. $detail ['arriveSchedule'] = round ( $detail ['invoiceArriveAmount'] / $detail ['invoiceTotalAmount'] * 100, 2 );
  338. }
  339. break;
  340. }
  341. }
  342. //办事处已收款
  343. foreach ($RIList as $key=>$value){
  344. if ($detail ['itid'] == $value ['trainId']) {
  345. $detail ['RIAmount'] = $value ['invoicePrice'];
  346. break;
  347. }
  348. }
  349. }
  350. //print_r($detail);
  351. return $detail;
  352. }
  353. /**
  354. * 根据ID删除数据
  355. * @param number $itid
  356. */
  357. function delInvoiceTrainingByItid($itid = 0) {
  358. Doo::loadClass ( 'XDeode' );
  359. $XDeode = new XDeode ( 5 );
  360. $itid = $XDeode->decode ( $itid );
  361. if (! empty ( $itid ) && is_numeric ( $itid ))
  362. $this->delete ( array (
  363. 'where' => 'itid=' . $itid
  364. ) );
  365. // 删除培训班下的发票
  366. Doo::loadModel ( 'invoiceStore' );
  367. $invoiceStore = new invoiceStore ();
  368. $invoiceStore->delete ( array (
  369. 'where' => 'trainId=' . $itid
  370. ) );
  371. }
  372. /**
  373. * 获得某办事处未完成的培训班
  374. * @return string
  375. */
  376. function getInvoiceTrainingByUnfinished($cid = 0) {
  377. $condition = array (
  378. 'where' => "(status= 0 or status=1) and cid=" . $cid,
  379. 'asArray' => true
  380. );
  381. $list = $this->find ( $condition );
  382. Doo::loadClass ( 'XDeode' );
  383. $XDeode = new XDeode ( 5 );
  384. foreach ( $list as $key => $value ) {
  385. $list [$key] ['itidKey'] = $XDeode->encode ( $value ['itid'] );
  386. }
  387. return $list;
  388. }
  389. /**
  390. * 获得所有培训班
  391. */
  392. function getInvoiceTrainingBySubmitStatus() {
  393. $condition = array (
  394. 'where' => "submitStatus=1",
  395. 'asArray' => TRUE
  396. );
  397. $list = $this->find ( $condition );
  398. Doo::loadClass ( 'XDeode' );
  399. $XDeode = new XDeode ( 5 );
  400. foreach ( $list as $key => $value ) {
  401. $list [$key] ['itidKey'] = $XDeode->encode ( $value ['itid'] );
  402. }
  403. return $list;
  404. }
  405. }
  406. ?>