invoiceTraining.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  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 $bindReceipt;
  13. public $status;
  14. public $submitStatus;
  15. public $trainName;
  16. public $cid;
  17. public $categoryName;
  18. public $creator;
  19. public $trainDate;
  20. public $invoiceTotal;
  21. public $invoiceTotalAmount;
  22. public $invoiceArriveAmount;
  23. public $arriveSchedule;
  24. public $creatorDate;
  25. public $settlementStatus;
  26. public $_table = 'CLD_invoiceTraining';
  27. public $_primarykey = 'itid';
  28. public $_fields = array (
  29. 'itid',
  30. 'bindReceipt',
  31. 'status',
  32. 'submitStatus',
  33. 'trainName',
  34. 'cid',
  35. 'categoryName',
  36. 'creator',
  37. 'trainDate',
  38. 'invoiceTotal',
  39. 'invoiceTotalAmount',
  40. 'invoiceArriveAmount',
  41. 'arriveSchedule',
  42. 'settlementStatus',
  43. 'creatorDate'
  44. );
  45. /**
  46. * 添加一个培训班
  47. * @param array $item 培训班相关数据
  48. * @return number 返回培训班ID
  49. */
  50. public function addInvoiceTraining($item = array()) {
  51. $itid = 0;
  52. if (is_array ( $item ) && ! empty ( $item )) {
  53. foreach ( $item as $key => $value ) {
  54. $this->$key = $value;
  55. }
  56. $itid = $this->insert ();
  57. }
  58. return $itid;
  59. }
  60. function getInvoiceTrainStatistics($itid = 0) {
  61. $itidCondition = ' and trainId=NULL ';
  62. if (! empty ( $itid ))
  63. $itidCondition = ' and trainId in (' . $itid . ') ';
  64. $sql = 'select sum(invoicePrice) as invoicePrice ,trainId
  65. from CLD_invoice
  66. where status=2 and printStatus=1 and (untreadStatus =0 or untreadStatus=3) ' . $itidCondition . '
  67. GROUP BY status';
  68. $query = Doo::db ()->query ( $sql );
  69. $result = $query->fetchAll ();
  70. if (! empty ( $result ))
  71. $detail = array (
  72. 'invoicePrice' => $result [0] ['invoicePrice']
  73. );
  74. else
  75. $detail = array (
  76. 'invoicePrice' => 0
  77. );
  78. // print_r($result);
  79. $itidCondition = ' and a.trainId=NULL ';
  80. if (! empty ( $itid ))
  81. $itidCondition = ' and a.trainId in (' . $itid . ') ';
  82. $sql = 'select sum(b.receivablesPrice) as receivablesPrice ,a.trainId,count(*) as count
  83. from CLD_invoice as a left join CLD_invoiceReceivables as b on find_in_set(b.irid,a.irid)
  84. where a.status=2 and a.printStatus=1 and (a.untreadStatus =0 or a.untreadStatus=3) and a.irid!="" ' . $itidCondition . '
  85. GROUP BY a.status';
  86. $query = Doo::db ()->query ( $sql );
  87. $result = $query->fetchAll ();
  88. if (! empty ( $result )) {
  89. $detail += array (
  90. 'receivablesPrice' => $result [0] ['receivablesPrice']
  91. );
  92. $detail += array (
  93. 'rPrice' => $detail ['invoicePrice'] - $result [0] ['receivablesPrice']
  94. );
  95. } else {
  96. $detail += array (
  97. 'receivablesPrice' => 0
  98. );
  99. $detail += array (
  100. 'rPrice' => $detail ['invoicePrice']
  101. );
  102. }
  103. return $detail;
  104. }
  105. /**
  106. * 根据办事处获得结算完成培训班
  107. * @param number $SStatus
  108. * @return string
  109. */
  110. function getInvoiceTrainBySettlementStatus($SStatus = 0, $cid = 0,$bindReceipt) {
  111. $condition = array (
  112. 'where' => " settlementStatus=" . $SStatus . ' and cid=' . $cid. ' and bindReceipt=' . $bindReceipt,
  113. 'asArray' => TRUE
  114. );
  115. $list = $this->find ( $condition );
  116. Doo::loadClass ( 'XDeode' );
  117. $XDeode = new XDeode ( 5 );
  118. foreach ( $list as $key => $value ) {
  119. $list [$key] ['itidKey'] = $XDeode->encode ( $value ['itid'] );
  120. }
  121. return $list;
  122. }
  123. /**
  124. * 获得办事处下的培训班
  125. */
  126. function getInvoiceTrainingByCid($cid = 0) {
  127. $condition = array (
  128. 'where' => " cid=" . $cid,
  129. 'asArray' => TRUE
  130. );
  131. $list = $this->find ( $condition );
  132. Doo::loadClass ( 'XDeode' );
  133. $XDeode = new XDeode ( 5 );
  134. foreach ( $list as $key => $value ) {
  135. $list [$key] ['itidKey'] = $XDeode->encode ( $value ['itid'] );
  136. }
  137. return $list;
  138. }
  139. function getInvoiceTrainingByTodo($select = "", $cid = 0, $sid = 0) {
  140. Doo::loadModel ( 'staff' );
  141. $staff = new staff ();
  142. Doo::loadModel ( 'L_category' );
  143. $lCategory = new L_category ();
  144. $condition = array (
  145. 'where' => "(status= 0 or status=1) and ( cid in (" . $cid . ") or creator=" . $sid . " )",
  146. // 'limit' => 8,
  147. 'asArray' => TRUE
  148. );
  149. if (! empty ( $select ))
  150. $condition += array (
  151. 'select' => $select
  152. );
  153. $list = $this->find ( $condition );
  154. Doo::loadClass ( 'XDeode' );
  155. $XDeode = new XDeode ( 5 );
  156. $itid = array ();
  157. foreach ( $list as $key => $value ) {
  158. $list [$key] ['trainingKey'] = $XDeode->encode ( $value ['itid'] );
  159. $detail = $staff->getStaffBySid ( $value ['creator'] );
  160. $list [$key] ['staff'] = $detail;
  161. $detail = $lCategory->getCategoryById ( $value ['cid'] );
  162. $list [$key] ['category'] = $detail;
  163. array_push ( $itid, $value ['itid'] );
  164. }
  165. // 获得开票金额合计 入账金额合计 入账完成度
  166. Doo::loadModel ( 'invoice' );
  167. $invoice = new invoice ();
  168. $invoiceList = $invoiceRecelvablesList = array ();
  169. if (! empty ( $itid )) {
  170. $itidSql = implode ( ',', $itid );
  171. $invoiceList = $invoice->sumOfinvoiceTrain ( $itidSql );
  172. $invoiceRecelvablesList = $invoice->sumOfInvoiceRecelvablesTrain ( $itidSql );
  173. }
  174. // print_r($invoiceRecelvablesList);
  175. foreach ( $list as $key => $value ) {
  176. $countInvoice = $invoice->getInvoiceByTrainingCount ( $value ['itid'] );
  177. $value ['invoiceTotal'] = $countInvoice;
  178. $list [$key] ['invoiceTotal'] = $countInvoice;
  179. foreach ( $invoiceList as $k => $v ) {
  180. if ($value ['itid'] == $v ['trainId']) {
  181. $list [$key] ['invoiceTotalAmount'] = $v ['invoicePrice'];
  182. break;
  183. }
  184. }
  185. foreach ( $invoiceRecelvablesList as $i => $o ) {
  186. if ($value ['itid'] == $o ['trainId']) {
  187. $list [$key] ['invoiceArriveAmount'] = $o ['receivablesPrice'];
  188. $list [$key] ['arriveSchedule'] = "0";
  189. if ($value ['invoiceTotal'] != 0) {
  190. $list [$key] ['arriveSchedule'] = round ( $list [$key] ['invoiceArriveAmount'] / $list [$key] ['invoiceTotalAmount'] * 100, 2 );
  191. // $list [$key] ['arriveSchedule'] = round ( $o ['count'] / $value ['invoiceTotal'] * 100, 2 );
  192. }
  193. break;
  194. }
  195. }
  196. }
  197. return $list;
  198. }
  199. /**
  200. * 根据参数字段更新相应字段(主键ID必须传)
  201. * @param array $item 相关需要更新的字段信息
  202. * @return number 返回发票ID
  203. */
  204. public function setInvoiceTrainByCondition($item = array(), $itid = "") {
  205. $lid = 0;
  206. if (is_array ( $item ) && ! empty ( $item )) {
  207. foreach ( $item as $key => $value ) {
  208. $this->$key = $value;
  209. }
  210. if (! empty ( $itid )) {
  211. $condition = array (
  212. 'where' => "itid in (" . $itid . ")",
  213. 'asArray' => TRUE
  214. );
  215. $this->update ( $condition );
  216. } else
  217. $lid = $this->update ();
  218. }
  219. return $lid;
  220. }
  221. /**
  222. * 根据状态获取培训班
  223. * @param number $status
  224. */
  225. function getInvoiceTrainingByStatus($status = 0, $select = "", $cid = 0, $sid = 0) {
  226. Doo::loadModel ( 'staff' );
  227. $staff = new staff ();
  228. Doo::loadModel ( 'L_category' );
  229. $lCategory = new L_category ();
  230. $condition = array (
  231. 'where' => "status= '" . $status . "' and (cid in(" . $cid . ") or creator=" . $sid . " )",
  232. // 'limit' => 8,
  233. 'asArray' => TRUE
  234. );
  235. if (! empty ( $select ))
  236. $condition += array (
  237. 'select' => $select
  238. );
  239. $list = $this->find ( $condition );
  240. Doo::loadClass ( 'XDeode' );
  241. $XDeode = new XDeode ( 5 );
  242. $itid = array ();
  243. foreach ( $list as $key => $value ) {
  244. $list [$key] ['trainingKey'] = $XDeode->encode ( $value ['itid'] );
  245. $detail = $staff->getStaffBySid ( $value ['creator'] );
  246. $list [$key] ['staff'] = $detail;
  247. $detail = $lCategory->getCategoryById ( $value ['cid'] );
  248. $list [$key] ['category'] = $detail;
  249. array_push ( $itid, $value ['itid'] );
  250. }
  251. // 获得开票金额合计 入账金额合计 入账完成度
  252. Doo::loadModel ( 'invoice' );
  253. $invoice = new invoice ();
  254. $invoiceList = $invoiceRecelvablesList = array ();
  255. if (! empty ( $itid )) {
  256. $itidSql = implode ( ',', $itid );
  257. $invoiceList = $invoice->sumOfinvoiceTrain ( $itidSql );
  258. $invoiceRecelvablesList = $invoice->sumOfInvoiceRecelvablesTrain ( $itidSql );
  259. }
  260. // print_r($invoiceRecelvablesList);
  261. foreach ( $list as $key => $value ) {
  262. $countInvoice = $invoice->getInvoiceByTrainingCount ( $value ['itid'] );
  263. $value ['invoiceTotal'] = $countInvoice;
  264. $list [$key] ['invoiceTotal'] = $countInvoice;
  265. foreach ( $invoiceList as $k => $v ) {
  266. if ($value ['itid'] == $v ['trainId']) {
  267. $list [$key] ['invoiceTotalAmount'] = $v ['invoicePrice'];
  268. break;
  269. }
  270. }
  271. foreach ( $invoiceRecelvablesList as $i => $o ) {
  272. if ($value ['itid'] == $o ['trainId']) {
  273. $list [$key] ['invoiceArriveAmount'] = $o ['receivablesPrice'];
  274. $list [$key] ['arriveSchedule'] = "0";
  275. if ($value ['invoiceTotal'] != 0) {
  276. $list [$key] ['arriveSchedule'] = round ( $list [$key] ['invoiceArriveAmount'] / $list [$key] ['invoiceTotalAmount'] * 100, 2 );
  277. // $list [$key] ['arriveSchedule'] = round ( $o ['count'] / $value ['invoiceTotal'] * 100, 2 );
  278. }
  279. break;
  280. }
  281. }
  282. }
  283. return $list;
  284. }
  285. /**
  286. * 根据ID获得培训班
  287. * @param number $itid
  288. */
  289. function getInvoiceTrainingByItid($itid = 0) {
  290. Doo::loadClass ( 'XDeode' );
  291. $XDeode = new XDeode ( 5 );
  292. if (! is_numeric ( $itid ))
  293. $itid = $XDeode->decode ( $itid );
  294. $detail = array ();
  295. if (! empty ( $itid ) && is_numeric ( $itid )) {
  296. $detail = $this->getOne ( array (
  297. 'where' => " itid=" . $itid,
  298. 'asArray' => TRUE
  299. ) );
  300. }
  301. $detail ['trainingKey'] = '';
  302. $detail ['RIAmount']=$detail ['invoiceArriveAmount']=$detail ['invoiceTotalAmount']=0;
  303. if (! empty ( $detail )) {
  304. Doo::loadModel ( 'L_category' );
  305. $lCategory = new L_category ();
  306. Doo::loadModel ( 'staff' );
  307. $staff = new staff ();
  308. $cateList = $lCategory->getCategoryById ( $detail ['cid'] );
  309. $itid = $detail ['itid'];
  310. $detail ['trainingKey'] = $XDeode->encode ( $detail ['itid'] );
  311. $staffdetail = $staff->getStaffBySid ( $detail ['creator'] );
  312. $detail ['staff'] = $staffdetail;
  313. $catedetail = $lCategory->getCategoryById ( $detail ['cid'] );
  314. $detail ['category'] = $catedetail;
  315. // 获得开票金额合计 入账金额合计 入账完成度
  316. Doo::loadModel ( 'invoice' );
  317. $invoice = new invoice ();
  318. $invoiceList=$companyList=$RIList = $invoiceRecelvablesList = array ();
  319. if (! empty ( $itid )) {
  320. $itidSql = $itid;
  321. //培训班收款
  322. $invoiceList = $invoice->sumOfinvoiceTrain ( $itidSql );
  323. $invoiceRecelvablesList = $invoice->sumOfInvoiceRecelvablesTrain ( $itidSql );
  324. //公司收款
  325. $companyList = $invoice->sumOfInvoiceRecelvablesCompany ( $itidSql );
  326. //获得办事处已收款
  327. $RIList=$invoice->sumOfInvoiceByItid($itid);
  328. }
  329. //print_r($invoiceRecelvablesList);
  330. $countInvoice = $invoice->getInvoiceByTrainingCount ( $detail ['itid'] );
  331. $detail ['invoiceTotal'] = $countInvoice;
  332. foreach ( $invoiceList as $k => $v ) {
  333. if ($detail ['itid'] == $v ['trainId']) {
  334. $detail ['invoiceTotalAmount'] = $v ['invoicePrice'];
  335. break;
  336. }
  337. }
  338. foreach ( $invoiceRecelvablesList as $i => $o ) {
  339. if ($detail['itid'] == $o ['trainId']) {
  340. $detail ['invoiceArriveAmount'] = $o ['receivablesPrice'];
  341. $detail ['arriveSchedule'] = 0;
  342. if ($detail ['invoiceTotal'] != 0) {
  343. $detail ['arriveSchedule'] = round ( $detail ['invoiceArriveAmount'] / $detail ['invoiceTotalAmount'] * 100, 2 );
  344. }
  345. break;
  346. }
  347. }
  348. //办事处已收款
  349. foreach ($RIList as $key=>$value){
  350. if ($detail ['itid'] == $value ['trainId']) {
  351. $detail ['RIAmount'] = $value ['invoicePrice'];
  352. break;
  353. }
  354. }
  355. //公司已收款
  356. $detail ['invoiceCompanyAmount']=0;
  357. foreach ($companyList as $key=>$value){
  358. if ($detail ['itid'] == $value ['trainId']) {
  359. $detail ['invoiceCompanyAmount'] = $value ['receivablesPrice'];
  360. break;
  361. }
  362. }
  363. }
  364. //echo var_dump($detail ['invoiceTotalAmount'] ) ;
  365. //print_r($detail);
  366. return $detail;
  367. }
  368. /**
  369. * 根据ID删除数据
  370. * @param number $itid
  371. */
  372. function delInvoiceTrainingByItid($itid = 0) {
  373. Doo::loadClass ( 'XDeode' );
  374. $XDeode = new XDeode ( 5 );
  375. $itid = $XDeode->decode ( $itid );
  376. if (! empty ( $itid ) && is_numeric ( $itid ))
  377. $this->delete ( array (
  378. 'where' => 'itid=' . $itid
  379. ) );
  380. // 删除培训班下的发票
  381. Doo::loadModel ( 'invoiceStore' );
  382. $invoiceStore = new invoiceStore ();
  383. $invoiceStore->delete ( array (
  384. 'where' => 'trainId=' . $itid
  385. ) );
  386. }
  387. /**
  388. * 获得某办事处未完成的培训班
  389. * @return string
  390. */
  391. function getInvoiceTrainingByUnfinished($cid = 0) {
  392. $condition = array (
  393. 'where' => "(status= 0 or status=1) and cid=" . $cid,
  394. 'asArray' => true
  395. );
  396. $list = $this->find ( $condition );
  397. Doo::loadClass ( 'XDeode' );
  398. $XDeode = new XDeode ( 5 );
  399. foreach ( $list as $key => $value ) {
  400. $list [$key] ['itidKey'] = $XDeode->encode ( $value ['itid'] );
  401. }
  402. return $list;
  403. }
  404. /**
  405. * 获得所有培训班
  406. */
  407. function getInvoiceTrainingBySubmitStatus() {
  408. $condition = array (
  409. 'where' => "submitStatus=1",
  410. 'asArray' => TRUE
  411. );
  412. $list = $this->find ( $condition );
  413. Doo::loadClass ( 'XDeode' );
  414. $XDeode = new XDeode ( 5 );
  415. foreach ( $list as $key => $value ) {
  416. $list [$key] ['itidKey'] = $XDeode->encode ( $value ['itid'] );
  417. }
  418. return $list;
  419. }
  420. }
  421. ?>