diff --git a/app/Controllers/Attributes.php b/app/Controllers/Attributes.php index 2b7cd5f61..e3a8c710f 100644 --- a/app/Controllers/Attributes.php +++ b/app/Controllers/Attributes.php @@ -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 ]); } } @@ -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 8ccee018d..0e5863e56 100644 --- a/app/Controllers/Cashups.php +++ b/app/Controllers/Cashups.php @@ -62,7 +62,7 @@ class Cashups extends Secure_Controller echo json_encode(['total' => $total_rows, 'rows' => $data_rows]); } - public function getView(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 = []; @@ -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/Employees.php b/app/Controllers/Employees.php index 9919964dc..8025cff21 100644 --- a/app/Controllers/Employees.php +++ b/app/Controllers/Employees.php @@ -62,7 +62,7 @@ class Employees extends Persons /** * Loads the employee edit form */ - public function getView(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); diff --git a/app/Controllers/Expenses.php b/app/Controllers/Expenses.php index 2a1911134..ed2a462d3 100644 --- a/app/Controllers/Expenses.php +++ b/app/Controllers/Expenses.php @@ -76,7 +76,7 @@ class Expenses extends Secure_Controller echo json_encode (['total' => $total_rows, 'rows' => $data_rows, 'payment_summary' => $payment_summary]); } - public function getView(int $expense_id = -1): void //TODO: Replace -1 with a constant + public function getView(int $expense_id = NEW_ENTRY): void { $data = []; //TODO: Duplicated code @@ -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 d7d4ee519..ce99904cc 100644 --- a/app/Controllers/Expenses_categories.php +++ b/app/Controllers/Expenses_categories.php @@ -53,14 +53,14 @@ class Expenses_categories extends Secure_Controller //TODO: Is this class ever u echo json_encode($data_row); } - public function getView(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 76d83f8e1..cf992b182 100644 --- a/app/Controllers/Giftcards.php +++ b/app/Controllers/Giftcards.php @@ -71,7 +71,7 @@ class Giftcards extends Secure_Controller echo json_encode($data_row); } - public function getView(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); @@ -93,11 +93,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 +112,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 +134,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 ]); } } @@ -150,7 +150,7 @@ class Giftcards extends Secure_Controller 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/Item_kits.php b/app/Controllers/Item_kits.php index 2fca99676..cb644b2cc 100644 --- a/app/Controllers/Item_kits.php +++ b/app/Controllers/Item_kits.php @@ -111,11 +111,11 @@ class Item_kits extends Secure_Controller echo json_encode(get_item_kit_data_row($item_kit)); } - public function getView(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 2274c6a1d..5beba18c9 100644 --- a/app/Controllers/Items.php +++ b/app/Controllers/Items.php @@ -242,12 +242,12 @@ class Items extends Secure_Controller echo json_encode($result); } - public function getView(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. { // Set default values - if($item_id == null) $item_id = NEW_ITEM; + if($item_id == null) $item_id = NEW_ENTRY; - if($item_id === NEW_ITEM) + if($item_id === NEW_ENTRY) { $data = []; } @@ -275,7 +275,7 @@ class Items extends Secure_Controller if($data['allow_temp_item'] === 1) { - if($item_id !== NEW_ITEM) + if($item_id !== NEW_ENTRY) { if($item_info->item_type != ITEM_TEMP) { @@ -305,7 +305,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']; @@ -400,14 +400,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]); @@ -420,7 +420,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 @@ -444,7 +444,7 @@ class Items extends Secure_Controller echo view('items/form_inventory', $data); } - public function count_details(int $item_id = NEW_ITEM): void + public function count_details(int $item_id = NEW_ENTRY): void { $item_info = $this->item->get_info($item_id); //TODO: Duplicate code @@ -492,7 +492,7 @@ class Items extends Secure_Controller echo view('barcodes/barcode_sheet', $data); } - public function getAttributes(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); @@ -554,7 +554,7 @@ 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 @@ -621,7 +621,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; @@ -722,7 +722,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]); } } @@ -778,7 +778,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. } @@ -800,7 +800,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); @@ -834,7 +834,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]); } } @@ -889,7 +889,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); @@ -941,7 +941,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 dd9411fac..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 getView(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/Receivings.php b/app/Controllers/Receivings.php index f5b41e513..7403942db 100644 --- a/app/Controllers/Receivings.php +++ b/app/Controllers/Receivings.php @@ -223,7 +223,7 @@ class Receivings extends Secure_Controller * @param $item_number * @return void */ - public function delete_item($item_number): void + public function postDelete_item($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 f443b20e3..caf978735 100644 --- a/app/Controllers/Sales.php +++ b/app/Controllers/Sales.php @@ -447,7 +447,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 +463,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; @@ -594,7 +594,7 @@ class Sales extends Secure_Controller * @return void * @throws ReflectionException */ - public function delete_item(int $item_id): void + public function postDelete_item(int $item_id): void { $this->sale_lib->delete_item($item_id); @@ -740,7 +740,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 +761,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 +791,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 +826,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 +867,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 +963,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 +1144,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 +1334,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 +1345,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 +1362,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 +1373,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 +1396,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 +1455,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 +1508,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 +1525,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 diff --git a/app/Controllers/Suppliers.php b/app/Controllers/Suppliers.php index 8e41ed6e7..e761cd9a8 100644 --- a/app/Controllers/Suppliers.php +++ b/app/Controllers/Suppliers.php @@ -87,7 +87,7 @@ class Suppliers extends Persons /* Loads the supplier edit form */ - public function getView(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 1e3b8be71..2a0daad1f 100644 --- a/app/Controllers/Tax_categories.php +++ b/app/Controllers/Tax_categories.php @@ -53,7 +53,7 @@ class Tax_categories extends Secure_Controller echo json_encode($data_row); } - public function getView(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); diff --git a/app/Controllers/Tax_codes.php b/app/Controllers/Tax_codes.php index 5249248f2..e6997483c 100644 --- a/app/Controllers/Tax_codes.php +++ b/app/Controllers/Tax_codes.php @@ -61,7 +61,7 @@ class Tax_codes extends Secure_Controller echo json_encode($data_row); } - public function getView(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); diff --git a/app/Controllers/Tax_jurisdictions.php b/app/Controllers/Tax_jurisdictions.php index 55bec76ad..fdb57141f 100644 --- a/app/Controllers/Tax_jurisdictions.php +++ b/app/Controllers/Tax_jurisdictions.php @@ -56,7 +56,7 @@ class Tax_jurisdictions extends Secure_Controller echo json_encode($data_row); } - public function getView(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); diff --git a/app/Controllers/Taxes.php b/app/Controllers/Taxes.php index 53023b86a..b080c13d4 100644 --- a/app/Controllers/Taxes.php +++ b/app/Controllers/Taxes.php @@ -126,7 +126,7 @@ class Taxes extends Secure_Controller echo json_encode($data_row); } - public function getView_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 getView(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 getView_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 getView_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);