diff --git a/app/Config/Validation/OSPOSRules.php b/app/Config/Validation/OSPOSRules.php index 2e1d1e115..6fc244f87 100644 --- a/app/Config/Validation/OSPOSRules.php +++ b/app/Config/Validation/OSPOSRules.php @@ -44,7 +44,7 @@ class OSPOSRules //GCaptcha Check $gcaptcha_enabled = array_key_exists('gcaptcha_enable', config('OSPOS')->settings) - ? config('OSPOS')->settings['gcaptcha_enable'] + ? $config['gcaptcha_enable'] : false; if($gcaptcha_enabled) @@ -73,7 +73,7 @@ class OSPOSRules if(!empty($response)) { $check = [ - 'secret' => config('OSPOS')->settings['gcaptcha_secret_key'], + 'secret' => $config['gcaptcha_secret_key'], 'response' => $response, 'remoteip' => $this->request->getIPAddress() ]; diff --git a/app/Controllers/Cashups.php b/app/Controllers/Cashups.php index 43f5fcf80..83578c1bc 100644 --- a/app/Controllers/Cashups.php +++ b/app/Controllers/Cashups.php @@ -5,11 +5,13 @@ namespace App\Controllers; use App\Models\Cashup; use App\Models\Expense; use App\Models\Reports\Summary_payments; +use CodeIgniter\Model; /** * @property cashup cashup * @property expense expense * @property summary_payments summary_payments + * @property array $config */ class Cashups extends Secure_Controller { @@ -20,6 +22,7 @@ class Cashups extends Secure_Controller $this->cashup = model('Cashup'); $this->expense = model('Expense'); $this->summary_payments = model('Reports/Summary_payments'); + $this->config = config('OSPOS')->settings; } public function getIndex(): void @@ -102,7 +105,7 @@ class Cashups extends Secure_Controller $cash_ups_info->closed_amount_cash = $cash_ups_info->open_amount_cash + $cash_ups_info->transfer_amount_cash; // if it's date mode only and not date & time truncate the open and end date to date only - if(empty(config('OSPOS')->settings['date_or_time_format'])) + if(empty($this->config['date_or_time_format'])) { // search for all the payments given the time range $inputs = [ @@ -186,10 +189,10 @@ class Cashups extends Secure_Controller public function save(int $cashup_id = -1): void //TODO: Need to replace -1 with a constant in constants.php { $open_date = $this->request->getPost('open_date', FILTER_SANITIZE_STRING); - $open_date_formatter = date_create_from_format(config('OSPOS')->settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'], $open_date); + $open_date_formatter = date_create_from_format($this->config['dateformat'] . ' ' . $this->config['timeformat'], $open_date); $close_date = $this->request->getPost('close_date', FILTER_SANITIZE_NUMBER_INT); - $close_date_formatter = date_create_from_format(config('OSPOS')->settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'], $close_date); + $close_date_formatter = date_create_from_format($this->config['dateformat'] . ' ' . $this->config['timeformat'], $close_date); $cash_up_data = [ 'open_date' => $open_date_formatter->format('Y-m-d H:i:s'), @@ -264,4 +267,4 @@ class Cashups extends Secure_Controller { return ($closed_amount_cash - $open_amount_cash - $transfer_amount_cash + $closed_amount_due + $closed_amount_card + $closed_amount_check); } -} \ No newline at end of file +} diff --git a/app/Controllers/Config.php b/app/Controllers/Config.php index 594b92b04..84e30a326 100644 --- a/app/Controllers/Config.php +++ b/app/Controllers/Config.php @@ -41,6 +41,7 @@ use ReflectionException; * @property rounding_mode rounding_mode * @property stock_location stock_location * @property tax tax + * @property array config */ class Config extends Secure_Controller { @@ -60,6 +61,7 @@ class Config extends Secure_Controller $this->rounding_mode = model('Rounding_mode'); $this->stock_location = model('Stock_location'); $this->tax = model('Tax'); + $this->config = config('OSPOS')->settings; } /* @@ -248,7 +250,7 @@ class Config extends Secure_Controller $data['dinner_tables'] = $this->dinner_table->get_all()->getResultArray(); $data['customer_rewards'] = $this->customer_rewards->get_all()->getResultArray(); $data['support_barcode'] = $this->barcode_lib->get_list_barcodes(); - $data['logo_exists'] = config('OSPOS')->settings['company_logo'] != ''; + $data['logo_exists'] = $this->config['company_logo'] != ''; $data['line_sequence_options'] = $this->sale_lib->get_line_sequence_options(); $data['register_mode_options'] = $this->sale_lib->get_register_mode_options(); $data['invoice_type_options'] = $this->sale_lib->get_invoice_type_options(); @@ -257,7 +259,7 @@ class Config extends Secure_Controller $data['tax_category_options'] = $this->tax_lib->get_tax_category_options(); $data['tax_jurisdiction_options'] = $this->tax_lib->get_tax_jurisdiction_options(); $data['show_office_group'] = $this->module->get_show_office_group(); - $data['currency_code'] = config('OSPOS')->settings['currency_code']; + $data['currency_code'] = $this->config['currency_code']; // load all the license statements, they are already XSS cleaned in the private function $data['licenses'] = $this->_licenses(); @@ -269,7 +271,7 @@ class Config extends Secure_Controller $image_allowed_types = ['jpg','jpeg','gif','svg','webp','bmp','png','tif','tiff']; $data['image_allowed_types'] = array_combine($image_allowed_types,$image_allowed_types); - $data['selected_image_allowed_types'] = explode('|', config('OSPOS')->settings['image_allowed_types']); + $data['selected_image_allowed_types'] = explode('|', $this->config['image_allowed_types']); //Load Integrations Related fields $data['mailchimp'] = []; @@ -278,8 +280,8 @@ class Config extends Secure_Controller { $encrypter = Services::encrypter(); - $data['mailchimp']['api_key'] = $encrypter->decrypt(config('OSPOS')->settings['mailchimp_api_key']); - $data['mailchimp']['list_id'] = $encrypter->decrypt(config('OSPOS')->settings['mailchimp_list_id']); + $data['mailchimp']['api_key'] = $encrypter->decrypt($this->config['mailchimp_api_key']); + $data['mailchimp']['list_id'] = $encrypter->decrypt($this->config['mailchimp_list_id']); } else { @@ -911,7 +913,7 @@ class Config extends Secure_Controller // switches immediately back to the register the mode reflects the change if($success == TRUE) { - if(config('OSPOS')->settings['invoice_enable']) + if($this->config['invoice_enable']) { $this->sale_lib->set_mode($batch_save_data['default_register_mode']); } @@ -939,7 +941,7 @@ class Config extends Secure_Controller */ private function _check_encryption(): bool //TODO: Hungarian notation { - $encryption_key = config('OSPOS')->settings['encryption_key']; + $encryption_key = $this->config['encryption_key']; // check if the encryption_key config item is the default one if($encryption_key == '' || $encryption_key == 'YOUR KEY') diff --git a/app/Controllers/Customers.php b/app/Controllers/Customers.php index 8262abe46..ab1f65332 100644 --- a/app/Controllers/Customers.php +++ b/app/Controllers/Customers.php @@ -24,6 +24,7 @@ use stdClass; * * @property encryption encryption * @property encrypterinterface encrypter + * @property array config * */ class Customers extends Persons @@ -38,10 +39,11 @@ class Customers extends Persons $this->customer = model('Customer'); $this->tax_code = model('Tax_code'); + $this->config = config('OSPOS')->settings; $encrypter = Services::encrypter(); - $this->_list_id = $encrypter->decrypt(config('OSPOS')->settings['mailchimp_list_id']); + $this->_list_id = $encrypter->decrypt($this->config['mailchimp_list_id']); } public function getIndex(): void @@ -174,7 +176,7 @@ class Customers extends Persons $data['packages'] = $packages; $data['selected_package'] = $info->package_id; - if(config('OSPOS')->settings['use_destination_based_tax']) //TODO: This can be shortened for ternary notation + if($$this->config['use_destination_based_tax']) //TODO: This can be shortened for ternary notation { $data['use_destination_based_tax'] = TRUE; } @@ -280,7 +282,7 @@ class Customers extends Persons 'comments' => $this->request->getPost('comments', FILTER_SANITIZE_STRING) ]; - $date_formatter = date_create_from_format(config('OSPOS')->settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'], $this->request->getPost('date', FILTER_SANITIZE_STRING)); + $date_formatter = date_create_from_format($$this->config['dateformat'] . ' ' . $$this->config['timeformat'], $this->request->getPost('date', FILTER_SANITIZE_STRING)); $customer_data = [ 'consent' => $this->request->getPost('consent') != NULL, diff --git a/app/Controllers/Expenses.php b/app/Controllers/Expenses.php index 4ef917df7..bece410a2 100644 --- a/app/Controllers/Expenses.php +++ b/app/Controllers/Expenses.php @@ -136,9 +136,10 @@ class Expenses extends Secure_Controller public function save(int $expense_id = -1): void //TODO: Replace -1 with a constant { + $config = config('OSPOS')->settings; $newdate = $this->request->getPost('date', FILTER_SANITIZE_STRING); - $date_formatter = date_create_from_format(config('OSPOS')->settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'], $newdate); + $date_formatter = date_create_from_format($config['dateformat'] . ' ' . $config['timeformat'], $newdate); $expense_data = [ 'date' => $date_formatter->format('Y-m-d H:i:s'), diff --git a/app/Controllers/Giftcards.php b/app/Controllers/Giftcards.php index a4083c588..220b91354 100644 --- a/app/Controllers/Giftcards.php +++ b/app/Controllers/Giftcards.php @@ -74,11 +74,12 @@ class Giftcards extends Secure_Controller public function view(int $giftcard_id = -1): void //TODO: Need to replace -1 with a constant { + $config = config('OSPOS')->settings; $giftcard_info = $this->giftcard->get_info($giftcard_id); $data['selected_person_name'] = ($giftcard_id > 0 && isset($giftcard_info->person_id)) ? $giftcard_info->first_name . ' ' . $giftcard_info->last_name : ''; $data['selected_person_id'] = $giftcard_info->person_id; - if(config('OSPOS')->settings['giftcard_number'] == 'random') + if($config['giftcard_number'] == 'random') { $data['giftcard_number'] = $giftcard_id > 0 ? $giftcard_info->giftcard_number : ''; } diff --git a/app/Controllers/Items.php b/app/Controllers/Items.php index c4deb4607..c81109c2c 100644 --- a/app/Controllers/Items.php +++ b/app/Controllers/Items.php @@ -35,6 +35,7 @@ require_once('Secure_Controller.php'); * @property stock_location stock_location * @property supplier supplier * @property tax_category tax_category + * @property array config */ class Items extends Secure_Controller { @@ -56,6 +57,7 @@ class Items extends Secure_Controller $this->stock_location = model('Stock_location'); $this->supplier = model('Supplier'); $this->tax_category = model('Tax_category'); + $this->config = config('OSPOS')->settings; } public function getIndex(): void @@ -151,14 +153,14 @@ class Items extends Secure_Controller if(sizeof($images) < 2 && !file_exists($thumb_path)) { - $config['image_library'] = 'gd2'; - $config['source_image'] = $image_path; - $config['maintain_ratio'] = TRUE; - $config['create_thumb'] = TRUE; - $config['width'] = 52; - $config['height'] = 32; + $gd2_config['image_library'] = 'gd2'; + $gd2_config['source_image'] = $image_path; + $gd2_config['maintain_ratio'] = TRUE; + $gd2_config['create_thumb'] = TRUE; + $gd2_config['width'] = 52; + $gd2_config['height'] = 32; - $this->image->initialize($config); + $this->image->initialize($gd2_config); $this->image->resize(); $thumb_path = $this->image->full_dst_path; @@ -285,9 +287,9 @@ class Items extends Secure_Controller } } - $use_destination_based_tax = (boolean)config('OSPOS')->settings['use_destination_based_tax']; - $data['include_hsn'] = config('OSPOS')->settings['include_hsn'] === '1'; - $data['category_dropdown'] = config('OSPOS')->settings['category_dropdown']; + $use_destination_based_tax = (boolean)$this->config['use_destination_based_tax']; + $data['include_hsn'] = $this->config['include_hsn'] === '1'; + $data['category_dropdown'] = $this->config['category_dropdown']; if($data['category_dropdown'] === '1') { @@ -301,8 +303,8 @@ class Items extends Secure_Controller if($item_id === NEW_ITEM) { - $data['default_tax_1_rate'] = config('OSPOS')->settings['default_tax_1_rate']; - $data['default_tax_2_rate'] = config('OSPOS')->settings['default_tax_2_rate']; + $data['default_tax_1_rate'] = $this->config['default_tax_1_rate']; + $data['default_tax_2_rate'] = $this->config['default_tax_2_rate']; $item_info->receiving_quantity = 1; $item_info->reorder_level = 1; @@ -315,7 +317,7 @@ class Items extends Secure_Controller if($use_destination_based_tax) { - $item_info->tax_category_id = config('OSPOS')->settings['default_tax_category']; + $item_info->tax_category_id = $this->config['default_tax_category']; } } @@ -323,7 +325,7 @@ class Items extends Secure_Controller $data['item_kit_disabled'] && $item_info->item_type == ITEM_KIT && !$data['allow_temp_item'] - && !(config('OSPOS')->settings['derive_sale_quantity'] === '1') + && !($this->config['derive_sale_quantity'] === '1') ); $data['item_info'] = $item_info; @@ -472,7 +474,7 @@ class Items extends Secure_Controller foreach($result as &$item) { - if(empty($item['item_number']) && config('OSPOS')->settings['barcode_generate_if_empty']) + if(empty($item['item_number']) && $this->config['barcode_generate_if_empty']) { $barcode_instance = Barcode_lib::barcode_instance($item, $config); $item['item_number'] = $barcode_instance->getData(); @@ -621,7 +623,7 @@ class Items extends Secure_Controller $new_item = TRUE; } - $use_destination_based_tax = (bool)config('OSPOS')->settings['use_destination_based_tax']; + $use_destination_based_tax = (bool)$this->config['use_destination_based_tax']; if(!$use_destination_based_tax) { @@ -734,9 +736,9 @@ class Items extends Secure_Controller 'rules' => [ 'uploaded[items_image]', 'is_image[items_image]', - 'max_size[items_image,' . config('OSPOS')->settings['image_max_size'] . ']', - 'max_dims[items_image,' . config('OSPOS')->settings['image_max_width'] . ',' . config('OSPOS')->settings['image_max_height'] . ']', - 'ext_in[items_image,' . config('OSPOS')->settings['image_allowed_types'] . ']' + 'max_size[items_image,' . $this->config['image_max_size'] . ']', + 'max_dims[items_image,' . $this->config['image_max_width'] . ',' . $this->config['image_max_height'] . ']', + 'ext_in[items_image,' . $this->config['image_allowed_types'] . ']' ] ] ]; diff --git a/app/Controllers/Receivings.php b/app/Controllers/Receivings.php index e02761f20..10c2a4d4a 100644 --- a/app/Controllers/Receivings.php +++ b/app/Controllers/Receivings.php @@ -23,6 +23,7 @@ use ReflectionException; * @property receiving receiving * @property stock_location stock_location * @property supplier supplier + * @property array config */ class Receivings extends Secure_Controller { @@ -40,6 +41,7 @@ class Receivings extends Secure_Controller $this->receiving = model('Receiving'); $this->stock_location = model('Stock_location'); $this->supplier = model('Supplier'); + $this->config = config('OSPOS')->settings; } public function getIndex(): void @@ -135,8 +137,8 @@ class Receivings extends Secure_Controller $this->token_lib->parse_barcode($quantity, $price, $item_id_or_number_or_item_kit_or_receipt); $quantity = ($mode == 'receive' || $mode == 'requisition') ? $quantity : -$quantity; $item_location = $this->receiving_lib->get_stock_source(); - $discount = config('OSPOS')->settings['default_receivings_discount']; - $discount_type = config('OSPOS')->settings['default_receivings_discount_type']; + $discount = $this->config['default_receivings_discount']; + $discount_type = $this->config['default_receivings_discount_type']; if($mode == 'return' && $this->receiving->is_valid_receipt($item_id_or_number_or_item_kit_or_receipt)) { @@ -445,7 +447,7 @@ class Receivings extends Secure_Controller { $newdate = $this->request->getPost('date', FILTER_SANITIZE_STRING); //TODO: newdate does not follow naming conventions - $date_formatter = date_create_from_format(config('OSPOS')->settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'], $newdate); + $date_formatter = date_create_from_format($this->config['dateformat'] . ' ' . $this->config['timeformat'], $newdate); $receiving_time = $date_formatter->format('Y-m-d H:i:s'); $receiving_data = [ @@ -485,4 +487,4 @@ class Receivings extends Secure_Controller $this->_reload(); //TODO: Hungarian Notation } -} \ No newline at end of file +} diff --git a/app/Controllers/Reports.php b/app/Controllers/Reports.php index 6b8d935a2..56767e39f 100644 --- a/app/Controllers/Reports.php +++ b/app/Controllers/Reports.php @@ -25,7 +25,6 @@ use App\Models\Reports\Summary_sales; use App\Models\Reports\Summary_sales_taxes; use App\Models\Reports\Summary_suppliers; use App\Models\Reports\Summary_taxes; -use CodeIgniter\HTTP\Uri; use Config\Services; /** @@ -52,6 +51,7 @@ use Config\Services; * @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 { @@ -61,6 +61,7 @@ class Reports extends Secure_Controller $request = Services::request(); $method_name = $request->getUri()->getSegment(2); $exploder = explode('_', $method_name); + $this->config = config('OSPOS')->settings; if(sizeof($exploder) > 1) { @@ -1575,10 +1576,10 @@ class Reports extends Secure_Controller $sale_type_options = []; $sale_type_options['complete'] = lang('Reports.complete'); $sale_type_options['sales'] = lang('Reports.completed_sales'); - if(config('OSPOS')->settings['invoice_enable']) + if($this->config['invoice_enable']) { $sale_type_options['quotes'] = lang('Reports.quotes'); - if(config('OSPOS')->settings['work_order_enable']) + if($this->config['work_order_enable']) { $sale_type_options['work_orders'] = lang('Reports.work_orders'); } @@ -1909,13 +1910,13 @@ class Reports extends Secure_Controller { $subtitle = ''; - if(empty(config('OSPOS')->settings['date_or_time_format'])) + if(empty($this->config['date_or_time_format'])) { - $subtitle .= date(config('OSPOS')->settings['dateformat'], strtotime($inputs['start_date'])) . ' - ' . date(config('OSPOS')->settings['dateformat'], strtotime($inputs['end_date'])); + $subtitle .= date($this->config['dateformat'], strtotime($inputs['start_date'])) . ' - ' . date($this->config['dateformat'], strtotime($inputs['end_date'])); } else { - $subtitle .= date(config('OSPOS')->settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'], strtotime(rawurldecode($inputs['start_date']))) . ' - ' . date(config('OSPOS')->settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'], strtotime(rawurldecode($inputs['end_date']))); + $subtitle .= date($this->config['dateformat'] . ' ' . $this->config['timeformat'], strtotime(rawurldecode($inputs['start_date']))) . ' - ' . date($this->config['dateformat'] . ' ' . $this->config['timeformat'], strtotime(rawurldecode($inputs['end_date']))); } return $subtitle; diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php index 65f39cc4f..338f8925e 100644 --- a/app/Controllers/Sales.php +++ b/app/Controllers/Sales.php @@ -39,6 +39,7 @@ use ReflectionException; * @property item_kit item_kit * @property sale sale * @property stock_location stock_location + * @property array config */ class Sales extends Secure_Controller { @@ -53,6 +54,7 @@ class Sales extends Secure_Controller $this->sale_lib = new Sale_lib(); $this->tax_lib = new Tax_lib(); $this->token_lib = new Token_lib(); + $this->config = config('OSPOS')->settings; } public function getIndex(): void @@ -109,7 +111,7 @@ class Sales extends Secure_Controller 'only_due' => FALSE, 'only_check' => FALSE, 'only_creditcard' => FALSE, - 'only_invoices' => config('OSPOS')->settings['invoice_enable'] && $this->request->getGet('only_invoices', FILTER_SANITIZE_NUMBER_INT), + 'only_invoices' => $this->config['invoice_enable'] && $this->request->getGet('only_invoices', FILTER_SANITIZE_NUMBER_INT), 'is_valid_receipt' => $this->sale->is_valid_receipt($search) ]; @@ -210,7 +212,7 @@ class Sales extends Secure_Controller $this->sale_lib->set_sale_type(SALE_TYPE_RETURN); } - if(config('OSPOS')->settings['dinner_table_enable']) + if($this->config['dinner_table_enable']) { $occupied_dinner_table = $this->request->getPost('dinner_table', FILTER_SANITIZE_NUMBER_INT); $released_dinner_table = $this->sale_lib->get_dinner_table(); @@ -451,8 +453,8 @@ class Sales extends Secure_Controller { $data = []; - $discount = config('OSPOS')->settings['default_sales_discount']; - $discount_type = config('OSPOS')->settings['default_sales_discount_type']; + $discount = $this->config['default_sales_discount']; + $discount_type = $this->config['default_sales_discount_type']; // check if any discount is assigned to the selected customer $customer_id = $this->sale_lib->get_customer(); @@ -625,7 +627,7 @@ class Sales extends Secure_Controller $data['cart'] = $this->sale_lib->get_cart(); - $data['include_hsn'] = (bool)config('OSPOS')->settings['include_hsn']; + $data['include_hsn'] = (bool)$this->config['include_hsn']; $__time = time(); $data['transaction_time'] = to_datetime($__time); $data['transaction_date'] = to_date($__time); @@ -635,16 +637,16 @@ class Sales extends Secure_Controller $employee_info = $this->employee->get_info($employee_id); $data['employee'] = $employee_info->first_name . ' ' . mb_substr($employee_info->last_name, 0, 1); - $data['company_info'] = implode("\n", [config('OSPOS')->settings['address'], config('OSPOS')->settings['phone']]); + $data['company_info'] = implode("\n", [$this->config['address'], $this->config['phone']]); - if(config('OSPOS')->settings['account_number']) + if($this->config['account_number']) { - $data['company_info'] .= "\n" . lang('Sales.account_number') . ": " . config('OSPOS')->settings['account_number']; + $data['company_info'] .= "\n" . lang('Sales.account_number') . ": " . $this->config['account_number']; } - if(config('OSPOS')->settings['tax_id'] != '') + if($this->config['tax_id'] != '') { - $data['company_info'] .= "\n" . lang('Sales.tax_id') . ": " . config('OSPOS')->settings['tax_id']; + $data['company_info'] .= "\n" . lang('Sales.tax_id') . ": " . $this->config['tax_id']; } $data['invoice_number_enabled'] = $this->sale_lib->is_invoice_mode(); @@ -723,7 +725,7 @@ class Sales extends Secure_Controller if($this->sale_lib->is_invoice_mode()) { - $invoice_format = config('OSPOS')->settings['sales_invoice_format']; + $invoice_format = $this->config['sales_invoice_format']; // generate final invoice number (if using the invoice in sales by receipt mode then the invoice number can be manually entered or altered in some way if(!empty($invoice_format) && $invoice_number == NULL) @@ -745,7 +747,7 @@ class Sales extends Secure_Controller $sale_type = SALE_TYPE_INVOICE; // The PHP file name is the same as the invoice_type key - $invoice_view = config('OSPOS')->settings['invoice_type']; + $invoice_view = $this->config['invoice_type']; // Save the data to the sales table $data['sale_id_num'] = $this->sale->save_value($sale_id, $data['sale_status'], $data['cart'], $customer_id, $employee_id, $data['comments'], $invoice_number, $work_order_number, $quote_number, $sale_type, $data['payments'], $data['dinner_table'], $tax_details); @@ -780,7 +782,7 @@ class Sales extends Secure_Controller if($work_order_number == NULL) { // generate work order number - $work_order_format = config('OSPOS')->settings['work_order_format']; + $work_order_format = $this->config['work_order_format']; $work_order_number = $this->token_lib->render($work_order_format); } @@ -815,7 +817,7 @@ class Sales extends Secure_Controller if($quote_number == NULL) { // generate quote number - $quote_format = config('OSPOS')->settings['sales_quote_format']; + $quote_format = $this->config['sales_quote_format']; $quote_number = $this->token_lib->render($quote_format); } @@ -892,14 +894,14 @@ class Sales extends Secure_Controller $number = $sale_data[$type."_number"]; $subject = lang('Sales.' . $type) . ' ' . $number; - $text = config('OSPOS')->settings['invoice_email_message']; + $text = $this->config['invoice_email_message']; $tokens = [ new Token_invoice_sequence($sale_data['invoice_number']), new Token_invoice_count('POS ' . $sale_data['sale_id']), new Token_customer((object)$sale_data) ]; $text = $this->token_lib->render($text, $tokens); - $sale_data['mimetype'] = mime_content_type(WRITEPATH . 'uploads/' . config('OSPOS')->settings['company_logo']); + $sale_data['mimetype'] = mime_content_type(WRITEPATH . 'uploads/' . $this->config['company_logo']); // generate email attachment: invoice in pdf format $view = Services::renderer(); @@ -1045,7 +1047,7 @@ class Sales extends Secure_Controller $data['transaction_date'] = to_date(strtotime($sale_info['sale_time'])); $data['show_stock_locations'] = $this->stock_location->show_locations('sales'); - $data['include_hsn'] = (bool)config('OSPOS')->settings['include_hsn']; + $data['include_hsn'] = (bool)$this->config['include_hsn']; // Returns 'subtotal', 'total', 'cash_total', 'payment_total', 'amount_due', 'cash_amount_due', 'payments_cover_total' $totals = $this->sale_lib->get_totals($tax_details[0]); @@ -1084,15 +1086,15 @@ class Sales extends Secure_Controller $data['quote_number'] = $sale_info['quote_number']; $data['sale_status'] = $sale_info['sale_status']; - $data['company_info'] = implode('\n', [config('OSPOS')->settings['address'], config('OSPOS')->settings['phone']]); //TODO: Duplicated code. + $data['company_info'] = implode('\n', [$this->config['address'], $this->config['phone']]); //TODO: Duplicated code. - if(config('OSPOS')->settings['account_number']) + if($this->config['account_number']) { - $data['company_info'] .= '\n' . lang('Sales.account_number') . ": " . config('OSPOS')->settings['account_number']; + $data['company_info'] .= '\n' . lang('Sales.account_number') . ": " . $this->config['account_number']; } - if(config('OSPOS')->settings['tax_id'] != '') + if($this->config['tax_id'] != '') { - $data['company_info'] .= '\n' . lang('Sales.tax_id') . ": " . config('OSPOS')->settings['tax_id']; + $data['company_info'] .= '\n' . lang('Sales.tax_id') . ": " . $this->config['tax_id']; } $data['barcode'] = $this->barcode_lib->generate_receipt_barcode($data['sale_id']); @@ -1125,7 +1127,7 @@ class Sales extends Secure_Controller $data['customer_required'] = lang('Sales.customer_optional'); } - $invoice_type = config('OSPOS')->settings['invoice_type']; + $invoice_type = $this->config['invoice_type']; $data['invoice_view'] = $invoice_type; return $data; @@ -1197,7 +1199,7 @@ class Sales extends Secure_Controller $data['comment'] = $this->sale_lib->get_comment(); $data['email_receipt'] = $this->sale_lib->is_email_receipt(); - if($customer_info && config('OSPOS')->settings['customer_reward_enable']) + if($customer_info && $this->config['customer_reward_enable']) { $data['payment_options'] = $this->sale->get_payment_options(TRUE, TRUE); } @@ -1210,7 +1212,7 @@ class Sales extends Secure_Controller $data['change_price'] = $this->employee->has_grant('sales_change_price', $this->employee->get_logged_in_employee_info()->person_id); $temp_invoice_number = $this->sale_lib->get_invoice_number(); - $invoice_format = config('OSPOS')->settings['sales_invoice_format']; + $invoice_format = $this->config['sales_invoice_format']; if ($temp_invoice_number == NULL || $temp_invoice_number == '') { @@ -1394,7 +1396,7 @@ class Sales extends Secure_Controller $newdate = $this->request->getPost('date', FILTER_SANITIZE_STRING); $employee_id = $this->employee->get_logged_in_employee_info()->person_id; - $date_formatter = date_create_from_format(config('OSPOS')->settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'], $newdate); + $date_formatter = date_create_from_format($this->config['dateformat'] . ' ' . $this->config['timeformat'], $newdate); $sale_time = $date_formatter->format('Y-m-d H:i:s'); $sale_data = [ @@ -1505,7 +1507,7 @@ class Sales extends Secure_Controller { $sale_type = $this->sale_lib->get_sale_type(); - if(config('OSPOS')->settings['dinner_table_enable']) + if($this->config['dinner_table_enable']) { $dinner_table = $this->sale_lib->get_dinner_table(); $this->dinner_table->release($dinner_table); diff --git a/app/Controllers/Taxes.php b/app/Controllers/Taxes.php index 4f2e7178c..6dc850077 100644 --- a/app/Controllers/Taxes.php +++ b/app/Controllers/Taxes.php @@ -30,6 +30,7 @@ class Taxes extends Secure_Controller $this->tax_jurisdiction = model('Tax_jurisdiction'); $this->tax_lib = new Tax_lib(); + $this->config = config('OSPOS')->settings; helper('tax_helper'); } @@ -58,7 +59,7 @@ class Taxes extends Secure_Controller $data['tax_categories_table_headers'] = get_tax_categories_table_headers(); $data['tax_types'] = $this->tax_lib->get_tax_types(); - if(config('OSPOS')->settings['tax_included']) + if($this->config['tax_included']) { $data['default_tax_type'] = Tax_lib::TAX_TYPE_INCLUDED; } @@ -134,7 +135,7 @@ class Taxes extends Secure_Controller $tax_rate_info = $this->tax->get_rate_info($tax_code, $default_tax_category_id); - if(config('OSPOS')->settings['tax_included']) + if($this->config['tax_included']) { $data['default_tax_type'] = Tax_lib::TAX_TYPE_INCLUDED; } @@ -206,9 +207,9 @@ class Taxes extends Secure_Controller if($tax_rate_id == -1) //TODO: Replace -1 with constant { - $data['rate_tax_code_id'] = config('OSPOS')->settings['default_tax_code']; - $data['rate_tax_category_id'] = config('OSPOS')->settings['default_tax_category']; - $data['rate_jurisdiction_id'] = config('OSPOS')->settings['default_tax_jurisdiction']; + $data['rate_tax_code_id'] = $this->config['default_tax_code']; + $data['rate_tax_category_id'] = $this->config['default_tax_category']; + $data['rate_jurisdiction_id'] = $this->config['default_tax_jurisdiction']; $data['tax_rounding_code'] = rounding_mode::HALF_UP; $data['tax_rate'] = '0.0000'; } @@ -237,7 +238,7 @@ class Taxes extends Secure_Controller $data['rounding_options'] = rounding_mode::get_rounding_options(); $data['html_rounding_options'] = $this->get_html_rounding_options(); - if(config('OSPOS')->settings['tax_included']) + if($this->config['tax_included']) { $data['default_tax_type'] = Tax_lib::TAX_TYPE_INCLUDED; } @@ -304,7 +305,7 @@ class Taxes extends Secure_Controller $data['rounding_options'] = rounding_mode::get_rounding_options(); $data['html_rounding_options'] = $this->get_html_rounding_options(); - if(config('OSPOS')->settings['tax_included']) + if($this->config['tax_included']) { $data['default_tax_type'] = Tax_lib::TAX_TYPE_INCLUDED; } @@ -557,7 +558,7 @@ class Taxes extends Secure_Controller { $tax_jurisdictions = $this->tax_jurisdiction->get_all()->getResultArray(); - if(config('OSPOS')->settings['tax_included']) //TODO: ternary notation + if($this->config['tax_included']) //TODO: ternary notation { $default_tax_type = Tax_lib::TAX_TYPE_INCLUDED; } @@ -574,4 +575,4 @@ class Taxes extends Secure_Controller 'default_tax_type' => $default_tax_type ]); } -} \ No newline at end of file +} diff --git a/app/Database/Migrations/20210422000000_database_optimizations.php b/app/Database/Migrations/20210422000000_database_optimizations.php index 231bfad1c..f2d50e965 100644 --- a/app/Database/Migrations/20210422000000_database_optimizations.php +++ b/app/Database/Migrations/20210422000000_database_optimizations.php @@ -60,7 +60,7 @@ class Migration_database_optimizations extends Migration break; case DATE: $attribute_date = DateTime::createFromFormat('Y-m-d', $attribute_value['attribute_date']); - $value = $attribute_date->format(config('OSPOS')->settings['dateformat']); + $value = $attribute_date->format($config['dateformat']); break; default: $value = $attribute_value['attribute_value']; diff --git a/app/Helpers/locale_helper.php b/app/Helpers/locale_helper.php index 23e54df0c..c46f82862 100644 --- a/app/Helpers/locale_helper.php +++ b/app/Helpers/locale_helper.php @@ -16,6 +16,7 @@ define('DEFAULT_DATETIME', mktime(0, 0, 0, 1, 1, 2010)); function current_language_code(bool $load_system_language = false): string { $employee = model(Employee::class); + $config = config('OSPOS')->settings; // Returns the language code of the employee if set or system language code if not if($employee->is_logged_in() && $load_system_language === false) @@ -28,7 +29,7 @@ function current_language_code(bool $load_system_language = false): string } } - $language_code = config('OSPOS')->settings['language_code']; + $language_code = $config['language_code']; return empty($language_code) ? DEFAULT_LANGUAGE_CODE : $language_code; } @@ -36,6 +37,7 @@ function current_language_code(bool $load_system_language = false): string function current_language(bool $load_system_language = FALSE): string { $employee = model(Employee::class); + $config = config('OSPOS')->settings; // Returns the language of the employee if set or system language if not if($employee->is_logged_in() && !$load_system_language) @@ -48,7 +50,7 @@ function current_language(bool $load_system_language = FALSE): string } } - $language = config('OSPOS')->settings['language']; + $language = $config['language']; return empty($language) ? DEFAULT_LANGUAGE : $language; } @@ -229,33 +231,34 @@ function get_timeformats(): array function get_payment_options(): array { $payments = []; + $config = config('OSPOS')->settings; //TODO: This needs to be switched to a switch statement - if(config('OSPOS')->settings['payment_options_order'] == 'debitcreditcash') //TODO: === + if($config['payment_options_order'] == 'debitcreditcash') //TODO: === { $payments[lang('Sales.debit')] = lang('Sales.debit'); $payments[lang('Sales.credit')] = lang('Sales.credit'); $payments[lang('Sales.cash')] = lang('Sales.cash'); } - elseif(config('OSPOS')->settings['payment_options_order'] == 'debitcashcredit') //TODO: === + elseif($config['payment_options_order'] == 'debitcashcredit') //TODO: === { $payments[lang('Sales.debit')] = lang('Sales.debit'); $payments[lang('Sales.cash')] = lang('Sales.cash'); $payments[lang('Sales.credit')] = lang('Sales.credit'); } - elseif(config('OSPOS')->settings['payment_options_order'] == 'creditdebitcash') //TODO: === + elseif($config['payment_options_order'] == 'creditdebitcash') //TODO: === { $payments[lang('Sales.credit')] = lang('Sales.credit'); $payments[lang('Sales.debit')] = lang('Sales.debit'); $payments[lang('Sales.cash')] = lang('Sales.cash'); } - elseif(config('OSPOS')->settings['payment_options_order'] == 'creditcashdebit') //TODO: === + elseif($config['payment_options_order'] == 'creditcashdebit') //TODO: === { $payments[lang('Sales.credit')] = lang('Sales.credit'); $payments[lang('Sales.cash')] = lang('Sales.cash'); $payments[lang('Sales.debit')] = lang('Sales.debit'); } - else // default: if(config('OSPOS')->settings['payment_options_order == 'cashdebitcredit') + else // default: if($config['payment_options_order == 'cashdebitcredit') { $payments[lang('Sales.cash')] = lang('Sales.cash'); $payments[lang('Sales.debit')] = lang('Sales.debit'); @@ -266,7 +269,7 @@ function get_payment_options(): array $payments[lang('Sales.check')] = lang('Sales.check'); // If India (list of country codes include India) then include Unified Payment Interface - if (stripos(config('OSPOS')->settings['country_codes'], 'IN') !== false) + if (stripos($config['country_codes'], 'IN') !== false) { $payments[lang('Sales.upi')] = lang('Sales.upi'); } @@ -276,40 +279,47 @@ function get_payment_options(): array function currency_side(): bool { - $fmt = new NumberFormatter(config('OSPOS')->settings['number_locale'], NumberFormatter::CURRENCY); - $fmt->setSymbol(NumberFormatter::CURRENCY_SYMBOL, config('OSPOS')->settings['currency_symbol']); + $config = config('OSPOS')->settings; + $fmt = new NumberFormatter($config['number_locale'], NumberFormatter::CURRENCY); + $fmt->setSymbol(NumberFormatter::CURRENCY_SYMBOL, $config['currency_symbol']); return !preg_match('/^ยค/', $fmt->getPattern()); } function quantity_decimals(): int { - return config('OSPOS')->settings['quantity_decimals'] ? config('OSPOS')->settings['quantity_decimals'] : 0; + $config = config('OSPOS')->settings; + return $config['quantity_decimals'] ? $config['quantity_decimals'] : 0; } function totals_decimals(): int { - return config('OSPOS')->settings['currency_decimals'] ? (int)config('OSPOS')->settings['currency_decimals'] : 0; + $config = config('OSPOS')->settings; + return $config['currency_decimals'] ? (int)$config['currency_decimals'] : 0; } function cash_decimals(): int { - return config('OSPOS')->settings['cash_decimals'] ? config('OSPOS')->settings['cash_decimals'] : 0; + $config = config('OSPOS')->settings; + return $config['cash_decimals'] ? $config['cash_decimals'] : 0; } function tax_decimals(): int { - return config('OSPOS')->settings['tax_decimals'] ? config('OSPOS')->settings['tax_decimals'] : 0; + $config = config('OSPOS')->settings; + return $config['tax_decimals'] ? $config['tax_decimals'] : 0; } function to_date(int $date = DEFAULT_DATE): string { - return date(config('OSPOS')->settings['dateformat, $date']); + $config = config('OSPOS')->settings; + return date($config['dateformat, $date']); } function to_datetime(int $datetime = DEFAULT_DATETIME): string { - return date(config('OSPOS')->settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'], $datetime); + $config = config('OSPOS')->settings; + return date($config['dateformat'] . ' ' . $config['timeformat'], $datetime); } function to_currency(float $number): string @@ -324,7 +334,9 @@ function to_currency_no_money(float $number): string function to_currency_tax(float $number): string { - if(config('OSPOS')->settings['tax_included']) //TODO: ternary notation + $config = config('OSPOS')->settings; + + if($config['tax_included']) //TODO: ternary notation { return to_decimals($number, 'tax_decimals', NumberFormatter::CURRENCY); } @@ -360,15 +372,16 @@ function to_decimals(float $number, string $decimals = NULL, int $type = NumberF return $number; } - $fmt = new NumberFormatter(config('OSPOS')->settings['number_locale'], $type); - $fmt->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, empty($decimals) ? DEFAULT_PRECISION : config('OSPOS')->settings[$decimals]); - $fmt->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, empty($decimals) ? DEFAULT_PRECISION : config('OSPOS')->settings[$decimals]); + $config = config('OSPOS')->settings; + $fmt = new NumberFormatter($config['number_locale'], $type); + $fmt->setAttribute(NumberFormatter::MIN_FRACTION_DIGITS, empty($decimals) ? DEFAULT_PRECISION : $config[$decimals]); + $fmt->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, empty($decimals) ? DEFAULT_PRECISION : $config[$decimals]); - if(empty(config('OSPOS')->settings['thousands_separator'])) + if(empty($config['thousands_separator'])) { $fmt->setAttribute(NumberFormatter::GROUPING_SEPARATOR_SYMBOL, ''); } - $fmt->setSymbol(NumberFormatter::CURRENCY_SYMBOL, config('OSPOS')->settings['currency_symbol']); + $fmt->setSymbol(NumberFormatter::CURRENCY_SYMBOL, $config['currency_symbol']); return $fmt->format($number); } @@ -410,14 +423,16 @@ function parse_decimals(string $number, int $decimals = NULL) return FALSE; } + $config = config('OSPOS')->settings; + if($decimals === NULL) { - $decimals = config('OSPOS')->settings['currency_decimals']; //TODO: $decimals is never used. + $decimals = $config['currency_decimals']; //TODO: $decimals is never used. } - $fmt = new NumberFormatter(config('OSPOS')->settings['number_locale'], NumberFormatter::DECIMAL); + $fmt = new NumberFormatter($config['number_locale'], NumberFormatter::DECIMAL); - if(empty(config('OSPOS')->settings['thousands_separator'])) + if(empty($config['thousands_separator'])) { $fmt->setAttribute(NumberFormatter::GROUPING_SEPARATOR_SYMBOL, ''); } @@ -482,7 +497,8 @@ function dateformat_momentjs(string $php_format): string function dateformat_mysql(): string { - $php_format = config('OSPOS')->settings['dateformat']; + $config = config('OSPOS')->settings; + $php_format = $config['dateformat']; $SYMBOLS_MATCHING = [ // Day @@ -566,7 +582,8 @@ function dateformat_bootstrap(string $php_format): string function valid_date(string $date): bool //TODO: need a better name for $date. Perhaps $candidate. Also the function name would be better as is_valid_date() { - return (DateTime::createFromFormat(config('OSPOS')->settings['dateformat'], $date)); + $config = config('OSPOS')->settings; + return (DateTime::createFromFormat($config['dateformat'], $date)); } function valid_decimal(string $decimal): bool //TODO: need a better name for $decimal. Perhaps $candidate. Also the function name would be better as is_valid_decimal() diff --git a/app/Helpers/tabular_helper.php b/app/Helpers/tabular_helper.php index 658c9e9d4..fca02ca04 100644 --- a/app/Helpers/tabular_helper.php +++ b/app/Helpers/tabular_helper.php @@ -75,8 +75,9 @@ function get_sales_manage_table_headers(): string ['change_due' => lang('Sales.change_due')], ['payment_type' => lang('Sales.payment_type')] ]; + $config = config('OSPOS')->settings; - if(config('OSPOS')->settings['invoice_enable']) + if($config['invoice_enable']) { $headers[] = ['invoice_number' => lang('Sales.invoice_number')]; $headers[] = ['invoice' => ' ', 'sortable' => FALSE, 'escape' => FALSE]; @@ -105,7 +106,9 @@ function get_sale_data_row(object $sale): array 'payment_type' => $sale->payment_type ]; - if(config('OSPOS')->settings['invoice_enable']) + $config = config('OSPOS')->settings; + + if($config['invoice_enable']) { $row['invoice_number'] = $sale->invoice_number; $row['invoice'] = empty($sale->invoice_number) @@ -390,7 +393,7 @@ function get_supplier_data_row(object $supplier): array function get_items_manage_table_headers(): string { $attribute = model(Attribute::class); - + $config = config('OSPOS')->settings; $definition_names = $attribute->get_definitions_by_flags($attribute::SHOW_IN_ITEMS); //TODO: this should be made into a constant in constants.php $headers = [ @@ -404,7 +407,7 @@ function get_items_manage_table_headers(): string ['quantity' => lang('Items.quantity')] ]; - if(config('OSPOS')->settings['use_destination_based_tax']) + if($config['use_destination_based_tax']) { $headers[] = ['tax_percents' => lang('Items.tax_category'), 'sortable' => FALSE]; } @@ -439,8 +442,9 @@ function get_item_data_row(object $item): array $attribute = model(Attribute::class); $item_taxes = model(Item_taxes::class); $tax_category = model(Tax_category::class); + $config = config('OSPOS')->settings; - if(config('OSPOS')->settings['use_destination_based_tax']) + if($config['use_destination_based_tax']) { if($item->tax_category_id == NULL) //TODO: === ? { @@ -489,7 +493,7 @@ function get_item_data_row(object $item): array } } - if(config('OSPOS')->settings['multi_pack_enabled']) + if($config['multi_pack_enabled']) { $item->name .= NAME_SEPARATOR . $item->pack_name; } diff --git a/app/Libraries/Barcode_lib.php b/app/Libraries/Barcode_lib.php index ac32e6e5d..092ea2473 100644 --- a/app/Libraries/Barcode_lib.php +++ b/app/Libraries/Barcode_lib.php @@ -27,21 +27,23 @@ class Barcode_lib public function get_barcode_config(): array { - $data['company'] = config('OSPOS')->settings['company']; - $data['barcode_content'] = config('OSPOS')->settings['barcode_content']; - $data['barcode_type'] = config('OSPOS')->settings['barcode_type']; - $data['barcode_font'] = config('OSPOS')->settings['barcode_font']; - $data['barcode_font_size'] = config('OSPOS')->settings['barcode_font_size']; - $data['barcode_height'] = config('OSPOS')->settings['barcode_height']; - $data['barcode_width'] = config('OSPOS')->settings['barcode_width']; - $data['barcode_first_row'] = config('OSPOS')->settings['barcode_first_row']; - $data['barcode_second_row'] = config('OSPOS')->settings['barcode_second_row']; - $data['barcode_third_row'] = config('OSPOS')->settings['barcode_third_row']; - $data['barcode_num_in_row'] = config('OSPOS')->settings['barcode_num_in_row']; - $data['barcode_page_width'] = config('OSPOS')->settings['barcode_page_width']; - $data['barcode_page_cellspacing'] = config('OSPOS')->settings['barcode_page_cellspacing']; - $data['barcode_generate_if_empty'] = config('OSPOS')->settings['barcode_generate_if_empty']; - $data['barcode_formats'] = config('OSPOS')->settings['barcode_formats']; + $config = config('OSPOS')->settings; + + $data['company'] = $config['company']; + $data['barcode_content'] = $config['barcode_content']; + $data['barcode_type'] = $config['barcode_type']; + $data['barcode_font'] = $config['barcode_font']; + $data['barcode_font_size'] = $config['barcode_font_size']; + $data['barcode_height'] = $config['barcode_height']; + $data['barcode_width'] = $config['barcode_width']; + $data['barcode_first_row'] = $config['barcode_first_row']; + $data['barcode_second_row'] = $config['barcode_second_row']; + $data['barcode_third_row'] = $config['barcode_third_row']; + $data['barcode_num_in_row'] = $config['barcode_num_in_row']; + $data['barcode_page_width'] = $config['barcode_page_width']; + $data['barcode_page_cellspacing'] = $config['barcode_page_cellspacing']; + $data['barcode_generate_if_empty'] = $config['barcode_generate_if_empty']; + $data['barcode_formats'] = $config['barcode_formats']; return $data; } @@ -246,4 +248,4 @@ class Barcode_lib { return substr($font_file_name, 0, -4); } -} \ No newline at end of file +} diff --git a/app/Libraries/Email_lib.php b/app/Libraries/Email_lib.php index 73f6bcc6a..2abece36b 100644 --- a/app/Libraries/Email_lib.php +++ b/app/Libraries/Email_lib.php @@ -16,6 +16,7 @@ use Config\Services; * @property email email * @property encryption encryption * @property encrypterinterface encrypter + * @property array config */ class Email_lib @@ -23,23 +24,25 @@ class Email_lib public function __construct() { $this->email = new Email(); + $this->config = config('OSPOS')->settings; $encrypter = Services::encrypter(); - - $config = [ + + + $email_config = [ 'mailtype' => 'html', 'useragent' => 'OSPOS', 'validate' => TRUE, - 'protocol' => config('OSPOS')->settings['protocol'], - 'mailpath' => config('OSPOS')->settings['mailpath'], - 'smtp_host' => config('OSPOS')->settings['smtp_host'], - 'smtp_user' => config('OSPOS')->settings['smtp_user'], - 'smtp_pass' => $encrypter->decrypt(config('OSPOS')->settings['smtp_pass']), - 'smtp_port' => config('OSPOS')->settings['smtp_port'], - 'smtp_timeout' => config('OSPOS')->settings['smtp_timeout'], - 'smtp_crypto' => config('OSPOS')->settings['smtp_crypto'] + 'protocol' => $this->config['protocol'], + 'mailpath' => $this->config['mailpath'], + 'smtp_host' => $this->config['smtp_host'], + 'smtp_user' => $this->config['smtp_user'], + 'smtp_pass' => $encrypter->decrypt($this->config['smtp_pass']), + 'smtp_port' => $this->config['smtp_port'], + 'smtp_timeout' => $this->config['smtp_timeout'], + 'smtp_crypto' => $this->config['smtp_crypto'] ]; - $this->email->initialize($config); + $this->email->initialize($email_config); } /** @@ -50,7 +53,7 @@ class Email_lib { $email = $this->email; - $email->setFrom(config('OSPOS')->settings['email'], config('OSPOS')->settings['company']); + $email->setFrom($this->config['email'], $this->config['company']); $email->setTo($to); $email->setSubject($subject); $email->setMessage($message); diff --git a/app/Libraries/Mailchimp_lib.php b/app/Libraries/Mailchimp_lib.php index edf532324..08cba4e54 100644 --- a/app/Libraries/Mailchimp_lib.php +++ b/app/Libraries/Mailchimp_lib.php @@ -37,10 +37,11 @@ class MailchimpConnector */ public function __construct(string $api_key = '') { + $config = config('OSPOS')->settings; $encrypter = Services::encrypter(); $this->_api_key = empty($api_key) - ? $encrypter->decrypt(config('OSPOS')->settings['mailchimp_api_key']) //TODO: Hungarian notation + ? $encrypter->decrypt($config['mailchimp_api_key']) //TODO: Hungarian notation : $api_key; //TODO: Hungarian notation if(!empty($this->_api_key)) //TODO: Hungarian notation diff --git a/app/Libraries/Receiving_lib.php b/app/Libraries/Receiving_lib.php index e605b66b6..2236534bf 100644 --- a/app/Libraries/Receiving_lib.php +++ b/app/Libraries/Receiving_lib.php @@ -185,6 +185,8 @@ class Receiving_lib //TODO: This array signature needs to be reworked. It's way too long. Perhaps an object needs to be passed rather than these? public function add_item(int $item_id, int $quantity = 1, int $item_location = NULL, float $discount = 0, int $discount_type = 0, float $price = NULL, string $description = NULL, string $serialnumber = NULL, float $receiving_quantity = NULL, int $receiving_id = NULL, bool $include_deleted = FALSE): bool { + $config = config('OSPOS')->settings; + //make sure item exists in database. if(!$this->item->exists($item_id, $include_deleted)) { @@ -234,7 +236,7 @@ class Receiving_lib //array records are identified by $insertkey and item_id is just another field. $price = $price != NULL ? $price : $item_info->cost_price; - if(config('OSPOS')->settings['multi_pack_enabled']) + if($config['multi_pack_enabled']) { $item_info->name .= NAME_SEPARATOR . $item_info->pack_name; } diff --git a/app/Libraries/Sale_lib.php b/app/Libraries/Sale_lib.php index 4e1bf686d..825c16e56 100644 --- a/app/Libraries/Sale_lib.php +++ b/app/Libraries/Sale_lib.php @@ -33,6 +33,7 @@ use App\Libraries\Tax_lib; * @property stock_location stock_location * @property Tax_lib tax_lib * @property session session + * @property array config */ class Sale_lib { @@ -50,6 +51,7 @@ class Sale_lib $this->rounding_mode = model('enums/Rounding_mode'); $this->sale = model('Sale'); $this->stock_location = model('Stock_location'); + $this->config = config('OSPOS')->settings; } public function get_line_sequence_options(): array @@ -65,7 +67,7 @@ class Sale_lib { $register_modes = []; - if(!config('OSPOS')->settings['invoice_enable']) + if(!$this->config['invoice_enable']) { $register_modes['sale'] = lang('Sales.sale'); } @@ -74,7 +76,7 @@ class Sale_lib $register_modes['sale'] = lang('Sales.receipt'); $register_modes['sale_quote'] = lang('Sales.quote'); - if(config('OSPOS')->settings['work_order_enable']) + if($this->config['work_order_enable']) { $register_modes['sale_work_order'] = lang('Sales.work_order'); } @@ -130,7 +132,7 @@ class Sale_lib //TODO: This set of if/elseif/else needs to be converted to a switch statement // Entry sequence (this will render kits in the expected sequence) - if(config('OSPOS')->settings['line_sequence'] == '0') + if($this->config['line_sequence'] == '0') { $sort = []; foreach($filtered_cart as $k => $v) @@ -140,7 +142,7 @@ class Sale_lib array_multisort($sort['line'], SORT_ASC, $filtered_cart); } // Group by Stock Type (nonstock first - type 1, stock next - type 0) - elseif(config('OSPOS')->settings['line_sequence'] == '1') //TODO: Need to change these to constants + elseif($this->config['line_sequence'] == '1') //TODO: Need to change these to constants { $sort = []; foreach($filtered_cart as $k => $v) @@ -152,7 +154,7 @@ class Sale_lib array_multisort($sort['stock_type'], SORT_DESC, $sort['description'], SORT_ASC, $sort['name'], SORT_ASC, $filtered_cart); } // Group by Item Category - elseif(config('OSPOS')->settings['line_sequence'] == '2') //TODO: Need to change these to constants + elseif($this->config['line_sequence'] == '2') //TODO: Need to change these to constants { $sort = []; foreach($filtered_cart as $k => $v) @@ -310,7 +312,7 @@ class Sale_lib public function is_invoice_mode(): bool { - return ($this->session->get('sales_mode') == 'sale_invoice' && config('OSPOS')->settings['invoice_enable']); + return ($this->session->get('sales_mode') == 'sale_invoice' && $this->config['invoice_enable']); } public function is_sale_by_receipt_mode(): bool //TODO: This function is not called anywhere in the code. @@ -351,11 +353,11 @@ class Sale_lib public function is_print_after_sale(): bool {//TODO: this needs to be converted to a switch statement - if(config('OSPOS')->settings['print_receipt_check_behaviour'] == 'always') //TODO: 'behaviour' is the british spelling, but the rest of the code is in American English. Not a big deal, but noticed. Also === + if($this->config['print_receipt_check_behaviour'] == 'always') //TODO: 'behaviour' is the british spelling, but the rest of the code is in American English. Not a big deal, but noticed. Also === { return TRUE; } - elseif(config('OSPOS')->settings['print_receipt_check_behaviour'] == 'never') //TODO: === ? + elseif($this->config['print_receipt_check_behaviour'] == 'never') //TODO: === ? { return FALSE; } @@ -378,11 +380,11 @@ class Sale_lib public function is_email_receipt(): bool {//TODO: this needs to be converted to a switch statement - if(config('OSPOS')->settings['email_receipt_check_behaviour'] == 'always') //TODO: 'behaviour' is the british spelling, but the rest of the code is in American English. Not a big deal, but noticed. Also === + if($this->config['email_receipt_check_behaviour'] == 'always') //TODO: 'behaviour' is the british spelling, but the rest of the code is in American English. Not a big deal, but noticed. Also === { return TRUE; } - elseif(config('OSPOS')->settings['email_receipt_check_behaviour'] == 'never') //TODO: === ? + elseif($this->config['email_receipt_check_behaviour'] == 'never') //TODO: === ? { return FALSE; } @@ -719,7 +721,7 @@ class Sale_lib { if(!$this->session->get('dinner_table')) { - if(config('OSPOS')->settings['dinner_table_enable']) + if($this->config['dinner_table_enable']) { $this->set_dinner_table(1); //TODO: Replace 1 with constant } @@ -926,7 +928,7 @@ class Sale_lib $total = $this->get_item_total($quantity, $price, $applied_discount, $discount_type); $discounted_total = $this->get_item_total($quantity, $price, $applied_discount, $discount_type, TRUE); - if(config('OSPOS')->settings['multi_pack_enabled']) + if($this->config['multi_pack_enabled']) { $item_info->name .= NAME_SEPARATOR . $item_info->pack_name; } @@ -1230,7 +1232,7 @@ class Sale_lib */ public function reset_cash_rounding(): int { - $cash_rounding_code = config('OSPOS')->settings['cash_rounding_code']; + $cash_rounding_code = $this->config['cash_rounding_code']; if(cash_decimals() < totals_decimals() || $cash_rounding_code == Rounding_mode::HALF_FIVE) //TODO: convert to ternary notation. { @@ -1378,7 +1380,7 @@ class Sale_lib { $item_total = $this->get_item_total($quantity, $price, $discount, $discount_type, TRUE); - if(config('OSPOS')->settings['tax_included']) + if($this->config['tax_included']) { $tax_fraction = bcdiv(bcadd('100', $tax_percentage), '100'); $price_tax_excl = bcdiv($item_total, $tax_fraction); @@ -1396,7 +1398,7 @@ class Sale_lib $subtotal = '0.0'; foreach($this->get_cart() as $item) { - if($exclude_tax && config('OSPOS')->settings['tax_included']) + if($exclude_tax && $this->config['tax_included']) { $subtotal = bcadd($subtotal, $this->get_item_total_tax_exclusive($item['item_id'], $item['quantity'], $item['price'], $item['discount'], $item['discount_type'], $include_discount)); } @@ -1420,7 +1422,7 @@ class Sale_lib $cash_mode = $this->session->get('cash_mode'); - if(!config('OSPOS')->settings['tax_included']) + if(!$this->config['tax_included']) { $cart = $this->get_cart(); $this->tax_lib = new \app\Libraries\Tax_lib(); @@ -1447,7 +1449,7 @@ class Sale_lib public function check_for_cash_rounding(string $total): string { $cash_decimals = cash_decimals(); - $cash_rounding_code = config('OSPOS')->settings['cash_rounding_code']; + $cash_rounding_code = $this->config['cash_rounding_code']; return Rounding_mode::round_number($cash_rounding_code, (float)$total, $cash_decimals); } diff --git a/app/Libraries/Sms_lib.php b/app/Libraries/Sms_lib.php index 082a38079..adfabc6ab 100644 --- a/app/Libraries/Sms_lib.php +++ b/app/Libraries/Sms_lib.php @@ -19,21 +19,18 @@ use Config\Services; class Sms_lib { - public function __construct() - { - } - /* * SMS sending function * Example of use: $response = sendSMS('4477777777', 'My test message'); */ public function sendSMS(int $phone, string $message): bool { + $config = config('OSPOS')->settings; $encrypter = Services::encrypter(); - $username = config('OSPOS')->settings['msg_uid']; - $password = $encrypter->decrypt(config('OSPOS')->settings['msg_pwd']); - $originator = config('OSPOS')->settings['msg_src']; + $username = $config['msg_uid']; + $password = $encrypter->decrypt($config['msg_pwd']); + $originator = $config['msg_src']; $response = FALSE; diff --git a/app/Libraries/Tax_lib.php b/app/Libraries/Tax_lib.php index 1a0a82106..018a46760 100644 --- a/app/Libraries/Tax_lib.php +++ b/app/Libraries/Tax_lib.php @@ -26,6 +26,7 @@ use App\Libraries\Sale_lib; * @property tax_category tax_category * @property tax_code tax_code * @property tax_jurisdiction tax_jurisdiction + * @property array config * */ @@ -46,6 +47,7 @@ class Tax_lib $this->tax_category = model('Tax_category'); $this->tax_code = model('Tax_code'); $this->tax_jurisdiction = model('Tax_jurisdiction'); + $this->config = config('OSPOS')->settings; } public function get_tax_types(): array @@ -98,7 +100,7 @@ class Tax_lib { $taxed = FALSE; - if(!config('OSPOS')->settings['use_destination_based_tax']) + if(!$this->config['use_destination_based_tax']) { // Start of current Base System tax calculations @@ -121,7 +123,7 @@ class Tax_lib $tax_basis = $this->sale_lib->get_item_total($item['quantity'], $item['price'], $item['discount'], $item['discount_type'], TRUE); $tax_amount = '0.0'; - if(config('OSPOS')->settings['tax_included']) + if($this->config['tax_included']) { $tax_type = Tax_lib::TAX_TYPE_INCLUDED; $tax_amount = $this->get_included_tax($item['quantity'], $item['price'], $item['discount'], $item['discount_type'], $tax['percent'], $tax_decimals, Rounding_mode::HALF_UP); @@ -161,7 +163,7 @@ class Tax_lib // Start of destination based tax calculations if($item['tax_category_id'] == NULL) //TODO: === ? { - $item['tax_category_id'] = config('OSPOS')->settings['default_tax_category']; + $item['tax_category_id'] = $this->config['default_tax_category']; } $taxed = $this->apply_destination_tax($item, $customer_info->city, $customer_info->state, $customer_info->sales_tax_code_id, $register_mode, 0, $taxes, $item_taxes, $item['line']); @@ -274,7 +276,7 @@ class Tax_lib } // If tax included then round decimal to tax decimals, otherwise round it to currency_decimals - if(config('OSPOS')->settings['tax_included']) //TODO: Convert to ternary notation + if($this->config['tax_included']) //TODO: Convert to ternary notation { $decimals = tax_decimals(); } @@ -405,7 +407,7 @@ class Tax_lib { if($register_mode == 'sale') { - $sales_tax_code_id = config('OSPOS')->settings['default_tax_code']; // overrides customer assigned code + $sales_tax_code_id = $this->config['default_tax_code']; // overrides customer assigned code } else { @@ -415,7 +417,7 @@ class Tax_lib if($sales_tax_code_id == NULL || $sales_tax_code_id == 0) { - $sales_tax_code_id = config('OSPOS')->settings['default_tax_code']; // overrides customer assigned code + $sales_tax_code_id = $this->config['default_tax_code']; // overrides customer assigned code } } } diff --git a/app/Libraries/Token_lib.php b/app/Libraries/Token_lib.php index 9fb654d4d..543ea6db7 100644 --- a/app/Libraries/Token_lib.php +++ b/app/Libraries/Token_lib.php @@ -74,7 +74,8 @@ class Token_lib public function parse_barcode(string &$quantity, string &$price, string &$item_id_or_number_or_item_kit_or_receipt): void { - $barcode_formats = json_decode(config('OSPOS')->settings['barcode_formats']); + $config = config('OSPOS')->settings; + $barcode_formats = json_decode($config['barcode_formats']); $barcode_tokens = Token::get_barcode_tokens(); if(!empty($barcode_formats)) @@ -164,4 +165,4 @@ class Token_lib return ''; } -} \ No newline at end of file +} diff --git a/app/Models/Appconfig.php b/app/Models/Appconfig.php index 32733a767..d1cf65460 100644 --- a/app/Models/Appconfig.php +++ b/app/Models/Appconfig.php @@ -2,14 +2,16 @@ namespace App\Models; +use CodeIgniter\Database\ConnectionInterface; use CodeIgniter\Database\ResultInterface; use CodeIgniter\Model; +use CodeIgniter\Validation\ValidationInterface; use ReflectionException; /** * Appconfig class * - * @property mixed config + * */ class Appconfig extends Model { @@ -43,21 +45,21 @@ class Appconfig extends Model } /** - * Calls the parent save() from BaseModel but additionally updates the cached array value. + * Calls the parent save() from BaseModel and updates the cached reference. * @param $data * @return bool * @throws ReflectionException */ public function save($data): bool { - $this->config = config('OSPOS'); $success = parent::save($data); - + $config = config('OSPOS'); $key = array_keys($data)[0]; if($success) { - $this->config[$key] = $data[$key]; + $config->settings[$key] = $data[$key]; + $config->update_settings(); } return $success; @@ -102,7 +104,8 @@ class Appconfig extends Model */ public function acquire_next_invoice_sequence(bool $save = true): string { - $last_used = (int)config('OSPOS')->settings['last_used_invoice_number'] + 1; + $config = config('OSPOS')->settings; + $last_used = (int)$config['last_used_invoice_number'] + 1; if($save) { @@ -117,7 +120,8 @@ class Appconfig extends Model */ public function acquire_next_quote_sequence(bool $save = true): string { - $last_used = (int)config('OSPOS')->settings['last_used_quote_number'] + 1; + $config = config('OSPOS')->settings; + $last_used = (int)$config['last_used_quote_number'] + 1; if($save) { @@ -132,7 +136,8 @@ class Appconfig extends Model */ public function acquire_next_work_order_sequence(bool $save = true): string { - $last_used = (int)config('OSPOS')->settings['last_used_work_order_number'] + 1; + $config = config('OSPOS')->settings; + $last_used = (int)$config['last_used_work_order_number'] + 1; if($save) { diff --git a/app/Models/Attribute.php b/app/Models/Attribute.php index d34800279..32ec72fc1 100644 --- a/app/Models/Attribute.php +++ b/app/Models/Attribute.php @@ -67,11 +67,12 @@ class Attribute extends Model */ public function value_exists($attribute_value, string $definition_type = TEXT): bool { + $config = config('OSPOS')->settings; switch($definition_type) { case DATE: $data_type = 'date'; - $attribute_date_value = DateTime::createFromFormat(config('OSPOS')->settings['dateformat'], $attribute_value); + $attribute_date_value = DateTime::createFromFormat($config['dateformat'], $attribute_value); $attribute_value = $attribute_date_value->format('Y-m-d'); break; case DECIMAL: @@ -648,7 +649,8 @@ class Attribute extends Model { $this->db->transStart(); - $locale_date_format = config('OSPOS')->settings['dateformat']; + $config = config('OSPOS')->settings; + $locale_date_format = $config['dateformat']; //New Attribute if(empty($attribute_id) || empty($item_id)) diff --git a/app/Models/Cashup.php b/app/Models/Cashup.php index 11ab7815f..1a6512a47 100644 --- a/app/Models/Cashup.php +++ b/app/Models/Cashup.php @@ -60,6 +60,7 @@ class Cashup extends Model */ public function search(string $search, array $filters, int $rows = 0, int $limit_from = 0, string $sort = 'cashup_id', string $order = 'asc', bool $count_only = FALSE): ResultInterface { + $config = config('OSPOS')->settings; $builder = $this->db->table('cash_up AS cash_up'); // get_found_rows case @@ -105,7 +106,7 @@ class Cashup extends Model $builder->where('cash_up.deleted', $filters['is_deleted']); - if(empty(config('OSPOS')->settings['date_or_time_format'])) //TODO: convert this to ternary notation. + if(empty($config['date_or_time_format'])) //TODO: convert this to ternary notation. { $builder->where('DATE_FORMAT(cash_up.open_date, "%Y-%m-%d") BETWEEN ' . $this->db->escape($filters['start_date']) . ' AND ' . $this->db->escape($filters['end_date'])); } diff --git a/app/Models/Customer.php b/app/Models/Customer.php index 8cd8842f9..4949897ac 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -226,9 +226,10 @@ class Customer extends Person public function delete($customer_id = null, bool $purge = false): bool { $result = TRUE; + $config = config('OSPOS')->settings; // if privacy enforcement is selected scramble customer data - if(config('OSPOS')->settings['enforce_privacy']) + if($config['enforce_privacy']) { $builder = $this->db->table('people'); $builder->where('person_id', $customer_id); @@ -421,4 +422,4 @@ class Customer extends Person return $builder->get(); } -} \ No newline at end of file +} diff --git a/app/Models/Expense.php b/app/Models/Expense.php index 0a6bb4b58..e65790b68 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -72,6 +72,7 @@ class Expense extends Model */ 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): ResultInterface { + $config = config('OSPOS')->settings; $builder = $this->db->table('expenses AS expenses'); // get_found_rows case @@ -113,11 +114,11 @@ class Expense extends Model $builder->where('expenses.deleted', $filters['is_deleted']); /* //TODO: Below needs to be replaced with Ternary notation - empty(config('OSPOS')->settings['date_or_time_format) + 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('OSPOS')->settings['date_or_time_format'])) + 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'])); } @@ -269,12 +270,14 @@ class Expense extends Model */ public function get_payments_summary(string $search, array $filters): array //TODO: $search is passed but never used in the function { + $config = config('OSPOS')->settings; + // get payment summary $builder = $this->db->table('expenses'); $builder->select('payment_type, COUNT(amount) AS count, SUM(amount) AS amount'); $builder->where('deleted', $filters['is_deleted']); - if(empty(config('OSPOS')->settings['date_or_time_format'])) + if(empty($config['date_or_time_format'])) { $builder->where('DATE_FORMAT(date, "%Y-%m-%d") BETWEEN ' . $this->db->escape($filters['start_date']) . ' AND ' . $this->db->escape($filters['end_date'])); } @@ -331,4 +334,4 @@ class Expense extends Model return $builder->get(); } -} \ No newline at end of file +} diff --git a/app/Models/Item.php b/app/Models/Item.php index 3dddcf3d6..72986b678 100644 --- a/app/Models/Item.php +++ b/app/Models/Item.php @@ -43,7 +43,9 @@ class Item extends Model */ public function item_number_exists(string $item_number, string $item_id = ''): bool { - if(config('OSPOS')->settings['allow_duplicate_barcodes']) + $config = config('OSPOS')->settings; + + if($config['allow_duplicate_barcodes']) { return FALSE; } @@ -93,6 +95,7 @@ class Item extends Model */ public function search(string $search, array $filters, int $rows = 0, int $limit_from = 0, string $sort = 'items.name', string $order = 'asc', bool $count_only = FALSE): ResultInterface { + $config = config('OSPOS')->settings; $builder = $this->db->table('items AS items'); //TODO: I'm not sure if it's needed to write items AS items... I think you can just get away with items // get_found_rows case @@ -150,7 +153,7 @@ class Item extends Model $builder->where('location_id', $filters['stock_location_id']); } - if(empty(config('OSPOS')->settings['date_or_time_format'])) //TODO: This needs to be replaced with Ternary notation + if(empty($config['date_or_time_format'])) //TODO: This needs to be replaced with Ternary notation { $builder->where('DATE_FORMAT(trans_date, "%Y-%m-%d") BETWEEN ' . $this->db->escape($filters['start_date']) . ' AND ' . $this->db->escape($filters['end_date'])); } @@ -505,16 +508,17 @@ class Item extends Model function get_search_suggestion_format(string $seed = NULL): string { - $seed .= ',' . config('OSPOS')->settings['suggestions_first_column']; + $config = config('OSPOS')->settings; + $seed .= ',' . $config['suggestions_first_column']; - if(config('OSPOS')->settings['suggestions_second_column'] !== '') + if($config['suggestions_second_column'] !== '') { - $seed .= ',' . config('OSPOS')->settings['suggestions_second_column']; + $seed .= ',' . $config['suggestions_second_column']; } - if(config('OSPOS')->settings['suggestions_third_column'] !== '') + if($config['suggestions_third_column'] !== '') { - $seed .= ',' . config('OSPOS')->settings['suggestions_third_column']; + $seed .= ',' . $config['suggestions_third_column']; } return $seed; @@ -522,13 +526,14 @@ class Item extends Model function get_search_suggestion_label($result_row): string { + $config = config('OSPOS')->settings; $label = ''; - $label1 = config('OSPOS')->settings['suggestions_first_column']; - $label2 = config('OSPOS')->settings['suggestions_second_column']; - $label3 = config('OSPOS')->settings['suggestions_third_column']; + $label1 = $config['suggestions_first_column']; + $label2 = $config['suggestions_second_column']; + $label3 = $config['suggestions_third_column']; // If multi_pack enabled then if "name" is part of the search suggestions then append pack - if(config('OSPOS')->settings['multi_pack_enabled']) + if($config['multi_pack_enabled']) { $this->append_label($label, $label1, $result_row); $this->append_label($label, $label2, $result_row); @@ -1028,6 +1033,8 @@ class Item extends Model */ function get_item_name(string $as_name = NULL): string { + $config = config('OSPOS')->settings; + if($as_name == NULL) //TODO: Replace with ternary notation { $as_name = ''; @@ -1037,7 +1044,7 @@ class Item extends Model $as_name = ' AS ' . $as_name; } - if(config('OSPOS')->settings['multi_pack_enabled']) //TODO: Replace with ternary notation + if($config['multi_pack_enabled']) //TODO: Replace with ternary notation { $item_name = "concat(items.name,'" . NAME_SEPARATOR . '\', items.pack_name)' . $as_name; } diff --git a/app/Models/Item_kit.php b/app/Models/Item_kit.php index 7de9285f0..bc13335f1 100644 --- a/app/Models/Item_kit.php +++ b/app/Models/Item_kit.php @@ -50,7 +50,9 @@ class Item_kit extends Model */ public function item_number_exists(string $item_kit_number, string $item_kit_id = ''): bool { - if(config('OSPOS')->settings['allow_duplicate_barcodes']) + $config = config('OSPOS')->settings; + + if($config['allow_duplicate_barcodes']) { return FALSE; } diff --git a/app/Models/Receiving.php b/app/Models/Receiving.php index ec45dfa9c..a93feaf31 100644 --- a/app/Models/Receiving.php +++ b/app/Models/Receiving.php @@ -107,6 +107,7 @@ class Receiving extends Model foreach($items as $line => $item_data) { + $config = config('OSPOS')->settings; $cur_item_info = $item->get_info($item['item_id']); $receivings_items_data = [ @@ -129,7 +130,7 @@ class Receiving extends Model $items_received = $item_data['receiving_quantity'] != 0 ? $item_data['quantity'] * $item_data['receiving_quantity'] : $item_data['quantity']; // update cost price, if changed AND is set in config as wanted - if($cur_item_info->cost_price != $item_data['price'] && config('OSPOS')->settings['receiving_calculate_average_price']) + if($cur_item_info->cost_price != $item_data['price'] && $config['receiving_calculate_average_price']) { $item->change_cost_price($item_data['item_id'], $items_received, $item_data['price'], $cur_item_info->cost_price); } @@ -275,9 +276,11 @@ class Receiving extends Model */ public function create_temp_table(array $inputs): void { + $config = config('OSPOS')->settings; + if(empty($inputs['receiving_id'])) { - if(empty(config('OSPOS')->settings['date_or_time_format'])) + if(empty($config['date_or_time_format'])) { $where = 'WHERE DATE(receiving_time) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date']); } diff --git a/app/Models/Reports/Summary_discounts.php b/app/Models/Reports/Summary_discounts.php index 5150af074..f4494881a 100644 --- a/app/Models/Reports/Summary_discounts.php +++ b/app/Models/Reports/Summary_discounts.php @@ -15,11 +15,12 @@ class Summary_discounts extends Summary_report public function getData(array $inputs): array { + $config = config('OSPOS')->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 ===? { - $builder->select('SUM(sales_items.discount) AS total, MAX(CONCAT("' . config('OSPOS')->settings['currency_symbol'] . '",sales_items.discount)) AS discount, count(*) AS count'); + $builder->select('SUM(sales_items.discount) AS total, MAX(CONCAT("' . $config['currency_symbol'] . '",sales_items.discount)) AS discount, count(*) AS count'); $builder->where('discount_type', FIXED); } elseif($inputs['discount_type'] == PERCENT) //TODO: === ? @@ -38,4 +39,4 @@ class Summary_discounts extends Summary_report return $builder->get()->getResultArray(); } -} \ No newline at end of file +} diff --git a/app/Models/Reports/Summary_expenses_categories.php b/app/Models/Reports/Summary_expenses_categories.php index 5ea60782c..9a944523e 100644 --- a/app/Models/Reports/Summary_expenses_categories.php +++ b/app/Models/Reports/Summary_expenses_categories.php @@ -16,12 +16,14 @@ class Summary_expenses_categories extends Summary_report public function getData(array $inputs): array { + $config = config('OSPOS')->settings; + $builder = $this->db->table('expenses AS expenses'); $builder->select('expense_categories.category_name AS category_name, COUNT(expenses.expense_id) AS count, SUM(expenses.amount) AS total_amount, SUM(expenses.tax_amount) AS total_tax_amount'); $builder->join('expense_categories AS expense_categories', 'expense_categories.expense_category_id = expenses.expense_category_id', 'LEFT'); //TODO: convert this to ternary notation - if(empty(config('OSPOS')->settings['date_or_time_format'])) //TODO: Duplicated code + if(empty($config['date_or_time_format'])) //TODO: Duplicated code { $builder->where('DATE(expenses.date) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date'])); } @@ -40,10 +42,12 @@ class Summary_expenses_categories extends Summary_report public function getSummaryData(array $inputs): array { + $config = config('OSPOS')->settings; + $builder = $this->db->table('expenses AS expenses'); $builder->select('SUM(expenses.amount) AS expenses_total_amount, SUM(expenses.tax_amount) AS expenses_total_tax_amount'); - if(empty(config('OSPOS')->settings['date_or_time_format'])) //TODO: Duplicated code + if(empty($config['date_or_time_format'])) //TODO: Duplicated code { $builder->where('DATE(expenses.date) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date'])); } @@ -56,4 +60,4 @@ class Summary_expenses_categories extends Summary_report return $builder->get()->getRowArray(); } -} \ No newline at end of file +} diff --git a/app/Models/Reports/Summary_payments.php b/app/Models/Reports/Summary_payments.php index 8c154fda9..d57921293 100644 --- a/app/Models/Reports/Summary_payments.php +++ b/app/Models/Reports/Summary_payments.php @@ -20,6 +20,7 @@ class Summary_payments extends Summary_report public function getData(array $inputs): array { $cash_payment = lang('Sales.cash'); //TODO: This is never used. Should it be? + $config = config('OSPOS')->settings; $separator[] = [ 'trans_group' => '