diff --git a/.env-example b/.env-example new file mode 100644 index 000000000..a92726251 --- /dev/null +++ b/.env-example @@ -0,0 +1,63 @@ +#-------------------------------------------------------------------- +# ENVIRONMENT +#-------------------------------------------------------------------- + +CI_ENVIRONMENT = production + +#-------------------------------------------------------------------- +# DATABASE +#-------------------------------------------------------------------- + +database.default.hostname = 'localhost' +database.default.database = 'ospos' +database.default.username = 'admin' +database.default.password = 'pointofsale' +database.default.DBDriver = 'MySQLi' +database.default.DBPrefix = 'ospos_' + +database.development.hostname = 'localhost' +database.development.database = 'ospos' +database.development.username = 'admin' +database.development.password = 'pointofsale' +database.development.DBDriver = 'MySQLi' +database.development.DBPrefix = 'ospos_' + +database.tests.hostname = 'localhost' +database.tests.database = 'ospos' +database.tests.username = 'admin' +database.tests.password = 'pointofsale' +database.tests.DBDriver = 'MySQLi' +database.tests.DBPrefix = 'ospos_' + +#-------------------------------------------------------------------- +# ENCRYPTION +#-------------------------------------------------------------------- + +encryption.key = '' + +#-------------------------------------------------------------------- +# LOGGER + # - 0 = Disables logging, Error logging TURNED OFF + # - 1 = Emergency Messages - System is unusable + # - 2 = Alert Messages - Action Must Be Taken Immediately + # - 3 = Critical Messages - Application component unavailable, unexpected exception. + # - 4 = Runtime Errors - Don't need immediate action, but should be monitored. + # - 5 = Warnings - Exceptional occurrences that are not errors. + # - 6 = Notices - Normal but significant events. + # - 7 = Info - Interesting events, like user logging in, etc. + # - 8 = Debug - Detailed debug information. + # - 9 = All Messages +#-------------------------------------------------------------------- + +logger.threshold = 0 +app.db_log_enabled = false + +#-------------------------------------------------------------------- +# HONEYPOT +#-------------------------------------------------------------------- + +honeypot.hidden = true +honeypot.label = 'Fill This Field' +honeypot.name = 'honeypot' +honeypot.template = '' +honeypot.container = '
{template}
' diff --git a/Gruntfile.js b/Gruntfile.js index 26129f641..7da72c692 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -72,10 +72,10 @@ module.exports = function(grunt) { }, minjs: { options: { - starttag: '', + starttag: '', }, files: { - 'app/Views/partial/header.php': [ospos_min_css] + 'app/Views/partial/header.php': [ospos_min_js] }, }, css_login: { @@ -126,7 +126,7 @@ module.exports = function(grunt) { concat: { js: { options: { - separator: ';' + separator: '\n' }, files: { 'tmp/opensourcepos.js': ['public/dist/jquery/jquery.js', 'tmp/opensourcepos_bower.js', 'public/js/*.js'] diff --git a/app/Config/Constants.php b/app/Config/Constants.php index 276d5f8da..48b873e15 100644 --- a/app/Config/Constants.php +++ b/app/Config/Constants.php @@ -93,6 +93,10 @@ define('EVENT_PRIORITY_NORMAL', 100); */ define('EVENT_PRIORITY_HIGH', 10); +/** + * Global Constants. + */ +const NEW_ENTRY = -1; /** * Attribute Related Constants. diff --git a/app/Controllers/Attributes.php b/app/Controllers/Attributes.php index 23805a11f..090d57970 100644 --- a/app/Controllers/Attributes.php +++ b/app/Controllers/Attributes.php @@ -31,13 +31,13 @@ class Attributes extends Secure_Controller /** * Returns customer table data rows. This will be called with AJAX. */ - public function search(): void + public function getSearch(): void { - $search = $this->request->getGet('search', FILTER_SANITIZE_STRING); - $limit = $this->request->getGet('limit', FILTER_SANITIZE_NUMBER_INT); - $offset = $this->request->getGet('offset', FILTER_SANITIZE_NUMBER_INT); - $sort = $this->request->getGet('sort', FILTER_SANITIZE_STRING); - $order = $this->request->getGet('order', FILTER_SANITIZE_STRING); + $search = $this->request->getVar('search', FILTER_SANITIZE_STRING); + $limit = $this->request->getVar('limit', FILTER_SANITIZE_NUMBER_INT); + $offset = $this->request->getVar('offset', FILTER_SANITIZE_NUMBER_INT); + $sort = $this->request->getVar('sort', FILTER_SANITIZE_STRING); + $order = $this->request->getVar('order', FILTER_SANITIZE_STRING); $attributes = $this->attribute->search($search, $limit, $offset, $sort, $order); $total_rows = $this->attribute->get_found_rows($search); @@ -55,7 +55,7 @@ class Attributes extends Secure_Controller /** * @return void */ - public function save_attribute_value(): void + public function postSave_attribute_value(): void { $success = $this->attribute->save_value( $this->request->getPost('attribute_value', FILTER_SANITIZE_STRING), @@ -70,7 +70,7 @@ class Attributes extends Secure_Controller /** * @return void */ - public function delete_attribute_value(): void + public function postDelete_attribute_value(): void { $success = $this->attribute->delete_value( $this->request->getPost('attribute_value', FILTER_SANITIZE_STRING), @@ -84,7 +84,7 @@ class Attributes extends Secure_Controller * @param int $definition_id * @return void */ - public function save_definition(int $definition_id = NO_DEFINITION_ID): void + public function postSave_definition(int $definition_id = NO_DEFINITION_ID): void { $definition_flags = 0; @@ -144,7 +144,7 @@ class Attributes extends Secure_Controller echo json_encode([ 'success' => FALSE, 'message' => lang('Attributes.definition_error_adding_updating', ['definition_name' => $definition_name]), - 'id' => -1 + 'id' => NEW_ENTRY ]); } } @@ -155,12 +155,12 @@ class Attributes extends Secure_Controller */ public function suggest_attribute(int $definition_id): void { - $suggestions = $this->attribute->get_suggestions($definition_id, $this->request->getGet('term', FILTER_SANITIZE_STRING)); + $suggestions = $this->attribute->get_suggestions($definition_id, $this->request->getVar('term', FILTER_SANITIZE_STRING)); echo json_encode($suggestions); } - public function get_row(int $row_id): void + public function getRow(int $row_id): void { $attribute_definition_info = $this->attribute->get_info($row_id); $attribute_definition_info->definition_flags = $this->get_attributes($attribute_definition_info->definition_flags); @@ -182,7 +182,7 @@ class Attributes extends Secure_Controller return $definition_flag_names; } - public function view(int $definition_id = NO_DEFINITION_ID): void + public function getView(int $definition_id = NO_DEFINITION_ID): void { $info = $this->attribute->get_info($definition_id); foreach(get_object_vars($info) as $property => $value) @@ -204,12 +204,12 @@ class Attributes extends Secure_Controller echo view('attributes/form', $data); } - public function delete_value(int $attribute_id): bool //TODO: This function appears to never be used in the codebase. Is it needed? + public function postDelete_value(int $attribute_id): bool //TODO: This function appears to never be used in the codebase. Is it needed? { return $this->attribute->delete_value($attribute_id, NO_DEFINITION_ID); } - public function delete(): void + public function postDelete(): void { $attributes_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_STRING); diff --git a/app/Controllers/Cashups.php b/app/Controllers/Cashups.php index 83578c1bc..665f42bc2 100644 --- a/app/Controllers/Cashups.php +++ b/app/Controllers/Cashups.php @@ -35,21 +35,21 @@ class Cashups extends Secure_Controller echo view('cashups/manage', $data); } - public function search(): void + public function getSearch(): void { - $search = $this->request->getGet('search', FILTER_SANITIZE_STRING); - $limit = $this->request->getGet('limit', FILTER_SANITIZE_NUMBER_INT); - $offset = $this->request->getGet('offset', FILTER_SANITIZE_NUMBER_INT); - $sort = $this->request->getGet('sort', FILTER_SANITIZE_STRING); - $order = $this->request->getGet('order', FILTER_SANITIZE_STRING); + $search = $this->request->getVar('search', FILTER_SANITIZE_STRING); + $limit = $this->request->getVar('limit', FILTER_SANITIZE_NUMBER_INT); + $offset = $this->request->getVar('offset', FILTER_SANITIZE_NUMBER_INT); + $sort = $this->request->getVar('sort', FILTER_SANITIZE_STRING); + $order = $this->request->getVar('order', FILTER_SANITIZE_STRING); $filters = [ - 'start_date' => $this->request->getGet('start_date', FILTER_SANITIZE_STRING), //TODO: Is this the best way to filter dates - 'end_date' => $this->request->getGet('end_date', FILTER_SANITIZE_STRING), + 'start_date' => $this->request->getVar('start_date', FILTER_SANITIZE_STRING), //TODO: Is this the best way to filter dates + 'end_date' => $this->request->getVar('end_date', FILTER_SANITIZE_STRING), 'is_deleted' => FALSE ]; // check if any filter is set in the multiselect dropdown - $filledup = array_fill_keys($this->request->getGet('filters', FILTER_SANITIZE_STRING), TRUE); //TODO: $filledup doesn't follow variable naming patterns we are using. + $filledup = array_fill_keys($this->request->getVar('filters', FILTER_SANITIZE_STRING), TRUE); //TODO: $filledup doesn't follow variable naming patterns we are using. $filters = array_merge($filters, $filledup); $cash_ups = $this->cashup->search($search, $filters, $limit, $offset, $sort, $order); $total_rows = $this->cashup->get_found_rows($search, $filters); @@ -62,7 +62,7 @@ class Cashups extends Secure_Controller echo json_encode(['total' => $total_rows, 'rows' => $data_rows]); } - public function view(int $cashup_id = -1): void //TODO: Need to replace -1 with a constant in constants.php + public function getView(int $cashup_id = NEW_ENTRY): void { $data = []; @@ -178,7 +178,7 @@ class Cashups extends Secure_Controller echo view("cashups/form", $data); } - public function get_row(int $row_id): void + public function getRow(int $row_id): void { $cash_ups_info = $this->cashup->get_info($row_id); $data_row = get_cash_up_data_row($cash_ups_info); @@ -186,7 +186,7 @@ class Cashups extends Secure_Controller echo json_encode($data_row); } - public function save(int $cashup_id = -1): void //TODO: Need to replace -1 with a constant in constants.php + public function postSave(int $cashup_id = NEW_ENTRY): void { $open_date = $this->request->getPost('open_date', FILTER_SANITIZE_STRING); $open_date_formatter = date_create_from_format($this->config['dateformat'] . ' ' . $this->config['timeformat'], $open_date); @@ -214,7 +214,7 @@ class Cashups extends Secure_Controller if($this->cashup->save_value($cash_up_data, $cashup_id)) { //New cashup_id - if($cashup_id == -1)//TODO: Need to replace -1 with a constant in constants.php + if($cashup_id == NEW_ENTRY) { echo json_encode(['success' => TRUE, 'message' => lang('Cashups.successful_adding'), 'id' => $cash_up_data['cashup_id']]); } @@ -225,11 +225,11 @@ class Cashups extends Secure_Controller } else//failure { - echo json_encode(['success' => FALSE, 'message' => lang('Cashups.error_adding_updating'), 'id' => -1]);//TODO: Need to replace -1 with a constant in constants.php + echo json_encode(['success' => FALSE, 'message' => lang('Cashups.error_adding_updating'), 'id' => NEW_ENTRY]); } } - public function delete(): void + public function postDelete(): void { $cash_ups_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_STRING); diff --git a/app/Controllers/Customers.php b/app/Controllers/Customers.php index c5ad9dc05..85151de34 100644 --- a/app/Controllers/Customers.php +++ b/app/Controllers/Customers.php @@ -35,7 +35,7 @@ class Customers extends Persons { parent::__construct('customers'); $this->mailchimp_lib = new Mailchimp_lib(); - + $this->customer_rewards = model('Customer_rewards'); $this->customer = model('Customer'); $this->tax_code = model('Tax_code'); $this->config = config('OSPOS')->settings; @@ -64,7 +64,7 @@ class Customers extends Persons /** * Gets one row for a customer manage table. This is called using AJAX to update one row. */ - public function get_row(int $row_id): void + public function getRow(int $row_id): void { $person = $this->customer->get_info($row_id); @@ -91,7 +91,7 @@ class Customers extends Persons /* Returns customer table data rows. This will be called with AJAX. */ - public function search(): void + public function getSearch() { $search = $this->request->getGet('search', FILTER_SANITIZE_STRING); $limit = $this->request->getGet('limit', FILTER_SANITIZE_NUMBER_INT); @@ -129,9 +129,9 @@ class Customers extends Persons /** * Gives search suggestions based on what is being searched for */ - public function suggest(): void + public function getSuggest(): void { - $suggestions = $this->customer->get_search_suggestions($this->request->getGet('term', FILTER_SANITIZE_STRING), 25,TRUE); + $suggestions = $this->customer->get_search_suggestions($this->request->getVar('term', FILTER_SANITIZE_STRING), 25,TRUE); echo json_encode($suggestions); } @@ -146,8 +146,11 @@ class Customers extends Persons /** * Loads the customer edit form */ - public function view(int $customer_id = -1): void //TODO: replace -1 with a constant + public function getView(int $customer_id = NEW_ENTRY): void { + // Set default values + if($customer_id == null) $customer_id = NEW_ENTRY; + $info = $this->customer->get_info($customer_id); foreach(get_object_vars($info) as $property => $value) { @@ -184,7 +187,7 @@ class Customers extends Persons $data['packages'] = $packages; $data['selected_package'] = $info->package_id; - if($$this->config['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; } @@ -265,7 +268,7 @@ class Customers extends Persons /** * Inserts/updates a customer */ - public function save(int $customer_id = -1): void //TODO: Replace -1 with a constant + public function postSave(int $customer_id = NEW_ENTRY): void { $first_name = $this->request->getPost('first_name', FILTER_SANITIZE_STRING); $last_name = $this->request->getPost('last_name', FILTER_SANITIZE_STRING); @@ -290,7 +293,7 @@ class Customers extends Persons 'comments' => $this->request->getPost('comments', FILTER_SANITIZE_STRING) ]; - $date_formatter = date_create_from_format($$this->config['dateformat'] . ' ' . $$this->config['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, @@ -309,17 +312,18 @@ class Customers extends Persons if($this->customer->save_customer($person_data, $customer_data, $customer_id)) { // save customer to Mailchimp selected list //TODO: addOrUpdateMember should be refactored... potentially pass an array or object instead of 6 parameters. + $mailchimp_status = $this->request->getPost('mailchimp_status', FILTER_SANITIZE_STRING); $this->mailchimp_lib->addOrUpdateMember( $this->_list_id, $email, $first_name, $last_name, - $this->request->getPost('mailchimp_status', FILTER_SANITIZE_STRING), + $mailchimp_status == null ? "" : $mailchimp_status, ['vip' => $this->request->getPost('mailchimp_vip') != NULL] ); // New customer - if($customer_id == -1) + if($customer_id == NEW_ENTRY) { echo json_encode ([ 'success' => TRUE, @@ -341,7 +345,7 @@ class Customers extends Persons echo json_encode ([ 'success' => FALSE, 'message' => lang('Customers.error_adding_updating') . ' ' . $first_name . ' ' . $last_name, - 'id' => -1 + 'id' => NEW_ENTRY ]); } } @@ -349,7 +353,7 @@ class Customers extends Persons /** * AJAX call to verify if an email address already exists */ - public function ajax_check_email(): void + public function postCheckEmail(): void { $exists = $this->customer->check_email_exists(strtolower($this->request->getPost('email')), $this->request->getPost('person_id', FILTER_SANITIZE_NUMBER_INT)); @@ -359,7 +363,7 @@ class Customers extends Persons /** * AJAX call to verify if an account number already exists */ - public function ajax_check_account_number(): void + public function postCheckAccountNumber(): void { $exists = $this->customer->check_account_number_exists($this->request->getPost('account_number'), $this->request->getPost('person_id', FILTER_SANITIZE_NUMBER_INT)); @@ -369,7 +373,7 @@ class Customers extends Persons /** * This deletes customers from the customers table */ - public function delete(): void + public function postDelete(): void { $customers_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_STRING); $customers_info = $this->customer->get_multiple_info($customers_to_delete); @@ -408,9 +412,9 @@ class Customers extends Persons force_download($name, $data); } - public function csv_import(): void + public function getCsvImport(): void { - echo view('customers/form_csv_import', NULL); + echo view('customers/form_csv_import'); } public function do_csv_import(): void diff --git a/app/Controllers/Employees.php b/app/Controllers/Employees.php index 814097122..8025cff21 100644 --- a/app/Controllers/Employees.php +++ b/app/Controllers/Employees.php @@ -22,13 +22,13 @@ class Employees extends Persons /** * Returns employee table data rows. This will be called with AJAX. */ - public function search(): void + public function getSearch(): void { - $search = $this->request->getGet('search', FILTER_SANITIZE_STRING); - $limit = $this->request->getGet('limit', FILTER_SANITIZE_NUMBER_INT); - $offset = $this->request->getGet('offset', FILTER_SANITIZE_NUMBER_INT); - $sort = $this->request->getGet('sort', FILTER_SANITIZE_STRING); - $order = $this->request->getGet('order', FILTER_SANITIZE_STRING); + $search = $this->request->getVar('search', FILTER_SANITIZE_STRING); + $limit = $this->request->getVar('limit', FILTER_SANITIZE_NUMBER_INT); + $offset = $this->request->getVar('offset', FILTER_SANITIZE_NUMBER_INT); + $sort = $this->request->getVar('sort', FILTER_SANITIZE_STRING); + $order = $this->request->getVar('order', FILTER_SANITIZE_STRING); $employees = $this->employee->search($search, $limit, $offset, $sort, $order); $total_rows = $this->employee->get_found_rows($search); @@ -47,14 +47,14 @@ class Employees extends Persons */ public function suggest(): void { - $suggestions = $this->employee->get_search_suggestions($this->request->getGet('term', FILTER_SANITIZE_STRING), 25, TRUE); + $suggestions = $this->employee->get_search_suggestions($this->request->getVar('term', FILTER_SANITIZE_STRING), 25, TRUE); echo json_encode($suggestions); } public function suggest_search(): void { - $suggestions = $this->employee->get_search_suggestions($this->request->getPost('term', FILTER_SANITIZE_STRING)); + $suggestions = $this->employee->get_search_suggestions($this->request->getVar('term', FILTER_SANITIZE_STRING)); echo json_encode($suggestions); } @@ -62,7 +62,7 @@ class Employees extends Persons /** * Loads the employee edit form */ - public function view(int $employee_id = -1): void //TODO: Replace -1 with a constant + public function getView(int $employee_id = NEW_ENTRY): void { $person_info = $this->employee->get_info($employee_id); foreach(get_object_vars($person_info) as $property => $value) @@ -98,7 +98,7 @@ class Employees extends Persons /** * Inserts/updates an employee */ - public function save(int $employee_id = -1): void //TODO: Replace -1 with a constant + public function postSave(int $employee_id = NEW_ENTRY): void { $first_name = $this->request->getPost('first_name', FILTER_SANITIZE_STRING); //TODO: duplicated code $last_name = $this->request->getPost('last_name', FILTER_SANITIZE_STRING); @@ -162,7 +162,7 @@ class Employees extends Persons if($this->employee->save_employee($person_data, $employee_data, $grants_array, $employee_id)) { // New employee - if($employee_id == -1) + if($employee_id == NEW_ENTRY) { echo json_encode ([ 'success' => TRUE, @@ -184,7 +184,7 @@ class Employees extends Persons echo json_encode ([ 'success' => FALSE, 'message' => lang('Employees.error_adding_updating') . ' ' . $first_name . ' ' . $last_name, - 'id' => -1 + 'id' => NEW_ENTRY ]); } } @@ -192,7 +192,7 @@ class Employees extends Persons /** * This deletes employees from the employees table */ - public function delete(): void + public function postDelete(): void { $employees_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_STRING); @@ -215,7 +215,7 @@ class Employees extends Persons */ public function check_username($employee_id): void { - $exists = $this->employee->username_exists($employee_id, $this->request->getGet('username', FILTER_SANITIZE_STRING)); + $exists = $this->employee->username_exists($employee_id, $this->request->getVar('username', FILTER_SANITIZE_STRING)); echo !$exists ? 'true' : 'false'; } -} \ No newline at end of file +} diff --git a/app/Controllers/Expenses.php b/app/Controllers/Expenses.php index 66618d385..eba38e35a 100644 --- a/app/Controllers/Expenses.php +++ b/app/Controllers/Expenses.php @@ -36,16 +36,16 @@ class Expenses extends Secure_Controller echo view('expenses/manage', $data); } - public function search(): void + public function getSearch(): void { - $search = $this->request->getGet('search', FILTER_SANITIZE_STRING); - $limit = $this->request->getGet('limit', FILTER_SANITIZE_NUMBER_INT); - $offset = $this->request->getGet('offset', FILTER_SANITIZE_NUMBER_INT); - $sort = $this->request->getGet('sort', FILTER_SANITIZE_STRING); - $order = $this->request->getGet('order', FILTER_SANITIZE_STRING); + $search = $this->request->getVar('search', FILTER_SANITIZE_STRING); + $limit = $this->request->getVar('limit', FILTER_SANITIZE_NUMBER_INT); + $offset = $this->request->getVar('offset', FILTER_SANITIZE_NUMBER_INT); + $sort = $this->request->getVar('sort', FILTER_SANITIZE_STRING); + $order = $this->request->getVar('order', FILTER_SANITIZE_STRING); $filters = [ - 'start_date' => $this->request->getGet('start_date', FILTER_SANITIZE_STRING), - 'end_date' => $this->request->getGet('end_date', FILTER_SANITIZE_STRING), + 'start_date' => $this->request->getVar('start_date', FILTER_SANITIZE_STRING), + 'end_date' => $this->request->getVar('end_date', FILTER_SANITIZE_STRING), 'only_cash' => FALSE, 'only_due' => FALSE, 'only_check' => FALSE, @@ -55,7 +55,7 @@ class Expenses extends Secure_Controller ]; // check if any filter is set in the multiselect dropdown - $filledup = array_fill_keys($this->request->getGet('filters', FILTER_SANITIZE_STRING), TRUE); //TODO: variable naming does not match standard + $filledup = array_fill_keys($this->request->getVar('filters', FILTER_SANITIZE_STRING), TRUE); //TODO: variable naming does not match standard $filters = array_merge($filters, $filledup); $expenses = $this->expense->search($search, $filters, $limit, $offset, $sort, $order); $total_rows = $this->expense->get_found_rows($search, $filters); @@ -76,7 +76,7 @@ class Expenses extends Secure_Controller echo json_encode (['total' => $total_rows, 'rows' => $data_rows, 'payment_summary' => $payment_summary]); } - public function view(int $expense_id = -1): void //TODO: Replace -1 with a constant + public function getView(int $expense_id = NEW_ENTRY): void { $data = []; //TODO: Duplicated code @@ -125,7 +125,7 @@ class Expenses extends Secure_Controller echo view("expenses/form", $data); } - public function get_row(int $row_id) + public function getRow(int $row_id): vpid { $expense_info = $this->expense->get_info($row_id); $data_row = get_expenses_data_row($expense_info); @@ -133,7 +133,7 @@ class Expenses extends Secure_Controller echo json_encode($data_row); } - public function save(int $expense_id = -1): void //TODO: Replace -1 with a constant + public function postSave(int $expense_id = NEW_ENTRY): void { $config = config('OSPOS')->settings; $newdate = $this->request->getPost('date', FILTER_SANITIZE_STRING); @@ -156,7 +156,7 @@ class Expenses extends Secure_Controller if($this->expense->save_value($expense_data, $expense_id)) { //New Expense - if($expense_id == -1) + if($expense_id == NEW_ENTRY) { echo json_encode (['success' => TRUE, 'message' => lang('Expenses.successful_adding'), 'id' => $expense_data['expense_id']]); } @@ -167,7 +167,7 @@ class Expenses extends Secure_Controller } else//failure { - echo json_encode (['success' => FALSE, 'message' => lang('Expenses.error_adding_updating'), 'id' => -1]); //TODO: Need to replace -1 with a constant + echo json_encode (['success' => FALSE, 'message' => lang('Expenses.error_adding_updating'), 'id' => NEW_ENTRY]); } } @@ -178,7 +178,7 @@ class Expenses extends Secure_Controller echo json_encode (['success' => $parsed_value !== FALSE]); } - public function delete(): void + public function postDelete(): void { $expenses_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_STRING); diff --git a/app/Controllers/Expenses_categories.php b/app/Controllers/Expenses_categories.php index 2a710b8bb..32a6083c4 100644 --- a/app/Controllers/Expenses_categories.php +++ b/app/Controllers/Expenses_categories.php @@ -26,13 +26,13 @@ class Expenses_categories extends Secure_Controller //TODO: Is this class ever u /* Returns expense_category_manage table data rows. This will be called with AJAX. */ - public function search(): void + public function getSearch(): void { - $search = $this->request->getGet('search', FILTER_SANITIZE_STRING); - $limit = $this->request->getGet('limit', FILTER_SANITIZE_NUMBER_INT); - $offset = $this->request->getGet('offset', FILTER_SANITIZE_NUMBER_INT); - $sort = $this->request->getGet('sort', FILTER_SANITIZE_STRING); - $order = $this->request->getGet('order', FILTER_SANITIZE_STRING); + $search = $this->request->getVar('search', FILTER_SANITIZE_STRING); + $limit = $this->request->getVar('limit', FILTER_SANITIZE_NUMBER_INT); + $offset = $this->request->getVar('offset', FILTER_SANITIZE_NUMBER_INT); + $sort = $this->request->getVar('sort', FILTER_SANITIZE_STRING); + $order = $this->request->getVar('order', FILTER_SANITIZE_STRING); $expense_categories = $this->expense_category->search($search, $limit, $offset, $sort, $order); $total_rows = $this->expense_category->get_found_rows($search); @@ -46,21 +46,21 @@ class Expenses_categories extends Secure_Controller //TODO: Is this class ever u echo json_encode (['total' => $total_rows, 'rows' => $data_rows]); } - public function get_row(int $row_id): void + public function getRow(int $row_id): void { $data_row = get_expense_category_data_row($this->expense_category->get_info($row_id)); echo json_encode($data_row); } - public function view(int $expense_category_id = -1): void //TODO: Replace -1 with a constant + public function getView(int $expense_category_id = NEW_ENTRY): void { $data['category_info'] = $this->expense_category->get_info($expense_category_id); echo view("expenses_categories/form", $data); } - public function save(int $expense_category_id = -1): void //TODO: Replace -1 with a constant + public function postSave(int $expense_category_id = NEW_ENTRY): void { $expense_category_data = [ 'category_name' => $this->request->getPost('category_name', FILTER_SANITIZE_STRING), @@ -70,7 +70,7 @@ class Expenses_categories extends Secure_Controller //TODO: Is this class ever u if($this->expense_category->save_value($expense_category_data, $expense_category_id)) //TODO: Reflection exception { // New expense_category - if($expense_category_id == -1) //TODO: Replace -1 with a constant. + if($expense_category_id == NEW_ENTRY) { echo json_encode ([ 'success' => TRUE, @@ -88,16 +88,16 @@ class Expenses_categories extends Secure_Controller //TODO: Is this class ever u } } else//failure - {//TODO: need to replace -1 for a constant + { echo json_encode ([ 'success' => FALSE, 'message' => lang('Expenses_categories.error_adding_updating') . ' ' . $expense_category_data['category_name'], - 'id' => -1 + 'id' => NEW_ENTRY ]); } } - public function delete(): void + public function postDelete(): void { $expense_category_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_STRING); diff --git a/app/Controllers/Giftcards.php b/app/Controllers/Giftcards.php index bc85a7af7..b64c63814 100644 --- a/app/Controllers/Giftcards.php +++ b/app/Controllers/Giftcards.php @@ -26,13 +26,13 @@ class Giftcards extends Secure_Controller /* Returns Giftcards table data rows. This will be called with AJAX. */ - public function search(): void + public function getSearch(): void { - $search = $this->request->getGet('search', FILTER_SANITIZE_STRING); - $limit = $this->request->getGet('limit', FILTER_SANITIZE_NUMBER_INT); - $offset = $this->request->getGet('offset', FILTER_SANITIZE_NUMBER_INT); - $sort = $this->request->getGet('sort', FILTER_SANITIZE_STRING); - $order = $this->request->getGet('order', FILTER_SANITIZE_STRING); + $search = $this->request->getVar('search', FILTER_SANITIZE_STRING); + $limit = $this->request->getVar('limit', FILTER_SANITIZE_NUMBER_INT); + $offset = $this->request->getVar('offset', FILTER_SANITIZE_NUMBER_INT); + $sort = $this->request->getVar('sort', FILTER_SANITIZE_STRING); + $order = $this->request->getVar('order', FILTER_SANITIZE_STRING); $giftcards = $this->giftcard->search($search, $limit, $offset, $sort, $order); $total_rows = $this->giftcard->get_found_rows($search); @@ -50,9 +50,9 @@ class Giftcards extends Secure_Controller Gives search suggestions based on what is being searched for */ - public function suggest(): void + public function getSuggest(): void { - $suggestions = $this->giftcard->get_search_suggestions($this->request->getGet('term', FILTER_SANITIZE_STRING), TRUE); + $suggestions = $this->giftcard->get_search_suggestions($this->request->getVar('term', FILTER_SANITIZE_STRING), TRUE); echo json_encode($suggestions); } @@ -64,14 +64,14 @@ class Giftcards extends Secure_Controller echo json_encode($suggestions); } - public function get_row(int $row_id): void + public function getRow(int $row_id): void { $data_row = get_giftcard_data_row($this->giftcard->get_info($row_id)); echo json_encode($data_row); } - public function view(int $giftcard_id = -1): void //TODO: Need to replace -1 with a constant + public function getView(int $giftcard_id = NEW_ENTRY): void { $config = config('OSPOS')->settings; $giftcard_info = $this->giftcard->get_info($giftcard_id); @@ -84,7 +84,8 @@ class Giftcards extends Secure_Controller } else { - $max_giftnumber = isset($this->giftcard->get_max_number()->giftcard_number) ? $this->Giftcard->get_max_number()->giftcard_number : 0; //TODO: variable does not follow naming standard. + $max_number_obj = $this->giftcard->get_max_number(); + $max_giftnumber = isset($max_number_obj) ? $this->giftcard->get_max_number()->giftcard_number : 0; //TODO: variable does not follow naming standard. $data['giftcard_number'] = $giftcard_id > 0 ? $giftcard_info->giftcard_number : $max_giftnumber + 1; } $data['giftcard_id'] = $giftcard_id; @@ -93,11 +94,11 @@ class Giftcards extends Secure_Controller echo view("giftcards/form", $data); } - public function save(int $giftcard_id = -1): void //TODO: Replace -1 with a constant + public function postSave(int $giftcard_id = NEW_ENTRY): void { $giftcard_number = $this->request->getPost('giftcard_number', FILTER_SANITIZE_STRING); - if($giftcard_id == -1 && trim($giftcard_number) == '') + if($giftcard_id == NEW_ENTRY && trim($giftcard_number) == '') { $giftcard_number = $this->giftcard->generate_unique_giftcard_name($this->request->getPost('giftcard_amount', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); } @@ -112,7 +113,7 @@ class Giftcards extends Secure_Controller if($this->giftcard->save_value($giftcard_data, $giftcard_id)) { //New giftcard - if($giftcard_id == -1) //TODO: Constant needed + if($giftcard_id == NEW_ENTRY) //TODO: Constant needed { echo json_encode ([ 'success' => TRUE, @@ -134,7 +135,7 @@ class Giftcards extends Secure_Controller echo json_encode ([ 'success' => FALSE, 'message' => lang('Giftcards.error_adding_updating') . ' ' . $giftcard_data['giftcard_number'], - 'id' => -1 + 'id' => NEW_ENTRY ]); } } @@ -144,13 +145,13 @@ class Giftcards extends Secure_Controller * * @return void */ - public function ajax_check_number_giftcard(): void + public function postCheckNumberGiftcard(): void { $parsed_value = parse_decimals($this->request->getPost('giftcard_amount', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); echo json_encode (['success' => $parsed_value !== FALSE, 'giftcard_amount' => to_currency_no_money($parsed_value)]); } - public function delete(): void + public function postDelete(): void { $giftcards_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_STRING); diff --git a/app/Controllers/Home.php b/app/Controllers/Home.php index b27cf89d9..3cecb5a26 100644 --- a/app/Controllers/Home.php +++ b/app/Controllers/Home.php @@ -2,6 +2,8 @@ namespace App\Controllers; +use CodeIgniter\HTTP\RedirectResponse; + class Home extends Secure_Controller { public function __construct() @@ -15,7 +17,7 @@ class Home extends Secure_Controller echo view('home/home'); } - public function getLogout(): \CodeIgniter\HTTP\RedirectResponse + public function getLogout(): RedirectResponse { $this->employee->logout(); return redirect()->to('login'); diff --git a/app/Controllers/Item_kits.php b/app/Controllers/Item_kits.php index 8535ce184..4f8e43680 100644 --- a/app/Controllers/Item_kits.php +++ b/app/Controllers/Item_kits.php @@ -74,13 +74,13 @@ class Item_kits extends Secure_Controller /** * Returns Item_kit table data rows. This will be called with AJAX. */ - public function search(): void + public function getSearch(): void { - $search = $this->request->getGet('search', FILTER_SANITIZE_STRING); - $limit = $this->request->getGet('limit', FILTER_SANITIZE_NUMBER_INT); - $offset = $this->request->getGet('offset', FILTER_SANITIZE_NUMBER_INT); - $sort = $this->request->getGet('sort', FILTER_SANITIZE_STRING); - $order = $this->request->getGet('order', FILTER_SANITIZE_STRING); + $search = $this->request->getVar('search', FILTER_SANITIZE_STRING); + $limit = $this->request->getVar('limit', FILTER_SANITIZE_NUMBER_INT); + $offset = $this->request->getVar('offset', FILTER_SANITIZE_NUMBER_INT); + $sort = $this->request->getVar('sort', FILTER_SANITIZE_STRING); + $order = $this->request->getVar('order', FILTER_SANITIZE_STRING); $item_kits = $this->item_kit->search($search, $limit, $offset, $sort, $order); $total_rows = $this->item_kit->get_found_rows($search); @@ -103,7 +103,7 @@ class Item_kits extends Secure_Controller echo json_encode($suggestions); } - public function get_row(int $row_id): void + public function getRow(int $row_id): void { // calculate the total cost and retail price of the Kit, so it can be added to the table refresh $item_kit = $this->_add_totals_to_item_kit($this->item_kit->get_info($row_id)); @@ -111,11 +111,11 @@ class Item_kits extends Secure_Controller echo json_encode(get_item_kit_data_row($item_kit)); } - public function view(int $item_kit_id = -1): void //TODO: Replace -1 with a constant + public function getView(int $item_kit_id = NEW_ENTRY): void { $info = $this->item_kit->get_info($item_kit_id); - if($item_kit_id == -1) //TODO: Replace -1 with a constant + if($item_kit_id == NEW_ENTRY) { $info->price_option = '0'; $info->print_option = PRINT_ALL; @@ -150,7 +150,7 @@ class Item_kits extends Secure_Controller echo view("item_kits/form", $data); } - public function save(int $item_kit_id = -1): void //TODO: Replace -1 with a constant + public function postSave(int $item_kit_id = NEW_ENTRY): void { $item_kit_data = [ 'name' => $this->request->getPost('name', FILTER_SANITIZE_STRING), @@ -167,7 +167,7 @@ class Item_kits extends Secure_Controller { $new_item = FALSE; //New item kit - if($item_kit_id == -1) //TODO: Replace -1 with a constant + if($item_kit_id == NEW_ENTRY) { $item_kit_id = $item_kit_data['item_kit_id']; $new_item = TRUE; @@ -213,12 +213,12 @@ class Item_kits extends Secure_Controller echo json_encode ([ 'success' => FALSE, 'message' => lang('Item_kits.error_adding_updating') . ' ' . $item_kit_data['name'], - 'id' => -1 //TODO: Replace -1 with a constant + 'id' => NEW_ENTRY ]); } } - public function delete(): void + public function postDelete(): void { $item_kits_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_STRING); diff --git a/app/Controllers/Items.php b/app/Controllers/Items.php index 6f0785ef8..ff51cde8c 100644 --- a/app/Controllers/Items.php +++ b/app/Controllers/Items.php @@ -43,6 +43,8 @@ class Items extends Secure_Controller { parent::__construct('items'); + $this->session = Services::session(); + $this->image = Services::image(); $this->barcode_lib = new Barcode_lib(); @@ -85,21 +87,21 @@ class Items extends Secure_Controller /* * Returns Items table data rows. This will be called with AJAX. */ - public function search(): void + public function getSearch(): void { - $search = $this->request->getGet('search', FILTER_SANITIZE_STRING); - $limit = $this->request->getGet('limit', FILTER_SANITIZE_NUMBER_INT); - $offset = $this->request->getGet('offset', FILTER_SANITIZE_NUMBER_INT); - $sort = $this->request->getGet('sort', FILTER_SANITIZE_STRING); - $order = $this->request->getGet('order', FILTER_SANITIZE_STRING); + $search = $this->request->getVar('search', FILTER_SANITIZE_STRING); + $limit = $this->request->getVar('limit', FILTER_SANITIZE_NUMBER_INT); + $offset = $this->request->getVar('offset', FILTER_SANITIZE_NUMBER_INT); + $sort = $this->request->getVar('sort', FILTER_SANITIZE_STRING); + $order = $this->request->getVar('order', FILTER_SANITIZE_STRING); - $this->item_lib->set_item_location($this->request->getGet('stock_location', FILTER_SANITIZE_NUMBER_INT)); + $this->item_lib->set_item_location($this->request->getVar('stock_location', FILTER_SANITIZE_NUMBER_INT)); $definition_names = $this->attribute->get_definitions_by_flags(Attribute::SHOW_IN_ITEMS); $filters = [ - 'start_date' => $this->request->getGet('start_date', FILTER_SANITIZE_STRING), - 'end_date' => $this->request->getGet('end_date', FILTER_SANITIZE_STRING), + 'start_date' => $this->request->getVar('start_date', FILTER_SANITIZE_STRING), + 'end_date' => $this->request->getVar('end_date', FILTER_SANITIZE_STRING), 'stock_location_id' => $this->item_lib->get_item_location(), 'empty_upc' => FALSE, 'low_inventory' => FALSE, @@ -112,7 +114,7 @@ class Items extends Secure_Controller ]; //Check if any filter is set in the multiselect dropdown - $filledup = array_fill_keys($this->request->getGet('filters', FILTER_SANITIZE_STRING), TRUE); //TODO: filled up does not meet naming standards + $filledup = array_fill_keys($this->request->getVar('filters', FILTER_SANITIZE_STRING), TRUE); //TODO: filled up does not meet naming standards $filters = array_merge($filters, $filledup); $items = $this->item->search($search, $filters, $limit, $offset, $sort, $order); $total_rows = $this->item->get_found_rows($search, $filters); @@ -209,7 +211,7 @@ class Items extends Secure_Controller /** * Gives search suggestions based on what is being searched for. Called from the view. */ - public function suggest_category(): void + public function getSuggestCategory(): void { $suggestions = $this->item->get_category_suggestions($this->request->getGet('term', FILTER_SANITIZE_STRING)); @@ -219,14 +221,14 @@ class Items extends Secure_Controller /** * Gives search suggestions based on what is being searched for. Called from the view. */ - public function suggest_location(): void + public function getSuggestLocation(): void { $suggestions = $this->item->get_location_suggestions($this->request->getGet('term', FILTER_SANITIZE_STRING)); echo json_encode($suggestions); } - public function get_row(string $item_ids): void //TODO: It's possible an array would be better. + public function getRow(string $item_ids): void //TODO: It's possible an array would be better. { $item_infos = $this->item->get_multiple_info(explode(':', $item_ids), $this->item_lib->get_item_location()); @@ -240,9 +242,12 @@ class Items extends Secure_Controller echo json_encode($result); } - public function view(int $item_id = NEW_ITEM): void //TODO: Super long function. Perhaps we need to refactor out some methods. + public function getView(int $item_id = NEW_ENTRY): void //TODO: Super long function. Perhaps we need to refactor out some methods. { - if($item_id === NEW_ITEM) + // Set default values + if($item_id == null) $item_id = NEW_ENTRY; + + if($item_id === NEW_ENTRY) { $data = []; } @@ -263,14 +268,9 @@ class Items extends Secure_Controller $item_info = $this->item->get_info($item_id); - foreach(get_object_vars($item_info) as $property => $value) - { - $item_info->$property = $value; - } - if($data['allow_temp_item'] === 1) { - if($item_id !== NEW_ITEM) + if($item_id !== NEW_ENTRY) { if($item_info->item_type != ITEM_TEMP) { @@ -300,7 +300,7 @@ class Items extends Secure_Controller $data['selected_category'] = $item_info->category; } - if($item_id === NEW_ITEM) + if($item_id === NEW_ENTRY) { $data['default_tax_1_rate'] = $this->config['default_tax_1_rate']; $data['default_tax_2_rate'] = $this->config['default_tax_2_rate']; @@ -327,6 +327,7 @@ class Items extends Secure_Controller && !($this->config['derive_sale_quantity'] === '1') ); + $data['item_info'] = $item_info; $suppliers = ['' => lang('Items.none')]; @@ -377,7 +378,7 @@ class Items extends Secure_Controller $data['tax_category'] = ''; } - $data['logo_exists'] = $item_info->pic_filename !== ''; + $data['logo_exists'] = $item_info->pic_filename !== null; $file_extension = pathinfo($item_info->pic_filename, PATHINFO_EXTENSION); if(empty($file_extension)) @@ -395,14 +396,14 @@ class Items extends Secure_Controller foreach($stock_locations as $location) { $quantity = $this->item_quantity->get_item_quantity($item_id, $location['location_id'])->quantity; - $quantity = ($item_id === NEW_ITEM) ? 0 : $quantity; + $quantity = ($item_id === NEW_ENTRY) ? 0 : $quantity; $location_array[$location['location_id']] = ['location_name' => $location['location_name'], 'quantity' => $quantity]; $data['stock_locations'] = $location_array; } $data['selected_low_sell_item_id'] = $item_info->low_sell_item_id; - if($item_id !== NEW_ITEM && $item_info->item_id !== $item_info->low_sell_item_id) + if($item_id !== NEW_ENTRY && $item_info->item_id !== $item_info->low_sell_item_id) { $low_sell_item_info = $this->item->get_info($item_info->low_sell_item_id); $data['selected_low_sell_item'] = implode(NAME_SEPARATOR, [$low_sell_item_info->name, $low_sell_item_info->pack_name]); @@ -415,7 +416,7 @@ class Items extends Secure_Controller echo view('items/form', $data); } - public function inventory(int $item_id = NEW_ITEM): void + public function inventory(int $item_id = NEW_ENTRY): void { $item_info = $this->item->get_info($item_id); //TODO: Duplicate code @@ -439,7 +440,7 @@ class Items extends Secure_Controller echo view('items/form_inventory', $data); } - public function count_details(int $item_id = NEW_ITEM): void + public function getCountDetails(int $item_id = NEW_ENTRY): void { $item_info = $this->item->get_info($item_id); //TODO: Duplicate code @@ -487,7 +488,7 @@ class Items extends Secure_Controller echo view('barcodes/barcode_sheet', $data); } - public function attributes(int $item_id = NEW_ITEM): void + public function getAttributes(int $item_id = NEW_ENTRY): void { $data['item_id'] = $item_id; $definition_ids = json_decode($this->request->getPost('definition_ids', FILTER_SANITIZE_STRING), TRUE); @@ -549,10 +550,14 @@ class Items extends Secure_Controller /** * @throws ReflectionException */ - public function save(int $item_id = NEW_ITEM): void + public function postSave(int $item_id = NEW_ENTRY): void { $upload_success = $this->upload_image(); - $upload_file = $this->request->hasFile('image') ? $this->request->getFile('image') : null; //TODO: https://codeigniter4.github.io/userguide/incoming/incomingrequest.html#uploaded-files + + // TODO the hasFile is not defined, so commenting this out and saving it for last. +// $upload_file = $this->request->hasFile('image') ? $this->request->getFile('image') : null; //TODO: https://codeigniter4.github.io/userguide/incoming/incomingrequest.html#uploaded-files + $upload_file = null; + $receiving_quantity = parse_quantity($this->request->getPost('receiving_quantity', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); $item_type = $this->request->getPost('item_type') === NULL ? ITEM : $this->request->getPost('item_type', FILTER_SANITIZE_NUMBER_INT); @@ -603,10 +608,17 @@ class Items extends Secure_Controller $item_data['tax_category_id'] = empty($this->request->getPost('tax_category_id')) ? NULL : $this->request->getPost('tax_category_id', FILTER_SANITIZE_NUMBER_INT); } - $original_name = $upload_file->getFilename(); - if(!empty($original_name)) + if ($upload_file != NULL) { - $item_data['pic_filename'] = $original_name; + $original_name = $upload_file->getFilename(); + if(!empty($original_name)) + { + $item_data['pic_filename'] = $original_name; + } + } + else + { + $item_data['pic_filename'] = NULL; } $employee_id = $this->employee->get_logged_in_employee_info()->person_id; @@ -616,7 +628,7 @@ class Items extends Secure_Controller $success = TRUE; $new_item = FALSE; - if($item_id === NEW_ITEM) + if($item_id === NEW_ENTRY) { $item_id = $item_data['item_id']; $new_item = TRUE; @@ -717,7 +729,7 @@ class Items extends Secure_Controller { $message = lang('Items.error_adding_updating') . ' ' . $item_data['name']; - echo json_encode (['success' => FALSE, 'message' => $message, 'id' => NEW_ITEM]); + echo json_encode (['success' => FALSE, 'message' => $message, 'id' => NEW_ENTRY]); } } @@ -762,7 +774,12 @@ class Items extends Secure_Controller } - public function check_item_number(): void + /** + * Ajax call to check to see if the item number, a.k.a. barcode, is already used by another item + * If it exists then that is an error condition so return TRUE for "error found" + * @return string + */ + public function postCheckItemNumber(): void { $exists = $this->item->item_number_exists($this->request->getPost('item_number', FILTER_SANITIZE_STRING), $this->request->getPost('item_id', FILTER_SANITIZE_NUMBER_INT)); echo !$exists ? 'true' : 'false'; @@ -773,7 +790,7 @@ class Items extends Secure_Controller */ public function check_kit_exists(): void //TODO: This function appears to be never called in the code. Need to confirm. { - if($this->request->getPost('item_number', FILTER_SANITIZE_STRING) === NEW_ITEM) + if($this->request->getPost('item_number', FILTER_SANITIZE_STRING) === NEW_ENTRY) { $exists = $this->item_kit->item_kit_exists_for_name($this->request->getPost('name', FILTER_SANITIZE_STRING)); //TODO: item_kit_exists_for_name doesn't exist in Item_kit. I looked at the blame and it appears to have never existed. } @@ -784,7 +801,7 @@ class Items extends Secure_Controller echo !$exists ? 'true' : 'false'; } - public function remove_logo($item_id): void + public function getRemoveLogo($item_id): void { $item_data = ['pic_filename' => NULL]; $result = $this->item->save_value($item_data, $item_id); @@ -795,7 +812,7 @@ class Items extends Secure_Controller /** * @throws ReflectionException */ - public function save_inventory($item_id = NEW_ITEM): void + public function save_inventory($item_id = NEW_ENTRY): void { $employee_id = $this->employee->get_logged_in_employee_info()->person_id; $cur_item_info = $this->item->get_info($item_id); @@ -829,7 +846,7 @@ class Items extends Secure_Controller { $message = lang('Items.error_adding_updating') . " $cur_item_info->name"; - echo json_encode (['success' => FALSE, 'message' => $message, 'id' => NEW_ITEM]); + echo json_encode (['success' => FALSE, 'message' => $message, 'id' => NEW_ENTRY]); } } @@ -884,7 +901,7 @@ class Items extends Secure_Controller /** * @throws ReflectionException */ - public function delete(): void + public function postDelete(): void { $items_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT); @@ -909,9 +926,9 @@ class Items extends Secure_Controller force_download($name, $data, TRUE); } - public function csv_import(): void + public function getCsvImport(): void { - echo view('items/form_csv_import', NULL); + echo view('items/form_csv_import'); } /** @@ -936,7 +953,7 @@ class Items extends Secure_Controller $allowed_stock_locations = $this->stock_location->get_allowed_locations(); $attribute_definition_names = $this->attribute->get_definition_names(); - unset($attribute_definition_names[-1]); //Removes the common_none_selected_text from the array + unset($attribute_definition_names[NEW_ENTRY]); //Removes the common_none_selected_text from the array $attribute_data = []; diff --git a/app/Controllers/Messages.php b/app/Controllers/Messages.php index d396e9a5f..938fc8224 100644 --- a/app/Controllers/Messages.php +++ b/app/Controllers/Messages.php @@ -30,7 +30,7 @@ class Messages extends Secure_Controller echo view('messages/sms'); } - public function view(int $person_id = -1): void //TODO: Replace -1 with a constant + public function getView(int $person_id = NEW_ENTRY): void { $info = $this->person->get_info($person_id); foreach(get_object_vars($info) as $property => $value) @@ -65,7 +65,7 @@ class Messages extends Secure_Controller * @param int $person_id * @return void */ - public function send_form(int $person_id = -1): void //TODO: Replace -1 with a constant + public function send_form(int $person_id = NEW_ENTRY): void { $phone = $this->request->getPost('phone', FILTER_SANITIZE_STRING); $message = $this->request->getPost('message', FILTER_SANITIZE_STRING); @@ -77,7 +77,7 @@ class Messages extends Secure_Controller echo json_encode ([ 'success' => TRUE, 'message' => lang('Messages.successfully_sent') . ' ' . esc($phone), - 'person_id' => $person_id //TODO: Replace -1 with a constant + 'person_id' => $person_id ]); } else @@ -85,7 +85,7 @@ class Messages extends Secure_Controller echo json_encode ([ 'success' => FALSE, 'message' => lang('Messages.unsuccessfully_sent') . ' ' . esc($phone), - 'person_id' => -1 //TODO: Replace -1 with a constant + 'person_id' => NEW_ENTRY ]); } } diff --git a/app/Controllers/Persons.php b/app/Controllers/Persons.php index d13070b4b..4b245554e 100644 --- a/app/Controllers/Persons.php +++ b/app/Controllers/Persons.php @@ -36,7 +36,7 @@ abstract class Persons extends Secure_Controller /** * Gets one row for a person manage table. This is called using AJAX to update one row. */ - public function get_row(int $row_id): void + public function getRow(int $row_id): void { $data_row = get_person_data_row($this->person->get_info($row_id)); diff --git a/app/Controllers/Receivings.php b/app/Controllers/Receivings.php index 10c2a4d4a..6dd022b23 100644 --- a/app/Controllers/Receivings.php +++ b/app/Controllers/Receivings.php @@ -53,10 +53,10 @@ class Receivings extends Secure_Controller * Called in the view. * @return void */ - public function item_search(): void + public function getItemSearch(): void { - $suggestions = $this->item->get_search_suggestions($this->request->getGet('term', FILTER_SANITIZE_STRING), ['search_custom' => FALSE, 'is_deleted' => FALSE], TRUE); - $suggestions = array_merge($suggestions, $this->item_kit->get_search_suggestions($this->request->getGet('term', FILTER_SANITIZE_STRING))); + $suggestions = $this->item->get_search_suggestions($this->request->getVar('term', FILTER_SANITIZE_STRING), ['search_custom' => FALSE, 'is_deleted' => FALSE], TRUE); + $suggestions = array_merge($suggestions, $this->item_kit->get_search_suggestions($this->request->getVar('term', FILTER_SANITIZE_STRING))); echo json_encode($suggestions); } @@ -65,10 +65,10 @@ class Receivings extends Secure_Controller * Called in the view. * @return void */ - public function stock_item_search(): void + public function getStockItemSearch(): void { - $suggestions = $this->item->get_stock_search_suggestions($this->request->getGet('term', FILTER_SANITIZE_STRING), ['search_custom' => FALSE, 'is_deleted' => FALSE], TRUE); - $suggestions = array_merge($suggestions, $this->item_kit->get_search_suggestions($this->request->getGet('term', FILTER_SANITIZE_STRING))); + $suggestions = $this->item->get_stock_search_suggestions($this->request->getVar('term', FILTER_SANITIZE_STRING), ['search_custom' => FALSE, 'is_deleted' => FALSE], TRUE); + $suggestions = array_merge($suggestions, $this->item_kit->get_search_suggestions($this->request->getVar('term', FILTER_SANITIZE_STRING))); echo json_encode($suggestions); } @@ -162,7 +162,7 @@ class Receivings extends Secure_Controller * @param $item_id * @return void */ - public function edit_item($item_id): void + public function postEditItem($item_id): void { $data = []; @@ -223,7 +223,7 @@ class Receivings extends Secure_Controller * @param $item_number * @return void */ - public function delete_item($item_number): void + public function getDeleteItem($item_number): void { $this->receiving_lib->delete_item($item_number); @@ -233,7 +233,7 @@ class Receivings extends Secure_Controller /** * @throws ReflectionException */ - public function delete(int $receiving_id = -1, bool $update_inventory = TRUE) : void + public function postDelete(int $receiving_id = -1, bool $update_inventory = TRUE) : void { $employee_id = $this->employee->get_logged_in_employee_info()->person_id; $receiving_ids = $receiving_id == -1 ? $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT) : [$receiving_id]; //TODO: Replace -1 with constant diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php index a70977aa0..cef276a21 100644 --- a/app/Controllers/Sales.php +++ b/app/Controllers/Sales.php @@ -43,11 +43,13 @@ use ReflectionException; */ class Sales extends Secure_Controller { + protected $helpers = ['form', 'file']; + public function __construct() { parent::__construct('sales'); - helper('file'); +// helper('file'); $this->session = session(); $this->barcode_lib = new Barcode_lib(); @@ -59,6 +61,8 @@ class Sales extends Secure_Controller $this->customer = model('Customer'); $this->sale = model('Sale'); + $this->item = model('Item'); + $this->item_kit = model('Item_kit'); $this->stock_location = model('Stock_location'); } @@ -91,7 +95,7 @@ class Sales extends Secure_Controller } } - public function get_row(int $row_id): void + public function getRow(int $row_id): void { $sale_info = $this->sale->get_info($row_id)->getRow(); $data_row = get_sale_data_row($sale_info); @@ -99,29 +103,29 @@ class Sales extends Secure_Controller echo json_encode($data_row); } - public function search(): void + public function getSearch(): void { - $search = $this->request->getGet('search', FILTER_SANITIZE_STRING); - $limit = $this->request->getGet('limit', FILTER_SANITIZE_NUMBER_INT); - $offset = $this->request->getGet('offset', FILTER_SANITIZE_NUMBER_INT); - $sort = $this->request->getGet('sort', FILTER_SANITIZE_STRING); - $order = $this->request->getGet('order', FILTER_SANITIZE_STRING); + $search = $this->request->getVar('search', FILTER_SANITIZE_STRING); + $limit = $this->request->getVar('limit', FILTER_SANITIZE_NUMBER_INT); + $offset = $this->request->getVar('offset', FILTER_SANITIZE_NUMBER_INT); + $sort = $this->request->getVar('sort', FILTER_SANITIZE_STRING); + $order = $this->request->getVar('order', FILTER_SANITIZE_STRING); $filters = [ 'sale_type' => 'all', 'location_id' => 'all', - 'start_date' => $this->request->getGet('start_date', FILTER_SANITIZE_STRING), - 'end_date' => $this->request->getGet('end_date', FILTER_SANITIZE_STRING), + 'start_date' => $this->request->getVar('start_date', FILTER_SANITIZE_STRING), + 'end_date' => $this->request->getVar('end_date', FILTER_SANITIZE_STRING), 'only_cash' => FALSE, 'only_due' => FALSE, 'only_check' => FALSE, 'only_creditcard' => FALSE, - 'only_invoices' => $this->config['invoice_enable'] && $this->request->getGet('only_invoices', FILTER_SANITIZE_NUMBER_INT), + 'only_invoices' => $this->config['invoice_enable'] && $this->request->getVar('only_invoices', FILTER_SANITIZE_NUMBER_INT), 'is_valid_receipt' => $this->sale->is_valid_receipt($search) ]; // check if any filter is set in the multiselect dropdown - $filledup = array_fill_keys($this->request->getGet('filters', FILTER_SANITIZE_STRING), TRUE); //TODO: Variable does not meet naming conventions + $filledup = array_fill_keys($this->request->getVar('filters', FILTER_SANITIZE_STRING), TRUE); //TODO: Variable does not meet naming conventions $filters = array_merge($filters, $filledup); $sales = $this->sale->search($search, $filters, $limit, $offset, $sort, $order); @@ -147,7 +151,7 @@ class Sales extends Secure_Controller * Called in the view. * @return void */ - public function item_search(): void + public function getItemSearch(): void { $suggestions = []; $receipt = $search = $this->request->getGet('term') != '' ? $this->request->getGet('term', FILTER_SANITIZE_STRING) : NULL; @@ -322,7 +326,7 @@ class Sales extends Secure_Controller * Multiple Payments. Called in the view. * @return void */ - public function add_payment(): void + public function postAddPayment(): void { $data = []; @@ -331,14 +335,16 @@ class Sales extends Secure_Controller //TODO: See the code block below. This too needs to be ternary notation. if($payment_type !== lang('Sales.giftcard')) { - $this->validator->setRule('amount_tendered', 'lang:sales_amount_tendered', 'trim|required|numeric'); + $rules = ['amount_tendered' => 'trim|required|decimal',]; + $messages = ['amount_tendered' => lang('Sales.must_enter_numeric')]; } else { - $this->validator->setRule('amount_tendered', 'lang:sales_amount_tendered', 'trim|required'); + $rules = ['amount_tendered' => 'trim|required',]; + $messages = ['amount_tendered' => lang('Sales.must_enter_numeric_giftcard')]; } - if(!$this->validate([])) + if(!$this->validate($rules, $messages)) {//TODO: the code below should be refactored to the following ternary notation since it's much more readable and concise: //$data['error'] = $payment_type === lang('Sales.giftcard') // ? $data['error'] = lang('Sales.must_enter_numeric_giftcard') @@ -439,7 +445,7 @@ class Sales extends Secure_Controller } } - $this->_reload($data); //TODO: Hungarian notation + $this->_reload($data); } /** @@ -447,7 +453,7 @@ class Sales extends Secure_Controller * @param string $payment_id * @return void */ - public function delete_payment(string $payment_id): void + public function postDelete_payment(string $payment_id): void { $this->sale_lib->delete_payment($payment_id); @@ -463,7 +469,7 @@ class Sales extends Secure_Controller // check if any discount is assigned to the selected customer $customer_id = $this->sale_lib->get_customer(); - if($customer_id != -1) //TODO: Replace -1 with a constant + if($customer_id != NEW_ENTRY) { // load the customer discount if any $customer_discount = $this->customer->get_info($customer_id)->discount; @@ -554,38 +560,43 @@ class Sales extends Secure_Controller * @param string $line * @return void */ - public function edit_item(string $line): void + public function postEditItem(string $line): void { $data = []; - $this->validator->setRule('price', 'lang:sales_price', 'required|numeric'); - $this->validator->setRule('quantity', 'lang:sales_quantity', 'required|numeric'); - $this->validator->setRule('discount', 'lang:sales_discount', 'required|numeric'); + $rules = [ + 'price' => 'trim|required|numeric', + 'quantity' => 'trim|required|numeric', + 'discount' => 'trim|required|numeric', + ]; - $description = $this->request->getPost('description', FILTER_SANITIZE_STRING); - $serialnumber = $this->request->getPost('serialnumber', FILTER_SANITIZE_STRING); - $price = parse_decimals($this->request->getPost('price', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); - $quantity = parse_quantity($this->request->getPost('quantity', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); - $discount_type = $this->request->getPost('discount_type', FILTER_SANITIZE_STRING); - $discount = $discount_type ? parse_quantity($this->request->getPost('discount', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)) : parse_decimals($this->request->getPost('discount', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); - - $item_location = $this->request->getPost('location', FILTER_SANITIZE_NUMBER_INT); - $discounted_total = $this->request->getPost('discounted_total') != '' ? $this->request->getPost('discounted_total', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION) : NULL; - - if(!$this->validate([])) + if($this->validate($rules)) { + + $description = $this->request->getPost('description', FILTER_SANITIZE_STRING); + $serialnumber = $this->request->getPost('serialnumber', FILTER_SANITIZE_STRING); + $price = parse_decimals($this->request->getPost('price', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); + $quantity = parse_quantity($this->request->getPost('quantity', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); + $discount_type = $this->request->getPost('discount_type', FILTER_SANITIZE_STRING); + $discount = $discount_type ? parse_quantity($this->request->getPost('discount', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)) : parse_decimals($this->request->getPost('discount', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); + + $item_location = $this->request->getPost('location', FILTER_SANITIZE_NUMBER_INT); + $discounted_total = $this->request->getPost('discounted_total') != '' ? $this->request->getPost('discounted_total', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION) : NULL; + + $this->sale_lib->edit_item($line, $description, $serialnumber, $quantity, $discount, $discount_type, $price, $discounted_total); $this->sale_lib->empty_payments(); + + $data['warning'] = $this->sale_lib->out_of_stock($this->sale_lib->get_item_id($line), $item_location); + } else { $data['error'] = lang('Sales.error_editing_item'); } - $data['warning'] = $this->sale_lib->out_of_stock($this->sale_lib->get_item_id($line), $item_location); - - $this->_reload($data); //TODO: Hungarian notation + $this->_reload($data); } /** @@ -594,7 +605,7 @@ class Sales extends Secure_Controller * @return void * @throws ReflectionException */ - public function delete_item(int $item_id): void + public function getDeleteItem(int $item_id): void { $this->sale_lib->delete_item($item_id); @@ -607,7 +618,7 @@ class Sales extends Secure_Controller * Called in the view. * @return void */ - public function remove_customer(): void + public function getRemoveCustomer(): void { $this->sale_lib->clear_giftcard_remainder(); $this->sale_lib->clear_rewards_remainder(); @@ -740,7 +751,7 @@ class Sales extends Secure_Controller } - if($sale_id == -1 && $this->sale->check_invoice_number_exists($invoice_number)) //TODO: Replace -1 with constant + if($sale_id == NEW_ENTRY && $this->sale->check_invoice_number_exists($invoice_number)) { $data['error'] = lang('Sales.invoice_number_duplicate', ['invoice_number' => $invoice_number]); $this->_reload($data); @@ -761,7 +772,7 @@ class Sales extends Secure_Controller // Resort and filter cart lines for printing $data['cart'] = $this->sale_lib->sort_and_filter_cart($data['cart']); - if($data['sale_id_num'] == -1) + if($data['sale_id_num'] == NEW_ENTRY) { $data['error_message'] = lang('Sales.transaction_failed'); } @@ -791,7 +802,7 @@ class Sales extends Secure_Controller $work_order_number = $this->token_lib->render($work_order_format); } - if($sale_id == -1 && $this->sale->check_work_order_number_exists($work_order_number)) + if($sale_id == NEW_ENTRY && $this->sale->check_work_order_number_exists($work_order_number)) { $data['error'] = lang('Sales.work_order_number_duplicate'); $this->_reload($data); @@ -826,7 +837,7 @@ class Sales extends Secure_Controller $quote_number = $this->token_lib->render($quote_format); } - if($sale_id == -1 && $this->sale->check_quote_number_exists($quote_number)) + if($sale_id == NEW_ENTRY && $this->sale->check_quote_number_exists($quote_number)) { $data['error'] = lang('Sales.quote_number_duplicate'); $this->_reload($data); @@ -867,7 +878,7 @@ class Sales extends Secure_Controller $data['cart'] = $this->sale_lib->sort_and_filter_cart($data['cart']); - if($data['sale_id_num'] == -1) //TODO: Replace -1 with a constant + if($data['sale_id_num'] == NEW_ENTRY) { $data['error_message'] = lang('Sales.transaction_failed'); } @@ -963,7 +974,7 @@ class Sales extends Secure_Controller { $customer_info = ''; - if($customer_id != -1) + if($customer_id != NEW_ENTRY) { $customer_info = $this->customer->get_info($customer_id); $data['customer_id'] = $customer_id; @@ -1144,8 +1155,8 @@ class Sales extends Secure_Controller if($sale_id == '') { - $sale_id = -1; - $this->session->set('sale_id', -1); //TODO: replace -1 with a constant + $sale_id = NEW_ENTRY; + $this->session->set('sale_id', NEW_ENTRY); } $cash_rounding = $this->sale_lib->reset_cash_rounding(); @@ -1334,7 +1345,7 @@ class Sales extends Secure_Controller /** * @throws ReflectionException */ - public function delete(int $sale_id = -1, bool $update_inventory = TRUE): void //TODO: Replace -1 with a constant + public function postDelete(int $sale_id = NEW_ENTRY, bool $update_inventory = TRUE): void { $employee_id = $this->employee->get_logged_in_employee_info()->person_id; $has_grant = $this->employee->has_grant('sales_delete', $employee_id); @@ -1345,7 +1356,7 @@ class Sales extends Secure_Controller } else { - $sale_ids = $sale_id == -1 ? $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT) : [$sale_id]; //TODO: Replace -1 with a constant + $sale_ids = $sale_id == NEW_ENTRY ? $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT) : [$sale_id]; if($this->sale->delete_list($sale_ids, $employee_id, $update_inventory)) { @@ -1362,7 +1373,7 @@ class Sales extends Secure_Controller } } - public function restore(int $sale_id = -1, bool $update_inventory = TRUE): void //TODO: Replace -1 with a constant + public function restore(int $sale_id = NEW_ENTRY, bool $update_inventory = TRUE): void { $employee_id = $this->employee->get_logged_in_employee_info()->person_id; $has_grant = $this->employee->has_grant('sales_delete', $employee_id); @@ -1373,7 +1384,7 @@ class Sales extends Secure_Controller } else { - $sale_ids = $sale_id == -1 ? $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT) : [$sale_id]; //TODO: Replace -1 with a constant + $sale_ids = $sale_id == NEW_ENTRY ? $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT) : [$sale_id]; if($this->sale->restore_list($sale_ids, $employee_id, $update_inventory)) { @@ -1396,7 +1407,7 @@ class Sales extends Secure_Controller * @param int $sale_id * @throws ReflectionException */ - public function save(int $sale_id = -1): void //TODO: Replace -1 with a constant + public function save(int $sale_id = NEW_ENTRY): void { $newdate = $this->request->getPost('date', FILTER_SANITIZE_STRING); $employee_id = $this->employee->get_logged_in_employee_info()->person_id; @@ -1455,7 +1466,7 @@ class Sales extends Secure_Controller ]; } - $payment_id = -1; //TODO: Replace -1 with a constant + $payment_id = NEW_ENTRY; $payment_amount = $this->request->getPost('payment_amount_new', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION); $payment_type = $this->request->getPost('payment_type_new', FILTER_SANITIZE_STRING); @@ -1508,7 +1519,7 @@ class Sales extends Secure_Controller public function cancel(): void { $sale_id = $this->sale_lib->get_sale_id(); - if($sale_id != -1 && $sale_id != '') //TODO: Replace -1 with a constant + if($sale_id != NEW_ENTRY && $sale_id != '') { $sale_type = $this->sale_lib->get_sale_type(); @@ -1525,7 +1536,7 @@ class Sales extends Secure_Controller else { $this->sale->delete($sale_id); - $this->session->set('sale_id', -1); //TODO: Replace -1 with a constant + $this->session->set('sale_id', NEW_ENTRY); } } else @@ -1702,7 +1713,7 @@ class Sales extends Secure_Controller $this->sale_lib->set_cart($cart); } - public function search_cart_for_item_id(int $id, array $array) //TODO: The second parameter should not be named array perhaps int $needle_item_id, array $shopping_cart + public function getSearch_cart_for_item_id(int $id, array $array) //TODO: The second parameter should not be named array perhaps int $needle_item_id, array $shopping_cart { foreach($array as $key => $val) //TODO: key and val are not reflective of the contents of the array and should be replaced with descriptive variable names. Perhaps $cart_haystack => $item_details { diff --git a/app/Controllers/Secure_Controller.php b/app/Controllers/Secure_Controller.php index a669d6b0a..29dae7ac9 100644 --- a/app/Controllers/Secure_Controller.php +++ b/app/Controllers/Secure_Controller.php @@ -26,6 +26,7 @@ class Secure_Controller extends BaseController $this->employee = model('Employee'); $this->module = model('Module'); $config = config('OSPOS')->settings; + $validation = \Config\Services::validation(); if(!$this->employee->is_logged_in()) { @@ -67,11 +68,11 @@ class Secure_Controller extends BaseController view('viewData', $global_view_data); } - public function check_numeric() + public function getCheckNumeric() { $result = TRUE; - foreach($this->request->getGet(NULL, FILTER_SANITIZE_STRING) as $str) + foreach($this->request->getVar(NULL, FILTER_SANITIZE_STRING) as $str) { $result &= parse_decimals($str); } @@ -81,9 +82,9 @@ class Secure_Controller extends BaseController // this is the basic set of methods most OSPOS Controllers will implement public function getIndex() { return FALSE; } - public function search() { return FALSE; } + public function getSearch() { return FALSE; } public function suggest_search() { return FALSE; } - 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; } + public function getView(int $data_item_id = -1) { return FALSE; } + public function postSave(int $data_item_id = -1) { return FALSE; } + public function postDelete() { return FALSE; } } diff --git a/app/Controllers/Suppliers.php b/app/Controllers/Suppliers.php index 81197f0ba..763c8e795 100644 --- a/app/Controllers/Suppliers.php +++ b/app/Controllers/Suppliers.php @@ -32,7 +32,7 @@ class Suppliers extends Persons * @param $row_id * @return void */ - public function get_row($row_id): void + public function getRow($row_id): void { $data_row = get_supplier_data_row($this->supplier->get_info($row_id)); $data_row['category'] = $this->supplier->get_category_name($data_row['category']); @@ -44,13 +44,13 @@ class Suppliers extends Persons * Returns Supplier table data rows. This will be called with AJAX. * @return void */ - public function search(): void + public function getSearch(): void { - $search = $this->request->getGet('search', FILTER_SANITIZE_STRING); - $limit = $this->request->getGet('limit', FILTER_SANITIZE_NUMBER_INT); - $offset = $this->request->getGet('offset', FILTER_SANITIZE_NUMBER_INT); - $sort = $this->request->getGet('sort', FILTER_SANITIZE_STRING); - $order = $this->request->getGet('order', FILTER_SANITIZE_STRING); + $search = $this->request->getVar('search', FILTER_SANITIZE_STRING); + $limit = $this->request->getVar('limit', FILTER_SANITIZE_NUMBER_INT); + $offset = $this->request->getVar('offset', FILTER_SANITIZE_NUMBER_INT); + $sort = $this->request->getVar('sort', FILTER_SANITIZE_STRING); + $order = $this->request->getVar('order', FILTER_SANITIZE_STRING); $suppliers = $this->supplier->search($search, $limit, $offset, $sort, $order); $total_rows = $this->supplier->get_found_rows($search); @@ -72,7 +72,7 @@ class Suppliers extends Persons */ public function suggest(): void { - $suggestions = $this->supplier->get_search_suggestions($this->request->getGet('term', FILTER_SANITIZE_STRING), TRUE); + $suggestions = $this->supplier->get_search_suggestions($this->request->getVar('term', FILTER_SANITIZE_STRING), TRUE); echo json_encode($suggestions); } @@ -87,7 +87,7 @@ class Suppliers extends Persons /* Loads the supplier edit form */ - public function view(int $supplier_id = -1): void //TODO: Replace -1 with constant + public function getView(int $supplier_id = NEW_ENTRY): void { $info = $this->supplier->get_info($supplier_id); foreach(get_object_vars($info) as $property => $value) @@ -103,7 +103,7 @@ class Suppliers extends Persons /* Inserts/updates a supplier */ - public function save(int $supplier_id = -1): void //TODO: Replace -1 with constant + public function postSave(int $supplier_id = NEW_ENTRY): void { $first_name = $this->request->getPost('first_name', FILTER_SANITIZE_STRING); //TODO: Duplicate code $last_name = $this->request->getPost('last_name', FILTER_SANITIZE_STRING); @@ -139,7 +139,7 @@ class Suppliers extends Persons if($this->supplier->save_supplier($person_data, $supplier_data, $supplier_id)) { //New supplier - if($supplier_id == -1) //TODO: Replace -1 with a constant + if($supplier_id == NEW_ENTRY) { echo json_encode ([ 'success' => TRUE, @@ -160,7 +160,7 @@ class Suppliers extends Persons echo json_encode ([ 'success' => FALSE, 'message' => lang('Suppliers.error_adding_updating') . ' ' . $supplier_data['company_name'], - 'id' => -1 //TODO: Replace -1 with a constant + 'id' => NEW_ENTRY ]); } } @@ -168,7 +168,7 @@ class Suppliers extends Persons /* This deletes suppliers from the suppliers table */ - public function delete(): void + public function postDelete(): void { $suppliers_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT); diff --git a/app/Controllers/Tax_categories.php b/app/Controllers/Tax_categories.php index d2348f54c..848869301 100644 --- a/app/Controllers/Tax_categories.php +++ b/app/Controllers/Tax_categories.php @@ -26,13 +26,13 @@ class Tax_categories extends Secure_Controller /* * Returns tax_category table data rows. This will be called with AJAX. */ - public function search(): void + public function getSearch(): void { - $search = $this->request->getGet('search', FILTER_SANITIZE_STRING); - $limit = $this->request->getGet('limit', FILTER_SANITIZE_NUMBER_INT); - $offset = $this->request->getGet('offset', FILTER_SANITIZE_NUMBER_INT); - $sort = $this->request->getGet('sort', FILTER_SANITIZE_STRING); - $order = $this->request->getGet('order', FILTER_SANITIZE_STRING); + $search = $this->request->getVar('search', FILTER_SANITIZE_STRING); + $limit = $this->request->getVar('limit', FILTER_SANITIZE_NUMBER_INT); + $offset = $this->request->getVar('offset', FILTER_SANITIZE_NUMBER_INT); + $sort = $this->request->getVar('sort', FILTER_SANITIZE_STRING); + $order = $this->request->getVar('order', FILTER_SANITIZE_STRING); $tax_categories = $this->tax_category->search($search, $limit, $offset, $sort, $order); $total_rows = $this->tax_category->get_found_rows($search); @@ -46,14 +46,14 @@ class Tax_categories extends Secure_Controller echo json_encode (['total' => $total_rows, 'rows' => $data_rows]); } - public function get_row($row_id): void + public function getRow($row_id): void { $data_row = get_tax_categories_data_row($this->tax_category->get_info($row_id)); echo json_encode($data_row); } - public function view(int $tax_category_id = -1): void //TODO: Need to replace -1 with constant + public function getView(int $tax_category_id = NEW_ENTRY): void { $data['tax_category_info'] = $this->tax_category->get_info($tax_category_id); @@ -61,7 +61,7 @@ class Tax_categories extends Secure_Controller } - public function save(int $tax_category_id = -1): void //TODO: Need to replace -1 with constant + public function postSave(int $tax_category_id = NEW_ENTRY): void { $tax_category_data = [ 'tax_category' => $this->request->getPost('tax_category', FILTER_SANITIZE_STRING), @@ -72,7 +72,7 @@ class Tax_categories extends Secure_Controller if($this->tax_category->save_value($tax_category_data, $tax_category_id)) { // New tax_category_id - if($tax_category_id == -1) //TODO: Need to replace -1 with constant + if($tax_category_id == NEW_ENTRY) { echo json_encode ([ 'success' => TRUE, @@ -94,12 +94,12 @@ class Tax_categories extends Secure_Controller echo json_encode ([ 'success' => FALSE, 'message' => lang('Tax_categories.error_adding_updating') . ' ' . $tax_category_data['tax_category'], - 'id' => -1 //TODO: Need to replace -1 with constant + 'id' => NEW_ENTRY ]); } } - public function delete(): void + public function postDelete(): void { $tax_categories_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT); @@ -115,4 +115,4 @@ class Tax_categories extends Secure_Controller echo json_encode (['success' => FALSE, 'message' => lang('Tax_categories.cannot_be_deleted')]); } } -} \ No newline at end of file +} diff --git a/app/Controllers/Tax_codes.php b/app/Controllers/Tax_codes.php index bae34c567..606b551b7 100644 --- a/app/Controllers/Tax_codes.php +++ b/app/Controllers/Tax_codes.php @@ -33,13 +33,13 @@ class Tax_codes extends Secure_Controller /* * Returns tax_category table data rows. This will be called with AJAX. */ - public function search(): void + public function getSearch(): void { - $search = $this->request->getGet('search', FILTER_SANITIZE_STRING); - $limit = $this->request->getGet('limit', FILTER_SANITIZE_NUMBER_INT); - $offset = $this->request->getGet('offset', FILTER_SANITIZE_NUMBER_INT); - $sort = $this->request->getGet('sort', FILTER_SANITIZE_STRING); - $order = $this->request->getGet('order', FILTER_SANITIZE_STRING); + $search = $this->request->getVar('search', FILTER_SANITIZE_STRING); + $limit = $this->request->getVar('limit', FILTER_SANITIZE_NUMBER_INT); + $offset = $this->request->getVar('offset', FILTER_SANITIZE_NUMBER_INT); + $sort = $this->request->getVar('sort', FILTER_SANITIZE_STRING); + $order = $this->request->getVar('order', FILTER_SANITIZE_STRING); $tax_codes = $this->tax_code->search($search, $limit, $offset, $sort, $order); $total_rows = $this->tax_code->get_found_rows($search); @@ -54,14 +54,14 @@ class Tax_codes extends Secure_Controller echo json_encode (['total' => $total_rows, 'rows' => $data_rows]); } - public function get_row(int $row_id): void + public function getRow(int $row_id): void { $data_row = get_tax_code_data_row($this->tax_code->get_info($row_id)); echo json_encode($data_row); } - public function view(int $tax_code_id = -1): void //TODO: Need to replace -1 with constant + public function getView(int $tax_code_id = NEW_ENTRY): void { $data['tax_code_info'] = $this->tax_code->get_info($tax_code_id); @@ -69,7 +69,7 @@ class Tax_codes extends Secure_Controller } - public function save(int $tax_code_id = -1): void //TODO: Need to replace -1 with constant + public function postSave(int $tax_code_id = NEW_ENTRY): void { $tax_code_data = [ 'tax_code' => $this->request->getPost('tax_code', FILTER_SANITIZE_STRING), @@ -80,7 +80,7 @@ class Tax_codes extends Secure_Controller if($this->tax_code->save($tax_code_data)) { - if($tax_code_id == -1) //TODO: Need to replace -1 with constant + if($tax_code_id == NEW_ENTRY) { echo json_encode ([ 'success' => TRUE, @@ -102,12 +102,12 @@ class Tax_codes extends Secure_Controller echo json_encode ([ 'success' => FALSE, 'message' => lang('Tax_codes.error_adding_updating') . ' ' . $tax_code_data['tax_code_id'], - 'id' => -1 + 'id' => NEW_ENTRY ]); } } - public function delete(): void + public function postDelete(): void { $tax_codes_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT); @@ -123,4 +123,4 @@ class Tax_codes extends Secure_Controller echo json_encode (['success' => FALSE, 'message' => lang('Tax_codes.cannot_be_deleted')]); } } -} \ No newline at end of file +} diff --git a/app/Controllers/Tax_jurisdictions.php b/app/Controllers/Tax_jurisdictions.php index 8b49f7597..d621e0483 100644 --- a/app/Controllers/Tax_jurisdictions.php +++ b/app/Controllers/Tax_jurisdictions.php @@ -29,13 +29,13 @@ class Tax_jurisdictions extends Secure_Controller /* * Returns tax_category table data rows. This will be called with AJAX. */ - public function search(): void + public function getSearch(): void { - $search = $this->request->getGet('search', FILTER_SANITIZE_STRING); - $limit = $this->request->getGet('limit', FILTER_SANITIZE_NUMBER_INT); - $offset = $this->request->getGet('offset', FILTER_SANITIZE_NUMBER_INT); - $sort = $this->request->getGet('sort', FILTER_SANITIZE_STRING); - $order = $this->request->getGet('order', FILTER_SANITIZE_STRING); + $search = $this->request->getVar('search', FILTER_SANITIZE_STRING); + $limit = $this->request->getVar('limit', FILTER_SANITIZE_NUMBER_INT); + $offset = $this->request->getVar('offset', FILTER_SANITIZE_NUMBER_INT); + $sort = $this->request->getVar('sort', FILTER_SANITIZE_STRING); + $order = $this->request->getVar('order', FILTER_SANITIZE_STRING); $tax_jurisdictions = $this->tax_jurisdiction->search($search, $limit, $offset, $sort, $order); $total_rows = $this->tax_jurisdiction->get_found_rows($search); @@ -49,14 +49,14 @@ class Tax_jurisdictions extends Secure_Controller echo json_encode (['total' => $total_rows, 'rows' => $data_rows]); } - public function get_row(int $row_id): void + public function getRow(int $row_id): void { $data_row = get_tax_jurisdictions_data_row($this->tax_jurisdiction->get_info($row_id)); echo json_encode($data_row); } - public function view(int $tax_jurisdiction_id = -1): void //TODO: Replace -1 with constant + public function getView(int $tax_jurisdiction_id = NEW_ENTRY): void { $data['tax_jurisdiction_info'] = $this->tax_jurisdiction->get_info($tax_jurisdiction_id); @@ -64,7 +64,7 @@ class Tax_jurisdictions extends Secure_Controller } - public function save(int $jurisdiction_id = -1): void //TODO: Replace -1 with constant + public function postSave(int $jurisdiction_id = NEW_ENTRY): void { $tax_jurisdiction_data = [ 'jurisdiction_name' => $this->request->getPost('jurisdiction_name', FILTER_SANITIZE_STRING), @@ -73,7 +73,7 @@ class Tax_jurisdictions extends Secure_Controller if($this->tax_jurisdiction->save_value($tax_jurisdiction_data)) { - if($jurisdiction_id == -1) //TODO: Replace -1 with constant + if($jurisdiction_id == NEW_ENTRY) { echo json_encode ([ 'success' => TRUE, @@ -95,12 +95,12 @@ class Tax_jurisdictions extends Secure_Controller echo json_encode ([ 'success' => FALSE, 'message' => lang('Tax_jurisdictions.error_adding_updating') . ' ' . $tax_jurisdiction_data['jurisdiction_name'], - 'id' => -1 + 'id' => NEW_ENTRY ]); } } - public function delete(): void + public function postDelete(): void { $tax_jurisdictions_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT); @@ -116,4 +116,4 @@ class Tax_jurisdictions extends Secure_Controller echo json_encode (['success' => FALSE, 'message' => lang('Tax_jurisdictions.cannot_be_deleted')]); } } -} \ No newline at end of file +} diff --git a/app/Controllers/Taxes.php b/app/Controllers/Taxes.php index 6dc850077..06e103781 100644 --- a/app/Controllers/Taxes.php +++ b/app/Controllers/Taxes.php @@ -77,13 +77,13 @@ class Taxes extends Secure_Controller /* Returns tax_codes table data rows. This will be called with AJAX. */ - public function search(): void + public function getSearch(): void { - $search = $this->request->getGet('search', FILTER_SANITIZE_STRING); - $limit = $this->request->getGet('limit', FILTER_SANITIZE_NUMBER_INT); - $offset = $this->request->getGet('offset', FILTER_SANITIZE_NUMBER_INT); - $sort = $this->request->getGet('sort', FILTER_SANITIZE_STRING); - $order = $this->request->getGet('order', FILTER_SANITIZE_STRING); + $search = $this->request->getVar('search', FILTER_SANITIZE_STRING); + $limit = $this->request->getVar('limit', FILTER_SANITIZE_NUMBER_INT); + $offset = $this->request->getVar('offset', FILTER_SANITIZE_NUMBER_INT); + $sort = $this->request->getVar('sort', FILTER_SANITIZE_STRING); + $order = $this->request->getVar('order', FILTER_SANITIZE_STRING); $tax_rates = $this->tax->search($search, $limit, $offset, $sort, $order); @@ -119,14 +119,14 @@ class Taxes extends Secure_Controller } - public function get_row(int $row_id): void + public function getRow(int $row_id): void { $data_row = get_tax_rates_data_row($this->tax->get_info($row_id)); echo json_encode($data_row); } - public function view_tax_codes(int $tax_code = -1): void //TODO: Replace -1 with constant + public function getView_tax_codes(int $tax_code = NEW_ENTRY): void { $tax_code_info = $this->tax->get_info($tax_code); @@ -147,7 +147,7 @@ class Taxes extends Secure_Controller $data['rounding_options'] = rounding_mode::get_rounding_options(); $data['html_rounding_options'] = $this->get_html_rounding_options(); - if($tax_code == -1) //TODO: Replace -1 with constant + if($tax_code == NEW_ENTRY) {//TODO: Duplicated code $data['tax_code'] = ''; $data['tax_code_name'] = ''; @@ -194,7 +194,7 @@ class Taxes extends Secure_Controller } - public function view(int $tax_rate_id = -1): void //TODO: Replace -1 with constant + public function getView(int $tax_rate_id = NEW_ENTRY): void { $tax_rate_info = $this->tax->get_info($tax_rate_id); @@ -205,7 +205,7 @@ class Taxes 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(); - if($tax_rate_id == -1) //TODO: Replace -1 with constant + if($tax_rate_id == NEW_ENTRY) { $data['rate_tax_code_id'] = $this->config['default_tax_code']; $data['rate_tax_category_id'] = $this->config['default_tax_category']; @@ -226,7 +226,7 @@ class Taxes extends Secure_Controller echo view('taxes/tax_rates_form', $data); } - public function view_tax_categories(int $tax_code = -1): void //TODO: Replace -1 with constant //TODO: This appears to be called no where in the code. + public function getView_tax_categories(int $tax_code = NEW_ENTRY): void //TODO: This appears to be called no where in the code. { $tax_code_info = $this->tax->get_info($tax_code); //TODO: Duplicated Code @@ -247,7 +247,7 @@ class Taxes extends Secure_Controller $data['default_tax_type'] = Tax_lib::TAX_TYPE_EXCLUDED; } - if($tax_code == -1) //TODO: Replace -1 with constant + if($tax_code == NEW_ENTRY) { $data['tax_code'] = ''; $data['tax_code_name'] = ''; @@ -293,7 +293,7 @@ class Taxes extends Secure_Controller echo view('taxes/tax_category_form', $data); } - public function view_tax_jurisdictions(int $tax_code = -1): void //TODO: Replace -1 with constant //TODO: This appears to be called no where in the code. + public function getView_tax_jurisdictions(int $tax_code = NEW_ENTRY): void //TODO: This appears to be called no where in the code. { $tax_code_info = $this->tax->get_info($tax_code); //TODO: Duplicated code @@ -314,7 +314,7 @@ class Taxes extends Secure_Controller $data['default_tax_type'] = Tax_lib::TAX_TYPE_EXCLUDED; } - if($tax_code == -1) //TODO: Replace -1 with constant + if($tax_code == NEW_ENTRY) { $data['tax_code'] = ''; $data['tax_code_name'] = ''; @@ -365,7 +365,7 @@ class Taxes extends Secure_Controller return rounding_mode::get_html_rounding_options(); } - public function save(int $tax_rate_id = -1): void //TODO: Replace -1 with constant + public function postSave(int $tax_rate_id = NEW_ENTRY): void { $tax_category_id = $this->request->getPost('rate_tax_category_id', FILTER_SANITIZE_NUMBER_INT); $tax_rate = parse_tax($this->request->getPost('tax_rate', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION)); @@ -385,7 +385,7 @@ class Taxes extends Secure_Controller if($this->tax->save_value($tax_rate_data, $tax_rate_id)) { - if($tax_rate_id == -1) //TODO: Replace -1 with constant + if($tax_rate_id == NEW_ENTRY) {//TODO: this needs to be replaced with ternary notation echo json_encode (['success' => TRUE, 'message' => lang('Taxes.tax_rate_successfully_added')]); } @@ -400,7 +400,7 @@ class Taxes extends Secure_Controller } } - public function delete(): void + public function postDelete(): void { $tax_codes_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT); @@ -417,7 +417,7 @@ class Taxes extends Secure_Controller * Called in the view. * @return void */ - public function suggest_tax_codes(): void + public function getSuggestTaxCodes(): void { $suggestions = $this->tax_code->get_tax_codes_search_suggestions($this->request->getPostGet('term', FILTER_SANITIZE_STRING)); diff --git a/app/Database/tables.sql b/app/Database/tables.sql index aff3b9003..8ddc3e89c 100644 --- a/app/Database/tables.sql +++ b/app/Database/tables.sql @@ -75,6 +75,9 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES ('payment_options_order', 'cashdebitcredit'), ('protocol', 'mail'), ('mailpath', '/usr/sbin/sendmail'), + ('smtp_host', ''), + ('smtp_user', ''), + ('smtp_pass', ''), ('smtp_port', '465'), ('smtp_timeout', '5'), ('smtp_crypto', 'ssl'), diff --git a/app/Helpers/locale_helper.php b/app/Helpers/locale_helper.php index 7ee794811..3f6cc18d3 100644 --- a/app/Helpers/locale_helper.php +++ b/app/Helpers/locale_helper.php @@ -322,17 +322,17 @@ function to_datetime(int $datetime = DEFAULT_DATETIME): string return date($config['dateformat'] . ' ' . $config['timeformat'], $datetime); } -function to_currency(float $number): string +function to_currency(?float $number): string { return to_decimals($number, 'currency_decimals', NumberFormatter::CURRENCY); } -function to_currency_no_money(float $number): string +function to_currency_no_money(?float $number): string { return to_decimals($number, 'currency_decimals'); } -function to_currency_tax(float $number): string +function to_currency_tax(?float $number): string { $config = config('OSPOS')->settings; @@ -346,8 +346,13 @@ function to_currency_tax(float $number): string } } -function to_tax_decimals(float $number): string +function to_tax_decimals($number): string { + // TODO: When the tax array is empty the value passed in is an empty string, For now I "untyped" it to get past + // the issue because I don't understand why an empty string is being passed in when I know the array is empty. + // It looks like it must be creating a String value on the fly because the form is referring to the index 0 when + // there IS no index[0] row in the table + // taxes that are NULL, '' or 0 don't need to be displayed // NOTE: do not remove this line otherwise the items edit form will show a tax with 0, and it will save it if(empty($number)) @@ -358,18 +363,18 @@ function to_tax_decimals(float $number): string return to_decimals($number, 'tax_decimals'); } -function to_quantity_decimals(float $number): string +function to_quantity_decimals(?float $number): string { return to_decimals($number, 'quantity_decimals'); } -function to_decimals(float $number, string $decimals = NULL, int $type = NumberFormatter::DECIMAL): string +function to_decimals(?float $number, string $decimals = NULL, int $type = NumberFormatter::DECIMAL): string { // ignore empty strings and return // NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol if(!isset($number)) { - return $number; + return ""; } $config = config('OSPOS')->settings; @@ -386,7 +391,11 @@ function to_decimals(float $number, string $decimals = NULL, int $type = NumberF return $fmt->format($number); } -function parse_quantity(string $number): float +/** + * @param string $number + * @return false|float|int|mixed|string + */ +function parse_quantity(string $number) { return parse_decimals($number, quantity_decimals()); } diff --git a/app/Helpers/report_helper.php b/app/Helpers/report_helper.php index fe573055e..10f12adab 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. ?> - "> + "> getSegment(1); + $controller = $uri->getSegment(1); $row = [ 'sale_id' => $sale->sale_id, @@ -114,25 +114,25 @@ function get_sale_data_row(object $sale): array $row['invoice'] = empty($sale->invoice_number) ? '' : anchor( - $controller_name."/invoice/$sale->sale_id", + "$controller/invoice/$sale->sale_id", '', ['title'=>lang('Sales.show_invoice')] ); } $row['receipt'] = anchor( - $controller_name."/receipt/$sale->sale_id", + "$controller/receipt/$sale->sale_id", '', ['title' => lang('Sales.show_receipt')] ); $row['edit'] = anchor( - $controller_name."/edit/$sale->sale_id", + "$controller/edit/$sale->sale_id", '', [ 'class' => 'modal-dlg print_hide', 'data-btn-delete' => lang('Common.delete'), 'data-btn-submit' => lang('Common.submit'), - 'title' => lang($controller_name . '.update') + 'title' => lang("$controller.update") ] ); @@ -217,8 +217,7 @@ function get_people_manage_table_headers(): string */ function get_person_data_row(object $person): array { - $router = service('router'); - $controller_name = strtolower($router->controllerName()); + $controller = get_controller(); return [ 'people.person_id' => $person->person_id, @@ -238,12 +237,12 @@ function get_person_data_row(object $person): array ] ), 'edit' => anchor( - $controller_name."/view/$person->person_id", //TODO: String interpolation + "$controller/view/$person->person_id", '', [ 'class' => 'modal-dlg', 'data-btn-submit' => lang('Common.submit'), - 'title'=>lang($controller_name . '.update') //TODO: String interpolation + 'title'=>lang($controller . '.update') //TODO: String interpolation ] ) ]; @@ -282,8 +281,7 @@ function get_customer_manage_table_headers(): string */ function get_customer_data_row(object $person, object $stats): array { - $router = service('router'); - $controller_name = strtolower($router->controllerName()); + $controller = get_controller(); return [ 'people.person_id' => $person->person_id, @@ -295,7 +293,7 @@ function get_customer_data_row(object $person, object $stats): array 'messages' => empty($person->phone_number) ? '' : anchor( - "Messages/view/$person->person_id", //TODO: String interpolation + "Messages/view/$person->person_id", '', [ 'class' => 'modal-dlg', @@ -304,12 +302,12 @@ function get_customer_data_row(object $person, object $stats): array ] ), 'edit' => anchor( - $controller_name."/view/$person->person_id", //TODO: String interpolation + "$controller/view/$person->person_id", '', [ 'class' => 'modal-dlg', 'data-btn-submit' => lang('Common.submit'), - 'title'=>lang($controller_name . '.update') //TODO: String interpolation + 'title'=>lang("$controller.update") ] ) ]; @@ -350,8 +348,7 @@ function get_suppliers_manage_table_headers(): string */ function get_supplier_data_row(object $supplier): array { - $router = service('router'); - $controller_name = strtolower($router->controllerName()); + $controller = get_controller(); return [ 'people.person_id' => $supplier->person_id, @@ -374,12 +371,12 @@ function get_supplier_data_row(object $supplier): array ] ), 'edit' => anchor( - $controller_name."/view/$supplier->person_id", //TODO: String interpolation + "$controller/view/$supplier->person_id", '', [ 'class'=>"modal-dlg", 'data-btn-submit' => lang('Common.submit'), - 'title'=>lang($controller_name . '.update') //TODO: String interpolation + 'title'=>lang("$controller.update") ] ) ]; @@ -469,8 +466,7 @@ function get_item_data_row(object $item): array $tax_percents = !$tax_percents ? '-' : $tax_percents; } - $router = service('router'); - $controller_name = strtolower($router->controllerName()); + $controller = get_controller(); $image = NULL; if($item->pic_filename != '') //TODO: !== ? @@ -515,29 +511,29 @@ function get_item_data_row(object $item): array $icons = [ 'inventory' => anchor( - $controller_name."/inventory/$item->item_id", //TODO: String interpolation + "$controller/inventory/$item->item_id", '', [ 'class' => 'modal-dlg', 'data-btn-submit' => lang('Common.submit'), - 'title' => lang($controller_name . '.count') //TODO: String interpolation + 'title' => lang("$controller.count") ] ), 'stock' => anchor( - $controller_name."/count_details/$item->item_id", //TODO: String interpolation + "$controller/countDetails/$item->item_id", '', [ 'class' => 'modal-dlg', - 'title' => lang($controller_name . '.details_count') //TODO: String interpolation + 'title' => lang("$controller.details_count") ] ), 'edit' => anchor( - $controller_name."/view/$item->item_id", //TODO: String interpolation + "$controller/view/$item->item_id", '', [ 'class' => 'modal-dlg', 'data-btn-submit' => lang('Common.submit'), - 'title' => lang($controller_name . '.update') //TODO: String interpolation + 'title' => lang("$controller.update") ] ) ]; @@ -566,9 +562,7 @@ function get_giftcards_manage_table_headers(): string */ function get_giftcard_data_row(object $giftcard): array { - - $router = service('router'); - $controller_name = strtolower($router->controllerName()); + $controller = get_controller(); return [ 'giftcard_id' => $giftcard->giftcard_id, @@ -577,12 +571,12 @@ function get_giftcard_data_row(object $giftcard): array 'giftcard_number' => $giftcard->giftcard_number, 'value' => to_currency($giftcard->value), 'edit' => anchor( - $controller_name."/view/$giftcard->giftcard_id", //TODO: String interpolation + "$controller/view/$giftcard->giftcard_id", '', [ 'class' => 'modal-dlg', 'data-btn-submit' => lang('Common.submit'), - 'title'=>lang($controller_name . '.update') //TODO: String interpolation + 'title'=>lang("$controller.update") ] ) ]; @@ -610,9 +604,7 @@ function get_item_kits_manage_table_headers(): string */ function get_item_kit_data_row(object $item_kit): array { - - $router = service('router'); - $controller_name = strtolower($router->controllerName()); + $controller = get_controller(); return [ 'item_kit_id' => $item_kit->item_kit_id, @@ -622,12 +614,12 @@ function get_item_kit_data_row(object $item_kit): array 'total_cost_price' => to_currency($item_kit->total_cost_price), 'total_unit_price' => to_currency($item_kit->total_unit_price), 'edit' => anchor( - $controller_name."/view/$item_kit->item_kit_id", //TODO: String interpolation + "$controller/view/$item_kit->item_kit_id", '', [ 'class' => 'modal-dlg', 'data-btn-submit' => lang('Common.submit'), - 'title'=>lang($controller_name . '.update') //TODO: String interpolation + 'title'=>lang("$controller.update") ] ) ]; @@ -691,8 +683,7 @@ function get_attribute_definition_data_row(object $attribute): array { $attribute = model('Attribute'); - $router = service('router'); - $controller_name = strtolower($router->controllerName()); + $controller = get_controller(); if(count($attribute->definition_flags) == 0) //TODO: === ? { @@ -714,12 +705,12 @@ function get_attribute_definition_data_row(object $attribute): array 'definition_group' => $attribute->definition_group, 'definition_flags' => $definition_flags, 'edit' => anchor( - "$controller_name/view/$attribute->definition_id", + "$controller/view/$attribute->definition_id", '', [ 'class' => 'modal-dlg', 'data-btn-submit' => lang('Common.submit'), - 'title'=>lang($controller_name . '.update') + 'title'=>lang("$controller.update") ] ) ]; @@ -744,20 +735,19 @@ function get_expense_category_manage_table_headers(): string */ function get_expense_category_data_row(object $expense_category): array { - $router = service('router'); - $controller_name = strtolower($router->controllerName()); + $controller = get_controller(); return [ 'expense_category_id' => $expense_category->expense_category_id, 'category_name' => $expense_category->category_name, 'category_description' => $expense_category->category_description, 'edit' => anchor( - $controller_name."/view/$expense_category->expense_category_id", //TODO: String interpolation + "$controller/view/$expense_category->expense_category_id", '', [ 'class' => 'modal-dlg', 'data-btn-submit' => lang('Common.submit'), - 'title'=>lang($controller_name . '.update') //TODO: String interpolation + 'title'=>lang("$controller.update") ] ) ]; @@ -790,8 +780,7 @@ function get_expenses_manage_table_headers(): string */ function get_expenses_data_row(object $expense): array { - $router = service('router'); - $controller_name = strtolower($router->controllerName()); + $controller = get_controller(); return [ 'expense_id' => $expense->expense_id, @@ -805,12 +794,12 @@ function get_expenses_data_row(object $expense): array 'description' => $expense->description, 'created_by' => $expense->first_name.' '. $expense->last_name, 'edit' => anchor( - $controller_name."/view/$expense->expense_id", + "$controller/view/$expense->expense_id", '', [ 'class' => 'modal-dlg', 'data-btn-submit' => lang('Common.submit'), - 'title'=>lang($controller_name . '.update') + 'title'=>lang("$controller.update") ] ) ]; @@ -887,8 +876,7 @@ function get_cashups_manage_table_headers(): string */ function get_cash_up_data_row(object $cash_up): array { - $router = service('router'); - $controller_name = strtolower($router->controllerName()); + $controller = get_controller(); return [ 'cashup_id' => $cash_up->cashup_id, @@ -905,13 +893,25 @@ function get_cash_up_data_row(object $cash_up): array 'closed_amount_check' => to_currency($cash_up->closed_amount_check), 'closed_amount_total' => to_currency($cash_up->closed_amount_total), 'edit' => anchor( - $controller_name."/view/$cash_up->cashup_id", + "$controller/view/$cash_up->cashup_id", '', [ 'class' => 'modal-dlg', 'data-btn-submit' => lang('Common.submit'), - 'title'=>lang($controller_name . '.update') + 'title'=>lang("$controller.update") ] ) ]; } + +/** + * Returns the right-most part of the controller name + * @return string + */ +function get_controller(): string +{ + $router = service('router'); + $controller_name = strtolower($router->controllerName()); + $controller_name_parts = explode('\\', $controller_name); + return end($controller_name_parts); +} diff --git a/app/Libraries/Item_lib.php b/app/Libraries/Item_lib.php index 44e777138..26f303008 100644 --- a/app/Libraries/Item_lib.php +++ b/app/Libraries/Item_lib.php @@ -33,7 +33,7 @@ class Item_lib return $this->session->get('item_location'); } - public function set_item_location(string $location): void + public function set_item_location(?string $location): void { $this->session->set('item_location',$location); } @@ -42,4 +42,4 @@ class Item_lib { $this->session->remove('item_location'); } -} \ No newline at end of file +} diff --git a/app/Libraries/Sale_lib.php b/app/Libraries/Sale_lib.php index eeb9d94ab..68a153699 100644 --- a/app/Libraries/Sale_lib.php +++ b/app/Libraries/Sale_lib.php @@ -418,7 +418,7 @@ class Sale_lib * @param string $payment_amount * @param int $cash_adjustment */ - public function add_payment(int $payment_id, string $payment_amount, int $cash_adjustment = CASH_ADJUSTMENT_FALSE): void + public function add_payment(string $payment_id, string $payment_amount, int $cash_adjustment = CASH_ADJUSTMENT_FALSE): void { $payments = $this->get_payments(); if(isset($payments[$payment_id])) @@ -807,7 +807,7 @@ class Sale_lib //make sure item exists if(empty($item_info)) { - $item_id = -1; //TODO: Replace -1 with constant + $item_id = NEW_ENTRY; return FALSE; } @@ -968,6 +968,7 @@ class Sale_lib 'tax_category_id' => $item_info->tax_category_id ] ]; + //add to existing array $items += $item; } @@ -1052,7 +1053,7 @@ class Sale_lib * @param string|NULL $discounted_total * @return bool */ - public function edit_item(string $line, string $description, string $serialnumber, string $quantity, string $discount, string $discount_type, string $price, string $discounted_total = NULL): bool + public function edit_item(string $line, string $description, string $serialnumber, string $quantity, string $discount, ?string $discount_type, ?string $price, ?string $discounted_total = NULL): bool { $items = $this->get_cart(); if(isset($items[$line])) diff --git a/app/Libraries/Token_lib.php b/app/Libraries/Token_lib.php index 543ea6db7..689eb6c22 100644 --- a/app/Libraries/Token_lib.php +++ b/app/Libraries/Token_lib.php @@ -72,7 +72,7 @@ class Token_lib return $token_tree; } - public function parse_barcode(string &$quantity, string &$price, string &$item_id_or_number_or_item_kit_or_receipt): void + public function parse_barcode(?string &$quantity, ?string &$price, ?string &$item_id_or_number_or_item_kit_or_receipt): void { $config = config('OSPOS')->settings; $barcode_formats = json_decode($config['barcode_formats']); diff --git a/app/Models/Attribute.php b/app/Models/Attribute.php index 901bc8621..891c6b3e1 100644 --- a/app/Models/Attribute.php +++ b/app/Models/Attribute.php @@ -150,8 +150,14 @@ class Attribute extends Model /* Performs a search on attribute definitions */ - public function search(string $search, int $rows = 0, int $limit_from = 0, string $sort = 'definition.definition_name', string $order = 'asc'): ResultInterface + public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'definition.definition_name', ?string $order = 'asc'): ResultInterface { + // Set default values + if($rows == null) $rows = 0; + if($limit_from == null) $limit_from = 0; + if($sort == null) $sort = 'definition.definition_name'; + if($order == null) $order = 'asc'; + $builder = $this->db->table('attribute_definitions AS definition'); $builder->select('parent_definition.definition_name AS definition_group, definition.*'); $builder->join('attribute_definitions AS parent_definition', 'parent_definition.definition_id = definition.definition_fk', 'left'); @@ -187,7 +193,7 @@ class Attribute extends Model return $this->to_array($results, 'definition_id'); } - public function get_values_by_definitions(array $definition_ids): array + public function get_values_by_definitions(?array $definition_ids): array { if(count($definition_ids ? : [])) { @@ -569,18 +575,21 @@ class Attribute extends Model return $builder->delete($delete_data); } - public function get_link_value(int $item_id, int $definition_id): object + public function get_link_value(int $item_id, ?int $definition_id): ?object { $builder = $this->db->table('attribute_links'); $builder->where('item_id', $item_id); $builder->where('sale_id', null); $builder->where('receiving_id', null); - $builder->where('definition_id', $definition_id); + if($definition_id != NULL) + { + $builder->where('definition_id', $definition_id); + } return $builder->get('attribute_links')->getRowObject(); } - public function get_link_values(int $item_id, string $sale_receiving_fk, int $id, int $definition_flags): ResultInterface + public function get_link_values(int $item_id, string $sale_receiving_fk, ?int $id, ?int $definition_flags): ResultInterface { $format = $this->db->escape(dateformat_mysql()); @@ -603,7 +612,10 @@ class Attribute extends Model $builder->where('receiving_id', null); } - $builder->where('definition_flags & ', $definition_flags); + if(!empty($id)) + { + $builder->where('definition_flags & ', $definition_flags); + } return $builder->get(); } diff --git a/app/Models/Cashup.php b/app/Models/Cashup.php index 3dc3ba351..44323857f 100644 --- a/app/Models/Cashup.php +++ b/app/Models/Cashup.php @@ -71,7 +71,7 @@ class Cashup extends Model /** * Gets rows */ - public function get_found_rows(string $search, array $filters): ResultInterface + public function get_found_rows(string $search, array $filters): int { return $this->search($search, $filters, 0, 0, 'cashup_id', 'asc', TRUE); } @@ -79,8 +79,15 @@ class Cashup extends Model /** * Searches cashups */ - 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 + 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) { + // Set default values + if($rows == null) $rows = 0; + if($limit_from == null) $limit_from = 0; + if($sort == null) $sort = 'cashup_id'; + if($order == null) $order = 'asc'; + if($count_only == null) $count_only = FALSE; + $config = config('OSPOS')->settings; $builder = $this->db->table('cash_up AS cash_up'); @@ -208,9 +215,9 @@ class Cashup extends Model /** * Inserts or updates a cashup */ - public function save_value(array &$cash_up_data, $cashup_id = FALSE): bool + public function save_value(array &$cash_up_data, $cashup_id = NEW_ENTRY): bool { - if(!$cashup_id == -1 || !$this->exists($cashup_id)) //TODO: Replace -1 with constant + if(!$cashup_id == NEW_ENTRY || !$this->exists($cashup_id)) { $builder = $this->db->table('cash_up'); if($builder->insert($cash_up_data)) diff --git a/app/Models/Customer.php b/app/Models/Customer.php index 7fb0d4856..0a60a94c8 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -38,7 +38,6 @@ class Customer extends Person $builder = $this->db->table('customers'); $builder->join('people', 'people.person_id = customers.person_id'); $builder->where('customers.person_id', $person_id); - return ($builder->get()->getNumRows() == 1); } @@ -103,20 +102,40 @@ class Customer extends Person } else { - //Get empty base parent object, as $customer_id is NOT a customer - $person_obj = parent::get_info(-1); //TODO: NEED TO CREATE A GLOBAL CONSTANT FOR NO_PERSON IN CONFIG/CONSTANTS.PHP AND CALL IT HERE FOR CLARITY. - - //Get all the fields from customer table - //append those fields to base parent object, we have a complete empty object - foreach($this->db->getFieldNames('customers') as $field) - { - $person_obj->$field = ''; - } - - return $person_obj; + return $this->getEmptyObject('customers'); } } + /** + * Initializes an empty object based on database definitions + * @param string $table_name + * @return object + */ + private function getEmptyObject(string $table_name): object + { + // Return an empty base parent object, as $item_id is NOT an item + $empty_obj = parent::get_info(NEW_ENTRY); + + // Iterate through field definitions to determine how the fields should be initialized + + foreach($this->db->getFieldData($table_name) as $field) { + + $field_name = $field->name; + + if(in_array($field->type, array('int', 'tinyint', 'decimal'))) + { + $empty_obj->$field_name = ($field->primary_key == 1) ? NEW_ENTRY : 0; + } + else + { + $empty_obj->$field_name = NULL; + } + } + + return $empty_obj; + } + + /** * Gets stats about a particular customer */ @@ -206,7 +225,7 @@ class Customer extends Person /** * Inserts or updates a customer */ - public function save_customer(array &$person_data, array &$customer_data, bool $customer_id = FALSE): bool + public function save_customer(array &$person_data, array &$customer_data, int $customer_id = NEW_ENTRY): bool { $success = FALSE; @@ -215,7 +234,7 @@ class Customer extends Person if(parent::save_value($person_data, $customer_id)) { $builder = $this->db->table('customers'); - if(!$customer_id || !$this->exists($customer_id)) + if($customer_id == NEW_ENTRY || !$customer_id || !$this->exists($customer_id)) { $customer_data['person_id'] = $person_data['person_id']; $success = $builder->insert($customer_data); @@ -398,16 +417,24 @@ class Customer extends Person /** * Gets rows */ - public function get_found_rows(string $search): ResultInterface + public function get_found_rows(string $search): int { - return $this->search($search, 0, 0, 'last_name', 'asc', TRUE); + $result = $this->search($search, 0, 0, 'last_name', 'asc', TRUE); + return $result; } /** * Performs a search on customers */ - public function search(string $search, int $rows = 0, int $limit_from = 0, string $sort = 'last_name', string $order = 'asc', bool $count_only = FALSE) + public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'last_name', ?string $order = 'asc', ?bool $count_only = FALSE) { + // Set default values + if($rows == null) $rows = 0; + if($limit_from == null) $limit_from = 0; + if($sort == null) $sort = 'last_name'; + if($order == null) $order = 'asc'; + if($count_only == null) $count_only = FALSE; + $builder = $this->db->table('customers AS customers'); // get_found_rows case diff --git a/app/Models/Employee.php b/app/Models/Employee.php index 07bfaee34..ab95ed6e2 100644 --- a/app/Models/Employee.php +++ b/app/Models/Employee.php @@ -3,7 +3,6 @@ namespace App\Models; use CodeIgniter\Database\ResultInterface; -use CodeIgniter\HTTP\RedirectResponse; use CodeIgniter\Session\Session; /** @@ -96,13 +95,13 @@ class Employee extends Person } //Get empty base parent object, as $employee_id is NOT an employee - $person_obj = parent::get_info(-1); //TODO: Replace -1 with a constant + $person_obj = parent::get_info(NEW_ITEM); //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 = ''; + $person_obj->$field = null; } return $person_obj; @@ -124,7 +123,7 @@ class Employee extends Person /** * Inserts or updates an employee */ - public function save_employee(array &$person_data, array &$employee_data, array &$grants_data, bool $employee_id = FALSE): bool + public function save_employee(array &$person_data, array &$employee_data, array &$grants_data, int $employee_id = NEW_ENTRY): bool { $success = FALSE; @@ -134,7 +133,7 @@ class Employee extends Person if(ENVIRONMENT != 'testing' && parent::save_value($person_data, $employee_id)) { $builder = $this->db->table('employees'); - if(!$employee_id || !$this->exists($employee_id)) + if($employee_id == NEW_ENTRY || !$this->exists($employee_id)) { $employee_data['person_id'] = $employee_id = $person_data['person_id']; $success = $builder->insert($employee_data); @@ -328,7 +327,7 @@ class Employee extends Person /** * Gets rows */ - public function get_found_rows(string $search): ResultInterface + public function get_found_rows(string $search): int { return $this->search($search, 0, 0, 'last_name', 'asc', TRUE); } @@ -336,8 +335,15 @@ class Employee extends Person /** * Performs a search on employees */ - public function search(string $search, int $rows = 0, int $limit_from = 0, string $sort = 'last_name', string $order = 'asc', bool $count_only = FALSE): ResultInterface + public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'last_name', ?string $order = 'asc', ?bool $count_only = FALSE) { + // Set default values + if($rows == null) $rows = 0; + if($limit_from == null) $limit_from = 0; + if($sort == null) $sort = 'last_name'; + if($order == null) $order = 'asc'; + if($count_only == null) $count_only = FALSE; + $builder = $this->db->table('employees AS employees'); // get_found_rows case @@ -408,7 +414,7 @@ class Employee extends Person /** * Logs out a user by destroying all session data and redirect to log in */ - public function logout() + public function logout(): void { session()->destroy(); } @@ -466,13 +472,17 @@ class Employee extends Person /** * Determines whether the employee specified employee has access the specific module. */ - public function has_grant(string $permission_id, int $person_id): bool + public function has_grant(?string $permission_id, ?int $person_id): bool { //if no module_id is null, allow access if($permission_id == NULL) { return TRUE; } + if($person_id == NULL) + { + return FALSE; + } $builder = $this->db->table('grants'); $query = $builder->getWhere(['person_id' => $person_id, 'permission_id' => $permission_id], 1); diff --git a/app/Models/Expense.php b/app/Models/Expense.php index ce9a69668..872fc3873 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -79,7 +79,7 @@ class Expense extends Model /** * Gets rows */ - public function get_found_rows(string $search, array $filters): ResultInterface + public function get_found_rows(string $search, array $filters): int { return $this->search($search, $filters, 0, 0, 'expense_id', 'asc', TRUE); } @@ -87,8 +87,15 @@ class Expense extends Model /** * Searches expenses */ - 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 + 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) { + // Set default values + if($rows == null) $rows = 0; + if($limit_from == null) $limit_from = 0; + if($sort == null) $sort = 'expense_id'; + if($order == null) $order = 'asc'; + if($count_only == null) $count_only = FALSE; + $config = config('OSPOS')->settings; $builder = $this->db->table('expenses AS expenses'); @@ -220,35 +227,56 @@ class Expense extends Model $query = $builder->get(); - if($query->getNumRows() == 1) //TODO: === + if ($query->getNumRows() == 1) //TODO: === { 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 - $expenses_obj = new stdClass(); - //Get all the fields from expenses table - foreach($this->db->getFieldNames('expenses') as $field) + $empty_obj = $this->getEmptyObject('expenses'); + $empty_obj->supplier_name = NULL; + $empty_obj->first_name = NULL; + $empty_obj->last_name = NULL; + + return $empty_obj; + } + + /** + * Initializes an empty object based on database definitions + * @param string $table_name + * @return object + */ + private function getEmptyObject(string $table_name): object + { + // Return an empty base parent object, as $item_id is NOT an item + $empty_obj = new stdClass(); + + // Iterate through field definitions to determine how the fields should be initialized + + foreach($this->db->getFieldData($table_name) as $field) { + + $field_name = $field->name; + + if(in_array($field->type, array('int', 'tinyint', 'decimal'))) { - $expenses_obj->$field = ''; + $empty_obj->$field_name = ($field->primary_key == 1) ? NEW_ENTRY : 0; + } + else + { + $empty_obj->$field_name = NULL; } - - $expenses_obj->supplier_name = ''; - - return $expenses_obj; } + + return $empty_obj; } /** * Inserts or updates an expense */ - public function save_value(array &$expense_data, bool $expense_id = FALSE): bool + public function save_value(array &$expense_data, int $expense_id = NEW_ENTRY): bool { $builder = $this->db->table('expenses'); - if(!$expense_id || !$this->exists($expense_id)) + if($expense_id == NEW_ENTRY || !$this->exists($expense_id)) { if($builder->insert($expense_data)) { diff --git a/app/Models/Expense_category.php b/app/Models/Expense_category.php index af9d6a46a..5bfc8a841 100644 --- a/app/Models/Expense_category.php +++ b/app/Models/Expense_category.php @@ -109,11 +109,11 @@ class Expense_category extends Model /** * Inserts or updates an expense_category */ - public function save_value(array &$expense_category_data, bool $expense_category_id = FALSE): bool + public function save_value(array &$expense_category_data, int $expense_category_id = NEW_ENTRY): bool { $builder = $this->db->table('expense_categories'); - if(!$expense_category_id || !$this->exists($expense_category_id)) + if($expense_category_id == NEW_ENTRY || !$this->exists($expense_category_id)) { if($builder->insert($expense_category_data)) { @@ -144,7 +144,7 @@ class Expense_category extends Model /** * Gets rows */ - public function get_found_rows(string $search): ResultInterface + public function get_found_rows(string $search): int { return $this->search($search, 0, 0, 'category_name', 'asc', TRUE); } @@ -152,8 +152,15 @@ class Expense_category extends Model /** * Perform a search on expense_category */ - public function search(string $search, int $rows = 0, int $limit_from = 0, string $sort = 'category_name', string $order='asc', bool $count_only = FALSE): ResultInterface + public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'category_name', ?string $order='asc', ?bool $count_only = FALSE) { + // Set default values + if($rows == null) $rows = 0; + if($limit_from == null) $limit_from = 0; + if($sort == null) $sort = 'category_name'; + if($order == null) $order = 'asc'; + if($count_only == null) $count_only = FALSE; + $builder = $this->db->table('expense_categories AS expense_categories'); // get_found_rows case diff --git a/app/Models/Giftcard.php b/app/Models/Giftcard.php index d23e1289c..6400d4ca0 100644 --- a/app/Models/Giftcard.php +++ b/app/Models/Giftcard.php @@ -36,13 +36,13 @@ class Giftcard extends Model } /** - * Gets max gift card number //TODO: This isn't entirely accurate. It returns the object and the results then pulls the giftcard_number. + * Gets max gift card number //TODO: This isn't entirely accurate. It returns the object and the results then pulls the giftcard_number */ - public function get_max_number(): object + public function get_max_number(): ?object { $builder = $this->db->table('giftcards'); $builder->select('CAST(giftcard_number AS UNSIGNED) AS giftcard_number'); - $builder->where('giftcard_number REGEXP', "'^[0-9]+$'", FALSE); + $builder->where('giftcard_number REGEXP \'^[0-9]+$\' = 0'); $builder->orderBy("giftcard_number","desc"); $builder->limit(1); @@ -78,19 +78,39 @@ class Giftcard extends Model } 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 $giftcard_id is NOT a giftcard - $giftcard_obj = new stdClass(); - - //Get all the fields from giftcards table - foreach($this->db->getFieldNames('giftcards') as $field) - { - $giftcard_obj->$field = ''; - } - - return $giftcard_obj; + return $this->getEmptyObject('giftcards'); } } + /** + * Initializes an empty object based on database definitions + * @param string $table_name + * @return object + */ + private function getEmptyObject(string $table_name): object + { + // Return an empty base parent object, as $item_id is NOT an item + $empty_obj = new stdClass(); + + // Iterate through field definitions to determine how the fields should be initialized + + foreach($this->db->getFieldData($table_name) as $field) { + + $field_name = $field->name; + + if(in_array($field->type, array('int', 'tinyint', 'decimal'))) + { + $empty_obj->$field_name = ($field->primary_key == 1) ? NEW_ENTRY : 0; + } + else + { + $empty_obj->$field_name = NULL; + } + } + + return $empty_obj; + } + /** * Gets a giftcard id given a giftcard number */ @@ -126,11 +146,11 @@ class Giftcard extends Model /** * Inserts or updates a giftcard */ - public function save_value(array &$giftcard_data, $giftcard_id = FALSE): bool + public function save_value(array &$giftcard_data, int $giftcard_id = NEW_ENTRY): bool { $builder = $this->db->table('giftcards'); - if(!$giftcard_id || !$this->exists($giftcard_id)) + if($giftcard_id == NEW_ENTRY || !$this->exists($giftcard_id)) { if($builder->insert($giftcard_data)) { @@ -225,7 +245,7 @@ class Giftcard extends Model /** * Gets gift cards */ - public function get_found_rows(string $search): ResultInterface + public function get_found_rows(string $search): int { return $this->search($search, 0, 0, 'giftcard_number', 'asc', TRUE); } @@ -233,14 +253,28 @@ class Giftcard extends Model /** * Performs a search on giftcards */ - public function search(string $search, int $rows = 0, int $limit_from = 0, string $sort = 'giftcard_number', string $order = 'asc', bool $count_only = FALSE): ResultInterface + public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'giftcard_number', ?string $order = 'asc', ?bool $count_only = FALSE) { + // Set default values + if($rows == null) $rows = 0; + if($limit_from == null) $limit_from = 0; + if($sort == null) $sort = 'giftcard_number'; + if($order == null) $order = 'asc'; + if($count_only == null) $count_only = FALSE; + + // Set default values + if($rows == null) $rows = 0; + if($limit_from == null) $limit_from = 0; + if($sort == null) $sort = 'giftcard_number'; + if($order == null) $order = 'asc'; + if($count_only == null) $count_only = FALSE; + $builder = $this->db->table('giftcards'); // get_found_rows case if($count_only) //TODO: replace this with `if($count_only)` { - $builder->select('COUNT(giftcards.giftcard_id) as count'); + $builder->select('COUNT(giftcard_id) as count'); } $builder->join('people AS person', 'giftcards.person_id = person.person_id', 'left'); @@ -254,7 +288,7 @@ class Giftcard extends Model $builder->where('giftcards.deleted', 0); // get_found_rows case - if($count_only) //TODO: replace this with `if($count_only)` + if($count_only) { return $builder->get()->getRow()->count; } diff --git a/app/Models/Item.php b/app/Models/Item.php index eb672f95d..083083c35 100644 --- a/app/Models/Item.php +++ b/app/Models/Item.php @@ -42,27 +42,21 @@ class Item extends Model 'hsn_code' ]; + /** * Determines if a given item_id is an item */ public function exists(int $item_id, bool $ignore_deleted = FALSE, bool $deleted = FALSE): bool { - // check if $item_id is a number and not a string starting with 0 - // because cases like 00012345 will be seen as a number where it is a barcode - if(ctype_digit($item_id) && substr($item_id, 0, 1) !== '0') + $builder = $this->db->table('items'); + $builder->where('item_id', $item_id); + + if($ignore_deleted === FALSE) { - $builder = $this->db->table('items'); - $builder->where('item_id', $item_id); - - if($ignore_deleted === FALSE) - { - $builder->where('deleted', $deleted); - } - - return ($builder->get()->getNumRows() === 1); + $builder->where('deleted', $deleted); } - return FALSE; + return ($builder->get()->getNumRows() === 1); } /** @@ -79,15 +73,16 @@ class Item extends Model $builder = $this->db->table('items'); $builder->where('item_number', $item_number); + $builder->where('deleted !=', 1); + $builder->where('item_id !=', intval($item_id)); - // check if $item_id is a number and not a string starting with 0 - // because cases like 00012345 will be seen as a number where it is a barcode +// // check if $item_id is a number and not a string starting with 0 +// // because cases like 00012345 will be seen as a number where it is a barcode if(ctype_digit($item_id) && substr($item_id, 0, 1) != '0') //TODO: !== { $builder->where('item_id !=', intval($item_id)); } - - return ($builder->get()->getNumRows() >= 1); + return ($builder->get()->getNumRows()) >= 1; } /** @@ -112,7 +107,7 @@ class Item extends Model /** * Get number of rows */ - public function get_found_rows(string $search, array $filters): ResultInterface + public function get_found_rows(string $search, array $filters): int { return $this->search($search, $filters, 0, 0, 'items.name', 'asc', TRUE); } @@ -120,8 +115,15 @@ class Item extends Model /** * Perform a search on items */ - 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 + 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) { + // Set default values + if($rows == NULL) $rows = 0; + if($limit_from == NULL) $limit_from = 0; + if($sort == NULL) $sort = 'items.name'; + if($order == NULL) $order = 'asc'; + if($count_only == NULL) $count_only = FALSE; + $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 @@ -273,11 +275,11 @@ class Item extends Model /** * Returns all the items */ - public function get_all(int $stock_location_id = -1, int $rows = 0, int $limit_from = 0): ResultInterface //TODO: Replace -1 with a constant + public function get_all(int $stock_location_id = NEW_ENTRY, int $rows = 0, int $limit_from = 0): ResultInterface { $builder = $this->db->table('items'); - if($stock_location_id > -1) //TODO: Replace -1 with a constant + if($stock_location_id > -1) { $builder->join('item_quantities', 'item_quantities.item_id = items.item_id'); $builder->where('location_id', $stock_location_id); @@ -318,16 +320,36 @@ class Item extends Model return $query->getRow(); } - //Get empty base parent object, as $item_id is NOT an item - $item_obj = new stdClass(); + return $this->getEmptyObject('items'); + } - //Get all the fields from items table - foreach($this->db->getFieldNames('items') as $field) - { - $item_obj->$field = ''; + /** + * Initializes an empty object based on database definitions + * @param string $table_name + * @return object + */ + private function getEmptyObject(string $table_name): object + { + // Return an empty base parent object, as $item_id is NOT an item + $empty_obj = new stdClass(); + + // Iterate through field definitions to determine how the fields should be initialized + + foreach($this->db->getFieldData($table_name) as $field) { + + $field_name = $field->name; + + if(in_array($field->type, array('int', 'tinyint', 'decimal'))) + { + $empty_obj->$field_name = ($field->primary_key == 1) ? NEW_ENTRY : 0; + } + else + { + $empty_obj->$field_name = NULL; + } } - return $item_obj; + return $empty_obj; } /** @@ -341,7 +363,7 @@ class Item extends Model // check if $item_id is a number and not a string starting with 0 // because cases like 00012345 will be seen as a number where it is a barcode - if(ctype_digit($item_id) && substr($item_id, 0, 1) != '0') + if(ctype_digit(strval($item_id)) && substr($item_id, 0, 1) != '0') { $builder->orWhere('items.item_id', $item_id); } @@ -422,16 +444,16 @@ class Item extends Model /** * Inserts or updates an item */ - public function save_value(array &$item_data, bool $item_id = FALSE): bool //TODO: need to bring this in line with parent or change the name + public function save_value(array &$item_data, int $item_id = NEW_ENTRY): bool //TODO: need to bring this in line with parent or change the name { $builder = $this->db->table('items'); - if(!$item_id || !$this->exists($item_id, TRUE)) + if($item_id == NEW_ENTRY || !$this->exists($item_id, TRUE)) { if($builder->insert($item_data)) { $item_data['item_id'] = $this->db->insertID(); - if($item_data['low_sell_item_id'] == -1) //TODO: Replace -1 with a constant... === ? + if($item_data['low_sell_item_id'] == NEW_ENTRY) { $builder = $this->db->table('items'); $builder->where('item_id', $item_data['item_id']); @@ -469,7 +491,7 @@ class Item extends Model * Deletes one item * @throws ReflectionException */ - public function delete($item_id = null, bool $purge = false) + public function delete($item_id = NULL, bool $purge = false) { $this->db->transStart(); diff --git a/app/Models/Item_kit.php b/app/Models/Item_kit.php index 56b262130..b5a96edee 100644 --- a/app/Models/Item_kit.php +++ b/app/Models/Item_kit.php @@ -167,10 +167,10 @@ class Item_kit extends Model /** * Inserts or updates an item kit */ - public function save_value(array &$item_kit_data, bool $item_kit_id = FALSE): bool + public function save_value(array &$item_kit_data, int $item_kit_id = NEW_ENTRY): bool { $builder = $this->db->table('item_kits'); - if(!$item_kit_id || !$this->exists($item_kit_id)) + if($item_kit_id == NEW_ENTRY || !$this->exists($item_kit_id)) { if($builder->insert($item_kit_data)) { @@ -249,7 +249,7 @@ class Item_kit extends Model /** * Gets rows */ - public function get_found_rows(string $search): ResultInterface + public function get_found_rows(string $search): int { return $this->search($search, 0, 0, 'name', 'asc', TRUE); } @@ -257,14 +257,21 @@ class Item_kit extends Model /** * Perform a search on items */ - public function search(string $search, int $rows = 0, int $limit_from = 0, string $sort = 'name', string $order = 'asc', bool $count_only = FALSE): ResultInterface + public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'name', ?string $order = 'asc', ?bool $count_only = FALSE) { - $builder = $this->db->table('item_kits AS item_kits'); //TODO: Can we just say 'item_kits' here? + // Set default values + if($rows == null) $rows = 0; + if($limit_from == null) $limit_from = 0; + if($sort == null) $sort = 'name'; + if($order == null) $order = 'asc'; + if($count_only == null) $count_only = FALSE; + + $builder = $this->db->table('item_kits'); // get_found_rows case if($count_only) { - $builder->select('COUNT(item_kits.item_kit_id) as count'); + $builder->select('COUNT(item_kit_id) as count'); } $builder->like('name', $search); diff --git a/app/Models/Person.php b/app/Models/Person.php index 9039977c1..d1998c85d 100644 --- a/app/Models/Person.php +++ b/app/Models/Person.php @@ -92,18 +92,40 @@ class Person extends Model } else { - //create object with empty properties. - $person_obj = new stdClass(); - - foreach($this->db->getFieldNames('people') as $field) - { - $person_obj->$field = ''; - } - - return $person_obj; + return $this->getEmptyObject('people'); } } + + /** + * Initializes an empty object based on database definitions + * @param string $table_name + * @return object + */ + private function getEmptyObject(string $table_name): object + { + // Return an empty base parent object, as $item_id is NOT an item + $empty_obj = new stdClass(); + + // Iterate through field definitions to determine how the fields should be initialized + + foreach($this->db->getFieldData($table_name) as $field) { + + $field_name = $field->name; + + if(in_array($field->type, array('int', 'tinyint', 'decimal'))) + { + $empty_obj->$field_name = ($field->primary_key == 1) ? NEW_ENTRY : 0; + } + else + { + $empty_obj->$field_name = NULL; + } + } + + return $empty_obj; + } + /** * Gets information about people as an array of rows * @@ -126,11 +148,11 @@ class Person extends Model * @param bool $person_id identifier of the person to update the information * @return boolean TRUE if the save was successful, FALSE if not */ - public function save_value(array &$person_data, bool $person_id = FALSE): bool + public function save_value(array &$person_data, int $person_id = NEW_ENTRY): bool { $builder = $this->db->table('people'); - if(!$person_id || !$this->exists($person_id)) + if($person_id == NEW_ENTRY || !$this->exists($person_id)) { if($builder->insert($person_data)) { diff --git a/app/Models/Receiving.php b/app/Models/Receiving.php index af8618673..e626186d7 100644 --- a/app/Models/Receiving.php +++ b/app/Models/Receiving.php @@ -88,7 +88,7 @@ class Receiving extends Model /** * @throws ReflectionException */ - public function save_value(array $items, int $supplier_id, int $employee_id, string $comment, string $reference, string $payment_type, bool $receiving_id = FALSE): int //TODO: $receiving_id gets overwritten before it's evaluated. It doesn't make sense to pass this here. + public function save_value(array $items, int $supplier_id, int $employee_id, string $comment, string $reference, string $payment_type, int $receiving_id = NEW_ENTRY): int //TODO: $receiving_id gets overwritten before it's evaluated. It doesn't make sense to pass this here. { $attribute = model(Attribute::class); $inventory = model('Inventory'); diff --git a/app/Models/Sale.php b/app/Models/Sale.php index 9d86158b1..8ced7d308 100644 --- a/app/Models/Sale.php +++ b/app/Models/Sale.php @@ -118,7 +118,7 @@ class Sale extends Model /** * Get number of rows for the takings (sales/manage) view */ - public function get_found_rows(string $search, array $filters): ResultInterface + public function get_found_rows(string $search, array $filters): int { return $this->search($search, $filters, 0, 0, 'sales.sale_time', 'desc', TRUE); } @@ -126,8 +126,15 @@ class Sale extends Model /** * Get the sales data for the takings (sales/manage) view */ - 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 + 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) { + // Set default values + if($rows == null) $rows = 0; + if($limit_from == null) $limit_from = 0; + if($sort == null) $sort = 'sales.sale_time'; + if($order == null) $order = 'desc'; + if($count_only == null) $count_only = FALSE; + $config = config('OSPOS')->settings; // Pick up only non-suspended records @@ -585,7 +592,7 @@ class Sale extends Model $cash_adjustment = $payment['cash_adjustment']; $employee_id = $payment['employee_id']; - if($payment_id == -1 && $payment_amount != 0) + if($payment_id == NEW_ENTRY && $payment_amount != 0) { // Add a new payment transaction $sales_payments_data = [ @@ -598,7 +605,7 @@ class Sale extends Model ]; $success = $builder->insert($sales_payments_data); } - elseif($payment_id != -1) + elseif($payment_id != NEW_ENTRY) { if($payment_amount != 0) { @@ -644,7 +651,7 @@ class Sale extends Model $item = model(Item::class); $item_quantity = model(Item_quantity::class); - if($sale_id != -1) + if($sale_id != NEW_ENTRY) { $this->clear_suspended_sale_detail($sale_id); } @@ -674,7 +681,7 @@ class Sale extends Model $builder = $this->db->table('sales'); - if($sale_id == -1) //TODO: I think we have a constant for this and the -1 needs to be replaced with the constant in constants.php... something like NEW_SALE + if($sale_id == NEW_ENTRY) { $builder->insert($sales_data); $sale_id = $this->db->insertID(); @@ -788,7 +795,7 @@ class Sale extends Model $attribute->copy_attribute_links($item_data['item_id'], 'sale_id', $sale_id); } - if($customer_id == -1 || $customer->taxable) //TODO: Need a NEW_CUSTOMER constant in constants.php instead of -1 + if($customer_id == NEW_ENTRY || $customer->taxable) { $this->save_sales_tax($sale_id, $sales_taxes[0]); $this->save_sales_items_taxes($sale_id, $sales_taxes[1]); @@ -1334,7 +1341,7 @@ class Sale extends Model */ public function get_all_suspended(int $customer_id = NULL): array { - if($customer_id == -1) //TODO: This should be converted to a global constant and stored in constants.php + if($customer_id == NEW_ENTRY) { $query = $this->db->query("SELECT sale_id, case when sale_type = '".SALE_TYPE_QUOTE."' THEN quote_number WHEN sale_type = '".SALE_TYPE_WORK_ORDER."' THEN work_order_number else sale_id end as doc_id, sale_id as suspended_sale_id, sale_status, sale_time, dinner_table_id, customer_id, employee_id, comment FROM " . $this->db->prefixTable('sales') . ' where sale_status = ' . SUSPENDED); @@ -1353,7 +1360,7 @@ class Sale extends Model */ public function get_dinner_table(int $sale_id) //TODO: this is returning NULL or the table_id. We can keep it this way but multiple return types can't be declared until PHP 8.x { - if($sale_id == -1) + if($sale_id == NEW_ENTRY) { return NULL; } diff --git a/app/Models/Stock_location.php b/app/Models/Stock_location.php index 3a4a7f5b3..e665c7221 100644 --- a/app/Models/Stock_location.php +++ b/app/Models/Stock_location.php @@ -31,7 +31,7 @@ class Stock_location extends Model $this->session = session(); } - public function exists(int $location_id = -1): bool //TODO: Replace -1 with a constant + public function exists(int $location_id = NEW_ENTRY): bool { $builder = $this->db->table('stock_locations'); $builder->where('location_id', $location_id); diff --git a/app/Models/Supplier.php b/app/Models/Supplier.php index 01644cba6..a88f3159d 100644 --- a/app/Models/Supplier.php +++ b/app/Models/Supplier.php @@ -81,7 +81,7 @@ class Supplier extends Person else { //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 + $person_obj = parent::get_info(NEW_ENTRY); //Get all the fields from supplier table //append those fields to base parent object, we have a complete empty object @@ -110,7 +110,7 @@ class Supplier extends Person /** * Inserts or updates a suppliers */ - public function save_supplier(array &$person_data, array &$supplier_data, bool $supplier_id = FALSE): bool + public function save_supplier(array &$person_data, array &$supplier_data, int $supplier_id = NEW_ENTRY): bool { $success = FALSE; @@ -120,7 +120,7 @@ class Supplier extends Person if(parent::save_value($person_data,$supplier_id)) { $builder = $this->db->table('suppliers'); - if(!$supplier_id || !$this->exists($supplier_id)) + if($supplier_id == NEW_ENTRY || !$this->exists($supplier_id)) { $supplier_data['person_id'] = $person_data['person_id']; $success = $builder->insert($supplier_data); @@ -255,7 +255,7 @@ class Supplier extends Person /** * Gets rows */ - public function get_found_rows(string $search): ResultInterface + public function get_found_rows(string $search): int { return $this->search($search, 0, 0, 'last_name', 'asc', TRUE); } @@ -263,8 +263,15 @@ class Supplier extends Person /** * Perform a search on suppliers */ - public function search(string $search, int $rows = 0, int $limit_from = 0, string $sort = 'last_name', string $order = 'asc', bool $count_only = FALSE): ResultInterface + public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'last_name', ?string $order = 'asc', ?bool $count_only = FALSE) { + // Set default values + if($rows == null) $rows = 0; + if($limit_from == null) $limit_from = 0; + if($sort == null) $sort = 'last_name'; + if($order == null) $order = 'asc'; + if($count_only == null) $count_only = FALSE; + $builder = $this->db->table('suppliers AS suppliers'); //get_found_rows case diff --git a/app/Models/Tax.php b/app/Models/Tax.php index b727b7552..012dd32ef 100644 --- a/app/Models/Tax.php +++ b/app/Models/Tax.php @@ -163,10 +163,10 @@ class Tax extends Model /** Inserts or updates a tax_rates entry */ - public function save_value(array &$tax_rate_data, int $tax_rate_id = -1): bool //TODO: the default value for $tax_rate_id should be made a constant and replaced here. + public function save_value(array &$tax_rate_data, int $tax_rate_id = NEW_ENTRY): bool { $builder = $this->db->table('tax_rates'); - if(!$this->exists($tax_rate_id)) + if($tax_rate_id == NEW_ENTRY || !$this->exists($tax_rate_id)) { if($builder->insert($tax_rate_data)) { @@ -212,7 +212,7 @@ class Tax extends Model /** * Gets tax_codes */ - public function get_found_rows(string $search): ResultInterface + public function get_found_rows(string $search): int { return $this->search($search, 0, 0, 'tax_code_name', 'asc', TRUE); } @@ -220,8 +220,15 @@ class Tax extends Model /** * Performs a search on tax_rates */ - public function search(string $search, int $rows = 0, int $limit_from = 0, string $sort = 'tax_code_name', string $order = 'asc', bool $count_only = FALSE): ResultInterface + public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'tax_code_name', ?string $order = 'asc', ?bool $count_only = FALSE) { + // Set default values + if($rows == null) $rows = 0; + if($limit_from == null) $limit_from = 0; + if($sort == null) $sort = 'tax_code_name'; + if($order == null) $order = 'asc'; + if($count_only == null) $count_only = FALSE; + $builder = $this->db->table('tax_rates'); // get_found_rows case diff --git a/app/Models/Tax_category.php b/app/Models/Tax_category.php index 4139fab49..f628b3d89 100644 --- a/app/Models/Tax_category.php +++ b/app/Models/Tax_category.php @@ -109,11 +109,11 @@ class Tax_category extends Model /** * Inserts or updates a row */ - public function save_value(array &$tax_category_data, bool $tax_category_id = FALSE): bool + public function save_value(array &$tax_category_data, int $tax_category_id = NEW_ENTRY): bool { $builder = $this->db->table('tax_categories'); - if(!$tax_category_id || !$this->exists($tax_category_id)) + if($tax_category_id == NEW_ENTRY || !$this->exists($tax_category_id)) { if($builder->insert($tax_category_data)) { @@ -150,7 +150,7 @@ class Tax_category extends Model $this->save_value($tax_category_data, $value['tax_category_id']); - if($value['tax_category_id'] == -1) //TODO: -1 should be converted into a constant for code readability. Perhaps NO_TAX_CATEGORY? + if($value['tax_category_id'] == NEW_ENTRY) { $not_to_delete[] = $tax_category_data['tax_category_id']; } @@ -200,7 +200,7 @@ class Tax_category extends Model /** * Gets rows */ - public function get_found_rows(string $search): ResultInterface + public function get_found_rows(string $search): int { return $this->search($search, 0, 0, 'tax_category', 'asc', TRUE); } @@ -208,8 +208,15 @@ class Tax_category extends Model /** * Perform a search for a set of rows */ - public function search(string $search, int $rows = 0, int $limit_from = 0, string $sort = 'tax_category', string $order = 'asc', bool $count_only = FALSE): ResultInterface + public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'tax_category', ?string $order = 'asc', ?bool $count_only = FALSE) { + // Set default values + if($rows == null) $rows = 0; + if($limit_from == null) $limit_from = 0; + if($sort == null) $sort = 'tax_category'; + if($order == null) $order = 'asc'; + if($count_only == null) $count_only = FALSE; + $builder = $this->db->table('tax_categories AS tax_categories'); // get_found_rows case @@ -263,7 +270,7 @@ class Tax_category extends Model { return [ '0' => [ - 'tax_category_id' => -1, //TODO: This should probably be a Constant instead of -1 + 'tax_category_id' => NEW_ENTRY, 'tax_category' => '', 'tax_group_sequence' => '', 'deleted' => '' diff --git a/app/Models/Tax_code.php b/app/Models/Tax_code.php index e026951b3..5a763086b 100644 --- a/app/Models/Tax_code.php +++ b/app/Models/Tax_code.php @@ -48,15 +48,18 @@ class Tax_code extends Model /** * Gets information about the particular record */ - public function get_info(int $tax_code_id): object + public function get_info(?int $tax_code_id): object { - $builder = $this->db->table('tax_codes'); + if($tax_code_id != null) + { + $builder = $this->db->table('tax_codes'); - $builder->where('tax_code_id', $tax_code_id); - $builder->where('deleted', 0); - $query = $builder->get(); + $builder->where('tax_code_id', $tax_code_id); + $builder->where('deleted', 0); + $query = $builder->get(); + } - if($query->getNumRows() == 1) //TODO: === + if($tax_code_id != null && $query->getNumRows() === 1) { return $query->getRow(); } @@ -68,7 +71,7 @@ class Tax_code extends Model //Get all the fields from the table foreach($this->db->getFieldNames('tax_codes') as $field) { - $tax_code_obj->$field = ''; + $tax_code_obj->$field = null; } return $tax_code_obj; } @@ -191,7 +194,7 @@ class Tax_code extends Model /** * Gets rows */ - public function get_found_rows(string $search): ResultInterface + public function get_found_rows(string $search): int { return $this->search($search, 0, 0, 'tax_code_name', 'asc', TRUE); } @@ -199,8 +202,15 @@ class Tax_code extends Model /** * Perform a search for a set of rows */ - public function search(string $search, int $rows = 0, int $limit_from = 0, string $sort = 'tax_code_name', string $order = 'asc', bool $count_only = FALSE): ResultInterface + public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'tax_code_name', ?string $order = 'asc', ?bool $count_only = FALSE) { + // Set default values + if($rows == null) $rows = 0; + if($limit_from == null) $limit_from = 0; + if($sort == null) $sort = 'tax_code_name'; + if($order == null) $order = 'asc'; + if($count_only == null) $count_only = FALSE; + $builder = $this->db->table('tax_codes AS tax_codes'); // get_found_rows case @@ -303,7 +313,7 @@ class Tax_code extends Model { return [ '0' => [ - 'tax_code_id' => -1, + 'tax_code_id' => NEW_ENTRY, 'tax_code' => '', 'tax_code_name' => '', 'city' => '', diff --git a/app/Models/Tax_jurisdiction.php b/app/Models/Tax_jurisdiction.php index d5b7beb1c..94951b6fc 100644 --- a/app/Models/Tax_jurisdiction.php +++ b/app/Models/Tax_jurisdiction.php @@ -113,10 +113,10 @@ class Tax_jurisdiction extends Model /** * Inserts or updates a row */ - public function save_value(array &$jurisdiction_data, bool $jurisdiction_id = FALSE): bool + public function save_value(array &$jurisdiction_data, int $jurisdiction_id = NEW_ENTRY): bool { $builder = $this->db->table('tax_jurisdictions'); - if(!$jurisdiction_id || !$this->exists($jurisdiction_id)) + if($jurisdiction_id == NEW_ENTRY || !$this->exists($jurisdiction_id)) { if($builder->insert($jurisdiction_data)) //TODO: Replace this with simply a return of the result of insert()... see update() below. { @@ -155,7 +155,7 @@ class Tax_jurisdiction extends Model $this->save_value($tax_jurisdiction_data, $value['jurisdiction_id']); - if($value['jurisdiction_id'] == -1) //TODO: replace -1 with a constant. Also === ?. Also replace this with ternary notation. + if($value['jurisdiction_id'] == NEW_ENTRY) { $not_to_delete[] = $tax_jurisdiction_data['jurisdiction_id']; } @@ -205,7 +205,7 @@ class Tax_jurisdiction extends Model /** * Gets rows */ - public function get_found_rows(string $search): ResultInterface + public function get_found_rows(string $search): int { return $this->search($search, 0, 0, 'jurisdiction_name', 'asc', TRUE); } @@ -213,8 +213,15 @@ class Tax_jurisdiction extends Model /** * Perform a search for a set of rows */ - public function search(string $search, int $rows = 0, int $limit_from = 0, string $sort = 'jurisdiction_name', string $order = 'asc', bool $count_only = FALSE): ResultInterface + public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'jurisdiction_name', ?string $order = 'asc', ?bool $count_only = FALSE) { + // Set default values + if($rows == null) $rows = 0; + if($limit_from == null) $limit_from = 0; + if($sort == null) $sort = 'jurisdiction_name'; + if($order == null) $order = 'asc'; + if($count_only == null) $count_only = FALSE; + $builder = $this->db->table('tax_jurisdictions AS tax_jurisdictions'); // get_found_rows case @@ -249,7 +256,7 @@ class Tax_jurisdiction extends Model { return [ '0' => [ - 'jurisdiction_id' => -1, //TODO: Replace -1 with a constant + 'jurisdiction_id' => NEW_ENTRY, 'jurisdiction_name' => '', 'tax_group' => '', 'tax_type' => '1', diff --git a/app/Models/Tokens/Token_customer.php b/app/Models/Tokens/Token_customer.php index 2475e2b05..83575e831 100644 --- a/app/Models/Tokens/Token_customer.php +++ b/app/Models/Tokens/Token_customer.php @@ -34,7 +34,7 @@ class Token_customer extends Token { //substitute customer info $customer_id = $this->sale_lib->get_customer(); - if($customer_id != -1 && empty($this->customer_info)) //TODO: Replace -1 with a Constant + if($customer_id != NEW_ITEM && empty($this->customer_info)) { $customer = model(Customer::class); $customer_info = $customer->get_info($customer_id); diff --git a/app/Views/attributes/form.php b/app/Views/attributes/form.php index 5bcd0ab87..8778dbfff 100644 --- a/app/Views/attributes/form.php +++ b/app/Views/attributes/form.php @@ -13,7 +13,7 @@ - 'attribute_form', 'class' => 'form-horizontal']) //TODO: String Interpolation?> + 'attribute_form', 'class' => 'form-horizontal']) //TODO: String Interpolation?>
@@ -23,7 +23,7 @@ 'name' => 'definition_name', 'id' => 'definition_name', 'class' => 'form-control input-sm', - 'value'=>esc($definition_info->definition_name, 'attr') + 'value'=>esc($definition_info->definition_name) ] ) ?>
@@ -41,8 +41,8 @@
definition_fk, 'attr'), + esc($definition_group), + esc($definition_info->definition_fk), 'id="definition_group" class="form-control" ' . (empty($definition_group) ? 'disabled="disabled"' : '') ) ?>
@@ -54,8 +54,8 @@
'definition_flags', 'class' => 'selectpicker show-menu-arrow', @@ -75,7 +75,7 @@
'definition_unit', - 'value' => esc($definition_info->definition_unit, 'attr'), + 'value' => esc($definition_info->definition_unit), 'class' => 'form-control input-sm', 'id' => 'definition_unit' ]) ?> @@ -181,7 +181,7 @@ $(document).ready(function() } else { - $.post('', {definition_id: definition_id, attribute_value: value}); + $.post('', {definition_id: definition_id, attribute_value: value}); } $(this).parents("li").remove(); }; @@ -210,7 +210,7 @@ $(document).ready(function() } else { - $.post('', {definition_id: definition_id, attribute_value: value}); + $.post('', {definition_id: definition_id, attribute_value: value}); } } @@ -256,7 +256,7 @@ $(document).ready(function() success: function(response) { dialog_support.hide(); - table_support.handle_submit('', response); + table_support.handle_submit('', response); }, dataType: 'json' }); @@ -274,4 +274,4 @@ $(document).ready(function() } }, form_support.error)); }); - \ No newline at end of file + diff --git a/app/Views/attributes/item.php b/app/Views/attributes/item.php index d327724a9..f0058ed3c 100644 --- a/app/Views/attributes/item.php +++ b/app/Views/attributes/item.php @@ -8,7 +8,7 @@
'control-label col-xs-3']) ?>
- 'definition_name', 'class' => 'form-control']) ?> + 'definition_name', 'class' => 'form-control']) ?>
@@ -19,18 +19,18 @@ foreach($definition_values as $definition_id => $definition_value) ?>
- 'control-label col-xs-3']) ?> + 'control-label col-xs-3']) ?>
attribute_date)) ? NOW : strtotime($attribute_value->attribute_date); echo form_input ([ - 'name' => esc("attribute_links[$definition_id]", 'attr'), + 'name' => esc("attribute_links[$definition_id]"), 'value' => to_date($value), 'class' => 'form-control input-sm datetime', 'data-definition-id' => $definition_id, @@ -40,17 +40,17 @@ foreach($definition_values as $definition_id => $definition_value) else if ($definition_value['definition_type'] == DROPDOWN) //TODO: === ? { $selected_value = $definition_value['selected_value']; - echo form_dropdown(esc("attribute_links[$definition_id]", 'attr'), esc($definition_value['values'], 'attr'), esc($selected_value, 'attr'), "class='form-control' data-definition-id='$definition_id'"); + echo form_dropdown(esc("attribute_links[$definition_id]"), esc($definition_value['values']), esc($selected_value), "class='form-control' data-definition-id='$definition_id'"); } else if ($definition_value['definition_type'] == TEXT) //TODO: === ? { $value = (empty($attribute_value) || empty($attribute_value->attribute_value)) ? $definition_value['selected_value'] : $attribute_value->attribute_value; - echo form_input(esc("attribute_links[$definition_id]"), esc($value, 'attr'), "class='form-control valid_chars' data-definition-id='$definition_id'"); + echo form_input(esc("attribute_links[$definition_id]"), esc($value), "class='form-control valid_chars' data-definition-id='$definition_id'"); } else if ($definition_value['definition_type'] == DECIMAL) //TODO: === ? { $value = (empty($attribute_value) || empty($attribute_value->attribute_decimal)) ? $definition_value['selected_value'] : $attribute_value->attribute_decimal; - echo form_input(esc("attribute_links[$definition_id]"), esc($value, 'attr'), "class='form-control valid_chars' data-definition-id='$definition_id'"); + echo form_input(esc("attribute_links[$definition_id]"), esc($value), "class='form-control valid_chars' data-definition-id='$definition_id'"); } else if ($definition_value['definition_type'] == CHECKBOX) //TODO: === ? { @@ -59,13 +59,13 @@ foreach($definition_values as $definition_id => $definition_value) //Sends 0 if the box is unchecked instead of not sending anything. echo form_input ([ 'type' => 'hidden', - 'name' => esc("attribute_links[$definition_id]", 'attr'), + 'name' => esc("attribute_links[$definition_id]"), 'id' => "attribute_links[$definition_id]", 'value' => 0, 'data-definition-id' => $definition_id ]); echo form_checkbox ([ - 'name' => esc("attribute_links[$definition_id]", 'attr'), + 'name' => esc("attribute_links[$definition_id]"), 'id' => "attribute_links[$definition_id]", 'value' => 1, 'checked' => ($value ? 1 : 0), @@ -100,7 +100,7 @@ foreach($definition_values as $definition_id => $definition_value) $("input[name='attribute_ids[" + definition_id + "]']").val(''); }).autocomplete({ source: function(request, response) { - $.get('' + this.element.data('definition-id') + '?term=' + request.term, function(data) { + $.get('' + this.element.data('definition-id') + '?term=' + request.term, function(data) { return response(data); }, 'json'); }, @@ -125,7 +125,7 @@ foreach($definition_values as $definition_id => $definition_value) var definition_id = $("#definition_name option:selected").val(); var attribute_values = definition_values(); attribute_values[definition_id] = ''; - $('#attributes').load('', { + $('#attributes').load('', { 'definition_ids': JSON.stringify(attribute_values) }, enable_delete); }; diff --git a/app/Views/attributes/manage.php b/app/Views/attributes/manage.php index d694f97d4..46f0e869d 100644 --- a/app/Views/attributes/manage.php +++ b/app/Views/attributes/manage.php @@ -13,8 +13,8 @@ table_support.init({ - resource: '', - headers: , + resource: '', + headers: , pageSize: , uniqueId: 'definition_id' }); @@ -23,7 +23,7 @@ diff --git a/app/Views/configs/email_config.php b/app/Views/configs/email_config.php index 1b90dd51d..b23b31c1c 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['protocol'], 'attr'), + esc($config['protocol']), ['class' => 'form-control input-sm', 'id' => 'protocol']) ?>
@@ -26,7 +26,7 @@ 'name' => 'mailpath', 'id' => 'mailpath', 'class' => 'form-control input-sm', - 'value' => esc($config['mailpath'], 'attr') + 'value' => esc($config['mailpath']) ]) ?>
@@ -38,7 +38,7 @@ 'name' => 'smtp_host', 'id' => 'smtp_host', 'class' => 'form-control input-sm', - 'value' => esc($config['smtp_host'], 'attr') + 'value' => esc($config['smtp_host']) ]) ?>
@@ -63,7 +63,7 @@ 'tls' => 'TLS', 'ssl' => 'SSL' ], - esc($config['smtp_crypto'], 'attr'), + esc($config['smtp_crypto']), ['class' => 'form-control input-sm', 'id' => 'smtp_crypto']) ?> @@ -90,7 +90,7 @@ 'name' => 'smtp_user', 'id' => 'smtp_user', 'class' => 'form-control input-sm', - 'value' => esc($config['smtp_user'], 'attr') + 'value' => esc($config['smtp_user']) ]) ?> @@ -105,7 +105,7 @@ 'name' => 'smtp_pass', 'id' => 'smtp_pass', 'class' => 'form-control input-sm', - 'value' => esc($config['smtp_pass'], 'attr') + 'value' => esc($config['smtp_pass']) ]) ?> diff --git a/app/Views/configs/general_config.php b/app/Views/configs/general_config.php index 9a5e4dca0..7d9b8130c 100644 --- a/app/Views/configs/general_config.php +++ b/app/Views/configs/general_config.php @@ -18,7 +18,7 @@
@@ -170,7 +170,7 @@ 'center' => lang('Config.center'), 'right' => lang('Config.right') ], - esc($config['notify_horizontal_position'], 'attr'), + esc($config['notify_horizontal_position']), ['class' => 'form-control input-sm'] ) ?>
@@ -274,7 +274,7 @@ 'name' => 'gcaptcha_site_key', 'id' => 'gcaptcha_site_key', 'class' => 'form-control input-sm required', - 'value' => esc($config['gcaptcha_site_key'], 'attr') + 'value' => esc($config['gcaptcha_site_key']) ]) ?> @@ -286,7 +286,7 @@ 'name' => 'gcaptcha_secret_key', 'id' => 'gcaptcha_secret_key', 'class' => 'form-control input-sm required', - 'value' => esc($config['gcaptcha_secret_key'], 'attr') + 'value' => esc($config['gcaptcha_secret_key']) ]) ?> @@ -306,7 +306,7 @@ 'unit_price' => lang('Items.unit_price'), 'cost_price' => lang('Items.cost_price') ], - esc($config['suggestions_first_column'], 'attr'), + esc($config['suggestions_first_column']), ['class' => 'form-control input-sm'] ) ?> @@ -323,7 +323,7 @@ 'unit_price' => lang('Items.unit_price'), 'cost_price' => lang('Items.cost_price') ], - esc($config['suggestions_second_column'], 'attr'), + esc($config['suggestions_second_column']), ['class' => 'form-control input-sm'] ) ?> @@ -340,7 +340,7 @@ 'unit_price' => lang('Items.unit_price'), 'cost_price' => lang('Items.cost_price') ], - esc($config['suggestions_third_column'], 'attr'), + esc($config['suggestions_third_column']), ['class' => 'form-control input-sm'] ) ?> @@ -473,12 +473,12 @@ $(document).ready(function() lines_per_page: { required: true, - remote: "" + remote: "" }, default_sales_discount: { required: true, - remote: "" + remote: "" }, gcaptcha_site_key: { diff --git a/app/Views/configs/info_config.php b/app/Views/configs/info_config.php index 6befe732a..5220a6f1f 100644 --- a/app/Views/configs/info_config.php +++ b/app/Views/configs/info_config.php @@ -55,7 +55,7 @@ 'name' => 'address', 'id' => 'address', 'class' => 'form-control input-sm required', - 'value'=> $config['address'], 'attr' + 'value'=> $config['address'] ]) ?> @@ -149,7 +149,7 @@ $(document).ready(function() $("a.fileinput-exists").click(function() { $.ajax({ type: 'POST', - url: '', + url: '', dataType: 'json' }) }); diff --git a/app/Views/configs/integrations_config.php b/app/Views/configs/integrations_config.php index 526598779..e01f3953a 100644 --- a/app/Views/configs/integrations_config.php +++ b/app/Views/configs/integrations_config.php @@ -20,7 +20,7 @@ 'name' => 'mailchimp_api_key', 'id' => 'mailchimp_api_key', 'class' => 'form-control input-sm', - 'value' => esc($mailchimp['api_key'], 'attr') + 'value' => esc($mailchimp['api_key']) ]) ?> @@ -38,8 +38,8 @@ 'mailchimp_list_id', 'class' => 'form-control input-sm'] ) ?> @@ -61,7 +61,7 @@ $(document).ready(function() { $('#mailchimp_api_key').change(function() { - $.post("", { + $.post("", { 'mailchimp_api_key': $('#mailchimp_api_key').val() }, function(response) { diff --git a/app/Views/configs/invoice_config.php b/app/Views/configs/invoice_config.php index 378a9d1fe..9587e9851 100644 --- a/app/Views/configs/invoice_config.php +++ b/app/Views/configs/invoice_config.php @@ -25,7 +25,7 @@
'control-label col-xs-2']) ?>
- 'form-control input-sm']) ?> + 'form-control input-sm']) ?>
@@ -36,7 +36,7 @@ 'name' => 'recv_invoice_format', 'id' => 'recv_invoice_format', 'class' => 'form-control input-sm', - 'value' => esc($config['recv_invoice_format'], 'attr') + 'value' => esc($config['recv_invoice_format']) ]) ?> @@ -48,7 +48,7 @@ 'name' => 'invoice_default_comments', 'id' => 'invoice_default_comments', 'class' => 'form-control input-sm', - 'value' => esc($config['invoice_default_comments'], 'attr') + 'value' => esc($config['invoice_default_comments']) ]) ?> @@ -60,7 +60,7 @@ 'name' => 'invoice_email_message', 'id' => 'invoice_email_message', 'class' => 'form-control input-sm', - 'value' => esc($config['invoice_email_message'], 'attr') + 'value' => esc($config['invoice_email_message']) ]) ?> @@ -68,7 +68,7 @@
'control-label col-xs-2']) ?>
- 'form-control input-sm']) ?> + 'form-control input-sm']) ?>
@@ -79,7 +79,7 @@ 'name' => 'sales_invoice_format', 'id' => 'sales_invoice_format', 'class' => 'form-control input-sm', - 'value' => esc($config['sales_invoice_format'], 'attr') + 'value' => esc($config['sales_invoice_format']) ]) ?> @@ -104,7 +104,7 @@ 'name' => 'sales_quote_format', 'id' => 'sales_quote_format', 'class' => 'form-control input-sm', - 'value' => esc($config['sales_quote_format'], 'attr') + 'value' => esc($config['sales_quote_format']) ]) ?> @@ -129,7 +129,7 @@ 'name' => 'quote_default_comments', 'id' => 'quote_default_comments', 'class' => 'form-control input-sm', - 'value' => esc($config['quote_default_comments'], 'attr') + 'value' => esc($config['quote_default_comments']) ]) ?> @@ -153,7 +153,7 @@ 'name' => 'work_order_format', 'id' => 'work_order_format', 'class' => 'form-control input-sm', - 'value' => esc($config['work_order_format'], 'attr') + 'value' => esc($config['work_order_format']) ]) ?> diff --git a/app/Views/configs/license_config.php b/app/Views/configs/license_config.php index 6faf9cea6..93086ce79 100644 --- a/app/Views/configs/license_config.php +++ b/app/Views/configs/license_config.php @@ -12,14 +12,14 @@ { ?>
- 'control-label col-xs-3']) ?> + 'control-label col-xs-3']) ?>
'license', 'id' => 'license_' . $counter++, //TODO: String Interpolation 'class' => 'form-control', 'readonly' => '', - 'value' => esc($license['text'], 'attr') + 'value' => esc($license['text']) ]) ?>
diff --git a/app/Views/configs/locale_config.php b/app/Views/configs/locale_config.php index 1f8b9d3c3..9063dc11d 100644 --- a/app/Views/configs/locale_config.php +++ b/app/Views/configs/locale_config.php @@ -16,8 +16,8 @@ 'control-label col-xs-2']) ?>
- 'form-control input-sm', 'id' => 'number_locale']) ?> - + 'form-control input-sm', 'id' => 'number_locale']) ?> +
@@ -63,7 +63,7 @@ 'name' => 'currency_code', 'id' => 'currency_code', 'class' => 'form-control input-sm number_locale', - 'value' => esc($currency_code, 'attr') + 'value' => esc($currency_code) ]) ?> @@ -144,7 +144,7 @@
'control-label col-xs-2']) ?>
- 'form-control input-sm']) ?> + 'form-control input-sm']) ?>
@@ -160,7 +160,7 @@ 'creditdebitcash' => lang('Sales.credit') . ' / ' . lang('Sales.debit') . ' / ' . lang('Sales.cash'), 'creditcashdebit' => lang('Sales.credit') . ' / ' . lang('Sales.cash') . ' / ' . lang('Sales.debit') ], - esc($config['payment_options_order'], 'attr'), + esc($config['payment_options_order']), ['class' => 'form-control input-sm'] ) ?> @@ -169,7 +169,7 @@
'control-label col-xs-2']) ?>
- 'form-control input-sm']) ?> + 'form-control input-sm']) ?>
@@ -207,7 +207,7 @@ 'form-control input-sm'] ) ?> diff --git a/app/Views/configs/message_config.php b/app/Views/configs/message_config.php index d261403ea..3afc35b28 100644 --- a/app/Views/configs/message_config.php +++ b/app/Views/configs/message_config.php @@ -13,7 +13,7 @@ 'name' => 'msg_uid', 'id' => 'msg_uid', 'class' => 'form-control input-sm required', - 'value' => esc($config['msg_uid'], 'attr') + 'value' => esc($config['msg_uid']) ]) ?> @@ -28,7 +28,7 @@ 'name' => 'msg_pwd', 'id' => 'msg_pwd', 'class' => 'form-control input-sm required', - 'value' => esc($config['msg_pwd'], 'attr') + 'value' => esc($config['msg_pwd']) ]) ?> @@ -43,7 +43,7 @@ 'name' => 'msg_src', 'id' => 'msg_src', 'class' => 'form-control input-sm required', - 'value' => $config['msg_src'] == NULL ? esc($config['company'], 'attr') : esc($config['msg_src'], 'attr') + 'value' => $config['msg_src'] == NULL ? esc($config['company']) : esc($config['msg_src']) ]) ?> diff --git a/app/Views/configs/receipt_config.php b/app/Views/configs/receipt_config.php index f272ada48..7aeb737a6 100644 --- a/app/Views/configs/receipt_config.php +++ b/app/Views/configs/receipt_config.php @@ -12,7 +12,7 @@ 'receipt_default' => lang('Config.receipt_default'), 'receipt_short' => lang('Config.receipt_short') ], - esc($config['receipt_template'], 'attr'), + esc($config['receipt_template']), ['class' => 'form-control input-sm'] ) ?> diff --git a/app/Views/configs/reward_config.php b/app/Views/configs/reward_config.php index a4478fb5e..ffd345121 100644 --- a/app/Views/configs/reward_config.php +++ b/app/Views/configs/reward_config.php @@ -122,7 +122,7 @@ $(document).ready(function() }, success: function(response) { $.notify({ message: response.message }, { type: response.success ? 'success' : 'danger'}); - $("#customer_rewards").load('', init_add_remove_tables); + $("#customer_rewards").load('', init_add_remove_tables); }, dataType: 'json' }); diff --git a/app/Views/configs/stock_config.php b/app/Views/configs/stock_config.php index 77b6f8136..dc918e9f4 100644 --- a/app/Views/configs/stock_config.php +++ b/app/Views/configs/stock_config.php @@ -80,7 +80,7 @@ $(document).ready(function() $(form).ajaxSubmit({ success: function(response) { $.notify({ message: response.message }, { type: response.success ? 'success' : 'danger'}); - $("#stock_locations").load('', init_add_remove_locations); + $("#stock_locations").load('', init_add_remove_locations); }, dataType: 'json' }); diff --git a/app/Views/configs/table_config.php b/app/Views/configs/table_config.php index 21e81df98..5dc6301bf 100644 --- a/app/Views/configs/table_config.php +++ b/app/Views/configs/table_config.php @@ -117,7 +117,7 @@ $(document).ready(function() }, success: function(response) { $.notify({ message: response.message }, { type: response.success ? 'success' : 'danger'}); - $("#dinner_tables").load('', init_add_remove_tables); + $("#dinner_tables").load('', init_add_remove_tables); }, dataType: 'json' }); diff --git a/app/Views/configs/tax_config.php b/app/Views/configs/tax_config.php index 9770bfd92..a401d3883 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['tax_id'], 'attr') + 'value' => esc($config['tax_id']) ]) ?> @@ -43,7 +43,7 @@ 'name' => 'default_tax_1_name', 'id' => 'default_tax_1_name', 'class' => 'form-control input-sm', - 'value' => $config['default_tax_1_name'] !== FALSE ? esc($config['default_tax_1_name'], 'attr') : lang('Items.sales_tax_1')]) ?> + 'value' => $config['default_tax_1_name'] !== FALSE ? esc($config['default_tax_1_name']) : lang('Items.sales_tax_1')]) ?>
'default_tax_2_name', 'id' => 'default_tax_2_name', 'class' => 'form-control input-sm', - 'value' => $config['default_tax_2_name'] !== FALSE ? esc($config['default_tax_2_name'], 'attr') : lang('Items.sales_tax_2') + 'value' => $config['default_tax_2_name'] !== FALSE ? esc($config['default_tax_2_name']) : lang('Items.sales_tax_2') ]) ?>
@@ -92,21 +92,21 @@
'control-label col-xs-2']) ?>
- 'form-control input-sm']) ?> + 'form-control input-sm']) ?>
'control-label col-xs-2']) ?>
- 'form-control input-sm']) ?> + 'form-control input-sm']) ?>
'control-label col-xs-2']) ?>
- 'form-control input-sm']) ?> + 'form-control input-sm']) ?>
@@ -159,11 +159,11 @@ $(document).ready(function() { default_tax_1_rate: { - remote: "" + remote: "" }, default_tax2_rate: { - remote: "" + remote: "" }, }, diff --git a/app/Views/customers/form.php b/app/Views/customers/form.php index ddb69bb6c..0adc08162 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['enforce_privacy'] : (boolean)$person_info->consent) ?> + consent == '' ? !$config['enforce_privacy'] : (boolean)$person_info->consent) ?>
@@ -100,7 +100,7 @@ 'name' => 'company_name', 'id' => 'company_name', 'class' => 'form-control input-sm', - 'value' => esc($person_info->company_name, 'attr') + 'value' => esc($person_info->company_name) ]) ?>
@@ -112,7 +112,7 @@ 'name' => 'account_number', 'id' => 'account_number', 'class' => 'form-control input-sm', - 'value' => esc($person_info->account_number, 'attr') + 'value' => esc($person_info->account_number) ]) ?> @@ -124,7 +124,7 @@ 'name' => 'tax_id', 'id' => 'tax_id', 'class' => 'form-control input-sm', - 'value' => esc($person_info->tax_id, 'attr') + 'value' => esc($person_info->tax_id) ]) ?> @@ -133,7 +133,7 @@
'control-label col-xs-3']) ?>
- 'form-control']) ?> + 'form-control']) ?>
@@ -154,7 +154,7 @@
'control-label col-xs-3']) ?>
- taxable == '' || $person_info->taxable) ?> + taxable == 1) ?>
@@ -171,7 +171,7 @@ 'id' => 'sales_tax_code_name', 'class' => 'form-control input-sm', 'size' => '50', - 'value' => esc($sales_tax_code_label, 'attr') + 'value' => esc($sales_tax_code_label) ]) ?> sales_tax_code_id) ?> @@ -204,7 +204,7 @@ 'name' => 'employee', 'id' => 'employee', 'class' => 'form-control input-sm', - 'value' => esc($employee, 'attr'), + 'value' => esc($employee), 'readonly' => 'true' ]) ?> @@ -356,7 +356,7 @@ 'cleaned' => 'cleaned', 'pending' => 'pending' ], - esc($mailchimp_info['status'], 'attr'), + esc($mailchimp_info['status']), ['id' => 'mailchimp_status', 'class' => 'form-control input-sm']) ?> @@ -364,7 +364,7 @@
'control-label col-xs-3']) ?>
- +
@@ -374,7 +374,7 @@ 'mailchimp_member_rating', 'class' => 'form-control input-sm', - 'value' => esc($mailchimp_info['member_rating'], 'attr'), + 'value' => esc($mailchimp_info['member_rating']), 'disabled' => '' ]) ?> @@ -386,7 +386,7 @@ 'mailchimp_activity_total', 'class' => 'form-control input-sm', - 'value' => esc($mailchimp_activity['total'], 'attr'), + 'value' => esc($mailchimp_activity['total']), 'disabled' => '' ]) ?> @@ -398,7 +398,7 @@ 'mailchimp_activity_lastopen', 'class' => 'form-control input-sm', - 'value' => esc($mailchimp_activity['lastopen'], 'attr'), + 'value' => esc($mailchimp_activity['lastopen']), 'disabled' => '' ]) ?> @@ -410,7 +410,7 @@ 'mailchimp_activity_open', 'class' => 'form-control input-sm', - 'value' => esc($mailchimp_activity['open'], 'attr'), + 'value' => esc($mailchimp_activity['open']), 'disabled' => '' ]) ?> @@ -422,7 +422,7 @@ 'mailchimp_activity_click', 'class' => 'form-control input-sm', - 'value' => esc($mailchimp_activity['click'], 'attr'), + 'value' => esc($mailchimp_activity['click']), 'disabled' => '' ]) ?> @@ -434,7 +434,7 @@ 'mailchimp_activity_unopen', 'class' => 'form-control input-sm', - 'value' => esc($mailchimp_activity['unopen'], 'attr'), + 'value' => esc($mailchimp_activity['unopen']), 'disabled' => '' ]) ?> @@ -446,7 +446,7 @@ 'mailchimp_email_client', 'class' => 'form-control input-sm', - 'value' => esc($mailchimp_info['email_client'], 'attr'), + 'value' => esc($mailchimp_info['email_client']), 'disabled' => '' ]) ?> @@ -476,7 +476,7 @@ $(document).ready(function() }; $('#sales_tax_code_name').autocomplete({ - source: "", + source: "", minChars: 0, delay: 15, cacheLength: 1, @@ -491,7 +491,7 @@ $(document).ready(function() success: function(response) { dialog_support.hide(); - table_support.handle_submit("", response); + table_support.handle_submit("", response); }, dataType: 'json' }); @@ -508,7 +508,7 @@ $(document).ready(function() { remote: { - url: "", + url: "", type: 'POST', data: { 'person_id': "person_id ?>" @@ -520,7 +520,7 @@ $(document).ready(function() { remote: { - url: "", + url: "", type: 'POST', data: { 'person_id': "person_id ?>" diff --git a/app/Views/customers/form_csv_import.php b/app/Views/customers/form_csv_import.php index 1f21597ef..9ca757388 100644 --- a/app/Views/customers/form_csv_import.php +++ b/app/Views/customers/form_csv_import.php @@ -4,7 +4,7 @@
@@ -30,7 +30,7 @@ $(document).ready(function() success: function(response) { dialog_support.hide(); - table_support.handle_submit('', response); + table_support.handle_submit('', response); }, dataType: 'json' }); diff --git a/app/Views/employees/form.php b/app/Views/employees/form.php index b5dbc26de..17ba45825 100644 --- a/app/Views/employees/form.php +++ b/app/Views/employees/form.php @@ -42,7 +42,7 @@ 'name' => 'username', 'id' => 'username', 'class' => 'form-control input-sm', - 'value' => esc($person_info->username, 'attr') + 'value' => esc($person_info->username) ]) ?> @@ -51,7 +51,7 @@ person_id == "" ? ['class' => 'required'] : []; ?>
- 'control-label col-xs-3']), 'attr'))?> + 'control-label col-xs-3'])))?>
@@ -65,7 +65,7 @@
- 'control-label col-xs-3']), 'attr')) ?> + 'control-label col-xs-3']))) ?>
@@ -97,8 +97,8 @@ echo form_dropdown( 'language', - esc($languages, 'attr'), - esc("$language_code:$language", 'attr'), + esc($languages), + esc("$language_code:$language"), ['class' => 'form-control input-sm'] ); ?> @@ -209,7 +209,7 @@ $(document).ready(function() success: function(response) { dialog_support.hide(); - table_support.handle_submit("", response); + table_support.handle_submit("", response); }, dataType: 'json' }); @@ -226,7 +226,7 @@ $(document).ready(function() required: true, minlength: 5, - remote: '' + remote: '' }, password: { diff --git a/app/Views/errors/html/error_exception.php b/app/Views/errors/html/error_exception.php index ae46d3056..29106a4e4 100644 --- a/app/Views/errors/html/error_exception.php +++ b/app/Views/errors/html/error_exception.php @@ -78,8 +78,8 @@   —   - ( arguments ) -
+ ( arguments ) +
'supplier_tax_code', 'id' => 'supplier_tax_code', 'class' => 'form-control input-sm', - 'value' => esc($expenses_info->supplier_tax_code, 'attr') + 'value' => esc($expenses_info->supplier_tax_code) ]) ?> @@ -111,21 +111,21 @@
'control-label col-xs-3']) ?>
- payment_type, 'attr'), ['class' => 'form-control', 'id' => 'payment_type']) ?> + payment_type), ['class' => 'form-control', 'id' => 'payment_type']) ?>
'control-label col-xs-3']) ?>
- expense_category_id, ['class' => 'form-control', 'id' => 'category']) ?> + expense_category_id, ['class' => 'form-control', 'id' => 'category']) ?>
'control-label col-xs-3']) ?>
- employee_id, 'id="employee_id" class="form-control"') ?> + employee_id, 'id="employee_id" class="form-control"') ?>
@@ -136,7 +136,7 @@ 'name' => 'description', 'id' => 'description', 'class' => 'form-control input-sm', - 'value' => esc($expenses_info->description, 'attr') + 'value' => esc($expenses_info->description) ]) ?> @@ -170,7 +170,7 @@ $(document).ready(function() var amount_validator = function(field) { return { - url: "", + url: "", type: 'POST', dataFilter: function(data) { var response = JSON.parse(data); @@ -226,7 +226,7 @@ $(document).ready(function() success: function(response) { dialog_support.hide(); - table_support.handle_submit("", response); + table_support.handle_submit("", response); }, dataType: 'json' }); diff --git a/app/Views/expenses/manage.php b/app/Views/expenses/manage.php index e5cf62814..a9a9a2cb6 100644 --- a/app/Views/expenses/manage.php +++ b/app/Views/expenses/manage.php @@ -25,8 +25,8 @@ $(document).ready(function() table_support.init({ - resource: '', - headers: , + resource: '', + headers: , pageSize: , uniqueId: 'expense_id', onLoadSuccess: function(response) { @@ -53,7 +53,7 @@ $(document).ready(function() - @@ -66,7 +66,7 @@ $(document).ready(function() 'daterangepicker', 'class' => 'form-control input-sm', 'id' => 'daterangepicker']) ?> - 'filters', 'data-none-selected-text' => lang('Common.none_selected_text'), 'class' => 'selectpicker show-menu-arrow', 'data-selected-text-format' => 'count > 1', 'data-style' => 'btn-default btn-sm', 'data-width' => 'fit']) ?> + 'filters', 'data-none-selected-text' => lang('Common.none_selected_text'), 'class' => 'selectpicker show-menu-arrow', 'data-selected-text-format' => 'count > 1', 'data-style' => 'btn-default btn-sm', 'data-width' => 'fit']) ?> diff --git a/app/Views/expenses_categories/form.php b/app/Views/expenses_categories/form.php index b531a9538..361a2020e 100644 --- a/app/Views/expenses_categories/form.php +++ b/app/Views/expenses_categories/form.php @@ -17,7 +17,7 @@ 'name' => 'category_name', 'id' => 'category_name', 'class' => 'form-control input-sm', - 'value' => esc($category_info->category_name, 'attr') + 'value' => esc($category_info->category_name) ]) ?> @@ -29,7 +29,7 @@ 'name' => 'category_description', 'id' => 'category_description', 'class' => 'form-control input-sm', - 'value' => esc($category_info->category_description, 'attr') + 'value' => esc($category_info->category_description) ]) ?> @@ -47,7 +47,7 @@ $(document).ready(function() success: function(response) { dialog_support.hide(); - table_support.handle_submit("", response); + table_support.handle_submit("", response); }, dataType: 'json' }); diff --git a/app/Views/expenses_categories/manage.php b/app/Views/expenses_categories/manage.php index 766e5b11d..18f0800a5 100644 --- a/app/Views/expenses_categories/manage.php +++ b/app/Views/expenses_categories/manage.php @@ -12,8 +12,8 @@ $(document).ready(function() table_support.init({ - resource: '', - headers: , + resource: '', + headers: , pageSize: , uniqueId: 'expense_category_id', @@ -28,7 +28,7 @@ $(document).ready(function()
- diff --git a/app/Views/giftcards/form.php b/app/Views/giftcards/form.php index 2f68c6c2d..6a8322b87 100644 --- a/app/Views/giftcards/form.php +++ b/app/Views/giftcards/form.php @@ -21,7 +21,7 @@ 'name' => 'person_name', 'id' => 'person_name', 'class' => 'form-control input-sm', - 'value' => esc($selected_person_name, 'attr') + 'value' => esc($selected_person_name) ]) ?>
@@ -41,7 +41,7 @@ 'name' => 'giftcard_number', 'id' => 'giftcard_number', 'class' => 'form-control input-sm', - 'value' => esc($giftcard_number, 'attr') + 'value' => esc($giftcard_number) ]) ?> @@ -83,7 +83,7 @@ $(document).ready(function() }; $('#person_name').autocomplete({ - source: "", + source: "", minChars: 0, delay: 15, cacheLength: 1, @@ -98,11 +98,11 @@ $(document).ready(function() success: function(response) { dialog_support.hide(); - table_support.handle_submit("", response); + table_support.handle_submit("", response); }, error: function(jqXHR, textStatus, errorThrown) { - table_support.handle_submit("", {message: errorThrown}); + table_support.handle_submit("", {message: errorThrown}); }, dataType: 'json' }); @@ -129,7 +129,7 @@ $(document).ready(function() required: true, remote: { - url: "", + url: "", type: 'POST', data: { 'amount': $('#giftcard_amount').val() diff --git a/app/Views/giftcards/manage.php b/app/Views/giftcards/manage.php index 49cf291c1..15b2bdaf2 100644 --- a/app/Views/giftcards/manage.php +++ b/app/Views/giftcards/manage.php @@ -10,8 +10,8 @@ $(document).ready(function() { table_support.init({ - resource: '', - headers: , + resource: '', + headers: , pageSize: , uniqueId: 'giftcard_id' }); @@ -19,7 +19,7 @@ $(document).ready(function()
- diff --git a/app/Views/home/form_change_password.php b/app/Views/home/form_change_password.php index 39448c650..516f63778 100644 --- a/app/Views/home/form_change_password.php +++ b/app/Views/home/form_change_password.php @@ -20,7 +20,7 @@ 'name' => 'username', 'id' => 'username', 'class' => 'form-control input-sm', - 'value' => esc($person_info->username, 'attr'), + 'value' => esc($person_info->username), 'readonly' => 'true' ]) ?>
diff --git a/app/Views/item_kits/form.php b/app/Views/item_kits/form.php index 416132f63..bf117cc32 100644 --- a/app/Views/item_kits/form.php +++ b/app/Views/item_kits/form.php @@ -22,7 +22,7 @@ 'name' => 'item_kit_number', 'id' => 'item_kit_number', 'class' => 'form-control input-sm', - 'value' => esc($item_kit_info->item_kit_number, 'attr') + 'value' => esc($item_kit_info->item_kit_number) ]) ?> @@ -35,7 +35,7 @@ 'name' => 'name', 'id' => 'name', 'class' => 'form-control input-sm', - 'value' => esc($item_kit_info->name, 'attr') + 'value' => esc($item_kit_info->name) ]) ?> @@ -49,7 +49,7 @@ 'id' => 'item_name', 'class' => 'form-control input-sm', 'size' => '50', - 'value' => esc($selected_kit_item, 'attr') + 'value' => esc($selected_kit_item) ]) ?> @@ -165,7 +165,7 @@ 'name' => 'description', 'id' => 'description', 'class' => 'form-control input-sm', - 'value' => esc($item_kit_info->description, 'attr') + 'value' => esc($item_kit_info->description) ]) ?> @@ -215,7 +215,7 @@ $(document).ready(function() { $('#item').autocomplete({ - source: "", + source: '', minChars: 0, autoFocus: false, delay: 10, @@ -253,7 +253,7 @@ $(document).ready(function() $('#item_name').autocomplete({ - source: "", + source: "", minChars: 0, delay: 15, cacheLength: 1, @@ -268,7 +268,7 @@ $(document).ready(function() success: function(response) { dialog_support.hide(); - table_support.handle_submit("", response); + table_support.handle_submit("", response); }, dataType: 'json' }); @@ -285,7 +285,7 @@ $(document).ready(function() required: false, remote: { - url: "", + url: '', type: 'POST', data: { diff --git a/app/Views/item_kits/manage.php b/app/Views/item_kits/manage.php index 5a772f299..85240aece 100644 --- a/app/Views/item_kits/manage.php +++ b/app/Views/item_kits/manage.php @@ -12,8 +12,8 @@ $(document).ready(function() table_support.init({ - resource: '', - headers: , + resource: '', + headers: , pageSize: , uniqueId: 'item_kit_id' }); @@ -30,7 +30,7 @@ $(document).ready(function()
- @@ -42,7 +42,7 @@ $(document).ready(function()   -
diff --git a/app/Views/items/form.php b/app/Views/items/form.php index 5fb45e3f6..965a8536b 100644 --- a/app/Views/items/form.php +++ b/app/Views/items/form.php @@ -38,7 +38,7 @@ 'name' => 'item_number', 'id' => 'item_number', 'class' => 'form-control input-sm', - 'value' => esc($item_info->item_number, 'attr') + 'value' => esc($item_info->item_number) ]) ?> @@ -51,7 +51,7 @@ 'name' => 'name', 'id' => 'name', 'class' => 'form-control input-sm', - 'value' => esc($item_info->name, 'attr') + 'value' => esc($item_info->name) ]) ?> @@ -64,7 +64,7 @@ 'form-control']); + echo form_dropdown('category', esc($categories), $selected_category, ['class' => 'form-control']); } else { @@ -72,7 +72,7 @@ 'name' => 'category', 'id' => 'category', 'class' => 'form-control input-sm', - 'value' => esc($item_info->category, 'attr') + 'value' => esc($item_info->category) ]); } ?> @@ -82,7 +82,7 @@
@@ -183,7 +183,7 @@
'control-label col-xs-3']) ?>
- 'form-control']) ?> + 'form-control']) ?>
@@ -240,7 +240,7 @@ 'name' => 'tax_names[]', 'id' => 'tax_name_1', 'class' => 'form-control input-sm', - 'value' => isset($item_tax_info[0]['name']) ? esc($item_tax_info[0]['name'], 'attr') : esc($config['default_tax_1_name'], 'attr') + 'value' => isset($item_tax_info[0]['name']) ? esc($item_tax_info[0]['name']) : esc($config['default_tax_1_name']) ]) ?>
@@ -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['default_tax_2_name'], 'attr') + 'value' => isset($item_tax_info[1]['name']) ? esc($item_tax_info[1]['name']) : esc($config['default_tax_2_name']) ]) ?>
@@ -292,7 +292,7 @@ 'id' => 'tax_category', 'class' => 'form-control input-sm', 'size' => '50', - 'value' => esc($tax_category, 'attr') + 'value' => esc($tax_category) ]) ?>
@@ -308,7 +308,7 @@ 'name' => 'hsn_code', 'id' => 'hsn_code', 'class' => 'form-control input-sm', - 'value' => esc($hsn_code, 'attr') + 'value' => esc($hsn_code) ]) ?> @@ -368,7 +368,7 @@ 'name' => 'description', 'id' => 'description', 'class' => 'form-control input-sm', - 'value' => esc($item_info->description, 'attr') + 'value' => esc($item_info->description) ]) ?> @@ -402,7 +402,7 @@ 'name' => 'allow_alt_description', 'id' => 'allow_alt_description', 'value' => 1, - 'checked' => ($item_info->allow_alt_description) ? 1 : 0 + 'checked' => ($item_info->allow_alt_description == 1) ? TRUE : FALSE ]) ?> @@ -414,7 +414,7 @@ 'name' => 'is_serialized', 'id' => 'is_serialized', 'value' => 1, - 'checked' => ($item_info->is_serialized) ? 1 : 0 + 'checked' => ($item_info->is_serialized == 1) ? TRUE : FALSE ]) ?> @@ -441,7 +441,7 @@ 'name' => 'pack_name', 'id' => 'pack_name', 'class' => 'form-control input-sm', - 'value' => esc($item_info->pack_name, 'attr') + 'value' => esc($item_info->pack_name) ]) ?> @@ -453,7 +453,7 @@ 'name' => 'low_sell_item_name', 'id' => 'low_sell_item_name', 'class' => 'form-control input-sm', - 'value' => esc($selected_low_sell_item, 'attr') + 'value' => esc($selected_low_sell_item) ]) ?> @@ -469,7 +469,7 @@ 'name' => 'is_deleted', 'id' => 'is_deleted', 'value'=>1, - 'checked' => ($item_info->deleted) ? 1 : 0 + 'checked' => ($item_info->deleted == 1) ? TRUE : FALSE ]) ?> @@ -501,7 +501,7 @@ $(document).ready(function() }; $('#tax_category').autocomplete({ - source: "", + source: "", minChars: 0, delay: 15, cacheLength: 1, @@ -517,7 +517,7 @@ $(document).ready(function() }; $('#low_sell_item_name').autocomplete({ - source: "", + source: "", minChars: 0, delay: 15, cacheLength: 1, @@ -527,7 +527,7 @@ $(document).ready(function() }); $('#category').autocomplete({ - source: "", + source: "", delay: 10, appendTo: '.modal-content' }); @@ -535,7 +535,7 @@ $(document).ready(function() $('a.fileinput-exists').click(function() { $.ajax({ type: 'GET', - url: 'item_id"), 'url') ?>', + url: 'item_id" ?>', dataType: 'json' }) }); @@ -553,7 +553,7 @@ $(document).ready(function() if(stay_open) { // set action of item_form to url without item id, so a new one can be created - $('#item_form').attr('action', ""); + $('#item_form').attr('action', ""); // use a whitelist of fields to minimize unintended side effects $(':text, :password, :file, #description, #item_form').not('.quantity, #reorder_level, #tax_name_1, #receiving_quantity, ' + '#tax_percent_name_1, #category, #reference_number, #name, #cost_price, #unit_price, #taxed_cost_price, #taxed_unit_price, #definition_name, [name^="attribute_links"]').val(''); @@ -564,7 +564,7 @@ $(document).ready(function() { dialog_support.hide(); } - table_support.handle_submit('', response, stay_open); + table_support.handle_submit('', response, stay_open); init_validation(); }, dataType: 'json' @@ -582,26 +582,23 @@ $(document).ready(function() required: false, remote: { - url: "", + url: "", type: 'POST', data: { - 'item_id' : "item_id ?>", - 'item_number' : function() - { - return $('#item_number').val(); - }, + 'item_id' : "item_id ?>" + // item_number should be passed into the function by default } } }, cost_price: { required: true, - remote: "" + remote: "" }, unit_price: { required: true, - remote: "" + remote: "" }, $location_detail) @@ -610,7 +607,7 @@ $(document).ready(function() : { required: true, - remote: "" + remote: "" }, " + remote: "" }, reorder_level: { required: true, - remote: "" + remote: "" }, tax_percent: { - required: true, - remote: "" + required: false, + remote: "" } }, @@ -671,7 +668,6 @@ $(document).ready(function() }, tax_percent: { - required: "", number: "" } } diff --git a/app/Views/items/form_bulk.php b/app/Views/items/form_bulk.php index 9197daf9f..7cd583159 100644 --- a/app/Views/items/form_bulk.php +++ b/app/Views/items/form_bulk.php @@ -40,7 +40,7 @@
'control-label col-xs-3']) ?>
- 'form-control']) ?> + 'form-control']) ?>
@@ -89,7 +89,7 @@ 'name' => 'tax_names[]', 'id' => 'tax_name_1', 'class' => 'form-control input-sm', - 'value' => esc($config['default_tax_1_name'], 'attr') + 'value' => esc($config['default_tax_1_name']) ]) ?>
@@ -112,7 +112,7 @@ 'name' => 'tax_names[]', 'id' => 'tax_name_2', 'class' => 'form-control input-sm', - 'value' => esc($config['default_tax_2_name'], 'attr') + 'value' => esc($config['default_tax_2_name']) ]) ?>
@@ -153,14 +153,14 @@
'control-label col-xs-3']) ?>
- 'form-control']) ?> + 'form-control']) ?>
'control-label col-xs-3']) ?>
- 'form-control']) ?> + 'form-control']) ?>
@@ -171,7 +171,7 @@ $(document).ready(function() { $('#category').autocomplete({ - source: "", + source: "", appendTo: '.modal-content', delay: 10 }); @@ -195,7 +195,7 @@ $(document).ready(function() success: function(response) { dialog_support.hide(); - table_support.handle_submit("", response); + table_support.handle_submit("", response); }, dataType: 'json' }); diff --git a/app/Views/items/form_count_details.php b/app/Views/items/form_count_details.php index 732c8fdac..581bd5c53 100644 --- a/app/Views/items/form_count_details.php +++ b/app/Views/items/form_count_details.php @@ -20,7 +20,7 @@ use App\Models\Employee; 'id' => 'item_number', 'class' => 'form-control input-sm', 'disabled' => '', - 'value' => esc($item_info->item_number, 'attr') + 'value' => esc($item_info->item_number) ]) ?>
@@ -34,7 +34,7 @@ use App\Models\Employee; 'id' => 'name', 'class' => 'form-control input-sm', 'disabled' => '', - 'value' => esc($item_info->name, 'attr') + 'value' => esc($item_info->name) ]) ?> @@ -49,7 +49,7 @@ use App\Models\Employee; 'id' => 'category', 'class' => 'form-control input-sm', 'disabled' => '', - 'value' => esc($item_info->category, 'attr') + 'value' => esc($item_info->category) ]) ?> @@ -58,7 +58,7 @@ use App\Models\Employee;
'control-label col-xs-3']) ?>
- 'display_stock(this.value);', 'class' => 'form-control']) ?> + 'display_stock(this.value);', 'class' => 'form-control']) ?>
diff --git a/app/Views/items/form_csv_import.php b/app/Views/items/form_csv_import.php index e6bb78044..b18ddedd7 100644 --- a/app/Views/items/form_csv_import.php +++ b/app/Views/items/form_csv_import.php @@ -4,7 +4,7 @@
- +
@@ -30,7 +30,7 @@ $(document).ready(function() success:function(response) { dialog_support.hide(); - table_support.handle_submit('', response); + table_support.handle_submit('', response); }, dataType: 'json' }); diff --git a/app/Views/items/form_inventory.php b/app/Views/items/form_inventory.php index 130459968..9584a5c2f 100644 --- a/app/Views/items/form_inventory.php +++ b/app/Views/items/form_inventory.php @@ -22,7 +22,7 @@ 'id' => 'item_number', 'class' => 'form-control input-sm', 'disabled' => '', - 'value' => esc($item_info->item_number, 'attr') + 'value' => esc($item_info->item_number) ]) ?> @@ -36,7 +36,7 @@ 'id' => 'name', 'class' => 'form-control input-sm', 'disabled' => '', - 'value' => esc($item_info->name, 'attr') + 'value' => esc($item_info->name) ]) ?> @@ -51,7 +51,7 @@ 'id' => 'category', 'class' => 'form-control input-sm', 'disabled' => '', - 'value' => esc($item_info->category, 'attr') + 'value' => esc($item_info->category) ]) ?> @@ -60,7 +60,7 @@
'control-label col-xs-3']) ?>
- 'fill_quantity(this.value)', 'class' => 'form-control']) ?> + 'fill_quantity(this.value)', 'class' => 'form-control']) ?>
@@ -111,7 +111,7 @@ $(document).ready(function() success: function(response) { dialog_support.hide(); - table_support.handle_submit("", response); + table_support.handle_submit("", response); }, dataType: 'json' }); diff --git a/app/Views/items/manage.php b/app/Views/items/manage.php index 36e4c6fde..ee505bd4c 100644 --- a/app/Views/items/manage.php +++ b/app/Views/items/manage.php @@ -50,8 +50,8 @@ $(document).ready(function() table_support.init({ employee_id: get_logged_in_employee_info()->person_id ?>, - resource: '', - headers: , + resource: '', + headers: , pageSize: , uniqueId: 'items.item_id', queryParams: function() { @@ -73,12 +73,12 @@ $(document).ready(function() @@ -22,7 +22,7 @@ 'name' => 'last_name', 'id' => 'last_name', 'class' => 'form-control input-sm', - 'value' => esc($person_info->last_name, 'attr') + 'value' => esc($person_info->last_name) ]) ?> @@ -61,7 +61,7 @@ 'name' => 'email', 'id' => 'email', 'class' => 'form-control input-sm', - 'value' => esc($person_info->email, 'attr') + 'value' => esc($person_info->email) ]) ?> @@ -76,7 +76,7 @@ 'name' => 'phone_number', 'id' => 'phone_number', 'class' => 'form-control input-sm', - 'value' => esc($person_info->phone_number, 'attr') + 'value' => esc($person_info->phone_number) ]) ?> @@ -89,7 +89,7 @@ 'name' => 'address_1', 'id' => 'address_1', 'class' => 'form-control input-sm', - 'value' => esc($person_info->address_1, 'attr') + 'value' => esc($person_info->address_1) ]) ?> @@ -101,7 +101,7 @@ 'name' => 'address_2', 'id' => 'address_2', 'class' => 'form-control input-sm', - 'value' => esc($person_info->address_2, 'attr') + 'value' => esc($person_info->address_2) ]) ?> @@ -113,7 +113,7 @@ 'name' => 'city', 'id' => 'city', 'class' => 'form-control input-sm', - 'value' => esc($person_info->city, 'attr') + 'value' => esc($person_info->city) ]) ?> @@ -125,7 +125,7 @@ 'name' => 'state', 'id' => 'state', 'class' => 'form-control input-sm', - 'value' => esc($person_info->state, 'attr') + 'value' => esc($person_info->state) ]) ?> @@ -137,7 +137,7 @@ 'name' => 'zip', 'id' => 'postcode', 'class' => 'form-control input-sm', - 'value' => esc($person_info->zip, 'attr') + 'value' => esc($person_info->zip) ]) ?> @@ -149,7 +149,7 @@ 'name' => 'country', 'id' => 'country', 'class' => 'form-control input-sm', - 'value' => esc($person_info->country, 'attr') + 'value' => esc($person_info->country) ]) ?> @@ -161,7 +161,7 @@ 'name' => 'comments', 'id' => 'comments', 'class' => 'form-control input-sm', - 'value' => esc($person_info->comments, 'attr') + 'value' => esc($person_info->comments) ]) ?> diff --git a/app/Views/people/manage.php b/app/Views/people/manage.php index cc46c0f6f..12ce85883 100644 --- a/app/Views/people/manage.php +++ b/app/Views/people/manage.php @@ -12,8 +12,8 @@ $(document).ready(function() table_support.init({ - resource: '', - headers: , + resource: '', + headers: , pageSize: , uniqueId: 'people.person_id', enableActions: function() @@ -39,14 +39,14 @@ $(document).ready(function() if ($controller_name == 'customers') //TODO: === ? { ?> - - diff --git a/app/Views/receivings/form.php b/app/Views/receivings/form.php index 19e4b02cb..a14438200 100644 --- a/app/Views/receivings/form.php +++ b/app/Views/receivings/form.php @@ -34,7 +34,7 @@
'control-label col-xs-3']) ?>
- 'supplier_name', 'value' => esc($selected_supplier_name, 'attr'), 'id' => 'supplier_name', 'class' => 'form-control input-sm']) ?> + 'supplier_name', 'value' => esc($selected_supplier_name), 'id' => 'supplier_name', 'class' => 'form-control input-sm']) ?>
@@ -42,21 +42,21 @@
'control-label col-xs-3']) ?>
- 'reference', 'value' => esc($receiving_info['reference'], 'attr'), 'id' => 'reference', 'class' => 'form-control input-sm']) ?> + 'reference', 'value' => esc($receiving_info['reference']), 'id' => 'reference', 'class' => 'form-control input-sm']) ?>
'control-label col-xs-3']) ?>
- +
'control-label col-xs-3']) ?>
- 'comment','value' => esc($receiving_info['comment'], 'attr'), 'id' => 'comment', 'class' => 'form-control input-sm']) ?> + 'comment','value' => esc($receiving_info['comment']), 'id' => 'comment', 'class' => 'form-control input-sm']) ?>
@@ -76,7 +76,7 @@ $(document).ready(function() }; $('#supplier_name').autocomplete({ - source: "", + source: "", minChars: 0, delay: 15, cacheLength: 1, @@ -88,7 +88,7 @@ $(document).ready(function() $('button#delete').click(function() { dialog_support.hide(); - table_support.do_delete("", ); + table_support.do_delete("", ); }); $('#receivings_edit_form').validate($.extend({ @@ -97,7 +97,7 @@ $(document).ready(function() success: function(response) { dialog_support.hide(); - table_support.handle_submit("", response); + table_support.handle_submit("", response); }, dataType: 'json' }); diff --git a/app/Views/receivings/receipt.php b/app/Views/receivings/receipt.php index 2c172cc12..ca4dfaf7c 100644 --- a/app/Views/receivings/receipt.php +++ b/app/Views/receivings/receipt.php @@ -162,7 +162,7 @@
- <?php echo esc($barcode, ' src='data:image/png;base64,' />
+ <?php echo esc($barcode) ?>
diff --git a/app/Views/receivings/receiving.php b/app/Views/receivings/receiving.php index 9b82311da..7bb3d3a53 100644 --- a/app/Views/receivings/receiving.php +++ b/app/Views/receivings/receiving.php @@ -39,14 +39,14 @@ if (isset($success)) - 'mode_form', 'class' => 'form-horizontal panel panel-default']) ?> + 'mode_form', 'class' => 'form-horizontal panel panel-default']) ?>
  • - "$('#mode_form').submit();", 'class' => 'selectpicker show-menu-arrow', 'data-style' => 'btn-default btn-sm', 'data-width' => 'fit']) ?> + "$('#mode_form').submit();", 'class' => 'selectpicker show-menu-arrow', 'data-style' => 'btn-default btn-sm', 'data-width' => 'fit']) ?>
  • - "$('#mode_form').submit();", 'class' => 'selectpicker show-menu-arrow', 'data-style' => 'btn-default btn-sm', 'data-width' => 'fit']) ?> + "$('#mode_form').submit();", 'class' => 'selectpicker show-menu-arrow', 'data-style' => 'btn-default btn-sm', 'data-width' => 'fit']) ?>
  • - "$('#mode_form').submit();", 'class' => 'selectpicker show-menu-arrow', 'data-style' => 'btn-default btn-sm', 'data-width' => 'fit']) ?> + "$('#mode_form').submit();", 'class' => 'selectpicker show-menu-arrow', 'data-style' => 'btn-default btn-sm', 'data-width' => 'fit']) ?>
  • ' data-btn-new='' - data-href='' + data-href='' title=''>   @@ -149,9 +149,9 @@ if (isset($success)) foreach(array_reverse($cart, TRUE) as $line => $item) { ?> - 'form-horizontal', 'id' => "cart_$line"]) ?> + 'form-horizontal', 'id' => "cart_$line"]) ?>
- + @@ -204,9 +204,9 @@ if (isset($success)) 'data-toggle' => "toggle", 'data-size' => 'small', 'data-onstyle' => 'success', - 'data-on' => '' . esc($config['currency_symbol'], 'attr') .'', + 'data-on' => '' . esc($config['currency_symbol']) .'', 'data-off' => '%', - 'data-line' => esc($line, 'attr'), + 'data-line' => esc($line), 'checked' => $item['discount_type'] ]) ?> @@ -242,7 +242,7 @@ if (isset($success)) echo form_input ([ 'name' => 'description', 'class' => 'form-control input-sm', - 'value' => esc($item['description'], 'attr') + 'value' => esc($item['description']) ]); } else @@ -250,7 +250,7 @@ if (isset($success)) if ($item['description'] != '') //TODO: !==? { echo $item['description']; - echo form_hidden('description', esc($item['description'], 'attr')); + echo form_hidden('description', esc($item['description'])); } else { @@ -332,7 +332,7 @@ if (isset($success)) else { ?> - 'select_supplier_form', 'class' => 'form-horizontal']) ?> + 'select_supplier_form', 'class' => 'form-horizontal']) ?>
lang('Receivings.start_typing_supplier_name') ]) ?> - @@ -383,7 +383,7 @@ if (isset($success)) if($mode == 'requisition') { ?> - 'finish_receiving_form', 'class' => 'form-horizontal']) ?> + 'finish_receiving_form', 'class' => 'form-horizontal']) ?>
'comment', 'id' => 'comment', 'class' => 'form-control input-sm', - 'value' => esc($comment, 'attr'), + 'value' => esc($comment), 'rows' => '4' ]) ?>
@@ -439,7 +439,7 @@ if (isset($success)) 'name' => 'recv_reference', 'id' => 'recv_reference', 'class' => 'form-control input-sm', - 'value' => esc($reference, 'attr'), + 'value' => esc($reference), 'size' => 5 ]) ?> @@ -452,7 +452,7 @@ if (isset($success))
'description', 'class' => 'form-control input-sm', 'value' => esc($item['description'], 'attr'), 'onClick' => 'this.select();']); + echo form_input (['name' => 'description', 'class' => 'form-control input-sm', 'value' => esc($item['description']), 'onClick' => 'this.select();']); } else { @@ -426,7 +426,7 @@ if(isset($success))
') ?>') ?>
@@ -184,7 +184,7 @@ if (isset($success))
'quantity', 'class' => 'form-control input-sm', 'value' => to_quantity_decimals($item['quantity']),'onClick' => 'this.select();']) ?> 'form-control input-sm'] ) ?> 'payment_types', @@ -496,7 +496,7 @@ $(document).ready(function() { $("#item").autocomplete( { - source: '', + source: '', minChars:0, delay:10, autoFocus: false, @@ -523,17 +523,17 @@ $(document).ready(function() $('#comment').keyup(function() { - $.post('', {comment: $('#comment').val()}); + $.post('', {comment: $('#comment').val()}); }); $('#recv_reference').keyup(function() { - $.post('', {recv_reference: $('#recv_reference').val()}); + $.post('', {recv_reference: $('#recv_reference').val()}); }); $("#recv_print_after_sale").change(function() { - $.post('', {recv_print_after_sale: $(this).is(":checked")}); + $.post('', {recv_print_after_sale: $(this).is(":checked")}); }); $('#item,#supplier').click(function() @@ -543,7 +543,7 @@ $(document).ready(function() $("#supplier").autocomplete( { - source: '', + source: '', minChars:0, delay:10, select: function (a, ui) { @@ -568,7 +568,7 @@ $(document).ready(function() { if (confirm('')) { - $('#finish_receiving_form').attr('action', ''); + $('#finish_receiving_form').attr('action', ''); $('#finish_receiving_form').submit(); } }); diff --git a/app/Views/reports/date_input.php b/app/Views/reports/date_input.php index 82d3d8673..d97d6ff72 100644 --- a/app/Views/reports/date_input.php +++ b/app/Views/reports/date_input.php @@ -38,7 +38,7 @@ if(isset($error)) ?> 'required control-label col-xs-2']) ?>
- 'input_type', 'class' => 'form-control']) ?> + 'input_type', 'class' => 'form-control']) ?>
'required control-label col-xs-2']) ?>
- 'discount_type_id', 'class' => 'form-control']) ?> + 'discount_type_id', 'class' => 'form-control']) ?>
'required control-label col-xs-2']) ?>
- 'location_id', 'class' => 'form-control']) ?> + 'location_id', 'class' => 'form-control']) ?>
'required control-label col-xs-2']) ?>
- +
'required control-label col-xs-2']) ?>
- +
@@ -55,4 +55,4 @@ $(document).ready(function() window.location = [window.location, $("#location_id").val(), $("#item_count").val()].join("/"); }); }); - \ No newline at end of file + diff --git a/app/Views/reports/specific_customer_input.php b/app/Views/reports/specific_customer_input.php index 196322719..ba948baa2 100644 --- a/app/Views/reports/specific_customer_input.php +++ b/app/Views/reports/specific_customer_input.php @@ -31,23 +31,23 @@ if(isset($error))
- 'required control-label col-xs-2']) ?> + 'required control-label col-xs-2']) ?>
- +
'required control-label col-xs-2']) ?>
- +
'required control-label col-xs-2']) ?>
- +
diff --git a/app/Views/reports/specific_input.php b/app/Views/reports/specific_input.php index 3ec8f17d2..38397f781 100644 --- a/app/Views/reports/specific_input.php +++ b/app/Views/reports/specific_input.php @@ -36,7 +36,7 @@ if(isset($error))
'required control-label col-xs-2']) ?>
- 'discount_type_id', 'class' => 'form-control']) ?> + 'discount_type_id', 'class' => 'form-control']) ?>
- 'required control-label col-xs-2']) ?> + 'required control-label col-xs-2']) ?>
- +
'required control-label col-xs-2']) ?>
- +
diff --git a/app/Views/sales/form.php b/app/Views/sales/form.php index b645b875a..de753fb0a 100644 --- a/app/Views/sales/form.php +++ b/app/Views/sales/form.php @@ -41,10 +41,10 @@ 'control-label col-xs-3']) ?>
- 'invoice_number', 'size'=>10, 'value' => esc($sale_info['invoice_number'], 'attr'), 'id' => 'invoice_number', 'class' => 'form-control input-sm']) ?> + 'invoice_number', 'size'=>10, 'value' => esc($sale_info['invoice_number']), 'id' => 'invoice_number', 'class' => 'form-control input-sm']) ?> - 'invoice_number', 'value' => esc($sale_info['invoice_number'], 'attr'), 'id' => 'invoice_number', 'class' => 'form-control input-sm']) ?> + 'invoice_number', 'value' => esc($sale_info['invoice_number']), 'id' => 'invoice_number', 'class' => 'form-control input-sm']) ?>
@@ -59,7 +59,7 @@
'control-label col-xs-3']) ?>
- 'payment_types_new', 'class' => 'form-control']) ?> + 'payment_types_new', 'class' => 'form-control']) ?>
@@ -88,15 +88,15 @@ payment_id) ?> payment_type, lang('Sales.giftcard'))) ): ?> - "payment_type_$i", 'value' => esc($row->payment_type, 'attr'), 'id' => "payment_type_$i", 'class' => 'form-control input-sm', 'readonly' => 'true']) ?> + "payment_type_$i", 'value' => esc($row->payment_type), 'id' => "payment_type_$i", 'class' => 'form-control input-sm', 'readonly' => 'true']) ?> - payment_type, 'attr'), ['id' => "payment_types_$i", 'class' => 'form-control']) ?> + payment_type), ['id' => "payment_types_$i", 'class' => 'form-control']) ?>
- + "payment_amount_$i", 'value' => $row->payment_amount, 'id' => "payment_amount_$i", 'class' => 'form-control input-sm', 'readonly' => 'true']) //TODO: add type attribute ?> @@ -113,7 +113,7 @@ payment_type, lang('Sales.giftcard')))): ?> "refund_type_$i", 'value'=>lang('Sales.cash'), 'id' => "refund_type_$i", 'class' => 'form-control input-sm', 'readonly' => 'true']) ?> - "refund_types_$i", 'class' => 'form-control']) ?> + "refund_types_$i", 'class' => 'form-control']) ?>
@@ -137,7 +137,7 @@
'control-label col-xs-3']) ?>
- 'customer_name', 'value' => esc($selected_customer_name, 'attr'), 'id' => 'customer_name', 'class' => 'form-control input-sm']) ?> + 'customer_name', 'value' => esc($selected_customer_name), 'id' => 'customer_name', 'class' => 'form-control input-sm']) ?>
@@ -145,7 +145,7 @@
'control-label col-xs-3']) ?>
- 'employee_name', 'value' => esc($selected_employee_name, 'attr'), 'id' => 'employee_name', 'class' => 'form-control input-sm']) ?> + 'employee_name', 'value' => esc($selected_employee_name), 'id' => 'employee_name', 'class' => 'form-control input-sm']) ?>
@@ -153,7 +153,7 @@
'control-label col-xs-3']) ?>
- 'comment', 'value' => esc($sale_info['comment'], 'attr'), 'id' => 'comment', 'class' => 'form-control input-sm']) ?> + 'comment', 'value' => esc($sale_info['comment']), 'id' => 'comment', 'class' => 'form-control input-sm']) ?>
@@ -165,7 +165,7 @@ $(document).ready(function() $('#send_invoice').click(function(event) { if (confirm("")) { - $.get("", + $.get("", function(response) { BootstrapDialog.closeAll(); $.notify( { message: response.message }, { type: response.success ? 'success' : 'danger'} ) @@ -184,7 +184,7 @@ $(document).ready(function() }; $('#customer_name').autocomplete( { - source: "", + source: "", minChars: 0, delay: 15, cacheLength: 1, @@ -200,7 +200,7 @@ $(document).ready(function() }; $('#employee_name').autocomplete( { - source: "", + source: "", minChars: 0, delay: 15, cacheLength: 1, @@ -211,12 +211,12 @@ $(document).ready(function() $('button#delete').click(function() { dialog_support.hide(); - table_support.do_delete("", ); + table_support.do_delete("", ); }); $('button#restore').click(function() { dialog_support.hide(); - table_support.do_restore("", ); + table_support.do_restore("", ); }); $('#sales_edit_form').validate($.extend( { @@ -225,10 +225,10 @@ $(document).ready(function() success: function(response) { dialog_support.hide(); - table_support.handle_submit("", response); + table_support.handle_submit("", response); const params = $.param(table_support.query_params()); - $.get("/search?" + params, function(response) { + $.get("/search?" + params, function(response) { $("#payment_summary").html(response.payment_summary); }, 'json'); }, @@ -244,7 +244,7 @@ $(document).ready(function() { remote: { - url: "", + url: "", type: 'POST', data: { 'sale_id': , diff --git a/app/Views/sales/invoice.php b/app/Views/sales/invoice.php index 48b74a5d2..8c0ae960c 100644 --- a/app/Views/sales/invoice.php +++ b/app/Views/sales/invoice.php @@ -260,7 +260,7 @@ $(document).ready(function()
- <?php echo esc($barcode, ' style='padding-top:4%;' src='data:image/png;base64,' />
+ <?php echo esc($barcode) ?>
diff --git a/app/Views/sales/invoice_email.php b/app/Views/sales/invoice_email.php index e7113e0e1..56f878abf 100644 --- a/app/Views/sales/invoice_email.php +++ b/app/Views/sales/invoice_email.php @@ -207,7 +207,7 @@ if(isset($error_message))
- <?php echo esc($barcode, ' src='data:image/png;base64,' />
+ <?php echo esc($barcode) ?>
diff --git a/app/Views/sales/manage.php b/app/Views/sales/manage.php index 94f69f2a6..228267366 100644 --- a/app/Views/sales/manage.php +++ b/app/Views/sales/manage.php @@ -34,8 +34,8 @@ $(document).ready(function() }; table_support.init({ - resource: '', - headers: , + resource: '', + headers: , pageSize: , uniqueId: 'sale_id', onLoadSuccess: function(response) { diff --git a/app/Views/sales/receipt_default.php b/app/Views/sales/receipt_default.php index 5d45bed36..d432094f1 100644 --- a/app/Views/sales/receipt_default.php +++ b/app/Views/sales/receipt_default.php @@ -242,7 +242,7 @@
- <?php echo esc($barcode, ' src='data:image/png;base64,' />
+ <?php echo esc($barcode) ?>
diff --git a/app/Views/sales/receipt_email.php b/app/Views/sales/receipt_email.php index 38eddb904..29709f186 100644 --- a/app/Views/sales/receipt_email.php +++ b/app/Views/sales/receipt_email.php @@ -222,7 +222,7 @@
- <?php echo esc($barcode, ' src='data:image/png;base64,' />
+ <?php echo esc($barcode) ?>
diff --git a/app/Views/sales/receipt_short.php b/app/Views/sales/receipt_short.php index 73945f466..823bb84c5 100644 --- a/app/Views/sales/receipt_short.php +++ b/app/Views/sales/receipt_short.php @@ -215,7 +215,7 @@
- <?php echo esc($barcode, ' src='data:image/png;base64,' />
+ <?php echo esc($barcode) ?>
diff --git a/app/Views/sales/register.php b/app/Views/sales/register.php index 0a083fe17..e41d68978 100644 --- a/app/Views/sales/register.php +++ b/app/Views/sales/register.php @@ -98,7 +98,7 @@ if(isset($success)) ?>
  • - @@ -176,11 +176,11 @@ if(isset($success)) foreach(array_reverse($cart, TRUE) as $line => $item) { ?> - 'form-horizontal', 'id' => "cart_$line"]) ?> + 'form-horizontal', 'id' => "cart_$line"]) ?>
  • '); + echo anchor(esc("$controller_name/deleteItem/$line"), ''); echo form_hidden('location', $item['item_location']); echo form_input (['type' => 'hidden', 'name' => 'item_id', 'value'=>$item['item_id']]); ?> @@ -267,7 +267,7 @@ if(isset($success)) ?> 'hidden', 'name' => 'item_id', 'value' => $item['item_id']]) ?> - 'item_description', 'id' => 'item_description', 'class' => 'form-control input-sm', 'value' => esc($item['description'], 'attr'), 'tabindex' => ++$tabindex]) ?> + 'item_description', 'id' => 'item_description', 'class' => 'form-control input-sm', 'value' => esc($item['description']), 'tabindex' => ++$tabindex]) ?>
     ' . lang('Common.remove') . ' ' . lang('Customers.customer'), ['class' => 'btn btn-danger btn-sm', 'id' => 'remove_customer_button', 'title' => lang('Common.remove') . ' ' . lang('Customers.customer')] ) @@ -440,7 +440,7 @@ if(isset($success)) 'customer', 'id' => 'customer', 'class' => 'form-control input-sm', 'value' => lang('Sales.start_typing_customer_name')]) ?> - @@ -505,7 +505,7 @@ if(isset($success)) if($payments_cover_total) { ?> - 'add_payment_form', 'class' => 'form-horizontal']) ?> + 'add_payment_form', 'class' => 'form-horizontal']) ?> @@ -552,7 +552,7 @@ if(isset($success)) else { ?> - 'add_payment_form', 'class' => 'form-horizontal']) ?> + 'add_payment_form', 'class' => 'form-horizontal']) ?>
    @@ -719,18 +719,18 @@ $(document).ready(function() $("#remove_customer_button").click(function() { - $.post("", redirect); + $.post("", redirect); }); $(".delete_item_button").click(function() { const item_id = $(this).data('item-id'); - $.post("" + item_id, redirect); + $.post("" + item_id, redirect); }); $(".delete_payment_button").click(function() { const item_id = $(this).data('payment-id'); - $.post("" + item_id, redirect); + $.post("" + item_id, redirect); }); $("input[name='item_number']").change(function() { @@ -782,7 +782,7 @@ $(document).ready(function() }); $('#item').autocomplete( { - source: "", + source: "", minChars: 0, autoFocus: false, delay: 500, diff --git a/app/Views/sales/tax_invoice.php b/app/Views/sales/tax_invoice.php index f0ae5883c..4bff54a3b 100644 --- a/app/Views/sales/tax_invoice.php +++ b/app/Views/sales/tax_invoice.php @@ -34,7 +34,7 @@ $(document).ready(function() { var send_email = function() { - $.get('', + $.get('', function(response) { $.notify( { message: response.message }, { type: response.success ? 'success' : 'danger'} ) @@ -262,7 +262,7 @@ $(document).ready(function()
    - <?php echo esc($barcode, ' src='data:image/png;base64,' />
    + <?php echo esc($barcode) ?>
    diff --git a/app/Views/sales/work_order.php b/app/Views/sales/work_order.php index 3532e3cbe..b8b32ff23 100644 --- a/app/Views/sales/work_order.php +++ b/app/Views/sales/work_order.php @@ -32,7 +32,7 @@ if(isset($error_message)) { var send_email = function() { - $.get('', + $.get('', function(response) { $.notify( { message: response.message }, { type: response.success ? 'success' : 'danger'} ) diff --git a/app/Views/suppliers/form.php b/app/Views/suppliers/form.php index 734263eb5..a551e08a9 100644 --- a/app/Views/suppliers/form.php +++ b/app/Views/suppliers/form.php @@ -18,7 +18,7 @@ 'name' => 'company_name', 'id' => 'company_name_input', 'class' => 'form-control input-sm', - 'value' => esc($person_info->company_name, 'attr') + 'value' => esc($person_info->company_name) ]) ?> @@ -38,7 +38,7 @@ 'name' => 'agency_name', 'id' => 'agency_name_input', 'class' => 'form-control input-sm', - 'value' => esc($person_info->agency_name, 'attr') + 'value' => esc($person_info->agency_name) ]) ?> @@ -53,7 +53,7 @@ 'name' => 'account_number', 'id' => 'account_number', 'class' => 'form-control input-sm', - 'value' => esc($person_info->account_number, 'attr') + 'value' => esc($person_info->account_number) ]) ?> @@ -66,7 +66,7 @@ 'name' => 'tax_id', 'id' => 'tax_id', 'class' => 'form-control input-sm', - 'value' => esc($person_info->tax_id, 'attr') + 'value' => esc($person_info->tax_id) ]) ?> @@ -84,7 +84,7 @@ $(document).ready(function() success: function(response) { dialog_support.hide(); - table_support.handle_submit("", response); + table_support.handle_submit("", response); }, dataType: 'json' }); diff --git a/app/Views/taxes/tax_categories.php b/app/Views/taxes/tax_categories.php index 84838c89c..b515f7b86 100644 --- a/app/Views/taxes/tax_categories.php +++ b/app/Views/taxes/tax_categories.php @@ -105,7 +105,7 @@ $(form).ajaxSubmit({ success: function(response) { $.notify({ message: response.message }, { type: response.success ? 'success' : 'danger'}); - $("#tax_categories").load('', init_add_remove_tax_categories); + $("#tax_categories").load('', init_add_remove_tax_categories); }, dataType: 'json' }); diff --git a/app/Views/taxes/tax_codes.php b/app/Views/taxes/tax_codes.php index 45fa8af51..7afa88078 100644 --- a/app/Views/taxes/tax_codes.php +++ b/app/Views/taxes/tax_codes.php @@ -104,7 +104,7 @@ $(form).ajaxSubmit({ success: function(response) { $.notify({ message: response.message }, { type: response.success ? 'success' : 'danger'}); - $("#tax_codes").load('', init_add_remove_tax_codes); + $("#tax_codes").load('', init_add_remove_tax_codes); }, dataType: 'json' }); diff --git a/app/Views/taxes/tax_jurisdictions.php b/app/Views/taxes/tax_jurisdictions.php index 5bc1790bc..ff89afebf 100644 --- a/app/Views/taxes/tax_jurisdictions.php +++ b/app/Views/taxes/tax_jurisdictions.php @@ -108,7 +108,7 @@ $(form).ajaxSubmit({ success: function(response) { $.notify({ message: response.message }, { type: response.success ? 'success' : 'danger'}); - $("#tax_jurisdictions").load('', init_add_remove_tax_jurisdiction); + $("#tax_jurisdictions").load('', init_add_remove_tax_jurisdiction); }, dataType: 'json' }); diff --git a/app/Views/taxes/tax_rates.php b/app/Views/taxes/tax_rates.php index ced06fb1f..d8a4f880a 100644 --- a/app/Views/taxes/tax_rates.php +++ b/app/Views/taxes/tax_rates.php @@ -9,8 +9,8 @@ $(document).ready(function() { table_support.init({ - resource: '', - headers: , + resource: '', + headers: , pageSize: , uniqueId: 'tax_rate_id' }); @@ -18,7 +18,7 @@ $(document).ready(function()
    - diff --git a/app/Views/taxes/tax_rates_form.php b/app/Views/taxes/tax_rates_form.php index 36e794f04..681545820 100644 --- a/app/Views/taxes/tax_rates_form.php +++ b/app/Views/taxes/tax_rates_form.php @@ -19,21 +19,21 @@
    'control-label col-xs-3']) ?>
    - 'form-control input-sm']) ?> + 'form-control input-sm']) ?>
    'control-label col-xs-3']) ?>
    - 'form-control input-sm']) ?> + 'form-control input-sm']) ?>
    'control-label col-xs-3']) ?>
    - 'form-control input-sm']) ?> + 'form-control input-sm']) ?>
    @@ -44,7 +44,7 @@ 'name' => 'tax_rate', 'id' => 'tax_rate', 'class' => 'form-control input-sm text-uppercase', - 'value' => esc($tax_rate, 'attr') + 'value' => esc($tax_rate) ]) ?> % @@ -55,7 +55,7 @@
    'control-label col-xs-3']) ?>
    - 'form-control input-sm']) ?> + 'form-control input-sm']) ?>
    @@ -71,7 +71,7 @@ $(form).ajaxSubmit({ success: function (response) { dialog_support.hide(); - table_support.handle_submit('', response); + table_support.handle_submit('', response); }, dataType: 'json' }); diff --git a/grunt045/Gruntfile.js b/grunt045/Gruntfile.js index 82fd061f4..6c9440464 100644 --- a/grunt045/Gruntfile.js +++ b/grunt045/Gruntfile.js @@ -13,11 +13,11 @@ module.exports = function(grunt) { 'dist/extensions/sticky-header/bootstrap-table-sticky-header.min.js', 'dist/extensions/sticky-header/bootstrap-table-sticky-header.css' ], - 'chartist-plugin-axistitle': [ "./dist/chartist-plugin-axistitle.min.js"] + 'chartist-plugin-axistitle': [ "dist/chartist-plugin-axistitle.min.js"] }, dest: { - 'js': '../../tmp/opensourcepos_bower.js', - 'css': '../../tmp/opensourcepos_bower.css' + 'js': '../tmp/opensourcepos_bower.js', + 'css': '../tmp/opensourcepos_bower.css' } } }, diff --git a/public/.htaccess b/public/.htaccess index 6142a5131..0429594e6 100644 --- a/public/.htaccess +++ b/public/.htaccess @@ -17,9 +17,9 @@ Options All -Indexes # RewriteBase / # Redirect Trailing Slashes... - RewriteCond %{REQUEST_FILENAME} !-d - RewriteCond %{REQUEST_URI} (.+)/$ - RewriteRule ^ %1 [L,R=301] + # RewriteCond %{REQUEST_FILENAME} !-d + # RewriteCond %{REQUEST_URI} (.+)/$ + # RewriteRule ^ %1 [L,R=301] # Rewrite "www.example.com -> example.com" RewriteCond %{HTTPS} !=on @@ -86,4 +86,4 @@ IndexIgnore * Require all denied - \ No newline at end of file + diff --git a/public/js/manage_tables.js b/public/js/manage_tables.js index d9eb205e2..bfddc7ac8 100644 --- a/public/js/manage_tables.js +++ b/public/js/manage_tables.js @@ -284,7 +284,7 @@ var submit_handler = function(url) { return function (resource, response) { - var id = response.id; + var id = response.id.toString(); if (!response.success) { $.notify(response.message, { type: 'danger' }); } else { @@ -292,8 +292,8 @@ var selector = rows_selector(response.id); var rows = $(selector.join(",")).length; if (rows > 0 && rows < 15) { - var ids = response.id.split(":"); - $.get([url || resource + '/get_row', id].join("/"), {}, function (response) { + var ids = id.split(":"); + $.get([url || resource + '/row', id].join("/"), {}, function (response) { $.each(selector, function (index, element) { var id = $(element).data('uniqueid'); table().updateByUniqueId({id: id, row: response[id] || response});