statistics.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. Doo::loadCore('db/DooModel');
  3. class statistics extends DooModel {
  4. public $sid;
  5. public $date;
  6. public $cid;
  7. public $staff;
  8. public $rePrice;
  9. public $agPrice;
  10. public $_table = 'CLD_statistics';
  11. public $_primarykey = 'sid';
  12. public $_fields = array('sid', 'staff', 'rePrice', 'date', 'cid','agPrice');
  13. function statisticsByYear($year,$sid){
  14. //
  15. $sql = "select sum(rePrice) as rePrice,sum(agPrice) as agPrice from " . $this->_table . " where staff= '".$sid."' and Year(date) =".$year." group by Year(date)" ;
  16. //echo '<div style="display:none">'.$sql.'</div>';
  17. $query = Doo::db ()->query ( $sql );
  18. $result = $query->fetch ();
  19. return $result;
  20. }
  21. function statisticsByComPanyYear($year,$sid,$cidString=''){
  22. //staff= '".$sid."' and
  23. $cidSql='';
  24. if(!empty($cidString))
  25. $cidSql=' and cid in ('.$cidString.')';
  26. $sql = "select sum(rePrice) as rePrice,sum(agPrice) as agPrice from " . $this->_table . " where Year(date) =".$year.$cidSql." group by Year(date)" ;
  27. $query = Doo::db ()->query ( $sql );
  28. $result = $query->fetch ();
  29. return $result;
  30. }
  31. function statisticsByCid($year,$cid){
  32. //
  33. $sql = "select sum(rePrice) as rePrice,sum(agPrice) as agPrice from " . $this->_table . " where cid= '".$cid."' and Year(date) =".$year." group by Year(date)" ;
  34. $query = Doo::db ()->query ( $sql );
  35. $result = $query->fetch ();
  36. return $result;
  37. }
  38. /**
  39. * 按员工年月获得报销单汇总信息
  40. * @param string $sid
  41. * @param string $year
  42. * @param string $month
  43. */
  44. function getStatisticsBySid($sid='',$year='',$month=''){
  45. if(empty($sid))
  46. return array();
  47. $stList = $this->getOne ( array (
  48. 'select' => 'sum(rePrice) as rePrice,sum(agPrice) as agPrice',
  49. 'where' => 'staff='.$sid.' and Month(date)=' . $month . " and Year(date)=" . $year,
  50. 'groupby' => 'Month(date)',
  51. 'asArray' => true
  52. ) );
  53. return $stList;
  54. }
  55. }
  56. ?>