diff --git a/app/Config/OSPOS.php b/app/Config/OSPOS.php index c1d79f7a4..d1acb7138 100644 --- a/app/Config/OSPOS.php +++ b/app/Config/OSPOS.php @@ -2,6 +2,7 @@ namespace Config; +use App\Models\Appconfig; use CodeIgniter\Cache\CacheInterface; use CodeIgniter\Config\BaseConfig; @@ -13,9 +14,7 @@ use CodeIgniter\Config\BaseConfig; class OSPOS extends BaseConfig { public array $settings; - public string $commit_sha1 = 'dev'; //TODO: Travis scripts need to be updated to replace this with the commit hash on build - private CacheInterface $cache; public function __construct() @@ -37,7 +36,7 @@ class OSPOS extends BaseConfig } else { - $appconfig = model('Appconfig'); + $appconfig = model(Appconfig::class); foreach($appconfig->get_all()->getResult() as $app_config) { $this->settings[$app_config->key] = $app_config->value; diff --git a/app/Config/Validation/OSPOSRules.php b/app/Config/Validation/OSPOSRules.php index 5103c4abd..2c36f3bca 100644 --- a/app/Config/Validation/OSPOSRules.php +++ b/app/Config/Validation/OSPOSRules.php @@ -7,11 +7,13 @@ use Config\OSPOS; use Config\Services; /** - * @property employee employee + * @property Employee employee * @property IncomingRequest request */ class OSPOSRules { + private IncomingRequest $request; + private array $config; /** * Validates the username and password sent to the login view. User is logged in on successful validation. * @@ -24,9 +26,9 @@ class OSPOSRules */ public function login_check(string $username, string $fields , array $data, ?string &$error = null): bool { - $this->employee = model('Employee'); + $employee = model(Employee::class); $this->request = Services::request(); - $config = config(OSPOS::class)->settings; + $this->config = config(OSPOS::class)->settings; //Installation Check if(!$this->installation_check()) @@ -36,21 +38,15 @@ class OSPOSRules return false; } - //Username and Password Check $password = $data['password']; - if(!$this->employee->login($username, $password)) + if(!$employee->login($username, $password)) { $error = lang('Login.invalid_username_and_password'); return false; } - - //GCaptcha Check - $gcaptcha_enabled = array_key_exists('gcaptcha_enable', $config) - ? $config['gcaptcha_enable'] - : false; - + $gcaptcha_enabled = array_key_exists('gcaptcha_enable', $this->config) && $this->config['gcaptcha_enable']; if($gcaptcha_enabled) { $g_recaptcha_response = $this->request->getPost('g-recaptcha-response'); @@ -77,7 +73,7 @@ class OSPOSRules if(!empty($response)) { $check = [ - 'secret' => $config['gcaptcha_secret_key'], + 'secret' => $this->config['gcaptcha_secret_key'], 'response' => $response, 'remoteip' => $this->request->getIPAddress() ]; diff --git a/app/Controllers/Attributes.php b/app/Controllers/Attributes.php index 65b9e1406..2ea49f1ef 100644 --- a/app/Controllers/Attributes.php +++ b/app/Controllers/Attributes.php @@ -8,24 +8,23 @@ require_once('Secure_Controller.php'); /** * Attributes controls the custom attributes assigned to items - * - * @property attribute attribute - * - */ + **/ class Attributes extends Secure_Controller { + private Attribute $attribute; + public function __construct() { parent::__construct('attributes'); - $this->attribute = model('Attribute'); + $this->attribute = model(Attribute::class); } /** * Gets and sends the main view for Attributes to the browser. * * @return void - */ + **/ public function getIndex(): void { $data['table_headers'] = get_attribute_definition_manage_table_headers(); diff --git a/app/Controllers/Cashups.php b/app/Controllers/Cashups.php index 66895c09d..bb276866d 100644 --- a/app/Controllers/Cashups.php +++ b/app/Controllers/Cashups.php @@ -8,21 +8,20 @@ use App\Models\Reports\Summary_payments; use CodeIgniter\Model; use Config\OSPOS; -/** - * @property cashup cashup - * @property expense expense - * @property summary_payments summary_payments - * @property array $config - */ class Cashups extends Secure_Controller { + private Cashup $cashup; + private Expense $expense; + private Summary_payments $summary_payments; + private array $config; + public function __construct() { parent::__construct('cashups'); - $this->cashup = model('Cashup'); - $this->expense = model('Expense'); - $this->summary_payments = model('Reports/Summary_payments'); + $this->cashup = model(Cashup::class); + $this->expense = model(Expense::class); + $this->summary_payments = model(Summary_payments::class); $this->config = config(OSPOS::class)->settings; } diff --git a/app/Controllers/Config.php b/app/Controllers/Config.php index b051d2a1d..4b169b0ad 100644 --- a/app/Controllers/Config.php +++ b/app/Controllers/Config.php @@ -17,38 +17,32 @@ use App\Models\Enums\Rounding_mode; use App\Models\Stock_location; use App\Models\Tax; +use CodeIgniter\Database\BaseConnection; use CodeIgniter\Encryption\EncrypterInterface; -use CodeIgniter\Files\File; use Config\Database; -use Config\Encryption; use Config\OSPOS; use Config\Services; use DirectoryIterator; use NumberFormatter; use ReflectionException; -/** - * @property barcode_lib barcode_lib - * @property mailchimp_lib mailchimp_lib - * @property receiving_lib receiving_lib - * @property sale_lib sale_lib - * @property tax_lib tax_lib - * @property encryption encryption - * @property encrypterinterface encrypter - * @property appconfig appconfig - * @property attribute attribute - * @property customer_rewards customer_rewards - * @property dinner_table dinner_table - * @property module module - * @property rounding_mode rounding_mode - * @property stock_location stock_location - * @property tax tax - * @property array config - */ class Config extends Secure_Controller { protected $helpers = ['security']; - private $db; + private BaseConnection $db; + private EncrypterInterface $encrypter; + private Barcode_lib $barcode_lib; + private Sale_lib $sale_lib; + private Receiving_lib $receiving_lib; + private Tax_lib $tax_lib; + private Appconfig $appconfig; + private Attribute $attribute; + private Customer_rewards $customer_rewards; + private Dinner_table $dinner_table; + protected Module $module; + private Stock_location $stock_location; + private Tax $tax; + private array $config; public function __construct() @@ -59,14 +53,13 @@ class Config extends Secure_Controller $this->sale_lib = new Sale_lib(); $this->receiving_lib = new receiving_lib(); $this->tax_lib = new Tax_lib(); - $this->appconfig = model('Appconfig'); - $this->attribute = model('Attribute'); - $this->customer_rewards = model('Customer_rewards'); - $this->dinner_table = model('Dinner_table'); - $this->module = model('Module'); - $this->rounding_mode = model('Rounding_mode'); - $this->stock_location = model('Stock_location'); - $this->tax = model('Tax'); + $this->appconfig = model(Appconfig::class); + $this->attribute = model(Attribute::class); + $this->customer_rewards = model(Customer_rewards::class); + $this->dinner_table = model(Dinner_table::class); + $this->module = model(Module::class); + $this->stock_location = model(Stock_location::class); + $this->tax = model(Tax::class); $this->config = config(OSPOS::class)->settings; $this->db = Database::connect(); @@ -277,7 +270,7 @@ class Config extends Secure_Controller $data['tax_jurisdiction_options'] = $this->tax_lib->get_tax_jurisdiction_options(); $data['show_office_group'] = $this->module->get_show_office_group(); $data['currency_code'] = $this->config['currency_code'] ?? ''; - $data['db_version'] = mysqli_get_server_info(db_connect()->mysqli); + $data['db_version'] = mysqli_get_server_info($this->db->getConnection()); // load all the license statements, they are already XSS cleaned in the private function $data['licenses'] = $this->_licenses(); @@ -582,11 +575,11 @@ class Config extends Secure_Controller */ private function _mailchimp(string $api_key = ''): array //TODO: Hungarian notation { - $this->mailchimp_lib = new Mailchimp_lib(['api_key' => $api_key]); + $mailchimp_lib = new Mailchimp_lib(['api_key' => $api_key]); $result = []; - $lists = $this->mailchimp_lib->getLists(); + $lists = $mailchimp_lib->getLists(); if($lists !== FALSE) { if(is_array($lists) && !empty($lists['lists']) && is_array($lists['lists'])) diff --git a/app/Controllers/Customers.php b/app/Controllers/Customers.php index 41c482871..15688b9ba 100644 --- a/app/Controllers/Customers.php +++ b/app/Controllers/Customers.php @@ -10,35 +10,27 @@ use App\Models\Tax_code; use CodeIgniter\Encryption\Encryption; use CodeIgniter\Encryption\EncrypterInterface; +use CodeIgniter\Model; use Config\OSPOS; use Config\Services; use stdClass; -/** - * - * - * @property mailchimp_lib mailchimp_lib - * - * @property customer customer - * @property customer_rewards customer_rewards - * @property tax_code tax_code - * - * @property encryption encryption - * @property encrypterinterface encrypter - * @property array config - * - */ class Customers extends Persons { - private $_list_id; + private string $_list_id; + private Mailchimp_lib $mailchimp_lib; + private Customer_rewards $customer_rewards; + private Customer $customer; + private Tax_code $tax_code; + private array $config; public function __construct() { parent::__construct('customers'); $this->mailchimp_lib = new Mailchimp_lib(); - $this->customer_rewards = model('Customer_rewards'); - $this->customer = model('Customer'); - $this->tax_code = model('Tax_code'); + $this->customer_rewards = model(Customer_rewards::class); + $this->customer = model(Customer::class); + $this->tax_code = model(Tax_code::class); $this->config = config(OSPOS::class)->settings; $encrypter = Services::encrypter(); diff --git a/app/Controllers/Expenses.php b/app/Controllers/Expenses.php index 8a36b63ab..4235ff324 100644 --- a/app/Controllers/Expenses.php +++ b/app/Controllers/Expenses.php @@ -4,19 +4,19 @@ namespace App\Controllers; use App\Models\Expense; use App\Models\Expense_category; +use Config\OSPOS; -/** - * @property expense expense - * @property expense_category expense_category - */ class Expenses extends Secure_Controller { + private Expense $expense; + private Expense_category $expense_category; + public function __construct() { parent::__construct('expenses'); - $this->expense = model('Expense'); - $this->expense_category = model('Expense_category'); + $this->expense = model(Expense::class); + $this->expense_category = model(Expense_category::class); } public function getIndex(): void diff --git a/app/Controllers/Expenses_categories.php b/app/Controllers/Expenses_categories.php index ea1716ffd..2db5435b6 100644 --- a/app/Controllers/Expenses_categories.php +++ b/app/Controllers/Expenses_categories.php @@ -4,16 +4,15 @@ namespace App\Controllers; use App\Models\Expense_category; -/** - * @property expense_category expense_category - */ class Expenses_categories extends Secure_Controller //TODO: Is this class ever used? { + private Expense_category $expense_category; + public function __construct() { parent::__construct('expenses_categories'); - $this->expense_category = model('Expense_category'); + $this->expense_category = model(Expense_category::class); } public function getIndex(): void @@ -23,9 +22,9 @@ class Expenses_categories extends Secure_Controller //TODO: Is this class ever u echo view('expenses_categories/manage', $data); } - /* - Returns expense_category_manage table data rows. This will be called with AJAX. - */ + /** + * Returns expense_category_manage table data rows. This will be called with AJAX. + **/ public function getSearch(): void { $search = $this->request->getVar('search', FILTER_SANITIZE_FULL_SPECIAL_CHARS); @@ -73,7 +72,7 @@ class Expenses_categories extends Secure_Controller //TODO: Is this class ever u if($expense_category_id == NEW_ENTRY) { echo json_encode ([ - 'success' => TRUE, + 'success' => true, 'message' => lang('Expenses_categories.successful_adding'), 'id' => $expense_category_data['expense_category_id'] ]); @@ -81,7 +80,7 @@ class Expenses_categories extends Secure_Controller //TODO: Is this class ever u else // Existing Expense Category { echo json_encode ([ - 'success' => TRUE, + 'success' => true, 'message' => lang('Expenses_categories.successful_updating'), 'id' => $expense_category_id ]); @@ -90,7 +89,7 @@ class Expenses_categories extends Secure_Controller //TODO: Is this class ever u else//failure { echo json_encode ([ - 'success' => FALSE, + 'success' => true, 'message' => lang('Expenses_categories.error_adding_updating') . ' ' . $expense_category_data['category_name'], 'id' => NEW_ENTRY ]); @@ -104,13 +103,13 @@ class Expenses_categories extends Secure_Controller //TODO: Is this class ever u if($this->expense_category->delete_list($expense_category_to_delete)) //TODO: Convert to ternary notation. { echo json_encode([ - 'success' => TRUE, + 'success' => true, 'message' => lang('Expenses_categories.successful_deleted') . ' ' . count($expense_category_to_delete) . ' ' . lang('Expenses_categories.one_or_multiple') ]); } else { - echo json_encode (['success' => FALSE, 'message' => lang('Expenses_categories.cannot_be_deleted')]); + echo json_encode (['success' => false, 'message' => lang('Expenses_categories.cannot_be_deleted')]); } } } diff --git a/app/Controllers/Giftcards.php b/app/Controllers/Giftcards.php index e50c9b15f..6d3b94df1 100644 --- a/app/Controllers/Giftcards.php +++ b/app/Controllers/Giftcards.php @@ -3,17 +3,17 @@ namespace App\Controllers; use App\Models\Giftcard; +use Config\OSPOS; -/** - * @property giftcard giftcard - */ class Giftcards extends Secure_Controller { + private Giftcard $giftcard; + public function __construct() { parent::__construct('giftcards'); - $this->giftcard = model('Giftcard'); + $this->giftcard = model(Giftcard::class); } public function getIndex(): void diff --git a/app/Controllers/Item_kits.php b/app/Controllers/Item_kits.php index 64ff433e2..635662dc4 100644 --- a/app/Controllers/Item_kits.php +++ b/app/Controllers/Item_kits.php @@ -7,26 +7,21 @@ use App\Libraries\Barcode_lib; use App\Models\Item; use App\Models\Item_kit; use App\Models\Item_kit_items; +use CodeIgniter\Model; -/** - * - * - * @property barcode_lib barcode_lib - * - * @property item item - * @property item_kit item_kit - * @property item_kit_items item_kit_items - * - */ class Item_kits extends Secure_Controller { + private Item $item; + private Item_kit $item_kit; + private Item_kit_items $item_kit_items; + public function __construct() { parent::__construct('item_kits'); - $this->item = model('Item'); - $this->item_kit = model('Item_kit'); - $this->item_kit_items = model('Item_kit_items'); + $this->item = model(Item::class); + $this->item_kit = model(Item_kit::class); + $this->item_kit_items = model(Item_kit_items::class); } /** @@ -59,7 +54,9 @@ class Item_kits extends Secure_Controller $discount_fraction = bcdiv($item_kit->kit_discount, '100'); - $item_kit->total_unit_price = $item_kit->total_unit_price - round(($item_kit->kit_discount_type == PERCENT)?bcmul($item_kit->total_unit_price, $discount_fraction): $item_kit->kit_discount, totals_decimals(), PHP_ROUND_HALF_UP); + $item_kit->total_unit_price = $item_kit->total_unit_price - round(($item_kit->kit_discount_type == PERCENT) + ? bcmul($item_kit->total_unit_price, $discount_fraction) + : $item_kit->kit_discount, totals_decimals(), PHP_ROUND_HALF_UP); return $item_kit; } @@ -76,7 +73,7 @@ class Item_kits extends Secure_Controller */ public function getSearch(): void { - $search = $this->request->getVar('search', FILTER_SANITIZE_FULL_SPECIAL_CHARS); + $search = $this->request->getVar('search', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? ''; $limit = $this->request->getVar('limit', FILTER_SANITIZE_NUMBER_INT); $offset = $this->request->getVar('offset', FILTER_SANITIZE_NUMBER_INT); $sort = $this->request->getVar('sort', FILTER_SANITIZE_FULL_SPECIAL_CHARS); @@ -250,7 +247,7 @@ class Item_kits extends Secure_Controller public function generate_barcodes(string $item_kit_ids): void { - $this->barcode_lib = new Barcode_lib(); + $barcode_lib = new Barcode_lib(); $result = []; $item_kit_ids = explode(':', $item_kit_ids); @@ -271,7 +268,7 @@ class Item_kits extends Secure_Controller } $data['items'] = $result; - $barcode_config = $this->barcode_lib->get_barcode_config(); + $barcode_config = $barcode_lib->get_barcode_config(); // in case the selected barcode type is not Code39 or Code128 we set by default Code128 // the rationale for this is that EAN codes cannot have strings as seed, so 'KIT ' is not allowed if($barcode_config['barcode_type'] != 'Code39' && $barcode_config['barcode_type'] != 'Code128') diff --git a/app/Controllers/Items.php b/app/Controllers/Items.php index 34e05339d..93f54a0cf 100644 --- a/app/Controllers/Items.php +++ b/app/Controllers/Items.php @@ -15,43 +15,27 @@ use App\Models\Stock_location; use App\Models\Supplier; use App\Models\Tax_category; -use CodeIgniter\Model; +use CodeIgniter\Images\Handlers\BaseHandler; use Config\OSPOS; use Config\Services; -use CodeIgniter\Images\Image; use ReflectionException; require_once('Secure_Controller.php'); -/** - * @property image image - * @property barcode_lib barcode_lib - * @property item_lib item_lib - * @property attribute attribute - * @property inventory inventory - * @property item item - * @property item_kit item_kit - * @property item_quantity item_quantity - * @property item_taxes item_taxes - * @property stock_location stock_location - * @property supplier supplier - * @property tax_category tax_category - * @property array config - */ class Items extends Secure_Controller { - private object $image; + private BaseHandler $image; private Barcode_lib $barcode_lib; private Item_lib $item_lib; - private Model $attribute; - private Model $inventory; - private Model $item; - private Model $item_kit; - private Model $item_quantity; - private Model $item_taxes; - private Model $stock_location; - private Model $supplier; - private Model $tax_category; + private Attribute $attribute; + private Inventory $inventory; + private Item $item; + private Item_kit $item_kit; + private Item_quantity $item_quantity; + private Item_taxes $item_taxes; + private Stock_location $stock_location; + private Supplier $supplier; + private Tax_category $tax_category; private array $config; @@ -66,15 +50,15 @@ class Items extends Secure_Controller $this->barcode_lib = new Barcode_lib(); $this->item_lib = new Item_lib(); - $this->attribute = model('Attribute'); - $this->inventory = model('Inventory'); - $this->item = model('Item'); - $this->item_kit = model('Item_kit'); - $this->item_quantity = model('Item_quantity'); - $this->item_taxes = model('Item_taxes'); - $this->stock_location = model('Stock_location'); - $this->supplier = model('Supplier'); - $this->tax_category = model('Tax_category'); + $this->attribute = model(Attribute::class); + $this->inventory = model(Inventory::class); + $this->item = model(Item::class); + $this->item_kit = model(Item_kit::class); + $this->item_quantity = model(Item_quantity::class); + $this->item_taxes = model(Item_taxes::class); + $this->stock_location = model(Stock_location::class); + $this->supplier = model(Supplier::class); + $this->tax_category = model(Tax_category::class); $this->config = config(OSPOS::class)->settings; } diff --git a/app/Controllers/Messages.php b/app/Controllers/Messages.php index a87550af7..153ef9a91 100644 --- a/app/Controllers/Messages.php +++ b/app/Controllers/Messages.php @@ -6,33 +6,27 @@ use App\Libraries\Sms_lib; use App\Models\Person; -/** - * - * - * @property sms_lib sms_lib - * - * @property person person - * - */ class Messages extends Secure_Controller { + private Sms_lib $sms_lib; + public function __construct() { parent::__construct('messages'); - - $this->sms_lib = new Sms_lib(); - $this->person = model('Person'); + $this->sms_lib = new Sms_lib(); } - + public function getIndex(): void { echo view('messages/sms'); } public function getView(int $person_id = NEW_ENTRY): void - { - $info = $this->person->get_info($person_id); + { + $person = model(Person::class); + $info = $person->get_info($person_id); + foreach(get_object_vars($info) as $property => $value) { $info->$property = $value; @@ -66,7 +60,7 @@ class Messages extends Secure_Controller * @return void */ public function send_form(int $person_id = NEW_ENTRY): void - { + { $phone = $this->request->getPost('phone', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $message = $this->request->getPost('message', FILTER_SANITIZE_FULL_SPECIAL_CHARS); diff --git a/app/Controllers/Office.php b/app/Controllers/Office.php index 3b212b438..f0b3c586f 100644 --- a/app/Controllers/Office.php +++ b/app/Controllers/Office.php @@ -5,10 +5,12 @@ namespace App\Controllers; use App\Models\Employee; /** - * @property employee employee + * @property Employee employee */ class Office extends Secure_Controller { + protected Employee $employee; + function __construct() { parent::__construct('office', NULL, 'office'); @@ -21,8 +23,8 @@ class Office extends Secure_Controller public function logout(): void { - $this->employee = model('Employee'); + $this->employee = model(Employee::class); $this->employee->logout(); } -} \ No newline at end of file +} diff --git a/app/Controllers/Persons.php b/app/Controllers/Persons.php index 0147cb191..7bb6ebc73 100644 --- a/app/Controllers/Persons.php +++ b/app/Controllers/Persons.php @@ -3,17 +3,17 @@ namespace App\Controllers; use App\Models\Person; +use CodeIgniter\Model; -/** - * @property person person - */ abstract class Persons extends Secure_Controller { + protected Person $person; + public function __construct(string $module_id = NULL) { parent::__construct($module_id); - $this->person = model('Person'); + $this->person = model(Person::class); } public function getIndex(): void diff --git a/app/Controllers/Receivings.php b/app/Controllers/Receivings.php index d150c5218..0ef28a5a8 100644 --- a/app/Controllers/Receivings.php +++ b/app/Controllers/Receivings.php @@ -14,20 +14,19 @@ use App\Models\Supplier; use Config\OSPOS; use ReflectionException; -/** - * @property receiving_lib receiving_lib - * @property token_lib token_lib - * @property barcode_lib barcode_lib - * @property inventory inventory - * @property item item - * @property item_kit item_kit - * @property receiving receiving - * @property stock_location stock_location - * @property supplier supplier - * @property array config - */ class Receivings extends Secure_Controller { + private Receiving_lib $receiving_lib; + private Token_lib $token_lib; + private Barcode_lib $barcode_lib; + private Inventory $inventory; + private Item $item; + private Item_kit $item_kit; + private Receiving $receiving; + private Stock_location $stock_location; + private Supplier $supplier; + private array $config; + public function __construct() { parent::__construct('receivings'); @@ -36,12 +35,12 @@ class Receivings extends Secure_Controller $this->token_lib = new Token_lib(); $this->barcode_lib = new Barcode_lib(); - $this->inventory = model('Inventory'); - $this->item_kit = model('Item_kit'); - $this->item = model('Item'); - $this->receiving = model('Receiving'); - $this->stock_location = model('Stock_location'); - $this->supplier = model('Supplier'); + $this->inventory = model(Inventory::class); + $this->item_kit = model(Item_kit::class); + $this->item = model(Item::class); + $this->receiving = model(Receiving::class); + $this->stock_location = model(Stock_location::class); + $this->supplier = model(Supplier::class); $this->config = config(OSPOS::class)->settings; } diff --git a/app/Controllers/Reports.php b/app/Controllers/Reports.php index 58a7eb2ac..08da498be 100644 --- a/app/Controllers/Reports.php +++ b/app/Controllers/Reports.php @@ -28,42 +28,54 @@ use App\Models\Reports\Summary_taxes; use Config\OSPOS; use Config\Services; -/** - * @property attribute attribute - * @property customer customer - * @property stock_location stock_location - * @property supplier supplier - * @property detailed_receivings detailed_receivings - * @property detailed_sales detailed_sales - * @property inventory_low inventory_low - * @property inventory_summary inventory_summary - * @property specific_customer specific_customer - * @property specific_discount specific_discount - * @property specific_employee specific_employee - * @property specific_supplier specific_supplier - * @property summary_categories summary_categories - * @property summary_customers summary_customers - * @property summary_discounts summary_discounts - * @property summary_employees summary_employees - * @property summary_expenses_categories summary_expenses_categories - * @property summary_items summary_items - * @property summary_payments summary_payments - * @property summary_sales summary_sales - * @property summary_sales_taxes summary_sales_taxes - * @property summary_suppliers summary_suppliers - * @property summary_taxes summary_taxes - * @property array config - */ class Reports extends Secure_Controller { + private Attribute $attribute; + private array $config; + private Customer $customer; + private Stock_location $stock_location; + private Summary_sales $summary_sales; + private Summary_sales_taxes $summary_sales_taxes; + private Summary_categories $summary_categories; + private Summary_expenses_categories $summary_expenses_categories; + private Summary_customers $summary_customers; + private Summary_items $summary_items; + private Summary_suppliers $summary_suppliers; + private Summary_employees $summary_employees; + private Summary_taxes $summary_taxes; + private Summary_discounts $summary_discounts; + private Summary_payments $summary_payments; + private Detailed_sales $detailed_sales; + private Supplier $supplier; + private Detailed_receivings $detailed_receivings; + private Inventory_summary $inventory_summary; + public function __construct() { parent::__construct('reports'); $request = Services::request(); $method_name = $request->getUri()->getSegment(2); $exploder = explode('_', $method_name); + + $this->attribute = config(Attribute::class); $this->config = config(OSPOS::class)->settings; - $this->stock_location = model('Stock_location'); + $this->customer = model(Customer::class); + $this->stock_location = model(Stock_location::class); + $this->summary_sales = model(Summary_sales::class); + $this->summary_sales_taxes = model(Summary_sales_taxes::class); + $this->summary_categories = model(Summary_categories::class); + $this->summary_expenses_categories = model(Summary_expenses_categories::class); + $this->summary_customers = model(Summary_customers::class); + $this->summary_items = model(Summary_items::class); + $this->summary_suppliers = model(Summary_suppliers::class); + $this->summary_employees = model(Summary_employees::class); + $this->summary_taxes = model(Summary_taxes::class); + $this->summary_discounts = model(Summary_discounts::class); + $this->summary_payments = model(Summary_payments::class); + $this->detailed_sales = model(Detailed_sales::class); + $this->supplier = model(Supplier::class); + $this->detailed_receivings = model(Detailed_receivings::class); + $this->inventory_summary = model(Inventory_summary::class); if(sizeof($exploder) > 1) { @@ -121,11 +133,8 @@ class Reports extends Secure_Controller 'location_id' => $location_id ]; - $this->summary_sales = model('reports/Summary_sales'); - $model = $this->summary_sales; - - $report_data = $model->getData($inputs); - $summary = $model->getSummaryData($inputs); + $report_data = $this->summary_sales->getData($inputs); + $summary = $this->summary_sales->getSummaryData($inputs); $tabular_data = []; foreach($report_data as $row) @@ -145,7 +154,7 @@ class Reports extends Secure_Controller $data = [ 'title' => lang('Reports.sales_summary_report'), 'subtitle' => $this->_get_subtitle_report(['start_date' => $start_date, 'end_date' => $end_date]), - 'headers' => $model->getDataColumns(), + 'headers' => $this->summary_sales->getDataColumns(), 'data' => $tabular_data, 'summary_data' => $summary ]; @@ -172,11 +181,8 @@ class Reports extends Secure_Controller 'location_id' => $location_id ]; - $this->summary_categories = model('reports/Summary_categories'); - $model = $this->summary_categories; - - $report_data = $model->getData($inputs); - $summary = $model->getSummaryData($inputs); + $report_data = $this->summary_categories->getData($inputs); + $summary = $this->summary_categories->getSummaryData($inputs); $tabular_data = []; foreach($report_data as $row) @@ -195,7 +201,7 @@ class Reports extends Secure_Controller $data = [ 'title' => lang('Reports.categories_summary_report'), 'subtitle' => $this->_get_subtitle_report(['start_date' => $start_date, 'end_date' => $end_date]), - 'headers' => $model->getDataColumns(), + 'headers' => $this->summary_categories->getDataColumns(), 'data' => $tabular_data, 'summary_data' => $summary ]; @@ -216,11 +222,8 @@ class Reports extends Secure_Controller $inputs = ['start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type]; //TODO: Duplicated Code - $this->summary_expenses_categories = model('reports/Summary_expenses_categories'); - $model = $this->summary_expenses_categories; - - $report_data = $model->getData($inputs); - $summary = $model->getSummaryData($inputs); + $report_data = $this->summary_expenses_categories->getData($inputs); + $summary = $this->summary_expenses_categories->getSummaryData($inputs); $tabular_data = []; foreach($report_data as $row) @@ -236,7 +239,7 @@ class Reports extends Secure_Controller $data = [ 'title' => lang('Reports.expenses_categories_summary_report'), 'subtitle' => $this->_get_subtitle_report(['start_date' => $start_date, 'end_date' => $end_date]), - 'headers' => $model->getDataColumns(), + 'headers' => $this->summary_expenses_categories->getDataColumns(), 'data' => $tabular_data, 'summary_data' => $summary ]; @@ -263,11 +266,8 @@ class Reports extends Secure_Controller 'location_id' => $location_id ]; - $this->summary_customers = model('reports/Summary_customers'); - $model = $this->summary_customers; - - $report_data = $model->getData($inputs); - $summary = $model->getSummaryData($inputs); + $report_data = $this->summary_customers->getData($inputs); + $summary = $this->summary_customers->getSummaryData($inputs); $tabular_data = []; @@ -288,7 +288,7 @@ class Reports extends Secure_Controller $data = [ 'title' => lang('Reports.customers_summary_report'), 'subtitle' => $this->_get_subtitle_report(['start_date' => $start_date, 'end_date' => $end_date]), - 'headers' => $model->getDataColumns(), + 'headers' => $this->summary_customers->getDataColumns(), 'data' => $tabular_data, 'summary_data' => $summary ]; @@ -315,11 +315,8 @@ class Reports extends Secure_Controller 'location_id' => $location_id ]; - $this->summary_suppliers = model('reports/Summary_suppliers'); - $model = $this->summary_suppliers; - - $report_data = $model->getData($inputs); - $summary = $model->getSummaryData($inputs); + $report_data = $this->summary_suppliers->getData($inputs); + $summary = $this->summary_suppliers->getSummaryData($inputs); $tabular_data = []; foreach($report_data as $row) @@ -338,7 +335,7 @@ class Reports extends Secure_Controller $data = [ 'title' => lang('Reports.suppliers_summary_report'), 'subtitle' => $this->_get_subtitle_report(['start_date' => $start_date, 'end_date' => $end_date]), - 'headers' => $model->getDataColumns(), + 'headers' => $this->summary_suppliers->getDataColumns(), 'data' => $tabular_data, 'summary_data' => $summary ]; @@ -365,11 +362,8 @@ class Reports extends Secure_Controller 'location_id' => $location_id ]; - $this->summary_items = model('reports/Summary_items'); - $model = $this->summary_items; - - $report_data = $model->getData($inputs); - $summary = $model->getSummaryData($inputs); + $report_data = $this->summary_items->getData($inputs); + $summary = $this->summary_items->getSummaryData($inputs); $tabular_data = []; @@ -392,7 +386,7 @@ class Reports extends Secure_Controller $data = [ 'title' => lang('Reports.items_summary_report'), 'subtitle' => $this->_get_subtitle_report(['start_date' => $start_date, 'end_date' => $end_date]), - 'headers' => $model->getDataColumns(), + 'headers' => $this->summary_items->getDataColumns(), 'data' => $tabular_data, 'summary_data' => $summary ]; @@ -419,11 +413,8 @@ class Reports extends Secure_Controller 'location_id' => $location_id ]; - $this->summary_employees = model('reports/summary_employees'); - $model = $this->summary_employees; - - $report_data = $model->getData($inputs); - $summary = $model->getSummaryData($inputs); + $report_data = $this->summary_employees->getData($inputs); + $summary = $this->summary_employees->getSummaryData($inputs); $tabular_data = []; @@ -444,7 +435,7 @@ class Reports extends Secure_Controller $data = [ 'title' => lang('Reports.employees_summary_report'), 'subtitle' => $this->_get_subtitle_report(['start_date' => $start_date, 'end_date' => $end_date]), - 'headers' => $model->getDataColumns(), + 'headers' => $this->summary_employees->getDataColumns(), 'data' => $tabular_data, 'summary_data' => $summary ]; @@ -471,11 +462,8 @@ class Reports extends Secure_Controller 'location_id' => $location_id ]; - $this->summary_taxes = model('reports/Summary_taxes'); - $model = $this->summary_taxes; - - $report_data = $model->getData($inputs); - $summary = $model->getSummaryData($inputs); + $report_data = $this->summary_taxes->getData($inputs); + $summary = $this->summary_taxes->getSummaryData($inputs); $tabular_data = []; @@ -494,7 +482,7 @@ class Reports extends Secure_Controller $data = [ 'title' => lang('Reports.taxes_summary_report'), 'subtitle' => $this->_get_subtitle_report(['start_date' => $start_date, 'end_date' => $end_date]), - 'headers' => $model->getDataColumns(), + 'headers' => $this->summary_taxes->getDataColumns(), 'data' => $tabular_data, 'summary_data' => $summary ]; @@ -514,11 +502,8 @@ class Reports extends Secure_Controller 'location_id' => $location_id ]; - $this->summary_sales_taxes = model('reports/Summary_sales_taxes'); - $model = $this->summary_sales_taxes; - - $report_data = $model->getData($inputs); - $summary = $model->getSummaryData($inputs); + $report_data = $this->summary_sales_taxes->getData($inputs); + $summary = $this->summary_sales_taxes->getSummaryData($inputs); $tabular_data = []; foreach($report_data as $row) @@ -535,7 +520,7 @@ class Reports extends Secure_Controller $data = [ 'title' => lang('Reports.sales_taxes_summary_report'), 'subtitle' => $this->_get_subtitle_report(['start_date' => $start_date, 'end_date' => $end_date]), - 'headers' => $model->getDataColumns(), + 'headers' => $this->summary_sales_taxes->getDataColumns(), 'data' => $tabular_data, 'summary_data' => $summary ]; @@ -557,7 +542,9 @@ class Reports extends Secure_Controller echo view('reports/date_input', $data); } - //Summary Discounts report + /** + * Summary Discounts report + **/ public function summary_discounts(string $start_date, string $end_date, string $sale_type, string $location_id = 'all', int $discount_type = 0): void {//TODO: Duplicated Code $this->clearCache(); @@ -570,11 +557,8 @@ class Reports extends Secure_Controller 'discount_type' => $discount_type ]; - $this->summary_discounts = model('reports/Summary_discounts'); - $model = $this->summary_discounts; - - $report_data = $model->getData($inputs); - $summary = $model->getSummaryData($inputs); + $report_data = $this->summary_discounts->getData($inputs); + $summary = $this->summary_discounts->getSummaryData($inputs); $tabular_data = []; foreach($report_data as $row) @@ -589,7 +573,7 @@ class Reports extends Secure_Controller $data = [ 'title' => lang('Reports.discounts_summary_report'), 'subtitle' => $this->_get_subtitle_report(['start_date' => $start_date, 'end_date' => $end_date]), - 'headers' => $model->getDataColumns(), + 'headers' => $this->summary_discounts->getDataColumns(), 'data' => $tabular_data, 'summary_data' => $summary ]; @@ -609,11 +593,8 @@ class Reports extends Secure_Controller 'location_id' => 'all' ]; - $this->summary_payments = model('reports/Summary_payments'); - $model = $this->summary_payments; - - $report_data = $model->getData($inputs); - $summary = $model->getSummaryData($inputs); + $report_data = $this->summary_payments->getData($inputs); + $summary = $this->summary_payments->getSummaryData($inputs); $tabular_data = []; @@ -653,7 +634,7 @@ class Reports extends Secure_Controller $data = [ 'title' => lang('Reports.payments_summary_report'), 'subtitle' => $this->_get_subtitle_report(['start_date' => $start_date, 'end_date' => $end_date]), - 'headers' => $model->getDataColumns(), + 'headers' => $this->summary_payments->getDataColumns(), 'data' => $tabular_data, 'summary_data' => $summary ]; @@ -719,11 +700,8 @@ class Reports extends Secure_Controller 'sale_type' => $sale_type ]; - $this->summary_expenses_categories = model('reports/Summary_expenses_categories'); - $model = $this->summary_expenses_categories; - - $report_data = $model->getData($inputs); - $summary = $model->getSummaryData($inputs); + $report_data = $this->summary_expenses_categories->getData($inputs); + $summary = $this->summary_expenses_categories->getSummaryData($inputs); $labels = []; $series = []; @@ -761,11 +739,8 @@ class Reports extends Secure_Controller 'location_id' => $location_id ]; - $this->summary_sales = model('reports/Summary_sales'); - $model = $this->summary_sales; - - $report_data = $model->getData($inputs); - $summary = $model->getSummaryData($inputs); + $report_data = $this->summary_sales->getData($inputs); + $summary = $this->summary_sales->getSummaryData($inputs); $labels = []; $series = []; @@ -803,11 +778,9 @@ class Reports extends Secure_Controller 'location_id' => $location_id ]; - $this->summary_items = model('reports/Summary_items'); - $model = $this->summary_items; - $report_data = $model->getData($inputs); - $summary = $model->getSummaryData($inputs); + $report_data = $this->summary_items->getData($inputs); + $summary = $this->summary_items->getSummaryData($inputs); $labels = []; $series = []; @@ -845,11 +818,8 @@ class Reports extends Secure_Controller 'location_id' => $location_id ]; - $this->summary_categories = model('reports/Summary_categories'); - $model = $this->summary_categories; - - $report_data = $model->getData($inputs); - $summary = $model->getSummaryData($inputs); + $report_data = $this->summary_categories->getData($inputs); + $summary = $this->summary_categories->getSummaryData($inputs); $labels = []; $series = []; @@ -884,11 +854,9 @@ class Reports extends Secure_Controller 'location_id' => $location_id ]; - $this->summary_suppliers = model('reports/Summary_suppliers'); - $model = $this->summary_suppliers; - $report_data = $model->getData($inputs); - $summary = $model->getSummaryData($inputs); + $report_data = $this->summary_suppliers->getData($inputs); + $summary = $this->summary_suppliers->getSummaryData($inputs); $labels = []; $series = []; @@ -924,11 +892,8 @@ class Reports extends Secure_Controller 'location_id' => $location_id ]; - $this->summary_employees = model('reports/Summary_employees'); - $model = $this->summary_employees; - - $report_data = $model->getData($inputs); - $summary = $model->getSummaryData($inputs); + $report_data = $this->summary_employees->getData($inputs); + $summary = $this->summary_employees->getSummaryData($inputs); $labels = []; $series = []; @@ -964,11 +929,8 @@ class Reports extends Secure_Controller 'location_id' => $location_id ]; - $this->summary_taxes = model('reports/Summary_taxes'); - $model = $this->summary_taxes; - - $report_data = $model->getData($inputs); - $summary = $model->getSummaryData($inputs); + $report_data = $this->summary_taxes->getData($inputs); + $summary = $this->summary_taxes->getSummaryData($inputs); $labels = []; $series = []; @@ -1004,11 +966,8 @@ class Reports extends Secure_Controller 'location_id' => $location_id ]; - $this->summary_sales_taxes = model('reports/Summary_sales_taxes'); - $model = $this->summary_sales_taxes; - - $report_data = $model->getData($inputs); - $summary = $model->getSummaryData($inputs); + $report_data = $this->summary_sales_taxes->getData($inputs); + $summary = $this->summary_sales_taxes->getSummaryData($inputs); $labels = []; $series = []; @@ -1044,11 +1003,8 @@ class Reports extends Secure_Controller 'location_id' => $location_id ]; - $this->summary_customers = model('reports/Summary_customers'); - $model = $this->summary_customers; - - $report_data = $model->getData($inputs); - $summary = $model->getSummaryData($inputs); + $report_data = $this->summary_customers->getData($inputs); + $summary = $this->summary_customers->getSummaryData($inputs); $labels = []; $series = []; @@ -1087,11 +1043,8 @@ class Reports extends Secure_Controller 'discount_type'=>$discount_type ]; - $this->summary_discounts = model('reports/Summary_discounts'); - $model = $this->summary_discounts; - - $report_data = $model->getData($inputs); - $summary = $model->getSummaryData($inputs); + $report_data = $this->summary_discounts->getData($inputs); + $summary = $this->summary_discounts->getSummaryData($inputs); $labels = []; $series = []; @@ -1129,11 +1082,8 @@ class Reports extends Secure_Controller 'location_id' => $location_id ]; - $this->summary_payments = model('reports/Summary_payments'); - $model = $this->summary_payments; - - $report_data = $model->getData($inputs); - $summary = $model->getSummaryData($inputs); + $report_data = $this->summary_payments->getData($inputs); + $summary = $this->summary_payments->getSummaryData($inputs); $labels = []; $series = []; @@ -1204,13 +1154,12 @@ class Reports extends Secure_Controller $inputs = ['start_date' => $start_date, 'end_date' => $end_date, 'customer_id' => $customer_id, 'sale_type' => $sale_type, 'payment_type' => $payment_type]; - $this->specific_customer = model('reports/Specific_customer'); - $model = $this->specific_customer; + $specific_customer = model(Specific_customer::class); - $model->create($inputs); + $specific_customer->create($inputs); - $headers = $model->getDataColumns(); - $report_data = $model->getData($inputs); + $headers = $specific_customer->getDataColumns(); + $report_data = $specific_customer->getData($inputs); $summary_data = []; $details_data = []; @@ -1294,7 +1243,7 @@ class Reports extends Secure_Controller 'summary_data' => $summary_data, 'details_data' => $details_data, 'details_data_rewards' => $details_data_rewards, - 'overall_summary_data' => $model->getSummaryData($inputs) + 'overall_summary_data' => $specific_customer->getSummaryData($inputs) ]; echo view('reports/tabular_details', $data); @@ -1324,13 +1273,12 @@ class Reports extends Secure_Controller $inputs = ['start_date' => $start_date, 'end_date' => $end_date, 'employee_id' => $employee_id, 'sale_type' => $sale_type]; - $this->specific_employee = model('reports/Specific_employee'); - $model = $this->specific_employee; + $specific_employee = model(Specific_employee::class); - $model->create($inputs); + $specific_employee->create($inputs); - $headers = $model->getDataColumns(); - $report_data = $model->getData($inputs); + $headers = $specific_employee->getDataColumns(); + $report_data = $specific_employee->getData($inputs); $summary_data = []; $details_data = []; @@ -1409,7 +1357,7 @@ class Reports extends Secure_Controller 'summary_data' => $summary_data, 'details_data' => $details_data, 'details_data_rewards' => $details_data_rewards, - 'overall_summary_data' => $model->getSummaryData($inputs) + 'overall_summary_data' => $specific_employee->getSummaryData($inputs) ]; echo view('reports/tabular_details', $data); @@ -1446,13 +1394,12 @@ class Reports extends Secure_Controller 'discount_type' => $discount_type ]; - $this->specific_discount = model('reports/Specific_discount'); - $model = $this->specific_discount; + $specific_discount = model(Specific_discount::class); - $model->create($inputs); + $specific_discount->create($inputs); - $headers = $model->getDataColumns(); - $report_data = $model->getData($inputs); + $headers = $specific_discount->getDataColumns(); + $report_data = $specific_discount->getData($inputs); $summary_data = []; $details_data = []; @@ -1531,7 +1478,7 @@ class Reports extends Secure_Controller 'summary_data' => $summary_data, 'details_data' => $details_data, 'details_data_rewards' => $details_data_rewards, - 'overall_summary_data' => $model->getSummaryData($inputs) + 'overall_summary_data' => $specific_discount->getSummaryData($inputs) ]; echo view('reports/tabular_details', $data); @@ -1543,12 +1490,9 @@ class Reports extends Secure_Controller $inputs = ['sale_id' => $sale_id]; - $this->detailed_sales = model('reports/Detailed_sales'); - $model = $this->detailed_sales; + $this->detailed_sales->create($inputs); - $model->create($inputs); - - $report_data = $model->getDataBySaleId($sale_id); + $report_data = $this->detailed_sales->getDataBySaleId($sale_id); if($report_data['sale_status'] == CANCELED) { @@ -1615,12 +1559,11 @@ class Reports extends Secure_Controller 'sale_type' => $sale_type ]; - $this->specific_supplier = model('reports/Specific_supplier'); - $model = $this->specific_supplier; + $specific_supplier = model(Specific_supplier::class); - $model->create($inputs); + $specific_supplier->create($inputs); - $report_data = $model->getData($inputs); + $report_data = $specific_supplier->getData($inputs); $tabular_data = []; foreach($report_data as $row) @@ -1646,9 +1589,9 @@ class Reports extends Secure_Controller $data = [ 'title' => $supplier_info->company_name . ' (' . $supplier_info->first_name . ' ' . $supplier_info->last_name . ') ' . lang('Reports.report'), 'subtitle' => $this->_get_subtitle_report(['start_date' => $start_date, 'end_date' => $end_date]), - 'headers' => $model->getDataColumns(), + 'headers' => $specific_supplier->getDataColumns(), 'data' => $tabular_data, - 'summary_data' => $model->getSummaryData($inputs) + 'summary_data' => $specific_supplier->getSummaryData($inputs) ]; echo view('reports/tabular', $data); @@ -1686,17 +1629,14 @@ class Reports extends Secure_Controller 'definition_ids' => array_keys($definition_names) ]; - $this->detailed_sales = model('reports/Detailed_sales'); - $model = $this->detailed_sales; + $this->detailed_sales->create($inputs); - $model->create($inputs); - - $columns = $model->getDataColumns(); + $columns = $this->detailed_sales->getDataColumns(); $columns['details'] = array_merge($columns['details'], $definition_names); $headers = $columns; - $report_data = $model->getData($inputs); + $report_data = $this->detailed_sales->getData($inputs); $summary_data = []; $details_data = []; @@ -1787,7 +1727,7 @@ class Reports extends Secure_Controller 'summary_data' => $summary_data, 'details_data' => $details_data, 'details_data_rewards' => $details_data_rewards, - 'overall_summary_data' => $model->getSummaryData($inputs) + 'overall_summary_data' => $this->detailed_sales->getSummaryData($inputs) ]; echo view('reports/tabular_details', $data); } @@ -1796,12 +1736,9 @@ class Reports extends Secure_Controller { $inputs = ['receiving_id' => $receiving_id]; - $this->detailed_receivings = model('reports/Detailed_receivings'); - $model = $this->detailed_receivings; + $this->detailed_receivings->create($inputs); - $model->create($inputs); - - $report_data = $model->getDataByReceivingId($receiving_id); + $report_data = $this->detailed_receivings->getDataByReceivingId($receiving_id); $summary_data = [ 'receiving_id' => $report_data['receiving_id'], @@ -1835,16 +1772,13 @@ class Reports extends Secure_Controller $inputs = ['start_date' => $start_date, 'end_date' => $end_date, 'receiving_type' => $receiving_type, 'location_id' => $location_id, 'definition_ids' => array_keys($definition_names)]; - $this->detailed_receivings = model('reports/Detailed_receivings'); - $model = $this->detailed_receivings; + $this->detailed_receivings->create($inputs); - $model->create($inputs); - - $columns = $model->getDataColumns(); + $columns = $this->detailed_receivings->getDataColumns(); $columns['details'] = array_merge($columns['details'], $definition_names); $headers = $columns; - $report_data = $model->getData($inputs); + $report_data = $this->detailed_receivings->getData($inputs); $summary_data = []; $details_data = []; @@ -1902,7 +1836,7 @@ class Reports extends Secure_Controller 'editable' => 'receivings', 'summary_data' => $summary_data, 'details_data' => $details_data, - 'overall_summary_data' => $model->getSummaryData($inputs) + 'overall_summary_data' => $this->detailed_receivings->getSummaryData($inputs) ]; echo view('reports/tabular_details', $data); @@ -1914,10 +1848,9 @@ class Reports extends Secure_Controller $inputs = []; - $this->inventory_low = model('reports/Inventory_low'); - $model = $this->inventory_low; + $inventory_low = model(Inventory_low::class); - $report_data = $model->getData($inputs); + $report_data = $inventory_low->getData($inputs); $tabular_data = []; foreach($report_data as $row) @@ -1934,9 +1867,9 @@ class Reports extends Secure_Controller $data = [ 'title' => lang('Reports.inventory_low_report'), 'subtitle' => '', - 'headers' => $model->getDataColumns(), + 'headers' => $inventory_low->getDataColumns(), 'data' => $tabular_data, - 'summary_data' => $model->getSummaryData($inputs) + 'summary_data' => $inventory_low->getSummaryData($inputs) ]; echo view('reports/tabular', $data); @@ -1946,11 +1879,8 @@ class Reports extends Secure_Controller { $this->clearCache(); - $this->inventory_summary = model('reports/Inventory_summary'); - $model = $this->inventory_summary; - $data = []; - $data['item_count'] = $model->getItemCountDropdownArray(); + $data['item_count'] = $this->inventory_summary->getItemCountDropdownArray(); $stock_locations = $this->stock_location->get_allowed_locations(); $stock_locations['all'] = lang('Reports.all'); @@ -1965,10 +1895,7 @@ class Reports extends Secure_Controller $inputs = ['location_id' => $location_id, 'item_count' => $item_count]; - $this->inventory_summary = model('reports/Inventory_summary'); - $model = $this->inventory_summary; - - $report_data = $model->getData($inputs); + $report_data = $this->inventory_summary->getData($inputs); $tabular_data = []; foreach($report_data as $row) @@ -1990,9 +1917,9 @@ class Reports extends Secure_Controller $data = [ 'title' => lang('Reports.inventory_summary_report'), 'subtitle' => '', - 'headers' => $model->getDataColumns(), + 'headers' => $this->inventory_summary->getDataColumns(), 'data' => $tabular_data, - 'summary_data' => $model->getSummaryData($report_data) + 'summary_data' => $this->inventory_summary->getSummaryData($report_data) ]; echo view('reports/tabular', $data); @@ -2015,7 +1942,7 @@ class Reports extends Secure_Controller return $subtitle; } - private function clearCache() + private function clearCache(): void { //Make sure the report is not cached by the browser $this->response->setHeader('Pragma', 'no-cache') diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php index 3cf443b37..82cbc03d5 100644 --- a/app/Controllers/Sales.php +++ b/app/Controllers/Sales.php @@ -24,34 +24,28 @@ use CodeIgniter\Config\Services; use Config\OSPOS; use ReflectionException; -/** - * @property barcode_lib barcode_lib - * @property email_lib email_lib - * @property sale_lib sale_lib - * @property tax_lib tax_lib - * @property token_lib token_lib - * @property customer customer - * @property customer_rewards customer_rewards - * @property dinner_table dinner_table - * @property employee employee - * @property giftcard giftcard - * @property inventory inventory - * @property item item - * @property item_kit item_kit - * @property sale sale - * @property stock_location stock_location - * @property array config - */ class Sales extends Secure_Controller { protected $helpers = ['form', 'file']; + private Barcode_lib $barcode_lib; + private Email_lib $email_lib; + private Sale_lib $sale_lib; + private Tax_lib $tax_lib; + private Token_lib $token_lib; + private Customer $customer; + private Customer_rewards $customer_rewards; + private Dinner_table $dinner_table; + protected Employee $employee; + private Item $item; + private Item_kit $item_kit; + private Sale $sale; + private Stock_location $stock_location; + private array $config; public function __construct() { parent::__construct('sales'); -// helper('file'); - $this->session = session(); $this->barcode_lib = new Barcode_lib(); $this->email_lib = new Email_lib(); @@ -60,11 +54,14 @@ class Sales extends Secure_Controller $this->token_lib = new Token_lib(); $this->config = config(OSPOS::class)->settings; - $this->customer = model('Customer'); - $this->sale = model('Sale'); - $this->item = model('Item'); - $this->item_kit = model('Item_kit'); - $this->stock_location = model('Stock_location'); + $this->customer = model(Customer::class); + $this->sale = model(Sale::class); + $this->item = model(Item::class); + $this->item_kit = model(Item_kit::class); + $this->stock_location = model(Stock_location::class); + $this->customer_rewards = model(Customer_rewards::class); + $this->dinner_table = model(Dinner_table::class); + $this->employee = model(Employee::class); } public function getIndex(): void @@ -330,7 +327,7 @@ class Sales extends Secure_Controller public function postAddPayment(): void { $data = []; - + $giftcard = model(Giftcard::class); $payment_type = $this->request->getPost('payment_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS); //TODO: See the code block below. This too needs to be ternary notation. @@ -370,8 +367,8 @@ class Sales extends Secure_Controller $payments = $this->sale_lib->get_payments(); $payment_type = $payment_type . ':' . $giftcard_num; $current_payments_with_giftcard = isset($payments[$payment_type]) ? $payments[$payment_type]['payment_amount'] : 0; - $cur_giftcard_value = $this->giftcard->get_giftcard_value($giftcard_num); - $cur_giftcard_customer = $this->giftcard->get_giftcard_customer($giftcard_num); + $cur_giftcard_value = $giftcard->get_giftcard_value($giftcard_num); + $cur_giftcard_customer = $giftcard->get_giftcard_customer($giftcard_num); $customer_id = $this->sale_lib->get_customer(); if(isset($cur_giftcard_customer) && $cur_giftcard_customer != $customer_id) @@ -384,12 +381,12 @@ class Sales extends Secure_Controller } else { - $new_giftcard_value = $this->giftcard->get_giftcard_value($giftcard_num) - $this->sale_lib->get_amount_due(); + $new_giftcard_value = $giftcard->get_giftcard_value($giftcard_num) - $this->sale_lib->get_amount_due(); $new_giftcard_value = max($new_giftcard_value, 0); $this->sale_lib->set_giftcard_remainder($new_giftcard_value); $new_giftcard_value = str_replace('$', '\$', to_currency($new_giftcard_value)); $data['warning'] = lang('Giftcards.remaining_balance', [$giftcard_num, $new_giftcard_value]); - $amount_tendered = min($this->sale_lib->get_amount_due(), $this->giftcard->get_giftcard_value($giftcard_num)); + $amount_tendered = min($this->sale_lib->get_amount_due(), $giftcard->get_giftcard_value($giftcard_num)); $this->sale_lib->add_payment($payment_type, $amount_tendered); } @@ -1411,7 +1408,7 @@ class Sales extends Secure_Controller { $newdate = $this->request->getPost('date', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $employee_id = $this->employee->get_logged_in_employee_info()->person_id; - + $inventory = model(Inventory::class); $date_formatter = date_create_from_format($this->config['dateformat'] . ' ' . $this->config['timeformat'], $newdate); $sale_time = $date_formatter->format('Y-m-d H:i:s'); @@ -1498,7 +1495,7 @@ class Sales extends Secure_Controller ]; } - $this->inventory->update('POS '.$sale_id, ['trans_date' => $sale_time]); //TODO: Reflection Exception + $inventory->update('POS '.$sale_id, ['trans_date' => $sale_time]); //TODO: Reflection Exception if($this->sale->update($sale_id, $sale_data)) { echo json_encode (['success' => TRUE, 'message' => lang('Sales.successfully_updated'), 'id' => $sale_id]); diff --git a/app/Controllers/Secure_Controller.php b/app/Controllers/Secure_Controller.php index 54f5cd816..c238b2df7 100644 --- a/app/Controllers/Secure_Controller.php +++ b/app/Controllers/Secure_Controller.php @@ -23,9 +23,9 @@ use Config\Services; class Secure_Controller extends BaseController { public array $global_view_data; - public Model $employee; - public Model $module; - public Session $session; + protected Employee $employee; + protected Module $module; + protected Session $session; public function __construct(string $module_id = '', string $submodule_id = null, string $menu_group = null) { diff --git a/app/Controllers/Suppliers.php b/app/Controllers/Suppliers.php index db503b2f5..12828e2bc 100644 --- a/app/Controllers/Suppliers.php +++ b/app/Controllers/Suppliers.php @@ -4,19 +4,15 @@ namespace App\Controllers; use App\Models\Supplier; -/** - * - * - * @property supplier supplier - * - */ class Suppliers extends Persons { + private Supplier $supplier; + public function __construct() { parent::__construct('suppliers'); - $this->supplier = model('Supplier'); + $this->supplier = model(Supplier::class); } public function getIndex(): void @@ -46,11 +42,11 @@ class Suppliers extends Persons */ public function getSearch(): void { - $search = $this->request->getVar('search', FILTER_SANITIZE_FULL_SPECIAL_CHARS); - $limit = $this->request->getVar('limit', FILTER_SANITIZE_NUMBER_INT); - $offset = $this->request->getVar('offset', FILTER_SANITIZE_NUMBER_INT); - $sort = $this->request->getVar('sort', FILTER_SANITIZE_FULL_SPECIAL_CHARS); - $order = $this->request->getVar('order', FILTER_SANITIZE_FULL_SPECIAL_CHARS); + $search = $this->request->getPost('search', FILTER_SANITIZE_FULL_SPECIAL_CHARS) ?? ''; + $limit = $this->request->getPost('limit', FILTER_SANITIZE_NUMBER_INT); + $offset = $this->request->getPost('offset', FILTER_SANITIZE_NUMBER_INT); + $sort = $this->request->getPost('sort', FILTER_SANITIZE_FULL_SPECIAL_CHARS); + $order = $this->request->getPost('order', FILTER_SANITIZE_FULL_SPECIAL_CHARS); $suppliers = $this->supplier->search($search, $limit, $offset, $sort, $order); $total_rows = $this->supplier->get_found_rows($search); @@ -66,7 +62,7 @@ class Suppliers extends Persons echo json_encode (['total' => $total_rows, 'rows' => $data_rows]); } - + /* Gives search suggestions based on what is being searched for */ @@ -83,7 +79,7 @@ class Suppliers extends Persons echo json_encode($suggestions); } - + /* Loads the supplier edit form */ @@ -99,7 +95,7 @@ class Suppliers extends Persons echo view("suppliers/form", $data); } - + /* Inserts/updates a supplier */ @@ -164,7 +160,7 @@ class Suppliers extends Persons ]); } } - + /* This deletes suppliers from the suppliers table */ diff --git a/app/Controllers/Taxes.php b/app/Controllers/Taxes.php index 51701f332..9f98e098a 100644 --- a/app/Controllers/Taxes.php +++ b/app/Controllers/Taxes.php @@ -10,27 +10,23 @@ use App\Models\Tax_code; use App\Models\Tax_jurisdiction; use Config\OSPOS; -/** - * @property tax_lib tax_lib - * @property rounding_mode rounding_mode - * @property tax tax - * @property tax_category tax_category - * @property tax_code tax_code - * @property tax_jurisdiction tax_jurisdiction - */ class Taxes extends Secure_Controller { - public array $config; + private array $config; + private Tax_lib $tax_lib; + private Tax $tax; + private Tax_category $tax_category; + private Tax_code $tax_code; + private Tax_jurisdiction $tax_jurisdiction; public function __construct() { parent::__construct('taxes'); - $this->rounding_mode = model('enums/Rounding_mode'); - $this->tax = model('Tax'); - $this->tax_category = model('Tax_category'); - $this->tax_code = model('Tax_code'); - $this->tax_jurisdiction = model('Tax_jurisdiction'); + $this->tax = model(Tax::class); + $this->tax_category = model(Tax_category::class); + $this->tax_code = model(Tax_code::class); + $this->tax_jurisdiction = model(Tax_jurisdiction::class); $this->tax_lib = new Tax_lib(); $this->config = config(OSPOS::class)->settings; diff --git a/app/Helpers/tabular_helper.php b/app/Helpers/tabular_helper.php index dff7e432f..797e5ee32 100644 --- a/app/Helpers/tabular_helper.php +++ b/app/Helpers/tabular_helper.php @@ -6,6 +6,7 @@ use App\Models\Item_taxes; use App\Models\Tax_category; use CodeIgniter\Database\ResultInterface; use CodeIgniter\Session\Session; +use Config\OSPOS; /** * Tabular views helper @@ -187,9 +188,6 @@ function get_sales_manage_payments_summary(array $payments): string /** * Get the header for the people tabular view - * - * @property employee $employee - * @property session $session */ function get_people_manage_table_headers(): string { @@ -250,9 +248,6 @@ function get_person_data_row(object $person): array /** * Get the header for the customer tabular view - * - * @property employee $employee - * @property session $session */ function get_customer_manage_table_headers(): string { @@ -315,9 +310,6 @@ function get_customer_data_row(object $person, object $stats): array /** * Get the header for the suppliers tabular view - * - * @property employee $employee - * @property session $session */ function get_suppliers_manage_table_headers(): string { @@ -384,8 +376,6 @@ function get_supplier_data_row(object $supplier): array /** * Get the header for the items tabular view - * - * @property attribute $attribute */ function get_items_manage_table_headers(): string { @@ -429,10 +419,6 @@ function get_items_manage_table_headers(): string /** * Get the html data row for the item - * - * @property attribute $attribute - * @property item_taxes $item_taxes - * @property tax_category $tax_category */ function get_item_data_row(object $item): array { @@ -676,7 +662,7 @@ function get_attribute_definition_manage_table_headers(): string function get_attribute_definition_data_row(object $attribute_row): array { - $attribute = model('Attribute'); + $attribute = model(Attribute::class); $controller = get_controller(); if(count($attribute->get_definition_flags()) == 0) diff --git a/app/Libraries/Barcode_lib.php b/app/Libraries/Barcode_lib.php index 6154bc1b1..aa801993a 100644 --- a/app/Libraries/Barcode_lib.php +++ b/app/Libraries/Barcode_lib.php @@ -2,6 +2,7 @@ namespace App\Libraries; +use Config\OSPOS; use Exception; use Picqer\Barcode\BarcodeGeneratorPNG; use App\Libraries\Barcodes\Code39; @@ -14,10 +15,9 @@ use App\Libraries\Barcodes\Ean13; * * Library with utilities to manage barcodes */ - class Barcode_lib { - private $supported_barcodes = [ + private array $supported_barcodes = [ 'Code39' => 'Code 39', 'Code128' => 'Code 128', 'Ean8' => 'EAN 8', diff --git a/app/Libraries/Email_lib.php b/app/Libraries/Email_lib.php index f20be3151..8ebfd8585 100644 --- a/app/Libraries/Email_lib.php +++ b/app/Libraries/Email_lib.php @@ -13,15 +13,13 @@ use Config\Services; * Email library * * Library with utilities to configure and send emails - * - * @property email email - * @property encryption encryption - * @property encrypterinterface encrypter - * @property array config */ class Email_lib { + private Email $email; + private array $config; + public function __construct() { $this->email = new Email(); @@ -38,7 +36,7 @@ class Email_lib $email_config = [ 'mailtype' => 'html', 'useragent' => 'OSPOS', - 'validate' => TRUE, + 'validate' => true, 'protocol' => $this->config['protocol'], 'mailpath' => $this->config['mailpath'], 'smtp_host' => $this->config['smtp_host'], diff --git a/app/Libraries/Item_lib.php b/app/Libraries/Item_lib.php index 9f4687caa..6cafc6d92 100644 --- a/app/Libraries/Item_lib.php +++ b/app/Libraries/Item_lib.php @@ -10,20 +10,17 @@ use App\Models\Stock_location; * Item library * * Library with utilities to manage items - * - * @property session session - * @property stock_location stock_location - */ + **/ class Item_lib { private Session $session; - private Model $stock_location; + private Stock_location $stock_location; public function __construct() { $this->session = Session(); - $this->stock_location = model('Stock_location'); + $this->stock_location = model(Stock_location::class); } public function get_item_location(): string diff --git a/app/Libraries/Receiving_lib.php b/app/Libraries/Receiving_lib.php index 9be4df62b..8459a88d1 100644 --- a/app/Libraries/Receiving_lib.php +++ b/app/Libraries/Receiving_lib.php @@ -10,33 +10,32 @@ use App\Models\Receiving; use App\Models\Stock_location; use CodeIgniter\Session\Session; +use Config\OSPOS; /** * Receiving library * * Library with utilities to manage receivings - * - * @property attribute attribute - * @property item item - * @property item_kit_items item_kit_items - * @property item_quantity item_quantity - * @property receiving receiving - * @property stock_location stock_location - * - * @property session session - * */ class Receiving_lib { + private Attribute $attribute; + private Item $item; + private Item_kit_items $item_kit_items; + private Item_quantity $item_quantity; + private Receiving $receiving; + private Stock_location $stock_location; + private Session $session; + public function __construct() { - $this->attribute = model('Attribute'); - $this->item = model('Item'); - $this->item_kit_items = model('Item_kit_items'); - $this->item_quantity = model('Item_quantity'); - $this->receiving = model('Receiving'); - $this->stock_location = model('Stock_location'); - + $this->attribute = model(Attribute::class); + $this->item = model(Item::class); + $this->item_kit_items = model(Item_kit_items::class); + $this->item_quantity = model(Item_quantity::class); + $this->receiving = model(Receiving::class); + $this->stock_location = model(Stock_location::class); + $this->session = session(); } @@ -94,7 +93,7 @@ class Receiving_lib { $this->session->set('recv_mode', $mode); } - + public function clear_mode(): void //TODO: This function verb is inconsistent from the others. Consider refactoring to remove_mode() { $this->session->remove('recv_mode'); @@ -109,60 +108,60 @@ class Receiving_lib return $this->session->get('recv_stock_source'); } - + public function get_comment(): string { $comment = $this->session->get('recv_comment'); return empty($comment) ? '' : $comment; } - + public function set_comment(string $comment): void { $this->session->set('recv_comment', $comment); } - + public function clear_comment(): void //TODO: This function verb is inconsistent from the others. Consider refactoring to remove_comment() { $this->session->remove('recv_comment'); } - + public function get_reference(): ?string { return $this->session->get('recv_reference'); } - + public function set_reference(string $reference): void { $this->session->set('recv_reference', $reference); } - + public function clear_reference(): void //TODO: This function verb is inconsistent from the others. Consider refactoring to remove_reference() { $this->session->remove('recv_reference'); } - + public function is_print_after_sale(): bool { return $this->session->get('recv_print_after_sale') == 'true' || $this->session->get('recv_print_after_sale') == '1'; } - + public function set_print_after_sale(bool $print_after_sale): void { $this->session->set('recv_print_after_sale', $print_after_sale); } - + public function set_stock_source(int $stock_source): void { $this->session->set('recv_stock_source', $stock_source); } - + public function clear_stock_source(): void { $this->session->remove('recv_stock_source'); } - + public function get_stock_destination(): string { if(!$this->session->get('recv_stock_destination')) @@ -177,7 +176,7 @@ class Receiving_lib { $this->session->set('recv_stock_destination', $stock_destination); } - + public function clear_stock_destination(): void { $this->session->remove('recv_stock_destination'); @@ -260,8 +259,6 @@ class Receiving_lib $attribute_links = $this->attribute->get_link_values($item_id, 'receiving_id', $receiving_id, Attribute::SHOW_IN_RECEIVINGS)->getRowObject(); - $item_quantity = model(Item_quantity::class); - $item = [ $insertkey => [ 'item_id' => $item_id, @@ -279,7 +276,7 @@ class Receiving_lib 'quantity' => $quantity, 'discount' => $discount, 'discount_type' => $discount_type, - 'in_stock' => $item_quantity->get_item_quantity($item_id, $item_location)->quantity, + 'in_stock' => $this->item_quantity->get_item_quantity($item_id, $item_location)->quantity, 'price' => $price, 'receiving_quantity' => $receiving_quantity, 'receiving_quantity_choices' => $receiving_quantity_choices, @@ -347,8 +344,8 @@ class Receiving_lib if(preg_match("/(RECV|KIT)/", $pieces[0])) //TODO: this needs to be converted to ternary notation. { $receiving_id = $pieces[1]; - } - else + } + else { $receiving_id = $this->receiving->get_receiving_by_reference($receipt_receiving_id)->getRow()->receiving_id; } @@ -370,7 +367,7 @@ class Receiving_lib //KIT # $pieces = explode(' ',$external_item_kit_id); $item_kit_id = count($pieces) > 1 ? $pieces[1] : $external_item_kit_id; - + foreach($this->item_kit_items->get_info($item_kit_id) as $item_kit_item) { $this->add_item($item_kit_item['item_id'], $item_kit_item['quantity'], $item_location, $discount, $discount_type); @@ -422,7 +419,7 @@ class Receiving_lib { $total = bcadd($total, $this->get_item_total(($item['quantity']), $item['price'], $item['discount'], $item['discount_type'], $item['receiving_quantity'])); } - + return $total; } } diff --git a/app/Libraries/Sale_lib.php b/app/Libraries/Sale_lib.php index 04ea5809b..ac25ca042 100644 --- a/app/Libraries/Sale_lib.php +++ b/app/Libraries/Sale_lib.php @@ -20,37 +20,34 @@ use ReflectionException; * Sale library * * Library with utilities to manage sales - * - * @property attribute attribute - * @property customer customer - * @property dinner_table dinner_table - * @property item item - * @property item_kit_items item_kit_items - * @property item_quantity item_quantity - * @property item_taxes item_taxes - * @property rounding_mode rounding_mode - * @property sale sale - * @property stock_location stock_location - * @property Tax_lib tax_lib - * @property session session - * @property array config - */ + **/ class Sale_lib { + private Attribute $attribute; + private Customer $customer; + private Dinner_table $dinner_table; + private Item $item; + private Item_kit_items $item_kit_items; + private Item_quantity $item_quantity; + private Item_taxes $item_taxes; + private Sale $sale; + private Stock_location $stock_location; + private Session $session; + private array $config; + public function __construct() { $this->session = session(); - $this->attribute = model('Attribute'); - $this->customer = model('Customer'); - $this->dinner_table = model('Dinner_table'); - $this->item = model('Item'); - $this->item_kit_items = model('Item_kit_items'); - $this->item_quantity = model('Item_quantity'); - $this->item_taxes = model('Item_taxes'); - $this->rounding_mode = model('enums/Rounding_mode'); -// $this->sale = model('Sale'); //TODO: This is causing an infinite loop because the constructor calls the sale library - $this->stock_location = model('Stock_location'); + $this->attribute = model(Attribute::class); + $this->customer = model(Customer::class); + $this->dinner_table = model(Dinner_table::class); + $this->item = model(Item::class); + $this->item_kit_items = model(Item_kit_items::class); + $this->item_quantity = model(Item_quantity::class); + $this->item_taxes = model(Item_taxes::class); + $this->sale = model(Sale::class); + $this->stock_location = model(Stock_location::class); $this->config = config(OSPOS::class)->settings; } @@ -938,8 +935,6 @@ class Sale_lib //Item already exists and is not serialized, add to quantity if(!$itemalreadyinsale || $item_info->is_serialized) { - $item_quantity = model(Item_quantity::class); - $item = [ $insertkey => [ 'item_id' => $item_id, @@ -957,7 +952,7 @@ class Sale_lib 'quantity' => $quantity, 'discount' => $applied_discount, 'discount_type' => $discount_type, - 'in_stock' => $item_quantity->get_item_quantity($item_id, $item_location)->quantity, + 'in_stock' => $this->item_quantity->get_item_quantity($item_id, $item_location)->quantity, 'price' => $price, 'cost_price' => $cost_price, 'total' => $total, @@ -995,8 +990,7 @@ class Sale_lib if($item_info->stock_type == HAS_STOCK) //TODO: === ? { - $item_quantity = model(Item_quantity::class); - $item_quantity = $item_quantity->get_item_quantity($item_id, $item_location)->quantity; + $item_quantity = $this->item_quantity->get_item_quantity($item_id, $item_location)->quantity; $quantity_added = $this->get_quantity_already_added($item_id, $item_location); if($item_quantity - $quantity_added < 0) @@ -1425,9 +1419,9 @@ class Sale_lib if(!$this->config['tax_included']) { $cart = $this->get_cart(); - $this->tax_lib = new \app\Libraries\Tax_lib(); + $tax_lib = new Tax_lib(); - foreach($this->tax_lib->get_taxes($cart)[0] as $tax) + foreach($tax_lib->get_taxes($cart)[0] as $tax) { $total = bcadd($total, $tax['sale_tax_amount']); } diff --git a/app/Libraries/Sms_lib.php b/app/Libraries/Sms_lib.php index 5565069c8..aa2599c92 100644 --- a/app/Libraries/Sms_lib.php +++ b/app/Libraries/Sms_lib.php @@ -4,6 +4,7 @@ namespace app\Libraries; use CodeIgniter\Encryption\Encryption; use CodeIgniter\Encryption\EncrypterInterface; +use Config\OSPOS; use Config\Services; @@ -11,18 +12,14 @@ use Config\Services; * SMS library * * Library with utilities to send texts via SMS Gateway (requires proxy implementation) - * - * @property encryption encryption - * @property encrypterinterface encrypter - * */ class Sms_lib { - /* + /** * SMS sending function * Example of use: $response = sendSMS('4477777777', 'My test message'); - */ + **/ public function sendSMS(int $phone, string $message): bool { $config = config(OSPOS::class)->settings; diff --git a/app/Libraries/Tax_lib.php b/app/Libraries/Tax_lib.php index f3142df6a..0f2346db3 100644 --- a/app/Libraries/Tax_lib.php +++ b/app/Libraries/Tax_lib.php @@ -17,37 +17,32 @@ use Config\OSPOS; * Tax library * * Library with utilities to manage taxes - * - * @property sale_lib sale_lib - * @property customer customer - * @property item_taxes item_taxes - * @property rounding_mode rounding_mode - * @property sale sale - * @property tax tax - * @property tax_category tax_category - * @property tax_code tax_code - * @property tax_jurisdiction tax_jurisdiction - * @property array config - * - */ - + **/ class Tax_lib { const TAX_TYPE_EXCLUDED = '1'; //TODO: These constants need to be moved to constants.php const TAX_TYPE_INCLUDED = '0'; + private Sale_lib $sale_lib; + private Customer $customer; + private Item_taxes $item_taxes; + private Sale $sale; + private Tax $tax; + private Tax_category $tax_category; + private Tax_code $tax_code; + private Tax_jurisdiction $tax_jurisdiction; + private array $config; public function __construct() { $this->sale_lib = new Sale_lib(); - $this->customer = model('Customer'); - $this->item_taxes = model('Item_taxes'); - $this->rounding_mode = model('Rounding_mode'); - $this->sale = model('Sale'); - $this->tax = model('Tax'); - $this->tax_category = model('Tax_category'); - $this->tax_code = model('Tax_code'); - $this->tax_jurisdiction = model('Tax_jurisdiction'); + $this->customer = model(Customer::class); + $this->item_taxes = model(Item_taxes::class); + $this->sale = model(Sale::class); + $this->tax = model(Tax::class); + $this->tax_category = model(Tax_category::class); + $this->tax_code = model(Tax_code::class); + $this->tax_jurisdiction = model(Tax_jurisdiction::class); $this->config = config(OSPOS::class)->settings; } diff --git a/app/Libraries/Token_lib.php b/app/Libraries/Token_lib.php index 0b36fbd20..96ab6aedf 100644 --- a/app/Libraries/Token_lib.php +++ b/app/Libraries/Token_lib.php @@ -3,6 +3,7 @@ namespace app\Libraries; use App\Models\Tokens\Token; +use Config\OSPOS; /** * Token library diff --git a/app/Models/Cashup.php b/app/Models/Cashup.php index 0fcb54355..e1197f24a 100644 --- a/app/Models/Cashup.php +++ b/app/Models/Cashup.php @@ -4,14 +4,13 @@ namespace App\Models; use CodeIgniter\Database\ResultInterface; use CodeIgniter\Model; +use Config\OSPOS; use stdClass; /** * Cashup class - * - * @property employee employee + * Cashups are used to report actual cash on hand, expenses and transactions at the end of a period. */ - class Cashup extends Model { protected $table = 'cash_up'; diff --git a/app/Models/Customer.php b/app/Models/Customer.php index cc1d3f4ae..603193f89 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -3,6 +3,7 @@ namespace App\Models; use CodeIgniter\Database\ResultInterface; +use Config\OSPOS; /** * Customer class diff --git a/app/Models/Expense.php b/app/Models/Expense.php index 42fd94769..c22cc343b 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -4,13 +4,11 @@ namespace App\Models; use CodeIgniter\Database\ResultInterface; use CodeIgniter\Model; +use Config\OSPOS; use stdClass; /** * Expense class - * - * @property employee employee - * @property expense_category expense_category */ class Expense extends Model { @@ -86,6 +84,15 @@ class Expense extends Model /** * Searches expenses + * + * @param string $search + * @param array $filters + * @param int|null $rows + * @param int|null $limit_from + * @param string|null $sort + * @param string|null $order + * @param bool|null $count_only + * @return ResultInterface|false|string */ public function search(string $search, array $filters, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'expense_id', ?string $order = 'asc', ?bool $count_only = FALSE) { @@ -100,7 +107,7 @@ class Expense extends Model $builder = $this->db->table('expenses AS expenses'); // get_found_rows case - if($count_only) //TODO: replace this with `if($count_only)` + if($count_only) { $builder->select('COUNT(DISTINCT expenses.expense_id) as count'); } diff --git a/app/Models/Item_kit.php b/app/Models/Item_kit.php index db1307fa3..4425061a9 100644 --- a/app/Models/Item_kit.php +++ b/app/Models/Item_kit.php @@ -4,6 +4,7 @@ namespace App\Models; use CodeIgniter\Database\ResultInterface; use CodeIgniter\Model; +use Config\OSPOS; use stdClass; /** diff --git a/app/Models/Receiving.php b/app/Models/Receiving.php index 78a6475b9..efab75e9a 100644 --- a/app/Models/Receiving.php +++ b/app/Models/Receiving.php @@ -4,16 +4,11 @@ namespace App\Models; use CodeIgniter\Database\ResultInterface; use CodeIgniter\Model; +use Config\OSPOS; use ReflectionException; /** * Receiving class - * - * @property attribute attribute - * @property inventory inventory - * @property item item - * @property item_quantity item_quantity - * @property supplier supplier */ class Receiving extends Model { diff --git a/app/Models/Reports/Summary_discounts.php b/app/Models/Reports/Summary_discounts.php index 87931403b..4d2cd1458 100644 --- a/app/Models/Reports/Summary_discounts.php +++ b/app/Models/Reports/Summary_discounts.php @@ -2,6 +2,8 @@ namespace App\Models\Reports; +use Config\OSPOS; + class Summary_discounts extends Summary_report { protected function _get_data_columns(): array //TODO: Hungarian notation diff --git a/app/Models/Reports/Summary_expenses_categories.php b/app/Models/Reports/Summary_expenses_categories.php index 900033547..ea66075da 100644 --- a/app/Models/Reports/Summary_expenses_categories.php +++ b/app/Models/Reports/Summary_expenses_categories.php @@ -2,6 +2,8 @@ namespace App\Models\Reports; +use Config\OSPOS; + class Summary_expenses_categories extends Summary_report { protected function _get_data_columns(): array //TODO: Hungarian notation diff --git a/app/Models/Reports/Summary_payments.php b/app/Models/Reports/Summary_payments.php index 01bcd12b2..502fc675a 100644 --- a/app/Models/Reports/Summary_payments.php +++ b/app/Models/Reports/Summary_payments.php @@ -2,6 +2,8 @@ namespace App\Models\Reports; +use Config\OSPOS; + class Summary_payments extends Summary_report { protected function _get_data_columns(): array //TODO: Hungarian notation diff --git a/app/Models/Reports/Summary_report.php b/app/Models/Reports/Summary_report.php index 88714b725..9b776c1f9 100644 --- a/app/Models/Reports/Summary_report.php +++ b/app/Models/Reports/Summary_report.php @@ -2,6 +2,8 @@ namespace App\Models\Reports; +use Config\OSPOS; + abstract class Summary_report extends Report { /** @@ -167,8 +169,8 @@ abstract class Summary_report extends Report protected function _group_order(object &$builder): void {} //TODO: hungarian notation /** - * Public interface implementing the base abstract class, - * in general it should not be extended unless there is a valid reason + * Public interface implementing the base abstract class, + * in general it should not be extended unless there is a valid reason * like a non sale report (e.g. expenses) */ diff --git a/app/Models/Reports/Summary_sales_taxes.php b/app/Models/Reports/Summary_sales_taxes.php index 9c1f4bf29..395c6bf0e 100644 --- a/app/Models/Reports/Summary_sales_taxes.php +++ b/app/Models/Reports/Summary_sales_taxes.php @@ -2,8 +2,18 @@ namespace App\Models\Reports; +use Config\OSPOS; + class Summary_sales_taxes extends Summary_report { + private array $config; + + public function __construct() + { + parent::__construct(); + $this->config = config(OSPOS::class)->settings; + } + protected function _get_data_columns(): array //TODO: hungarian notation { return [ @@ -17,11 +27,9 @@ class Summary_sales_taxes extends Summary_report protected function _where(array $inputs, object &$builder): void //TODO: hungarian notation { - $config = config(OSPOS::class)->settings; - $builder->where('sales.sale_status', COMPLETED); - if(empty($config['date_or_time_format'])) //TODO: Duplicated code + if(empty($this->config['date_or_time_format'])) //TODO: Duplicated code { $builder->where('DATE(sales.sale_time) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date'])); } @@ -33,11 +41,9 @@ class Summary_sales_taxes extends Summary_report public function getData(array $inputs): array { - $config = config(OSPOS::class)->settings; - $where = 'WHERE sale_status = ' . COMPLETED . ' '; - if(empty($config['date_or_time_format'])) + if(empty($this->config['date_or_time_format'])) { $where .= 'AND DATE(sale_time) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date']); diff --git a/app/Models/Reports/Summary_taxes.php b/app/Models/Reports/Summary_taxes.php index f5369f5f4..aff5cd58a 100644 --- a/app/Models/Reports/Summary_taxes.php +++ b/app/Models/Reports/Summary_taxes.php @@ -2,8 +2,18 @@ namespace App\Models\Reports; +use Config\OSPOS; + class Summary_taxes extends Summary_report { + private array $config; + + public function __construct() + { + parent::__construct(); + $this->config = config(OSPOS::class)->settings; + } + protected function _get_data_columns(): array //TODO: hungarian notation { return [ @@ -18,11 +28,9 @@ class Summary_taxes extends Summary_report protected function _where(array $inputs, &$builder): void //TODO: hungarian notation { - $config = config(OSPOS::class)->settings; - $builder->where('sales.sale_status', COMPLETED); - if(empty($config['date_or_time_format'])) + if(empty($this->config['date_or_time_format'])) { $builder->where('DATE(sales.sale_time) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date'])); } @@ -34,11 +42,10 @@ class Summary_taxes extends Summary_report public function getData(array $inputs): array { - $config = config(OSPOS::class)->settings; $where = 'WHERE sale_status = ' . COMPLETED . ' '; //TODO: Duplicated code - if(empty($config['date_or_time_format'])) //TODO: Ternary notation + if(empty($this->config['date_or_time_format'])) //TODO: Ternary notation { $where .= 'AND DATE(sale_time) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date']); } @@ -48,7 +55,7 @@ class Summary_taxes extends Summary_report } $decimals = totals_decimals(); - if($config['tax_included']) + if($this->config['tax_included']) { $sale_total = '(CASE WHEN sales_items.discount_type = ' . PERCENT . " THEN sales_items.quantity_purchased * sales_items.item_unit_price - ROUND(sales_items.quantity_purchased * sales_items.item_unit_price * sales_items.discount / 100, $decimals)" diff --git a/app/Models/Sale.php b/app/Models/Sale.php index ad059171b..59cd4b034 100644 --- a/app/Models/Sale.php +++ b/app/Models/Sale.php @@ -5,23 +5,11 @@ namespace App\Models; use CodeIgniter\Database\ResultInterface; use CodeIgniter\Model; use App\Libraries\Sale_lib; +use Config\OSPOS; use ReflectionException; /** * Sale class - * - * @property attribute attribute - * @property customer customer - * @property customer_rewards customer_rewards - * @property dinner_table dinner_table - * @property employee employee - * @property giftcard giftcard - * @property inventory inventory - * @property item item - * @property item_quantity item_quantity - * @property rewards rewards - * - * @property Sale_lib sale_lib */ class Sale extends Model { @@ -46,7 +34,6 @@ class Sale extends Model { parent::__construct(); helper('text'); - $this->sale_lib = new Sale_lib(); } /** @@ -1076,8 +1063,8 @@ class Sale extends Model { $payments[lang('Sales.rewards')] = lang('Sales.rewards'); } - - if($this->sale_lib->get_mode() == 'sale_work_order') + $sale_lib = new Sale_lib(); + if($sale_lib->get_mode() == 'sale_work_order') { $payments[lang('Sales.cash_deposit')] = lang('Sales.cash_deposit'); $payments[lang('Sales.credit_deposit')] = lang('Sales.credit_deposit'); diff --git a/app/Models/Supplier.php b/app/Models/Supplier.php index a88f3159d..d88c9b1a5 100644 --- a/app/Models/Supplier.php +++ b/app/Models/Supplier.php @@ -263,14 +263,14 @@ class Supplier extends Person /** * Perform a search on suppliers */ - public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'last_name', ?string $order = 'asc', ?bool $count_only = FALSE) + public function search(string $search, ?int $rows = 25, ?int $limit_from = 0, ?string $sort = 'last_name', ?string $order = 'asc', ?bool $count_only = false) { - // Set default values - if($rows == null) $rows = 0; - if($limit_from == null) $limit_from = 0; - if($sort == null) $sort = 'last_name'; - if($order == null) $order = 'asc'; - if($count_only == null) $count_only = FALSE; + //Set default values on null + $rows = $rows ?? 25; + $limit_from = $limit_from ?? 0; + $sort = $sort ?? 'last_name'; + $order = $order ?? 'asc'; + $count_only = $count_only ?? false; $builder = $this->db->table('suppliers AS suppliers'); diff --git a/app/Models/Tax_code.php b/app/Models/Tax_code.php index 0cc78e0c1..43a679833 100644 --- a/app/Models/Tax_code.php +++ b/app/Models/Tax_code.php @@ -4,6 +4,7 @@ namespace App\Models; use CodeIgniter\Database\ResultInterface; use CodeIgniter\Model; +use Config\OSPOS; use stdClass; /** diff --git a/app/Models/Tokens/Token_customer.php b/app/Models/Tokens/Token_customer.php index 83575e831..458f3a2e8 100644 --- a/app/Models/Tokens/Token_customer.php +++ b/app/Models/Tokens/Token_customer.php @@ -8,15 +8,11 @@ use App\Models\Customer; /** * Token_customer class - * - * @property sale_lib sale_lib - * - * @property customer customer - * - */ + **/ class Token_customer extends Token { private string $customer_info; + private Sale_lib $sale_lib; public function __construct(string $customer_info = '') { diff --git a/app/Models/Tokens/Token_invoice_sequence.php b/app/Models/Tokens/Token_invoice_sequence.php index 38b1bb373..22c096bce 100644 --- a/app/Models/Tokens/Token_invoice_sequence.php +++ b/app/Models/Tokens/Token_invoice_sequence.php @@ -7,16 +7,16 @@ use ReflectionException; /** * Token_invoice_sequence class - * - * @property appconfig appconfig - */ + **/ class Token_invoice_sequence extends Token { + private Appconfig $appconfig; + public function __construct(string $value = '') { parent::__construct($value); - $this->appconfig = model('Appconfig'); + $this->appconfig = model(Appconfig::class); } public function token_id(): string @@ -31,4 +31,4 @@ class Token_invoice_sequence extends Token { return $this->appconfig->acquire_next_invoice_sequence($save); } -} \ No newline at end of file +} diff --git a/app/Models/Tokens/Token_quote_sequence.php b/app/Models/Tokens/Token_quote_sequence.php index 4cfa6cb51..b45ab29c0 100644 --- a/app/Models/Tokens/Token_quote_sequence.php +++ b/app/Models/Tokens/Token_quote_sequence.php @@ -7,16 +7,15 @@ use ReflectionException; /** * Token_quote_sequence class - * - * @property appconfig appconfig - * - */ + **/ class Token_quote_sequence extends Token { + private Appconfig $appconfig; + public function __construct() { parent::__construct(); - $this->appconfig = model('AppConfig'); + $this->appconfig = model(AppConfig::class); } @@ -32,4 +31,4 @@ class Token_quote_sequence extends Token { return $this->appconfig->acquire_next_quote_sequence($save); } -} \ No newline at end of file +} diff --git a/app/Models/Tokens/Token_work_order_sequence.php b/app/Models/Tokens/Token_work_order_sequence.php index 13beb396e..5a48af15e 100644 --- a/app/Models/Tokens/Token_work_order_sequence.php +++ b/app/Models/Tokens/Token_work_order_sequence.php @@ -7,16 +7,15 @@ use ReflectionException; /** * Token_work_order_sequence class - * - * @property appconfig appconfig - * - */ + **/ class Token_work_order_sequence extends Token { + private Appconfig $appconfig; + public function __construct(string $value = '') { parent::__construct($value); - $this->appconfig = model('AppConfig'); + $this->appconfig = model(AppConfig::class); } public function token_id(): string @@ -31,4 +30,4 @@ class Token_work_order_sequence extends Token { return $this->appconfig->acquire_next_work_order_sequence($save); } -} \ No newline at end of file +} diff --git a/app/Views/configs/system_info.php b/app/Views/configs/system_info.php index 35143f635..4765f8571 100644 --- a/app/Views/configs/system_info.php +++ b/app/Views/configs/system_info.php @@ -1,3 +1,6 @@ +