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,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
{