invoiceTraining.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  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. 'desc'=>'itid',
  130. 'asArray' => TRUE
  131. );
  132. $list = $this->find ( $condition );
  133. Doo::loadClass ( 'XDeode' );
  134. $XDeode = new XDeode ( 5 );
  135. foreach ( $list as $key => $value ) {
  136. $list [$key] ['itidKey'] = $XDeode->encode ( $value ['itid'] );
  137. }
  138. return $list;
  139. }
  140. function getInvoiceTrainingByTodo($select = "", $cid = 0, $sid = 0) {
  141. Doo::loadModel ( 'staff' );
  142. $staff = new staff ();
  143. Doo::loadModel ( 'L_category' );
  144. $lCategory = new L_category ();
  145. $condition = array (
  146. 'where' => "(status= 0 or status=1) and ( cid in (" . $cid . ") or creator=" . $sid . " )",
  147. // 'limit' => 8,
  148. 'asArray' => TRUE
  149. );
  150. if (! empty ( $select ))
  151. $condition += array (
  152. 'select' => $select
  153. );
  154. $list = $this->find ( $condition );
  155. Doo::loadClass ( 'XDeode' );
  156. $XDeode = new XDeode ( 5 );
  157. $itid = array ();
  158. foreach ( $list as $key => $value ) {
  159. $list [$key] ['trainingKey'] = $XDeode->encode ( $value ['itid'] );
  160. $detail = $staff->getStaffBySid ( $value ['creator'] );
  161. $list [$key] ['staff'] = $detail;
  162. $detail = $lCategory->getCategoryById ( $value ['cid'] );
  163. $list [$key] ['category'] = $detail;
  164. array_push ( $itid, $value ['itid'] );
  165. }
  166. // 获得开票金额合计 入账金额合计 入账完成度
  167. Doo::loadModel ( 'invoice' );
  168. $invoice = new invoice ();
  169. $invoiceList = $invoiceRecelvablesList = array ();
  170. if (! empty ( $itid )) {
  171. $itidSql = implode ( ',', $itid );
  172. $invoiceList = $invoice->sumOfinvoiceTrain ( $itidSql );
  173. $invoiceRecelvablesList = $invoice->sumOfInvoiceRecelvablesTrain ( $itidSql );
  174. }
  175. // print_r($invoiceRecelvablesList);
  176. foreach ( $list as $key => $value ) {
  177. $countInvoice = $invoice->getInvoiceByTrainingCount ( $value ['itid'] );
  178. $value ['invoiceTotal'] = $countInvoice;
  179. $list [$key] ['invoiceTotal'] = $countInvoice;
  180. foreach ( $invoiceList as $k => $v ) {
  181. if ($value ['itid'] == $v ['trainId']) {
  182. $list [$key] ['invoiceTotalAmount'] = $v ['invoicePrice'];
  183. break;
  184. }
  185. }
  186. foreach ( $invoiceRecelvablesList as $i => $o ) {
  187. if ($value ['itid'] == $o ['trainId']) {
  188. $list [$key] ['invoiceArriveAmount'] = $o ['receivablesPrice'];
  189. $list [$key] ['arriveSchedule'] = "0";
  190. if ($value ['invoiceTotal'] != 0) {
  191. $list [$key] ['arriveSchedule'] = round ( $list [$key] ['invoiceArriveAmount'] / $list [$key] ['invoiceTotalAmount'] * 100, 2 );
  192. // $list [$key] ['arriveSchedule'] = round ( $o ['count'] / $value ['invoiceTotal'] * 100, 2 );
  193. }
  194. break;
  195. }
  196. }
  197. }
  198. return $list;
  199. }
  200. /**
  201. * 根据参数字段更新相应字段(主键ID必须传)
  202. * @param array $item 相关需要更新的字段信息
  203. * @return number 返回发票ID
  204. */
  205. public function setInvoiceTrainByCondition($item = array(), $itid = "") {
  206. $lid = 0;
  207. if (is_array ( $item ) && ! empty ( $item )) {
  208. foreach ( $item as $key => $value ) {
  209. $this->$key = $value;
  210. }
  211. if (! empty ( $itid )) {
  212. $condition = array (
  213. 'where' => "itid in (" . $itid . ")",
  214. 'asArray' => TRUE
  215. );
  216. $this->update ( $condition );
  217. } else
  218. $lid = $this->update ();
  219. }
  220. return $lid;
  221. }
  222. /**
  223. * 根据状态获取培训班
  224. * @param number $status
  225. */
  226. function getInvoiceTrainingByStatus($status = 0, $select = "", $cid = 0, $sid = 0) {
  227. Doo::loadModel ( 'staff' );
  228. $staff = new staff ();
  229. Doo::loadModel ( 'L_category' );
  230. $lCategory = new L_category ();
  231. $condition = array (
  232. 'where' => "status= '" . $status . "' and (cid in(" . $cid . ") or creator=" . $sid . " )",
  233. // 'limit' => 8,
  234. 'asArray' => TRUE
  235. );
  236. if (! empty ( $select ))
  237. $condition += array (
  238. 'select' => $select
  239. );
  240. $list = $this->find ( $condition );
  241. Doo::loadClass ( 'XDeode' );
  242. $XDeode = new XDeode ( 5 );
  243. $itid = array ();
  244. foreach ( $list as $key => $value ) {
  245. $list [$key] ['trainingKey'] = $XDeode->encode ( $value ['itid'] );
  246. $detail = $staff->getStaffBySid ( $value ['creator'] );
  247. $list [$key] ['staff'] = $detail;
  248. $detail = $lCategory->getCategoryById ( $value ['cid'] );
  249. $list [$key] ['category'] = $detail;
  250. array_push ( $itid, $value ['itid'] );
  251. }
  252. // 获得开票金额合计 入账金额合计 入账完成度
  253. Doo::loadModel ( 'invoice' );
  254. $invoice = new invoice ();
  255. $invoiceList = $invoiceRecelvablesList = array ();
  256. if (! empty ( $itid )) {
  257. $itidSql = implode ( ',', $itid );
  258. $invoiceList = $invoice->sumOfinvoiceTrain ( $itidSql );
  259. $invoiceRecelvablesList = $invoice->sumOfInvoiceRecelvablesTrain ( $itidSql );
  260. }
  261. // print_r($invoiceRecelvablesList);
  262. foreach ( $list as $key => $value ) {
  263. $countInvoice = $invoice->getInvoiceByTrainingCount ( $value ['itid'] );
  264. $value ['invoiceTotal'] = $countInvoice;
  265. $list [$key] ['invoiceTotal'] = $countInvoice;
  266. foreach ( $invoiceList as $k => $v ) {
  267. if ($value ['itid'] == $v ['trainId']) {
  268. $list [$key] ['invoiceTotalAmount'] = $v ['invoicePrice'];
  269. break;
  270. }
  271. }
  272. foreach ( $invoiceRecelvablesList as $i => $o ) {
  273. if ($value ['itid'] == $o ['trainId']) {
  274. $list [$key] ['invoiceArriveAmount'] = $o ['receivablesPrice'];
  275. $list [$key] ['arriveSchedule'] = "0";
  276. if ($value ['invoiceTotal'] != 0) {
  277. $list [$key] ['arriveSchedule'] = round ( $list [$key] ['invoiceArriveAmount'] / $list [$key] ['invoiceTotalAmount'] * 100, 2 );
  278. // $list [$key] ['arriveSchedule'] = round ( $o ['count'] / $value ['invoiceTotal'] * 100, 2 );
  279. }
  280. break;
  281. }
  282. }
  283. }
  284. return $list;
  285. }
  286. /**
  287. * 根据ID获得培训班
  288. * @param number $itid
  289. */
  290. function getInvoiceTrainingByItid($itid = 0) {
  291. Doo::loadClass ( 'XDeode' );
  292. $XDeode = new XDeode ( 5 );
  293. if (! is_numeric ( $itid ))
  294. $itid = $XDeode->decode ( $itid );
  295. $detail = array ();
  296. if (! empty ( $itid ) && is_numeric ( $itid )) {
  297. $detail = $this->getOne ( array (
  298. 'where' => " itid=" . $itid,
  299. 'asArray' => TRUE
  300. ) );
  301. }
  302. if (! empty ( $detail )) {
  303. $detail ['trainingKey'] = '';
  304. $detail ['invoiceArriveAmount']=$detail ['invoiceCompanyAmount']=$detail ['RIAmount']=$detail ['invoiceArriveAmount']=$detail ['invoiceTotalAmount']=0;
  305. Doo::loadModel ( 'L_category' );
  306. $lCategory = new L_category ();
  307. Doo::loadModel ( 'staff' );
  308. $staff = new staff ();
  309. $cateList = $lCategory->getCategoryById ( $detail ['cid'] );
  310. $itid = $detail ['itid'];
  311. $detail ['trainingKey'] = $XDeode->encode ( $detail ['itid'] );
  312. $staffdetail = $staff->getStaffBySid ( $detail ['creator'] );
  313. $detail ['staff'] = $staffdetail;
  314. $catedetail = $lCategory->getCategoryById ( $detail ['cid'] );
  315. $detail ['category'] = $catedetail;
  316. // 获得开票金额合计 入账金额合计 入账完成度
  317. Doo::loadModel ( 'invoice' );
  318. $invoice = new invoice ();
  319. //echo $itid;
  320. $invoiceList=$companyList=$RIList = $invoiceRecelvablesList = array ();
  321. if (! empty ( $itid )) {
  322. $itidSql = $itid;
  323. //培训班收款
  324. $invoiceList = $invoice->sumOfinvoiceTrain ( $itidSql );
  325. $invoiceRecelvablesList = $invoice->sumOfInvoiceRecelvablesTrain ( $itidSql );
  326. //公司收款--新的入账--fix
  327. $companyList = $invoice->sumOfInvoiceRecelvablesCompany ( $itidSql );
  328. //获得办事处已收款
  329. $RIList=$invoice->sumOfInvoiceByItid($itid);
  330. //print_r($RIList);
  331. }
  332. //print_r($invoiceRecelvablesList);
  333. //入账金额-培训班
  334. Doo::loadModel ( 'bill' );
  335. $bill = new bill ();
  336. $billPrice=$bill->find(array (
  337. 'select'=>'sum(price) as price',
  338. 'where' => 'trainId='. $itid ,
  339. 'orderby' => 'trainId',
  340. 'asArray' => true
  341. ));
  342. $detail ['billPrice']=0;
  343. if (!empty($billPrice)){
  344. if (!empty($billPrice[0]['price'])){
  345. $detail ['billPrice']=$billPrice[0]['price'];
  346. }
  347. }
  348. $countInvoice = $invoice->getInvoiceByTrainingCount ( $detail ['itid'] );
  349. $detail ['invoiceTotal'] = $countInvoice;
  350. foreach ( $invoiceList as $k => $v ) {
  351. if ($detail ['itid'] == $v ['trainId']) {
  352. $detail ['invoiceTotalAmount'] = $v ['invoicePrice'];
  353. break;
  354. }
  355. }
  356. foreach ( $invoiceRecelvablesList as $i => $o ) {
  357. if ($detail['itid'] == $o ['trainId']) {
  358. $detail ['invoiceArriveAmount'] = $o ['receivablesPrice'];
  359. $detail ['arriveSchedule'] = 0;
  360. if ($detail ['invoiceTotal'] != 0) {
  361. $detail ['arriveSchedule'] = round ( $detail ['invoiceArriveAmount'] / $detail ['invoiceTotalAmount'] * 100, 2 );
  362. }
  363. break;
  364. }
  365. }
  366. //办事处已收款
  367. foreach ($RIList as $key=>$value){
  368. if ($detail ['itid'] == $value ['trainId']) {
  369. $detail ['RIAmount'] = $value ['invoicePrice'];
  370. break;
  371. }
  372. }
  373. //公司已收款
  374. $detail ['invoiceCompanyAmount']=0;
  375. foreach ($companyList as $key=>$value){
  376. if ($detail ['itid'] == $value ['trainId']) {
  377. $detail ['invoiceCompanyAmount'] = $value ['receivablesPrice'];
  378. break;
  379. }
  380. }
  381. $detail ['invoiceCompanyAmountM']=sprintf ( "%.2f", $detail ['invoiceCompanyAmount'] );
  382. $detail ['invoiceArriveAmountM']=sprintf ( "%.2f", $detail ['invoiceArriveAmount'] );
  383. }
  384. //echo var_dump($detail ['invoiceTotalAmount'] ) ;
  385. //print_r($detail);
  386. return $detail;
  387. }
  388. /**
  389. * 根据ID删除数据
  390. * @param number $itid
  391. */
  392. function delInvoiceTrainingByItid($itid = 0) {
  393. Doo::loadClass ( 'XDeode' );
  394. $XDeode = new XDeode ( 5 );
  395. $itid = $XDeode->decode ( $itid );
  396. if (! empty ( $itid ) && is_numeric ( $itid ))
  397. $this->delete ( array (
  398. 'where' => 'itid=' . $itid
  399. ) );
  400. // 删除培训班下的发票
  401. Doo::loadModel ( 'invoiceStore' );
  402. $invoiceStore = new invoiceStore ();
  403. $invoiceStore->delete ( array (
  404. 'where' => 'trainId=' . $itid
  405. ) );
  406. }
  407. /**
  408. * 获得某办事处未完成的培训班
  409. * @return string
  410. */
  411. function getInvoiceTrainingByUnfinished($cid = 0) {
  412. $condition = array (
  413. 'where' => "(status= 0 or status=1) and cid=" . $cid,
  414. 'asArray' => true
  415. );
  416. $list = $this->find ( $condition );
  417. Doo::loadClass ( 'XDeode' );
  418. $XDeode = new XDeode ( 5 );
  419. foreach ( $list as $key => $value ) {
  420. $list [$key] ['itidKey'] = $XDeode->encode ( $value ['itid'] );
  421. }
  422. return $list;
  423. }
  424. /**
  425. * 获得所有培训班
  426. */
  427. function getInvoiceTrainingBySubmitStatus() {
  428. $condition = array (
  429. 'where' => "submitStatus=1",
  430. 'asArray' => TRUE
  431. );
  432. $list = $this->find ( $condition );
  433. Doo::loadClass ( 'XDeode' );
  434. $XDeode = new XDeode ( 5 );
  435. foreach ( $list as $key => $value ) {
  436. $list [$key] ['itidKey'] = $XDeode->encode ( $value ['itid'] );
  437. }
  438. return $list;
  439. }
  440. }
  441. ?>