invoiceTraining.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  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(b.irid,a.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. $countInvoice=$invoice->getInvoiceByTrainingCount($value['itid']);
  139. $value ['invoiceTotal']=$countInvoice;
  140. $list [$key] ['invoiceTotal'] =$countInvoice;
  141. foreach ( $invoiceList as $k => $v ) {
  142. if ($value ['itid'] == $v ['trainId']) {
  143. $list [$key] ['invoiceTotalAmount'] = $v ['invoicePrice'];
  144. break;
  145. }
  146. }
  147. foreach ( $invoiceRecelvablesList as $i => $o ) {
  148. if ($value ['itid'] == $o ['trainId']) {
  149. $list [$key] ['invoiceArriveAmount'] = $o ['receivablesPrice'];
  150. $list [$key] ['arriveSchedule'] = "0";
  151. if ($value ['invoiceTotal'] != 0)
  152. $list [$key] ['arriveSchedule'] = round ( $o ['count'] / $value ['invoiceTotal'] * 100, 2 );
  153. break;
  154. }
  155. }
  156. }
  157. return $list;
  158. }
  159. /**
  160. * 根据参数字段更新相应字段(主键ID必须传)
  161. * @param array $item 相关需要更新的字段信息
  162. * @return number 返回发票ID
  163. */
  164. public function setInvoiceTrainByCondition($item = array(), $itid = "") {
  165. $lid = 0;
  166. if (is_array ( $item ) && ! empty ( $item )) {
  167. foreach ( $item as $key => $value ) {
  168. $this->$key = $value;
  169. }
  170. if (! empty ( $isid )) {
  171. $condition = array (
  172. 'where' => "itid in (" . $itid . ")",
  173. 'asArray' => TRUE
  174. );
  175. $this->update ( $condition );
  176. } else
  177. $lid = $this->update ();
  178. }
  179. return $lid;
  180. }
  181. /**
  182. * 根据状态获取培训班
  183. * @param number $status
  184. */
  185. function getInvoiceTrainingByStatus($status = 0, $select = "", $cid = 0, $sid = 0) {
  186. Doo::loadModel ( 'staff' );
  187. $staff = new staff ();
  188. Doo::loadModel ( 'L_category' );
  189. $lCategory = new L_category ();
  190. $condition = array (
  191. 'where' => "status= '" . $status . "' and (cid=" . $cid . " or creator=" . $sid . " )",
  192. 'limit' => 8,
  193. 'asArray' => TRUE
  194. );
  195. if (! empty ( $select ))
  196. $condition += array (
  197. 'select' => $select
  198. );
  199. $list = $this->find ( $condition );
  200. foreach ( $list as $key => $value ) {
  201. $detail = $staff->getStaffBySid ( $value ['creator'] );
  202. $list [$key] ['staff'] = $detail;
  203. $detail = $lCategory->getCategoryById ( $value ['cid'] );
  204. $list [$key] ['category'] = $detail;
  205. }
  206. return $list;
  207. }
  208. /**
  209. * 根据ID获得培训班
  210. * @param number $itid
  211. */
  212. function getInvoiceTrainingByItid($itid = 0) {
  213. Doo::loadClass ( 'XDeode' );
  214. $XDeode = new XDeode ( 5 );
  215. $itid = $XDeode->decode ( $itid );
  216. $detail = array ();
  217. if (! empty ( $itid ) && is_numeric ( $itid )) {
  218. $detail = $this->getOne ( array (
  219. 'where' => " itid=" . $itid,
  220. 'asArray' => TRUE
  221. ) );
  222. }
  223. $detail ['trainingKey'] = '';
  224. if (! empty ( $detail ))
  225. $detail ['trainingKey'] = $XDeode->encode ( $detail ['itid'] );
  226. return $detail;
  227. }
  228. /**
  229. * 根据ID删除数据
  230. * @param number $itid
  231. */
  232. function delInvoiceTrainingByItid($itid = 0) {
  233. Doo::loadClass ( 'XDeode' );
  234. $XDeode = new XDeode ( 5 );
  235. $itid = $XDeode->decode ( $itid );
  236. if (! empty ( $itid ) && is_numeric ( $itid ))
  237. $this->delete ( array (
  238. 'where' => 'itid=' . $itid
  239. ) );
  240. // 删除培训班下的发票
  241. Doo::loadModel ( 'invoiceStore' );
  242. $invoiceStore = new invoiceStore ();
  243. $invoiceStore->delete ( array (
  244. 'where' => 'trainId=' . $itid
  245. ) );
  246. }
  247. /**
  248. * 获得所有培训班
  249. */
  250. function getInvoiceTrainingBySubmitStatus() {
  251. $condition = array (
  252. 'where' => "submitStatus=1",
  253. 'asArray' => TRUE
  254. );
  255. $list = $this->find ( $condition );
  256. Doo::loadClass ( 'XDeode' );
  257. $XDeode = new XDeode ( 5 );
  258. foreach ( $list as $key => $value ) {
  259. $list[$key] ['itidKey'] = $XDeode->encode ( $value ['itid'] );
  260. }
  261. return $list;
  262. }
  263. }
  264. ?>