invoiceTraining.php 6.4 KB

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