invoiceStatistics.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  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,$priceClass=0) {
  47. if (is_numeric ( $irid ) && is_array ( $item ) && ! empty ( $item )) {
  48. foreach ( $item as $key => $value ) {
  49. $this->$key = $value;
  50. }
  51. $sql="";
  52. if (!empty($priceClass))
  53. $sql=" and priceClass=".$priceClass;
  54. $lid = $this->update ( array (
  55. 'where' => 'irid=' . $irid .$sql
  56. ) );
  57. }
  58. return $lid;
  59. }
  60. /**
  61. * 根据发票ID和绑定状态获得收款数据,绑定状态为ALL获取所有状态数据
  62. * @param string $iid 发票ID
  63. * @param string $bindStatus
  64. * @return mixed
  65. */
  66. public function getInvoiceStatisticsByYear($year = "", $cid = "0") {
  67. $list = array ();
  68. $sql = '';
  69. if (empty ( $year ))
  70. $year = date ( "Y" );
  71. if ($cid != 0)
  72. $sql = " and cid=" . $cid;
  73. $list ['statisticsMonthCid'] = $this->find ( array (
  74. 'select' => 'cid,sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  75. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  76. 'groupby' => 'cid,Month(date)',
  77. 'asArray' => TRUE
  78. ) );
  79. $list ['statisticsYear'] = $this->find ( array (
  80. 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Year(date) as Year',
  81. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  82. 'groupby' => 'Year(date)',
  83. 'asArray' => TRUE
  84. ) );
  85. if (empty ( $list ['statisticsYear'] )) {
  86. $list ['statisticsYear'] [0] ['invoicePrice'] = 0;
  87. $list ['statisticsYear'] [0] ['receivablesPrice'] = 0;
  88. $list ['statisticsYear'] [0] ['accountPrice'] = 0;
  89. }
  90. $list ['statisticsMonth'] = $this->find ( array (
  91. 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  92. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  93. 'groupby' => 'Month(date)',
  94. 'asArray' => TRUE
  95. ) );
  96. return $list;
  97. }
  98. /**
  99. * 获取用户的统计信息
  100. * @param string $year
  101. * @param string $cid
  102. * @return NULL[]
  103. */
  104. public function getInvoiceStatisticsByStaff($year = "", $cid = "0") {
  105. $list = array ();
  106. $sql = '';
  107. if (empty ( $year ))
  108. $year = date ( "Y" );
  109. if ($cid != 0)
  110. $sql = " and cid=" . $cid;
  111. $list ['statisticsMonthCid'] = $this->find ( array (
  112. 'select' => 'cid,sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  113. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  114. 'groupby' => 'cid,Month(date)',
  115. 'asArray' => TRUE
  116. ) );
  117. $list ['statisticsMonthStaff'] = $this->find ( array (
  118. 'select' => 'cid,staff,sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  119. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  120. 'groupby' => 'staff,Month(date)',
  121. 'asArray' => TRUE
  122. ) );
  123. $list ['statisticsMonth'] = $this->find ( array (
  124. 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  125. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  126. 'groupby' => 'Month(date)',
  127. 'asArray' => TRUE
  128. ) );
  129. return $list;
  130. }
  131. public function getInvoiceStatisticsByCategory($year = "", $cid = "0") {
  132. $list = array ();
  133. $sql = '';
  134. if (empty ( $year ))
  135. $year = date ( "Y" );
  136. if ($cid != 0)
  137. $sql = " and cid=" . $cid;
  138. $list ['statisticsMonthCid'] = $this->find ( array (
  139. 'select' => 'cid,sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  140. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  141. 'groupby' => 'cid,Month(date)',
  142. 'asArray' => TRUE
  143. ) );
  144. $list ['statisticsMonthStaff'] = $this->find ( array (
  145. 'select' => 'cid,staff,sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  146. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  147. 'groupby' => 'staff,Month(date)',
  148. 'asArray' => TRUE
  149. ) );
  150. $list ['statisticsMonth'] = $this->find ( array (
  151. 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  152. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  153. 'groupby' => 'Month(date)',
  154. 'asArray' => TRUE
  155. ) );
  156. return $list;
  157. }
  158. /**
  159. * 获取某年的汇总金额
  160. * @param string $year
  161. * @param string $cid
  162. * @return NULL[]
  163. */
  164. public function getInvoiceStatisticsByTote($year = "", $cid = "0") {
  165. $list = array ();
  166. $sql = '';
  167. if (empty ( $year ))
  168. $year = date ( "Y" );
  169. if ($cid != 0)
  170. $sql = " and cid=" . $cid;
  171. $list ['statisticsYear'] = $this->find ( array (
  172. 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Year(date) as Year',
  173. 'where' => " Year(date) =" . $year . $sql,
  174. 'groupby' => 'Year(date)',
  175. 'asArray' => TRUE
  176. ) );
  177. if (empty ( $list ['statisticsYear'] )) {
  178. $list ['statisticsYear'] [0] ['invoicePrice'] = 0;
  179. $list ['statisticsYear'] [0] ['receivablesPrice'] = 0;
  180. $list ['statisticsYear'] [0] ['accountPrice'] = 0;
  181. }
  182. return $list;
  183. }
  184. public function getStatisticsByMonth() {
  185. $month = date ( "m" );
  186. $year = date ( "Y" );
  187. $list ['statisticsMonth'] = $this->find ( array (
  188. 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  189. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . " and Month(date)=" . $month,
  190. 'groupby' => 'Month(date)',
  191. 'asArray' => TRUE
  192. ) );
  193. if (empty ( $list ['statisticsMonth'] )) {
  194. $list ['statisticsMonth'] [0] ['invoicePrice'] = 0;
  195. $list ['statisticsMonth'] [0] ['receivablesPrice'] = 0;
  196. $list ['statisticsMonth'] [0] ['accountPrice'] = 0;
  197. $list ['statisticsMonth'] [0] ['month'] = $month;
  198. }
  199. $list ['statisticsYear'] = $this->find ( array (
  200. 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Year(date) as Year',
  201. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year,
  202. 'groupby' => 'Year(date)',
  203. 'asArray' => TRUE
  204. ) );
  205. if (empty ( $list ['statisticsYear'] )) {
  206. $list ['statisticsYear'] [0] ['invoicePrice'] = 0;
  207. $list ['statisticsYear'] [0] ['receivablesPrice'] = 0;
  208. $list ['statisticsYear'] [0] ['accountPrice'] = 0;
  209. $list ['statisticsYear'] [0] ['month'] = $month;
  210. }
  211. return $list;
  212. }
  213. public function getBrieflyStatistics() {
  214. $year = date ( "Y" );
  215. $month = date ( "m" );
  216. $tmp_date = date ( "Ym" );
  217. $tmp_year = substr ( $tmp_date, 0, 4 );
  218. $tmp_mon = substr ( $tmp_date, 4, 2 );
  219. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  220. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  221. $list ['statisticsMonth'] = $this->find ( array (
  222. 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  223. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . " and Month(date)=" . $fm_forward_month,
  224. 'groupby' => 'Month(date)',
  225. 'asArray' => TRUE
  226. ) );
  227. if (empty ( $list ['statisticsMonth'] )) {
  228. $list ['statisticsMonth'] [0] ['invoicePrice'] = 0;
  229. $list ['statisticsMonth'] [0] ['receivablesPrice'] = 0;
  230. $list ['statisticsMonth'] [0] ['accountPrice'] = 0;
  231. $list ['statisticsMonth'] [0] ['month'] = $fm_forward_month;
  232. }
  233. return $list;
  234. }
  235. public function getInvoiceStatisticsByCondition($condition = '') {
  236. if (empty ( $condition ))
  237. return array ();
  238. $list = $this->find ( array (
  239. 'where' => $condition,
  240. 'asArray' => TRUE
  241. ) );
  242. return $list;
  243. }
  244. }
  245. ?>