From 8d80f5a2616dfdd27b4bfb911935abbaf9d60df2 Mon Sep 17 00:00:00 2001 From: objecttothis Date: Wed, 1 Mar 2023 01:41:43 +0400 Subject: [PATCH] CI4 bugfixes - Added session variable instantiation where needed. - Added tabular helper to autoload - removed tabular helper reference where no longer needed. - Remove esc() references where it was causing display problems. - Remove excess whitespace on blank line - Remove unecessary using reference - Make parameters for dinner table functions nullable --- app/Config/Autoload.php | 3 +- app/Controllers/Attributes.php | 5 ++-- app/Controllers/Customers.php | 1 - app/Controllers/Expenses.php | 1 - app/Controllers/Expenses_categories.php | 1 - app/Controllers/Giftcards.php | 1 - app/Controllers/Item_kits.php | 19 ++++++------- app/Controllers/Items.php | 1 - app/Controllers/Persons.php | 1 - app/Controllers/Sales.php | 6 ++-- app/Libraries/Sale_lib.php | 15 +++++----- app/Models/Dinner_table.php | 2 +- app/Models/Reports/Report.php | 2 +- app/Views/configs/info_config.php | 37 +++++++++++++------------ 14 files changed, 45 insertions(+), 50 deletions(-) diff --git a/app/Config/Autoload.php b/app/Config/Autoload.php index 86e0d8404..21edc26ec 100644 --- a/app/Config/Autoload.php +++ b/app/Config/Autoload.php @@ -204,6 +204,7 @@ class Autoload extends AutoloadConfig */ public $helpers = [ 'form', - 'cookie' + 'cookie', + 'tabular' ]; } diff --git a/app/Controllers/Attributes.php b/app/Controllers/Attributes.php index 09a659e0b..23805a11f 100644 --- a/app/Controllers/Attributes.php +++ b/app/Controllers/Attributes.php @@ -8,9 +8,9 @@ require_once('Secure_Controller.php'); /** * Attributes controls the custom attributes assigned to items - * + * * @property attribute attribute - * + * */ class Attributes extends Secure_Controller { @@ -23,7 +23,6 @@ class Attributes extends Secure_Controller public function getIndex(): void { - helper('tabular'); $data['table_headers'] = get_attribute_definition_manage_table_headers(); echo view('attributes/manage', $data); diff --git a/app/Controllers/Customers.php b/app/Controllers/Customers.php index b450a6eb9..b23712897 100644 --- a/app/Controllers/Customers.php +++ b/app/Controllers/Customers.php @@ -34,7 +34,6 @@ class Customers extends Persons public function __construct() { parent::__construct('customers'); - helper('tabular'); $this->mailchimp_lib = new Mailchimp_lib(); $this->customer = model('Customer'); diff --git a/app/Controllers/Expenses.php b/app/Controllers/Expenses.php index bece410a2..66618d385 100644 --- a/app/Controllers/Expenses.php +++ b/app/Controllers/Expenses.php @@ -21,7 +21,6 @@ class Expenses extends Secure_Controller public function getIndex(): void { - helper('tabular'); $data['table_headers'] = get_expenses_manage_table_headers(); // filters that will be loaded in the multiselect dropdown diff --git a/app/Controllers/Expenses_categories.php b/app/Controllers/Expenses_categories.php index dffbc1b75..2a710b8bb 100644 --- a/app/Controllers/Expenses_categories.php +++ b/app/Controllers/Expenses_categories.php @@ -18,7 +18,6 @@ class Expenses_categories extends Secure_Controller //TODO: Is this class ever u public function getIndex(): void { - helper('tabular'); $data['table_headers'] = get_expense_category_manage_table_headers(); echo view('expenses_categories/manage', $data); diff --git a/app/Controllers/Giftcards.php b/app/Controllers/Giftcards.php index 220b91354..bc85a7af7 100644 --- a/app/Controllers/Giftcards.php +++ b/app/Controllers/Giftcards.php @@ -18,7 +18,6 @@ class Giftcards extends Secure_Controller public function getIndex(): void { - helper('tabular'); $data['table_headers'] = get_giftcards_manage_table_headers(); echo view('giftcards/manage', $data); diff --git a/app/Controllers/Item_kits.php b/app/Controllers/Item_kits.php index 0242f471d..8535ce184 100644 --- a/app/Controllers/Item_kits.php +++ b/app/Controllers/Item_kits.php @@ -28,7 +28,7 @@ class Item_kits extends Secure_Controller $this->item_kit = model('Item_kit'); $this->item_kit_items = model('Item_kit_items'); } - + /** * Add the total cost and retail price to a passed item_kit retrieving the data from each singular item part of the kit */ @@ -63,10 +63,9 @@ class Item_kits extends Secure_Controller return $item_kit; } - + public function getIndex(): void { - helper('tabular'); $data['table_headers'] = get_item_kits_manage_table_headers(); echo view('item_kits/manage', $data); @@ -111,7 +110,7 @@ class Item_kits extends Secure_Controller echo json_encode(get_item_kit_data_row($item_kit)); } - + public function view(int $item_kit_id = -1): void //TODO: Replace -1 with a constant { $info = $this->item_kit->get_info($item_kit_id); @@ -150,7 +149,7 @@ class Item_kits extends Secure_Controller echo view("item_kits/form", $data); } - + public function save(int $item_kit_id = -1): void //TODO: Replace -1 with a constant { $item_kit_data = [ @@ -163,7 +162,7 @@ class Item_kits extends Secure_Controller 'print_option' => $this->request->getPost('print_option', FILTER_SANITIZE_NUMBER_INT), 'description' => $this->request->getPost('description', FILTER_SANITIZE_STRING) ]; - + if($this->item_kit->save_value($item_kit_data, $item_kit_id)) { $new_item = FALSE; @@ -218,7 +217,7 @@ class Item_kits extends Secure_Controller ]); } } - + public function delete(): void { $item_kits_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_STRING); @@ -241,7 +240,7 @@ class Item_kits extends Secure_Controller $exists = $this->item_kit->item_number_exists($this->request->getPost('item_kit_number', FILTER_SANITIZE_STRING), $this->request->getPost('item_kit_id', FILTER_SANITIZE_NUMBER_INT)); echo !$exists ? 'true' : 'false'; } - + public function generate_barcodes(string $item_kit_ids): void { $this->barcode_lib = new Barcode_lib(); @@ -249,10 +248,10 @@ class Item_kits extends Secure_Controller $item_kit_ids = explode(':', $item_kit_ids); foreach($item_kit_ids as $item_kid_id) - { + { // calculate the total cost and retail price of the Kit, so it can be added to the barcode text at the bottom $item_kit = $this->_add_totals_to_item_kit($this->item_kit->get_info($item_kid_id)); - + $item_kid_id = 'KIT '. urldecode($item_kid_id); $result[] = [ diff --git a/app/Controllers/Items.php b/app/Controllers/Items.php index c81109c2c..6f0785ef8 100644 --- a/app/Controllers/Items.php +++ b/app/Controllers/Items.php @@ -62,7 +62,6 @@ class Items extends Secure_Controller public function getIndex(): void { - helper('tabular'); $this->session->set('allow_temp_items', 0); $data['table_headers'] = get_items_manage_table_headers(); diff --git a/app/Controllers/Persons.php b/app/Controllers/Persons.php index 7b5934e83..d13070b4b 100644 --- a/app/Controllers/Persons.php +++ b/app/Controllers/Persons.php @@ -18,7 +18,6 @@ abstract class Persons extends Secure_Controller public function getIndex(): void { - helper('tabular'); $data['table_headers'] = get_people_manage_table_headers(); echo view('people/manage', $data); diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php index 338f8925e..3d0d8548d 100644 --- a/app/Controllers/Sales.php +++ b/app/Controllers/Sales.php @@ -49,12 +49,14 @@ class Sales extends Secure_Controller helper('file'); + $this->session = session(); $this->barcode_lib = new Barcode_lib(); $this->email_lib = new Email_lib(); $this->sale_lib = new Sale_lib(); $this->tax_lib = new Tax_lib(); $this->token_lib = new Token_lib(); $this->config = config('OSPOS')->settings; + $this->stock_location = model('Stock_location'); } public function getIndex(): void @@ -570,7 +572,7 @@ class Sales extends Secure_Controller if(!$this->validate([])) { $this->sale_lib->edit_item($line, $description, $serialnumber, $quantity, $discount, $discount_type, $price, $discounted_total); - + $this->sale_lib->empty_payments(); } else @@ -1286,7 +1288,7 @@ class Sales extends Secure_Controller $data['selected_employee_name'] = $employee_info->first_name . ' ' . $employee_info->last_name; $data['sale_info'] = $sale_info; $balance_due = round($sale_info['amount_due'] - $sale_info['amount_tendered'] + $sale_info['cash_refund'], totals_decimals(), PHP_ROUND_HALF_UP); - + if(!$this->sale_lib->reset_cash_rounding() && $balance_due < 0) { $balance_due = 0; diff --git a/app/Libraries/Sale_lib.php b/app/Libraries/Sale_lib.php index 825c16e56..d2a6102f5 100644 --- a/app/Libraries/Sale_lib.php +++ b/app/Libraries/Sale_lib.php @@ -14,7 +14,6 @@ use App\Models\Sale; use CodeIgniter\Session\Session; use App\Models\Stock_location; use ReflectionException; -use App\Libraries\Tax_lib; /** * Sale library @@ -39,7 +38,7 @@ class Sale_lib { public function __construct() { - $this->session = Session(); + $this->session = session(); $this->attribute = model('Attribute'); $this->customer = model('Customer'); @@ -700,10 +699,10 @@ class Sale_lib public function get_mode(): string { - if(!$this->session->get('sales_mode')) - { - $this->set_mode('sale'); - } + if(!$this->session->get('sales_mode')) + { + $this->set_mode('sale'); + } return $this->session->get('sales_mode'); } @@ -717,7 +716,7 @@ class Sale_lib $this->session->remove('sales_mode'); } - public function get_dinner_table(): int + public function get_dinner_table(): ?int { if(!$this->session->get('dinner_table')) { @@ -1441,7 +1440,7 @@ class Sale_lib return $total; } - public function get_empty_tables(int $current_dinner_table_id): array + public function get_empty_tables(?int $current_dinner_table_id): array { return $this->dinner_table->get_empty_tables($current_dinner_table_id); } diff --git a/app/Models/Dinner_table.php b/app/Models/Dinner_table.php index 5715cf28e..207156c1f 100644 --- a/app/Models/Dinner_table.php +++ b/app/Models/Dinner_table.php @@ -46,7 +46,7 @@ class Dinner_table extends Model /** * Get empty tables */ - public function get_empty_tables(int $current_dinner_table_id): array + public function get_empty_tables(?int $current_dinner_table_id): array { $builder = $this->db->table('dinner_tables'); $builder->where('status', 0); diff --git a/app/Models/Reports/Report.php b/app/Models/Reports/Report.php index 898bc4ffa..b7362a17e 100644 --- a/app/Models/Reports/Report.php +++ b/app/Models/Reports/Report.php @@ -32,4 +32,4 @@ abstract class Report extends Model // Returns key=>value pairing of summary data for the report public abstract function getSummaryData(array $inputs): array; -} \ No newline at end of file +} diff --git a/app/Views/configs/info_config.php b/app/Views/configs/info_config.php index 9f0e9dc96..6befe732a 100644 --- a/app/Views/configs/info_config.php +++ b/app/Views/configs/info_config.php @@ -2,6 +2,7 @@ /** * @var bool $logo_exists * @var string $controller_name + * @var array $config */ ?> 'info_config_form', 'enctype' => 'multipart/form-data', 'class' => 'form-horizontal']) ?> @@ -10,7 +11,7 @@
-
+
'control-label col-xs-2 required']) ?>
@@ -19,20 +20,20 @@ 'name' => 'company', 'id' => 'company', 'class' => 'form-control input-sm required', - 'value' => esc($config['company'], 'attr') + 'value' => $config['company'] ]) ?>
-
+
'control-label col-xs-2']) ?>
<?php echo lang('Config.company_logo') ?>
@@ -47,19 +48,19 @@
-
+
'control-label col-xs-2 required']) ?>
'address', 'id' => 'address', 'class' => 'form-control input-sm required', - 'value'=> esc($config['address'], 'attr') + 'value'=> $config['address'], 'attr' ]) ?>
-
+
'control-label col-xs-2']) ?>
@@ -68,13 +69,13 @@ 'name' => 'website', 'id' => 'website', 'class' => 'form-control input-sm', - 'value'=> esc($config['website'], 'url') + 'value'=> $config['website'] ]) ?>
-
+
'control-label col-xs-2']) ?>
@@ -84,13 +85,13 @@ 'id' => 'email', 'type' => 'email', 'class' => 'form-control input-sm', - 'value'=> esc($config['email'], 'attr') + 'value'=> $config['email'] ]) ?>
-
+
'control-label col-xs-2 required']) ?>
@@ -99,13 +100,13 @@ 'name' => 'phone', 'id' => 'phone', 'class' => 'form-control input-sm required', - 'value'=> esc($config['phone'], 'attr') + 'value'=> $config['phone'] ]) ?>
-
+
'control-label col-xs-2']) ?>
@@ -114,20 +115,20 @@ 'name' => 'fax', 'id' => 'fax', 'class' => 'form-control input-sm', - 'value'=> esc($config['fax'], 'attr') + 'value'=> $config['fax'] ]) ?>
-
+
'control-label col-xs-2 required']) ?>
'return_policy', 'id' => 'return_policy', 'class' => 'form-control input-sm required', - 'value' => esc($config['return_policy'], 'attr') + 'value' => $config['return_policy'] ]) ?>
@@ -148,7 +149,7 @@ $(document).ready(function() $("a.fileinput-exists").click(function() { $.ajax({ type: 'POST', - url: '', + url: '', dataType: 'json' }) }); @@ -166,7 +167,7 @@ $(document).ready(function() return_policy: "required" }, - messages: + messages: { company: "", address: "",