invoiceStatistics.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357
  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($sid=0) {
  185. $month = date ( "m" );
  186. $year = date ( "Y" );
  187. if(empty($sid)){
  188. $list ['statisticsMonth'] [0] ['invoicePrice'] = 0;
  189. $list ['statisticsMonth'] [0] ['receivablesPrice'] = 0;
  190. $list ['statisticsMonth'] [0] ['accountPrice'] = 0;
  191. $list ['statisticsMonth'] [0] ['month'] = $month;
  192. $list ['statisticsYear'] [0] ['invoicePrice'] = 0;
  193. $list ['statisticsYear'] [0] ['receivablesPrice'] = 0;
  194. $list ['statisticsYear'] [0] ['accountPrice'] = 0;
  195. $list ['statisticsYear'] [0] ['month'] = $month;
  196. return $list;
  197. }
  198. $list ['statisticsMonth'] = $this->find ( array (
  199. 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  200. 'where' => " cid!=0 and staff=".$sid." and Year(date) =" . $year . " and Month(date)=" . $month,
  201. 'groupby' => 'Month(date)',
  202. 'asArray' => TRUE
  203. ) );
  204. if (empty ( $list ['statisticsMonth'] )) {
  205. $list ['statisticsMonth'] [0] ['invoicePrice'] = 0;
  206. $list ['statisticsMonth'] [0] ['receivablesPrice'] = 0;
  207. $list ['statisticsMonth'] [0] ['accountPrice'] = 0;
  208. $list ['statisticsMonth'] [0] ['month'] = $month;
  209. }
  210. $list ['statisticsYear'] = $this->find ( array (
  211. 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Year(date) as Year',
  212. 'where' => " cid!=0 and staff=".$sid." and Year(date) =" . $year,
  213. 'groupby' => 'Year(date)',
  214. 'asArray' => TRUE
  215. ) );
  216. if (empty ( $list ['statisticsYear'] )) {
  217. $list ['statisticsYear'] [0] ['invoicePrice'] = 0;
  218. $list ['statisticsYear'] [0] ['receivablesPrice'] = 0;
  219. $list ['statisticsYear'] [0] ['accountPrice'] = 0;
  220. $list ['statisticsYear'] [0] ['month'] = $month;
  221. }
  222. return $list;
  223. }
  224. public function getBrieflyStatistics($sid=0) {
  225. $year = date ( "Y" );
  226. $month = date ( "m" );
  227. $tmp_date = date ( "Ym" );
  228. $tmp_year = substr ( $tmp_date, 0, 4 );
  229. $tmp_mon = substr ( $tmp_date, 4, 2 );
  230. $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
  231. $fm_forward_month = date ( "m", $tmp_forwardmonth );
  232. $list ['statisticsMonth'] = $this->find ( array (
  233. 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
  234. 'where' => " cid!=0 and staff='.$sid.' and Year(date) =" . $year . " and Month(date)=" . $fm_forward_month,
  235. 'groupby' => 'Month(date)',
  236. 'asArray' => TRUE
  237. ) );
  238. if (empty ( $list ['statisticsMonth'] )) {
  239. $list ['statisticsMonth'] [0] ['invoicePrice'] = 0;
  240. $list ['statisticsMonth'] [0] ['receivablesPrice'] = 0;
  241. $list ['statisticsMonth'] [0] ['accountPrice'] = 0;
  242. $list ['statisticsMonth'] [0] ['month'] = $fm_forward_month;
  243. }
  244. return $list;
  245. }
  246. public function getInvoiceStatisticsByCondition($condition = '') {
  247. if (empty ( $condition ))
  248. return array ();
  249. $list = $this->find ( array (
  250. 'where' => $condition,
  251. 'asArray' => TRUE
  252. ) );
  253. return $list;
  254. }
  255. /**
  256. * 获得办事处下成员本月的开票汇总
  257. * @param number $cid
  258. */
  259. public function getISMSByCategoryByMonth($cid = 0, $month) {
  260. if (empty ( $cid ))
  261. return array ();
  262. //date_format(column,'%Y-%m')=
  263. // $sql = 'select sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice ,cid,staff,Month(date) as month
  264. // from ' . $this->_table . '
  265. // where Month(date)=' . $month . ' and cid = ' . $cid . '
  266. // GROUP BY staff';
  267. $sql = 'select sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice ,cid,staff,Month(date) as month
  268. from ' . $this->_table . '
  269. where date_format(date,"%Y-%m")=' . $month . ' and cid = ' . $cid . '
  270. GROUP BY staff';
  271. //echo $sql;
  272. $query = Doo::db ()->query ( $sql );
  273. return $result = $query->fetchAll ();
  274. }
  275. /**
  276. * 获得办事处下成员本月的开票汇总
  277. * @param number $cid
  278. */
  279. public function getISMSByCategory($cid = 0) {
  280. if (empty ( $cid ))
  281. return array ();
  282. $month = date ( "m" );
  283. $year=date('Y');
  284. $sql = 'select sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice ,cid,staff,Month(date) as month
  285. from ' . $this->_table . '
  286. where Month(date)=' . $month . ' and Year(date)='.$year.' and cid = ' . $cid . '
  287. GROUP BY staff';
  288. $query = Doo::db ()->query ( $sql );
  289. //echo $sql;
  290. return $result = $query->fetchAll ();
  291. }
  292. /**
  293. * 获得办事处成员全部个人汇总数据
  294. * @param unknown $cid
  295. */
  296. public function getISASByCategory($cid) {
  297. if (empty ( $cid ))
  298. return array ();
  299. $month = date ( "m" );
  300. $sql = 'select sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice ,cid,staff,Month(date) as month
  301. from ' . $this->_table . '
  302. where cid = ' . $cid . '
  303. GROUP BY staff';
  304. $query = Doo::db ()->query ( $sql );
  305. return $result = $query->fetchAll ();
  306. }
  307. /**
  308. * 获得某办事处本月汇总
  309. */
  310. public function getInvoiceStatistiscsMothByCategory($cid = 0) {
  311. if (empty ( $cid ))
  312. return array ();
  313. $month = date ( "m" );
  314. $sql = 'select sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice ,cid,Month(date) as month
  315. from ' . $this->_table . '
  316. where Month(date)=' . $month . ' and cid = ' . $cid . ' and staff!=0
  317. GROUP BY cid';
  318. $query = Doo::db ()->query ( $sql );
  319. //echo $sql;
  320. return $result = $query->fetch ();
  321. }
  322. }
  323. ?>