invoiceTraining.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 $_table = 'CLD_invoiceTraining';
  25. public $_primarykey = 'itid';
  26. public $_fields = array (
  27. 'itid',
  28. 'status',
  29. 'submitStatus',
  30. 'trainName',
  31. 'cid',
  32. 'categoryName',
  33. 'creator',
  34. 'trainDate',
  35. 'invoiceTotal',
  36. 'invoiceTotalAmount',
  37. 'invoiceArriveAmount',
  38. 'arriveSchedule',
  39. 'creatorDate'
  40. );
  41. /**
  42. * 添加一个培训班
  43. * @param array $item 培训班相关数据
  44. * @return number 返回培训班ID
  45. */
  46. public function addInvoiceTraining($item = array()) {
  47. $itid = 0;
  48. if (is_array ( $item ) && ! empty ( $item )) {
  49. foreach ( $item as $key => $value ) {
  50. $this->$key = $value;
  51. }
  52. $itid = $this->insert ();
  53. }
  54. return $itid;
  55. }
  56. function getInvoiceTrainStatistics($itid=0) {
  57. $itidCondition=' and trainId=NULL ';
  58. if (!empty($itid))
  59. $itidCondition=' and trainId in ('.$itid.') ';
  60. $sql = 'select sum(invoicePrice) as invoicePrice ,trainId
  61. from CLD_invoice
  62. where status=2 and printStatus=1 and (untreadStatus =0 or untreadStatus=3) '.$itidCondition.'
  63. GROUP BY status';
  64. $query = Doo::db ()->query ( $sql );
  65. $result = $query->fetchAll ();
  66. if (! empty ( $result ))
  67. $detail = array (
  68. 'invoicePrice' => $result [0] ['invoicePrice']
  69. );
  70. else
  71. $detail = array (
  72. 'invoicePrice' => 0
  73. );
  74. // print_r($result);
  75. $itidCondition=' and a.trainId=NULL ';
  76. if (!empty($itid))
  77. $itidCondition=' and a.trainId in ('.$itid.') ';
  78. $sql = 'select sum(b.receivablesPrice) as receivablesPrice ,a.trainId,count(*) as count
  79. from CLD_invoice as a left join CLD_invoiceReceivables as b on find_in_set(a.irid,b.irid)
  80. where a.status=2 and a.printStatus=1 and (a.untreadStatus =0 or a.untreadStatus=3) and a.irid!="" '.$itidCondition.'
  81. GROUP BY a.status';
  82. $query = Doo::db ()->query ( $sql );
  83. $result = $query->fetchAll ();
  84. if (! empty ( $result )) {
  85. $detail += array (
  86. 'receivablesPrice' => $result [0] ['receivablesPrice']
  87. );
  88. $detail += array (
  89. 'rPrice' => $detail ['invoicePrice'] - $result [0] ['receivablesPrice']
  90. );
  91. } else {
  92. $detail += array (
  93. 'receivablesPrice' => 0
  94. );
  95. $detail += array (
  96. 'rPrice' => $detail ['invoicePrice']
  97. );
  98. }
  99. return $detail;
  100. }
  101. function getInvoiceTrainingByTodo($select = "", $cid = 0,$sid=0) {
  102. Doo::loadModel ( 'staff' );
  103. $staff = new staff ();
  104. Doo::loadModel ( 'L_category' );
  105. $lCategory = new L_category ();
  106. $condition = array (
  107. 'where' => "(status= 0 or status=1) and ( cid=" . $cid." or creator=".$sid." )",
  108. 'limit' => 8,
  109. 'asArray' => TRUE
  110. );
  111. if (! empty ( $select ))
  112. $condition += array (
  113. 'select' => $select
  114. );
  115. $list = $this->find ( $condition );
  116. Doo::loadClass ( 'XDeode' );
  117. $XDeode = new XDeode ( 5 );
  118. $itid = array ();
  119. foreach ( $list as $key => $value ) {
  120. $list [$key] ['trainingKey'] = $XDeode->encode ( $value ['itid'] );
  121. $detail = $staff->getStaffBySid ( $value ['creator'] );
  122. $list [$key] ['staff'] = $detail;
  123. $detail = $lCategory->getCategoryById ( $value ['cid'] );
  124. $list [$key] ['category'] = $detail;
  125. array_push ( $itid, $value ['itid'] );
  126. }
  127. // 获得开票金额合计 入账金额合计 入账完成度
  128. Doo::loadModel ( 'invoice' );
  129. $invoice = new invoice ();
  130. $invoiceList=$invoiceRecelvablesList=array();
  131. if (! empty ( $itid )) {
  132. $itidSql = implode ( ',', $itid );
  133. $invoiceList = $invoice->sumOfinvoiceTrain ( $itidSql );
  134. $invoiceRecelvablesList = $invoice->sumOfInvoiceRecelvablesTrain ( $itidSql );
  135. }
  136. // print_r($invoiceRecelvablesList);
  137. foreach ( $list as $key => $value ) {
  138. foreach ( $invoiceList as $k => $v ) {
  139. if ($value ['itid'] == $v ['trainId']) {
  140. $list [$key] ['invoiceTotalAmount'] = $v ['invoicePrice'];
  141. break;
  142. }
  143. }
  144. foreach ( $invoiceRecelvablesList as $i => $o ) {
  145. if ($value ['itid'] == $o ['trainId']) {
  146. $list [$key] ['invoiceArriveAmount'] = $o ['receivablesPrice'];
  147. $list [$key] ['arriveSchedule'] = "0";
  148. if ($value ['invoiceTotal'] != 0)
  149. $list [$key] ['arriveSchedule'] = round ( $o ['count'] / $value ['invoiceTotal'] * 100, 2 );
  150. break;
  151. }
  152. }
  153. }
  154. return $list;
  155. }
  156. /**
  157. * 根据参数字段更新相应字段(主键ID必须传)
  158. * @param array $item 相关需要更新的字段信息
  159. * @return number 返回发票ID
  160. */
  161. public function setInvoiceTrainByCondition($item = array(), $itid = "") {
  162. $lid = 0;
  163. if (is_array ( $item ) && ! empty ( $item )) {
  164. foreach ( $item as $key => $value ) {
  165. $this->$key = $value;
  166. }
  167. if (! empty ( $isid )) {
  168. $condition = array (
  169. 'where' => "itid in (" . $itid . ")",
  170. 'asArray' => TRUE
  171. );
  172. $this->update ( $condition );
  173. } else
  174. $lid = $this->update ();
  175. }
  176. return $lid;
  177. }
  178. /**
  179. * 根据状态获取培训班
  180. * @param number $status
  181. */
  182. function getInvoiceTrainingByStatus($status = 0, $select = "", $cid = 0,$sid=0) {
  183. Doo::loadModel ( 'staff' );
  184. $staff = new staff ();
  185. Doo::loadModel ( 'L_category' );
  186. $lCategory = new L_category ();
  187. $condition = array (
  188. 'where' => "status= '" . $status . "' and (cid=" . $cid." or creator=".$sid." )",
  189. 'limit' => 8,
  190. 'asArray' => TRUE
  191. );
  192. if (! empty ( $select ))
  193. $condition += array (
  194. 'select' => $select
  195. );
  196. $list = $this->find ( $condition );
  197. foreach ( $list as $key => $value ) {
  198. $detail = $staff->getStaffBySid ( $value ['creator'] );
  199. $list [$key] ['staff'] = $detail;
  200. $detail = $lCategory->getCategoryById ( $value ['cid'] );
  201. $list [$key] ['category'] = $detail;
  202. }
  203. return $list;
  204. }
  205. /**
  206. * 根据ID获得培训班
  207. * @param number $itid
  208. */
  209. function getInvoiceTrainingByItid($itid = 0) {
  210. Doo::loadClass ( 'XDeode' );
  211. $XDeode = new XDeode ( 5 );
  212. $itid = $XDeode->decode ( $itid );
  213. $detail = array ();
  214. if (! empty ( $itid ) && is_numeric ( $itid )) {
  215. $detail = $this->getOne ( array (
  216. 'where' => " itid=" . $itid,
  217. 'asArray' => TRUE
  218. ) );
  219. }
  220. $detail ['trainingKey'] = '';
  221. if (! empty ( $detail ))
  222. $detail ['trainingKey'] = $XDeode->encode ( $detail ['itid'] );
  223. return $detail;
  224. }
  225. /**
  226. * 根据ID删除数据
  227. * @param number $itid
  228. */
  229. function delInvoiceTrainingByItid($itid = 0) {
  230. Doo::loadClass ( 'XDeode' );
  231. $XDeode = new XDeode ( 5 );
  232. $itid = $XDeode->decode ( $itid );
  233. if (! empty ( $itid ) && is_numeric ( $itid ))
  234. $this->delete ( array (
  235. 'where' => 'itid=' . $itid
  236. ) );
  237. }
  238. }
  239. ?>