invoiceTraining.php 6.3 KB

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