mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-07-20 11:52:56 -04:00
Make Summary reports more OOD (#976)
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
require_once("Report.php");
|
||||
|
||||
class Detailed_receivings extends Report
|
||||
{
|
||||
function __construct()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
require_once("Report.php");
|
||||
|
||||
class Detailed_sales extends Report
|
||||
{
|
||||
function __construct()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
require_once("Report.php");
|
||||
|
||||
class Inventory_low extends Report
|
||||
{
|
||||
function __construct()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
require_once("Report.php");
|
||||
|
||||
class Inventory_summary extends Report
|
||||
{
|
||||
function __construct()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
abstract class Report extends CI_Model
|
||||
{
|
||||
function __construct()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
require_once("Report.php");
|
||||
|
||||
class Specific_customer extends Report
|
||||
{
|
||||
function __construct()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
require_once("Report.php");
|
||||
|
||||
class Specific_discount extends Report
|
||||
{
|
||||
function __construct()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
require_once("Report.php");
|
||||
|
||||
class Specific_employee extends Report
|
||||
{
|
||||
function __construct()
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
require_once("Summary_report.php");
|
||||
|
||||
class Summary_categories extends Summary_report
|
||||
{
|
||||
function __construct()
|
||||
@@ -7,30 +9,32 @@ class Summary_categories extends Summary_report
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getDataColumns()
|
||||
protected function _get_data_columns()
|
||||
{
|
||||
return array($this->lang->line('reports_category'), $this->lang->line('reports_quantity'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit'));
|
||||
}
|
||||
|
||||
public function getData(array $inputs)
|
||||
protected function _select(array $inputs)
|
||||
{
|
||||
$this->commonSelect($inputs);
|
||||
parent::_select($inputs);
|
||||
|
||||
$this->db->select('
|
||||
items.category AS category,
|
||||
SUM(sales_items.quantity_purchased) AS quantity_purchased
|
||||
');
|
||||
}
|
||||
|
||||
$this->commonFrom();
|
||||
protected function _from()
|
||||
{
|
||||
parent::_from();
|
||||
|
||||
$this->db->join('items AS items', 'sales_items.item_id = items.item_id', 'inner');
|
||||
}
|
||||
|
||||
$this->commonWhere($inputs);
|
||||
|
||||
protected function _group_order()
|
||||
{
|
||||
$this->db->group_by('category');
|
||||
$this->db->order_by('category');
|
||||
|
||||
return $this->db->get()->result_array();
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
require_once("Summary_report.php");
|
||||
|
||||
class Summary_customers extends Summary_report
|
||||
{
|
||||
function __construct()
|
||||
@@ -7,30 +9,32 @@ class Summary_customers extends Summary_report
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getDataColumns()
|
||||
protected function _get_data_columns()
|
||||
{
|
||||
return array($this->lang->line('reports_customer'), $this->lang->line('reports_quantity'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit'));
|
||||
}
|
||||
|
||||
public function getData(array $inputs)
|
||||
protected function _select(array $inputs)
|
||||
{
|
||||
$this->commonSelect($inputs);
|
||||
parent::_select($inputs);
|
||||
|
||||
$this->db->select('
|
||||
CONCAT(customer_p.first_name, " ", customer_p.last_name) AS customer,
|
||||
SUM(sales_items.quantity_purchased) AS quantity_purchased
|
||||
');
|
||||
}
|
||||
|
||||
$this->commonFrom();
|
||||
protected function _from()
|
||||
{
|
||||
parent::_from();
|
||||
|
||||
$this->db->join('people AS customer_p', 'sales.customer_id = customer_p.person_id');
|
||||
}
|
||||
|
||||
$this->commonWhere($inputs);
|
||||
|
||||
protected function _group_order()
|
||||
{
|
||||
$this->db->group_by('sales.customer_id');
|
||||
$this->db->order_by('customer_p.last_name');
|
||||
|
||||
return $this->db->get()->result_array();
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
require_once("Summary_report.php");
|
||||
|
||||
class Summary_discounts extends Summary_report
|
||||
{
|
||||
function __construct()
|
||||
@@ -7,11 +9,11 @@ class Summary_discounts extends Summary_report
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getDataColumns()
|
||||
protected function _get_data_columns()
|
||||
{
|
||||
return array($this->lang->line('reports_discount_percent'), $this->lang->line('reports_count'));
|
||||
}
|
||||
|
||||
|
||||
public function getData(array $inputs)
|
||||
{
|
||||
$this->db->select('CONCAT(sales_items.discount_percent, "%") AS discount_percent, count(*) AS count');
|
||||
@@ -20,7 +22,7 @@ class Summary_discounts extends Summary_report
|
||||
|
||||
$this->db->where('discount_percent > 0');
|
||||
|
||||
$this->commonWhere($inputs);
|
||||
$this->_where($inputs);
|
||||
|
||||
$this->db->group_by('sales_items.discount_percent');
|
||||
$this->db->order_by('sales_items.discount_percent');
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
require_once("Summary_report.php");
|
||||
|
||||
class Summary_employees extends Summary_report
|
||||
{
|
||||
function __construct()
|
||||
@@ -7,30 +9,32 @@ class Summary_employees extends Summary_report
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getDataColumns()
|
||||
protected function _get_data_columns()
|
||||
{
|
||||
return array($this->lang->line('reports_employee'), $this->lang->line('reports_quantity'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit'));
|
||||
}
|
||||
|
||||
public function getData(array $inputs)
|
||||
|
||||
protected function _select(array $inputs)
|
||||
{
|
||||
$this->commonSelect($inputs);
|
||||
parent::_select($inputs);
|
||||
|
||||
$this->db->select('
|
||||
CONCAT(employee_p.first_name, " ", employee_p.last_name) AS employee,
|
||||
SUM(sales_items.quantity_purchased) AS quantity_purchased
|
||||
');
|
||||
}
|
||||
|
||||
$this->commonFrom();
|
||||
protected function _from()
|
||||
{
|
||||
parent::_from();
|
||||
|
||||
$this->db->join('people AS employee_p', 'sales.employee_id = employee_p.person_id');
|
||||
}
|
||||
|
||||
$this->commonWhere($inputs);
|
||||
|
||||
protected function _group_order()
|
||||
{
|
||||
$this->db->group_by('sales.employee_id');
|
||||
$this->db->order_by('employee_p.last_name');
|
||||
|
||||
return $this->db->get()->result_array();
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
require_once("Summary_report.php");
|
||||
|
||||
class Summary_items extends Summary_report
|
||||
{
|
||||
function __construct()
|
||||
@@ -7,30 +9,32 @@ class Summary_items extends Summary_report
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getDataColumns()
|
||||
protected function _get_data_columns()
|
||||
{
|
||||
return array($this->lang->line('reports_item'), $this->lang->line('reports_quantity'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit'));
|
||||
}
|
||||
|
||||
public function getData(array $inputs)
|
||||
|
||||
protected function _select(array $inputs)
|
||||
{
|
||||
$this->commonSelect($inputs);
|
||||
parent::_select($inputs);
|
||||
|
||||
$this->db->select('
|
||||
items.name AS name,
|
||||
SUM(sales_items.quantity_purchased) AS quantity_purchased
|
||||
');
|
||||
}
|
||||
|
||||
$this->commonFrom();
|
||||
protected function _from()
|
||||
{
|
||||
parent::_from();
|
||||
|
||||
$this->db->join('items AS items', 'sales_items.item_id = items.item_id', 'inner');
|
||||
}
|
||||
|
||||
$this->commonWhere($inputs);
|
||||
|
||||
protected function _group_order()
|
||||
{
|
||||
$this->db->group_by('items.item_id');
|
||||
$this->db->order_by('items.name');
|
||||
|
||||
return $this->db->get()->result_array();
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
require_once("Summary_report.php");
|
||||
|
||||
class Summary_payments extends Summary_report
|
||||
{
|
||||
function __construct()
|
||||
@@ -7,7 +9,7 @@ class Summary_payments extends Summary_report
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getDataColumns()
|
||||
protected function _get_data_columns()
|
||||
{
|
||||
return array($this->lang->line('reports_payment_type'), $this->lang->line('reports_count'), $this->lang->line('sales_amount_tendered'));
|
||||
}
|
||||
@@ -18,7 +20,7 @@ class Summary_payments extends Summary_report
|
||||
$this->db->from('sales_payments');
|
||||
$this->db->join('sales AS sales', 'sales.sale_id = sales_payments.sale_id');
|
||||
|
||||
$this->commonWhere($inputs);
|
||||
$this->_where($inputs);
|
||||
|
||||
$this->db->group_by("payment_type");
|
||||
|
||||
@@ -39,7 +41,7 @@ class Summary_payments extends Summary_report
|
||||
}
|
||||
}
|
||||
|
||||
if( $gift_card_count > 0 )
|
||||
if($gift_card_count > 0)
|
||||
{
|
||||
$payments[] = array('payment_type' => $this->lang->line('sales_giftcard'), 'count' => $gift_card_count, 'payment_amount' => $gift_card_amount);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
require_once("Report.php");
|
||||
|
||||
abstract class Summary_report extends Report
|
||||
{
|
||||
function __construct()
|
||||
@@ -7,9 +9,15 @@ abstract class Summary_report extends Report
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
protected function commonSelect(array $inputs)
|
||||
/*
|
||||
|
||||
Private interface
|
||||
|
||||
*/
|
||||
|
||||
private function _common_select(array $inputs)
|
||||
{
|
||||
// create a temporary table to contain all the payment types and amount
|
||||
// create a temporary table to contain all the sum of taxes per sale item
|
||||
$this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->dbprefix('sales_items_taxes_temp') .
|
||||
' (INDEX(sale_id), INDEX(item_id))
|
||||
(
|
||||
@@ -52,14 +60,14 @@ abstract class Summary_report extends Report
|
||||
");
|
||||
}
|
||||
|
||||
protected function commonFrom()
|
||||
private function _common_from()
|
||||
{
|
||||
$this->db->from('sales_items AS sales_items');
|
||||
$this->db->join('sales AS sales', 'sales_items.sale_id = sales.sale_id', 'inner');
|
||||
$this->db->join('sales_items_taxes_temp AS sales_items_taxes', 'sales_items.sale_id = sales_items_taxes.sale_id AND sales_items.item_id = sales_items_taxes.item_id', 'left outer');
|
||||
}
|
||||
|
||||
protected function commonWhere(array $inputs)
|
||||
private function _common_where(array $inputs)
|
||||
{
|
||||
$this->db->where('DATE(sales.sale_time) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date']));
|
||||
|
||||
@@ -78,13 +86,50 @@ abstract class Summary_report extends Report
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Protected class interface implemented by derived classes
|
||||
|
||||
*/
|
||||
|
||||
abstract protected function _get_data_columns();
|
||||
|
||||
protected function _select(array $inputs) { $this->_common_select($inputs); }
|
||||
protected function _from() { $this->_common_from(); }
|
||||
protected function _where(array $inputs) { $this->_common_where($inputs); }
|
||||
protected function _group_order() {}
|
||||
|
||||
/*
|
||||
|
||||
Public interface implementing the base abstract class, in general it should not be extended unless there is a valid reason
|
||||
|
||||
*/
|
||||
|
||||
public function getDataColumns()
|
||||
{
|
||||
return $this->_get_data_columns();
|
||||
}
|
||||
|
||||
public function getData(array $inputs)
|
||||
{
|
||||
$this->_select($inputs);
|
||||
|
||||
$this->_from();
|
||||
|
||||
$this->_where($inputs);
|
||||
|
||||
$this->_group_order();
|
||||
|
||||
return $this->db->get()->result_array();
|
||||
}
|
||||
|
||||
public function getSummaryData(array $inputs)
|
||||
{
|
||||
$this->commonSelect($inputs);
|
||||
$this->_common_select($inputs);
|
||||
|
||||
$this->commonFrom();
|
||||
$this->_common_from();
|
||||
|
||||
$this->commonWhere($inputs);
|
||||
$this->_common_where($inputs);
|
||||
|
||||
return $this->db->get()->row_array();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
require_once("Summary_report.php");
|
||||
|
||||
class Summary_sales extends Summary_report
|
||||
{
|
||||
function __construct()
|
||||
@@ -7,28 +9,25 @@ class Summary_sales extends Summary_report
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getDataColumns()
|
||||
protected function _get_data_columns()
|
||||
{
|
||||
return array($this->lang->line('reports_date'), $this->lang->line('reports_quantity'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit'));
|
||||
}
|
||||
|
||||
public function getData(array $inputs)
|
||||
protected function _select(array $inputs)
|
||||
{
|
||||
$this->commonSelect($inputs);
|
||||
parent::_select($inputs);
|
||||
|
||||
$this->db->select('
|
||||
DATE(sales.sale_time) AS sale_date,
|
||||
SUM(sales_items.quantity_purchased) AS quantity_purchased
|
||||
');
|
||||
|
||||
$this->commonFrom();
|
||||
|
||||
$this->commonWhere($inputs);
|
||||
|
||||
}
|
||||
|
||||
protected function _group_order()
|
||||
{
|
||||
$this->db->group_by('sale_date');
|
||||
$this->db->order_by('sale_date');
|
||||
|
||||
return $this->db->get()->result_array();
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
require_once("Summary_report.php");
|
||||
|
||||
class Summary_suppliers extends Summary_report
|
||||
{
|
||||
function __construct()
|
||||
@@ -7,32 +9,34 @@ class Summary_suppliers extends Summary_report
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getDataColumns()
|
||||
protected function _get_data_columns()
|
||||
{
|
||||
return array($this->lang->line('reports_supplier'), $this->lang->line('reports_quantity'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'), $this->lang->line('reports_cost'), $this->lang->line('reports_profit'));
|
||||
}
|
||||
|
||||
public function getData(array $inputs)
|
||||
protected function _select(array $inputs)
|
||||
{
|
||||
$this->commonSelect($inputs);
|
||||
parent::_select($inputs);
|
||||
|
||||
$this->db->select('
|
||||
CONCAT(supplier_c.company_name, " (", supplier_p.first_name, " ", supplier_p.last_name, ")") AS supplier,
|
||||
SUM(sales_items.quantity_purchased) AS quantity_purchased
|
||||
');
|
||||
}
|
||||
|
||||
$this->commonFrom();
|
||||
protected function _from()
|
||||
{
|
||||
parent::_from();
|
||||
|
||||
$this->db->join('items AS items', 'sales_items.item_id = items.item_id', 'inner');
|
||||
$this->db->join('suppliers AS supplier_c', 'supplier_c.person_id = items.supplier_id');
|
||||
$this->db->join('people AS supplier_p', 'supplier_c.person_id = supplier_p.person_id');
|
||||
}
|
||||
|
||||
$this->commonWhere($inputs);
|
||||
|
||||
protected function _group_order()
|
||||
{
|
||||
$this->db->group_by('items.supplier_id');
|
||||
$this->db->order_by('supplier_p.last_name');
|
||||
|
||||
return $this->db->get()->result_array();
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,5 +1,7 @@
|
||||
<?php
|
||||
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
||||
|
||||
require_once("Summary_report.php");
|
||||
|
||||
class Summary_taxes extends Summary_report
|
||||
{
|
||||
function __construct()
|
||||
@@ -7,7 +9,7 @@ class Summary_taxes extends Summary_report
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
public function getDataColumns()
|
||||
protected function _get_data_columns()
|
||||
{
|
||||
return array($this->lang->line('reports_tax_percent'), $this->lang->line('reports_count'), $this->lang->line('reports_subtotal'), $this->lang->line('reports_total'), $this->lang->line('reports_tax'));
|
||||
}
|
||||
@@ -15,16 +17,17 @@ class Summary_taxes extends Summary_report
|
||||
public function getData(array $inputs)
|
||||
{
|
||||
$quantity_cond = '';
|
||||
if ($inputs['sale_type'] == 'sales')
|
||||
|
||||
if($inputs['sale_type'] == 'sales')
|
||||
{
|
||||
$quantity_cond = 'AND quantity_purchased > 0';
|
||||
}
|
||||
elseif ($inputs['sale_type'] == 'returns')
|
||||
elseif($inputs['sale_type'] == 'returns')
|
||||
{
|
||||
$quantity_cond = 'AND quantity_purchased < 0';
|
||||
}
|
||||
|
||||
if ($inputs['location_id'] != 'all')
|
||||
if($inputs['location_id'] != 'all')
|
||||
{
|
||||
$quantity_cond .= 'AND item_location = '. $this->db->escape($inputs['location_id']);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user