receiptTraining.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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 $freeParticipants;
  19. public $trainAddress;
  20. public $trainRemarks;
  21. public $creator;
  22. public $creatorDate;
  23. public $identifyingTotal;
  24. public $_table = 'CLD_receiptTraining';
  25. public $_primarykey = 'rtid';
  26. public $_fields = array (
  27. 'rtid',
  28. 'trainName',
  29. 'cid',
  30. 'categoryName',
  31. 'trainStartDate',
  32. 'trainEndDate',
  33. 'participants',
  34. 'freeParticipants',
  35. 'trainAddress',
  36. 'trainRemarks',
  37. 'creator',
  38. 'creatorDate' ,
  39. 'identifyingTotal'
  40. );
  41. /**
  42. * 添加一个培训班
  43. * @param array $item 培训班相关数据
  44. * @return number 返回培训班ID
  45. */
  46. public function addReceiptTraining($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 setReceiptTrainByCondition($item = array(), $rtid = "") {
  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' => "rtid in (" . $rtid . ")",
  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 getReceiptTrainingByRtid($rtid = 0) {
  213. Doo::loadClass ( 'XDeode' );
  214. $XDeode = new XDeode ( 5 );
  215. if (!is_numeric($rtid))
  216. $rtid = $XDeode->decode ( $rtid );
  217. $detail = array ();
  218. if (! empty ( $rtid ) && is_numeric ( $rtid )) {
  219. $detail = $this->getOne ( array (
  220. 'where' => " rtid=" . $rtid,
  221. 'asArray' => TRUE
  222. ) );
  223. }
  224. $detail ['rtidKey'] = '';
  225. if (! empty ( $detail )){
  226. $detail ['rtidKey'] = $XDeode->encode ( $detail ['rtid'] );
  227. $detail ['participantsTotal'] = $detail['participants']+$detail['freeParticipants'];
  228. }
  229. return $detail;
  230. }
  231. /**
  232. * 根据ID删除数据
  233. * @param number $itid
  234. */
  235. function delInvoiceTrainingByItid($itid = 0) {
  236. Doo::loadClass ( 'XDeode' );
  237. $XDeode = new XDeode ( 5 );
  238. $itid = $XDeode->decode ( $itid );
  239. if (! empty ( $itid ) && is_numeric ( $itid ))
  240. $this->delete ( array (
  241. 'where' => 'itid=' . $itid
  242. ) );
  243. // 删除培训班下的发票
  244. Doo::loadModel ( 'invoiceStore' );
  245. $invoiceStore = new invoiceStore ();
  246. $invoiceStore->delete ( array (
  247. 'where' => 'trainId=' . $itid
  248. ) );
  249. }
  250. /**
  251. * 获得某办事处未完成的培训班
  252. * @return string
  253. */
  254. function getInvoiceTrainingByUnfinished($cid=0){
  255. $condition = array (
  256. 'where' => "(status= 0 or status=1) and cid=".$cid,
  257. 'asArray' => true
  258. );
  259. $list = $this->find ( $condition );
  260. Doo::loadClass ( 'XDeode' );
  261. $XDeode = new XDeode ( 5 );
  262. foreach ( $list as $key => $value ) {
  263. $list[$key] ['itidKey'] = $XDeode->encode ( $value ['itid'] );
  264. }
  265. return $list;
  266. }
  267. /**
  268. * 获得所有培训班
  269. */
  270. function getInvoiceTrainingBySubmitStatus() {
  271. $condition = array (
  272. 'where' => "submitStatus=1",
  273. 'asArray' => TRUE
  274. );
  275. $list = $this->find ( $condition );
  276. Doo::loadClass ( 'XDeode' );
  277. $XDeode = new XDeode ( 5 );
  278. foreach ( $list as $key => $value ) {
  279. $list[$key] ['itidKey'] = $XDeode->encode ( $value ['itid'] );
  280. }
  281. return $list;
  282. }
  283. }
  284. ?>