accountBookStatistics.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <?php
  2. Doo::loadCore ( 'db/DooModel' );
  3. class accountBookStatistics extends DooModel {
  4. public $reusltPrice=0;
  5. public $aid;
  6. public $asid;
  7. public $inComePrice;
  8. public $payPrice;
  9. public $expensesType;
  10. public $financingPrice;
  11. public $date;
  12. public $accountType;
  13. public $expenditureType;
  14. public $_table = 'CLD_accountBookStatistics';
  15. public $_primarykey = 'asid';
  16. public $_fields = array (
  17. 'aid',
  18. 'expensesType',
  19. 'asid',
  20. 'inComePrice',
  21. 'payPrice',
  22. 'financingPrice',
  23. 'date',
  24. 'accountType',
  25. 'expenditureType',
  26. 'accountMsg',
  27. 'expenditureMsg',
  28. );
  29. /**
  30. * 添加相关开票操作日志
  31. *
  32. * @param array $item 要记录的相关发票操作数据
  33. * @return integer|0 返回操作ID
  34. */
  35. public function setAccountBookStatistics($item = array()) {
  36. $lid = 0;
  37. if (is_array ( $item ) && ! empty ( $item )) {
  38. foreach ( $item as $key => $value ) {
  39. $this->$key = $value;
  40. }
  41. $lid = $this->insert ();
  42. }
  43. return $lid;
  44. }
  45. public function updateAccountBookStatistics($item = array(),$aid=0){
  46. $lid = 0;
  47. if (is_array ( $item ) && ! empty ( $item )&& ! empty ( $aid )) {
  48. foreach ( $item as $key => $value ) {
  49. $this->$key = $value;
  50. }
  51. $lid = $this->update (array (
  52. 'where' => "aid=" . $aid.' and ',
  53. 'asArray' => TRUE
  54. ));
  55. }
  56. return $lid;
  57. }
  58. /**
  59. *
  60. * @param unknown $year
  61. * @param number $expensesType 汇总类型
  62. */
  63. public function getStatisticsByCollect($year= '',$expensesType=1) {
  64. if (empty($year))
  65. $year=date ( "Y" );
  66. $list=array();
  67. if ($expensesType==1){
  68. $list = $this->find ( array (
  69. 'select' => 'sum(inComePrice) as inComePrice,sum(payPrice) as payPrice,Month(date) as month,accountType,accountMsg,Year(date)',
  70. 'where' => " Year(date) =" . $year . " and expensesType=" . $expensesType,
  71. 'groupby' => 'Month(date),accountType,accountMsg',
  72. 'asArray' => TRUE
  73. ) );
  74. }elseif($expensesType==2){
  75. $list = $this->find ( array (
  76. 'select' => 'sum(inComePrice) as inComePrice,sum(payPrice) as payPrice,Month(date) as month,expenditureType,expenditureMsg,Year(date)',
  77. 'where' => " Year(date) =" . $year . " and expensesType=" . $expensesType,
  78. 'groupby' => 'Month(date),expenditureType,expenditureMsg',
  79. 'asArray' => TRUE
  80. ) );
  81. }
  82. return $list;
  83. }
  84. /**
  85. *
  86. * @param unknown $year
  87. * @param number $expensesType 汇总类型
  88. */
  89. public function getStatisticsByCollectDay($year= '',$expensesType=1,$month=1) {
  90. if (empty($year))
  91. $year=date ( "Y" );
  92. $list=array();
  93. if ($expensesType==1){
  94. $list = $this->find ( array (
  95. 'select' => 'sum(inComePrice) as inComePrice,sum(payPrice) as payPrice,Month(date) as month,accountType,accountMsg,Year(date),Day(date) as day',
  96. 'where' => " Year(date) =" . $year . " and expensesType=" . $expensesType.' and Month(date)='.$month,
  97. 'groupby' => 'Day(date),accountType,accountMsg',
  98. 'asArray' => TRUE
  99. ) );
  100. }elseif($expensesType==2){
  101. $list = $this->find ( array (
  102. 'select' => 'sum(inComePrice) as inComePrice,sum(payPrice) as payPrice,Month(date) as month,expenditureType,expenditureMsg,Year(date),Day(date) as day',
  103. 'where' => " Year(date) =" . $year . " and expensesType=" . $expensesType.' and Month(date)='.$month,
  104. 'groupby' => 'Day(date),expenditureType,expenditureMsg',
  105. 'asArray' => TRUE
  106. ) );
  107. }
  108. return $list;
  109. }
  110. public function getStatisticsByMonth() {
  111. $day = date ( "d" );
  112. $month = date ( "m" );
  113. $year = date ( "Y" );
  114. $list ['statisticsMonth'] = $this->find ( array (
  115. 'select' => 'sum(inComePrice) as inComePrice,sum(payPrice) as payPrice,Month(date) as month',
  116. 'where' => " Year(date) =" . $year . " and Month(date)=" . $month.' and (accountType!=8 and expenditureType!=5)',
  117. 'groupby' => 'Month(date)',
  118. 'asArray' => TRUE
  119. ) );
  120. if (empty ( $list ['statisticsMonth'] )) {
  121. $list ['statisticsMonth'] [0] ['inComePrice'] = 0;
  122. $list ['statisticsMonth'] [0] ['payPrice'] = 0;
  123. $list ['statisticsMonth'] [0] ['month'] = $month;
  124. }
  125. $list ['statisticsDay'] = $this->find ( array (
  126. 'select' => 'sum(inComePrice) as inComePrice,sum(payPrice) as payPrice,Year(date) as Year',
  127. 'where' => " Year(date) =" . $year. " and Month(date)=" . $month.' and Day(date)='.$day.' and (accountType!=8 and expenditureType!=5)',
  128. 'groupby' => 'Day(date)',
  129. 'asArray' => TRUE
  130. ) );
  131. if (empty ( $list ['statisticsDay'] )) {
  132. $list ['statisticsDay'] [0] ['inComePrice'] = 0;
  133. $list ['statisticsDay'] [0] ['payPrice'] = 0;
  134. $list ['statisticsDay'] [0] ['month'] = $month;
  135. }
  136. //理财
  137. $list ['financingPrice'] = $this->find ( array (
  138. 'select' => 'sum(financingPrice) as financingPrice',
  139. 'where' => " expensesType=3",
  140. 'groupby' => 'expensesType',
  141. 'asArray' => TRUE
  142. ) );
  143. //保证金
  144. $list ['statisticsBond'] = $this->find ( array (
  145. 'select' => 'sum(inComePrice) as inComePrice,sum(payPrice) as payPrice',
  146. 'where' => " accountType=8 or expenditureType=5",
  147. 'groupby' => 'expenditureType,accountType',
  148. 'asArray' => TRUE
  149. ) );
  150. $bondPriceA=0;
  151. if (isset($list ['statisticsBond'][0])){
  152. $bondPriceA=$list ['statisticsBond'][0]['inComePrice'];
  153. }
  154. $bondPriceB=0;
  155. if (isset($list ['statisticsBond'][1])){
  156. $bondPriceB=$list ['statisticsBond'][1]['payPrice'];
  157. }
  158. $list ['statisticsBond']=$bondPriceA+$bondPriceB;
  159. if (empty ( $list ['financingPrice'] )) {
  160. $list ['financingPrice'] [0] ['financingPrice'] = $this->reusltPrice;
  161. }else{
  162. $list ['financingPrice'][0]['financingPrice']=$this->reusltPrice+$list ['financingPrice'][0]['financingPrice'];
  163. }
  164. return $list;
  165. }
  166. public function getStatisticsByBalance($year= '',$expensesType=1,$month=0) {
  167. $con='';$groupby='Month(date)';
  168. if ($month!=0){
  169. $con=' and Month(date)='.$month;
  170. $groupby='Day(date)';
  171. }
  172. $list = $this->find ( array (
  173. 'select' => 'sum(inComePrice) as inComePrice,sum(payPrice) as payPrice,Month(date) as month,expensesType,Year(date),Day(date) as day',
  174. 'where' => " Year(date) =" . $year . " and expensesType=" . $expensesType.$con,
  175. 'groupby' => $groupby,
  176. 'asArray' => TRUE
  177. ) );
  178. return $list;
  179. }
  180. }
  181. ?>