diff --git a/.travis.yml b/.travis.yml index 7f5eae765..7f7354767 100644 --- a/.travis.yml +++ b/.travis.yml @@ -18,7 +18,7 @@ before_install: script: - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin - docker run --rm -v $(pwd):/app opensourcepos/composer composer install - - version=$(grep application_version application/config/config.php | sed "s/.*=\s'\(.*\)';/\1/g") + - version=$(grep application_version app/Config/App.php | sed "s/.*=\s'\(.*\)';/\1/g") - echo "$version-$branch-$rev" - npm version "$version-$branch-$rev" --force || true - docker run --rm -it -v $(pwd):/app -w /app opensourcepos/node-grunt-bower diff --git a/app/Config/App.php b/app/Config/App.php index 04768f508..d968861b3 100644 --- a/app/Config/App.php +++ b/app/Config/App.php @@ -523,7 +523,7 @@ class App extends BaseConfig parent::__construct(); $this->https_on = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_ENV['FORCE_HTTPS']) && $_ENV['FORCE_HTTPS'] == 'true'); $this->baseURL = $this->https_on ? 'https' : 'http'; - $this->baseURL .= '://' . ((isset($_SERVER['HTTP_HOST'])) ? $_SERVER['HTTP_HOST'] : 'localhost'); + $this->baseURL .= '://' . ((isset($_SERVER['HTTP_HOST'])) ? $_SERVER['HTTP_HOST'] : 'localhost') . '/'; $this->baseURL .= str_replace(basename($_SERVER['SCRIPT_NAME']), '', $_SERVER['SCRIPT_NAME']); } } diff --git a/app/Config/Autoload.php b/app/Config/Autoload.php index d329f9d05..86e0d8404 100644 --- a/app/Config/Autoload.php +++ b/app/Config/Autoload.php @@ -202,5 +202,8 @@ class Autoload extends AutoloadConfig * @var string[] * @phpstan-var list */ - public $helpers = []; + public $helpers = [ + 'form', + 'cookie' + ]; } diff --git a/app/Config/Cache.php b/app/Config/Cache.php index 659d9ed6a..7a290f1cf 100644 --- a/app/Config/Cache.php +++ b/app/Config/Cache.php @@ -85,7 +85,7 @@ class Cache extends BaseConfig * hard-coded, but may be useful to projects and modules. This will replace * the hard-coded value in a future release. */ - public int $ttl = 60; + public int $ttl = 300; /** * -------------------------------------------------------------------------- diff --git a/app/Config/Encryption.php b/app/Config/Encryption.php index e37b4e2a1..39fa4703b 100644 --- a/app/Config/Encryption.php +++ b/app/Config/Encryption.php @@ -57,7 +57,15 @@ class Encryption extends BaseConfig */ public string $digest = 'SHA512'; - /** + /** + * The cipher to use. + * This setting is only used by OpenSSLHandler. + * + * Set to aes-128-cbc for CI3 Encryption compatibility. + */ + public string $cipher = 'aes-256-ctr'; + + /** * Whether the cipher-text should be raw. If set to false, then it will be base64 encoded. * This setting is only used by OpenSSLHandler. * diff --git a/app/Config/OSPOS.php b/app/Config/OSPOS.php index 974709328..c1d79f7a4 100644 --- a/app/Config/OSPOS.php +++ b/app/Config/OSPOS.php @@ -2,6 +2,7 @@ namespace Config; +use CodeIgniter\Cache\CacheInterface; use CodeIgniter\Config\BaseConfig; /** @@ -11,5 +12,43 @@ use CodeIgniter\Config\BaseConfig; */ class OSPOS extends BaseConfig { - public $settings = []; -} \ No newline at end of file + public array $settings; + + public string $commit_sha1 = 'dev'; //TODO: Travis scripts need to be updated to replace this with the commit hash on build + + private CacheInterface $cache; + + public function __construct() + { + parent::__construct(); + $this->cache = Services::cache(); + $this->set_settings(); + } + + public function set_settings(): void + { + helper('locale'); + + $cache = $this->cache->get('settings'); + + if($cache) + { + $this->settings = decode_array($cache); + } + else + { + $appconfig = model('Appconfig'); + foreach($appconfig->get_all()->getResult() as $app_config) + { + $this->settings[$app_config->key] = $app_config->value; + } + $this->cache->save('settings', encode_array($this->settings)); + } + } + + public function update_settings(): void + { + $this->cache->delete('settings'); + $this->set_settings(); + } +} diff --git a/app/Config/Session.php b/app/Config/Session.php index e19e415ff..c3e116c18 100644 --- a/app/Config/Session.php +++ b/app/Config/Session.php @@ -89,7 +89,7 @@ class Session extends BaseConfig * when auto-regenerating the session ID. When set to FALSE, the data * will be later deleted by the garbage collector. */ - public bool $regenerateDestroy = false; + public bool $regenerateDestroy = true; /** * -------------------------------------------------------------------------- diff --git a/app/Config/Validation/OSPOSRules.php b/app/Config/Validation/OSPOSRules.php index 2e1d1e115..0976005ee 100644 --- a/app/Config/Validation/OSPOSRules.php +++ b/app/Config/Validation/OSPOSRules.php @@ -24,6 +24,7 @@ class OSPOSRules { $this->employee = model('Employee'); $this->request = Services::request(); + $config = config('OSPOS')->settings; //Installation Check if(!$this->installation_check()) @@ -42,9 +43,10 @@ class OSPOSRules return false; } + //GCaptcha Check - $gcaptcha_enabled = array_key_exists('gcaptcha_enable', config('OSPOS')->settings) - ? config('OSPOS')->settings['gcaptcha_enable'] + $gcaptcha_enabled = array_key_exists('gcaptcha_enable', $config) + ? $config['gcaptcha_enable'] : false; if($gcaptcha_enabled) @@ -73,7 +75,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/Attributes.php b/app/Controllers/Attributes.php index 611d257ef..09a659e0b 100644 --- a/app/Controllers/Attributes.php +++ b/app/Controllers/Attributes.php @@ -23,6 +23,7 @@ class Attributes extends Secure_Controller public function getIndex(): void { + helper('tabular'); $data['table_headers'] = get_attribute_definition_manage_table_headers(); echo view('attributes/manage', $data); @@ -223,4 +224,4 @@ class Attributes extends Secure_Controller echo json_encode(['success' => FALSE, 'message' => lang('Attributes.definition_cannot_be_deleted')]); } } -} \ No newline at end of file +} 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 0143b646a..963dbcb4d 100644 --- a/app/Controllers/Config.php +++ b/app/Controllers/Config.php @@ -7,6 +7,7 @@ use App\Libraries\Mailchimp_lib; use App\Libraries\Receiving_lib; use App\Libraries\Sale_lib; use App\Libraries\Tax_lib; +use App\Libraries\Ci3encrypt; use App\Models\Appconfig; use App\Models\Attribute; @@ -17,9 +18,10 @@ use App\Models\Enums\Rounding_mode; use App\Models\Stock_location; use App\Models\Tax; -use CodeIgniter\Encryption\Encryption; use CodeIgniter\Encryption\EncrypterInterface; use CodeIgniter\Files\File; +use Config\Encryption; +use Config\Services; use DirectoryIterator; use NumberFormatter; use ReflectionException; @@ -40,6 +42,7 @@ use ReflectionException; * @property rounding_mode rounding_mode * @property stock_location stock_location * @property tax tax + * @property array config */ class Config extends Secure_Controller { @@ -51,7 +54,7 @@ class Config extends Secure_Controller $this->sale_lib = new Sale_lib(); $this->receiving_lib = new receiving_lib(); $this->tax_lib = new Tax_lib(); - + $this->attribute = model('Attribute'); $this->customer_rewards = model('Customer_rewards'); $this->dinner_table = model('Dinner_table'); @@ -59,9 +62,7 @@ class Config extends Secure_Controller $this->rounding_mode = model('Rounding_mode'); $this->stock_location = model('Stock_location'); $this->tax = model('Tax'); - - $this->encryption = new Encryption(); - $this->encrypter = $this->encryption->initialize(); + $this->config = config('OSPOS')->settings; } /* @@ -74,7 +75,7 @@ class Config extends Secure_Controller $composer = FALSE; $license = []; - $license[$i]['title'] = 'Open Source Point Of Sale ' . config('OSPOSConfig')->application_version; + $license[$i]['title'] = 'Open Source Point Of Sale ' . config('App')->application_version; if(file_exists('license/LICENSE')) { @@ -250,7 +251,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(); @@ -259,7 +260,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(); @@ -271,15 +272,17 @@ 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'] = []; if($this->_check_encryption()) //TODO: Hungarian notation { - $data['mailchimp']['api_key'] = $this->encrypter->decrypt(config('OSPOS')->settings['mailchimp_api_key']); - $data['mailchimp']['list_id'] = $this->encrypter->decrypt(config('OSPOS')->settings['mailchimp_list_id']); + $encrypter = Services::encrypter(); + + $data['mailchimp']['api_key'] = $encrypter->decrypt($this->config['mailchimp_api_key'] ?? ''); + $data['mailchimp']['list_id'] = $encrypter->decrypt($this->config['mailchimp_list_id'] ?? ''); } else { @@ -287,7 +290,6 @@ class Config extends Secure_Controller $data['mailchimp']['list_id'] = ''; } - // load mailchimp lists associated to the given api key, already XSS cleaned in the private function $data['mailchimp']['lists'] = $this->_mailchimp(); echo view('configs/manage', $data); @@ -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,13 +941,13 @@ class Config extends Secure_Controller */ private function _check_encryption(): bool //TODO: Hungarian notation { - $encryption_key = config('OSPOS')->settings['encryption_key']; + $encryption_key = config('Encryption')->key; // check if the encryption_key config item is the default one if($encryption_key == '' || $encryption_key == 'YOUR KEY') { // Config path - $config_path = APPPATH . 'config/config.php'; + $config_path = APPPATH . 'Config/config.php'; //TODO: This is now in APPPATH . 'Config\Encryption.php' but it shouldn't be pulled from here. It should be pulled from '\.env' // Open the file $config = file_get_contents($config_path); @@ -953,11 +955,8 @@ class Config extends Secure_Controller // $key will be assigned a 32-byte (256-bit) hex-encoded random key $key = bin2hex($this->encryption->createKey()); - // set the encryption key in the config item - $this->appconfig->save(['encryption_key' => $key]); - // replace the empty placeholder with a real randomly generated encryption key - $config = preg_replace("/(.*encryption_key.*)('');/", "$1'$key';", $config); + $config = preg_replace("/(.*encryption_key.*)('');/", "$1'$key';", $config); //TODO: This needs to be modified also so that it replaces encryption.key = '' with encryption.key = '[NEW KEY]' $result = FALSE; @@ -984,4 +983,4 @@ class Config extends Secure_Controller return TRUE; } -} \ No newline at end of file +} diff --git a/app/Controllers/Customers.php b/app/Controllers/Customers.php index b8377fc44..b450a6eb9 100644 --- a/app/Controllers/Customers.php +++ b/app/Controllers/Customers.php @@ -10,6 +10,7 @@ use App\Models\Tax_code; use CodeIgniter\Encryption\Encryption; use CodeIgniter\Encryption\EncrypterInterface; +use Config\Services; use stdClass; /** @@ -23,6 +24,7 @@ use stdClass; * * @property encryption encryption * @property encrypterinterface encrypter + * @property array config * */ class Customers extends Persons @@ -32,16 +34,16 @@ class Customers extends Persons public function __construct() { parent::__construct('customers'); - + helper('tabular'); $this->mailchimp_lib = new Mailchimp_lib(); $this->customer = model('Customer'); $this->tax_code = model('Tax_code'); + $this->config = config('OSPOS')->settings; - $this->encryption = new Encryption(); - $this->encrypter = $this->encryption->initialize(); + $encrypter = Services::encrypter(); - $this->_list_id = $this->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, @@ -500,4 +502,4 @@ class Customers extends Persons } } } -} \ No newline at end of file +} diff --git a/app/Controllers/Expenses.php b/app/Controllers/Expenses.php index 2bfce324b..bece410a2 100644 --- a/app/Controllers/Expenses.php +++ b/app/Controllers/Expenses.php @@ -21,6 +21,7 @@ class Expenses extends Secure_Controller public function getIndex(): void { + helper('tabular'); $data['table_headers'] = get_expenses_manage_table_headers(); // filters that will be loaded in the multiselect dropdown @@ -135,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'), @@ -190,4 +192,4 @@ class Expenses extends Secure_Controller echo json_encode (['success' => FALSE, 'message' => lang('Expenses.cannot_be_deleted'), 'ids' => $expenses_to_delete]); } } -} \ No newline at end of file +} diff --git a/app/Controllers/Expenses_categories.php b/app/Controllers/Expenses_categories.php index fe1415191..dffbc1b75 100644 --- a/app/Controllers/Expenses_categories.php +++ b/app/Controllers/Expenses_categories.php @@ -18,7 +18,8 @@ class Expenses_categories extends Secure_Controller //TODO: Is this class ever u public function getIndex(): void { - $data['table_headers'] = get_expense_category_manage_table_headers(); + helper('tabular'); + $data['table_headers'] = get_expense_category_manage_table_headers(); echo view('expenses_categories/manage', $data); } @@ -113,4 +114,4 @@ class Expenses_categories extends Secure_Controller //TODO: Is this class ever u echo json_encode (['success' => FALSE, 'message' => lang('Expenses_categories.cannot_be_deleted')]); } } -} \ No newline at end of file +} diff --git a/app/Controllers/Giftcards.php b/app/Controllers/Giftcards.php index 61323ee15..220b91354 100644 --- a/app/Controllers/Giftcards.php +++ b/app/Controllers/Giftcards.php @@ -18,6 +18,7 @@ class Giftcards extends Secure_Controller public function getIndex(): void { + helper('tabular'); $data['table_headers'] = get_giftcards_manage_table_headers(); echo view('giftcards/manage', $data); @@ -73,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 : ''; } @@ -165,4 +167,4 @@ class Giftcards extends Secure_Controller echo json_encode (['success' => FALSE, 'message' => lang('Giftcards.cannot_be_deleted')]); } } -} \ No newline at end of file +} diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php index 090cfef58..2f11069dd 100644 --- a/app/Controllers/Home.php +++ b/app/Controllers/Home.php @@ -6,22 +6,23 @@ class Home extends Secure_Controller { public function __construct() { - parent::__construct(NULL, NULL, 'home'); + parent::__construct('home', NULL, 'home'); } public function getIndex(): void { + $logged_in = $this->employee->is_logged_in(); echo view('home/home'); } - public function logout(): void + public function getLogout(): void { $this->employee->logout(); } - /* - Load "change employee password" form - */ + /** + * Load "change employee password" form + */ public function change_password(int $employee_id = -1): void //TODO: Replace -1 with a constant { $person_info = $this->employee->get_info($employee_id); @@ -34,9 +35,9 @@ class Home extends Secure_Controller echo view('home/form_change_password', $data); } - /* - Change employee password - */ + /** + * Change employee password + */ public function save(int $employee_id = -1): void //TODO: Replace -1 with a constant { if($this->request->getPost('current_password') != '' && $employee_id != -1) @@ -84,4 +85,4 @@ class Home extends Secure_Controller ]); } } -} \ No newline at end of file +} diff --git a/app/Controllers/Item_kits.php b/app/Controllers/Item_kits.php index 9079b5d2b..0242f471d 100644 --- a/app/Controllers/Item_kits.php +++ b/app/Controllers/Item_kits.php @@ -66,6 +66,7 @@ class Item_kits extends Secure_Controller public function getIndex(): void { + helper('tabular'); $data['table_headers'] = get_item_kits_manage_table_headers(); echo view('item_kits/manage', $data); @@ -276,4 +277,4 @@ class Item_kits extends Secure_Controller // display barcodes echo view("barcodes/barcode_sheet", $data); } -} \ No newline at end of file +} diff --git a/app/Controllers/Items.php b/app/Controllers/Items.php index 7d340e9ec..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,10 +57,12 @@ 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 { + helper('tabular'); $this->session->set('allow_temp_items', 0); $data['table_headers'] = get_items_manage_table_headers(); @@ -150,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; @@ -284,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') { @@ -300,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; @@ -314,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']; } } @@ -322,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; @@ -471,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(); @@ -620,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) { @@ -733,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'] . ']' ] ] ]; @@ -1311,4 +1314,4 @@ class Items extends Secure_Controller } } } -} \ No newline at end of file +} diff --git a/app/Controllers/Login.php b/app/Controllers/Login.php index 452ca5a75..0947d007f 100644 --- a/app/Controllers/Login.php +++ b/app/Controllers/Login.php @@ -11,18 +11,16 @@ use Config\Services; */ class Login extends BaseController { - protected $helpers = ['form']; - public function index() { $this->employee = model('Employee'); if(!$this->employee->is_logged_in()) { $migration = new MY_Migration(config('Migrations')); + $config = config('OSPOS')->settings; - //The gcaptcha_enable key was not added to app settings until 3.1.1. Without this check we get an error on new instances. - $gcaptcha_enabled = array_key_exists('gcaptcha_enable', config('OSPOS')->settings) - ? config('OSPOS')->settings['gcaptcha_enable'] + $gcaptcha_enabled = array_key_exists('gcaptcha_enable', $config) + ? $config['gcaptcha_enable'] : false; $migration->migrate_to_ci4(); @@ -31,7 +29,8 @@ class Login extends BaseController 'has_errors' => false, 'is_latest' => $migration->is_latest(), 'latest_version' => $migration->get_latest_migration(), - 'gcaptcha_enabled' => $gcaptcha_enabled + 'gcaptcha_enabled' => $gcaptcha_enabled, + 'config' => $config ]; if(strtolower($this->request->getMethod()) !== 'post') @@ -55,8 +54,10 @@ class Login extends BaseController set_time_limit(3600); $migration->setNamespace('App')->latest(); + return redirect()->to('login'); } } + return redirect()->to('home'); } } diff --git a/app/Controllers/Persons.php b/app/Controllers/Persons.php index 8acf164b8..7b5934e83 100644 --- a/app/Controllers/Persons.php +++ b/app/Controllers/Persons.php @@ -18,6 +18,7 @@ abstract class Persons extends Secure_Controller public function getIndex(): void { + helper('tabular'); $data['table_headers'] = get_people_manage_table_headers(); echo view('people/manage', $data); @@ -57,4 +58,4 @@ abstract class Persons extends Secure_Controller { return str_name_case($string); } -} \ No newline at end of file +} 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 00e493032..d24e12151 100644 --- a/app/Controllers/Reports.php +++ b/app/Controllers/Reports.php @@ -25,7 +25,7 @@ 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; /** * @property attribute attribute @@ -51,17 +51,18 @@ use CodeIgniter\HTTP\Uri; * @property summary_sales_taxes summary_sales_taxes * @property summary_suppliers summary_suppliers * @property summary_taxes summary_taxes - * @property URI uri + * @property array config */ class Reports extends Secure_Controller { public function __construct() { parent::__construct('reports'); - - $this->uri->setURI(uri_string()); - $method_name = $this->uri->getSegment(2); + $request = Services::request(); + $method_name = $request->getUri()->getSegment(2); $exploder = explode('_', $method_name); + $this->config = config('OSPOS')->settings; + $this->stock_location = model('Stock_location'); if(sizeof($exploder) > 1) { @@ -1577,10 +1578,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'); } @@ -1912,15 +1913,15 @@ 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; } -} \ No newline at end of file +} diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php index 95afb75ff..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 = [ @@ -1471,7 +1473,7 @@ class Sales extends Secure_Controller } } - $payments[] = [ + $sale_data['payments'] = [ 'payment_id' => $payment_id, 'payment_type' => $payment_type, 'payment_amount' => $payment_amount, @@ -1482,7 +1484,7 @@ class Sales extends Secure_Controller } $this->inventory->update('POS '.$sale_id, ['trans_date' => $sale_time]); //TODO: Reflection Exception - if($this->sale->update($sale_id, $sale_data, $payments)) + if($this->sale->update($sale_id, $sale_data)) { echo json_encode (['success' => TRUE, 'message' => lang('Sales.successfully_updated'), 'id' => $sale_id]); } @@ -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); @@ -1707,4 +1709,4 @@ class Sales extends Secure_Controller return NULL; } -} \ No newline at end of file +} diff --git a/app/Controllers/Secure_Controller.php b/app/Controllers/Secure_Controller.php index a53a55725..a669d6b0a 100644 --- a/app/Controllers/Secure_Controller.php +++ b/app/Controllers/Secure_Controller.php @@ -13,16 +13,19 @@ use CodeIgniter\Session\Session; * * @property employee employee * @property module module - * + * @property array global_view_data * @property session session * */ class Secure_Controller extends BaseController { - public function __construct(string $module_id = NULL, string $submodule_id = NULL, string $menu_group = NULL) + public array $global_view_data; + + public function __construct(string $module_id = '', string $submodule_id = NULL, string $menu_group = NULL) { $this->employee = model('Employee'); $this->module = model('Module'); + $config = config('OSPOS')->settings; if(!$this->employee->is_logged_in()) { @@ -36,7 +39,7 @@ class Secure_Controller extends BaseController redirect("no_access/$module_id/$submodule_id"); } - // load up global data visible to all the loaded views + // load up global global_view_data visible to all the loaded views $this->session = session(); if($menu_group == NULL) { @@ -47,24 +50,21 @@ class Secure_Controller extends BaseController $this->session->set('menu_group', $menu_group); } - if($menu_group == 'home') //TODO: Convert to ternary notation - { - $allowed_modules = $this->module->get_allowed_home_modules($logged_in_employee_info->person_id); - } - else - { - $allowed_modules = $this->module->get_allowed_office_modules($logged_in_employee_info->person_id); - } + $allowed_modules = $menu_group == 'home' + ? $this->module->get_allowed_home_modules($logged_in_employee_info->person_id) + : $this->module->get_allowed_office_modules($logged_in_employee_info->person_id); foreach($allowed_modules->getResult() as $module) { - $data['allowed_modules'][] = $module; + $global_view_data['allowed_modules'][] = $module; } - $data['user_info'] = $logged_in_employee_info; - $data['controller_name'] = $module_id; - - echo view('viewData', $data); + $global_view_data += [ + 'user_info' => $logged_in_employee_info, + 'controller_name' => $module_id, + 'config' => $config + ]; + view('viewData', $global_view_data); } public function check_numeric() @@ -86,4 +86,4 @@ class Secure_Controller extends BaseController public function view(int $data_item_id = -1) { return FALSE; } public function save(int $data_item_id = -1) { return FALSE; } public function delete() { return FALSE; } -} \ No newline at end of file +} diff --git a/app/Controllers/Suppliers.php b/app/Controllers/Suppliers.php index 941114f5a..81197f0ba 100644 --- a/app/Controllers/Suppliers.php +++ b/app/Controllers/Suppliers.php @@ -21,6 +21,7 @@ class Suppliers extends Persons public function getIndex(): void { + helper('tabular'); $data['table_headers'] = get_suppliers_manage_table_headers(); echo view('people/manage', $data); @@ -183,4 +184,4 @@ class Suppliers extends Persons echo json_encode (['success' => FALSE, 'message' => lang('Suppliers.cannot_be_deleted')]); } } -} \ No newline at end of file +} 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/Database/Migrations/sqlscripts/3.4.0_ci4_conversion.sql b/app/Database/Migrations/sqlscripts/3.4.0_ci4_conversion.sql index 99ad3a664..483b42be9 100644 --- a/app/Database/Migrations/sqlscripts/3.4.0_ci4_conversion.sql +++ b/app/Database/Migrations/sqlscripts/3.4.0_ci4_conversion.sql @@ -1,13 +1,12 @@ --- creating new column of TIMESTAMP type -ALTER TABLE `ospos_sessions` - ADD COLUMN `temp_timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(); --- Use FROM_UNIXTIME() to convert from the INT timestamp to a proper datetime type --- assigning value from old INT column to it, in hope that it will be recognized as timestamp -UPDATE `ospos_sessions` SET `temp_timestamp` = FROM_UNIXTIME(`timestamp`); +DROP TABLE `ospos_sessions`; --- dropping the old INT column -ALTER TABLE `ospos_sessions` DROP COLUMN `timestamp`; +CREATE TABLE IF NOT EXISTS `ospos_sessions` ( + `id` varchar(128) NOT null, + `ip_address` varchar(45) NOT null, + `timestamp` timestamp DEFAULT CURRENT_TIMESTAMP NOT null, + `data` blob NOT null, + KEY `ospos_sessions_timestamp` (`timestamp`) + ); --- changing the name of the column -ALTER TABLE `ospos_sessions` CHANGE `temp_timestamp` `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP(); \ No newline at end of file +ALTER TABLE ospos_sessions ADD PRIMARY KEY (id, ip_address); diff --git a/app/Database/tables.sql b/app/Database/tables.sql index 3d13af4c5..aff3b9003 100644 --- a/app/Database/tables.sql +++ b/app/Database/tables.sql @@ -82,7 +82,7 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('theme', 'flatly'), ('statistics', '1'), ('language', 'english'), - ('language_code', 'en'); + ('language_code', 'en-US'); -- -------------------------------------------------------- diff --git a/app/Events/Load_config.php b/app/Events/Load_config.php index ceb6e9473..5245dcb54 100644 --- a/app/Events/Load_config.php +++ b/app/Events/Load_config.php @@ -16,48 +16,41 @@ use Config\Services; */ class Load_config { - /** - * Loads configuration from database into App CI config and then applies those settings - */ - public function load_config() - { - //Migrations - $migration_config = config('Migrations'); - $migration = new MY_Migration($migration_config); + /** + * Loads configuration from database into App CI config and then applies those settings + */ + public function load_config() + { + //Migrations + $migration_config = config('Migrations'); + $migration = new MY_Migration($migration_config); - $this->session = session(); + $this->session = session(); - //Database Configuration - $config = config('OSPOS'); - $appconfig = model(Appconfig::class); + //Database Configuration + $config = config('OSPOS'); if (!$migration->is_latest()) - { - $this->session->destroy(); - } + { + $this->session->destroy(); + } - $config->settings['application_version'] = $migration->get_current_version(); - foreach($appconfig->get_all()->getResult() as $app_config) - { - $config->settings[$app_config->key] = $app_config->value; - } - - //Language + //Language helper('locale'); - $language_exists = file_exists('../app/Language/' . current_language_code()); + $language_exists = file_exists('../app/Language/' . current_language_code()); - if(current_language_code() == null || current_language() == null || !$language_exists) //TODO: current_language() is undefined - { - $config->language = 'english'; - $config->language_code = 'en-US'; - } + if(current_language_code() == null || current_language() == null || !$language_exists) //TODO: current_language() is undefined + { + $config->language = 'english'; + $config->language_code = 'en-US'; + } - $language = Services::language(); - $language->setLocale($config->settings['language_code']); + $language = Services::language(); + $language->setLocale($config->settings['language_code']); - //Time Zone - date_default_timezone_set($config->timezone ?? 'America/New_York'); + //Time Zone + date_default_timezone_set($config->timezone ?? 'America/New_York'); - bcscale(max(2, totals_decimals() + tax_decimals())); - } + bcscale(max(2, totals_decimals() + tax_decimals())); + } } diff --git a/app/Helpers/locale_helper.php b/app/Helpers/locale_helper.php index 09d139294..5e87b8106 100644 --- a/app/Helpers/locale_helper.php +++ b/app/Helpers/locale_helper.php @@ -13,12 +13,13 @@ define('DEFAULT_DATETIME', mktime(0, 0, 0, 1, 1, 2010)); /** * Currency locale helper */ -function current_language_code(bool $load_system_language = FALSE): string +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 != TRUE) //TODO: !== + if($employee->is_logged_in() && $load_system_language === false) { $employee_info = $employee->get_logged_in_employee_info(); @@ -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,9 +37,10 @@ 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 != TRUE) //TODO: !== + if($employee->is_logged_in() && !$load_system_language) { $employee_info = $employee->get_logged_in_employee_info(); @@ -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; } @@ -101,26 +103,6 @@ function get_languages(): array ]; } -function load_language(array $lang_array, bool $load_system_language = FALSE): void //TODO: this is not called anywhere in the code. -{ - $lang = get_instance()->lang; - - if($load_system_language) - { - foreach($lang_array as $language_file) - { - $lang->load($language_file, current_language_code(TRUE)); - } - } - else - { - foreach($lang_array as $language_file) - { - $lang->load($language_file, current_language_code()); - } - } -} - function get_timezones(): array { return [ @@ -249,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'); @@ -286,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'); } @@ -296,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 @@ -344,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); } @@ -380,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); } @@ -430,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, ''); } @@ -502,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 @@ -586,10 +582,25 @@ 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() { return (preg_match('/^(\d*\.)?\d+$/', $decimal) === 1); -} \ No newline at end of file +} + +function encode_array(array $data): array +{ + array_walk($data, function(&$value, &$key) { $value = rawurlencode($value);}); + + return $data; +} + +function decode_array(array $data): array +{ + array_walk($data, function(&$value, &$key) { $value = rawurldecode($value);}); + + return $data; +} diff --git a/app/Helpers/report_helper.php b/app/Helpers/report_helper.php index 5cbf128c5..fe573055e 100644 --- a/app/Helpers/report_helper.php +++ b/app/Helpers/report_helper.php @@ -33,7 +33,7 @@ function show_report(string $report_prefix, string $report_name, string $lang_ke if(!empty($report_label) && $report_label != $lang_key . ' (TBD)') //TODO: String Interpolation. Also !== {//TODO: Is there a better way to do this? breaking the php like this makes it more difficult to read. ?> - + "> 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 7ea932aee..2abece36b 100644 --- a/app/Libraries/Email_lib.php +++ b/app/Libraries/Email_lib.php @@ -5,6 +5,7 @@ namespace app\Libraries; use CodeIgniter\Email\Email; use CodeIgniter\Encryption\Encryption; use CodeIgniter\Encryption\EncrypterInterface; +use Config\Services; /** @@ -15,6 +16,7 @@ use CodeIgniter\Encryption\EncrypterInterface; * @property email email * @property encryption encryption * @property encrypterinterface encrypter + * @property array config */ class Email_lib @@ -22,25 +24,25 @@ class Email_lib public function __construct() { $this->email = new Email(); - $this->encryption = new Encryption(); - $this->encrypter = $this->encryption->initialize(); - - - $config = [ + $this->config = config('OSPOS')->settings; + $encrypter = Services::encrypter(); + + + $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' => $this->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); } /** @@ -51,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); @@ -70,4 +72,4 @@ class Email_lib return $result; } -} \ No newline at end of file +} diff --git a/app/Libraries/MY_Migration.php b/app/Libraries/MY_Migration.php index d9c3642fc..178081d31 100644 --- a/app/Libraries/MY_Migration.php +++ b/app/Libraries/MY_Migration.php @@ -27,11 +27,12 @@ class MY_Migration extends MigrationRunner * * @return string The version number of the last successfully run database migration. */ - public function get_current_version(): int + public static function get_current_version(): int { - if($this->db->tableExists('migrations')) + $db = Database::connect(); + if($db->tableExists('migrations')) { - $builder = $this->db->table('migrations'); + $builder = $db->table('migrations'); $builder->select('version')->orderBy('version', 'DESC')->limit(1); return $builder->get()->getRow()->version; } diff --git a/app/Libraries/Mailchimp_lib.php b/app/Libraries/Mailchimp_lib.php index 5f79f1a36..a36efe0df 100644 --- a/app/Libraries/Mailchimp_lib.php +++ b/app/Libraries/Mailchimp_lib.php @@ -3,7 +3,7 @@ namespace app\Libraries; use CodeIgniter\Encryption\EncrypterInterface; -use CodeIgniter\Encryption\Encryption; +use Config\Services; /** * MailChimp API v3 REST client Connector @@ -14,7 +14,6 @@ use CodeIgniter\Encryption\Encryption; * - Rajitha Bandara: https://github.com/rajitha-bandara/ci-mailchimp-v3-rest-client * - Stefan Ashwell: https://github.com/stef686/codeigniter-mailchimp-api-v3 * - * @property encryption encryption * @property encrypterinterface encrypter */ class MailchimpConnector @@ -38,16 +37,13 @@ class MailchimpConnector */ public function __construct(string $api_key = '') { - $this->encryption = new Encryption(); + $config = config('OSPOS')->settings; - if(empty($api_key)) - { - $this->_api_key = $this->encrypter->decrypt(config('OSPOS')->settings['mailchimp_api_key']); //TODO: Hungarian notation - } - else - { - $this->_api_key = $api_key; //TODO: Hungarian notation - } + $encrypter = Services::encrypter(); + + $this->_api_key = empty($api_key) + ? $encrypter->decrypt($config['mailchimp_api_key']) //TODO: Hungarian notation + : $api_key; //TODO: Hungarian notation if(!empty($this->_api_key)) //TODO: Hungarian notation { @@ -335,4 +331,4 @@ class Mailchimp_lib //TODO: IMO We need to stick to the one class per file princ return $this->_connector->call("/lists/$list_id/members/" . md5(strtolower($email)), 'PUT', $parameters); //TODO: Hungarian notation } -} \ No newline at end of file +} diff --git a/app/Libraries/Receiving_lib.php b/app/Libraries/Receiving_lib.php index 025c532c2..2236534bf 100644 --- a/app/Libraries/Receiving_lib.php +++ b/app/Libraries/Receiving_lib.php @@ -127,7 +127,7 @@ class Receiving_lib $this->session->remove('recv_comment'); } - public function get_reference(): string + public function get_reference(): ?string { return $this->session->get('recv_reference'); } @@ -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; } @@ -423,4 +425,4 @@ class Receiving_lib return $total; } -} \ No newline at end of file +} diff --git a/app/Libraries/Sale_lib.php b/app/Libraries/Sale_lib.php index 3e8eec954..825c16e56 100644 --- a/app/Libraries/Sale_lib.php +++ b/app/Libraries/Sale_lib.php @@ -14,6 +14,7 @@ use App\Models\Sale; use CodeIgniter\Session\Session; use App\Models\Stock_location; use ReflectionException; +use App\Libraries\Tax_lib; /** * Sale library @@ -30,15 +31,14 @@ use ReflectionException; * @property rounding_mode rounding_mode * @property sale sale * @property stock_location stock_location - * - * @property tax_lib tax_lib + * @property Tax_lib tax_lib * @property session session + * @property array config */ class Sale_lib { public function __construct() { - $this->tax_lib = new Tax_lib(); $this->session = Session(); $this->attribute = model('Attribute'); @@ -51,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 @@ -66,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'); } @@ -75,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'); } @@ -131,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) @@ -141,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) @@ -153,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) @@ -311,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. @@ -352,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; } @@ -379,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; } @@ -720,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 } @@ -927,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; } @@ -1231,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. { @@ -1379,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); @@ -1397,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)); } @@ -1421,9 +1422,11 @@ 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(); + foreach($this->tax_lib->get_taxes($cart)[0] as $tax) { $total = bcadd($total, $tax['sale_tax_amount']); @@ -1446,8 +1449,8 @@ 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); } -} \ No newline at end of file +} diff --git a/app/Libraries/Sms_lib.php b/app/Libraries/Sms_lib.php index 7d85280f9..adfabc6ab 100644 --- a/app/Libraries/Sms_lib.php +++ b/app/Libraries/Sms_lib.php @@ -4,6 +4,7 @@ namespace app\Libraries; use CodeIgniter\Encryption\Encryption; use CodeIgniter\Encryption\EncrypterInterface; +use Config\Services; /** @@ -18,21 +19,18 @@ use CodeIgniter\Encryption\EncrypterInterface; class Sms_lib { - public function __construct() - { - $this->encryption = new Encryption(); //TODO: Is this the correct way to load the encryption service now? - $this->encrypter = $this->encryption->initialize(); - } - /* * SMS sending function * Example of use: $response = sendSMS('4477777777', 'My test message'); */ public function sendSMS(int $phone, string $message): bool { - $username = config('OSPOS')->settings['msg_uid']; - $password = $this->encrypter->decrypt(config('OSPOS')->settings['msg_pwd']); - $originator = config('OSPOS')->settings['msg_src']; + $config = config('OSPOS')->settings; + $encrypter = Services::encrypter(); + + $username = $config['msg_uid']; + $password = $encrypter->decrypt($config['msg_pwd']); + $originator = $config['msg_src']; $response = FALSE; @@ -78,4 +76,4 @@ class Sms_lib return $response; } -} \ No newline at end of file +} 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 2b388cc64..5ce677932 100644 --- a/app/Models/Appconfig.php +++ b/app/Models/Appconfig.php @@ -9,10 +9,19 @@ use ReflectionException; /** * Appconfig class * - * @property mixed config + * */ class Appconfig extends Model { + protected $table = 'app_config'; + protected $primaryKey = 'key'; + protected $useAutoIncrement = false; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'key', + 'value' + ]; + public function exists(string $key): bool { $builder = $this->db->table('app_config'); @@ -32,7 +41,7 @@ class Appconfig extends Model public function get_value(string $key, string $default = ''): string { $builder = $this->db->table('app_config'); - $query = $builder->getWhere(['key' => $key], 1, 1); + $query = $builder->getWhere(['key' => $key], 1); if($query->getNumRows() == 1) //TODO: === { @@ -43,21 +52,19 @@ class Appconfig extends Model } /** - * Calls the parent save() from BaseModel but additionally updates the cached array value. - * @param $data + * Calls the parent save() from BaseModel and updates the cached reference. + * @param array|object $data * @return bool * @throws ReflectionException */ - public function save($data): bool + public function save($data): bool //TODO: This is puking: Allowed fields must be specified for model: "App\Models\Appconfig" { - $this->config = config('OSPOS'); $success = parent::save($data); - - $key = array_keys($data)[0]; + $config = config('OSPOS'); if($success) { - $this->config[$key] = $data[$key]; + $config->update_settings(); //TODO: We need to investigate whether there is a possibility of stale data. It updates the cache in this function, but when save() returns any instances of $config->settings[] may not be updated yet. } return $success; @@ -102,7 +109,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 +125,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 +141,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 910812179..901bc8621 100644 --- a/app/Models/Attribute.php +++ b/app/Models/Attribute.php @@ -13,6 +13,26 @@ use ReflectionClass; */ class Attribute extends Model { + protected $table = 'attribute_definitions'; + protected $primaryKey = 'definition_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; + protected $allowedFields = [ //TODO: This model may not be well designed... The model accesses three different tables (attribute_definitions, attribute_links, attribute_values). Should that be more than one model? According to CodeIgniter, these are meant to model a single table https://codeigniter.com/user_guide/models/model.html#models + 'definition_name', + 'definition_type', + 'definition_unit', + 'definition_flags', + 'deleted', + 'attribute_id', + 'definition_id', + 'item_id', + 'sale_id', + 'receiving_id', + 'attribute_value', + 'attribute_date', + 'attribute_decimal' + ]; + const SHOW_IN_ITEMS = 1; //TODO: These need to be moved to constants.php const SHOW_IN_SALES = 2; const SHOW_IN_RECEIVINGS = 4; @@ -67,11 +87,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: @@ -207,7 +228,7 @@ class Attribute extends Model public function get_definitions_by_flags(int $definition_flags): array { $builder = $this->db->table('attribute_definitions'); - $builder->where('definition_flags &', $definition_flags); + $builder->where('definition_flags', $definition_flags); $builder->where('deleted', 0); $builder->where('definition_type <>', GROUP); $builder->orderBy('definition_id'); @@ -490,12 +511,12 @@ class Attribute extends Model return $success; } - public function get_definition_by_name(string $definition_name, $definition_type = FALSE): array + public function get_definition_by_name(string $definition_name, $definition_type = false): array { $builder = $this->db->table('attribute_definitions'); $builder->where('definition_name', $definition_name); - if($definition_type != FALSE) + if($definition_type) { $builder->where('definition_type', $definition_type); } @@ -648,7 +669,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)) @@ -825,7 +847,7 @@ class Attribute extends Model { $new_attribute_id = $this->save_value($attribute['attribute_value'], $definition_id, FALSE, $attribute['attribute_id'], $definition_type); - if($this->save_link($attribute['item_id'], $definition_id, $new_attribute_id) == FALSE) + if(!$this->save_link($attribute['item_id'], $definition_id, $new_attribute_id)) { log_message('Error', 'Transaction failed'); $this->db->transRollback(); diff --git a/app/Models/Cashup.php b/app/Models/Cashup.php index 6b723d281..3dc3ba351 100644 --- a/app/Models/Cashup.php +++ b/app/Models/Cashup.php @@ -14,6 +14,27 @@ use stdClass; class Cashup extends Model { + protected $table = 'cash_up'; + protected $primaryKey = 'cashup_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'open_date', + 'close_date', + 'open_cash_amount', + 'transfer_cash_amount', + 'note', + 'closed_amount_cash', + 'closed_amount_card', + 'closed_amount_check', + 'closed_amount_total', + 'description', + 'open_employee_id', + 'close_employee_id', + 'deleted', + 'closed_amount_due' + ]; + /** * Determines if a given Cashup_id is a Cashup */ @@ -60,10 +81,11 @@ 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 - if($count_only == TRUE) + if($count_only) { $builder->select('COUNT(cash_up.cashup_id) as count'); } @@ -105,7 +127,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'])); } @@ -117,7 +139,7 @@ class Cashup extends Model $builder->groupBy('cashup_id'); // get_found_rows case - if($count_only == TRUE) + if($count_only) { return $builder->get()->getRowArray()['count']; } @@ -221,4 +243,4 @@ class Cashup extends Model return $success; } -} \ No newline at end of file +} diff --git a/app/Models/Customer.php b/app/Models/Customer.php index 8cd8842f9..7fb0d4856 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -9,6 +9,27 @@ use CodeIgniter\Database\ResultInterface; */ class Customer extends Person { + protected $table = 'customers'; + protected $primaryKey = 'person_id'; + protected $useAutoIncrement = false; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'account_number', + 'taxable', + 'tax_id', + 'sales_tax_code_id', + 'deleted', + 'discount', + 'discount_type', + 'company_name', + 'package_id', + 'points', + 'date', + 'employee_id', + 'consent' + ]; + + /** * Determines if a given person_id is a customer */ @@ -226,9 +247,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); @@ -407,7 +429,7 @@ class Customer extends Person $builder->where('deleted', 0); // get_found_rows case - if($count_only == TRUE) + if($count_only) { return $builder->get()->getRow()->count; } @@ -421,4 +443,4 @@ class Customer extends Person return $builder->get(); } -} \ No newline at end of file +} diff --git a/app/Models/Customer_rewards.php b/app/Models/Customer_rewards.php index 3ebe5e651..a68415a59 100644 --- a/app/Models/Customer_rewards.php +++ b/app/Models/Customer_rewards.php @@ -10,6 +10,16 @@ use CodeIgniter\Model; */ class Customer_rewards extends Model { + protected $table = 'customer_packages'; + protected $primaryKey = 'package_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'package_name', + 'points_percent', + 'deleted' + ]; + public function exists(int $package_id): bool { $builder = $this->db->table('customers_packages'); diff --git a/app/Models/Dinner_table.php b/app/Models/Dinner_table.php index bb2dff55e..5715cf28e 100644 --- a/app/Models/Dinner_table.php +++ b/app/Models/Dinner_table.php @@ -10,6 +10,16 @@ use CodeIgniter\Model; */ class Dinner_table extends Model { + protected $table = 'dinner_tables'; + protected $primaryKey = 'dinner_table_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'name', + 'status', + 'deleted' + ]; + public function exists(int $dinner_table_id): bool { $builder = $this->db->table('dinner_tables'); @@ -145,4 +155,4 @@ class Dinner_table extends Model { return $this->release($release_dinner_table_id) && $this->occupy($occupy_dinner_table_id); } -} \ No newline at end of file +} diff --git a/app/Models/Employee.php b/app/Models/Employee.php index 062f2a4a5..0ee5df93b 100644 --- a/app/Models/Employee.php +++ b/app/Models/Employee.php @@ -3,6 +3,7 @@ namespace App\Models; use CodeIgniter\Database\ResultInterface; +use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\Session\Session; /** @@ -13,6 +14,19 @@ use CodeIgniter\Session\Session; */ class Employee extends Person { + protected $table = 'Employees'; + protected $primaryKey = 'person_id'; + protected $useAutoIncrement = false; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'username', + 'password', + 'deleted', + 'hashversion', + 'language', + 'language_code' + ]; + public function __construct() { parent::__construct(); @@ -80,20 +94,18 @@ class Employee extends Person { return $query->getRow(); } - else //TODO: No need for this else statement. Just put it's contents outside of the else since the if has a return in it. + + //Get empty base parent object, as $employee_id is NOT an employee + $person_obj = parent::get_info(-1); //TODO: Replace -1 with a constant + + //Get all the fields from employee table + //append those fields to base parent object, we have a complete empty object + foreach($this->db->getFieldNames('employees') as $field) { - //Get empty base parent object, as $employee_id is NOT an employee - $person_obj = parent::get_info(-1); //TODO: Replace -1 with a constant - - //Get all the fields from employee table - //append those fields to base parent object, we have a complete empty object - foreach($this->db->getFieldNames('employees') as $field) - { - $person_obj->$field = ''; - } - - return $person_obj; + $person_obj->$field = ''; } + + return $person_obj; } /** @@ -244,7 +256,7 @@ class Employee extends Person $builder->orLike('CONCAT(first_name, " ", last_name)', $search); $builder->groupEnd(); - if($unique == FALSE) + if(!$unique) { $builder->where('deleted', 0); } @@ -396,11 +408,11 @@ class Employee extends Person /** * Logs out a user by destroying all session data and redirect to log in */ - public function logout(): void + public function logout(): RedirectResponse { - $this->session->destroy(); + session()->destroy(); - redirect()->to('login'); + return redirect()->to('login'); } /** @@ -547,4 +559,4 @@ class Employee extends Person return $success; } -} \ No newline at end of file +} diff --git a/app/Models/Enums/Rounding_mode.php b/app/Models/Enums/Rounding_mode.php index 0b2e2901f..6769fa3c3 100644 --- a/app/Models/Enums/Rounding_mode.php +++ b/app/Models/Enums/Rounding_mode.php @@ -55,7 +55,7 @@ class Rounding_mode } public static function round_number(int $rounding_mode, float $amount, int $decimals): string - {//TODO: this needs to be be replaced with a switch statement + {//TODO: this needs to be replaced with a switch statement if($rounding_mode == Rounding_mode::ROUND_UP) { $fig = pow(10, $decimals); diff --git a/app/Models/Expense.php b/app/Models/Expense.php index 0a6bb4b58..ce9a69668 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -14,6 +14,23 @@ use stdClass; */ class Expense extends Model { + protected $table = 'expenses'; + protected $primaryKey = 'expense_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'date', + 'amount', + 'payment_type', + 'expense_category_id', + 'description', + 'employee_id', + 'deleted', + 'supplier_tax_code', + 'tax_amount', + 'supplier_id' + ]; + /** * Determines if a given Expense_id is an Expense */ @@ -72,10 +89,11 @@ 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 - if($count_only == TRUE) //TODO: replace this with `if($count_only)` + if($count_only) //TODO: replace this with `if($count_only)` { $builder->select('COUNT(DISTINCT expenses.expense_id) as count'); } @@ -113,11 +131,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'])); } @@ -126,17 +144,17 @@ class Expense extends Model $builder->where('expenses.date BETWEEN ' . $this->db->escape(rawurldecode($filters['start_date'])) . ' AND ' . $this->db->escape(rawurldecode($filters['end_date']))); } - if($filters['only_debit'] != FALSE) //TODO: Avoid the double negative on these... just replace it with `if($filters['only_debit'])`... same with below. + if($filters['only_debit']) { $builder->like('expenses.payment_type', lang('Expenses.debit')); } - if($filters['only_credit'] != FALSE) + if($filters['only_credit']) { $builder->like('expenses.payment_type', lang('Expenses.credit')); } - if($filters['only_cash'] != FALSE) + if($filters['only_cash']) { $builder->groupStart(); $builder->like('expenses.payment_type', lang('Expenses.cash')); @@ -144,17 +162,17 @@ class Expense extends Model $builder->groupEnd(); } - if($filters['only_due'] != FALSE) + if($filters['only_due']) { $builder->like('expenses.payment_type', lang('Expenses.due')); } - if($filters['only_check'] != FALSE) + if($filters['only_check']) { $builder->like('expenses.payment_type', lang('Expenses.check')); } - if($count_only == TRUE) //TODO: replace this with `if($count_only)` + if($count_only) //TODO: replace this with `if($count_only)` { return $builder->get()->getRow()->count; } @@ -269,12 +287,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'])); } @@ -283,27 +303,27 @@ class Expense extends Model $builder->where('date BETWEEN ' . $this->db->escape(rawurldecode($filters['start_date'])) . ' AND ' . $this->db->escape(rawurldecode($filters['end_date']))); } - if($filters['only_cash'] != FALSE) //TODO: Avoid the double negative on these... just replace it with `if($filters['only_cash'])`... same with below. + if($filters['only_cash']) { $builder->like('payment_type', lang('Expenses.cash')); } - if($filters['only_due'] != FALSE) + if($filters['only_due']) { $builder->like('payment_type', lang('Expenses.due')); } - if($filters['only_check'] != FALSE) + if($filters['only_check']) { $builder->like('payment_type', lang('Expenses.check')); } - if($filters['only_credit'] != FALSE) + if($filters['only_credit']) { $builder->like('payment_type', lang('Expenses.credit')); } - if($filters['only_debit'] != FALSE) + if($filters['only_debit']) { $builder->like('payment_type', lang('Expenses.debit')); } @@ -331,4 +351,4 @@ class Expense extends Model return $builder->get(); } -} \ No newline at end of file +} diff --git a/app/Models/Expense_category.php b/app/Models/Expense_category.php index 23b6e4777..af9d6a46a 100644 --- a/app/Models/Expense_category.php +++ b/app/Models/Expense_category.php @@ -11,6 +11,16 @@ use stdClass; */ class Expense_category extends Model { + protected $table = 'expense_categories'; + protected $primaryKey = 'expense_category_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'category_name', + 'category_description', + 'deleted' + ]; + /** * Determines if a given Expense_id is an Expense category */ @@ -69,7 +79,7 @@ class Expense_category extends Model { $builder = $this->db->table('expense_categories'); - if($no_deleted == TRUE) + if($no_deleted) { $builder->where('deleted', 0); } @@ -173,4 +183,4 @@ class Expense_category extends Model return $builder->get(); } -} \ No newline at end of file +} diff --git a/app/Models/Giftcard.php b/app/Models/Giftcard.php index ae76a64c7..d23e1289c 100644 --- a/app/Models/Giftcard.php +++ b/app/Models/Giftcard.php @@ -11,6 +11,18 @@ use stdClass; */ class Giftcard extends Model { + protected $table = 'giftcards'; + protected $primaryKey = 'giftcard_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'giftcard_number', + 'value', + 'deleted', + 'person_id', + 'record_time' + ]; + /** * Determines if a given giftcard_id is a giftcard */ @@ -226,7 +238,7 @@ class Giftcard extends Model $builder = $this->db->table('giftcards'); // get_found_rows case - if($count_only == TRUE) //TODO: replace this with `if($count_only)` + if($count_only) //TODO: replace this with `if($count_only)` { $builder->select('COUNT(giftcards.giftcard_id) as count'); } @@ -242,7 +254,7 @@ class Giftcard extends Model $builder->where('giftcards.deleted', 0); // get_found_rows case - if($count_only == TRUE) //TODO: replace this with `if($count_only)` + if($count_only) //TODO: replace this with `if($count_only)` { return $builder->get()->getRow()->count; } @@ -329,4 +341,4 @@ class Giftcard extends Model return $builder->get()->getRow()->person_id; } -} \ No newline at end of file +} diff --git a/app/Models/Inventory.php b/app/Models/Inventory.php index 1ee3cb106..2957fb69c 100644 --- a/app/Models/Inventory.php +++ b/app/Models/Inventory.php @@ -14,14 +14,27 @@ use ReflectionException; */ class Inventory extends Model { - public function insert(array $inventory_data = NULL, bool $returnID = TRUE): bool //TODO: $returnID does not match variable naming conventions. It's also never used in the function + protected $table = 'inventory'; + protected $primaryKey = 'trans_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'trans_items', + 'trans_user', + 'trans_date', + 'trans_comment', + 'trans_inventory', + 'trans_location' + ]; + + public function insert($inventory_data = NULL, bool $returnID = TRUE) { $builder = $this->db->table('inventory'); return $builder->insert($inventory_data); } - public function update(string $comment = NULL, array $inventory_data = NULL): bool //TODO: this function either needs a name change or to be brought in line with the parent function declaration. + public function update($comment = NULL, $inventory_data = NULL): bool { $builder = $this->db->table('inventory'); $builder->where('trans_comment', $comment); @@ -40,7 +53,7 @@ class Inventory extends Model $builder = $this->db->table('inventory'); $builder->where('trans_items', $item_id); - if($location_id != FALSE) + if($location_id) { $builder->where('trans_location', $location_id); } @@ -84,4 +97,4 @@ class Inventory extends Model return $builder->get()->getResultArray(); } -} \ No newline at end of file +} diff --git a/app/Models/Item.php b/app/Models/Item.php index 13ceaacb8..eb672f95d 100644 --- a/app/Models/Item.php +++ b/app/Models/Item.php @@ -15,6 +15,33 @@ use stdClass; */ class Item extends Model { + protected $table = 'items'; + protected $primaryKey = 'item_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'name', + 'category', + 'supplier_id', + 'item_number', + 'description', + 'cost_price', + 'unit_price', + 'reorder_level', + 'allow_alt_description', + 'is_serialized', + 'deleted', + 'stock_type', + 'item_type', + 'tax_category_id', + 'receiving_quantity', + 'pic_filename', + 'qty_per_pack', + 'pack_name', + 'low_sell_item_id', + 'hsn_code' + ]; + /** * Determines if a given item_id is an item */ @@ -43,7 +70,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 +122,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 +180,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'])); } @@ -194,23 +224,23 @@ class Item extends Model $builder->where('items.deleted', $filters['is_deleted']); - if($filters['empty_upc'] != FALSE) //TODO: Avoid the double negative on these... just replace it with `if($filters['empty_upc'])`... same with below. + if($filters['empty_upc']) { $builder->where('item_number', NULL); } - if($filters['low_inventory'] != FALSE) + if($filters['low_inventory']) { $builder->where('quantity <=', 'reorder_level'); } - if($filters['is_serialized'] != FALSE) + if($filters['is_serialized']) { $builder->where('is_serialized', 1); } - if($filters['no_description'] != FALSE) + if($filters['no_description']) { $builder->where('items.description', ''); } - if($filters['temporary'] != FALSE) + if($filters['temporary']) { $builder->where('items.item_type', ITEM_TEMP); } @@ -346,7 +376,7 @@ class Item extends Model $builder->join('suppliers', 'suppliers.person_id = items.supplier_id', 'left'); $builder->where('item_number', $item_number); - if($ignore_deleted == FALSE) //TODO: === + if(!$ignore_deleted) { $builder->where('items.deleted', $deleted); } @@ -439,7 +469,7 @@ class Item extends Model * Deletes one item * @throws ReflectionException */ - public function delete(int $item_id = null, bool $purge = false): bool //TODO: need to figure out what to do with these override functions that don't match our signature. + public function delete($item_id = null, bool $purge = false) { $this->db->transStart(); @@ -505,16 +535,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 +553,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 +1060,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 +1071,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; } @@ -1048,4 +1082,4 @@ class Item extends Model return $item_name; } -} \ No newline at end of file +} diff --git a/app/Models/Item_kit.php b/app/Models/Item_kit.php index 4878466b6..56b262130 100644 --- a/app/Models/Item_kit.php +++ b/app/Models/Item_kit.php @@ -11,6 +11,20 @@ use stdClass; */ class Item_kit extends Model { + protected $table = 'item_kits'; + protected $primaryKey = 'item_kit_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'item_kit_number', + 'name', + 'description', + 'item_id', + 'kit_discount', + 'kit_discount_type', + 'price_option' + ]; + /** * Determines if a given item_id is an item kit */ @@ -50,7 +64,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; } @@ -174,7 +190,7 @@ class Item_kit extends Model /** * Deletes one item kit */ - public function delete(int $item_kit_id = null, bool $purge = false): bool + public function delete($item_kit_id = null, bool $purge = false) { $builder = $this->db->table('item_kits'); @@ -246,7 +262,7 @@ class Item_kit extends Model $builder = $this->db->table('item_kits AS item_kits'); //TODO: Can we just say 'item_kits' here? // get_found_rows case - if($count_only == TRUE) //TODO: replace this with `if($count_only)` + if($count_only) { $builder->select('COUNT(item_kits.item_kit_id) as count'); } @@ -262,7 +278,7 @@ class Item_kit extends Model } // get_found_rows case - if($count_only == TRUE) //TODO: replace this with `if($count_only)` + if($count_only) { return $builder->get()->getRow()->count; } @@ -276,4 +292,4 @@ class Item_kit extends Model return $builder->get(); } -} \ No newline at end of file +} diff --git a/app/Models/Item_kit_items.php b/app/Models/Item_kit_items.php index 7ccbcae5b..13fcb0c88 100644 --- a/app/Models/Item_kit_items.php +++ b/app/Models/Item_kit_items.php @@ -9,6 +9,14 @@ use CodeIgniter\Model; */ class Item_kit_items extends Model { + protected $table = 'item_kit_items'; + protected $primaryKey = 'item_kit_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'kit_sequence' + ]; + /** * Gets item kit items for a particular item kit */ @@ -72,10 +80,10 @@ class Item_kit_items extends Model /** * Deletes item kit items given an item kit */ - public function delete(int $item_kit_id = null, bool $purge = false): bool + public function delete($item_kit_id = null, bool $purge = false) { $builder = $this->db->table('item_kit_items'); return $builder->delete(['item_kit_id' => $item_kit_id]); } -} \ No newline at end of file +} diff --git a/app/Models/Item_quantity.php b/app/Models/Item_quantity.php index 5564e362c..4059f5ca7 100644 --- a/app/Models/Item_quantity.php +++ b/app/Models/Item_quantity.php @@ -10,6 +10,14 @@ use stdClass; */ class Item_quantity extends Model { + protected $table = 'item_quantities'; + protected $primaryKey = 'item_id'; + protected $useAutoIncrement = false; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'quantity' + ]; + public function exists(int $item_id, int $location_id): bool { $builder = $this->db->table('item_quantities'); @@ -41,7 +49,7 @@ class Item_quantity extends Model $builder->where('location_id', $location_id); $result = $builder->get()->getRow(); - if(empty($result) == TRUE) + if(empty($result)) { //Get empty base parent object, as $item_id is NOT an item $result = new stdClass(); @@ -93,4 +101,4 @@ class Item_quantity extends Model return $builder->update(['quantity' => 0]); } -} \ No newline at end of file +} diff --git a/app/Models/Item_taxes.php b/app/Models/Item_taxes.php index 4eed703f4..3a5acc9c3 100644 --- a/app/Models/Item_taxes.php +++ b/app/Models/Item_taxes.php @@ -9,6 +9,15 @@ use CodeIgniter\Model; */ class Item_taxes extends Model { + protected $table = 'item_taxes'; + protected $primaryKey = 'item_id'; + protected $useAutoIncrement = false; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'name', + 'percent' + ]; + /** * Gets tax info for a particular item */ @@ -81,10 +90,10 @@ class Item_taxes extends Model /** * Deletes taxes given an item */ - public function delete(int $item_id = null, bool $purge = false): bool + public function delete($item_id = null, bool $purge = false) { $builder = $this->db->table('items_taxes'); return $builder->delete(['item_id' => $item_id]); } -} \ No newline at end of file +} diff --git a/app/Models/Module.php b/app/Models/Module.php index 5610e8aab..bbc2fd4ba 100644 --- a/app/Models/Module.php +++ b/app/Models/Module.php @@ -10,6 +10,16 @@ use CodeIgniter\Model; */ class Module extends Model { + protected $table = 'modules'; + protected $primaryKey = 'module_id'; + protected $useAutoIncrement = false; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'name_lang_key', + 'desc_lang_key', + 'sort' + ]; + public function get_module_name(string $module_id): string { $builder = $this->db->table('modules'); @@ -128,4 +138,4 @@ class Module extends Model return $builder->get()->getRow()->sort; } -} \ No newline at end of file +} diff --git a/app/Models/Person.php b/app/Models/Person.php index 2afeb09a6..9039977c1 100644 --- a/app/Models/Person.php +++ b/app/Models/Person.php @@ -11,6 +11,25 @@ use stdClass; */ class Person extends Model { + protected $table = 'people'; + protected $primaryKey = 'person_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'first_name', + 'last_name', + 'phone_number', + 'email', + 'address_1', + 'address_2', + 'city', + 'state', + 'zip', + 'country', + 'comments', + 'gender' + ]; + /** * Determines whether the given person exists in the people database table * @@ -176,7 +195,7 @@ class Person extends Model */ public function delete($person_id = null, bool $purge = false): bool { - return TRUE; + return true; } /** @@ -189,4 +208,4 @@ class Person extends Model { return TRUE; } -} \ No newline at end of file +} diff --git a/app/Models/Receiving.php b/app/Models/Receiving.php index 1bb7917f9..af8618673 100644 --- a/app/Models/Receiving.php +++ b/app/Models/Receiving.php @@ -17,6 +17,20 @@ use ReflectionException; */ class Receiving extends Model { + protected $table = 'receivings'; + protected $primaryKey = 'receiving_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'receiving_time', + 'supplier_id', + 'employee_id', + 'comment', + 'receiving_id', + 'payment_type', + 'reference' + ]; + public function get_info(int $receiving_id): ResultInterface { $builder = $this->db->table('receivings'); @@ -63,7 +77,7 @@ class Receiving extends Model return ($builder->get()->getNumRows() == 1); } - public function update(int $receiving_id = NULL, array $receiving_data = NULL): bool + public function update($receiving_id = NULL, $receiving_data = NULL): bool { $builder = $this->db->table('receivings'); $builder->where('receiving_id', $receiving_id); @@ -107,6 +121,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 +144,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); } @@ -238,7 +253,7 @@ class Receiving extends Model // execute transaction $this->db->transComplete(); - + return $this->db->transStatus(); } @@ -249,7 +264,7 @@ class Receiving extends Model return $builder->get(); } - + public function get_supplier(int $receiving_id): object { $builder = $this->db->table('receivings'); @@ -275,9 +290,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']); } @@ -331,4 +348,4 @@ class Receiving extends Model $this->db->query($sql); } -} \ No newline at end of file +} 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' => '
', @@ -34,7 +35,7 @@ class Summary_payments extends Summary_report $where = ''; //TODO: Duplicated code //TODO: this needs to be converted to ternary notation - if(empty(config('OSPOS')->settings['date_or_time_format'])) { + if(empty($config['date_or_time_format'])) { $where .= 'DATE(sale_time) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date']); } else { $where .= 'sale_time BETWEEN ' . $this->db->escape(rawurldecode($inputs['start_date'])) . ' AND ' . $this->db->escape(rawurldecode($inputs['end_date'])); @@ -170,4 +171,4 @@ class Summary_payments extends Summary_report )' ); } -} \ No newline at end of file +} diff --git a/app/Models/Reports/Summary_report.php b/app/Models/Reports/Summary_report.php index 8ad83da8f..7dda0e934 100644 --- a/app/Models/Reports/Summary_report.php +++ b/app/Models/Reports/Summary_report.php @@ -9,9 +9,10 @@ abstract class Summary_report extends Report */ private function __common_select(array $inputs, &$builder): void //TODO: Hungarian notation { + $config = config('OSPOS')->settings; $where = ''; //TODO: Duplicated code - if(empty(config('OSPOS')->settings['date_or_time_format'])) + if(empty($config['date_or_time_format'])) { $where .= 'DATE(sale_time) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date']); } @@ -32,7 +33,7 @@ abstract class Summary_report extends Report $cash_adjustment = 'IFNULL(SUM(payments.sale_cash_adjustment), 0)'; - if(config('OSPOS')->settings['tax_included']) + if($config['tax_included']) { $sale_total = "ROUND(SUM($sale_price), $decimals) + $cash_adjustment"; $sale_subtotal = "$sale_total - $sales_tax"; @@ -100,8 +101,10 @@ abstract class Summary_report extends Report private function __common_where(array $inputs, &$builder): void { + $config = config('OSPOS')->settings; + //TODO: Probably going to need to rework these since you can't reference $builder without it's instantiation. - 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(sales.sale_time) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date'])); } @@ -193,4 +196,4 @@ abstract class Summary_report extends Report return $builder->get()->getRowArray(); } -} \ No newline at end of file +} diff --git a/app/Models/Reports/Summary_sales_taxes.php b/app/Models/Reports/Summary_sales_taxes.php index 9ead0c8c1..57edd8d76 100644 --- a/app/Models/Reports/Summary_sales_taxes.php +++ b/app/Models/Reports/Summary_sales_taxes.php @@ -17,9 +17,11 @@ class Summary_sales_taxes extends Summary_report protected function _where(array $inputs, object &$builder): void //TODO: hungarian notation { + $config = config('OSPOS')->settings; + $builder->where('sales.sale_status', COMPLETED); - 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(sales.sale_time) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date'])); } @@ -31,9 +33,11 @@ class Summary_sales_taxes extends Summary_report public function getData(array $inputs): array { + $config = config('OSPOS')->settings; + $where = 'WHERE sale_status = ' . COMPLETED . ' '; - if(empty(config('OSPOS')->settings['date_or_time_format'])) + if(empty($config['date_or_time_format'])) { $where .= 'AND DATE(sale_time) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date']); @@ -55,4 +59,4 @@ class Summary_sales_taxes extends Summary_report return $query->getResultArray(); } -} \ No newline at end of file +} diff --git a/app/Models/Reports/Summary_taxes.php b/app/Models/Reports/Summary_taxes.php index 0800fb338..2905e7f1c 100644 --- a/app/Models/Reports/Summary_taxes.php +++ b/app/Models/Reports/Summary_taxes.php @@ -7,7 +7,7 @@ class Summary_taxes extends Summary_report protected function _get_data_columns(): array //TODO: hungarian notation { return [ - ['tax_name' => $this->lang->line('Reports.tax_name'), 'sortable' => FALSE], + ['tax_name' => lang('Reports.tax_name'), 'sortable' => FALSE], ['tax_percent' => lang('Reports.tax_percent'), 'sorter' => 'number_sorter'], ['report_count' => lang('Reports.sales'), 'sorter' => 'number_sorter'], ['subtotal' => lang('Reports.subtotal'), 'sorter' => 'number_sorter'], @@ -18,9 +18,11 @@ class Summary_taxes extends Summary_report protected function _where(array $inputs, &$builder): void //TODO: hungarian notation { + $config = config('OSPOS')->settings; + $builder->where('sales.sale_status', COMPLETED); - if(empty(config('OSPOS')->settings['date_or_time_format'])) + if(empty($config['date_or_time_format'])) { $builder->where('DATE(sales.sale_time) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date'])); } @@ -32,9 +34,11 @@ class Summary_taxes extends Summary_report public function getData(array $inputs): array { + $config = config('OSPOS')->settings; + $where = 'WHERE sale_status = ' . COMPLETED . ' '; //TODO: Duplicated code - if(empty(config('OSPOS')->settings['date_or_time_format'])) //TODO: Ternary notation + if(empty($config['date_or_time_format'])) //TODO: Ternary notation { $where .= 'AND DATE(sale_time) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date']); } @@ -44,7 +48,7 @@ class Summary_taxes extends Summary_report } $decimals = totals_decimals(); - if(config('OSPOS')->settings['tax_included']) + if($config['tax_included']) { $sale_total = '(CASE WHEN sales_items.discount_type = ' . PERCENT . " THEN sales_items.quantity_purchased * sales_items.item_unit_price - ROUND(sales_items.quantity_purchased * sales_items.item_unit_price * sales_items.discount / 100, $decimals)" diff --git a/app/Models/Rewards.php b/app/Models/Rewards.php index e85ffbc8c..0afbee8ee 100644 --- a/app/Models/Rewards.php +++ b/app/Models/Rewards.php @@ -10,6 +10,16 @@ use CodeIgniter\Model; class Rewards extends Model //TODO: This class is named with plural while the general practice is to name models singular { + protected $table = 'sales_reward_points'; + protected $primaryKey = 'id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'sale_id', + 'earned', + 'used' + ]; + /** * Inserts or updates a rewards */ @@ -32,4 +42,4 @@ class Rewards extends Model //TODO: This class is named with plural while the ge return $builder->update($rewards_data); } -} \ No newline at end of file +} diff --git a/app/Models/Sale.php b/app/Models/Sale.php index c12b18451..18008ba1d 100644 --- a/app/Models/Sale.php +++ b/app/Models/Sale.php @@ -25,11 +25,28 @@ use ReflectionException; */ class Sale extends Model { + protected $table = 'sales'; + protected $primaryKey = 'sale_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'sale_time', + 'customer_id', + 'employee_id', + 'comment', + 'quote_number', + 'sale_status', + 'invoice_number', + 'dinner_table_id', + 'work_order_number', + 'sale_type' + ]; + public function __construct() { parent::__construct(); - $this->sale_lib = new Sale_lib(); +// $this->sale_lib = new Sale_lib(); //TODO: This is causing an infinite loop because the sale lib is invoking the sale model and the model invokes the sale_lib } /** @@ -37,6 +54,7 @@ class Sale extends Model */ public function get_info(int $sale_id): ResultInterface { + $config = config('OSPOS')->settings; $this->create_temp_table (['sale_id' => $sale_id]); $decimals = totals_decimals(); @@ -46,7 +64,7 @@ class Sale extends Model . " 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'; - if(config('OSPOS')->settings['tax_included']) //TODO: This needs to be replaced with Ternary notation + if($config['tax_included']) //TODO: This needs to be replaced with Ternary notation { $sale_total = "ROUND(SUM($sale_price), $decimals) + $cash_adjustment"; } @@ -110,10 +128,12 @@ class Sale extends Model */ public function search(string $search, array $filters, int $rows = 0, int $limit_from = 0, string $sort = 'sales.sale_time', string $order = 'desc', bool $count_only = FALSE): ResultInterface { + $config = config('OSPOS')->settings; + // Pick up only non-suspended records $where = 'sales.sale_status = 0 AND '; - if(empty(config('OSPOS')->settings['date_or_time_format'])) + if(empty($config['date_or_time_format'])) { $where .= 'DATE(sales.sale_time) BETWEEN ' . $this->db->escape($filters['start_date']) . ' AND ' . $this->db->escape($filters['end_date']); } @@ -178,7 +198,7 @@ class Sale extends Model $builder = $this->db->table('sales_items AS sales_items'); // get_found_rows case - if($count_only == TRUE) //TODO: replace this with `if($count_only)` + if($count_only) { $builder->select('COUNT(DISTINCT sales.sale_id) AS count'); } @@ -219,7 +239,7 @@ class Sale extends Model if(!empty($search)) //TODO: this is duplicated code. We should think about refactoring out a method { - if($filters['is_valid_receipt'] != FALSE) + if($filters['is_valid_receipt']) { $pieces = explode(' ', $search); $builder->where('sales.sale_id', $pieces[1]); @@ -245,12 +265,12 @@ class Sale extends Model } //TODO: Avoid double negatives. This can be changed to `if($filters['only_invoices'])`... also below - if($filters['only_invoices'] != FALSE) + if($filters['only_invoices']) { $builder->where('sales.invoice_number IS NOT NULL'); } - if($filters['only_cash'] != FALSE) + if($filters['only_cash']) { $builder->groupStart(); $builder->like('payments.payment_type', lang('Sales.cash')); @@ -258,23 +278,23 @@ class Sale extends Model $builder->groupEnd(); } - if($filters['only_creditcard'] != FALSE) + if($filters['only_creditcard']) { $builder->like('payments.payment_type', lang('Sales.credit')); } - if($filters['only_due'] != FALSE) + if($filters['only_due']) { $builder->like('payments.payment_type', lang('Sales.due')); } - if($filters['only_check'] != FALSE) + if($filters['only_check']) { $builder->like('payments.payment_type', lang('Sales.check')); } //get_found_rows - if($count_only == TRUE) //TODO: replace this with `if($count_only)` + if($count_only) { return $builder->get()->getRow()->count; } @@ -297,6 +317,8 @@ class Sale extends Model */ public function get_payments_summary(string $search, array $filters): array { + $config = config('OSPOS')->settings; + // get payment summary $builder = $this->db->table('sales AS sales'); $builder->select('payment_type, COUNT(payment_amount) AS count, SUM(payment_amount - cash_refund) AS payment_amount'); @@ -305,7 +327,7 @@ class Sale extends Model $builder->join('customers AS customer', 'sales.customer_id = customer.person_id', 'LEFT'); //TODO: This needs to be replaced with Ternary notation - if(empty(config('OSPOS')->settings['date_or_time_format'])) //TODO: duplicated code. We should think about refactoring out a method. + if(empty($config['date_or_time_format'])) //TODO: duplicated code. We should think about refactoring out a method. { $builder->where('DATE(sales.sale_time) BETWEEN ' . $this->db->escape($filters['start_date']) . ' AND ' . $this->db->escape($filters['end_date'])); } @@ -316,7 +338,7 @@ class Sale extends Model if(!empty($search)) //TODO: duplicated code. We should think about refactoring out a method. { - if($filters['is_valid_receipt'] != FALSE)//TODO: Avoid double negatives + if($filters['is_valid_receipt']) { $pieces = explode(' ',$search); $builder->where('sales.sale_id', $pieces[1]); @@ -351,27 +373,27 @@ class Sale extends Model } //TODO: Avoid the double negatives - if($filters['only_invoices'] != FALSE) + if($filters['only_invoices']) { $builder->where('invoice_number IS NOT NULL'); } - if($filters['only_cash'] != FALSE) + if($filters['only_cash']) { $builder->like('payment_type', lang('Sales.cash')); } - if($filters['only_due'] != FALSE) + if($filters['only_due']) { $builder->like('payment_type', lang('Sales.due')); } - if($filters['only_check'] != FALSE) + if($filters['only_check']) { $builder->like('payment_type', lang('Sales.check')); } - if($filters['only_creditcard'] != FALSE) + if($filters['only_creditcard']) { $builder->like('payment_type', lang('Sales.credit')); } @@ -386,7 +408,7 @@ class Sale extends Model foreach($payments as $key => $payment) { - if(strstr($payment['payment_type'], lang('Sales.giftcard')) != FALSE) + if(strstr($payment['payment_type'], lang('Sales.giftcard'))) { $gift_card_count += $payment['count']; $gift_card_amount += $payment['payment_amount']; @@ -498,6 +520,8 @@ class Sale extends Model */ public function is_valid_receipt(string &$receipt_sale_id): bool //TODO: like the others, maybe this should be an array rather than a delimited string... either that or the parameter name needs to be changed. $receipt_sale_id implies that it's an int. { + $config = config('OSPOS')->settings; + if(!empty($receipt_sale_id)) { //POS # @@ -507,7 +531,7 @@ class Sale extends Model { return $this->exists($pieces[1]); } - elseif(config('OSPOS')->settings['invoice_enable']) + elseif($config['invoice_enable']) { $sale_info = $this->get_sale_by_invoice_number($receipt_sale_id); @@ -537,14 +561,14 @@ class Sale extends Model /** * Update sale */ - public function update($sale_id = NULL, array $sale_data = NULL, array $payments = NULL): bool + public function update($sale_id = NULL, $sale_data = NULL): bool { $builder = $this->db->table('sales'); $builder->where('sale_id', $sale_id); $success = $builder->update($sale_data); //touch payment only if update sale is successful and there is a payments object otherwise the result would be to delete all the payments associated to the sale - if($success && !empty($payments)) + if($success && !empty($sale_data['payments'])) { //Run these queries as a transaction, we want to make sure we do all or nothing $this->db->transStart(); @@ -552,7 +576,7 @@ class Sale extends Model $builder = $this->db->table('sales_payments'); // add new payments - foreach($payments as $payment) + foreach($sale_data['payments'] as $payment) { $payment_id = $payment['payment_id']; $payment_type = $payment['payment_type']; @@ -612,6 +636,7 @@ class Sale extends Model public function save_value(int $sale_id, string &$sale_status, array &$items, int $customer_id, int $employee_id, string $comment, string $invoice_number, string $work_order_number, string $quote_number, int $sale_type, array $payments, int $dinner_table_id, array &$sales_taxes): int //TODO: this method returns the sale_id but the override is expecting it to return a bool. The signature needs to be reworked. Generally when there are more than 3 maybe 4 parameters, there's a good chance that an object needs to be passed rather than so many params. { + $config = config('OSPOS')->settings; $attribute = model(Attribute::class); $customer = model(Customer::class); $giftcard = model(Giftcard::class); @@ -769,7 +794,7 @@ class Sale extends Model $this->save_sales_items_taxes($sale_id, $sales_taxes[1]); } - if(config('OSPOS')->settings['dinner_table_enable']) + if($config['dinner_table_enable']) { $dinner_table = model(Dinner_table::class); if($sale_status == COMPLETED) //TODO: === ? @@ -966,7 +991,9 @@ class Sale extends Model */ public function get_sale_items_ordered(int $sale_id): ResultInterface { + $config = config('OSPOS')->settings; $item = model(Item::class); + $builder = $this->db->table('sales_items AS sales_items'); $builder->select(' sales_items.sale_id, @@ -989,12 +1016,12 @@ class Sale extends Model $builder->where('sales_items.sale_id', $sale_id); // Entry sequence (this will render kits in the expected sequence) - if(config('OSPOS')->settings['line_sequence'] == '0') //TODO: Replace these with constants and this should be converted to a switch. + if($config['line_sequence'] == '0') //TODO: Replace these with constants and this should be converted to a switch. { $builder->orderBy('line', 'asc'); } // Group by Stock Type (nonstock first - type 1, stock next - type 0) - elseif(config('OSPOS')->settings['line_sequence'] == '1') + elseif($config['line_sequence'] == '1') { $builder->orderBy('stock_type', 'desc'); $builder->orderBy('sales_items.description', 'asc'); @@ -1002,7 +1029,7 @@ class Sale extends Model $builder->orderBy('items.qty_per_pack', 'asc'); } // Group by Item Category - elseif(config('OSPOS')->settings['line_sequence'] == '2') + elseif($config['line_sequence'] == '2') { $builder->orderBy('category', 'asc'); $builder->orderBy('sales_items.description', 'asc'); @@ -1032,16 +1059,16 @@ class Sale extends Model /** * Gets sale payment options */ - public function get_payment_options(bool $giftcard = TRUE, bool $reward_points = FALSE): array + public function get_payment_options(bool $giftcard = true, bool $reward_points = true): array { $payments = get_payment_options(); - if($giftcard == TRUE) + if($giftcard) { $payments[lang('Sales.giftcard')] = lang('Sales.giftcard'); } - if($reward_points == TRUE) + if($reward_points) { $payments[lang('Sales.rewards')] = lang('Sales.rewards'); } @@ -1104,7 +1131,7 @@ class Sale extends Model { $builder = $this->db->table('sales'); $builder->where('invoice_number', $invoice_number); - + if(!empty($sale_id)) { $builder->where('sale_id !=', $sale_id); @@ -1152,9 +1179,11 @@ class Sale extends Model */ public function create_temp_table(array $inputs): void { + $config = config('OSPOS')->settings; + if(empty($inputs['sale_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 { $where = 'DATE(sales.sale_time) BETWEEN ' . $this->db->escape($inputs['start_date']) . ' AND ' . $this->db->escape($inputs['end_date']); } @@ -1182,7 +1211,7 @@ class Sale extends Model $cash_adjustment = 'IFNULL(SUM(payments.sale_cash_adjustment), 0)'; - if(config('OSPOS')->settings['tax_included']) + if($config['tax_included']) { $sale_total = "ROUND(SUM($sale_price), $decimals) + $cash_adjustment"; $sale_subtotal = "$sale_total - $internal_tax"; @@ -1211,7 +1240,7 @@ class Sale extends Model WHERE ' . $where . ' GROUP BY sale_id, item_id, line )'; - + $this->db->query($sql); // create a temporary table to contain all the payment types and amount @@ -1229,7 +1258,7 @@ class Sale extends Model WHERE ' . $where . ' GROUP BY payments.sale_id )'; - + $this->db->query($sql); $item = model(Item::class); $sql = 'CREATE TEMPORARY TABLE IF NOT EXISTS ' . $this->db->prefixTable('sales_items_temp') . @@ -1296,7 +1325,7 @@ class Sale extends Model WHERE ' . $where . ' GROUP BY sale_id, item_id, line )'; - + $this->db->query($sql); } @@ -1360,7 +1389,7 @@ class Sale extends Model public function update_sale_status(int $sale_id, int $sale_status): void { $builder = $this->db->table('sales'); - + $builder->where('sale_id', $sale_id); $builder->update(['sale_status' => $sale_status]); } @@ -1439,8 +1468,9 @@ class Sale extends Model { //Run these queries as a transaction, we want to make sure we do all or nothing $this->db->transStart(); + $config = config('OSPOS')->settings; - if(config('OSPOS')->settings['dinner_table_enable']) + if($config['dinner_table_enable']) { $dinner_table = model(Dinner_table::class); $dinner_table_id = $this->get_dinner_table($sale_id); @@ -1461,8 +1491,9 @@ class Sale extends Model public function clear_suspended_sale_detail(int $sale_id): bool { $this->db->transStart(); + $config = config('OSPOS')->settings; - if(config('OSPOS')->settings['dinner_table_enable']) + if($config['dinner_table_enable']) { $dinner_table = model(Dinner_table::class); $dinner_table_id = $this->get_dinner_table($sale_id); @@ -1507,7 +1538,9 @@ class Sale extends Model */ private function save_customer_rewards(int $customer_id, int $sale_id, float $total_amount, float $total_amount_used): void { - if(!empty($customer_id) && config('OSPOS')->settings['customer_reward_enable']) + $config = config('OSPOS')->settings; + + if(!empty($customer_id) && $config['customer_reward_enable']) { $customer = model(Customer::class); $customer_rewards = model(Customer_rewards::class); diff --git a/app/Models/Stock_location.php b/app/Models/Stock_location.php index 431bdf98e..67d3c7ce7 100644 --- a/app/Models/Stock_location.php +++ b/app/Models/Stock_location.php @@ -16,6 +16,15 @@ use CodeIgniter\Session\Session; */ class Stock_location extends Model { + protected $table = 'stock_locations'; + protected $primaryKey = 'location_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'location_name', + 'deleted' + ]; + public function __construct() { parent::__construct(); @@ -207,7 +216,7 @@ class Stock_location extends Model * @param bool $purge * @return bool */ - public function delete(int $location_id = null, bool $purge = FALSE): bool + public function delete($location_id = null, bool $purge = FALSE): bool { $this->db->transStart(); @@ -222,4 +231,4 @@ class Stock_location extends Model return $this->db->transStatus(); } -} \ No newline at end of file +} diff --git a/app/Models/Supplier.php b/app/Models/Supplier.php index 41e218382..01644cba6 100644 --- a/app/Models/Supplier.php +++ b/app/Models/Supplier.php @@ -9,15 +9,28 @@ use CodeIgniter\Database\ResultInterface; */ class Supplier extends Person { + protected $table = 'suppliers'; + protected $primaryKey = 'person_id'; + protected $useAutoIncrement = false; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'company_name', + 'account_number', + 'tax_id', + 'deleted', + 'agency_name', + 'category' + ]; + /** * Determines if a given person_id is a customer */ public function exists(int $person_id): bool { - $builder = $this->db->table('suppliers'); + $builder = $this->db->table('suppliers'); $builder->join('people', 'people.person_id = suppliers.person_id'); $builder->where('suppliers.person_id', $person_id); - + return ($builder->get()->getNumRows() == 1); //TODO: === } @@ -31,7 +44,7 @@ class Supplier extends Person return $builder->countAllResults(); } - + /** * Returns all the suppliers */ @@ -50,17 +63,17 @@ class Supplier extends Person return $builder->get(); } - + /** * Gets information about a particular supplier */ public function get_info(int $person_id): object { - $builder = $this->db->table('suppliers'); + $builder = $this->db->table('suppliers'); $builder->join('people', 'people.person_id = suppliers.person_id'); $builder->where('suppliers.person_id', $person_id); $query = $builder->get(); - + if($query->getNumRows() == 1) //TODO: === { return $query->getRow(); @@ -69,18 +82,18 @@ class Supplier extends Person { //Get empty base parent object, as $supplier_id is NOT a supplier $person_obj = parent::get_info(-1); //TODO: need to replace with a constant instead of -1 - - //Get all the fields from supplier table + + //Get all the fields from supplier table //append those fields to base parent object, we have a complete empty object foreach($this->db->getFieldNames('suppliers') as $field) { $person_obj->$field = ''; } - + return $person_obj; } } - + /** * Gets information about multiple suppliers */ @@ -93,7 +106,7 @@ class Supplier extends Person return $builder->get(); } - + /** * Inserts or updates a suppliers */ @@ -103,7 +116,7 @@ class Supplier extends Person //Run these queries as a transaction, we want to make sure we do all or nothing $this->db->transStart(); - + if(parent::save_value($person_data,$supplier_id)) { $builder = $this->db->table('suppliers'); @@ -118,25 +131,25 @@ class Supplier extends Person $success = $builder->update($supplier_data); } } - + $this->db->transComplete(); - + $success &= $this->db->transStatus(); return $success; } - + /** * Deletes one supplier */ - public function delete(int $supplier_id = null, bool $purge = false): bool + public function delete($supplier_id = null, bool $purge = false): bool { $builder = $this->db->table('suppliers'); $builder->where('person_id', $supplier_id); return $builder->update(['deleted' => 1]); } - + /** * Deletes a list of suppliers */ @@ -147,7 +160,7 @@ class Supplier extends Person return $builder->update(['deleted' => 1]); } - + /** * Get search suggestions to find suppliers */ @@ -183,7 +196,7 @@ class Supplier extends Person $builder->join('people', 'suppliers.person_id = people.person_id'); $builder->groupStart(); $builder->like('first_name', $search); - $builder->orLike('last_name', $search); + $builder->orLike('last_name', $search); $builder->orLike('CONCAT(first_name, " ", last_name)', $search); $builder->groupEnd(); $builder->where('deleted', 0); @@ -246,7 +259,7 @@ class Supplier extends Person { return $this->search($search, 0, 0, 'last_name', 'asc', TRUE); } - + /** * Perform a search on suppliers */ @@ -255,7 +268,7 @@ class Supplier extends Person $builder = $this->db->table('suppliers AS suppliers'); //get_found_rows case - if($count_only == TRUE) //TODO: This needs to be replaced with `if($count_only)` + if($count_only) { $builder->select('COUNT(suppliers.person_id) as count'); } @@ -272,8 +285,8 @@ class Supplier extends Person $builder->orLike('CONCAT(first_name, " ", last_name)', $search); //TODO: According to PHPStorm, this line down to the return is repeated in Customer.php and Employee.php... perhaps refactoring a method in a library could be helpful? $builder->groupEnd(); $builder->where('deleted', 0); - - if($count_only == TRUE) //TODO: This needs to be replaced with `if($count_only)` + + if($count_only) { return $builder->get()->getRow()->count; } @@ -308,4 +321,4 @@ class Supplier extends Person { return lang("Suppliers.$supplier_type"); } -} \ No newline at end of file +} diff --git a/app/Models/Tax.php b/app/Models/Tax.php index bbb2af4ef..b727b7552 100644 --- a/app/Models/Tax.php +++ b/app/Models/Tax.php @@ -11,6 +11,18 @@ use stdClass; */ class Tax extends Model { + protected $table = 'tax_rates'; + protected $primaryKey = 'tax_rate_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'rate_tax_code_id', + 'rate_tax_category_id', + 'rate_jurisdiction_id', + 'tax_rate', + 'tax_rounding_code' + ]; + /** * Determines if a given row is on file */ @@ -179,7 +191,7 @@ class Tax extends Model /** * Deletes a single tax rate entry */ - public function delete(int $tax_rate_id = null, bool $purge = false): bool + public function delete($tax_rate_id = null, bool $purge = false) { $builder = $this->db->table('tax_rates'); @@ -213,7 +225,7 @@ class Tax extends Model $builder = $this->db->table('tax_rates'); // get_found_rows case - if($count_only == TRUE) + if($count_only) { $builder->select('COUNT(tax_rate_id) as count'); } else @@ -241,7 +253,7 @@ class Tax extends Model } // get_found_rows case - if($count_only == TRUE) + if($count_only) { return $builder->get()->getRow()->count; } @@ -292,4 +304,4 @@ class Tax extends Model return $builder->get()->getRow()->tax_category_id; } -} \ No newline at end of file +} diff --git a/app/Models/Tax_category.php b/app/Models/Tax_category.php index a6b3cf383..4139fab49 100644 --- a/app/Models/Tax_category.php +++ b/app/Models/Tax_category.php @@ -12,6 +12,16 @@ use stdClass; class Tax_category extends Model { + protected $table = 'tax_categories'; + protected $primaryKey = 'tax_category_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'tax_category', + 'tax_group_sequence', + 'deleted' + ]; + /** * Determines if it exists in the table */ @@ -68,7 +78,7 @@ class Tax_category extends Model public function get_all(int $rows = 0, int $limit_from = 0, bool $no_deleted = TRUE): ResultInterface //TODO: $no_deleted needs a new name. $not_deleted is the correct grammar, but it's a bit confusing by naming the variable a negative. Probably better to name it is_deleted and flip the logic { $builder = $this->db->table('tax_categories'); - if($no_deleted == TRUE) + if($no_deleted) { $builder->where('deleted', 0); } @@ -203,7 +213,7 @@ class Tax_category extends Model $builder = $this->db->table('tax_categories AS tax_categories'); // get_found_rows case - if($count_only == TRUE) //TODO: This should probably be === since $count_only is a bool + if($count_only) { $builder->select('COUNT(tax_categories.tax_category_id) as count'); } @@ -212,7 +222,7 @@ class Tax_category extends Model $builder->where('deleted', 0); // get_found_rows case - if($count_only == TRUE) //TODO: This should probably be === since $count_only is a bool + if($count_only) { return $builder->get()->getRow()->count; } @@ -260,4 +270,4 @@ class Tax_category extends Model ] ]; } -} \ No newline at end of file +} diff --git a/app/Models/Tax_code.php b/app/Models/Tax_code.php index 6ce9717cf..e026951b3 100644 --- a/app/Models/Tax_code.php +++ b/app/Models/Tax_code.php @@ -11,6 +11,18 @@ use stdClass; */ class Tax_code extends Model { + protected $table = 'tax_codes'; + protected $primaryKey = 'tax_code_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'tax_code', + 'tax_code_name', + 'city', + 'state', + 'deleted' + ]; + /** * Determines if it exists in the table */ @@ -65,10 +77,10 @@ class Tax_code extends Model /** * Returns all rows from the table */ - public function get_all(int $rows = 0, int $limit_from = 0, bool $no_deleted = TRUE): ResultInterface //TODO: $no_deleted should be something like $is_deleted and flip the logic. + public function get_all(int $rows = 0, int $limit_from = 0, bool $no_deleted = true): ResultInterface //TODO: $no_deleted should be something like $is_deleted and flip the logic. { $builder = $this->db->table('tax_codes'); - if($no_deleted == TRUE) + if($no_deleted) { $builder->where('deleted', 0); } @@ -157,7 +169,7 @@ class Tax_code extends Model /** * Deletes a specific tax code */ - public function delete(string $tax_code = null, bool $purge = false): bool + public function delete($tax_code = null, bool $purge = false) { $builder = $this->db->table('tax_codes'); $builder->where('tax_code', $tax_code); @@ -192,7 +204,7 @@ class Tax_code extends Model $builder = $this->db->table('tax_codes AS tax_codes'); // get_found_rows case - if($count_only == TRUE) + if($count_only) { $builder->select('COUNT(tax_codes.tax_code) as count'); } @@ -204,7 +216,7 @@ class Tax_code extends Model $builder->where('deleted', 0); // get_found_rows case - if($count_only == TRUE) + if($count_only) { return $builder->get()->getRow()->count; } @@ -224,6 +236,8 @@ class Tax_code extends Model */ public function get_sales_tax_code(string $city = '', string $state = '') { + $config = config('OSPOS')->settings; + // if tax code using both city and state cannot be found then try again using just the state // if the state tax code cannot be found then try again using blanks for both $builder = $this->db->table('tax_codes'); @@ -252,7 +266,7 @@ class Tax_code extends Model } else { - return config('OSPOS')->settings['default_tax_code']; + return $config['default_tax_code']; } } @@ -298,4 +312,4 @@ class Tax_code extends Model ] ]; } -} \ No newline at end of file +} diff --git a/app/Models/Tax_jurisdiction.php b/app/Models/Tax_jurisdiction.php index 8d46f0e34..d5b7beb1c 100644 --- a/app/Models/Tax_jurisdiction.php +++ b/app/Models/Tax_jurisdiction.php @@ -12,6 +12,20 @@ use stdClass; class Tax_jurisdiction extends Model { + protected $table = 'tax_jurisdictions'; + protected $primaryKey = 'cashup_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; + protected $allowedFields = [ + 'jurisdiction_name', + 'tax_group', + 'tax_type', + 'reporting_authority', + 'tax_group_sequence', + 'cascade_sequence', + 'deleted' + ]; + /** * Determines if it exists in the table */ @@ -69,7 +83,7 @@ class Tax_jurisdiction extends Model { $builder = $this->db->table('tax_jurisdictions'); - if($no_deleted == TRUE) + if($no_deleted) { $builder->where('deleted', 0); } @@ -169,7 +183,7 @@ class Tax_jurisdiction extends Model /** * Soft deletes a specific tax jurisdiction */ - public function delete(int $jurisdiction_id = null, bool $purge = false): bool + public function delete($jurisdiction_id = null, bool $purge = false) { $builder = $this->db->table('tax_jurisdictions'); $builder->where('jurisdiction_id', $jurisdiction_id); @@ -204,7 +218,7 @@ class Tax_jurisdiction extends Model $builder = $this->db->table('tax_jurisdictions AS tax_jurisdictions'); // get_found_rows case - if($count_only == TRUE) //TODO: Replace this with just count_only: `if($count_only)` + if($count_only) { $builder->select('COUNT(tax_jurisdictions.jurisdiction_id) as count'); } @@ -216,7 +230,7 @@ class Tax_jurisdiction extends Model $builder->where('deleted', 0); // get_found_rows case - if($count_only == TRUE) //TODO: === + if($count_only) { return $builder->get()->getRow()->count; } @@ -246,4 +260,4 @@ class Tax_jurisdiction extends Model ] ]; } -} \ No newline at end of file +} diff --git a/app/Models/Tokens/Token.php b/app/Models/Tokens/Token.php index b96d1a9d6..e9aa13a80 100644 --- a/app/Models/Tokens/Token.php +++ b/app/Models/Tokens/Token.php @@ -9,7 +9,7 @@ use CodeIgniter\Model; */ abstract class Token Extends Model { - protected $value = ''; + protected string $value = ''; public function __construct(string $value = '') { @@ -60,4 +60,4 @@ abstract class Token Extends Model return $text; } -} \ No newline at end of file +} diff --git a/app/Models/Tokens/Token_customer.php b/app/Models/Tokens/Token_customer.php index 380d80d7c..2475e2b05 100644 --- a/app/Models/Tokens/Token_customer.php +++ b/app/Models/Tokens/Token_customer.php @@ -16,7 +16,7 @@ use App\Models\Customer; */ class Token_customer extends Token { - private $customer_info; + private string $customer_info; public function __construct(string $customer_info = '') { @@ -47,4 +47,4 @@ class Token_customer extends Token return ''; } -} \ No newline at end of file +} diff --git a/app/Views/attributes/item.php b/app/Views/attributes/item.php index 9e113ba7b..d327724a9 100644 --- a/app/Views/attributes/item.php +++ b/app/Views/attributes/item.php @@ -85,7 +85,7 @@ foreach($definition_values as $definition_id => $definition_value) \ No newline at end of file + diff --git a/app/Views/attributes/manage.php b/app/Views/attributes/manage.php index a03deece8..d694f97d4 100644 --- a/app/Views/attributes/manage.php +++ b/app/Views/attributes/manage.php @@ -15,7 +15,7 @@ table_support.init({ resource: '', headers: , - pageSize: settings['lines_per_page'] ?>, + pageSize: , uniqueId: 'definition_id' }); }); diff --git a/app/Views/cashups/form.php b/app/Views/cashups/form.php index aab5703f3..4629b3f0f 100644 --- a/app/Views/cashups/form.php +++ b/app/Views/cashups/form.php @@ -43,7 +43,7 @@
- settings['currency_symbol']) ?> + 'open_amount_cash', @@ -52,7 +52,7 @@ 'value' => to_currency_no_money($cash_ups_info->open_amount_cash) ]) ?> - settings['currency_symbol']) ?> +
@@ -63,7 +63,7 @@
- settings['currency_symbol']) ?> + 'transfer_amount_cash', @@ -73,7 +73,7 @@ ]) ?> - settings['currency_symbol']) ?> +
@@ -106,7 +106,7 @@
- settings['currency_symbol']) ?> + 'closed_amount_cash', @@ -115,7 +115,7 @@ 'value'=>to_currency_no_money($cash_ups_info->closed_amount_cash)] ) ?> - settings['currency_symbol']) ?> +
@@ -138,7 +138,7 @@
- settings['currency_symbol']) ?> + 'closed_amount_due', @@ -147,7 +147,7 @@ 'value'=>to_currency_no_money($cash_ups_info->closed_amount_due)] ) ?> - settings['currency_symbol']) ?> +
@@ -158,7 +158,7 @@
- settings['currency_symbol']) ?> + 'closed_amount_card', @@ -167,7 +167,7 @@ 'value'=>to_currency_no_money($cash_ups_info->closed_amount_card)] ) ?> - settings['currency_symbol']) ?> +
@@ -178,7 +178,7 @@
- settings['currency_symbol']) ?> + 'closed_amount_check', @@ -187,7 +187,7 @@ 'value'=>to_currency_no_money($cash_ups_info->closed_amount_check)] ) ?> - settings['currency_symbol']) ?> +
@@ -198,7 +198,7 @@
- settings['currency_symbol']) ?> + 'closed_amount_total', @@ -209,7 +209,7 @@ ] ) ?> - settings['currency_symbol']) ?> +
@@ -256,12 +256,12 @@ $(document).ready(function() $('#open_date').datetimepicker({ - format: "settings['dateformat']) . ' ' . dateformat_bootstrap(config('OSPOS')->settings['timeformat']) ?>", - startDate: "settings['dateformat'] . ' ' . esc(config('OSPOS')->settings['timeformat'], 'js'), mktime(0, 0, 0, 1, 1, 2010)) ?>", + format: "", + startDate: "", settings['timeformat']; + $t = $config['timeformat']; $m = $t[strlen($t)-1]; - if( strpos(config('OSPOS')->settings['timeformat'], 'a') !== false || strpos(config('OSPOS')->settings['timeformat'], 'A') !== false ) + if( strpos($config['timeformat'], 'a') !== false || strpos($config['timeformat'], 'A') !== false ) { ?> showMeridian: true, @@ -283,12 +283,12 @@ $(document).ready(function() }); $('#close_date').datetimepicker({ - format: "settings['dateformat']) . ' ' . dateformat_bootstrap(config('OSPOS')->settings['timeformat']) ?>", - startDate: "settings['dateformat'] . ' ' . esc(config('OSPOS')->settings['timeformat'], 'js'), mktime(0, 0, 0, 1, 1, 2010)) ?>", + format: "", + startDate: "", settings['timeformat']; + $t = $config['timeformat']; $m = $t[strlen($t)-1]; - if( strpos(config('OSPOS')->settings['timeformat'], 'a') !== false || strpos(config('OSPOS')->settings['timeformat'], 'A') !== false ) + if( strpos($config['timeformat'], 'a') !== false || strpos($config['timeformat'], 'A') !== false ) { ?> showMeridian: true, diff --git a/app/Views/cashups/manage.php b/app/Views/cashups/manage.php index 513f0f728..998d1dead 100644 --- a/app/Views/cashups/manage.php +++ b/app/Views/cashups/manage.php @@ -27,7 +27,7 @@ $(document).ready(function() table_support.init({ resource: '', headers: , - pageSize: settings['lines_per_page'] ?>, + pageSize: , uniqueId: 'cashup_id', queryParams: function() { return $.extend(arguments[0], { diff --git a/app/Views/configs/barcode_config.php b/app/Views/configs/barcode_config.php index 00f3be399..a8f41bab4 100644 --- a/app/Views/configs/barcode_config.php +++ b/app/Views/configs/barcode_config.php @@ -12,7 +12,7 @@
'control-label col-xs-2']) ?>
- settings['barcode_type'], 'attr'), ['class' => 'form-control input-sm']) ?> + 'form-control input-sm']) ?>
@@ -27,7 +27,7 @@ 'name' => 'barcode_width', 'id' => 'barcode_width', 'class' => 'form-control input-sm required', - 'value' => config('OSPOS')->settings['barcode_width'] + 'value' => $config['barcode_width'] ]) ?> @@ -42,7 +42,7 @@ 'name' => 'barcode_height', 'id' => 'barcode_height', 'class' => 'form-control input-sm required', - 'value'=>config('OSPOS')->settings['barcode_height'] + 'value'=>$config['barcode_height'] ]) ?> @@ -53,7 +53,7 @@ barcode_lib->listfonts('fonts'), 'attr'), - esc(config('OSPOS')->settings['barcode_font'], 'attr'), + esc($config['barcode_font'], 'attr'), ['class' => 'form-control input-sm required'] ) ?> @@ -65,7 +65,7 @@ 'name' => 'barcode_font_size', 'id' => 'barcode_font_size', 'class' => 'form-control input-sm required', - 'value' => config('OSPOS')->settings['barcode_font_size'] + 'value' => $config['barcode_font_size'] ]) ?> @@ -77,7 +77,7 @@ 'name' => 'allow_duplicate_barcodes', 'id' => 'allow_duplicate_barcodes', 'value' => 'allow_duplicate_barcodes', - 'checked' => config('OSPOS')->settings['allow_duplicate_barcodes'] + 'checked' => $config['allow_duplicate_barcodes'] ]) ?>   @@ -101,7 +101,7 @@ 'barcode_content', 'value' => 'number', - 'checked' => config('OSPOS')->settings['barcode_content'] === 'number']) ?> + 'checked' => $config['barcode_content'] === 'number']) ?>   @@ -110,7 +110,7 @@ 'barcode_generate_if_empty', 'value' => 'barcode_generate_if_empty', - 'checked' => config('OSPOS')->settings['barcode_generate_if_empty'] + 'checked' => $config['barcode_generate_if_empty'] ]) ?> @@ -121,7 +121,7 @@ 'control-label col-xs-2']) ?>
settings['barcode_formats']); + $barcode_formats = json_decode($config['barcode_formats']); echo form_dropdown ([ 'name' => 'barcode_formats[]', 'id' => 'barcode_formats', @@ -146,7 +146,7 @@ 'unit_price' => lang('Items.unit_price'), 'company_name' => lang('Suppliers.company_name') ], - config('OSPOS')->settings['barcode_first_row'], ['class' => 'form-control input-sm']); + $config['barcode_first_row'], ['class' => 'form-control input-sm']); ?>
@@ -160,7 +160,7 @@ 'item_code' => lang('Items.item_number'), 'company_name' => lang('Suppliers.company_name') ], - config('OSPOS')->settings['barcode_second_row'], ['class' => 'form-control input-sm']) ?> + $config['barcode_second_row'], ['class' => 'form-control input-sm']) ?>
@@ -173,7 +173,7 @@ 'item_code' => lang('Items.item_number'), 'company_name' => lang('Suppliers.company_name') ], - config('OSPOS')->settings['barcode_third_row'], ['class' => 'form-control input-sm']) ?> + $config['barcode_third_row'], ['class' => 'form-control input-sm']) ?>
@@ -186,7 +186,7 @@ 'name' => 'barcode_num_in_row', 'id' => 'barcode_num_in_row', 'class' => 'form-control input-sm required', - 'value' => config('OSPOS')->settings['barcode_num_in_row'] + 'value' => $config['barcode_num_in_row'] ]) ?> @@ -199,7 +199,7 @@ 'name' => 'barcode_page_width', 'id' => 'barcode_page_width', 'class' => 'form-control input-sm required', - 'value' => config('OSPOS')->settings['barcode_page_width'] + 'value' => $config['barcode_page_width'] ]) ?> % @@ -214,7 +214,7 @@ 'name' => 'barcode_page_cellspacing', 'id' => 'barcode_page_cellspacing', 'class' => 'form-control input-sm required', - 'value' => config('OSPOS')->settings['barcode_page_cellspacing'] + 'value' => $config['barcode_page_cellspacing'] ]) ?> px diff --git a/app/Views/configs/email_config.php b/app/Views/configs/email_config.php index 5d89e5be3..1b90dd51d 100644 --- a/app/Views/configs/email_config.php +++ b/app/Views/configs/email_config.php @@ -13,7 +13,7 @@ 'sendmail' => 'sendmail', 'smtp' => 'smtp' ], - esc(config('OSPOS')->settings['protocol'], 'attr'), + esc($config['protocol'], 'attr'), ['class' => 'form-control input-sm', 'id' => 'protocol']) ?> @@ -26,7 +26,7 @@ 'name' => 'mailpath', 'id' => 'mailpath', 'class' => 'form-control input-sm', - 'value' => esc(config('OSPOS')->settings['mailpath'], 'attr') + 'value' => esc($config['mailpath'], 'attr') ]) ?> @@ -38,7 +38,7 @@ 'name' => 'smtp_host', 'id' => 'smtp_host', 'class' => 'form-control input-sm', - 'value' => esc(config('OSPOS')->settings['smtp_host'], 'attr') + 'value' => esc($config['smtp_host'], 'attr') ]) ?> @@ -50,7 +50,7 @@ 'name' => 'smtp_port', 'id' => 'smtp_port', 'class' => 'form-control input-sm', - 'value' => config('OSPOS')->settings['smtp_port'] + 'value' => $config['smtp_port'] ]) ?> @@ -63,7 +63,7 @@ 'tls' => 'TLS', 'ssl' => 'SSL' ], - esc(config('OSPOS')->settings['smtp_crypto'], 'attr'), + esc($config['smtp_crypto'], 'attr'), ['class' => 'form-control input-sm', 'id' => 'smtp_crypto']) ?> @@ -76,7 +76,7 @@ 'name' => 'smtp_timeout', 'id' => 'smtp_timeout', 'class' => 'form-control input-sm', - 'value' => config('OSPOS')->settings['smtp_timeout'] + 'value' => $config['smtp_timeout'] ]) ?> @@ -90,7 +90,7 @@ 'name' => 'smtp_user', 'id' => 'smtp_user', 'class' => 'form-control input-sm', - 'value' => esc(config('OSPOS')->settings['smtp_user'], 'attr') + 'value' => esc($config['smtp_user'], 'attr') ]) ?> @@ -105,7 +105,7 @@ 'name' => 'smtp_pass', 'id' => 'smtp_pass', 'class' => 'form-control input-sm', - 'value' => esc(config('OSPOS')->settings['smtp_pass'], 'attr') + 'value' => esc($config['smtp_pass'], 'attr') ]) ?> diff --git a/app/Views/configs/general_config.php b/app/Views/configs/general_config.php index 8480bf9de..9a5e4dca0 100644 --- a/app/Views/configs/general_config.php +++ b/app/Views/configs/general_config.php @@ -18,11 +18,11 @@
- settings['theme'], 'attr'), ['class' => 'form-control input-sm', 'id' => 'theme-change']) ?> + 'form-control input-sm', 'id' => 'theme-change']) ?>
@@ -38,7 +38,7 @@ 'floating_labels' => lang('Config.floating_labels'), 'input_groups' => lang('Config.input_groups') ], - esc(config('OSPOS')->settings['login_form'], 'attr'), + esc($config['login_form'], 'attr'), ['class' => 'form-control input-sm'] ) ?>
@@ -55,7 +55,7 @@ 'type' => 'number', 'min' => 0, 'max' => 100, - 'value' => config('OSPOS')->settings['default_sales_discount'] + 'value' => $config['default_sales_discount'] ]) ?> 'toggle', 'data-size' => 'normal', 'data-onstyle' => 'success', - 'data-on' => '' . esc(config('OSPOS')->settings['currency_symbol'], 'attr').'', + 'data-on' => '' . esc($config['currency_symbol'], 'attr').'', 'data-off' => '%', - 'checked' => config('OSPOS')->settings['default_sales_discount_type'] + 'checked' => $config['default_sales_discount_type'] ]) ?> @@ -85,7 +85,7 @@ 'type' => 'number', 'min' => 0, 'max' => 100, - 'value' => config('OSPOS')->settings['default_receivings_discount'] + 'value' => $config['default_receivings_discount'] ]) ?> 'toggle', 'data-size' => 'normal', 'data-onstyle' => 'success', - 'data-on' => '' . esc(config('OSPOS')->settings['currency_symbol'], 'attr') . '', + 'data-on' => '' . esc($config['currency_symbol'], 'attr') . '', 'data-off' => '%', - 'checked' => config('OSPOS')->settings['default_receivings_discount_type'] + 'checked' => $config['default_receivings_discount_type'] ]) ?> @@ -111,7 +111,7 @@ 'name' => 'enforce_privacy', 'id' => 'enforce_privacy', 'value' => 'enforce_privacy', - 'checked' => config('OSPOS')->settings['enforce_privacy'] + 'checked' => $config['enforce_privacy'] ]) ?>   @@ -77,7 +77,7 @@ 'email_receipt_check_behaviour', 'value' => 'last', - 'checked' => config('OSPOS')->settings['email_receipt_check_behaviour'] == 'last' + 'checked' => $config['email_receipt_check_behaviour'] == 'last' ]) ?> @@ -91,7 +91,7 @@ 'print_receipt_check_behaviour', 'value' => 'always', - 'checked' => config('OSPOS')->settings['print_receipt_check_behaviour'] == 'always' + 'checked' => $config['print_receipt_check_behaviour'] == 'always' ]) ?> @@ -99,7 +99,7 @@ 'print_receipt_check_behaviour', 'value' => 'never', - 'checked' => config('OSPOS')->settings['print_receipt_check_behaviour'] == 'never' + 'checked' => $config['print_receipt_check_behaviour'] == 'never' ]) ?> @@ -107,7 +107,7 @@ 'print_receipt_check_behaviour', 'value' => 'last', - 'checked' => config('OSPOS')->settings['print_receipt_check_behaviour'] == 'last' + 'checked' => $config['print_receipt_check_behaviour'] == 'last' ]) ?> @@ -121,7 +121,7 @@ 'name' => 'receipt_show_company_name', 'value' => 'receipt_show_company_name', 'id' => 'receipt_show_company_name', - 'checked' => config('OSPOS')->settings['receipt_show_company_name'] + 'checked' => $config['receipt_show_company_name'] ]) ?> @@ -133,7 +133,7 @@ 'name' => 'receipt_show_taxes', 'value' => 'receipt_show_taxes', 'id' => 'receipt_show_taxes', - 'checked' => config('OSPOS')->settings['receipt_show_taxes'] + 'checked' => $config['receipt_show_taxes'] ]) ?> @@ -145,7 +145,7 @@ 'name' => 'receipt_show_tax_ind', 'value' => 'receipt_show_tax_ind', 'id' => 'receipt_show_tax_ind', - 'checked' => config('OSPOS')->settings['receipt_show_tax_ind'] + 'checked' => $config['receipt_show_tax_ind'] ]) ?> @@ -157,7 +157,7 @@ 'name' => 'receipt_show_total_discount', 'value' => 'receipt_show_total_discount', 'id' => 'receipt_show_total_discount', - 'checked' => config('OSPOS')->settings['receipt_show_total_discount'] + 'checked' => $config['receipt_show_total_discount'] ]) ?> @@ -169,7 +169,7 @@ 'name' => 'receipt_show_description', 'value' => 'receipt_show_description', 'id' => 'receipt_show_description', - 'checked' => config('OSPOS')->settings['receipt_show_description'] + 'checked' => $config['receipt_show_description'] ]) ?> @@ -181,7 +181,7 @@ 'name' => 'receipt_show_serialnumber', 'value' => 'receipt_show_serialnumber', 'id' => 'receipt_show_serialnumber', - 'checked' => config('OSPOS')->settings['receipt_show_serialnumber'] + 'checked' => $config['receipt_show_serialnumber'] ]) ?> @@ -193,7 +193,7 @@ 'name' => 'print_silently', 'id' => 'print_silently', 'value' => 'print_silently', - 'checked' => config('OSPOS')->settings['print_silently'] + 'checked' => $config['print_silently'] ]) ?> @@ -205,7 +205,7 @@ 'name' => 'print_header', 'id' => 'print_header', 'value' => 'print_header', - 'checked' => config('OSPOS')->settings['print_header'] + 'checked' => $config['print_header'] ]) ?> @@ -217,7 +217,7 @@ 'name' => 'print_footer', 'id' => 'print_footer', 'value' => 'print_footer', - 'checked' => config('OSPOS')->settings['print_footer'] + 'checked' => $config['print_footer'] ]) ?> @@ -254,7 +254,7 @@ 'name' => 'print_top_margin', 'id' => 'print_top_margin', 'class' => 'form-control input-sm required', - 'value' => config('OSPOS')->settings['print_top_margin'] + 'value' => $config['print_top_margin'] ]) ?> px @@ -272,7 +272,7 @@ 'name' => 'print_left_margin', 'id' => 'print_left_margin', 'class' => 'form-control input-sm required', - 'value' => config('OSPOS')->settings['print_left_margin'] + 'value' => $config['print_left_margin'] ]) ?> px @@ -290,7 +290,7 @@ 'name' => 'print_bottom_margin', 'id' => 'print_bottom_margin', 'class' => 'form-control input-sm required', - 'value' => config('OSPOS')->settings['print_bottom_margin'] + 'value' => $config['print_bottom_margin'] ]) ?> px @@ -308,7 +308,7 @@ 'name' => 'print_right_margin', 'id' => 'print_right_margin', 'class' => 'form-control input-sm required', - 'value' => config('OSPOS')->settings['print_right_margin'] + 'value' => $config['print_right_margin'] ]) ?> px diff --git a/app/Views/configs/reward_config.php b/app/Views/configs/reward_config.php index f5f9d64bb..a4478fb5e 100644 --- a/app/Views/configs/reward_config.php +++ b/app/Views/configs/reward_config.php @@ -16,7 +16,7 @@ 'name' => 'customer_reward_enable', 'value' => 'customer_reward_enable', 'id' => 'customer_reward_enable', - 'checked' => config('OSPOS')->settings['customer_reward_enable'] + 'checked' => $config['customer_reward_enable'] ]) ?> diff --git a/app/Views/configs/system_info.php b/app/Views/configs/system_info.php index b5d7fd4b2..c16268277 100644 --- a/app/Views/configs/system_info.php +++ b/app/Views/configs/system_info.php @@ -18,7 +18,7 @@

- settings['application_version']) ?> - settings['commit_sha1'], 0, 6)) ?>
+ application_version) ?> - commit_sha1, 0, 6)) ?>
Language Code:

Extensions & Modules:
@@ -53,9 +53,9 @@ .OS:

File Permissions:
» [writeable/logs:] -


-
+

@@ -205,6 +205,6 @@ }); if($('#timezone').html() !== $('#ostimezone').html()) - document.getElementById("TimeError").innerHTML = '


settings['timezone']) ?>

'; + document.getElementById("TimeError").innerHTML = '



'; diff --git a/app/Views/configs/table_config.php b/app/Views/configs/table_config.php index 77bbe1f34..21e81df98 100644 --- a/app/Views/configs/table_config.php +++ b/app/Views/configs/table_config.php @@ -16,7 +16,7 @@ 'name' => 'dinner_table_enable', 'value' => 'dinner_table_enable', 'id' => 'dinner_table_enable', - 'checked' => config('OSPOS')->settings['dinner_table_enable'] + 'checked' => $config['dinner_table_enable'] ]) ?> diff --git a/app/Views/configs/tax_config.php b/app/Views/configs/tax_config.php index 221b0f57c..9770bfd92 100644 --- a/app/Views/configs/tax_config.php +++ b/app/Views/configs/tax_config.php @@ -19,7 +19,7 @@ 'name' => 'tax_id', 'id' => 'tax_id', 'class' => 'form-control input-sm', - 'value' => esc(config('OSPOS')->settings['tax_id'], 'attr') + 'value' => esc($config['tax_id'], 'attr') ]) ?> @@ -31,7 +31,7 @@ 'name' => 'tax_included', 'id' => 'tax_included', 'value' => 'tax_included', - 'checked' => config('OSPOS')->settings['tax_included'] + 'checked' => $config['tax_included'] ]) ?> @@ -43,14 +43,14 @@ 'name' => 'default_tax_1_name', 'id' => 'default_tax_1_name', 'class' => 'form-control input-sm', - 'value' => config('OSPOS')->settings['default_tax_1_name'] !== FALSE ? esc(config('OSPOS')->settings['default_tax_1_name'], 'attr') : lang('Items.sales_tax_1')]) ?> + 'value' => $config['default_tax_1_name'] !== FALSE ? esc($config['default_tax_1_name'], 'attr') : lang('Items.sales_tax_1')]) ?>
'default_tax_1_rate', 'id' => 'default_tax_1_rate', 'class' => 'form-control input-sm', - 'value' => to_tax_decimals(config('OSPOS')->settings['default_tax_1_rate']) + 'value' => to_tax_decimals($config['default_tax_1_rate']) ]) ?> %
@@ -63,7 +63,7 @@ 'name' => 'default_tax_2_name', 'id' => 'default_tax_2_name', 'class' => 'form-control input-sm', - 'value' => config('OSPOS')->settings['default_tax_2_name'] !== FALSE ? esc(config('OSPOS')->settings['default_tax_2_name'], 'attr') : lang('Items.sales_tax_2') + 'value' => $config['default_tax_2_name'] !== FALSE ? esc($config['default_tax_2_name'], 'attr') : lang('Items.sales_tax_2') ]) ?>
@@ -71,7 +71,7 @@ 'name' => 'default_tax_2_rate', 'id' => 'default_tax_2_rate', 'class' => 'form-control input-sm', - 'value' => to_tax_decimals(config('OSPOS')->settings['default_tax_2_rate']) + 'value' => to_tax_decimals($config['default_tax_2_rate']) ]) ?> %
@@ -84,7 +84,7 @@ 'name' => 'use_destination_based_tax', 'id' => 'use_destination_based_tax', 'value' => 'use_destination_based_tax', - 'checked' => config('OSPOS')->settings['use_destination_based_tax'] + 'checked' => $config['use_destination_based_tax'] ]) ?> @@ -92,21 +92,21 @@
'control-label col-xs-2']) ?>
- settings['default_tax_code'], 'attr'), ['class' => 'form-control input-sm']) ?> + 'form-control input-sm']) ?>
'control-label col-xs-2']) ?>
- settings['default_tax_category'], 'attr'), ['class' => 'form-control input-sm']) ?> + 'form-control input-sm']) ?>
'control-label col-xs-2']) ?>
- settings['default_tax_jurisdiction'], 'attr'), ['class' => 'form-control input-sm']) ?> + 'form-control input-sm']) ?>
diff --git a/app/Views/customers/form.php b/app/Views/customers/form.php index a85d977ca..ddb69bb6c 100644 --- a/app/Views/customers/form.php +++ b/app/Views/customers/form.php @@ -46,7 +46,7 @@
'required control-label col-xs-3']) ?>
- consent == '' ? !config('OSPOS')->settings['enforce_privacy'] : (boolean)$person_info->consent) ?> + consent == '' ? !$config['enforce_privacy'] : (boolean)$person_info->consent) ?>
@@ -129,7 +129,7 @@ - settings['customer_reward_enable'] == TRUE): ?> +
'control-label col-xs-3']) ?>
@@ -225,7 +225,7 @@
- settings['currency_symbol']) ?> + 'total', @@ -235,7 +235,7 @@ 'disabled' => '' ]) ?> - settings['currency_symbol']) ?> +
@@ -246,7 +246,7 @@
- settings['currency_symbol']) ?> + 'max', @@ -256,7 +256,7 @@ 'disabled' => '' ]) ?> - settings['currency_symbol']) ?> +
@@ -267,7 +267,7 @@
- settings['currency_symbol']) ?> + 'min', @@ -277,7 +277,7 @@ 'disabled' => '' ]) ?> - settings['currency_symbol']) ?> +
@@ -288,7 +288,7 @@
- settings['currency_symbol']) ?> + 'average', @@ -298,7 +298,7 @@ 'disabled' => '' ]) ?> - settings['currency_symbol']) ?> +
diff --git a/app/Views/expenses/form.php b/app/Views/expenses/form.php index 9094c75fe..dd04d0b5a 100644 --- a/app/Views/expenses/form.php +++ b/app/Views/expenses/form.php @@ -73,7 +73,7 @@
- settings['currency_symbol']) ?> + 'amount', @@ -82,7 +82,7 @@ 'value' => to_currency_no_money($expenses_info->amount) ]) ?> - settings['currency_symbol']) ?> +
@@ -93,7 +93,7 @@
- settings['currency_symbol']) ?> + 'tax_amount', @@ -102,7 +102,7 @@ 'value' => to_currency_no_money($expenses_info->tax_amount) ]) ?> - settings['currency_symbol']) ?> +
diff --git a/app/Views/expenses/manage.php b/app/Views/expenses/manage.php index 0d482f634..e5cf62814 100644 --- a/app/Views/expenses/manage.php +++ b/app/Views/expenses/manage.php @@ -27,7 +27,7 @@ $(document).ready(function() table_support.init({ resource: '', headers: , - pageSize: settings['lines_per_page'] ?>, + pageSize: , uniqueId: 'expense_id', onLoadSuccess: function(response) { if($("#table tbody tr").length > 1) { diff --git a/app/Views/expenses_categories/manage.php b/app/Views/expenses_categories/manage.php index eaeb83714..766e5b11d 100644 --- a/app/Views/expenses_categories/manage.php +++ b/app/Views/expenses_categories/manage.php @@ -14,7 +14,7 @@ $(document).ready(function() table_support.init({ resource: '', headers: , - pageSize: settings['lines_per_page'] ?>, + pageSize: , uniqueId: 'expense_category_id', }); diff --git a/app/Views/giftcards/form.php b/app/Views/giftcards/form.php index 2ec465bd1..2f68c6c2d 100644 --- a/app/Views/giftcards/form.php +++ b/app/Views/giftcards/form.php @@ -29,7 +29,7 @@ settings['giftcard_number'] == 'series') + if($config['giftcard_number'] == 'series') { $class = ' required'; } @@ -51,7 +51,7 @@
- settings['currency_symbol']) ?> + 'giftcard_amount', @@ -60,7 +60,7 @@ 'value'=>to_currency_no_money($giftcard_value) ]) ?> - settings['currency_symbol']) ?> +
@@ -113,7 +113,7 @@ $(document).ready(function() rules: { settings['giftcard_number'] == 'series') + if($config['giftcard_number'] == 'series') { ?> giftcard_number: @@ -146,7 +146,7 @@ $(document).ready(function() messages: { settings['giftcard_number'] == 'series') + if($config['giftcard_number'] == 'series') { ?> giftcard_number: diff --git a/app/Views/giftcards/manage.php b/app/Views/giftcards/manage.php index 67df3599e..49cf291c1 100644 --- a/app/Views/giftcards/manage.php +++ b/app/Views/giftcards/manage.php @@ -12,7 +12,7 @@ $(document).ready(function() table_support.init({ resource: '', headers: , - pageSize: settings['lines_per_page'] ?>, + pageSize: , uniqueId: 'giftcard_id' }); }); @@ -37,4 +37,4 @@ $(document).ready(function()
- \ No newline at end of file + diff --git a/app/Views/home/home.php b/app/Views/home/home.php index 911adae17..1dc673d22 100644 --- a/app/Views/home/home.php +++ b/app/Views/home/home.php @@ -3,26 +3,26 @@ * @var array $allowed_modules */ ?> - + -

+

- + diff --git a/app/Views/home/office.php b/app/Views/home/office.php index c1c6614eb..da65d77c6 100644 --- a/app/Views/home/office.php +++ b/app/Views/home/office.php @@ -3,26 +3,26 @@ * @var array $allowed_modules */ ?> - + -

+

- - + diff --git a/app/Views/item_kits/manage.php b/app/Views/item_kits/manage.php index 4a2ba4f5a..5a772f299 100644 --- a/app/Views/item_kits/manage.php +++ b/app/Views/item_kits/manage.php @@ -14,7 +14,7 @@ $(document).ready(function() table_support.init({ resource: '', headers: , - pageSize: settings['lines_per_page'] ?>, + pageSize: , uniqueId: 'item_kit_id' }); @@ -52,4 +52,4 @@ $(document).ready(function()
- \ No newline at end of file + diff --git a/app/Views/items/form.php b/app/Views/items/form.php index dd99b7c71..5fb45e3f6 100644 --- a/app/Views/items/form.php +++ b/app/Views/items/form.php @@ -62,7 +62,7 @@
settings['category_dropdown']) + if($config['category_dropdown']) { echo form_dropdown('category', esc($categories, 'attr'), $selected_category, ['class' => 'form-control']); } @@ -146,7 +146,7 @@ echo form_radio($radio_button) ?> settings['derive_sale_quantity'] == '1') + if($config['derive_sale_quantity'] == '1') { ?>
@@ -263,7 +263,7 @@ 'name' => 'tax_names[]', 'id' => 'tax_name_2', 'class' => 'form-control input-sm', - 'value' => isset($item_tax_info[1]['name']) ? esc($item_tax_info[1]['name'], 'attr') : esc(config('OSPOS')->settings['default_tax_2_name'], 'attr') + 'value' => isset($item_tax_info[1]['name']) ? esc($item_tax_info[1]['name'], 'attr') : esc($config['default_tax_2_name'], 'attr') ]) ?>
@@ -420,7 +420,7 @@
settings['multi_pack_enabled'] == '1') + if($config['multi_pack_enabled'] == '1') { ?>
diff --git a/app/Views/items/form_bulk.php b/app/Views/items/form_bulk.php index 20e3f3c81..9197daf9f 100644 --- a/app/Views/items/form_bulk.php +++ b/app/Views/items/form_bulk.php @@ -49,7 +49,7 @@
- settings['currency_symbol']) ?> + 'cost_price', @@ -57,7 +57,7 @@ 'class' => 'form-control input-sm' ]) ?> - settings['currency_symbol']) ?> +
@@ -68,7 +68,7 @@
- settings['currency_symbol']) ?> + 'unit_price', @@ -76,7 +76,7 @@ 'class' => 'form-control input-sm' ]) ?> - settings['currency_symbol']) ?> +
@@ -89,7 +89,7 @@ 'name' => 'tax_names[]', 'id' => 'tax_name_1', 'class' => 'form-control input-sm', - 'value' => esc(config('OSPOS')->settings['default_tax_1_name'], 'attr') + 'value' => esc($config['default_tax_1_name'], 'attr') ]) ?>
@@ -98,7 +98,7 @@ 'name' => 'tax_percents[]', 'id' => 'tax_percent_name_1', 'class' => 'form-control input-sm', - 'value'=>to_tax_decimals(config('OSPOS')->settings['default_tax_1_rate']) + 'value'=>to_tax_decimals($config['default_tax_1_rate']) ]) ?> %
@@ -112,7 +112,7 @@ 'name' => 'tax_names[]', 'id' => 'tax_name_2', 'class' => 'form-control input-sm', - 'value' => esc(config('OSPOS')->settings['default_tax_2_name'], 'attr') + 'value' => esc($config['default_tax_2_name'], 'attr') ]) ?>
@@ -121,7 +121,7 @@ 'name' => 'tax_percents[]', 'id' => 'tax_percent_name_2', 'class' => 'form-control input-sm', - 'value' => to_tax_decimals(config('OSPOS')->settings['default_tax_2_rate']) + 'value' => to_tax_decimals($config['default_tax_2_rate']) ]) ?> %
diff --git a/app/Views/items/manage.php b/app/Views/items/manage.php index f89c1ffa5..36e4c6fde 100644 --- a/app/Views/items/manage.php +++ b/app/Views/items/manage.php @@ -32,7 +32,7 @@ $(document).ready(function() // load the preset daterange picker // set the beginning of time as starting date - $('#daterangepicker').data('daterangepicker').setStartDate("settings['dateformat'], mktime(0,0,0,01,01,2010)) ?>"); + $('#daterangepicker').data('daterangepicker').setStartDate(""); // update the hidden inputs with the selected dates before submitting the search data var start_date = ""; $("#daterangepicker").on('apply.daterangepicker', function(ev, picker) { @@ -52,7 +52,7 @@ $(document).ready(function() employee_id: get_logged_in_employee_info()->person_id ?>, resource: '', headers: , - pageSize: settings['lines_per_page'] ?>, + pageSize: , uniqueId: 'items.item_id', queryParams: function() { return $.extend(arguments[0], { diff --git a/app/Views/login.php b/app/Views/login.php index d28fda69d..98bdc7683 100644 --- a/app/Views/login.php +++ b/app/Views/login.php @@ -4,25 +4,29 @@ * @var bool $is_latest * @var string $latest_version * @var bool $gcaptcha_enabled + * @var array $config */ ?> - + - - - <?php echo config('OSPOS')->settings['company'] . ' | ' . lang('Common.software_short') . ' | ' . lang('Login.login') ?> - + + + <?= $config['company'] . ' | ' . lang('Common.software_short') . ' | ' . lang('Login.login') ?> - - - - + + + " rel="stylesheet" type="text/css"> - - + @@ -30,83 +34,81 @@
diff --git a/app/Views/messages/form_sms.php b/app/Views/messages/form_sms.php index 3a8e07176..edfcf2d83 100644 --- a/app/Views/messages/form_sms.php +++ b/app/Views/messages/form_sms.php @@ -34,7 +34,7 @@
'message', 'class' => 'control-label col-xs-2 required']) ?>
- 'form-control input-sm required', 'name' => 'message', 'id' => 'message', 'value' => esc(config('OSPOS')->settings['msg_msg'], 'attr')]) ?> + 'form-control input-sm required', 'name' => 'message', 'id' => 'message', 'value' => esc($config['msg_msg'], 'attr')]) ?>
diff --git a/app/Views/partial/datepicker_locale.php b/app/Views/partial/datepicker_locale.php index a225eca7b..faee25bb0 100644 --- a/app/Views/partial/datepicker_locale.php +++ b/app/Views/partial/datepicker_locale.php @@ -2,11 +2,11 @@ var pickerconfig = function(config) { return $.extend({ - format: "settings['dateformat']) . ' ' . dateformat_bootstrap(config('OSPOS')->settings['timeformat']) ?>", + format: "", settings['timeformat']; + $t = $config['timeformat']; $m = $t[strlen($t)-1]; - if( strpos(config('OSPOS')->settings['timeformat'], 'a') !== false || strpos(config('OSPOS')->settings['timeformat'], 'A') !== false ) + if( strpos($config['timeformat'], 'a') !== false || strpos($config['timeformat'], 'A') !== false ) { ?> showMeridian: true, @@ -28,7 +28,7 @@ var pickerconfig = function(config) { }, ); }; -$.fn.datetimepicker.dates['settings['language'] ?>'] = { +$.fn.datetimepicker.dates[''] = { days: [ "", "", @@ -87,13 +87,13 @@ $.fn.datetimepicker.dates['settings['language'] ?>'] ], today: "", settings['timeformat'], 'a') !== false ) + if( strpos($config['timeformat'], 'a') !== false ) { ?> meridiem: ["am", "pm"], settings['timeformat'], 'A') !== false ) + elseif( strpos($config['timeformat'], 'A') !== false ) { ?> meridiem: ["AM", "PM"], diff --git a/app/Views/partial/daterangepicker.php b/app/Views/partial/daterangepicker.php index 7e5ca51a9..dc4939944 100644 --- a/app/Views/partial/daterangepicker.php +++ b/app/Views/partial/daterangepicker.php @@ -1,109 +1,113 @@ -lang->load("calendar"); $this->lang->load("date"); - if(empty(config('OSPOS')->settings['date_or_time_format'])) + $('#daterangepicker').css("width","180"); - var start_date = ""; - var end_date = ""; + var start_date = ""; + var end_date = ""; $('#daterangepicker').daterangepicker({ "ranges": { - "": [ - "settings['dateformat'], mktime(0,0,0,date("m"),date("d"),date("Y"))) ?>", - "settings['dateformat'], mktime(0,0,0,date("m"),date("d")+1,date("Y"))-1) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'], mktime(0,0,0,date("m"),date("d"),date("Y")-1)) ?>", - "settings['dateformat'], mktime(0,0,0,date("m"),date("d")+1,date("Y")-1)-1) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'], mktime(0,0,0,date("m"),date("d")-1,date("Y"))) ?>", - "settings['dateformat'], mktime(0,0,0,date("m"),date("d"),date("Y"))-1) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'], mktime(0,0,0,date("m"),date("d")-6,date("Y"))) ?>", - "settings['dateformat'], mktime(0,0,0,date("m"),date("d")+1,date("Y"))-1) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'], mktime(0,0,0,date("m"),date("d")-29,date("Y"))) ?>", - "settings['dateformat'], mktime(0,0,0,date("m"),date("d")+1,date("Y"))-1) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'], mktime(0,0,0,date("m"),1,date("Y"))) ?>", - "settings['dateformat'], mktime(0,0,0,date("m")+1,1,date("Y"))-1) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'], mktime(0,0,0,date("m"),1,date("Y")-1)) ?>", - "settings['dateformat'], mktime(0,0,0,date("m"),date("d")+1,date("Y")-1)-1) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'], mktime(0,0,0,date("m"),1,date("Y")-1)) ?>", - "settings['dateformat'], mktime(0,0,0,date("m")+1,1,date("Y")-1)-1) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'], mktime(0,0,0,date("m")-1,1,date("Y"))) ?>", - "settings['dateformat'], mktime(0,0,0,date("m"),1,date("Y"))-1) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'], mktime(0,0,0,1,1,date("Y"))) ?>", - "settings['dateformat'], mktime(0,0,0,date("m"),1,date("Y")+1)-1) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'], mktime(0,0,0,1,1,date("Y")-1)) ?>", - "settings['dateformat'], mktime(0,0,0,1,1,date("Y"))-1) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'], mktime(0,0,0,config('OSPOS')->settings['financial_year'],1,date("Y"))) ?>", - "settings['dateformat'], mktime(0,0,0,date("m"),1,date("Y")+1)-1) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'], mktime(0,0,0,config('OSPOS')->settings['financial_year'],1,date("Y")-1)) ?>", - "settings['dateformat'], mktime(0,0,0,config('OSPOS')->settings['financial_year'],1,date("Y"))-1) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'], mktime(0,0,0,1,1,2010)) ?>", - "settings['dateformat'], mktime(0,0,0,date("m"),date("d")+1,date("Y"))-1) ?>" + "": [ + "", + "" ], }, "locale": { - "format": 'settings['dateformat']) ?>', + "format": '', "separator": " - ", - "applyLabel": "", - "cancelLabel": "", - "fromLabel": "", - "toLabel": "", - "customRangeLabel": "", + "applyLabel": "", + "cancelLabel": "", + "fromLabel": "", + "toLabel": "", + "customRangeLabel": "", "daysOfWeek": [ - "", - "", - "", - "", - "", - "", - "", - "" + "", + "", + "", + "", + "", + "", + "", + "" ], "monthNames": [ - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "" + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "" ], - "firstDay": + "firstDay": }, "alwaysShowCalendars": true, - "startDate": "settings['dateformat'], mktime(0,0,0,date("m"),date("d")+1,date("Y"))-1) ?>", - "endDate": "settings['dateformat'], mktime(0,0,0,date("m"),date("d")+1,date("Y"))-1) ?>", - "minDate": "settings['dateformat'], mktime(0,0,0,01,01,2010)) ?>", - "maxDate": "settings['dateformat'], mktime(0,0,0,date("m"),date("d")+1,date("Y"))-1) ?>" + "startDate": "", + "endDate": "", + "minDate": "", + "maxDate": "" }, function(start, end, label) { start_date = start.format('YYYY-MM-DD'); end_date = end.format('YYYY-MM-DD'); @@ -114,108 +118,108 @@ { ?> $('#daterangepicker').css("width","305"); - var start_date = ""; - var end_date = ""; + var start_date = ""; + var end_date = ""; $('#daterangepicker').daterangepicker({ "ranges": { - "": [ - "settings['dateformat'] . ' ' . config('OSPOS')->settings['dateformat'], mktime(0,0,0,date("m"),date("d"),date("Y"))) ?>", - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(23,59,59,date("m"),date("d"),date("Y"))) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(0,0,0,date("m"),date("d"),date("Y")-1)) ?>", - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(23,59,59,date("m"),date("d"),date("Y")-1)) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(0,0,0,date("m"),date("d")-1,date("Y"))) ?>", - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(23,59,59,date("m"),date("d")-1,date("Y"))) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(0,0,0,date("m"),date("d")-6,date("Y"))) ?>", - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(23,59,59,date("m"),date("d"),date("Y"))) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(0,0,0,date("m"),date("d")-29,date("Y"))) ?>", - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(23,59,59,date("m"),date("d"),date("Y"))) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(0,0,0,date("m"),1,date("Y"))) ?>", - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(23,59,59,date("m"),date("d"),date("Y"))) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(0,0,0,date("m"),1,date("Y")-1)) ?>", - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(23,59,59,date("m"),date("d"),date("Y")-1)) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(0,0,0,date("m"),1,date("Y")-1)) ?>", - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(23,59,59,date("m")+1,0,date("Y")-1)) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(0,0,0,date("m")-1,1,date("Y"))) ?>", - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(23,59,59,date("m"),0,date("Y"))) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(0,0,0,1,1,date("Y"))) ?>", - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(23,59,59,date("m")+1,0,date("Y"))) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(0,0,0,1,1,date("Y")-1)) ?>", - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(23,59,59,12,31,date("Y")-1)) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(0,0,0,config('OSPOS')->settings['financial_year'],1,date("Y"))) ?>", - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(23,59,59,date("m")+1,0,date("Y"))) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(0,0,0,config('OSPOS')->settings['financial_year'],1,date("Y")-1)) ?>", - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(23,59,59,config('OSPOS')->settings['financial_year'],0,date("Y"))) ?>" + "": [ + "", + "" ], - "": [ - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(0,0,0,1,1,2010)) ?>", - "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(23,59,59,date("m"),date("d"),date("Y"))) ?>" + "": [ + "", + "" ], }, "locale": { - "format": 'settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat']) ?>', + "format": '', "separator": " - ", - "applyLabel": "", - "cancelLabel": "", - "fromLabel": "", - "toLabel": "", - "customRangeLabel": "", + "applyLabel": "", + "cancelLabel": "", + "fromLabel": "", + "toLabel": "", + "customRangeLabel": "", "daysOfWeek": [ - "", - "", - "", - "", - "", - "", - "", - "" + "", + "", + "", + "", + "", + "", + "", + "" ], "monthNames": [ - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "", - "" + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "", + "" ], - "firstDay": + "firstDay": }, "timePicker": true, "timePickerSeconds": true, "alwaysShowCalendars": true, - "startDate": "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(0,0,0,date("m"),date("d"),date("Y"))) ?>", - "endDate": "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(23,59,59,date("m"),date("d"),date("Y"))) ?>", - "minDate": "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(0,0,0,01,01,2010)) ?>", - "maxDate": "settings['dateformat'] . ' ' . config('OSPOS')->settings['timeformat'],mktime(23,59,59,date("m"),date("d"),date("Y"))) ?>" + "startDate": "", + "endDate": "", + "minDate": "", + "maxDate": "" }, function(start, end, label) { start_date = start.format('YYYY-MM-DD HH:mm:ss'); end_date = end.format('YYYY-MM-DD HH:mm:ss'); diff --git a/app/Views/partial/footer.php b/app/Views/partial/footer.php index 9eb188c69..828216b60 100644 --- a/app/Views/partial/footer.php +++ b/app/Views/partial/footer.php @@ -3,9 +3,9 @@ diff --git a/app/Views/partial/header.php b/app/Views/partial/header.php index 9b18f6b0e..9bd13c91a 100644 --- a/app/Views/partial/header.php +++ b/app/Views/partial/header.php @@ -3,19 +3,21 @@ * @var object $user_info * @var array $allowed_modules * @var CodeIgniter\HTTP\IncomingRequest $request + * @var array $config */ -$request = \Config\Services::request(); -helper('cookie'); +use Config\Services; + +$request = Services::request(); ?> - <?php echo esc(config('OSPOS')->settings['company']) . ' | ' . lang('Common.powered_by') . ' OSPOS ' . esc(config('OSPOS')->settings['application_version']) ?> + <?php echo esc($config['company']) . ' | ' . lang('Common.powered_by') . ' OSPOS ' . esc(config('App')->application_version) ?> - + getGet('debug') == 'true') : ?> @@ -33,69 +35,68 @@ helper('cookie'); - - - - - - - - + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + - - + + - settings['theme'] != 'flatly' && file_exists($_SERVER['DOCUMENT_ROOT'] . '/public/css/' . esc(config('OSPOS')->settings['theme']) . '.css')) { ?> - + + - + @@ -114,17 +115,17 @@ helper('cookie');
@@ -139,17 +140,17 @@ helper('cookie'); - + settings['lines_per_page'] ?>, + pageSize: , sortable: true, showExport: true, exportDataType: 'all', diff --git a/app/Views/reports/tabular_details.php b/app/Views/reports/tabular_details.php index 10342fac4..b8e7cb4e4 100644 --- a/app/Views/reports/tabular_details.php +++ b/app/Views/reports/tabular_details.php @@ -36,7 +36,7 @@ var details_data = ; settings['customer_reward_enable'] == TRUE && !empty($details_data_rewards)) //TODO: === ? + if($config['customer_reward_enable'] == TRUE && !empty($details_data_rewards)) //TODO: === ? { ?> var details_data_rewards = ; @@ -63,7 +63,7 @@ stickyHeader: true, stickyHeaderOffsetLeft: $('#table').offset().left + 'px', stickyHeaderOffsetRight: $('#table').offset().right + 'px', - pageSize: settings['lines_per_page'] ?>, + pageSize: , pagination: true, sortable: true, showColumns: true, @@ -88,7 +88,7 @@ }); settings['customer_reward_enable'] == TRUE && !empty($details_data_rewards)) + if($config['customer_reward_enable'] == TRUE && !empty($details_data_rewards)) { ?> $detail.append('
').find("table").bootstrapTable({ diff --git a/app/Views/sales/form.php b/app/Views/sales/form.php index 44daec4fd..b645b875a 100644 --- a/app/Views/sales/form.php +++ b/app/Views/sales/form.php @@ -34,7 +34,7 @@ settings['invoice_enable'] == TRUE) //TODO: Replace this with just `if(config('OSPOS')->settings['invoice_enable']))` + if($config['invoice_enable'] == TRUE) //TODO: Replace this with just `if($config['invoice_enable']))` { ?>
@@ -64,11 +64,11 @@
- settings['currency_symbol']) ?> + 'payment_amount_new', 'value' => $payment_amount_new, 'id' => 'payment_amount_new', 'class' => 'form-control input-sm']) //TODO: potentially we need to add type to be float/decimal/numeric to reduce improper data entry ?> - settings['currency_symbol']) ?> +
@@ -96,11 +96,11 @@
- settings['currency_symbol'], 'attr') ?> + "payment_amount_$i", 'value' => $row->payment_amount, 'id' => "payment_amount_$i", 'class' => 'form-control input-sm', 'readonly' => 'true']) //TODO: add type attribute ?> - settings['currency_symbol']) ?> +
@@ -119,11 +119,11 @@
- settings['currency_symbol']) ?> + "refund_amount_$i", 'value' => $row->cash_refund, 'id' => "refund_amount_$i", 'class' => 'form-control input-sm', 'readonly' => 'true']) ?> - settings['currency_symbol']) ?> +
diff --git a/app/Views/sales/invoice.php b/app/Views/sales/invoice.php index db91be048..48b74a5d2 100644 --- a/app/Views/sales/invoice.php +++ b/app/Views/sales/invoice.php @@ -79,19 +79,19 @@ $(document).ready(function()