receiptTraining.php 8.1 KB

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