RItem.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. <?php
  2. Doo::loadCore ( 'db/DooModel' );
  3. class RItem extends DooModel {
  4. public $riid;
  5. public $rid;
  6. public $identifying;
  7. public $item;
  8. public $price;
  9. public $date;
  10. public $inputer;
  11. public $describe;
  12. public $payType;
  13. public $creater;
  14. public $createrId;
  15. public $creatDate;
  16. public $_table = 'CLD_RItem';
  17. public $_primarykey = 'riid';
  18. public $_fields = array (
  19. 'riid',
  20. 'rid',
  21. 'identifying',
  22. 'item',
  23. 'price',
  24. 'date',
  25. 'inputer',
  26. 'describe',
  27. 'payType',
  28. 'creater',
  29. 'createrId',
  30. 'creatDate',
  31. );
  32. /**
  33. * 一组培训班结算支出项金额总和
  34. * @param string $rids
  35. */
  36. function getRItemPriceByRids($rids=''){
  37. if (empty($rids)){
  38. return 0;
  39. }
  40. $sum = $this->getOne ( array (
  41. 'select' => 'sum(price) as price',
  42. 'where' => " rid in (" .$rids.")",
  43. //'groupby' => 'cid,Month(date)',
  44. 'asArray' => TRUE
  45. ) );
  46. return $sum['price'];
  47. }
  48. function getRItemByRiid($riid){
  49. $detail=$this->getOne(array (
  50. 'where' => "riid=".$riid,
  51. 'asArray' => TRUE
  52. ));
  53. return $detail;
  54. }
  55. function addRItem($itemData,$receipt,$receiptDetail,$rid,$item,$price,$payType){
  56. if (is_array ( $itemData ) && ! empty ( $itemData )) {
  57. foreach ( $itemData as $key => $value ) {
  58. $this->$key = $value;
  59. }
  60. $lid = $this->insert ();
  61. }
  62. // 添加公司汇总
  63. // 报销详情
  64. $rInfo = $receipt->getReceiptByRid ( $rid );
  65. $rdInfo = $receiptDetail->getReceiptDetailByRIC ( $rid, $item, '培训班费用' );
  66. if (empty ( $rdInfo )) {
  67. $receiptDetail = new receiptDetail ();
  68. $receiptDetail->staff = $rInfo ['staff'];
  69. $receiptDetail->item = $item;
  70. $receiptDetail->itemCategory = '培训班费用';
  71. $receiptDetail->price = $price;
  72. $receiptDetail->date = date ( "Y-m-d" );
  73. $receiptDetail->cid = $rInfo ['cid'];
  74. $receiptDetail->rid = $rid;
  75. $receiptDetail->status = 4;
  76. $receiptDetail->insert ();
  77. } else {
  78. $receiptDetail = new receiptDetail ();
  79. $rdInfo ['price'] += $price;
  80. $receiptDetail->price = $rdInfo ['price'];
  81. $receiptDetail->update ( array (
  82. 'where' => 'rid=' . $rid . ' and item like "' . $item . '" and itemCategory like "培训班费用"'
  83. ) );
  84. }
  85. //更新费用合计金额
  86. $receipt = new receipt ();
  87. $receipt->sum=$rInfo['sum']+ $price;
  88. $receipt->update ( array (
  89. 'where' => 'rid=' . $rid
  90. ) );
  91. //汇总金额--提交审批之后有 支出项时 需要更新汇总
  92. if($payType=='company'){
  93. Doo::loadModel ( "statistics" );
  94. $statistics = new statistics ();
  95. $dateArray = explode ( "-", $rInfo ['date'] );
  96. $dateCondition = " and Year(date) =" . $dateArray [0] . " and Month(date) = " . $dateArray [1];
  97. $stat = $statistics->getOne ( array (
  98. 'where' => 'staff=' . $rInfo ['staff'] . $dateCondition,
  99. 'asArray' => true
  100. ) );
  101. if (!empty($stat)){
  102. //$statistics->agPrice = $stat ['agPrice'] + $price;
  103. $statistics->rePrice = $stat ['rePrice'] + $price;
  104. $statistics->update ( array (
  105. 'where' => 'sid=' . $stat ['sid']
  106. ) );
  107. }
  108. }
  109. }
  110. /**
  111. * 根据rid获得支出项详情
  112. * @param number $rid
  113. */
  114. function getRItemByRid($rid=0,$name=''){
  115. $con='';
  116. if(!empty($name)){
  117. $con=' ORDER BY case WHEN item like "%'.$name.'%" then 1 end desc';
  118. }else{
  119. $con=' ORDER BY creatDate desc';
  120. }
  121. $sql = 'select (@rowNO := @rowNo+1) AS i, a.* from ' . $this->_table . ' a , (select @rowNO :=0) b where rid='.$rid.$con;
  122. $query = Doo::db ()->query ( $sql );
  123. $list = $query->fetchAll ();
  124. Doo::loadClass ( 'XDeode' );
  125. $XDeode = new XDeode ( 5 );
  126. foreach ($list as $key=>$value){
  127. $list[$key]['riidKey']=$XDeode->encode($value['riid']);
  128. // if($value['item']=='税款'){
  129. // $list[$key]['price']=$value['price']*0.07;
  130. // }
  131. }
  132. return $list;
  133. }
  134. }
  135. ?>