Tack on the void return type onto the Employee:logout method.

This commit is contained in:
Steve Ireland
2023-03-03 13:37:28 -05:00
committed by jekkos
parent 1d87de6f7d
commit 4798041408
123 changed files with 1270 additions and 937 deletions

View File

@@ -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 = [];