From fafa6aff4ea7f2cad8db389bd411797cb68fe9cd Mon Sep 17 00:00:00 2001 From: objecttothis Date: Mon, 6 May 2024 17:45:27 +0400 Subject: [PATCH] - Removed TODOs that had been completed - Added TODO where we need to convert to querybuilder - Converted to switch statement. - Removed unnecessary local variable - Replaced Qualifiers with imports - Replaced isset() call with null coalescing operator - Replaced strpos function calls in if statements with str_contains calls - Removed unnecessary leading \ in use statement - Replaced deprecated functions - Updated PHPdocs to match function signature - Added missing type declarations - Made class variables private. - Explicitly declared dynamic properties - use https:// links instead of http:// - Fixed type error from sending null when editing transactions - Fixed Search Suggestion function name in Employees, Persons, Suppliers controller - Fixed function name on Receivings Controller Signed-off-by: objecttothis --- app/Config/Mimes.php | 11 +- app/Controllers/Config.php | 4 +- app/Controllers/Employees.php | 2 +- app/Controllers/Items.php | 4 +- app/Controllers/Login.php | 2 +- app/Controllers/No_access.php | 4 +- app/Controllers/Persons.php | 4 +- app/Controllers/Receivings.php | 6 +- app/Controllers/Sales.php | 48 +++--- app/Controllers/Suppliers.php | 2 +- app/Controllers/Tax_categories.php | 4 +- app/Controllers/Tax_codes.php | 4 +- app/Controllers/Tax_jurisdictions.php | 4 +- .../20170502221506_sales_tax_data.php | 9 +- .../Migrations/20200202000000_taxamount.php | 3 +- .../20210422000000_database_optimizations.php | 2 +- .../20210422000001_remove_duplicate_links.php | 2 +- .../20220127000000_convert_to_ci4.php | 3 +- .../20230307000000_int_to_tinyint.php | 2 +- app/Events/Method.php | 2 +- app/Helpers/locale_helper.php | 8 +- app/Helpers/report_helper.php | 2 +- app/Helpers/security_helper.php | 4 +- app/Libraries/Barcode_lib.php | 2 +- app/Libraries/MY_Email.php | 10 +- app/Libraries/MY_Migration.php | 6 +- app/Libraries/Mailchimp_lib.php | 24 +-- app/Libraries/Receiving_lib.php | 8 +- app/Libraries/Sale_lib.php | 10 +- app/Libraries/Token_lib.php | 31 ++-- app/Models/Appconfig.php | 2 +- app/Models/Attribute.php | 11 +- app/Models/Customer.php | 3 +- app/Models/Expense.php | 7 +- app/Models/Inventory.php | 2 +- app/Models/Item.php | 8 +- app/Models/Item_kit.php | 4 +- app/Models/Item_kit_items.php | 2 +- app/Models/Item_quantity.php | 2 +- app/Models/Item_taxes.php | 2 +- app/Models/Reports/Detailed_receivings.php | 23 +-- app/Models/Reports/Detailed_sales.php | 142 ++++++++--------- app/Models/Reports/Inventory_low.php | 2 +- app/Models/Reports/Specific_customer.php | 145 +++++++++--------- app/Models/Reports/Specific_discount.php | 71 ++++----- app/Models/Reports/Specific_employee.php | 71 ++++----- app/Models/Reports/Specific_supplier.php | 142 ++++++++--------- app/Models/Reports/Summary_discounts.php | 2 +- app/Models/Reports/Summary_employees.php | 1 - app/Models/Reports/Summary_payments.php | 5 +- app/Models/Reports/Summary_report.php | 11 +- app/Models/Reports/Summary_suppliers.php | 3 - app/Models/Sale.php | 6 +- app/Models/Stock_location.php | 3 +- app/Models/Tax.php | 2 +- app/Models/Tax_code.php | 2 +- app/Models/Tax_jurisdiction.php | 2 +- app/Models/Tokens/Token.php | 2 +- app/Views/cashups/form.php | 4 +- app/Views/configs/integrations_config.php | 2 +- app/Views/configs/locale_config.php | 2 +- app/Views/items/form.php | 2 +- app/Views/partial/datepicker_locale.php | 6 +- app/Views/sales/form.php | 2 +- 64 files changed, 463 insertions(+), 460 deletions(-) diff --git a/app/Config/Mimes.php b/app/Config/Mimes.php index 7722444abe..e47cc0fae6 100644 --- a/app/Config/Mimes.php +++ b/app/Config/Mimes.php @@ -490,11 +490,12 @@ class Mimes * * @return string|null The mime type found, or none if unable to determine. */ - public static function guessTypeFromExtension(string $extension) - { + public static function guessTypeFromExtension(string $extension): array|string|null + { $extension = trim(strtolower($extension), '. '); - if (! array_key_exists($extension, static::$mimes)) { + if (!array_key_exists($extension, static::$mimes)) + { return null; } @@ -508,8 +509,8 @@ public static function guessTypeFromExtension(string $extension) * * @return string|null The extension determined, or null if unable to match. */ - public static function guessExtensionFromType(string $type, ?string $proposedExtension = null) - { + public static function guessExtensionFromType(string $type, ?string $proposedExtension = null): ?string + { $type = trim(strtolower($type), '. '); $proposedExtension = trim(strtolower($proposedExtension ?? '')); diff --git a/app/Controllers/Config.php b/app/Controllers/Config.php index 2039b25fd5..6d084d4046 100644 --- a/app/Controllers/Config.php +++ b/app/Controllers/Config.php @@ -714,7 +714,7 @@ public function postSaveLocations(): void $not_to_delete = []; foreach($this->request->getPost() as $key => $value) { - if(strstr($key, 'stock_location')) + if(str_contains($key, 'stock_location')) { // save or update foreach ($value as $location_id => $location_name) @@ -854,7 +854,7 @@ public function postSaveRewards(): void $not_to_delete[] = $customer_reward_id; $array_save[$customer_reward_id]['package_name'] = $value; } - elseif(strstr($key, 'reward_points')) + elseif(str_contains($key, 'reward_points')) { $customer_reward_id = preg_replace("/.*?_(\d+)$/", "$1", $key); $array_save[$customer_reward_id]['points_percent'] = $value; diff --git a/app/Controllers/Employees.php b/app/Controllers/Employees.php index ac770ffdc0..656d25cba8 100644 --- a/app/Controllers/Employees.php +++ b/app/Controllers/Employees.php @@ -49,7 +49,7 @@ public function getSearch(): void * * @return void */ - public function suggest(): void + public function getSuggest(): void { $suggestions = $this->employee->get_search_suggestions($this->request->getGet('term', FILTER_SANITIZE_FULL_SPECIAL_CHARS), 25, true); diff --git a/app/Controllers/Items.php b/app/Controllers/Items.php index 28c0761d16..5b17c894ae 100644 --- a/app/Controllers/Items.php +++ b/app/Controllers/Items.php @@ -989,7 +989,6 @@ public function postBulkUpdate(): void } /** - * @throws ReflectionException */ public function postDelete(): void { @@ -1008,8 +1007,7 @@ public function postDelete(): void /** * Generates a template CSV file for item import/update containing headers for current stock locations and attributes - * @return void - * @noinspection PhpUnused + * @return DownloadResponse */ public function getGenerateCsvFile(): DownloadResponse { diff --git a/app/Controllers/Login.php b/app/Controllers/Login.php index 71aa601204..61448420d8 100644 --- a/app/Controllers/Login.php +++ b/app/Controllers/Login.php @@ -19,7 +19,7 @@ class Login extends BaseController /** * @return RedirectResponse|string */ - public function index() + public function index(): string|RedirectResponse { $this->employee = model(Employee::class); if(!$this->employee->is_logged_in()) diff --git a/app/Controllers/No_access.php b/app/Controllers/No_access.php index 2890511533..3153bba315 100644 --- a/app/Controllers/No_access.php +++ b/app/Controllers/No_access.php @@ -12,9 +12,11 @@ */ class No_access extends BaseController { + private Module $module; + public function __construct() { - $this->module = model('Module'); + $this->module = model(Module::class); } /** diff --git a/app/Controllers/Persons.php b/app/Controllers/Persons.php index 34290f3085..15f3d2cc8a 100644 --- a/app/Controllers/Persons.php +++ b/app/Controllers/Persons.php @@ -3,7 +3,7 @@ namespace App\Controllers; use App\Models\Person; -use function \Tamtamchik\NameCase\str_name_case; +use function Tamtamchik\NameCase\str_name_case; abstract class Persons extends Secure_Controller { @@ -32,7 +32,7 @@ public function getIndex(): void /** * Gives search suggestions based on what is being searched for */ - public function suggest(): void + public function getSuggest(): void { $suggestions = $this->person->get_search_suggestions($this->request->getPost('term', FILTER_SANITIZE_FULL_SPECIAL_CHARS)); diff --git a/app/Controllers/Receivings.php b/app/Controllers/Receivings.php index fc84346182..8c58c5e5ad 100644 --- a/app/Controllers/Receivings.php +++ b/app/Controllers/Receivings.php @@ -80,7 +80,7 @@ public function getStockItemSearch(): void * Called in the view. * @return void */ - public function select_supplier(): void + public function postSelect_supplier(): void { $supplier_id = $this->request->getPost('supplier', FILTER_SANITIZE_NUMBER_INT); if($this->supplier->exists($supplier_id)) @@ -427,10 +427,10 @@ public function receipt($receiving_id): void } /** - * @param $data + * @param array $data * @return void */ - private function _reload($data = []): void //TODO: Hungarian notation + private function _reload(array $data = []): void //TODO: Hungarian notation { $data['cart'] = $this->receiving_lib->get_cart(); $data['modes'] = ['receive' => lang('Receivings.receiving'), 'return' => lang('Receivings.return')]; diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php index 277c87a1f4..d82c7a882b 100644 --- a/app/Controllers/Sales.php +++ b/app/Controllers/Sales.php @@ -23,6 +23,7 @@ use CodeIgniter\Config\Services; use Config\OSPOS; use ReflectionException; +use stdClass; class Sales extends Secure_Controller { @@ -282,26 +283,13 @@ public function postChangeMode(): void */ public function change_register_mode(int $sale_type): void { - switch ($sale_type) { - case SALE_TYPE_POS: - $mode = 'sale'; - break; - case SALE_TYPE_QUOTE: - $mode = 'sale_quote'; - break; - case SALE_TYPE_WORK_ORDER: - $mode = 'sale_work_order'; - break; - case SALE_TYPE_INVOICE: - $mode = 'sale_invoice'; - break; - case SALE_TYPE_RETURN: - $mode = 'return'; - break; - default: - $mode = 'sale'; - break; - } + $mode = match($sale_type) { + SALE_TYPE_QUOTE => 'sale_quote', + SALE_TYPE_WORK_ORDER => 'sale_work_order', + SALE_TYPE_INVOICE => 'sale_invoice', + SALE_TYPE_RETURN => 'return', + default => 'sale' //SALE_TYPE_POS + }; $this->sale_lib->set_mode($mode); } @@ -394,7 +382,7 @@ public function postAddPayment(): void //In the case of giftcard payment the register input amount_tendered becomes the giftcard number $amount_tendered = prepare_decimal($this->request->getPost('amount_tendered')); $giftcard_num = filter_var($amount_tendered, FILTER_SANITIZE_FULL_SPECIAL_CHARS, FILTER_FLAG_ALLOW_FRACTION); - + $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; @@ -1018,9 +1006,9 @@ public function send_receipt(int $sale_id): bool * @param int $customer_id * @param array $data * @param bool $stats - * @return array|object|\stdClass|string|null + * @return array|stdClass|string|null */ - private function _load_customer_data(int $customer_id, array &$data, bool $stats = false) //TODO: Hungarian notation + private function _load_customer_data(int $customer_id, array &$data, bool $stats = false): array|string|stdClass|null //TODO: Hungarian notation { $customer_info = ''; @@ -1204,10 +1192,10 @@ private function _load_sale_data($sale_id): array //TODO: Hungarian notation } /** - * @param $data + * @param array $data * @return void */ - private function _reload($data = []): void //TODO: Hungarian notation + private function _reload(array $data = []): void //TODO: Hungarian notation { $sale_id = $this->session->get('sale_id'); //TODO: This variable is never used @@ -1811,15 +1799,15 @@ public function change_item_description(): void } /** - * @param int $id - * @param array $array + * @param int $search_item_id + * @param array $shopping_cart * @return int|string|null */ - public function getSearch_cart_for_item_id(int $id, array $array) //TODO: The second parameter should not be named array perhaps int $needle_item_id, array $shopping_cart + public function getSearch_cart_for_item_id(int $search_item_id, array $shopping_cart): int|string|null { - foreach($array as $key => $val) //TODO: key and val are not reflective of the contents of the array and should be replaced with descriptive variable names. Perhaps $cart_haystack => $item_details + foreach($shopping_cart as $key => $val) { - if($val['item_id'] === $id) //TODO: Then this becomes more readable $item_details['item_id'] === $needle_item_id + if($val['item_id'] === $search_item_id) { return $key; } diff --git a/app/Controllers/Suppliers.php b/app/Controllers/Suppliers.php index 4d3084f3ad..82c6ac9fa4 100644 --- a/app/Controllers/Suppliers.php +++ b/app/Controllers/Suppliers.php @@ -68,7 +68,7 @@ public function getSearch(): void /** * Gives search suggestions based on what is being searched for **/ - public function suggest(): void + public function getSuggest(): void { $suggestions = $this->supplier->get_search_suggestions($this->request->getGet('term', FILTER_SANITIZE_FULL_SPECIAL_CHARS), true); diff --git a/app/Controllers/Tax_categories.php b/app/Controllers/Tax_categories.php index e1cf5e16bb..f8608fc264 100644 --- a/app/Controllers/Tax_categories.php +++ b/app/Controllers/Tax_categories.php @@ -9,11 +9,13 @@ */ class Tax_categories extends Secure_Controller { + private Tax_category $tax_category; + public function __construct() { parent::__construct('tax_categories'); - $this->tax_category = model('Tax_category'); + $this->tax_category = model(Tax_category::class); } /** diff --git a/app/Controllers/Tax_codes.php b/app/Controllers/Tax_codes.php index 7ee70198bd..fd7f868d78 100644 --- a/app/Controllers/Tax_codes.php +++ b/app/Controllers/Tax_codes.php @@ -9,11 +9,13 @@ */ class Tax_codes extends Secure_Controller { + private Tax_code $tax_code; + public function __construct() { parent::__construct('tax_codes'); - $this->tax_code = model('Tax_code'); + $this->tax_code = model(Tax_code::class); helper('tax_helper'); } diff --git a/app/Controllers/Tax_jurisdictions.php b/app/Controllers/Tax_jurisdictions.php index 5eafd0caec..0c1c77fdbf 100644 --- a/app/Controllers/Tax_jurisdictions.php +++ b/app/Controllers/Tax_jurisdictions.php @@ -9,11 +9,13 @@ */ class Tax_jurisdictions extends Secure_Controller { + private Tax_jurisdiction $tax_jurisdiction; + public function __construct() { parent::__construct('tax_jurisdictions'); - $this->tax_jurisdiction = model('Tax_jurisdiction'); + $this->tax_jurisdiction = model(Tax_jurisdiction::class); helper('tax_helper'); } diff --git a/app/Database/Migrations/20170502221506_sales_tax_data.php b/app/Database/Migrations/20170502221506_sales_tax_data.php index 27ef67816f..893097b8ea 100644 --- a/app/Database/Migrations/20170502221506_sales_tax_data.php +++ b/app/Database/Migrations/20170502221506_sales_tax_data.php @@ -19,11 +19,12 @@ class Migration_Sales_Tax_Data extends Migration public const YES = '1'; public const VAT_TAX = '0'; public const SALES_TAX = '1'; + private Appconfig $appconfig; public function __construct() { parent::__construct(); - $this->appconfig = model('Appconfig'); + $this->appconfig = model(Appconfig::class); } //TODO: we need to figure out why we get a server error when uncommented portions of this migration run @@ -361,9 +362,9 @@ public function apply_invoice_taxing(array &$sales_taxes): void { $sort = []; - foreach($sales_taxes as $k => $v) //TODO: Refactor $k and $v to proper variable names + foreach($sales_taxes as $key => $value) { - $sort['print_sequence'][$k] = $v['print_sequence']; + $sort['print_sequence'][$key] = $value['print_sequence']; } array_multisort($sort['print_sequence'], SORT_ASC, $sales_taxes); @@ -401,7 +402,7 @@ public function round_sales_taxes(array &$sales_taxes): void $rounding_code = $sales_tax['rounding_code']; $rounded_sale_tax_amount = $sale_tax_amount; - if ($rounding_code == PHP_ROUND_HALF_UP //TODO: This block of if/elseif statements should be replaced by a switch + if ($rounding_code == PHP_ROUND_HALF_UP || $rounding_code == PHP_ROUND_HALF_DOWN || $rounding_code == PHP_ROUND_HALF_EVEN || $rounding_code == PHP_ROUND_HALF_ODD) diff --git a/app/Database/Migrations/20200202000000_taxamount.php b/app/Database/Migrations/20200202000000_taxamount.php index a70cf63abb..3ec7a87e79 100644 --- a/app/Database/Migrations/20200202000000_taxamount.php +++ b/app/Database/Migrations/20200202000000_taxamount.php @@ -21,12 +21,13 @@ class Migration_TaxAmount extends Migration public const YES = '1'; public const VAT_TAX = '0'; public const SALES_TAX = '1'; //TODO: It appears that this constant is never used + private Appconfig $appconfig; public function __construct() { parent::__construct(); - $this->appconfig = model('Appconfig'); + $this->appconfig = model(Appconfig::class); } /** diff --git a/app/Database/Migrations/20210422000000_database_optimizations.php b/app/Database/Migrations/20210422000000_database_optimizations.php index a8f9a9aed7..48e1c3095c 100644 --- a/app/Database/Migrations/20210422000000_database_optimizations.php +++ b/app/Database/Migrations/20210422000000_database_optimizations.php @@ -119,7 +119,7 @@ private function migrate_duplicate_attribute_values($attribute_type): void * @param ResultInterface $attribute_ids_to_fix All attribute_ids that need to parsed * @param array $attribute_value The attribute value in question. */ - private function reassign_duplicate_attribute_values(ResultInterface $attribute_ids_to_fix, array $attribute_value) + private function reassign_duplicate_attribute_values(ResultInterface $attribute_ids_to_fix, array $attribute_value): void { foreach($attribute_ids_to_fix->getResultArray() as $attribute_id) { diff --git a/app/Database/Migrations/20210422000001_remove_duplicate_links.php b/app/Database/Migrations/20210422000001_remove_duplicate_links.php index 4648d4b3f1..90a45ac842 100644 --- a/app/Database/Migrations/20210422000001_remove_duplicate_links.php +++ b/app/Database/Migrations/20210422000001_remove_duplicate_links.php @@ -24,7 +24,7 @@ public function up(): void * * @property attribute $attribute */ - private function migrate_duplicate_attribute_links() + private function migrate_duplicate_attribute_links(): void { $attribute = model(Attribute::class); diff --git a/app/Database/Migrations/20220127000000_convert_to_ci4.php b/app/Database/Migrations/20220127000000_convert_to_ci4.php index f795c310b1..cef3a6dc31 100644 --- a/app/Database/Migrations/20220127000000_convert_to_ci4.php +++ b/app/Database/Migrations/20220127000000_convert_to_ci4.php @@ -9,6 +9,7 @@ use CodeIgniter\HTTP\Exceptions\RedirectException; use Config\Encryption; use Config\Services; +use ReflectionException; class Convert_to_ci4 extends Migration { @@ -55,7 +56,7 @@ public function down(): void /** * @return RedirectResponse|void - * @throws \ReflectionException + * @throws ReflectionException */ private function convert_ci3_encrypted_data() { diff --git a/app/Database/Migrations/20230307000000_int_to_tinyint.php b/app/Database/Migrations/20230307000000_int_to_tinyint.php index e2df672d80..8a73533ad0 100644 --- a/app/Database/Migrations/20230307000000_int_to_tinyint.php +++ b/app/Database/Migrations/20230307000000_int_to_tinyint.php @@ -18,7 +18,7 @@ public function up(): void /** * Revert a migration step. */ - public function down() + public function down(): void { $this->db->query('ALTER TABLE ' . $this->db->prefixTable('customers') . ' MODIFY `consent` int NOT NULL DEFAULT 0'); $this->db->query('ALTER TABLE ' . $this->db->prefixTable('cash_up') . ' MODIFY `note` int NOT NULL DEFAULT 0'); diff --git a/app/Events/Method.php b/app/Events/Method.php index c8ca736c6f..04fb69e16d 100644 --- a/app/Events/Method.php +++ b/app/Events/Method.php @@ -7,7 +7,7 @@ class Method /** * @return void */ - public static function validate_method() + public static function validate_method(): void { $url = $_SERVER['REQUEST_URI']; diff --git a/app/Helpers/locale_helper.php b/app/Helpers/locale_helper.php index d7c7620fee..ee2df2739f 100644 --- a/app/Helpers/locale_helper.php +++ b/app/Helpers/locale_helper.php @@ -456,7 +456,7 @@ function to_decimals(?float $number, string $decimals = null, int $type = Number * @param string $number * @return false|float|int|mixed|string */ -function parse_quantity(string $number) +function parse_quantity(string $number): mixed { return parse_decimals($number, quantity_decimals()); } @@ -465,7 +465,7 @@ function parse_quantity(string $number) * @param string $number * @return false|float|int|mixed|string */ -function parse_tax(string $number) +function parse_tax(string $number): mixed { return parse_decimals($number, tax_decimals()); } @@ -475,7 +475,7 @@ function parse_tax(string $number) * @param int|null $decimals * @return false|float|int|mixed|string */ -function parse_decimals(string $number, int $decimals = null) +function parse_decimals(string $number, int $decimals = null): mixed { if(empty($number)) { @@ -713,7 +713,7 @@ function prepare_decimal(string $decimal): string $fmt = new NumberFormatter($config['number_locale'], NumberFormatter::DECIMAL); $decimal_separator = $fmt->getSymbol(NumberFormatter::DECIMAL_SEPARATOR_SYMBOL); - if($decimal_separator === ',' && strpos($decimal, ',') !== false) + if($decimal_separator === ',' && str_contains($decimal, ',')) { $decimal = str_replace('.', '', $decimal); //Remove thousands separator $decimal = str_replace(',', '.', $decimal); //Replace decimal separator diff --git a/app/Helpers/report_helper.php b/app/Helpers/report_helper.php index b05256fde0..138f19c821 100644 --- a/app/Helpers/report_helper.php +++ b/app/Helpers/report_helper.php @@ -39,7 +39,7 @@ function get_report_link(string $report_name, string $report_prefix = '', string */ function can_show_report(string $permission_id, array $restrict_views = []): bool { - if(strpos($permission_id, 'reports_') === false) + if(!str_contains($permission_id, 'reports_')) { return false; } diff --git a/app/Helpers/security_helper.php b/app/Helpers/security_helper.php index 18e6d5bc29..97cda041fa 100644 --- a/app/Helpers/security_helper.php +++ b/app/Helpers/security_helper.php @@ -74,7 +74,7 @@ function check_encryption(): bool /** * @return void */ -function abort_encryption_conversion() +function abort_encryption_conversion(): void { $config_path = ROOTPATH . '.env'; $backup_path = WRITEPATH . '/backup/.env.bak'; @@ -105,7 +105,7 @@ function abort_encryption_conversion() /** * @return void */ -function remove_backup() +function remove_backup(): void { $backup_path = WRITEPATH . '/backup/.env.bak'; if( ! file_exists($backup_path)) diff --git a/app/Libraries/Barcode_lib.php b/app/Libraries/Barcode_lib.php index 0ee41ec358..7fd5b634c6 100644 --- a/app/Libraries/Barcode_lib.php +++ b/app/Libraries/Barcode_lib.php @@ -220,7 +220,7 @@ public function listfonts(string $folder): array //TODO: This function does not { while(($file = readdir($handle)) !== false) { - if(substr($file, -4, 4) === '.ttf') + if(str_ends_with($file, '.ttf')) { $array[$file] = $file; } diff --git a/app/Libraries/MY_Email.php b/app/Libraries/MY_Email.php index 833781a7a6..0dc6397ea4 100644 --- a/app/Libraries/MY_Email.php +++ b/app/Libraries/MY_Email.php @@ -5,11 +5,11 @@ class MY_Email extends Email { - var $default_cc_address = ""; - var $default_email_address = ""; - var $default_sender_name = ""; - var $default_sender_address = ""; - var $default_bounce_address = ""; + private string $default_cc_address = ''; + private string $default_email_address = ''; + private string $default_sender_name = ''; + private string $default_sender_address = ''; + private string $default_bounce_address = ''; /** * @param array $config diff --git a/app/Libraries/MY_Migration.php b/app/Libraries/MY_Migration.php index 1e30970f26..52727ec0d2 100644 --- a/app/Libraries/MY_Migration.php +++ b/app/Libraries/MY_Migration.php @@ -61,9 +61,9 @@ public function migrate_to_ci4(): void /** * Checks to see if a ci3 version of the migrations table exists * - * @return string|false The version number of the last CI3 migration to run or false if the table is CI4 or doesn't exist + * @return bool|string The version number of the last CI3 migration to run or false if the table is CI4 or doesn't exist */ - private function ci3_migrations_exists() + private function ci3_migrations_exists(): bool|string { if($this->db->tableExists('migrations') && !$this->db->fieldExists('id','migrations')) { @@ -79,7 +79,7 @@ private function ci3_migrations_exists() * @param string $ci3_migrations_version * @return void */ - private function migrate_table(string $ci3_migrations_version) + private function migrate_table(string $ci3_migrations_version): void { $this->convert_table(); diff --git a/app/Libraries/Mailchimp_lib.php b/app/Libraries/Mailchimp_lib.php index eaec760729..d8d2b49493 100644 --- a/app/Libraries/Mailchimp_lib.php +++ b/app/Libraries/Mailchimp_lib.php @@ -71,7 +71,7 @@ public function __construct(string $api_key = '') * @param array $args An array of arguments to pass to the method. Will be json-encoded for you. * @return array|bool Associative array of json decoded API response or false on error. */ - public function call(string $method, string $httpVerb = 'POST', array $args = []) + public function call(string $method, string $httpVerb = 'POST', array $args = []): bool|array { if(!empty($this->_api_key)) //TODO: Hungarian notation { @@ -105,7 +105,7 @@ private function _build_request_url(string $method, string $httpVerb = 'POST', a * @param array $args Assoc array of parameters to be passed * @return bool|array Assoc array of decoded result or False */ - private function _request(string $httpVerb, string $method, array $args = []) //TODO: Hungarian notation + private function _request(string $httpVerb, string $method, array $args = []): bool|array //TODO: Hungarian notation { $result = false; @@ -163,7 +163,7 @@ public function __construct(array $params = []) * @return array|bool * @see http://developer.mailchimp.com/documentation/mailchimp/reference/lists/#read-get_lists */ - public function getLists(array $parameters = ['fields' => 'lists.id,lists.name,lists.stats.member_count,lists.stats.merge_field_count']) + public function getLists(array $parameters = ['fields' => 'lists.id,lists.name,lists.stats.member_count,lists.stats.merge_field_count']): bool|array { return $this->_connector->call('/lists', 'GET', $parameters); //TODO: Hungarian notation } @@ -177,7 +177,7 @@ public function getLists(array $parameters = ['fields' => 'lists.id,lists.name,l * @return array|bool * @see http://developer.mailchimp.com/documentation/mailchimp/reference/lists/#read-get_lists_list_id */ - public function getList(string $list_id, array $parameters = ['fields' => 'id,name,stats.member_count,stats.merge_field_count']) + public function getList(string $list_id, array $parameters = ['fields' => 'id,name,stats.member_count,stats.merge_field_count']): bool|array { return $this->_connector->call("/lists/$list_id", 'GET', $parameters); //TODO: Hungarian notation } @@ -192,7 +192,7 @@ public function getList(string $list_id, array $parameters = ['fields' => 'id,na * @return array|bool * @see http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#read-get_lists_list_id_members */ - public function getMembers(string $list_id, int $count, int $offset, array $parameters = ['fields' => 'members.id,members.email_address,members.unique_email_id,members.status,members.merge_fields']) + public function getMembers(string $list_id, int $count, int $offset, array $parameters = ['fields' => 'members.id,members.email_address,members.unique_email_id,members.status,members.merge_fields']): bool|array { $parameters += [ 'count' => $count, @@ -214,7 +214,7 @@ public function getMembers(string $list_id, int $count, int $offset, array $para * @return array|bool * @see http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#read-get_lists_list_id_members_subscriber_hash */ - public function getMemberInfoById(string $list_id, string $md5id, array $parameters = ['fields' => 'email_address,status,merge_fields']) + public function getMemberInfoById(string $list_id, string $md5id, array $parameters = ['fields' => 'email_address,status,merge_fields']): bool|array { return $this->_connector->call("/lists/$list_id/members/$md5id", 'GET', $parameters); //TODO: Hungarian notation } @@ -231,7 +231,7 @@ public function getMemberInfoById(string $list_id, string $md5id, array $paramet * @return array|bool * @see http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#read-get_lists_list_id_members_subscriber_hash */ - public function getMemberInfo(string $list_id, string $email, array $parameters = []) + public function getMemberInfo(string $list_id, string $email, array $parameters = []): bool|array { return $this->_connector->call("/lists/$list_id/members/" . md5(strtolower($email)), 'GET', $parameters); } @@ -245,7 +245,7 @@ public function getMemberInfo(string $list_id, string $email, array $parameters * @return array|bool Associative array of results or false. * @see http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/activity/#read-get_lists_list_id_members_subscriber_hash_activity */ - public function getMemberActivity(string $list_id, string $email, array $parameters = []) + public function getMemberActivity(string $list_id, string $email, array $parameters = []): bool|array { return $this->_connector->call("/lists/$list_id/members/" . md5(strtolower($email)) . '/activity', 'GET', $parameters); //TODO: Hungarian notation } @@ -262,7 +262,7 @@ public function getMemberActivity(string $list_id, string $email, array $paramet * @return array|bool * @see http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#create-post_lists_list_id_members */ - public function addMember(string $list_id, string $email, string $first_name, string $last_name, array $parameters = []) + public function addMember(string $list_id, string $email, string $first_name, string $last_name, array $parameters = []): bool|array { $parameters += [ 'email_address' => $email, @@ -286,7 +286,7 @@ public function addMember(string $list_id, string $email, string $first_name, st * @return array|bool * @see http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#delete-delete_lists_list_id_members_subscriber_hash */ - public function removeMember(string $list_id, string $email) + public function removeMember(string $list_id, string $email): bool|array { return $this->_connector->call("/lists/$list_id/members/" . md5(strtolower($email)), 'DELETE'); //TODO: Hungarian notation } @@ -303,7 +303,7 @@ public function removeMember(string $list_id, string $email) * @return array|bool * @see http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#edit-patch_lists_list_id_members_subscriber_hash */ - public function updateMember(string $list_id, string $email, string $first_name, string $last_name, array $parameters = []) + public function updateMember(string $list_id, string $email, string $first_name, string $last_name, array $parameters = []): bool|array { $parameters += [ 'status' => 'subscribed', @@ -328,7 +328,7 @@ public function updateMember(string $list_id, string $email, string $first_name, * @return array|bool * @see http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#edit-put_lists_list_id_members_subscriber_hash */ - public function addOrUpdateMember(string $list_id, string $email, string $first_name, string $last_name, string $status, array $parameters = []) + public function addOrUpdateMember(string $list_id, string $email, string $first_name, string $last_name, string $status, array $parameters = []): bool|array { $parameters += [ 'email_address' => $email, diff --git a/app/Libraries/Receiving_lib.php b/app/Libraries/Receiving_lib.php index d57604b86b..5f3e971657 100644 --- a/app/Libraries/Receiving_lib.php +++ b/app/Libraries/Receiving_lib.php @@ -170,7 +170,7 @@ public function clear_comment(): void //TODO: This function verb is inconsistent } /** - * @return string|null + * @return string */ public function get_reference(): string { @@ -399,7 +399,7 @@ public function add_item(int $item_id, int $quantity = 1, int $item_location = n * @param string $serialnumber * @param float $quantity * @param float $discount - * @param int $discount_type + * @param int|null $discount_type * @param float $price * @param float $receiving_quantity * @return bool @@ -416,7 +416,7 @@ public function edit_item($line, string $description, string $serialnumber, floa $line['receiving_quantity'] = $receiving_quantity; $line['discount'] = $discount; - if(!is_null($discount_type)) + if(!is_null($discount_type)) { $line['discount_type'] = $discount_type; } @@ -522,7 +522,7 @@ public function clear_all(): void * @param float $quantity * @param float $price * @param float $discount - * @param int $discount_type + * @param int|null $discount_type * @param float $receiving_quantity * @return string */ diff --git a/app/Libraries/Sale_lib.php b/app/Libraries/Sale_lib.php index a12a1ad989..e6eea0bf31 100644 --- a/app/Libraries/Sale_lib.php +++ b/app/Libraries/Sale_lib.php @@ -211,7 +211,6 @@ public function empty_cart(): void /** * @return void - * @throws ReflectionException */ public function remove_temp_items(): void { @@ -279,7 +278,7 @@ public function get_work_order_number(): ?string } /** - * @return int + * @return int|null */ public function get_sale_type(): ?int { @@ -302,7 +301,7 @@ public function set_invoice_number(int $invoice_number, bool $keep_custom = fals } /** - * @param string $quote_number + * @param string|null $quote_number * @param bool $keep_custom * @return void */ @@ -317,7 +316,7 @@ public function set_quote_number(?string $quote_number, bool $keep_custom = fals } /** - * @param string $work_order_number + * @param string|null $work_order_number * @param bool $keep_custom * @return void */ @@ -898,7 +897,7 @@ public function get_dinner_table(): ?int } /** - * @param int $dinner_table + * @param int|null $dinner_table * @return void */ public function set_dinner_table(?int $dinner_table): void @@ -1327,7 +1326,6 @@ public function edit_item(string $line, string $description, string $serialnumbe /** * @param int $line * @return void - * @throws ReflectionException */ public function delete_item(int $line): void { diff --git a/app/Libraries/Token_lib.php b/app/Libraries/Token_lib.php index 107a18492a..122097c647 100644 --- a/app/Libraries/Token_lib.php +++ b/app/Libraries/Token_lib.php @@ -4,6 +4,8 @@ use App\Models\Tokens\Token; use Config\OSPOS; +use IntlDateFormatter; +use DateTime; /** * Token library @@ -17,25 +19,26 @@ class Token_lib */ public function render(string $tokened_text, array $tokens = [], $save = true): string { - // Apply the transformation for the "%" tokens if any are used - if(strpos($tokened_text, '%') !== false) + $config = config(OSPOS::class)->settings; + $formatter = new IntlDateFormatter( + $config['number_locale'], // Locale + IntlDateFormatter::FULL, // Date type + IntlDateFormatter::FULL // Time type + ); + + //Apply the transformation for the "%" tokens if any are used + if(str_contains($tokened_text, '%')) { - $tokened_text = strftime($tokened_text); //TODO: these need to be converted to IntlDateFormatter::format() + + $tokened_text = $formatter->format(new DateTime()); } - // Call scan to build an array of all of the tokens used in the text to be transformed + //Call scan to build an array of all tokens used in the text to be transformed $token_tree = $this->scan($tokened_text); if(empty($token_tree)) { - if(strpos($tokened_text, '%') !== false) - { - return strftime($tokened_text); - } - else - { - return $tokened_text; - } + return str_contains($tokened_text, '%') ? $formatter->format(new DateTime()) : $tokened_text; } $token_values = []; @@ -177,10 +180,10 @@ public function generate(array $used_tokens, array &$tokens_to_replace, array &$ /** * @param $token_code * @param array $tokens - * @param $save + * @param bool $save * @return string */ - private function resolve_token($token_code, array $tokens = [], $save = true): string + private function resolve_token($token_code, array $tokens = [], bool $save = true): string { foreach(array_merge($tokens, Token::get_tokens()) as $token) { diff --git a/app/Models/Appconfig.php b/app/Models/Appconfig.php index 390c83b2ec..4251ce35ed 100644 --- a/app/Models/Appconfig.php +++ b/app/Models/Appconfig.php @@ -119,7 +119,7 @@ public function batch_save(array $data): bool * @param bool $purge A hard delete is conducted if true and soft delete on false. * @return bool Result of the delete operation. */ - public function delete($id = null, bool $purge = false) + public function delete($id = null, bool $purge = false): bool { $builder = $this->db->table('app_config'); return $builder->delete(['key' => $id]); diff --git a/app/Models/Attribute.php b/app/Models/Attribute.php index b3bc40be19..c75827dac5 100644 --- a/app/Models/Attribute.php +++ b/app/Models/Attribute.php @@ -92,11 +92,11 @@ public function link_exists(int $item_id, bool $definition_id = false): bool /** * Determines if a given attribute_value exists in the attribute_values table and returns the attribute_id if it does * - * @param string|float $attribute_value The value to search for in the attribute values table. + * @param float|string $attribute_value The value to search for in the attribute values table. * @param string $definition_type The definition type which will dictate which column is searched. * @return int|bool The attribute ID of the found row or false if no attribute value was found. */ - public function value_exists($attribute_value, string $definition_type = TEXT) + public function value_exists(float|string $attribute_value, string $definition_type = TEXT): bool|int { $config = config(OSPOS::class)->settings; @@ -822,8 +822,8 @@ public function get_suggestions(int $definition_id, string $term): array /** * @param string $attribute_value * @param int $definition_id - * @param bool $item_id - * @param bool $attribute_id + * @param $item_id + * @param $attribute_id * @param string $definition_type * @return int */ @@ -908,8 +908,9 @@ public function save_value(string $attribute_value, int $definition_id, $item_id * @param int $definition_id * @return bool|BaseResult|Query */ - public function delete_value(string $attribute_value, int $definition_id) + public function delete_value(string $attribute_value, int $definition_id): Query|bool|BaseResult { + //TODO: convert to using QueryBuilder. Use App/Models/Reports/Summary_taxes.php getData() as a reference template $query = 'DELETE atrv, atrl '; $query .= 'FROM ' . $this->db->prefixTable('attribute_values') . ' atrv, ' . $this->db->prefixTable('attribute_links') . ' atrl '; $query .= 'WHERE atrl.attribute_id = atrv.attribute_id AND atrv.attribute_value = ' . $this->db->escape($attribute_value); diff --git a/app/Models/Customer.php b/app/Models/Customer.php index ff9903cbf8..9e651d3b02 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -423,8 +423,7 @@ public function get_search_suggestions(string $search, int $limit = 25, bool $un */ public function get_found_rows(string $search): int { - $result = $this->search($search, 0, 0, 'last_name', 'asc', true); - return $result; + return $this->search($search, 0, 0, 'last_name', 'asc', true); } /** diff --git a/app/Models/Expense.php b/app/Models/Expense.php index ce948fc8f8..658c4b3f7f 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -98,7 +98,7 @@ public function get_found_rows(string $search, array $filters): int * @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) + 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): false|string|ResultInterface { // Set default values if($rows == null) $rows = 0; @@ -148,11 +148,6 @@ public function search(string $search, array $filters, ?int $rows = 0, ?int $lim $builder->where('expenses.deleted', $filters['is_deleted']); - /* //TODO: Below needs to be replaced with Ternary notation - empty($config['date_or_time_format) - ? $builder->where('DATE_FORMAT(expenses.date, "%Y-%m-%d") BETWEEN ' . $this->db->escape($filters['start_date']) . ' AND ' . $this->db->escape($filters['end_date'])) - : $builder->where('expenses.date BETWEEN ' . $this->db->escape(rawurldecode($filters['start_date'])) . ' AND ' . $this->db->escape(rawurldecode($filters['end_date']))); - */ if(empty($config['date_or_time_format'])) { $builder->where('DATE_FORMAT(expenses.date, "%Y-%m-%d") BETWEEN ' . $this->db->escape($filters['start_date']) . ' AND ' . $this->db->escape($filters['end_date'])); diff --git a/app/Models/Inventory.php b/app/Models/Inventory.php index 23eda3e4fe..2a7877d112 100644 --- a/app/Models/Inventory.php +++ b/app/Models/Inventory.php @@ -64,7 +64,7 @@ public function get_inventory_data_for_item(int $item_id, bool $location_id = fa * @param int $item_id ID number for the item to have quantity reset. * @return bool|int|string The row id of the inventory table on insert or false on failure */ - public function reset_quantity(int $item_id) + public function reset_quantity(int $item_id): bool|int|string { $inventory_sums = $this->get_inventory_sum($item_id); foreach($inventory_sums as $inventory_sum) diff --git a/app/Models/Item.php b/app/Models/Item.php index 0e29e2b123..786555f692 100644 --- a/app/Models/Item.php +++ b/app/Models/Item.php @@ -79,7 +79,7 @@ public function item_number_exists(string $item_number, string $item_id = ''): b // // check if $item_id is a number and not a string starting with 0 // // because cases like 00012345 will be seen as a number where it is a barcode - if(ctype_digit($item_id) && substr($item_id, 0, 1) != '0') //TODO: !== + if(ctype_digit($item_id) && !str_starts_with($item_id, '0')) { $builder->where('item_id !=', intval($item_id)); } @@ -382,7 +382,7 @@ public function get_info_by_id_or_number(int $item_id, bool $include_deleted = t // check if $item_id is a number and not a string starting with 0 // because cases like 00012345 will be seen as a number where it is a barcode - if(ctype_digit(strval($item_id)) && substr($item_id, 0, 1) != '0') + if(ctype_digit(strval($item_id)) && !str_starts_with($item_id, '0')) { $builder->orWhere('items.item_id', $item_id); } @@ -509,7 +509,7 @@ public function update_multiple(array $item_data, string $item_ids): bool /** * Deletes one item */ - public function delete($item_id = null, bool $purge = false) + public function delete($item_id = null, bool $purge = false): bool|int|string { $this->db->transStart(); @@ -1105,7 +1105,7 @@ public function get_location_suggestions(string $search): array /** * @return ResultInterface|false|string */ - public function get_categories() //TODO: This function is never called in the code. + public function get_categories(): ResultInterface|bool //TODO: This function is never called in the code. { $builder = $this->db->table('items'); $builder->select('category'); diff --git a/app/Models/Item_kit.php b/app/Models/Item_kit.php index 17662569e5..d5bd799172 100644 --- a/app/Models/Item_kit.php +++ b/app/Models/Item_kit.php @@ -77,7 +77,7 @@ public function item_number_exists(string $item_kit_number, string $item_kit_id // check if $item_id is a number and not a string starting with 0 // because cases like 00012345 will be seen as a number where it is a barcode - if(ctype_digit($item_kit_id) && substr($item_kit_id, 0, 1) !== '0') + if(ctype_digit($item_kit_id) && !str_starts_with($item_kit_id, '0')) { $builder->where('item_kit_id !=', (int) $item_kit_id); } @@ -191,7 +191,7 @@ public function save_value(array &$item_kit_data, int $item_kit_id = NEW_ENTRY): /** * Deletes one item kit */ - public function delete($item_kit_id = null, bool $purge = false) + public function delete($item_kit_id = null, bool $purge = false): bool { $builder = $this->db->table('item_kits'); diff --git a/app/Models/Item_kit_items.php b/app/Models/Item_kit_items.php index 7b674d6d69..b7aeba5c12 100644 --- a/app/Models/Item_kit_items.php +++ b/app/Models/Item_kit_items.php @@ -80,7 +80,7 @@ public function save_value(array &$item_kit_items_data, int $item_kit_id): bool /** * Deletes item kit items given an item kit */ - public function delete($item_kit_id = null, bool $purge = false) + public function delete($item_kit_id = null, bool $purge = false): bool { $builder = $this->db->table('item_kit_items'); diff --git a/app/Models/Item_quantity.php b/app/Models/Item_quantity.php index f80734db06..20c169c058 100644 --- a/app/Models/Item_quantity.php +++ b/app/Models/Item_quantity.php @@ -56,7 +56,7 @@ public function save_value(array $location_detail, int $item_id, int $location_i /** * @param int $item_id * @param int $location_id - * @return array|Item_quantity|null + * @return array|Item_quantity|stdClass|null */ public function get_item_quantity(int $item_id, int $location_id): array|Item_quantity|StdClass|null { diff --git a/app/Models/Item_taxes.php b/app/Models/Item_taxes.php index 3bf6a4665a..3692b942a8 100644 --- a/app/Models/Item_taxes.php +++ b/app/Models/Item_taxes.php @@ -90,7 +90,7 @@ public function save_multiple(array &$items_taxes_data, string $item_ids): bool /** * Deletes taxes given an item */ - public function delete($item_id = null, bool $purge = false) + public function delete($item_id = null, bool $purge = false): bool { $builder = $this->db->table('items_taxes'); diff --git a/app/Models/Reports/Detailed_receivings.php b/app/Models/Reports/Detailed_receivings.php index 9c0ea0d738..980e3002b2 100644 --- a/app/Models/Reports/Detailed_receivings.php +++ b/app/Models/Reports/Detailed_receivings.php @@ -171,18 +171,19 @@ public function getSummaryData(array $inputs): array $builder->where('item_location', $inputs['location_id']); } - //TODO: These if statements should be replaced with a switch statement - if($inputs['receiving_type'] == 'receiving') + switch($inputs['receiving_type']) { - $builder->where('quantity_purchased >', 0); - } - elseif($inputs['receiving_type'] == 'returns') - { - $builder->where('quantity_purchased <', 0); - } - elseif($inputs['receiving_type'] == 'requisitions') - { - $builder->where('quantity_purchased', 0); + case 'receiving': + $builder->where('quantity_purchased >', 0); + break; + + case 'returns': + $builder->where('quantity_purchased <', 0); + break; + + case 'requisitions': + $builder->where('quantity_purchased', 0); + break; } return $builder->get()->getRowArray(); diff --git a/app/Models/Reports/Detailed_sales.php b/app/Models/Reports/Detailed_sales.php index 355629c3b8..3856d3acdf 100644 --- a/app/Models/Reports/Detailed_sales.php +++ b/app/Models/Reports/Detailed_sales.php @@ -124,42 +124,43 @@ public function getData(array $inputs): array $builder->where('item_location', $inputs['location_id']); } - //TODO: These if statements should be converted to a switch statement - if($inputs['sale_type'] == 'complete') //TODO: Duplicated code + switch($inputs['sale_type']) { - $builder->where('sale_status', COMPLETED); - $builder->groupStart(); - $builder->where('sale_type', SALE_TYPE_POS); - $builder->orWhere('sale_type', SALE_TYPE_INVOICE); - $builder->orWhere('sale_type', SALE_TYPE_RETURN); - $builder->groupEnd(); - } - elseif($inputs['sale_type'] == 'sales') - { - $builder->where('sale_status', COMPLETED); - $builder->groupStart(); - $builder->where('sale_type', SALE_TYPE_POS); - $builder->orWhere('sale_type', SALE_TYPE_INVOICE); - $builder->groupEnd(); - } - elseif($inputs['sale_type'] == 'quotes') - { - $builder->where('sale_status', SUSPENDED); - $builder->where('sale_type', SALE_TYPE_QUOTE); - } - elseif($inputs['sale_type'] == 'work_orders') - { - $builder->where('sale_status', SUSPENDED); - $builder->where('sale_type', SALE_TYPE_WORK_ORDER); - } - elseif($inputs['sale_type'] == 'canceled') - { - $builder->where('sale_status', CANCELED); - } - elseif($inputs['sale_type'] == 'returns') - { - $builder->where('sale_status', COMPLETED); - $builder->where('sale_type', SALE_TYPE_RETURN); + case 'complete': + $builder->where('sale_status', COMPLETED); + $builder->groupStart(); + $builder->where('sale_type', SALE_TYPE_POS); + $builder->orWhere('sale_type', SALE_TYPE_INVOICE); + $builder->orWhere('sale_type', SALE_TYPE_RETURN); + $builder->groupEnd(); + break; + + case 'sales': + $builder->where('sale_status', COMPLETED); + $builder->groupStart(); + $builder->where('sale_type', SALE_TYPE_POS); + $builder->orWhere('sale_type', SALE_TYPE_INVOICE); + $builder->groupEnd(); + break; + + case 'quotes': + $builder->where('sale_status', SUSPENDED); + $builder->where('sale_type', SALE_TYPE_QUOTE); + break; + + case 'work_orders': + $builder->where('sale_status', SUSPENDED); + $builder->where('sale_type', SALE_TYPE_WORK_ORDER); + break; + + case 'canceled': + $builder->where('sale_status', CANCELED); + break; + + case 'returns': + $builder->where('sale_status', COMPLETED); + $builder->where('sale_type', SALE_TYPE_RETURN); + break; } $builder->groupBy('sale_id'); @@ -226,42 +227,43 @@ public function getSummaryData(array $inputs): array $builder->where('item_location', $inputs['location_id']); } - //TODO: This should be converted to a switch statement - if($inputs['sale_type'] == 'complete') + switch($inputs['sale_type']) { - $builder->where('sale_status', COMPLETED); - $builder->groupStart(); - $builder->where('sale_type', SALE_TYPE_POS); - $builder->orWhere('sale_type', SALE_TYPE_INVOICE); - $builder->orWhere('sale_type', SALE_TYPE_RETURN); - $builder->groupEnd(); - } - elseif($inputs['sale_type'] == 'sales') - { - $builder->where('sale_status', COMPLETED); - $builder->groupStart(); - $builder->where('sale_type', SALE_TYPE_POS); - $builder->orWhere('sale_type', SALE_TYPE_INVOICE); - $builder->groupEnd(); - } - elseif($inputs['sale_type'] == 'quotes') - { - $builder->where('sale_status', SUSPENDED); - $builder->where('sale_type', SALE_TYPE_QUOTE); - } - elseif($inputs['sale_type'] == 'work_orders') - { - $builder->where('sale_status', SUSPENDED); - $builder->where('sale_type', SALE_TYPE_WORK_ORDER); - } - elseif($inputs['sale_type'] == 'canceled') - { - $builder->where('sale_status', CANCELED); - } - elseif($inputs['sale_type'] == 'returns') - { - $builder->where('sale_status', COMPLETED); - $builder->where('sale_type', SALE_TYPE_RETURN); + case 'complete': + $builder->where('sale_status', COMPLETED); + $builder->groupStart(); + $builder->where('sale_type', SALE_TYPE_POS); + $builder->orWhere('sale_type', SALE_TYPE_INVOICE); + $builder->orWhere('sale_type', SALE_TYPE_RETURN); + $builder->groupEnd(); + break; + + case 'sales': + $builder->where('sale_status', COMPLETED); + $builder->groupStart(); + $builder->where('sale_type', SALE_TYPE_POS); + $builder->orWhere('sale_type', SALE_TYPE_INVOICE); + $builder->groupEnd(); + break; + + case 'quotes': + $builder->where('sale_status', SUSPENDED); + $builder->where('sale_type', SALE_TYPE_QUOTE); + break; + + case 'work_orders': + $builder->where('sale_status', SUSPENDED); + $builder->where('sale_type', SALE_TYPE_WORK_ORDER); + break; + + case 'canceled': + $builder->where('sale_status', CANCELED); + break; + + case 'returns': + $builder->where('sale_status', COMPLETED); + $builder->where('sale_type', SALE_TYPE_RETURN); + break; } return $builder->get()->getRowArray(); diff --git a/app/Models/Reports/Inventory_low.php b/app/Models/Reports/Inventory_low.php index 1fc792d5f9..3d4a120385 100644 --- a/app/Models/Reports/Inventory_low.php +++ b/app/Models/Reports/Inventory_low.php @@ -31,7 +31,7 @@ public function getDataColumns(): array * @return array */ public function getData(array $inputs): array - {//TODO: we need to see if this can be converted into using QueryBuilder + {//TODO: convert to using QueryBuilder. Use App/Models/Reports/Summary_taxes.php getData() as a reference template $item = model(Item::class); $query = $this->db->query("SELECT " . $item->get_item_name('name') . ", items.item_number, diff --git a/app/Models/Reports/Specific_customer.php b/app/Models/Reports/Specific_customer.php index c647e216ec..14dbdfd1ac 100644 --- a/app/Models/Reports/Specific_customer.php +++ b/app/Models/Reports/Specific_customer.php @@ -101,44 +101,46 @@ public function getData(array $inputs): array } elseif($inputs['payment_type'] != 'all') { - $builder->like('payment_type', lang('Sales.'.$inputs['payment_type'])); + $builder->like('payment_type', lang('Sales.' . $inputs['payment_type'])); } - if($inputs['sale_type'] == 'complete') - { - $builder->where('sale_status', COMPLETED); - $builder->groupStart(); - $builder->where('sale_type', SALE_TYPE_POS); - $builder->orWhere('sale_type', SALE_TYPE_INVOICE); - $builder->orWhere('sale_type', SALE_TYPE_RETURN); - $builder->groupEnd(); - } - elseif($inputs['sale_type'] == 'sales') - { - $builder->where('sale_status', COMPLETED); - $builder->groupStart(); - $builder->where('sale_type', SALE_TYPE_POS); - $builder->orWhere('sale_type', SALE_TYPE_INVOICE); - $builder->groupEnd(); - } - elseif($inputs['sale_type'] == 'quotes') - { - $builder->where('sale_status', SUSPENDED); - $builder->where('sale_type', SALE_TYPE_QUOTE); - } - elseif($inputs['sale_type'] == 'work_orders') + switch($inputs['sale_type']) { - $builder->where('sale_status', SUSPENDED); - $builder->where('sale_type', SALE_TYPE_WORK_ORDER); - } - elseif($inputs['sale_type'] == 'canceled') - { - $builder->where('sale_status', CANCELED); - } - elseif($inputs['sale_type'] == 'returns') - { - $builder->where('sale_status', COMPLETED); - $builder->where('sale_type', SALE_TYPE_RETURN); + case 'complete': + $builder->where('sale_status', COMPLETED); + $builder->groupStart(); + $builder->where('sale_type', SALE_TYPE_POS); + $builder->orWhere('sale_type', SALE_TYPE_INVOICE); + $builder->orWhere('sale_type', SALE_TYPE_RETURN); + $builder->groupEnd(); + break; + + case 'sales': + $builder->where('sale_status', COMPLETED); + $builder->groupStart(); + $builder->where('sale_type', SALE_TYPE_POS); + $builder->orWhere('sale_type', SALE_TYPE_INVOICE); + $builder->groupEnd(); + break; + + case 'quotes': + $builder->where('sale_status', SUSPENDED); + $builder->where('sale_type', SALE_TYPE_QUOTE); + break; + + case 'work_orders': + $builder->where('sale_status', SUSPENDED); + $builder->where('sale_type', SALE_TYPE_WORK_ORDER); + break; + + case 'canceled': + $builder->where('sale_status', CANCELED); + break; + + case 'returns': + $builder->where('sale_status', COMPLETED); + $builder->where('sale_type', SALE_TYPE_RETURN); + break; } $builder->groupBy('sale_id'); //TODO: Duplicated code @@ -185,42 +187,43 @@ public function getSummaryData(array $inputs): array $builder->like('payment_type', lang('Sales.'.$inputs['payment_type'])); } - //TODO: This needs to be converted to a switch statement - if($inputs['sale_type'] == 'complete') - { - $builder->where('sale_status', COMPLETED); - $builder->groupStart(); - $builder->where('sale_type', SALE_TYPE_POS); - $builder->orWhere('sale_type', SALE_TYPE_INVOICE); - $builder->orWhere('sale_type', SALE_TYPE_RETURN); - $builder->groupEnd(); - } - elseif($inputs['sale_type'] == 'sales') - { - $builder->where('sale_status', COMPLETED); - $builder->groupStart(); - $builder->where('sale_type', SALE_TYPE_POS); - $builder->orWhere('sale_type', SALE_TYPE_INVOICE); - $builder->groupEnd(); - } - elseif($inputs['sale_type'] == 'quotes') - { - $builder->where('sale_status', SUSPENDED); - $builder->where('sale_type', SALE_TYPE_QUOTE); - } - elseif($inputs['sale_type'] == 'work_orders') - { - $builder->where('sale_status', SUSPENDED); - $builder->where('sale_type', SALE_TYPE_WORK_ORDER); - } - elseif($inputs['sale_type'] == 'canceled') - { - $builder->where('sale_status', CANCELED); - } - elseif($inputs['sale_type'] == 'returns') - { - $builder->where('sale_status', COMPLETED); - $builder->where('sale_type', SALE_TYPE_RETURN); + switch($inputs['sale_type']) + { + case 'complete': + $builder->where('sale_status', COMPLETED); + $builder->groupStart(); + $builder->where('sale_type', SALE_TYPE_POS); + $builder->orWhere('sale_type', SALE_TYPE_INVOICE); + $builder->orWhere('sale_type', SALE_TYPE_RETURN); + $builder->groupEnd(); + break; + + case 'sales': + $builder->where('sale_status', COMPLETED); + $builder->groupStart(); + $builder->where('sale_type', SALE_TYPE_POS); + $builder->orWhere('sale_type', SALE_TYPE_INVOICE); + $builder->groupEnd(); + break; + + case 'quotes': + $builder->where('sale_status', SUSPENDED); + $builder->where('sale_type', SALE_TYPE_QUOTE); + break; + + case 'work_orders': + $builder->where('sale_status', SUSPENDED); + $builder->where('sale_type', SALE_TYPE_WORK_ORDER); + break; + + case 'canceled': + $builder->where('sale_status', CANCELED); + break; + + case 'returns': + $builder->where('sale_status', COMPLETED); + $builder->where('sale_type', SALE_TYPE_RETURN); + break; } return $builder->get()->getRowArray(); diff --git a/app/Models/Reports/Specific_discount.php b/app/Models/Reports/Specific_discount.php index 8e36eac1f2..eef71bd4fc 100644 --- a/app/Models/Reports/Specific_discount.php +++ b/app/Models/Reports/Specific_discount.php @@ -98,42 +98,43 @@ public function getData(array $inputs): array $builder->where('discount >=', $inputs['discount']); //TODO: Duplicated code $builder->where('discount_type', $inputs['discount_type']); - //TODO: this needs to be converted to a switch statement - if($inputs['sale_type'] == 'complete') - { - $builder->where('sale_status', COMPLETED); - $builder->groupStart(); - $builder->where('sale_type', SALE_TYPE_POS); - $builder->orWhere('sale_type', SALE_TYPE_INVOICE); - $builder->orWhere('sale_type', SALE_TYPE_RETURN); - $builder->groupEnd(); - } - elseif($inputs['sale_type'] == 'sales') + switch($inputs['sale_type']) { - $builder->where('sale_status', COMPLETED); - $builder->groupStart(); - $builder->where('sale_type', SALE_TYPE_POS); - $builder->orWhere('sale_type', SALE_TYPE_INVOICE); - $builder->groupEnd(); - } - elseif($inputs['sale_type'] == 'quotes') - { - $builder->where('sale_status', SUSPENDED); - $builder->where('sale_type', SALE_TYPE_QUOTE); - } - elseif($inputs['sale_type'] == 'work_orders') - { - $builder->where('sale_status', SUSPENDED); - $builder->where('sale_type', SALE_TYPE_WORK_ORDER); - } - elseif($inputs['sale_type'] == 'canceled') - { - $builder->where('sale_status', CANCELED); - } - elseif($inputs['sale_type'] == 'returns') - { - $builder->where('sale_status', COMPLETED); - $builder->where('sale_type', SALE_TYPE_RETURN); + case 'complete': + $builder->where('sale_status', COMPLETED); + $builder->groupStart(); + $builder->where('sale_type', SALE_TYPE_POS); + $builder->orWhere('sale_type', SALE_TYPE_INVOICE); + $builder->orWhere('sale_type', SALE_TYPE_RETURN); + $builder->groupEnd(); + break; + + case 'sales': + $builder->where('sale_status', COMPLETED); + $builder->groupStart(); + $builder->where('sale_type', SALE_TYPE_POS); + $builder->orWhere('sale_type', SALE_TYPE_INVOICE); + $builder->groupEnd(); + break; + + case 'quotes': + $builder->where('sale_status', SUSPENDED); + $builder->where('sale_type', SALE_TYPE_QUOTE); + break; + + case 'work_orders': + $builder->where('sale_status', SUSPENDED); + $builder->where('sale_type', SALE_TYPE_WORK_ORDER); + break; + + case 'canceled': + $builder->where('sale_status', CANCELED); + break; + + case 'returns': + $builder->where('sale_status', COMPLETED); + $builder->where('sale_type', SALE_TYPE_RETURN); + break; } $builder->groupBy('sale_id'); //TODO: Duplicated code diff --git a/app/Models/Reports/Specific_employee.php b/app/Models/Reports/Specific_employee.php index 5937642d8d..b0667d60fb 100644 --- a/app/Models/Reports/Specific_employee.php +++ b/app/Models/Reports/Specific_employee.php @@ -95,42 +95,43 @@ public function getData(array $inputs): array $builder->where('employee_id', $inputs['employee_id']); //TODO: Duplicated code - //TODO: this needs to be converted to a switch statement - if($inputs['sale_type'] == 'complete') - { - $builder->where('sale_status', COMPLETED); - $builder->groupStart(); - $builder->where('sale_type', SALE_TYPE_POS); - $builder->orWhere('sale_type', SALE_TYPE_INVOICE); - $builder->orWhere('sale_type', SALE_TYPE_RETURN); - $builder->groupEnd(); - } - elseif($inputs['sale_type'] == 'sales') - { - $builder->where('sale_status', COMPLETED); - $builder->groupStart(); - $builder->where('sale_type', SALE_TYPE_POS); - $builder->orWhere('sale_type', SALE_TYPE_INVOICE); - $builder->groupEnd(); - } - elseif($inputs['sale_type'] == 'quotes') - { - $builder->where('sale_status', SUSPENDED); - $builder->where('sale_type', SALE_TYPE_QUOTE); - } - elseif($inputs['sale_type'] == 'work_orders') - { - $builder->where('sale_status', SUSPENDED); - $builder->where('sale_type', SALE_TYPE_WORK_ORDER); - } - elseif($inputs['sale_type'] == 'canceled') - { - $builder->where('sale_status', CANCELED); - } - elseif($inputs['sale_type'] == 'returns') + switch($inputs['sale_type']) { - $builder->where('sale_status', COMPLETED); - $builder->where('sale_type', SALE_TYPE_RETURN); + case 'complete': + $builder->where('sale_status', COMPLETED); + $builder->groupStart(); + $builder->where('sale_type', SALE_TYPE_POS); + $builder->orWhere('sale_type', SALE_TYPE_INVOICE); + $builder->orWhere('sale_type', SALE_TYPE_RETURN); + $builder->groupEnd(); + break; + + case 'sales': + $builder->where('sale_status', COMPLETED); + $builder->groupStart(); + $builder->where('sale_type', SALE_TYPE_POS); + $builder->orWhere('sale_type', SALE_TYPE_INVOICE); + $builder->groupEnd(); + break; + + case 'quotes': + $builder->where('sale_status', SUSPENDED); + $builder->where('sale_type', SALE_TYPE_QUOTE); + break; + + case 'work_orders': + $builder->where('sale_status', SUSPENDED); + $builder->where('sale_type', SALE_TYPE_WORK_ORDER); + break; + + case 'canceled': + $builder->where('sale_status', CANCELED); + break; + + case 'returns': + $builder->where('sale_status', COMPLETED); + $builder->where('sale_type', SALE_TYPE_RETURN); + break; } $builder->groupBy('sale_id'); diff --git a/app/Models/Reports/Specific_supplier.php b/app/Models/Reports/Specific_supplier.php index 8f802a3ab1..0d7a9f1975 100644 --- a/app/Models/Reports/Specific_supplier.php +++ b/app/Models/Reports/Specific_supplier.php @@ -79,42 +79,43 @@ public function getData(array $inputs): array $builder->where('supplier_id', $inputs['supplier_id']); //TODO: Duplicated code - //TODO: this needs to be converted to a switch statement - if($inputs['sale_type'] == 'complete') + switch($inputs['sale_type']) { - $builder->where('sale_status', COMPLETED); - $builder->groupStart(); - $builder->where('sale_type', SALE_TYPE_POS); - $builder->orWhere('sale_type', SALE_TYPE_INVOICE); - $builder->orWhere('sale_type', SALE_TYPE_RETURN); - $builder->groupEnd(); - } - elseif($inputs['sale_type'] == 'sales') - { - $builder->where('sale_status', COMPLETED); - $builder->groupStart(); - $builder->where('sale_type', SALE_TYPE_POS); - $builder->orWhere('sale_type', SALE_TYPE_INVOICE); - $builder->groupEnd(); - } - elseif($inputs['sale_type'] == 'quotes') - { - $builder->where('sale_status', SUSPENDED); - $builder->where('sale_type', SALE_TYPE_QUOTE); - } - elseif($inputs['sale_type'] == 'work_orders') - { - $builder->where('sale_status', SUSPENDED); - $builder->where('sale_type', SALE_TYPE_WORK_ORDER); - } - elseif($inputs['sale_type'] == 'canceled') - { - $builder->where('sale_status', CANCELED); - } - elseif($inputs['sale_type'] == 'returns') - { - $builder->where('sale_status', COMPLETED); - $builder->where('sale_type', SALE_TYPE_RETURN); + case 'complete': + $builder->where('sale_status', COMPLETED); + $builder->groupStart(); + $builder->where('sale_type', SALE_TYPE_POS); + $builder->orWhere('sale_type', SALE_TYPE_INVOICE); + $builder->orWhere('sale_type', SALE_TYPE_RETURN); + $builder->groupEnd(); + break; + + case 'sales': + $builder->where('sale_status', COMPLETED); + $builder->groupStart(); + $builder->where('sale_type', SALE_TYPE_POS); + $builder->orWhere('sale_type', SALE_TYPE_INVOICE); + $builder->groupEnd(); + break; + + case 'quotes': + $builder->where('sale_status', SUSPENDED); + $builder->where('sale_type', SALE_TYPE_QUOTE); + break; + + case 'work_orders': + $builder->where('sale_status', SUSPENDED); + $builder->where('sale_type', SALE_TYPE_WORK_ORDER); + break; + + case 'canceled': + $builder->where('sale_status', CANCELED); + break; + + case 'returns': + $builder->where('sale_status', COMPLETED); + $builder->where('sale_type', SALE_TYPE_RETURN); + break; } $builder->groupBy(['item_id', 'sale_id']); @@ -133,42 +134,43 @@ public function getSummaryData(array $inputs): array $builder->select('SUM(subtotal) AS subtotal, SUM(tax) AS tax, SUM(total) AS total, SUM(cost) AS cost, SUM(profit) AS profit'); $builder->where('supplier_id', $inputs['supplier_id']); - //TODO: this needs to be converted to a switch statement - if($inputs['sale_type'] == 'complete') + switch($inputs['sale_type']) { - $builder->where('sale_status', COMPLETED); - $builder->groupStart(); - $builder->where('sale_type', SALE_TYPE_POS); - $builder->orWhere('sale_type', SALE_TYPE_INVOICE); - $builder->orWhere('sale_type', SALE_TYPE_RETURN); - $builder->groupEnd(); - } - elseif($inputs['sale_type'] == 'sales') - { - $builder->where('sale_status', COMPLETED); - $builder->groupStart(); - $builder->where('sale_type', SALE_TYPE_POS); - $builder->orWhere('sale_type', SALE_TYPE_INVOICE); - $builder->groupEnd(); - } - elseif($inputs['sale_type'] == 'quotes') - { - $builder->where('sale_status', SUSPENDED); - $builder->where('sale_type', SALE_TYPE_QUOTE); - } - elseif($inputs['sale_type'] == 'work_orders') - { - $builder->where('sale_status', SUSPENDED); - $builder->where('sale_type', SALE_TYPE_WORK_ORDER); - } - elseif($inputs['sale_type'] == 'canceled') - { - $builder->where('sale_status', CANCELED); - } - elseif($inputs['sale_type'] == 'returns') - { - $builder->where('sale_status', COMPLETED); - $builder->where('sale_type', SALE_TYPE_RETURN); + case 'complete': + $builder->where('sale_status', COMPLETED); + $builder->groupStart(); + $builder->where('sale_type', SALE_TYPE_POS); + $builder->orWhere('sale_type', SALE_TYPE_INVOICE); + $builder->orWhere('sale_type', SALE_TYPE_RETURN); + $builder->groupEnd(); + break; + + case 'sales': + $builder->where('sale_status', COMPLETED); + $builder->groupStart(); + $builder->where('sale_type', SALE_TYPE_POS); + $builder->orWhere('sale_type', SALE_TYPE_INVOICE); + $builder->groupEnd(); + break; + + case 'quotes': + $builder->where('sale_status', SUSPENDED); + $builder->where('sale_type', SALE_TYPE_QUOTE); + break; + + case 'work_orders': + $builder->where('sale_status', SUSPENDED); + $builder->where('sale_type', SALE_TYPE_WORK_ORDER); + break; + + case 'canceled': + $builder->where('sale_status', CANCELED); + break; + + case 'returns': + $builder->where('sale_status', COMPLETED); + $builder->where('sale_type', SALE_TYPE_RETURN); + break; } return $builder->get()->getRowArray(); diff --git a/app/Models/Reports/Summary_discounts.php b/app/Models/Reports/Summary_discounts.php index c300cc16a7..f595c4d450 100644 --- a/app/Models/Reports/Summary_discounts.php +++ b/app/Models/Reports/Summary_discounts.php @@ -27,7 +27,7 @@ public function getData(array $inputs): array $config = config(OSPOS::class)->settings; $builder = $this->db->table('sales_items AS sales_items'); - if($inputs['discount_type'] == FIXED) //TODO: if there are only two options for this if/else statement then it needs to be refactored to use ternary operators. Also ===? + if($inputs['discount_type'] == FIXED) { $builder->select('SUM(sales_items.discount) AS total, MAX(CONCAT("' . $config['currency_symbol'] . '",sales_items.discount)) AS discount, count(*) AS count'); $builder->where('discount_type', FIXED); diff --git a/app/Models/Reports/Summary_employees.php b/app/Models/Reports/Summary_employees.php index e89aabc285..f4477b3feb 100644 --- a/app/Models/Reports/Summary_employees.php +++ b/app/Models/Reports/Summary_employees.php @@ -20,7 +20,6 @@ protected function _get_data_columns(): array //TODO: Hungarian notation ['profit' => lang('Reports.profit'), 'sorter' => 'number_sorter'] ]; } -//TODO: Probably going to need to rework these since you can't reference $builder without it's instantiation. /** * @param array $inputs diff --git a/app/Models/Reports/Summary_payments.php b/app/Models/Reports/Summary_payments.php index 0f9558ffbb..aef2be78ed 100644 --- a/app/Models/Reports/Summary_payments.php +++ b/app/Models/Reports/Summary_payments.php @@ -110,7 +110,7 @@ public function getData(array $inputs): array $gift_card_amount = 0; foreach($payments as $key => $payment) { - if(strstr($payment['trans_type'], lang('Sales.giftcard')) !== false) + if(str_contains($payment['trans_type'], lang('Sales.giftcard'))) { $gift_card_count += $payment['trans_sales']; $gift_card_amount += $payment['trans_amount']; @@ -142,12 +142,13 @@ public function getData(array $inputs): array */ protected function create_summary_payments_temp_tables(string $where): void { +//TODO: convert to using QueryBuilder. Use App/Models/Reports/Summary_taxes.php getData() as a reference template $decimals = totals_decimals(); $trans_amount = 'SUM(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) " . ' ELSE sales_items.quantity_purchased * (sales_items.item_unit_price - sales_items.discount) END) AS trans_amount'; -//TODO: look into converting these to use QueryBuilder + $this->db->query('CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->prefixTable('sumpay_taxes_temp') . ' (INDEX(sale_id)) ENGINE=MEMORY ( diff --git a/app/Models/Reports/Summary_report.php b/app/Models/Reports/Summary_report.php index 6743d3d78c..161649d71b 100644 --- a/app/Models/Reports/Summary_report.php +++ b/app/Models/Reports/Summary_report.php @@ -13,6 +13,7 @@ abstract class Summary_report extends Report private function __common_select(array $inputs, &$builder): void //TODO: Hungarian notation { $config = config(OSPOS::class)->settings; +//TODO: convert to using QueryBuilder. Use App/Models/Reports/Summary_taxes.php getData() as a reference template $where = ''; //TODO: Duplicated code if(empty($config['date_or_time_format'])) @@ -81,7 +82,6 @@ private function __common_select(array $inputs, &$builder): void //TODO: Hungari )' ); -//TODO: Probably going to need to rework these since you can't reference $builder without it's instantiation. $builder->select(" IFNULL($sale_subtotal, $sale_total) AS subtotal, $sales_tax AS tax, @@ -92,6 +92,7 @@ private function __common_select(array $inputs, &$builder): void //TODO: Hungari } /** + * @param BaseBuilder $builder * @return void */ private function __common_from(BaseBuilder &$builder): void //TODO: hungarian notation @@ -172,26 +173,26 @@ abstract protected function _get_data_columns(): array; //TODO: hungarian notati /** * @param array $inputs - * @param object $builder + * @param BaseBuilder $builder * @return void */ protected function _select(array $inputs, BaseBuilder &$builder): void { $this->__common_select($inputs, $builder); } //TODO: hungarian notation /** - * @param object $builder + * @param BaseBuilder $builder * @return void */ protected function _from(BaseBuilder &$builder): void { $this->__common_from($builder); } //TODO: hungarian notation TODO: Do we need to pass &$builder to the __common_from()? /** * @param array $inputs - * @param object $builder + * @param BaseBuilder $builder * @return void */ protected function _where(array $inputs, BaseBuilder &$builder): void { $this->__common_where($inputs, $builder); } //TODO: hungarian notation /** - * @param object $builder + * @param BaseBuilder $builder * @return void */ protected function _group_order(BaseBuilder &$builder): void {} //TODO: hungarian notation diff --git a/app/Models/Reports/Summary_suppliers.php b/app/Models/Reports/Summary_suppliers.php index 6fadf60aa6..f8b5ea5f2f 100644 --- a/app/Models/Reports/Summary_suppliers.php +++ b/app/Models/Reports/Summary_suppliers.php @@ -29,7 +29,6 @@ protected function _select(array $inputs, object &$builder): void //TODO: hungar { parent::_select($inputs, $builder); //TODO: hungarian notation -//TODO: Probably going to need to rework these since you can't reference $builder without it's instantiation. $builder->select(' MAX(CONCAT(supplier_c.company_name, " (", supplier_p.first_name, " ", supplier_p.last_name, ")")) AS supplier, SUM(sales_items.quantity_purchased) AS quantity_purchased @@ -44,12 +43,10 @@ protected function _from(object &$builder): void //TODO: hungarian notation { parent::_from($builder); //TODO: hungarian notation -//TODO: Probably going to need to rework these since you can't reference $builder without it's instantiation. $builder->join('items AS items', 'sales_items.item_id = items.item_id'); $builder->join('suppliers AS supplier_c', 'items.supplier_id = supplier_c.person_id '); $builder->join('people AS supplier_p', 'items.supplier_id = supplier_p.person_id'); } -//TODO: Probably going to need to rework these since you can't reference $builder without it's instantiation. /** * @param object $builder diff --git a/app/Models/Sale.php b/app/Models/Sale.php index 9cddabec2a..e50ed8dfc2 100644 --- a/app/Models/Sale.php +++ b/app/Models/Sale.php @@ -494,11 +494,11 @@ public function get_invoice_number_for_year(string $year = '', int $start_from = } /** - * @param $year - * @param $start_from + * @param string $year + * @param int $start_from * @return int */ - public function get_quote_number_for_year($year = '', $start_from = 0): int + public function get_quote_number_for_year(string $year = '', int $start_from = 0): int { return $this->get_number_for_year('quote_number', $year, $start_from); } diff --git a/app/Models/Stock_location.php b/app/Models/Stock_location.php index dff255032c..e8b852d550 100644 --- a/app/Models/Stock_location.php +++ b/app/Models/Stock_location.php @@ -26,6 +26,7 @@ class Stock_location extends Model ]; private Session $session; + private Employee $employee; public function __construct() { @@ -252,7 +253,7 @@ private function _insert_new_permission(string $module, int $location_id, string foreach($employees->getResultArray() as $employee) { - $this->employee = model('Employee'); + $this->employee = model(Employee::class); // Retrieve the menu_group assigned to the grant for the module and use that for the new stock locations $menu_group = $this->employee->get_menu_group($module, $employee['person_id']); diff --git a/app/Models/Tax.php b/app/Models/Tax.php index 9a183c0307..a11b22f344 100644 --- a/app/Models/Tax.php +++ b/app/Models/Tax.php @@ -191,7 +191,7 @@ public function save_value(array &$tax_rate_data, int $tax_rate_id = NEW_ENTRY): /** * Deletes a single tax rate entry */ - public function delete($tax_rate_id = null, bool $purge = false) + public function delete($tax_rate_id = null, bool $purge = false): bool { $builder = $this->db->table('tax_rates'); diff --git a/app/Models/Tax_code.php b/app/Models/Tax_code.php index ee0a235e90..bf3d48aaac 100644 --- a/app/Models/Tax_code.php +++ b/app/Models/Tax_code.php @@ -173,7 +173,7 @@ public function save_tax_codes(array $array_save): bool //TODO: Need to rename $ /** * Deletes a specific tax code */ - public function delete($tax_code = null, bool $purge = false) + public function delete($tax_code = null, bool $purge = false): bool { $builder = $this->db->table('tax_codes'); $builder->where('tax_code', $tax_code); diff --git a/app/Models/Tax_jurisdiction.php b/app/Models/Tax_jurisdiction.php index 0851743173..b5c94b8956 100644 --- a/app/Models/Tax_jurisdiction.php +++ b/app/Models/Tax_jurisdiction.php @@ -183,7 +183,7 @@ public function save_jurisdictions(array $array_save): bool /** * Soft deletes a specific tax jurisdiction */ - public function delete($jurisdiction_id = null, bool $purge = false) + public function delete($jurisdiction_id = null, bool $purge = false): bool { $builder = $this->db->table('tax_jurisdictions'); $builder->where('jurisdiction_id', $jurisdiction_id); diff --git a/app/Models/Tokens/Token.php b/app/Models/Tokens/Token.php index 065fe4f9e0..00efe8a7d9 100644 --- a/app/Models/Tokens/Token.php +++ b/app/Models/Tokens/Token.php @@ -59,7 +59,7 @@ abstract public function token_id(): string; /** * @return mixed */ - abstract public function get_value(); + abstract public function get_value(): mixed; /** * @param $token_id diff --git a/app/Views/cashups/form.php b/app/Views/cashups/form.php index 39487d8839..d3dce6bfbb 100644 --- a/app/Views/cashups/form.php +++ b/app/Views/cashups/form.php @@ -262,7 +262,7 @@ showMeridian: true, @@ -289,7 +289,7 @@ showMeridian: true, diff --git a/app/Views/configs/integrations_config.php b/app/Views/configs/integrations_config.php index 123a2cf8b3..32880eb2ed 100644 --- a/app/Views/configs/integrations_config.php +++ b/app/Views/configs/integrations_config.php @@ -26,7 +26,7 @@
diff --git a/app/Views/configs/locale_config.php b/app/Views/configs/locale_config.php index 2247f99a9f..3ab2343884 100644 --- a/app/Views/configs/locale_config.php +++ b/app/Views/configs/locale_config.php @@ -189,7 +189,7 @@
diff --git a/app/Views/items/form.php b/app/Views/items/form.php index 587de97048..03a9d3fd91 100644 --- a/app/Views/items/form.php +++ b/app/Views/items/form.php @@ -241,7 +241,7 @@ 'name' => 'tax_names[]', 'id' => 'tax_name_1', 'class' => 'form-control input-sm', - 'value' => isset($item_tax_info[0]['name']) ? $item_tax_info[0]['name'] : $config['default_tax_1_name'] + 'value' => $item_tax_info[0]['name'] ?? $config['default_tax_1_name'] ]) ?>
diff --git a/app/Views/partial/datepicker_locale.php b/app/Views/partial/datepicker_locale.php index 4efdc6615d..61251ec86b 100644 --- a/app/Views/partial/datepicker_locale.php +++ b/app/Views/partial/datepicker_locale.php @@ -9,7 +9,7 @@ showMeridian: true, @@ -90,13 +90,13 @@ ], today: "", meridiem: ["am", "pm"], meridiem: ["AM", "PM"], diff --git a/app/Views/sales/form.php b/app/Views/sales/form.php index 42ccf771e1..cd0e09fbb3 100644 --- a/app/Views/sales/form.php +++ b/app/Views/sales/form.php @@ -139,7 +139,7 @@ 'control-label col-xs-3']) ?>
'customer_name', 'value' => $selected_customer_name, 'id' => 'customer_name', 'class' => 'form-control input-sm']) ?> - +