|
<?php defined('SYSPATH') or die('No direct script access.');
|
|
/*
|
|
* This file is part of open source system FreeNetIS
|
|
* and it is release under GPLv3 licence.
|
|
*
|
|
* More info about licence can be found:
|
|
* http://www.gnu.org/licenses/gpl-3.0.html
|
|
*
|
|
* More info about project can be found:
|
|
* http://www.freenetis.org/
|
|
*
|
|
*/
|
|
|
|
/**
|
|
* @package Model
|
|
*/
|
|
class Bank_statement_Model extends ORM
|
|
{
|
|
protected $belongs_to = array("bank_account", "user");
|
|
protected $has_many = array("bank_transfers");
|
|
|
|
/**
|
|
* Contruct of app, shutdown action logs by default
|
|
* @param type $id
|
|
*/
|
|
public function __construct($id = NULL)
|
|
{
|
|
parent::__construct($id);
|
|
|
|
// disable action log
|
|
$this->set_logger(FALSE);
|
|
}
|
|
|
|
/**
|
|
* Counts bank statements of given bank account.
|
|
* @author Jiri Svitak
|
|
* @param $ba_id
|
|
* @param $filter_values
|
|
* @return integer
|
|
*/
|
|
public function count_bank_statements($ba_id, $filter_values = array())
|
|
{
|
|
return $this->db->query("
|
|
SELECT COUNT(*) AS total
|
|
FROM bank_statements
|
|
WHERE bank_account_id = ?
|
|
", array($ba_id))->current()->total;
|
|
}
|
|
|
|
/**
|
|
* Gets bank statements of given bank account.
|
|
* @author Jiri Svitak
|
|
* @param $ba_id
|
|
* @param $limit_from
|
|
* @param $limit_results
|
|
* @param $order_by
|
|
* @param $order_by_direction
|
|
* @param $filter_values
|
|
* @return unknown_type
|
|
*/
|
|
public function get_bank_statements(
|
|
$ba_id = null, $limit_from = 0, $limit_results = 20, $order_by = 'id',
|
|
$order_by_direction = 'DESC', $filter_values = array())
|
|
{
|
|
// order by direction check
|
|
if (strtolower($order_by_direction) != 'desc')
|
|
{
|
|
$order_by_direction = 'asc';
|
|
}
|
|
// query
|
|
return $this->db->query("
|
|
SELECT * FROM bank_statements
|
|
WHERE bank_account_id = ?
|
|
ORDER BY ".$this->db->escape_column($order_by)." $order_by_direction
|
|
LIMIT " . intval($limit_from) . ", " . intval($limit_results) . "
|
|
", array($ba_id));
|
|
}
|
|
}
|