123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270 |
- <?php
- Doo::loadCore ( 'db/DooModel' );
- class invoiceStatistics extends DooModel {
- public $sid;
- public $priceClass;
- public $date;
- public $cid;
- public $staff;
- public $invoicePrice;
- public $accountPrice;
- public $receivablesPrice;
- public $irid;
- public $_table = 'CLD_invoiceStatistics';
- public $_primarykey = 'sid';
- public $_fields = array (
- 'sid',
- 'staff',
- 'priceClass',
- 'invoicePrice',
- 'receivablesPrice',
- 'accountPrice',
- 'date',
- 'cid',
- 'irid'
- );
-
- /**
- * 根据参数字段更新相应字段(主键ID必须传)
- * @param array $item 相关需要更新的字段信息
- * @return number 返回发票ID
- */
- public function setInvoiceStatisticsByCondition($item = array()) {
- $lid = 0;
- if (is_array ( $item ) && ! empty ( $item )) {
- foreach ( $item as $key => $value ) {
- $this->$key = $value;
- }
- $lid = $this->insert ();
- }
- return $lid;
- }
-
- /**
- * 根据参数字段更新相应字段(主键ID必须传)
- * @param array $item 相关需要更新的字段信息
- * @return number 返回发票ID
- */
- public function updateInvoiceStatisticsByIrid($item = array(), $irid = 0,$priceClass=0) {
- if (is_numeric ( $irid ) && is_array ( $item ) && ! empty ( $item )) {
- foreach ( $item as $key => $value ) {
- $this->$key = $value;
- }
- $sql="";
- if (!empty($priceClass))
- $sql=" and priceClass=".$priceClass;
- $lid = $this->update ( array (
- 'where' => 'irid=' . $irid .$sql
- ) );
- }
- return $lid;
- }
-
- /**
- * 根据发票ID和绑定状态获得收款数据,绑定状态为ALL获取所有状态数据
- * @param string $iid 发票ID
- * @param string $bindStatus
- * @return mixed
- */
- public function getInvoiceStatisticsByYear($year = "", $cid = "0") {
- $list = array ();
- $sql = '';
- if (empty ( $year ))
- $year = date ( "Y" );
- if ($cid != 0)
- $sql = " and cid=" . $cid;
-
- $list ['statisticsMonthCid'] = $this->find ( array (
- 'select' => 'cid,sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
- 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
- 'groupby' => 'cid,Month(date)',
- 'asArray' => TRUE
- ) );
-
- $list ['statisticsYear'] = $this->find ( array (
- 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Year(date) as Year',
- 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
- 'groupby' => 'Year(date)',
- 'asArray' => TRUE
- ) );
-
- if (empty ( $list ['statisticsYear'] )) {
- $list ['statisticsYear'] [0] ['invoicePrice'] = 0;
- $list ['statisticsYear'] [0] ['receivablesPrice'] = 0;
- $list ['statisticsYear'] [0] ['accountPrice'] = 0;
- }
-
- $list ['statisticsMonth'] = $this->find ( array (
- 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
- 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
- 'groupby' => 'Month(date)',
- 'asArray' => TRUE
- ) );
-
- return $list;
- }
-
- /**
- * 获取用户的统计信息
- * @param string $year
- * @param string $cid
- * @return NULL[]
- */
- public function getInvoiceStatisticsByStaff($year = "", $cid = "0") {
- $list = array ();
- $sql = '';
- if (empty ( $year ))
- $year = date ( "Y" );
- if ($cid != 0)
- $sql = " and cid=" . $cid;
-
- $list ['statisticsMonthCid'] = $this->find ( array (
- 'select' => 'cid,sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
- 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
- 'groupby' => 'cid,Month(date)',
- 'asArray' => TRUE
- ) );
-
- $list ['statisticsMonthStaff'] = $this->find ( array (
- 'select' => 'cid,staff,sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
- 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
- 'groupby' => 'staff,Month(date)',
- 'asArray' => TRUE
- ) );
-
- $list ['statisticsMonth'] = $this->find ( array (
- 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
- 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
- 'groupby' => 'Month(date)',
- 'asArray' => TRUE
- ) );
-
- return $list;
- }
- public function getInvoiceStatisticsByCategory($year = "", $cid = "0") {
- $list = array ();
- $sql = '';
- if (empty ( $year ))
- $year = date ( "Y" );
- if ($cid != 0)
- $sql = " and cid=" . $cid;
-
- $list ['statisticsMonthCid'] = $this->find ( array (
- 'select' => 'cid,sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
- 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
- 'groupby' => 'cid,Month(date)',
- 'asArray' => TRUE
- ) );
-
- $list ['statisticsMonthStaff'] = $this->find ( array (
- 'select' => 'cid,staff,sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
- 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
- 'groupby' => 'staff,Month(date)',
- 'asArray' => TRUE
- ) );
-
- $list ['statisticsMonth'] = $this->find ( array (
- 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
- 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . $sql,
- 'groupby' => 'Month(date)',
- 'asArray' => TRUE
- ) );
-
- return $list;
- }
-
- /**
- * 获取某年的汇总金额
- * @param string $year
- * @param string $cid
- * @return NULL[]
- */
- public function getInvoiceStatisticsByTote($year = "", $cid = "0") {
- $list = array ();
- $sql = '';
- if (empty ( $year ))
- $year = date ( "Y" );
- if ($cid != 0)
- $sql = " and cid=" . $cid;
- $list ['statisticsYear'] = $this->find ( array (
- 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Year(date) as Year',
- 'where' => " Year(date) =" . $year . $sql,
- 'groupby' => 'Year(date)',
- 'asArray' => TRUE
- ) );
-
- if (empty ( $list ['statisticsYear'] )) {
- $list ['statisticsYear'] [0] ['invoicePrice'] = 0;
- $list ['statisticsYear'] [0] ['receivablesPrice'] = 0;
- $list ['statisticsYear'] [0] ['accountPrice'] = 0;
- }
-
- return $list;
- }
- public function getStatisticsByMonth() {
- $month = date ( "m" );
- $year = date ( "Y" );
- $list ['statisticsMonth'] = $this->find ( array (
- 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
- 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . " and Month(date)=" . $month,
- 'groupby' => 'Month(date)',
- 'asArray' => TRUE
- ) );
- if (empty ( $list ['statisticsMonth'] )) {
- $list ['statisticsMonth'] [0] ['invoicePrice'] = 0;
- $list ['statisticsMonth'] [0] ['receivablesPrice'] = 0;
- $list ['statisticsMonth'] [0] ['accountPrice'] = 0;
- $list ['statisticsMonth'] [0] ['month'] = $month;
- }
- $list ['statisticsYear'] = $this->find ( array (
- 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Year(date) as Year',
- 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year,
- 'groupby' => 'Year(date)',
- 'asArray' => TRUE
- ) );
- if (empty ( $list ['statisticsYear'] )) {
- $list ['statisticsYear'] [0] ['invoicePrice'] = 0;
- $list ['statisticsYear'] [0] ['receivablesPrice'] = 0;
- $list ['statisticsYear'] [0] ['accountPrice'] = 0;
- $list ['statisticsYear'] [0] ['month'] = $month;
- }
- return $list;
- }
- public function getBrieflyStatistics() {
- $year = date ( "Y" );
- $month = date ( "m" );
-
- $tmp_date = date ( "Ym" );
- $tmp_year = substr ( $tmp_date, 0, 4 );
- $tmp_mon = substr ( $tmp_date, 4, 2 );
- $tmp_forwardmonth = mktime ( 0, 0, 0, $tmp_mon - 1, 1, $tmp_year );
- $fm_forward_month = date ( "m", $tmp_forwardmonth );
-
- $list ['statisticsMonth'] = $this->find ( array (
- 'select' => 'sum(invoicePrice) as invoicePrice,sum(receivablesPrice) as receivablesPrice,sum(accountPrice) as accountPrice,Month(date) as month',
- 'where' => " cid!=0 and staff!=0 and Year(date) =" . $year . " and Month(date)=" . $fm_forward_month,
- 'groupby' => 'Month(date)',
- 'asArray' => TRUE
- ) );
- if (empty ( $list ['statisticsMonth'] )) {
- $list ['statisticsMonth'] [0] ['invoicePrice'] = 0;
- $list ['statisticsMonth'] [0] ['receivablesPrice'] = 0;
- $list ['statisticsMonth'] [0] ['accountPrice'] = 0;
- $list ['statisticsMonth'] [0] ['month'] = $fm_forward_month;
- }
-
- return $list;
- }
- public function getInvoiceStatisticsByCondition($condition = '') {
- if (empty ( $condition ))
- return array ();
-
- $list = $this->find ( array (
- 'where' => $condition,
- 'asArray' => TRUE
- ) );
- return $list;
- }
- }
- ?>
|