invoiceStatistics.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. Doo::loadCore ( 'db/DooModel' );
  3. class invoiceStatistics extends DooModel {
  4. public $sid;
  5. public $priceClass;
  6. public $date;
  7. public $cid;
  8. public $staff;
  9. public $invoicePrice;
  10. public $accountPrice;
  11. public $receivablesPrice;
  12. public $irid;
  13. public $_table = 'CLD_invoiceStatistics';
  14. public $_primarykey = 'sid';
  15. public $_fields = array (
  16. 'sid',
  17. 'staff',
  18. 'priceClass',
  19. 'invoicePrice',
  20. 'receivablesPrice',
  21. 'accountPrice',
  22. 'date',
  23. 'cid',
  24. 'irid'
  25. );
  26. /**
  27. * 根据参数字段更新相应字段(主键ID必须传)
  28. * @param array $item 相关需要更新的字段信息
  29. * @return number 返回发票ID
  30. */
  31. public function setInvoiceStatisticsByCondition($item = array()) {
  32. $lid = 0;
  33. if (is_array ( $item ) && ! empty ( $item )) {
  34. foreach ( $item as $key => $value ) {
  35. $this->$key = $value;
  36. }
  37. $lid = $this->insert ();
  38. }
  39. return $lid;
  40. }
  41. /**
  42. * 根据参数字段更新相应字段(主键ID必须传)
  43. * @param array $item 相关需要更新的字段信息
  44. * @return number 返回发票ID
  45. */
  46. public function updateInvoiceStatisticsByIrid($item = array(), $irid = 0) {
  47. if (is_numeric ( $irid ) && is_array ( $item ) && ! empty ( $item )) {
  48. foreach ( $item as $key => $value ) {
  49. $this->$key = $value;
  50. }
  51. $lid = $this->update ( array (
  52. 'where' => 'irid=' . $irid
  53. ) );
  54. }
  55. return $lid;
  56. }
  57. /**
  58. * 根据发票ID和绑定状态获得收款数据,绑定状态为ALL获取所有状态数据
  59. * @param string $iid 发票ID
  60. * @param string $bindStatus
  61. * @return mixed
  62. */
  63. public function getInvoiceStatisticsByYear($year="", $cid = "0") {
  64. $list = array ();
  65. $sql = '';
  66. if (empty($year))
  67. $year=date("Y");
  68. if ($cid != 0)
  69. $sql = " and cid=" . $cid;
  70. $list['statisticsMonthCid'] = $this->find ( array (
  71. 'select'=>'cid,sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  72. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  73. 'groupby'=>'cid,Month(date)',
  74. 'asArray' => TRUE
  75. ) );
  76. $list['statisticsYear'] = $this->find ( array (
  77. 'select'=>'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Year(date) as Year',
  78. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  79. 'groupby'=>'Year(date)',
  80. 'asArray' => TRUE
  81. ) );
  82. $list['statisticsMonth'] = $this->find ( array (
  83. 'select'=>'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  84. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  85. 'groupby'=>'Month(date)',
  86. 'asArray' => TRUE
  87. ) );
  88. return $list;
  89. }
  90. /**
  91. * 获取用户的统计信息
  92. * @param string $year
  93. * @param string $cid
  94. * @return NULL[]
  95. */
  96. public function getInvoiceStatisticsByStaff($year="", $cid = "0") {
  97. $list = array ();
  98. $sql = '';
  99. if (empty($year))
  100. $year=date("Y");
  101. if ($cid != 0)
  102. $sql = " and cid=" . $cid;
  103. $list['statisticsMonthCid'] = $this->find ( array (
  104. 'select'=>'cid,sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  105. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  106. 'groupby'=>'cid,Month(date)',
  107. 'asArray' => TRUE
  108. ) );
  109. $list['statisticsMonthStaff'] = $this->find ( array (
  110. 'select'=>'cid,staff,sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  111. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  112. 'groupby'=>'staff,Month(date)',
  113. 'asArray' => TRUE
  114. ) );
  115. $list['statisticsMonth'] = $this->find ( array (
  116. 'select'=>'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  117. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  118. 'groupby'=>'Month(date)',
  119. 'asArray' => TRUE
  120. ) );
  121. return $list;
  122. }
  123. public function getInvoiceStatisticsByCategory($year="", $cid = "0") {
  124. $list = array ();
  125. $sql = '';
  126. if (empty($year))
  127. $year=date("Y");
  128. if ($cid != 0)
  129. $sql = " and cid=" . $cid;
  130. $list['statisticsMonthCid'] = $this->find ( array (
  131. 'select'=>'cid,sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  132. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  133. 'groupby'=>'cid,Month(date)',
  134. 'asArray' => TRUE
  135. ) );
  136. $list['statisticsMonthStaff'] = $this->find ( array (
  137. 'select'=>'cid,staff,sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  138. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  139. 'groupby'=>'staff,Month(date)',
  140. 'asArray' => TRUE
  141. ) );
  142. $list['statisticsMonth'] = $this->find ( array (
  143. 'select'=>'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  144. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  145. 'groupby'=>'Month(date)',
  146. 'asArray' => TRUE
  147. ) );
  148. return $list;
  149. }
  150. /**
  151. * 获取某年的汇总金额
  152. * @param string $year
  153. * @param string $cid
  154. * @return NULL[]
  155. */
  156. public function getInvoiceStatisticsByTote($year="", $cid = "0") {
  157. $list = array ();
  158. $sql = '';
  159. if (empty($year))
  160. $year=date("Y");
  161. if ($cid != 0)
  162. $sql = " and cid=" . $cid;
  163. $list['statisticsYear'] = $this->find ( array (
  164. 'select'=>'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Year(date) as Year',
  165. 'where' => " Year(date) =" . $year . $sql,
  166. 'groupby'=>'Year(date)',
  167. 'asArray' => TRUE
  168. ) );
  169. if (empty($list['statisticsYear'])){
  170. $list['statisticsYear'][0]['invoicePrice']=0;
  171. $list['statisticsYear'][0]['receivablesPrice']=0;
  172. $list['statisticsYear'][0]['accountPrice']=0;
  173. }
  174. return $list;
  175. }
  176. }
  177. ?>