mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-04-02 14:24:27 -04:00
- Added TODO where we need to convert to querybuilder - Converted to switch statement. - Removed unnecessary local variable - Replaced Qualifiers with imports - Replaced isset() call with null coalescing operator - Replaced strpos function calls in if statements with str_contains calls - Removed unnecessary leading \ in use statement - Replaced deprecated functions - Updated PHPdocs to match function signature - Added missing type declarations - Made class variables private. - Explicitly declared dynamic properties - use https:// links instead of http:// - Fixed type error from sending null when editing transactions - Fixed Search Suggestion function name in Employees, Persons, Suppliers controller - Fixed function name on Receivings Controller Signed-off-by: objecttothis <objecttothis@gmail.com>
52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Models\Reports;
|
|
|
|
use Config\OSPOS;
|
|
|
|
class Summary_discounts extends Summary_report
|
|
{
|
|
/**
|
|
* @return array[]
|
|
*/
|
|
protected function _get_data_columns(): array //TODO: Hungarian notation
|
|
{
|
|
return [
|
|
['discount' => lang('Reports.discount'), 'sorter' => 'number_sorter'],
|
|
['count' => lang('Reports.count')],
|
|
['total' => lang('Reports.total')]
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @param array $inputs
|
|
* @return array
|
|
*/
|
|
public function getData(array $inputs): array
|
|
{
|
|
$config = config(OSPOS::class)->settings;
|
|
$builder = $this->db->table('sales_items AS sales_items');
|
|
|
|
if($inputs['discount_type'] == FIXED)
|
|
{
|
|
$builder->select('SUM(sales_items.discount) AS total, MAX(CONCAT("' . $config['currency_symbol'] . '",sales_items.discount)) AS discount, count(*) AS count');
|
|
$builder->where('discount_type', FIXED);
|
|
}
|
|
elseif($inputs['discount_type'] == PERCENT) //TODO: === ?
|
|
{
|
|
$builder->select('SUM(item_unit_price) * sales_items.discount / 100.0 AS total, MAX(CONCAT(sales_items.discount, "%")) AS discount, count(*) AS count');
|
|
$builder->where('discount_type', PERCENT);
|
|
}
|
|
|
|
$builder->where('discount >', 0);
|
|
$builder->groupBy('sales_items.discount');
|
|
$builder->orderBy('sales_items.discount');
|
|
|
|
$builder->join('sales AS sales', 'sales_items.sale_id = sales.sale_id', 'inner');
|
|
|
|
$this->_where($inputs, $builder); //TODO: Hungarian notation
|
|
|
|
return $builder->get()->getResultArray();
|
|
}
|
|
}
|