invoiceStatistics.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. if (empty ( $list ['statisticsYear'] )) {
  83. $list ['statisticsYear'] [0] ['invoicePrice'] = 0;
  84. $list ['statisticsYear'] [0] ['receivablesPrice'] = 0;
  85. $list ['statisticsYear'] [0] ['accountPrice'] = 0;
  86. }
  87. $list ['statisticsMonth'] = $this->find ( array (
  88. 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  89. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  90. 'groupby' => 'Month(date)',
  91. 'asArray' => TRUE
  92. ) );
  93. return $list;
  94. }
  95. /**
  96. * 获取用户的统计信息
  97. * @param string $year
  98. * @param string $cid
  99. * @return NULL[]
  100. */
  101. public function getInvoiceStatisticsByStaff($year = "", $cid = "0") {
  102. $list = array ();
  103. $sql = '';
  104. if (empty ( $year ))
  105. $year = date ( "Y" );
  106. if ($cid != 0)
  107. $sql = " and cid=" . $cid;
  108. $list ['statisticsMonthCid'] = $this->find ( array (
  109. 'select' => 'cid,sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  110. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  111. 'groupby' => 'cid,Month(date)',
  112. 'asArray' => TRUE
  113. ) );
  114. $list ['statisticsMonthStaff'] = $this->find ( array (
  115. 'select' => 'cid,staff,sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  116. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  117. 'groupby' => 'staff,Month(date)',
  118. 'asArray' => TRUE
  119. ) );
  120. $list ['statisticsMonth'] = $this->find ( array (
  121. 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  122. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  123. 'groupby' => 'Month(date)',
  124. 'asArray' => TRUE
  125. ) );
  126. return $list;
  127. }
  128. public function getInvoiceStatisticsByCategory($year = "", $cid = "0") {
  129. $list = array ();
  130. $sql = '';
  131. if (empty ( $year ))
  132. $year = date ( "Y" );
  133. if ($cid != 0)
  134. $sql = " and cid=" . $cid;
  135. $list ['statisticsMonthCid'] = $this->find ( array (
  136. 'select' => 'cid,sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  137. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  138. 'groupby' => 'cid,Month(date)',
  139. 'asArray' => TRUE
  140. ) );
  141. $list ['statisticsMonthStaff'] = $this->find ( array (
  142. 'select' => 'cid,staff,sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  143. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  144. 'groupby' => 'staff,Month(date)',
  145. 'asArray' => TRUE
  146. ) );
  147. $list ['statisticsMonth'] = $this->find ( array (
  148. 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  149. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
  150. 'groupby' => 'Month(date)',
  151. 'asArray' => TRUE
  152. ) );
  153. return $list;
  154. }
  155. /**
  156. * 获取某年的汇总金额
  157. * @param string $year
  158. * @param string $cid
  159. * @return NULL[]
  160. */
  161. public function getInvoiceStatisticsByTote($year = "", $cid = "0") {
  162. $list = array ();
  163. $sql = '';
  164. if (empty ( $year ))
  165. $year = date ( "Y" );
  166. if ($cid != 0)
  167. $sql = " and cid=" . $cid;
  168. $list ['statisticsYear'] = $this->find ( array (
  169. 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Year(date) as Year',
  170. 'where' => " Year(date) =" . $year . $sql,
  171. 'groupby' => 'Year(date)',
  172. 'asArray' => TRUE
  173. ) );
  174. if (empty ( $list ['statisticsYear'] )) {
  175. $list ['statisticsYear'] [0] ['invoicePrice'] = 0;
  176. $list ['statisticsYear'] [0] ['receivablesPrice'] = 0;
  177. $list ['statisticsYear'] [0] ['accountPrice'] = 0;
  178. }
  179. return $list;
  180. }
  181. public function getStatisticsByMonth() {
  182. $month = date ( "m" );
  183. $year = date ( "Y" );
  184. $list ['statisticsMonth'] = $this->find ( array (
  185. 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  186. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . " and Month(date)=" . $month,
  187. 'groupby' => 'Month(date)',
  188. 'asArray' => TRUE
  189. ) );
  190. if (empty ( $list ['statisticsMonth'] )) {
  191. $list ['statisticsMonth'] [0] ['invoicePrice'] = 0;
  192. $list ['statisticsMonth'] [0] ['receivablesPrice'] = 0;
  193. $list ['statisticsMonth'] [0] ['accountPrice'] = 0;
  194. $list ['statisticsMonth'] [0] ['month'] = $month;
  195. }
  196. $list ['statisticsYear'] = $this->find ( array (
  197. 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Year(date) as Year',
  198. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year,
  199. 'groupby' => 'Year(date)',
  200. 'asArray' => TRUE
  201. ) );
  202. if (empty ( $list ['statisticsYear'] )) {
  203. $list ['statisticsYear'] [0] ['invoicePrice'] = 0;
  204. $list ['statisticsYear'] [0] ['receivablesPrice'] = 0;
  205. $list ['statisticsYear'] [0] ['accountPrice'] = 0;
  206. $list ['statisticsYear'] [0] ['month'] = $month;
  207. }
  208. return $list;
  209. }
  210. public function getBrieflyStatistics() {
  211. $year = date ( "Y" );
  212. $month = date ( "m" );
  213. $tmp_date = date ( "Ym" );
  214. $tmp_year = substr ( $tmp_date, 0, 4 );
  215. $tmp_mon = substr ( $tmp_date, 4, 2 );
  216. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  217. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  218. $list ['statisticsMonth'] = $this->find ( array (
  219. 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  220. 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . " and Month(date)=" . $fm_forward_month,
  221. 'groupby' => 'Month(date)',
  222. 'asArray' => TRUE
  223. ) );
  224. if (empty ( $list ['statisticsMonth'] )) {
  225. $list ['statisticsMonth'] [0] ['invoicePrice'] = 0;
  226. $list ['statisticsMonth'] [0] ['receivablesPrice'] = 0;
  227. $list ['statisticsMonth'] [0] ['accountPrice'] = 0;
  228. $list ['statisticsMonth'] [0] ['month'] = $fm_forward_month;
  229. }
  230. return $list;
  231. }
  232. public function getInvoiceStatisticsByCondition($condition = '') {
  233. if (empty ( $condition ))
  234. return array ();
  235. $list = $this->find ( array (
  236. 'where' => $condition,
  237. 'asArray' => TRUE
  238. ) );
  239. return $list;
  240. }
  241. }
  242. ?>