コード例 #1
0
 public function __construct($id = 0, $data = NULL)
 {
     database_helper::database_helper(NULL, 'decline_price_gifts');
     if (!empty($data)) {
         $this->data = $data;
     } elseif (!empty($id)) {
         $this->load_data($id);
     }
     $this->_gifts2partners = $this->_get_table_name('gifts2partners');
 }
コード例 #2
0
 public function parse_filter($filter = array(), &$join = '', &$join_select = '')
 {
     $where = parent::parse_filter($filter, $join, $join_select);
     //$join_select = ", SUM(`operation_sum` < 0) AS expenses, SUM(`operation_sum` > 0) AS amount_income";
     if (isset($filter['dt_start']) && isset($filter['dt_finish'])) {
         $date_start = Zend_Registry::get('target')->db->escape($filter['dt_start']);
         $date_finish = Zend_Registry::get('target')->db->escape($filter['dt_finish']);
         $where .= " AND `date` >= '{$date_start}' AND `date` <= '{$date_finish}' ";
     }
     if (isset($filter['type'])) {
         //0 - расход, 1 - доход
         if (empty($filter['type'])) {
             $where .= " AND `operation_sum` < 0 ";
         } else {
             $where .= " AND `operation_sum` > 0 ";
         }
     }
     if (isset($filter['fin_category_id'])) {
         // Общие части выносим из под if
         $join_select = ", fin_cat.`category_name`";
         $join = "LEFT JOIN {$this->_financial_cat} as fin_cat ON fin_cat.`id` = {$this->table}.`fin_category_id`";
         if (!empty($filter['fin_category_id'])) {
             $fin_category_id = (int) $filter['fin_category_id'];
             $where .= " AND {$this->table}.`fin_category_id` = {$fin_category_id}";
         }
     }
     if (isset($filter['user_id']) && $filter['user_id'] != '') {
         $user_id = (int) $filter['user_id'];
         $where .= " AND {$this->table}.`user_id` = {$user_id}";
     }
     if (!empty($filter['user_name'])) {
         $join_select .= ", user.`name`";
         $join .= "LEFT JOIN {$this->_get_table_name('users')} as user ON user.`id` = {$this->table}.`user_id`";
     }
     if (!empty($filter['by_categories'])) {
         $join_select .= ", SUM({$this->table}.`operation_sum`) AS sum, fin_cat.`type`";
         $where .= " GROUP BY {$this->table}.`fin_category_id`";
     }
     return $where;
 }