- Added missing PHPdocs
- Corrected Syntax
- Added noinspection parameters to PHPdoc for AJAX called functions
- Added missing function return types
- Added missing parameter types
- Added public keyword to functions without visibility modifier
- Corrected incorrectly formatted PHPdocs
- Added public to constants and functions missing a visibility keyword
This commit is contained in:
objecttothis
2023-12-05 17:26:28 +04:00
committed by jekkos
parent 88007f56be
commit ba9bcd7786
137 changed files with 3070 additions and 330 deletions

View File

@@ -78,7 +78,7 @@ class Exceptions extends BaseConfig
*/
public string $deprecationLogLevel = LogLevel::WARNING;
/*
/**
* DEFINE THE HANDLERS USED
* --------------------------------------------------------------------------
* Given the HTTP status code, returns exception handler that

View File

@@ -24,6 +24,9 @@ class OSPOS extends BaseConfig
$this->set_settings();
}
/**
* @return void
*/
public function set_settings(): void
{
helper('locale');
@@ -45,6 +48,9 @@ class OSPOS extends BaseConfig
}
}
/**
* @return void
*/
public function update_settings(): void
{
$this->cache->delete('settings');

View File

@@ -106,7 +106,7 @@ class Attributes extends Secure_Controller
$definition_flags |= $flag;
}
//Save definition data
//Save definition data
$definition_data = [
'definition_name' => $this->request->getPost('definition_name'),
'definition_unit' => $this->request->getPost('definition_unit') != '' ? $this->request->getPost('definition_unit') : null,
@@ -123,7 +123,7 @@ class Attributes extends Secure_Controller
if($this->attribute->save_definition($definition_data, $definition_id))
{
//New definition
//New definition
if($definition_id == NO_DEFINITION_ID)
{
$definition_values = json_decode(html_entity_decode($this->request->getPost('definition_values')));
@@ -139,7 +139,7 @@ class Attributes extends Secure_Controller
'id' => $definition_data['definition_id']
]);
}
//Existing definition
//Existing definition
else
{
echo json_encode([
@@ -149,7 +149,7 @@ class Attributes extends Secure_Controller
]);
}
}
//Failure
//Failure
else
{
echo json_encode([
@@ -186,6 +186,10 @@ class Attributes extends Secure_Controller
echo json_encode($data_row);
}
/**
* @param int $definition_flags
* @return array
*/
private function get_attributes(int $definition_flags = 0): array
{
$definition_flag_names = [];
@@ -199,6 +203,10 @@ class Attributes extends Secure_Controller
return $definition_flag_names;
}
/**
* @param int $definition_id
* @return void
*/
public function getView(int $definition_id = NO_DEFINITION_ID): void
{
$info = $this->attribute->get_info($definition_id);

View File

@@ -25,6 +25,9 @@ class Cashups extends Secure_Controller
$this->config = config(OSPOS::class)->settings;
}
/**
* @return void
*/
public function getIndex(): void
{
$data['table_headers'] = get_cashups_manage_table_headers();
@@ -35,6 +38,9 @@ class Cashups extends Secure_Controller
echo view('cashups/manage', $data);
}
/**
* @return void
*/
public function getSearch(): void
{
$search = $this->request->getGet('search', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
@@ -62,6 +68,10 @@ class Cashups extends Secure_Controller
echo json_encode(['total' => $total_rows, 'rows' => $data_rows]);
}
/**
* @param int $cashup_id
* @return void
*/
public function getView(int $cashup_id = NEW_ENTRY): void
{
$data = [];
@@ -194,6 +204,10 @@ class Cashups extends Secure_Controller
echo view("cashups/form", $data);
}
/**
* @param int $row_id
* @return void
*/
public function getRow(int $row_id): void
{
$cash_ups_info = $this->cashup->get_info($row_id);
@@ -202,6 +216,10 @@ class Cashups extends Secure_Controller
echo json_encode($data_row);
}
/**
* @param int $cashup_id
* @return void
*/
public function postSave(int $cashup_id = NEW_ENTRY): void
{
$open_date = $this->request->getPost('open_date');
@@ -245,6 +263,9 @@ class Cashups extends Secure_Controller
}
}
/**
* @return void
*/
public function postDelete(): void
{
$cash_ups_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_FULL_SPECIAL_CHARS);

View File

@@ -74,7 +74,7 @@ class Config extends Secure_Controller
}
}
/*
/**
* This function loads all the licenses starting with the first one being OSPOS one
*/
private function _licenses(): array //TODO: remove hungarian notation. Super long function. Perhaps we need to refactor out functions?
@@ -227,8 +227,9 @@ class Config extends Secure_Controller
return $license;
}
/*
/**
* This function loads all the available themes in the dist/bootswatch directory
* @return array
*/
private function _themes(): array //TODO: Hungarian notation
{
@@ -570,7 +571,7 @@ class Config extends Secure_Controller
echo json_encode(['success' => $success, 'message' => lang('Config.saved_' . ($success ? '' : 'un') . 'successfully')]);
}
/*
/**
* This function fetches all the available lists from Mailchimp for the given API key
*/
private function _mailchimp(string $api_key = ''): array //TODO: Hungarian notation
@@ -644,6 +645,9 @@ class Config extends Secure_Controller
echo json_encode(['success' => $success, 'message' => lang('Config.saved_' . ($success ? '' : 'un') . 'successfully')]);
}
/**
* @return void
*/
public function getStockLocations(): void
{
$stock_locations = $this->stock_location->get_all()->getResultArray();
@@ -651,6 +655,9 @@ class Config extends Secure_Controller
echo view('partial/stock_locations', ['stock_locations' => $stock_locations]);
}
/**
* @return void
*/
public function getDinnerTables(): void
{
$dinner_tables = $this->dinner_table->get_all()->getResultArray();
@@ -658,6 +665,10 @@ class Config extends Secure_Controller
echo view('partial/dinner_tables', ['dinner_tables' => $dinner_tables]);
}
/**
* @return void
*/
public function ajax_tax_categories(): void
{
$tax_categories = $this->tax->get_all_tax_categories()->getResultArray();
@@ -665,6 +676,9 @@ class Config extends Secure_Controller
echo view('partial/tax_categories', ['tax_categories' => $tax_categories]);
}
/**
* @return void
*/
public function getCustomerRewards(): void
{
$customer_rewards = $this->customer_rewards->get_all()->getResultArray();
@@ -672,6 +686,9 @@ class Config extends Secure_Controller
echo view('partial/customer_rewards', ['customer_rewards' => $customer_rewards]);
}
/**
* @return void
*/
private function _clear_session_state(): void //TODO: Hungarian notation
{
$this->sale_lib->clear_sale_location();
@@ -683,6 +700,9 @@ class Config extends Secure_Controller
$this->receiving_lib->clear_all();
}
/**
* @return void
*/
public function postSaveLocations(): void
{
$this->db->transStart();

View File

@@ -47,6 +47,9 @@ class Customers extends Persons
}
}
/**
* @return void
*/
public function getIndex(): void
{
$data['table_headers'] = get_customer_manage_table_headers();
@@ -81,10 +84,13 @@ class Customers extends Persons
echo json_encode($data_row);
}
/*
Returns customer table data rows. This will be called with AJAX.
*/
public function getSearch()
/**
* Returns customer table data rows. This will be called with AJAX.
*
* @return void
*/
public function getSearch(): void
{
$search = $this->request->getGet('search');
$limit = $this->request->getGet('limit', FILTER_SANITIZE_NUMBER_INT);
@@ -129,6 +135,9 @@ class Customers extends Persons
echo json_encode($suggestions);
}
/**
* @return void
*/
public function suggest_search(): void
{
$suggestions = $this->customer->get_search_suggestions($this->request->getPost('term'), 25, false);
@@ -404,11 +413,17 @@ class Customers extends Persons
$this->response->download($name, $data);
}
/**
* @return void
*/
public function getCsvImport(): void
{
echo view('customers/form_csv_import');
}
/**
* @return void
*/
public function do_csv_import(): void
{
if($_FILES['file_path']['error'] != UPLOAD_ERR_OK)

View File

@@ -21,6 +21,8 @@ class Employees extends Persons
/**
* Returns employee table data rows. This will be called with AJAX.
*
* @return void
*/
public function getSearch(): void
{
@@ -43,7 +45,9 @@ class Employees extends Persons
}
/**
* Gives search suggestions based on what is being searched for
* AJAX called function gives search suggestions based on what is being searched for.
*
* @return void
*/
public function suggest(): void
{
@@ -52,6 +56,9 @@ class Employees extends Persons
echo json_encode($suggestions);
}
/**
* @return void
*/
public function suggest_search(): void
{
$suggestions = $this->employee->get_search_suggestions($this->request->getPost('term', FILTER_SANITIZE_FULL_SPECIAL_CHARS));

View File

@@ -19,6 +19,9 @@ class Expenses extends Secure_Controller
$this->expense_category = model(Expense_category::class);
}
/**
* @return void
*/
public function getIndex(): void
{
$data['table_headers'] = get_expenses_manage_table_headers();
@@ -36,6 +39,9 @@ class Expenses extends Secure_Controller
echo view('expenses/manage', $data);
}
/**
* @return void
*/
public function getSearch(): void
{
$search = $this->request->getGet('search', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
@@ -76,6 +82,10 @@ class Expenses extends Secure_Controller
echo json_encode (['total' => $total_rows, 'rows' => $data_rows, 'payment_summary' => $payment_summary]);
}
/**
* @param int $expense_id
* @return void
*/
public function getView(int $expense_id = NEW_ENTRY): void
{
$data = []; //TODO: Duplicated code
@@ -125,6 +135,10 @@ class Expenses extends Secure_Controller
echo view("expenses/form", $data);
}
/**
* @param int $row_id
* @return void
*/
public function getRow(int $row_id): void
{
$expense_info = $this->expense->get_info($row_id);
@@ -133,6 +147,10 @@ class Expenses extends Secure_Controller
echo json_encode($data_row);
}
/**
* @param int $expense_id
* @return void
*/
public function postSave(int $expense_id = NEW_ENTRY): void
{
$config = config(OSPOS::class)->settings;
@@ -171,6 +189,9 @@ class Expenses extends Secure_Controller
}
}
/**
* @return void
*/
public function ajax_check_amount(): void
{
$value = $this->request->getPost(null, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
@@ -178,6 +199,9 @@ class Expenses extends Secure_Controller
echo json_encode (['success' => $parsed_value !== false]);
}
/**
* @return void
*/
public function postDelete(): void
{
$expenses_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_FULL_SPECIAL_CHARS);

View File

@@ -15,6 +15,9 @@ class Expenses_categories extends Secure_Controller //TODO: Is this class ever u
$this->expense_category = model(Expense_category::class);
}
/**
* @return void
*/
public function getIndex(): void
{
$data['table_headers'] = get_expense_category_manage_table_headers();
@@ -45,6 +48,10 @@ class Expenses_categories extends Secure_Controller //TODO: Is this class ever u
echo json_encode (['total' => $total_rows, 'rows' => $data_rows]);
}
/**
* @param int $row_id
* @return void
*/
public function getRow(int $row_id): void
{
$data_row = get_expense_category_data_row($this->expense_category->get_info($row_id));
@@ -52,6 +59,10 @@ class Expenses_categories extends Secure_Controller //TODO: Is this class ever u
echo json_encode($data_row);
}
/**
* @param int $expense_category_id
* @return void
*/
public function getView(int $expense_category_id = NEW_ENTRY): void
{
$data['category_info'] = $this->expense_category->get_info($expense_category_id);
@@ -59,6 +70,10 @@ class Expenses_categories extends Secure_Controller //TODO: Is this class ever u
echo view("expenses_categories/form", $data);
}
/**
* @param int $expense_category_id
* @return void
*/
public function postSave(int $expense_category_id = NEW_ENTRY): void
{
$expense_category_data = [
@@ -96,6 +111,9 @@ class Expenses_categories extends Secure_Controller //TODO: Is this class ever u
}
}
/**
* @return void
*/
public function postDelete(): void
{
$expense_category_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_FULL_SPECIAL_CHARS);

View File

@@ -16,6 +16,9 @@ class Giftcards extends Secure_Controller
$this->giftcard = model(Giftcard::class);
}
/**
* @return void
*/
public function getIndex(): void
{
$data['table_headers'] = get_giftcards_manage_table_headers();
@@ -23,9 +26,9 @@ class Giftcards extends Secure_Controller
echo view('giftcards/manage', $data);
}
/*
Returns Giftcards table data rows. This will be called with AJAX.
*/
/**
* Returns Giftcards table data rows. This will be called with AJAX.
*/
public function getSearch(): void
{
$search = $this->request->getGet('search', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
@@ -46,10 +49,9 @@ class Giftcards extends Secure_Controller
echo json_encode (['total' => $total_rows, 'rows' => $data_rows]);
}
/*
Gives search suggestions based on what is being searched for
*/
/**
* Gives search suggestions based on what is being searched for
*/
public function getSuggest(): void
{
$suggestions = $this->giftcard->get_search_suggestions($this->request->getGet('term', FILTER_SANITIZE_FULL_SPECIAL_CHARS), true);
@@ -57,6 +59,9 @@ class Giftcards extends Secure_Controller
echo json_encode($suggestions);
}
/**
* @return void
*/
public function suggest_search(): void
{
$suggestions = $this->giftcard->get_search_suggestions($this->request->getPost('term', FILTER_SANITIZE_FULL_SPECIAL_CHARS));
@@ -64,6 +69,10 @@ class Giftcards extends Secure_Controller
echo json_encode($suggestions);
}
/**
* @param int $row_id
* @return void
*/
public function getRow(int $row_id): void
{
$data_row = get_giftcard_data_row($this->giftcard->get_info($row_id));
@@ -71,6 +80,10 @@ class Giftcards extends Secure_Controller
echo json_encode($data_row);
}
/**
* @param int $giftcard_id
* @return void
*/
public function getView(int $giftcard_id = NEW_ENTRY): void
{
$config = config(OSPOS::class)->settings;
@@ -94,6 +107,10 @@ class Giftcards extends Secure_Controller
echo view("giftcards/form", $data);
}
/**
* @param int $giftcard_id
* @return void
*/
public function postSave(int $giftcard_id = NEW_ENTRY): void
{
$giftcard_number = $this->request->getPost('giftcard_number', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
@@ -151,6 +168,9 @@ class Giftcards extends Secure_Controller
echo json_encode (['success' => $parsed_value !== false, 'giftcard_amount' => to_currency_no_money($parsed_value)]);
}
/**
* @return void
*/
public function postDelete(): void
{
$giftcards_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_FULL_SPECIAL_CHARS);

View File

@@ -11,12 +11,18 @@ class Home extends Secure_Controller
parent::__construct('home', null, 'home');
}
/**
* @return void
*/
public function getIndex(): void
{
$logged_in = $this->employee->is_logged_in();
echo view('home/home');
}
/**
* @return RedirectResponse
*/
public function getLogout(): RedirectResponse
{
$this->employee->logout();

View File

@@ -61,6 +61,9 @@ class Item_kits extends Secure_Controller
return $item_kit;
}
/**
* @return void
*/
public function getIndex(): void
{
$data['table_headers'] = get_item_kits_manage_table_headers();
@@ -93,6 +96,9 @@ class Item_kits extends Secure_Controller
echo json_encode (['total' => $total_rows, 'rows' => $data_rows]);
}
/**
* @return void
*/
public function suggest_search(): void
{
$suggestions = $this->item_kit->get_search_suggestions($this->request->getPost('term', FILTER_SANITIZE_FULL_SPECIAL_CHARS));
@@ -100,6 +106,10 @@ class Item_kits extends Secure_Controller
echo json_encode($suggestions);
}
/**
* @param int $row_id
* @return 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
@@ -108,6 +118,10 @@ class Item_kits extends Secure_Controller
echo json_encode(get_item_kit_data_row($item_kit));
}
/**
* @param int $item_kit_id
* @return void
*/
public function getView(int $item_kit_id = NEW_ENTRY): void
{
$info = $this->item_kit->get_info($item_kit_id);
@@ -147,6 +161,10 @@ class Item_kits extends Secure_Controller
echo view("item_kits/form", $data);
}
/**
* @param int $item_kit_id
* @return void
*/
public function postSave(int $item_kit_id = NEW_ENTRY): void
{
$item_kit_data = [
@@ -222,6 +240,9 @@ class Item_kits extends Secure_Controller
}
}
/**
* @return void
*/
public function postDelete(): void
{
$item_kits_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
@@ -239,12 +260,19 @@ class Item_kits extends Secure_Controller
}
}
/**
* @return void
*/
public function postCheckItemNumber(): void
{
$exists = $this->item_kit->item_number_exists($this->request->getPost('item_kit_number', FILTER_SANITIZE_FULL_SPECIAL_CHARS), $this->request->getPost('item_kit_id', FILTER_SANITIZE_NUMBER_INT));
echo !$exists ? 'true' : 'false';
}
/**
* @param string $item_kit_ids
* @return void
*/
public function generate_barcodes(string $item_kit_ids): void
{
$barcode_lib = new Barcode_lib();

View File

@@ -62,6 +62,9 @@ class Items extends Secure_Controller
$this->config = config(OSPOS::class)->settings;
}
/**
* @return void
*/
public function getIndex(): void
{
$this->session->set('allow_temp_items', 0);
@@ -239,6 +242,10 @@ class Items extends Secure_Controller
echo json_encode($suggestions);
}
/**
* @param string $item_ids
* @return void
*/
public function getRow(string $item_ids): void //TODO: An array would be better for parameter.
{
$item_infos = $this->item->get_multiple_info(explode(':', $item_ids), $this->item_lib->get_item_location());
@@ -481,6 +488,10 @@ class Items extends Secure_Controller
echo view('items/form_count_details', $data);
}
/**
* @param string $item_ids
* @return void
*/
public function generate_barcodes(string $item_ids): void //TODO: Passing these through as a string instead of an array limits the contents of the item_ids
{
$item_ids = explode(':', $item_ids);
@@ -505,6 +516,10 @@ class Items extends Secure_Controller
echo view('barcodes/barcode_sheet', $data);
}
/**
* @param int $item_id
* @return void
*/
public function getAttributes(int $item_id = NEW_ENTRY): void
{
$data['item_id'] = $item_id;
@@ -578,6 +593,9 @@ class Items extends Secure_Controller
echo view('attributes/item', $data);
}
/**
* @return void
*/
public function bulk_edit(): void //TODO: This function may not be called in the code. Need to confirm
{
$suppliers = ['' => lang('Items.none')];
@@ -892,7 +910,7 @@ class Items extends Secure_Controller
$this->inventory->insert($inv_data);
//Update stock quantity
//Update stock quantity
$item_quantity = $this->item_quantity->get_item_quantity($item_id, $location_id);
$item_quantity_data = [
'item_id' => $item_id,

View File

@@ -4,6 +4,7 @@ namespace App\Controllers;
use App\Libraries\MY_Migration;
use App\Models\Employee;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\Model;
use Config\OSPOS;
use Config\Services;
@@ -14,6 +15,10 @@ use Config\Services;
class Login extends BaseController
{
public Model $employee;
/**
* @return RedirectResponse|string
*/
public function index()
{
$this->employee = model(Employee::class);

View File

@@ -17,11 +17,18 @@ class Messages extends Secure_Controller
$this->sms_lib = new Sms_lib();
}
/**
* @return void
*/
public function getIndex(): void
{
echo view('messages/sms');
}
/**
* @param int $person_id
* @return void
*/
public function getView(int $person_id = NEW_ENTRY): void
{
$person = model(Person::class);
@@ -36,6 +43,9 @@ class Messages extends Secure_Controller
echo view('messages/form_sms', $data);
}
/**
* @return void
*/
public function send(): void
{
$phone = $this->request->getPost('phone', FILTER_SANITIZE_FULL_SPECIAL_CHARS);

View File

@@ -16,6 +16,12 @@ class No_Access extends BaseController
{
$this->module = model('Module');
}
/**
* @param string $module_id
* @param string $permission_id
* @return void
*/
public function getIndex(string $module_id = '', string $permission_id = ''): void
{
$data['module_name'] = $this->module->get_module_name($module_id);
@@ -23,4 +29,4 @@ class No_Access extends BaseController
echo view('no_access', $data);
}
}
}

View File

@@ -11,16 +11,22 @@ class Office extends Secure_Controller
{
protected Employee $employee;
function __construct()
public function __construct()
{
parent::__construct('office', null, 'office');
}
/**
* @return void
*/
public function getIndex(): void
{
echo view('home/office');
}
/**
* @return void
*/
public function logout(): void
{
$this->employee = model(Employee::class);

View File

@@ -9,6 +9,9 @@ abstract class Persons extends Secure_Controller
{
protected Person $person;
/**
* @param string|null $module_id
*/
public function __construct(string $module_id = null)
{
parent::__construct($module_id);
@@ -16,6 +19,9 @@ abstract class Persons extends Secure_Controller
$this->person = model(Person::class);
}
/**
* @return void
*/
public function getIndex(): void
{
$data['table_headers'] = get_people_manage_table_headers();

View File

@@ -44,6 +44,9 @@ class Receivings extends Secure_Controller
$this->config = config(OSPOS::class)->settings;
}
/**
* @return void
*/
public function getIndex(): void
{
$this->_reload();
@@ -88,6 +91,9 @@ class Receivings extends Secure_Controller
$this->_reload(); //TODO: Hungarian notation
}
/**
* @return void
*/
public function change_mode(): void
{
$stock_destination = $this->request->getPost('stock_destination', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
@@ -109,6 +115,9 @@ class Receivings extends Secure_Controller
$this->_reload(); //TODO: Hungarian notation
}
/**
* @return void
*/
public function set_comment(): void
{
$this->receiving_lib->set_comment($this->request->getPost('comment', FILTER_SANITIZE_FULL_SPECIAL_CHARS));
@@ -123,11 +132,17 @@ class Receivings extends Secure_Controller
$this->receiving_lib->set_print_after_sale($this->request->getPost('recv_print_after_sale', FILTER_SANITIZE_NUMBER_INT));
}
/**
* @return void
*/
public function set_reference(): void
{
$this->receiving_lib->set_reference($this->request->getPost('recv_reference', FILTER_SANITIZE_FULL_SPECIAL_CHARS));
}
/**
* @return void
*/
public function add(): void
{
$data = [];
@@ -193,6 +208,10 @@ class Receivings extends Secure_Controller
$this->_reload($data); //TODO: Hungarian notation
}
/**
* @param $receiving_id
* @return void
*/
public function edit($receiving_id): void
{
$data = [];
@@ -353,6 +372,10 @@ class Receivings extends Secure_Controller
}
}
/**
* @param $receiving_id
* @return void
*/
public function receipt($receiving_id): void
{
$receiving_info = $this->receiving->get_info($receiving_id)->getRowArray();
@@ -395,6 +418,10 @@ class Receivings extends Secure_Controller
$this->receiving_lib->clear_all();
}
/**
* @param $data
* @return void
*/
private function _reload($data = []): void //TODO: Hungarian notation
{
$data['cart'] = $this->receiving_lib->get_cart();

View File

@@ -93,12 +93,17 @@ class Reports extends Secure_Controller
helper('report');
}
/**
* @return void
*/
public function index(): void
{
$this->getIndex();
}
//Initial Report listing screen
/**
* Initial Report listing screen
*/
public function getIndex(): void
{
$person_id = $this->session->get('person_id');
@@ -490,7 +495,9 @@ class Reports extends Secure_Controller
echo view('reports/tabular', $data);
}
//Summary Sales Taxes report
/**
* Summary Sales Taxes report
*/
public function summary_sales_taxes(string $start_date, string $end_date, string $sale_type, string $location_id = 'all'): void
{//TODO: Duplicated code
$this->clearCache();
@@ -528,6 +535,9 @@ class Reports extends Secure_Controller
echo view('reports/tabular', $data);
}
/**
* @return void
*/
public function summary_discounts_input(): void
{
$this->clearCache();
@@ -581,7 +591,9 @@ class Reports extends Secure_Controller
echo view('reports/tabular', $data);
}
//Summary Payments report
/**
* Summary Payments report
*/
public function summary_payments(string $start_date, string $end_date): void
{
$this->clearCache();
@@ -642,7 +654,9 @@ class Reports extends Secure_Controller
echo view('reports/tabular', $data);
}
//Input for reports that require only a date range. (see routes.php to see that all graphical summary reports route here)
/**
* Input for reports that require only a date range. (see routes.php to see that all graphical summary reports route here)
*/
public function date_input(): void
{//TODO: Duplicated Code
$this->clearCache();
@@ -656,7 +670,9 @@ class Reports extends Secure_Controller
echo view('reports/date_input', $data);
}
//Input for reports that require only a date range. (see routes.php to see that all graphical summary reports route here)
/**
* Input for reports that require only a date range. (see routes.php to see that all graphical summary reports route here)
*/
public function date_input_only(): void
{
$this->clearCache();
@@ -665,7 +681,9 @@ class Reports extends Secure_Controller
echo view('reports/date_input', $data);
}
//Input for reports that require only a date range. (see routes.php to see that all graphical summary reports route here)
/**
* Input for reports that require only a date range. (see routes.php to see that all graphical summary reports route here)
*/
public function date_input_sales(): void
{//TODO: Duplicated Code
$this->clearCache();
@@ -679,6 +697,9 @@ class Reports extends Secure_Controller
echo view('reports/date_input', $data);
}
/**
* @return void
*/
public function date_input_recv(): void
{
$stock_locations = $data = $this->stock_location->get_allowed_locations('receivings');
@@ -689,7 +710,9 @@ class Reports extends Secure_Controller
echo view('reports/date_input', $data);
}
//Graphical Expenses by Categories report
/**
* Graphical Expenses by Categories report
*/
public function graphical_summary_expenses_categories(string $start_date, string $end_date, string $sale_type): void
{
$this->clearCache();
@@ -727,7 +750,9 @@ class Reports extends Secure_Controller
echo view('reports/graphical', $data);
}
//Graphical summary sales report
/**
* Graphical summary sales report
*/
public function graphical_summary_sales(string $start_date, string $end_date, string $sale_type, string $location_id = 'all'): void
{
$this->clearCache();
@@ -766,7 +791,9 @@ class Reports extends Secure_Controller
echo view('reports/graphical', $data);
}
//Graphical summary items report
/**
* Graphical summary items report
*/
public function graphical_summary_items(string $start_date, string $end_date, string $sale_type, string $location_id = 'all'): void
{
$this->clearCache();
@@ -806,7 +833,9 @@ class Reports extends Secure_Controller
echo view('reports/graphical', $data);
}
//Graphical summary customers report
/**
* Graphical summary customers report
*/
public function graphical_summary_categories(string $start_date, string $end_date, string $sale_type, string $location_id = 'all'): void
{//TODO: Duplicated Code
$this->clearCache();
@@ -842,7 +871,9 @@ class Reports extends Secure_Controller
echo view('reports/graphical', $data);
}
//Graphical summary suppliers report
/**
* Graphical summary suppliers report
*/
public function graphical_summary_suppliers(string $start_date, string $end_date, string $sale_type, string $location_id = 'all'): void
{//TODO: Duplicated Code
$this->clearCache();
@@ -880,7 +911,9 @@ class Reports extends Secure_Controller
echo view('reports/graphical', $data);
}
//Graphical summary employees report
/**
* Graphical summary employees report
*/
public function graphical_summary_employees(string $start_date, string $end_date, string $sale_type, string $location_id = 'all'): void
{
$this->clearCache();
@@ -917,7 +950,9 @@ class Reports extends Secure_Controller
echo view('reports/graphical', $data);
}
//Graphical summary taxes report
/**
* Graphical summary taxes report
*/
public function graphical_summary_taxes(string $start_date, string $end_date, string $sale_type, string $location_id = 'all'): void
{//TODO: Duplicated Code
$this->clearCache();
@@ -954,7 +989,9 @@ class Reports extends Secure_Controller
echo view('reports/graphical', $data);
}
//Graphical summary sales taxes report
/**
* Graphical summary sales taxes report
*/
public function graphical_summary_sales_taxes(string $start_date, string $end_date, string $sale_type, string $location_id = 'all'): void
{//TODO: Duplicated Code
$this->clearCache();
@@ -991,7 +1028,9 @@ class Reports extends Secure_Controller
echo view('reports/graphical', $data);
}
//Graphical summary customers report
/**
* Graphical summary customers report
*/
public function graphical_summary_customers(string $start_date, string $end_date, string $sale_type, string $location_id = 'all'): void
{//TODO: Duplicated Code
$this->clearCache();
@@ -1030,7 +1069,15 @@ class Reports extends Secure_Controller
echo view('reports/graphical', $data);
}
//Graphical summary discounts report
/**
* Graphical summary discounts report
*
* @param string $start_date Start date of the report
* @param string $end_date End date of the report
* @param string $sale_type
* @param string $location_id ID of the location to be reported or 'all' if none is specified
* @param int $discount_type
*/
public function graphical_summary_discounts(string $start_date, string $end_date, string $sale_type, string $location_id = 'all', int $discount_type = 0): void
{//TODO: Duplicated Code
$this->clearCache();
@@ -1070,7 +1117,9 @@ class Reports extends Secure_Controller
echo view('reports/graphical', $data);
}
//Graphical summary payments report
/**
* Graphical summary payments report
*/
public function graphical_summary_payments(string $start_date, string $end_date, string $sale_type, string $location_id = 'all'): void
{
$this->clearCache();
@@ -1110,6 +1159,9 @@ class Reports extends Secure_Controller
echo view('reports/graphical', $data);
}
/**
* @return void
*/
public function specific_customer_input(): void
{
$this->clearCache();
@@ -1135,6 +1187,9 @@ class Reports extends Secure_Controller
echo view('reports/specific_customer_input', $data);
}
/**
* @return array
*/
public function get_payment_type(): array
{
return [
@@ -1148,6 +1203,14 @@ class Reports extends Secure_Controller
];
}
/**
* @param string $start_date
* @param string $end_date
* @param string $customer_id
* @param string $sale_type
* @param string $payment_type
* @return void
*/
public function specific_customer(string $start_date, string $end_date, string $customer_id, string $sale_type, string $payment_type): void
{
$this->clearCache();
@@ -1249,6 +1312,9 @@ class Reports extends Secure_Controller
echo view('reports/tabular_details', $data);
}
/**
* @return void
*/
public function specific_employee_input(): void
{
$this->clearCache();
@@ -1267,6 +1333,13 @@ class Reports extends Secure_Controller
echo view('reports/specific_input', $data);
}
/**
* @param string $start_date
* @param string $end_date
* @param string $employee_id
* @param string $sale_type
* @return void
*/
public function specific_employee(string $start_date, string $end_date, string $employee_id, string $sale_type): void
{
$this->clearCache();
@@ -1363,6 +1436,9 @@ class Reports extends Secure_Controller
echo view('reports/tabular_details', $data);
}
/**
* @return void
*/
public function specific_discount_input(): void
{
$this->clearCache();
@@ -1382,6 +1458,14 @@ class Reports extends Secure_Controller
echo view('reports/specific_input', $data);
}
/**
* @param string $start_date
* @param string $end_date
* @param string $discount
* @param string $sale_type
* @param string $discount_type
* @return void
*/
public function specific_discount(string $start_date, string $end_date, string $discount, string $sale_type, string $discount_type): void
{
$this->clearCache();
@@ -1484,6 +1568,10 @@ class Reports extends Secure_Controller
echo view('reports/tabular_details', $data);
}
/**
* @param string $sale_id
* @return void
*/
public function get_detailed_sales_row(string $sale_id): void
{
$this->clearCache();
@@ -1532,6 +1620,9 @@ class Reports extends Secure_Controller
echo json_encode ([$sale_id => $summary_data]);
}
/**
* @return void
*/
public function specific_supplier_input(): void
{
$this->clearCache();
@@ -1550,6 +1641,13 @@ class Reports extends Secure_Controller
echo view('reports/specific_input', $data);
}
/**
* @param string $start_date
* @param string $end_date
* @param string $supplier_id
* @param string $sale_type
* @return void
*/
public function specific_supplier(string $start_date, string $end_date, string $supplier_id, string $sale_type): void
{
$inputs = [
@@ -1597,6 +1695,9 @@ class Reports extends Secure_Controller
echo view('reports/tabular', $data);
}
/**
* @return array
*/
public function get_sale_type_options(): array
{
$sale_type_options = [];
@@ -1615,6 +1716,13 @@ class Reports extends Secure_Controller
return $sale_type_options;
}
/**
* @param string $start_date
* @param string $end_date
* @param string $sale_type
* @param string $location_id
* @return void
*/
public function getDetailed_sales(string $start_date, string $end_date, string $sale_type, string $location_id = 'all'): void
{
$this->clearCache();
@@ -1732,6 +1840,10 @@ class Reports extends Secure_Controller
echo view('reports/tabular_details', $data);
}
/**
* @param string $receiving_id
* @return void
*/
public function get_detailed_receivings_row(string $receiving_id): void
{
$inputs = ['receiving_id' => $receiving_id];
@@ -1764,6 +1876,13 @@ class Reports extends Secure_Controller
echo json_encode ([$receiving_id => $summary_data]);
}
/**
* @param string $start_date
* @param string $end_date
* @param string $receiving_type
* @param string $location_id
* @return void
*/
public function detailed_receivings(string $start_date, string $end_date, string $receiving_type, string $location_id = 'all'): void
{
$this->clearCache();
@@ -1842,6 +1961,9 @@ class Reports extends Secure_Controller
echo view('reports/tabular_details', $data);
}
/**
* @return void
*/
public function inventory_low(): void
{
$this->clearCache();
@@ -1875,6 +1997,9 @@ class Reports extends Secure_Controller
echo view('reports/tabular', $data);
}
/**
* @return void
*/
public function inventory_summary_input(): void
{
$this->clearCache();
@@ -1889,6 +2014,11 @@ class Reports extends Secure_Controller
echo view('reports/inventory_summary_input', $data);
}
/**
* @param string $location_id
* @param string $item_count
* @return void
*/
public function inventory_summary(string $location_id = 'all', string $item_count = 'all'): void
{
$this->clearCache();
@@ -1925,7 +2055,9 @@ class Reports extends Secure_Controller
echo view('reports/tabular', $data);
}
// Returns subtitle for the reports
/**
* Returns subtitle for the reports
*/
private function _get_subtitle_report(array $inputs): string //TODO: Hungarian Notation
{
$subtitle = '';
@@ -1942,6 +2074,9 @@ class Reports extends Secure_Controller
return $subtitle;
}
/**
* @return void
*/
private function clearCache(): void
{
//Make sure the report is not cached by the browser

View File

@@ -64,12 +64,18 @@ class Sales extends Secure_Controller
$this->employee = model(Employee::class);
}
/**
* @return void
*/
public function getIndex(): void
{
$this->session->set('allow_temp_items', 1);
$this->_reload(); //TODO: Hungarian Notation
}
/**
* @return void
*/
public function getManage(): void
{
$person_id = $this->session->get('person_id');
@@ -93,6 +99,10 @@ class Sales extends Secure_Controller
}
}
/**
* @param int $row_id
* @return void
*/
public function getRow(int $row_id): void
{
$sale_info = $this->sale->get_info($row_id)->getRow();
@@ -101,6 +111,9 @@ class Sales extends Secure_Controller
echo json_encode($data_row);
}
/**
* @return void
*/
public function getSearch(): void
{
$search = $this->request->getGet('search', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
@@ -165,6 +178,9 @@ class Sales extends Secure_Controller
echo json_encode($suggestions);
}
/**
* @return void
*/
public function suggest_search(): void
{
$search = $this->request->getPost('term') != '' ? $this->request->getPost('term', FILTER_SANITIZE_FULL_SPECIAL_CHARS) : null;
@@ -174,6 +190,9 @@ class Sales extends Secure_Controller
echo json_encode($suggestions);
}
/**
* @return void
*/
public function postSelect_customer(): void
{
$customer_id = (int)$this->request->getPost('customer', FILTER_SANITIZE_NUMBER_INT);
@@ -193,6 +212,9 @@ class Sales extends Secure_Controller
$this->_reload();
}
/**
* @return void
*/
public function postChange_mode(): void
{
$mode = $this->request->getPost('mode', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
@@ -249,6 +271,10 @@ class Sales extends Secure_Controller
$this->_reload();
}
/**
* @param int $sale_type
* @return void
*/
public function change_register_mode(int $sale_type): void
{//TODO: This set of if statements should be refactored to a switch
if($sale_type == SALE_TYPE_POS)
@@ -277,6 +303,9 @@ class Sales extends Secure_Controller
}
}
/**
* @return void
*/
public function set_comment(): void
{
$this->sale_lib->set_comment($this->request->getPost('comment', FILTER_SANITIZE_FULL_SPECIAL_CHARS));
@@ -291,6 +320,9 @@ class Sales extends Secure_Controller
$this->sale_lib->set_invoice_number($this->request->getPost('sales_invoice_number', FILTER_SANITIZE_NUMBER_INT));
}
/**
* @return void
*/
public function set_payment_type(): void //TODO: This function does not appear to be called anywhere in the code.
{
$this->sale_lib->set_payment_type($this->request->getPost('selected_payment_type', FILTER_SANITIZE_FULL_SPECIAL_CHARS));
@@ -306,6 +338,9 @@ class Sales extends Secure_Controller
$this->sale_lib->set_print_after_sale($this->request->getPost('sales_print_after_sale', FILTER_SANITIZE_NUMBER_INT));
}
/**
* @return void
*/
public function set_price_work_orders(): void
{
$this->sale_lib->set_price_work_orders($this->request->getPost('price_work_orders', FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION));
@@ -458,6 +493,9 @@ class Sales extends Secure_Controller
$this->_reload(); //TODO: Hungarian notation
}
/**
* @return void
*/
public function postAdd(): void
{
$data = [];
@@ -938,6 +976,10 @@ class Sales extends Secure_Controller
return $result;
}
/**
* @param int $sale_id
* @return bool
*/
public function send_receipt(int $sale_id): bool
{
$sale_data = $this->_load_sale_data($sale_id);
@@ -967,6 +1009,12 @@ class Sales extends Secure_Controller
return $result;
}
/**
* @param int $customer_id
* @param array $data
* @param bool $stats
* @return array|object|\stdClass|string|null
*/
private function _load_customer_data(int $customer_id, array &$data, bool $stats = false) //TODO: Hungarian notation
{
$customer_info = '';
@@ -1040,6 +1088,10 @@ class Sales extends Secure_Controller
return $customer_info;
}
/**
* @param $sale_id
* @return array
*/
private function _load_sale_data($sale_id): array //TODO: Hungarian notation
{
$this->sale_lib->clear_all();
@@ -1146,6 +1198,10 @@ class Sales extends Secure_Controller
return $data;
}
/**
* @param $data
* @return void
*/
private function _reload($data = []): void //TODO: Hungarian notation
{
$sale_id = $this->session->get('sale_id'); //TODO: This variable is never used
@@ -1272,6 +1328,10 @@ class Sales extends Secure_Controller
echo view("sales/register", $data);
}
/**
* @param int $sale_id
* @return void
*/
public function receipt(int $sale_id): void
{
$data = $this->_load_sale_data($sale_id);
@@ -1279,6 +1339,10 @@ class Sales extends Secure_Controller
$this->sale_lib->clear_all();
}
/**
* @param int $sale_id
* @return void
*/
public function invoice(int $sale_id): void
{
$data = $this->_load_sale_data($sale_id);
@@ -1287,6 +1351,10 @@ class Sales extends Secure_Controller
$this->sale_lib->clear_all();
}
/**
* @param int $sale_id
* @return void
*/
public function edit(int $sale_id): void
{
$data = [];
@@ -1370,6 +1438,11 @@ class Sales extends Secure_Controller
}
}
/**
* @param int $sale_id
* @param bool $update_inventory
* @return void
*/
public function restore(int $sale_id = NEW_ENTRY, bool $update_inventory = true): void
{
$employee_id = $this->employee->get_logged_in_employee_info()->person_id;
@@ -1544,6 +1617,9 @@ class Sales extends Secure_Controller
$this->_reload(); //TODO: Hungarian notation
}
/**
* @return void
*/
public function discard_suspended_sale(): void
{
$suspended_id = $this->sale_lib->get_suspended_id();
@@ -1627,11 +1703,17 @@ class Sales extends Secure_Controller
$this->_reload(); //TODO: Hungarian notation
}
/**
* @return void
*/
public function sales_keyboard_help()
{
$this->load->view('sales/help');
}
/**
* @return void
*/
public function check_invoice_number(): void
{
$sale_id = $this->request->getPost('sale_id', FILTER_SANITIZE_NUMBER_INT);
@@ -1640,6 +1722,10 @@ class Sales extends Secure_Controller
echo !$exists ? 'true' : 'false';
}
/**
* @param array $cart
* @return array
*/
public function get_filtered(array $cart): array
{
$filtered_cart = [];
@@ -1659,6 +1745,9 @@ class Sales extends Secure_Controller
return $filtered_cart;
}
/**
* @return void
*/
public function change_item_number(): void
{
$item_id = $this->request->getPost('item_id', FILTER_SANITIZE_NUMBER_INT);
@@ -1673,6 +1762,9 @@ class Sales extends Secure_Controller
$this->sale_lib->set_cart($cart);
}
/**
* @return void
*/
public function change_item_name(): void
{
$item_id = $this->request->getPost('item_id', FILTER_SANITIZE_NUMBER_INT);
@@ -1691,6 +1783,9 @@ class Sales extends Secure_Controller
$this->sale_lib->set_cart($cart);
}
/**
* @return void
*/
public function change_item_description(): void
{
$item_id = $this->request->getPost('item_id', FILTER_SANITIZE_NUMBER_INT);
@@ -1709,6 +1804,11 @@ class Sales extends Secure_Controller
$this->sale_lib->set_cart($cart);
}
/**
* @param int $id
* @param array $array
* @return int|string|null
*/
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

View File

@@ -27,6 +27,11 @@ class Secure_Controller extends BaseController
protected Module $module;
protected Session $session;
/**
* @param string $module_id
* @param string|null $submodule_id
* @param string|null $menu_group
*/
public function __construct(string $module_id = '', string $submodule_id = null, string $menu_group = null)
{
$this->employee = model(Employee::class);
@@ -93,6 +98,10 @@ class Secure_Controller extends BaseController
echo $result !== false ? 'true' : 'false';
}
/**
* @param $key
* @return mixed|void
*/
public function getConfig($key)
{
if (isset($config[$key]))
@@ -101,11 +110,35 @@ class Secure_Controller extends BaseController
}
}
// this is the basic set of methods most OSPOS Controllers will implement
/**
* @return false
*/
public function getIndex() { return false; }
/**
* @return false
*/
public function getSearch() { return false; }
/**
* @return false
*/
public function suggest_search() { return false; }
/**
* @param int $data_item_id
* @return false
*/
public function getView(int $data_item_id = -1) { return false; }
/**
* @param int $data_item_id
* @return false
*/
public function postSave(int $data_item_id = -1) { return false; }
/**
* @return false
*/
public function postDelete() { return false; }
}

View File

@@ -15,6 +15,9 @@ class Suppliers extends Persons
$this->supplier = model(Supplier::class);
}
/**
* @return void
*/
public function getIndex(): void
{
helper('tabular');
@@ -73,6 +76,9 @@ class Suppliers extends Persons
echo json_encode($suggestions);
}
/**
* @return void
*/
public function suggest_search(): void
{
$suggestions = $this->supplier->get_search_suggestions($this->request->getPost('term', FILTER_SANITIZE_FULL_SPECIAL_CHARS), false);
@@ -80,9 +86,12 @@ class Suppliers extends Persons
echo json_encode($suggestions);
}
/*
Loads the supplier edit form
*/
/**
* Loads the supplier edit form
*
* @param int $supplier_id
* @return void
*/
public function getView(int $supplier_id = NEW_ENTRY): void
{
$info = $this->supplier->get_info($supplier_id);
@@ -96,9 +105,12 @@ class Suppliers extends Persons
echo view("suppliers/form", $data);
}
/*
Inserts/updates a supplier
*/
/**
* Inserts/updates a supplier
*
* @param int $supplier_id
* @return void
*/
public function postSave(int $supplier_id = NEW_ENTRY): void
{
$first_name = $this->request->getPost('first_name', FILTER_SANITIZE_FULL_SPECIAL_CHARS); //TODO: Duplicate code
@@ -161,9 +173,11 @@ class Suppliers extends Persons
}
}
/*
This deletes suppliers from the suppliers table
*/
/**
* This deletes suppliers from the suppliers table
*
* @return void
*/
public function postDelete(): void
{
$suppliers_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT);

View File

@@ -16,6 +16,9 @@ class Tax_categories extends Secure_Controller
$this->tax_category = model('Tax_category');
}
/**
* @return void
*/
public function getIndex(): void
{
$data['tax_categories_table_headers'] = get_tax_categories_table_headers();
@@ -23,9 +26,11 @@ class Tax_categories extends Secure_Controller
echo view('taxes/tax_categories', $data);
}
/*
/**
* Returns tax_category table data rows. This will be called with AJAX.
*/
*
* @return void
*/
public function getSearch(): void
{
$search = $this->request->getGet('search', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
@@ -46,6 +51,10 @@ class Tax_categories extends Secure_Controller
echo json_encode (['total' => $total_rows, 'rows' => $data_rows]);
}
/**
* @param $row_id
* @return void
*/
public function getRow($row_id): void
{
$data_row = get_tax_categories_data_row($this->tax_category->get_info($row_id));
@@ -53,6 +62,10 @@ class Tax_categories extends Secure_Controller
echo json_encode($data_row);
}
/**
* @param int $tax_category_id
* @return void
*/
public function getView(int $tax_category_id = NEW_ENTRY): void
{
$data['tax_category_info'] = $this->tax_category->get_info($tax_category_id);
@@ -61,6 +74,10 @@ class Tax_categories extends Secure_Controller
}
/**
* @param int $tax_category_id
* @return void
*/
public function postSave(int $tax_category_id = NEW_ENTRY): void
{
$tax_category_data = [
@@ -99,6 +116,9 @@ class Tax_categories extends Secure_Controller
}
}
/**
* @return void
*/
public function postDelete(): void
{
$tax_categories_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT);

View File

@@ -18,11 +18,17 @@ class Tax_codes extends Secure_Controller
}
/**
* @return void
*/
public function getIndex(): void
{
echo view('taxes/tax_codes', $this->get_data());
}
/**
* @return array
*/
public function get_data(): array
{
@@ -30,8 +36,10 @@ class Tax_codes extends Secure_Controller
return $data;
}
/*
/**
* Returns tax_category table data rows. This will be called with AJAX.
*
* @return void
*/
public function getSearch(): void
{
@@ -54,6 +62,10 @@ class Tax_codes extends Secure_Controller
echo json_encode (['total' => $total_rows, 'rows' => $data_rows]);
}
/**
* @param int $row_id
* @return void
*/
public function getRow(int $row_id): void
{
$data_row = get_tax_code_data_row($this->tax_code->get_info($row_id));
@@ -61,6 +73,10 @@ class Tax_codes extends Secure_Controller
echo json_encode($data_row);
}
/**
* @param int $tax_code_id
* @return void
*/
public function getView(int $tax_code_id = NEW_ENTRY): void
{
$data['tax_code_info'] = $this->tax_code->get_info($tax_code_id);
@@ -69,6 +85,10 @@ class Tax_codes extends Secure_Controller
}
/**
* @param int $tax_code_id
* @return void
*/
public function postSave(int $tax_code_id = NEW_ENTRY): void
{
$tax_code_data = [
@@ -107,6 +127,9 @@ class Tax_codes extends Secure_Controller
}
}
/**
* @return void
*/
public function postDelete(): void
{
$tax_codes_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT);

View File

@@ -19,6 +19,9 @@ class Tax_jurisdictions extends Secure_Controller
}
/**
* @return void
*/
public function getIndex(): void
{
$data['table_headers'] = get_tax_jurisdictions_table_headers();
@@ -26,8 +29,10 @@ class Tax_jurisdictions extends Secure_Controller
echo view('taxes/tax_jurisdictions', $data);
}
/*
/**
* Returns tax_category table data rows. This will be called with AJAX.
*
* @return void
*/
public function getSearch(): void
{
@@ -49,6 +54,10 @@ class Tax_jurisdictions extends Secure_Controller
echo json_encode (['total' => $total_rows, 'rows' => $data_rows]);
}
/**
* @param int $row_id
* @return void
*/
public function getRow(int $row_id): void
{
$data_row = get_tax_jurisdictions_data_row($this->tax_jurisdiction->get_info($row_id));
@@ -56,6 +65,10 @@ class Tax_jurisdictions extends Secure_Controller
echo json_encode($data_row);
}
/**
* @param int $tax_jurisdiction_id
* @return void
*/
public function getView(int $tax_jurisdiction_id = NEW_ENTRY): void
{
$data['tax_jurisdiction_info'] = $this->tax_jurisdiction->get_info($tax_jurisdiction_id);
@@ -64,6 +77,10 @@ class Tax_jurisdictions extends Secure_Controller
}
/**
* @param int $jurisdiction_id
* @return void
*/
public function postSave(int $jurisdiction_id = NEW_ENTRY): void
{
$tax_jurisdiction_data = [
@@ -100,6 +117,9 @@ class Tax_jurisdictions extends Secure_Controller
}
}
/**
* @return void
*/
public function postDelete(): void
{
$tax_jurisdictions_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT);

View File

@@ -34,6 +34,9 @@ class Taxes extends Secure_Controller
helper('tax_helper');
}
/**
* @return void
*/
public function getIndex(): void
{
$data['tax_codes'] = $this->tax_code->get_all()->getResultArray();
@@ -72,10 +75,11 @@ class Taxes extends Secure_Controller
echo view('taxes/manage', $data);
}
/*
Returns tax_codes table data rows. This will be called with AJAX.
*/
/**
* Returns tax_codes table data rows. This will be called with AJAX.
*
* @return void
*/
public function getSearch(): void
{
$search = $this->request->getGet('search', FILTER_SANITIZE_FULL_SPECIAL_CHARS);
@@ -107,9 +111,11 @@ class Taxes extends Secure_Controller
echo json_encode($suggestions);
}
/*
Provides list of tax categories to select from
*/
/**
* Provides list of tax categories to select from
*
* @return void
*/
public function suggest_tax_categories(): void
{
$suggestions = $this->tax_category->get_tax_category_suggestions($this->request->getPost('term', FILTER_SANITIZE_FULL_SPECIAL_CHARS));
@@ -118,6 +124,10 @@ class Taxes extends Secure_Controller
}
/**
* @param int $row_id
* @return void
*/
public function getRow(int $row_id): void
{
$data_row = get_tax_rates_data_row($this->tax->get_info($row_id));
@@ -125,6 +135,10 @@ class Taxes extends Secure_Controller
echo json_encode($data_row);
}
/**
* @param int $tax_code
* @return void
*/
public function getView_tax_codes(int $tax_code = NEW_ENTRY): void
{
$tax_code_info = $this->tax->get_info($tax_code);
@@ -193,6 +207,10 @@ class Taxes extends Secure_Controller
}
/**
* @param int $tax_rate_id
* @return void
*/
public function getView(int $tax_rate_id = NEW_ENTRY): void
{
$tax_rate_info = $this->tax->get_info($tax_rate_id);
@@ -225,6 +243,10 @@ class Taxes extends Secure_Controller
echo view('taxes/tax_rates_form', $data);
}
/**
* @param int $tax_code
* @return void
*/
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
@@ -292,6 +314,10 @@ class Taxes extends Secure_Controller
echo view('taxes/tax_category_form', $data);
}
/**
* @param int $tax_code
* @return void
*/
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
@@ -359,11 +385,18 @@ class Taxes extends Secure_Controller
echo view('taxes/tax_jurisdiction_form', $data);
}
/**
* @return string
*/
public static function get_html_rounding_options(): string
{
return rounding_mode::get_html_rounding_options();
}
/**
* @param int $tax_rate_id
* @return void
*/
public function postSave(int $tax_rate_id = NEW_ENTRY): void
{
$tax_category_id = $this->request->getPost('rate_tax_category_id', FILTER_SANITIZE_NUMBER_INT);
@@ -399,6 +432,9 @@ class Taxes extends Secure_Controller
}
}
/**
* @return void
*/
public function postDelete(): void
{
$tax_codes_to_delete = $this->request->getPost('ids', FILTER_SANITIZE_NUMBER_INT);
@@ -455,6 +491,9 @@ class Taxes extends Secure_Controller
]);
}
/**
* @return void
*/
public function save_tax_jurisdictions(): void
{
$jurisdiction_id = $this->request->getPost('jurisdiction_id', FILTER_SANITIZE_NUMBER_INT);
@@ -502,6 +541,9 @@ class Taxes extends Secure_Controller
]);
}
/**
* @return void
*/
public function save_tax_categories(): void
{
$tax_category_id = $this->request->getPost('tax_category_id', FILTER_SANITIZE_NUMBER_INT);

View File

@@ -11,12 +11,18 @@ class Migration_Upgrade_To_3_1_1 extends Migration
parent::__construct();
}
/**
* Perform a migration step.
*/
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.0.2_to_3.1.1.sql');
}
/**
* Revert a migration step.
*/
public function down(): void
{

View File

@@ -13,12 +13,12 @@ use CodeIgniter\Database\ResultInterface;
*/
class Migration_Sales_Tax_Data extends Migration
{
const ROUND_UP = 5; //TODO: These need to be moved to constants.php
const ROUND_DOWN = 6;
const HALF_FIVE = 7;
const YES = '1';
const VAT_TAX = '0';
const SALES_TAX = '1';
public const ROUND_UP = 5; //TODO: These need to be moved to constants.php
public const ROUND_DOWN = 6;
public const HALF_FIVE = 7;
public const YES = '1';
public const VAT_TAX = '0';
public const SALES_TAX = '1';
public function __construct()
{
@@ -26,6 +26,10 @@ class Migration_Sales_Tax_Data extends Migration
$this->appconfig = model('Appconfig');
}
//TODO: we need to figure out why we get a server error when uncommented portions of this migration run
/**
* Perform a migration step.
*/
public function up(): void
{
$number_of_unmigrated = $this->get_count_of_unmigrated();
@@ -44,10 +48,17 @@ class Migration_Sales_Tax_Data extends Migration
error_log('Migrating sales tax history. The number of sales that will be migrated is finished.');
}
/**
* Revert a migration step.
*/
public function down(): void
{
}
/**
* @param int $sale_id
* @return void
*/
private function upgrade_tax_history_for_sale(int $sale_id): void
{
$tax_decimals = $this->appconfig->get_value('tax_decimals', 2);
@@ -91,6 +102,10 @@ class Migration_Sales_Tax_Data extends Migration
$this->save_sales_tax($sales_taxes);
}
/**
* @param int $block_count
* @return ResultInterface
*/
private function get_unmigrated(int $block_count): ResultInterface
{
$builder = $this->db->table('sales_items_taxes as SIT');
@@ -106,6 +121,10 @@ class Migration_Sales_Tax_Data extends Migration
return $builder->get();
}
/**
* @param int $sale_id
* @return ResultInterface
*/
private function get_sale_items_for_migration(int $sale_id): ResultInterface
{
$builder = $this->db->table('sales_items as sales_items');
@@ -122,6 +141,9 @@ class Migration_Sales_Tax_Data extends Migration
return $builder->get();
}
/**
* @return int
*/
private function get_count_of_unmigrated(): int
{
$result = $this->db->query('SELECT COUNT(*) FROM(SELECT SIT.sale_id, ST.sale_id as sales_taxes_sale_id FROM '
@@ -133,6 +155,15 @@ class Migration_Sales_Tax_Data extends Migration
return $result[0]['COUNT(*)'];
}
/**
* @param int $sale_id
* @param int $line
* @param string $name
* @param float $percent
* @param int $tax_type
* @param float $item_tax_amount
* @return void
*/
private function update_sales_items_taxes_amount(int $sale_id, int $line, string $name, float $percent, int $tax_type, float $item_tax_amount): void
{
$builder = $this->db->table('sales_items_taxes');
@@ -143,6 +174,10 @@ class Migration_Sales_Tax_Data extends Migration
$builder->update(['tax_type' => $tax_type, 'item_tax_amount' => $item_tax_amount]);
}
/**
* @param array $sales_taxes
* @return void
*/
private function save_sales_tax(array &$sales_taxes): void
{
$builder = $this->db->Table('sales_taxes');
@@ -153,6 +188,13 @@ class Migration_Sales_Tax_Data extends Migration
}
}
/**
* @param string $quantity
* @param string $price
* @param string $discount_percentage
* @param bool $include_discount
* @return string
*/
public function get_item_total(string $quantity, string $price, string $discount_percentage, bool $include_discount = false): string
{
$total = bcmul($quantity, $price);
@@ -166,6 +208,12 @@ class Migration_Sales_Tax_Data extends Migration
return $total;
}
/**
* @param string $quantity
* @param string $price
* @param string $discount
* @return float
*/
public function get_item_discount(string $quantity, string $price, string $discount): float
{
$total = bcmul($quantity, $price);
@@ -175,6 +223,13 @@ class Migration_Sales_Tax_Data extends Migration
return round($discount, totals_decimals(), PHP_ROUND_HALF_UP); //TODO: I don't think this is currency safe. Round will cast it's first parameter to a float. It also returns a float.
}
/**
* @param string $quantity
* @param string $price
* @param string $discount_percentage
* @param string $tax_percentage
* @return string
*/
public function get_item_tax(string $quantity, string $price, string $discount_percentage, string $tax_percentage): string
{
$tax_included = $this->appconfig->get_value('tax_included', Migration_Sales_Tax_Data::YES) == Migration_Sales_Tax_Data::YES;
@@ -194,6 +249,13 @@ class Migration_Sales_Tax_Data extends Migration
return bcmul($price, $tax_fraction);
}
/**
* @param string $tax_basis
* @param string $tax_percentage
* @param int $rounding_mode
* @param int $decimals
* @return float
*/
public function get_sales_tax_for_amount(string $tax_basis, string $tax_percentage, int $rounding_mode, int $decimals): float
{
$tax_fraction = bcdiv($tax_percentage, '100');
@@ -202,6 +264,12 @@ class Migration_Sales_Tax_Data extends Migration
return $this->round_number($rounding_mode, $tax_amount, $decimals);
}
/**
* @param int $rounding_mode
* @param string $amount
* @param int $decimals
* @return float
*/
public function round_number(int $rounding_mode, string $amount, int $decimals): float
{
if($rounding_mode == Migration_Sales_Tax_Data::ROUND_UP)
@@ -226,6 +294,20 @@ class Migration_Sales_Tax_Data extends Migration
return $rounded_total; //TODO: I don't think this is currency safe. I think we need to be using bcmath() functions like we are in the rest of the code.
}
/**
* @param array $sales_taxes
* @param string $tax_type
* @param string $tax_group
* @param float $tax_rate
* @param string $tax_basis
* @param string $item_tax_amount
* @param int $tax_group_sequence
* @param int $rounding_code
* @param int $sale_id
* @param string $name
* @param string $tax_code
* @return void
*/
public function update_sales_taxes(array &$sales_taxes, string $tax_type, string $tax_group, float $tax_rate, string $tax_basis, string $item_tax_amount, int $tax_group_sequence, int $rounding_code, int $sale_id, string $name = '', string $tax_code = ''): void
{
$tax_group_index = $this->clean('X'.$tax_group);
@@ -258,6 +340,10 @@ class Migration_Sales_Tax_Data extends Migration
}
}
/**
* @param string $string
* @return string
*/
public function clean(string $string): string //TODO: $string is not a good name for this variable
{
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
@@ -265,6 +351,10 @@ class Migration_Sales_Tax_Data extends Migration
return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}
/**
* @param array $sales_taxes
* @return void
*/
public function apply_invoice_taxing(array &$sales_taxes): void
{
if(!empty($sales_taxes)) //TODO: Duplicated code
@@ -287,6 +377,10 @@ class Migration_Sales_Tax_Data extends Migration
}
}
/**
* @param array $sales_taxes
* @return void
*/
public function round_sales_taxes(array &$sales_taxes): void
{
if(!empty($sales_taxes))

View File

@@ -6,12 +6,18 @@ use CodeIgniter\Database\Migration;
class Migration_Upgrade_To_3_2_0 extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.1.1_to_3.2.0.sql');
}
/**
* Revert a migration step.
*/
public function down(): void
{

View File

@@ -6,12 +6,18 @@ use CodeIgniter\Database\Migration;
class Migration_Upgrade_To_3_2_1 extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.2.0_to_3.2.1.sql');
}
/**
* Revert a migration step.
*/
public function down(): void
{

View File

@@ -6,12 +6,18 @@ use CodeIgniter\Database\Migration;
class Migration_Attributes extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.0_attributes.sql');
}
/**
* Revert a migration step.
*/
public function down(): void
{

View File

@@ -6,12 +6,18 @@ use CodeIgniter\Database\Migration;
class Migration_Upgrade_To_3_3_0 extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.2.1_to_3.3.0.sql');
}
/**
* Revert a migration step.
*/
public function down(): void
{

View File

@@ -6,6 +6,9 @@ use CodeIgniter\Database\Migration;
class Migration_IndiaGST extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
if(!$this->db->fieldExists('sales_tax_code', 'customers'))
@@ -20,7 +23,7 @@ class Migration_IndiaGST extends Migration
error_log('Migrating tax configuration');
$count_of_tax_codes = $this->get_count_of_tax_code_entries();
if($count_of_tax_codes > 0)
{
$this->migrate_tax_code_data();
@@ -47,38 +50,52 @@ class Migration_IndiaGST extends Migration
error_log('Migrating tax configuration completed');
}
/**
* Revert a migration step.
*/
public function down(): void
{
}
/**
* @return int
*/
private function get_count_of_tax_code_entries(): int
{
$builder = $this->db->table('tax_codes_backup');
$builder->select('COUNT(*) as count');
return $builder->get()->getRow()->count;
}
/**
* @return int
*/
private function get_count_of_sales_taxes_entries(): int
{
$builder = $this->db->table('sales_taxes_backup');
$builder->select('COUNT(*) as count');
return $builder->get()->getRow()->count;
}
/**
* @return int
*/
private function get_count_of_rate_entries(): int
{
$builder = $this->db->table('tax_code_rates_backup');
$builder->select('COUNT(*) as count');
return $builder->get()->getRow()->count;
}
/*
* This copies the old tax code configuration into the new tax code configuration
* assigning a tax_code_id id to the entry This only needs to be done if there are
* tax codes in the table.
/**
* This copies the old tax code configuration into the new tax code configuration
* assigning a tax_code_id id to the entry This only needs to be done if there are
* tax codes in the table.
*
* @return void
*/
private function migrate_tax_code_data(): void
{
@@ -86,12 +103,14 @@ class Migration_IndiaGST extends Migration
SELECT tax_code, tax_code_name, city, state FROM ' . $this->db->prefixTable('tax_codes_backup'));
}
/*
* The previous upgrade script added the new column to the customers table.
* This will assign a tax code id using the tax code field that was left in place on the customer table.
* After it is complete then it will drop the old customer tax code.
* This MUST run so that the old tax code is dropped
*/
/**
* The previous upgrade script added the new column to the customers table.
* This will assign a tax code id using the tax code field that was left in place on the customer table.
* After it is complete then it will drop the old customer tax code.
* This MUST run so that the old tax code is dropped
*
* @return void
*/
private function migrate_customer_tax_codes(): void
{
$this->db->query('UPDATE ' . $this->db->prefixTable('customers') . ' AS fa SET fa.sales_tax_code_id = (
@@ -123,6 +142,9 @@ class Migration_IndiaGST extends Migration
. 'order by sale_id');
}
/**
* @return void
*/
private function migrate_tax_rates(): void
{
// create a dummy jurisdiction record and retrieve the jurisdiction rate id
@@ -140,6 +162,9 @@ class Migration_IndiaGST extends Migration
. ' ON tax_code = rate_tax_code');
}
/**
* @return void
*/
private function drop_backups(): void
{
$this->db->query('DROP TABLE IF EXISTS ' . $this->db->prefixTable('tax_codes_backup'));

View File

@@ -6,6 +6,9 @@ use CodeIgniter\Database\Migration;
class Migration_IndiaGST1 extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
helper('migration');
@@ -16,6 +19,9 @@ class Migration_IndiaGST1 extends Migration
error_log('Definition of Supplier.Tax Id corrected');
}
/**
* Revert a migration step.
*/
public function down(): void
{
}

View File

@@ -6,12 +6,18 @@ use CodeIgniter\Database\Migration;
class Migration_IndiaGST2 extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.0_indiagst2.sql');
}
/**
* Revert a migration step.
*/
public function down(): void
{
}

View File

@@ -6,12 +6,18 @@ use CodeIgniter\Database\Migration;
class Migration_decimal_attribute_type extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.0_decimal_attribute_type.sql');
}
/**
* Revert a migration step.
*/
public function down(): void
{

View File

@@ -6,12 +6,18 @@ use CodeIgniter\Database\Migration;
class Migration_add_iso_4217 extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.0_add_iso_4217.sql');
}
/**
* Revert a migration step.
*/
public function down(): void
{

View File

@@ -6,12 +6,18 @@ use CodeIgniter\Database\Migration;
class Migration_PaymentTracking extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.0_paymenttracking.sql');
}
/**
* Revert a migration step.
*/
public function down(): void
{

View File

@@ -6,6 +6,9 @@ use CodeIgniter\Database\Migration;
class Migration_RefundTracking extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
helper(['migration', 'locale']);
@@ -100,6 +103,9 @@ class Migration_RefundTracking extends Migration
$this->db->query('DROP TABLE IF EXISTS ' . $this->db->prefixTable('migrate_refund'));
}
/**
* Revert a migration step.
*/
public function down(): void
{

View File

@@ -6,12 +6,18 @@ use CodeIgniter\Database\Migration;
class Migration_DBFix extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.0_dbfix.sql');
}
/**
* Revert a migration step.
*/
public function down(): void
{

View File

@@ -6,12 +6,18 @@ use CodeIgniter\Database\Migration;
class Migration_fix_attribute_datetime extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.0_fix_attribute_datetime.sql');
}
/**
* Revert a migration step.
*/
public function down(): void
{

View File

@@ -6,6 +6,9 @@ use CodeIgniter\Database\Migration;
class Migration_fix_empty_reports extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
$builder = $this->db->table('stock_locations');
@@ -22,8 +25,11 @@ class Migration_fix_empty_reports extends Migration
$builder->update();
}
/**
* Revert a migration step.
*/
public function down(): void
{
}
}
}

View File

@@ -6,14 +6,20 @@ use CodeIgniter\Database\Migration;
class Migration_receipttaxindicator extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
$this->db->query('INSERT INTO ' . $this->db->prefixTable('app_config') . ' (`key`, `value`)
VALUES (\'receipt_show_tax_ind\', \'0\')');
}
/**
* Revert a migration step.
*/
public function down(): void
{
$this->db->query('DELETE FROM ' . $this->db->prefixTable('app_config') . ' WHERE key = \'receipt_show_tax_ind\'');
}
}
}

View File

@@ -6,12 +6,18 @@ use CodeIgniter\Database\Migration;
class Migration_PaymentDateFix extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.2_paymentdatefix.sql');
}
/**
* Revert a migration step.
*/
public function down(): void
{

View File

@@ -6,12 +6,18 @@ use CodeIgniter\Database\Migration;
class Migration_SalesChangePrice extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
helper('migration');
execute_script(APPPATH . 'Database/Migrations/sqlscripts/3.3.2_saleschangeprice.sql');
}
/**
* Revert a migration step.
*/
public function down(): void
{

View File

@@ -15,12 +15,12 @@ use CodeIgniter\Database\ResultInterface;
*/
class Migration_TaxAmount extends Migration
{
const ROUND_UP = 5;
const ROUND_DOWN = 6;
const HALF_FIVE = 7;
const YES = '1';
const VAT_TAX = '0';
const SALES_TAX = '1'; //TODO: It appears that this constant is never used
public const ROUND_UP = 5;
public const ROUND_DOWN = 6;
public const HALF_FIVE = 7;
public const YES = '1';
public const VAT_TAX = '0';
public const SALES_TAX = '1'; //TODO: It appears that this constant is never used
public function __construct()
{
@@ -29,6 +29,9 @@ class Migration_TaxAmount extends Migration
$this->appconfig = model('Appconfig');
}
/**
* Perform a migration step.
*/
public function up(): void
{
$tax_included = ($this->appconfig->get_value('tax_included', Migration_TaxAmount::YES) == Migration_TaxAmount::YES);
@@ -57,11 +60,20 @@ class Migration_TaxAmount extends Migration
}
}
/**
* Revert a migration step.
*/
public function down(): void
{
}
/**
* @param int $sale_id
* @param string $tax_decimals
* @param bool $tax_included
* @return void
*/
private function upgrade_tax_history_for_sale(int $sale_id, string $tax_decimals, bool $tax_included): void //TODO: $tax_included is passed as a parameter but never used in the function body.
{
$customer_sales_tax_support = false;
@@ -90,6 +102,10 @@ class Migration_TaxAmount extends Migration
$this->save_sales_tax($sales_taxes);
}
/**
* @param int $block_count
* @return ResultInterface
*/
private function get_unmigrated(int $block_count): ResultInterface
{
$builder = $this->db->table('sales_items_taxes as SIT');
@@ -104,6 +120,9 @@ class Migration_TaxAmount extends Migration
return $builder->get();
}
/**
* @return int
*/
private function get_count_of_unmigrated(): int
{
$result = $this->db->query('SELECT COUNT(*) FROM(SELECT SIT.sale_id, ST.sale_id as sales_taxes_sale_id FROM '
@@ -116,6 +135,10 @@ class Migration_TaxAmount extends Migration
return $result[0]['COUNT(*)'];
}
/**
* @param int $sale_id
* @return ResultInterface
*/
private function get_sale_items_for_migration(int $sale_id): ResultInterface
{
$builder = $this->db->table('sales_items as sales_items');
@@ -132,6 +155,15 @@ class Migration_TaxAmount extends Migration
return $builder->get();
}
/**
* @param int $sale_id
* @param int $line
* @param string $name
* @param float $percent
* @param int $tax_type
* @param float $item_tax_amount
* @return void
*/
private function update_sales_items_taxes_amount(int $sale_id, int $line, string $name, float $percent, int $tax_type, float $item_tax_amount): void
{
$builder = $this->db->table('sales_items_taxes');
@@ -142,6 +174,10 @@ class Migration_TaxAmount extends Migration
$builder->update(['tax_type' => $tax_type, 'item_tax_amount' => $item_tax_amount]);
}
/**
* @param array $sales_taxes
* @return void
*/
private function save_sales_tax(array &$sales_taxes): void
{
$builder = $this->db->table('sales_taxes');
@@ -152,6 +188,13 @@ class Migration_TaxAmount extends Migration
}
}
/**
* @param string $quantity
* @param string $price
* @param string $discount
* @param bool $include_discount
* @return string
*/
public function get_item_total(string $quantity, string $price, string $discount, bool $include_discount = false): string
{
$total = bcmul($quantity, $price);
@@ -164,6 +207,13 @@ class Migration_TaxAmount extends Migration
return $total;
}
/**
* @param string $tax_basis
* @param string $tax_percentage
* @param int $rounding_mode
* @param int $decimals
* @return float
*/
public function get_item_tax(string $tax_basis, string $tax_percentage, int $rounding_mode, int $decimals): float //TODO: is this currency safe?
{
$tax_fraction = bcdiv(bcadd('100', $tax_percentage), '100');
@@ -173,6 +223,13 @@ class Migration_TaxAmount extends Migration
return $this->round_number($rounding_mode, $tax_amount, $decimals);
}
/**
* @param string $tax_basis
* @param string $tax_percentage
* @param int $rounding_mode
* @param int $decimals
* @return float
*/
public function get_sales_tax_for_amount(string $tax_basis, string $tax_percentage, int $rounding_mode, int $decimals): float //TODO: is this currency safe?
{
$tax_fraction = bcdiv($tax_percentage, '100');
@@ -181,6 +238,12 @@ class Migration_TaxAmount extends Migration
return $this->round_number($rounding_mode, $tax_amount, $decimals);
}
/**
* @param int $rounding_mode
* @param string $amount
* @param int $decimals
* @return float
*/
public function round_number(int $rounding_mode, string $amount, int $decimals): float //TODO: is this currency safe?
{//TODO: This needs to be converted to a switch
if($rounding_mode == Migration_TaxAmount::ROUND_UP) //TODO: === ?
@@ -205,6 +268,20 @@ class Migration_TaxAmount extends Migration
return $rounded_total;
}
/**
* @param array $sales_taxes
* @param int $tax_type
* @param string $tax_group
* @param float $tax_rate
* @param string $tax_basis
* @param string $item_tax_amount
* @param int $tax_group_sequence
* @param int $rounding_code
* @param int $sale_id
* @param string $name
* @param string $tax_code
* @return void
*/
public function update_sales_taxes(array &$sales_taxes, int $tax_type, string $tax_group, float $tax_rate, string $tax_basis, string $item_tax_amount, int $tax_group_sequence, int $rounding_code, int $sale_id, string $name = '', string $tax_code = ''): void
{
$tax_group_index = $this->clean('X' . $tax_group);
@@ -239,6 +316,10 @@ class Migration_TaxAmount extends Migration
}
}
/**
* @param string $string
* @return string
*/
public function clean(string $string): string //TODO: This can probably go into the migration helper as it's used it more than one migration. Also, $string needs to be refactored to a different name.
{
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
@@ -246,6 +327,10 @@ class Migration_TaxAmount extends Migration
return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}
/**
* @param array $sales_taxes
* @return void
*/
public function apply_invoice_taxing(array &$sales_taxes): void
{
if(!empty($sales_taxes)) //TODO: Duplicated code
@@ -266,6 +351,10 @@ class Migration_TaxAmount extends Migration
}
}
/**
* @param array $sales_taxes
* @return void
*/
public function round_sales_taxes(array &$sales_taxes): void
{
if(!empty($sales_taxes))

View File

@@ -6,13 +6,19 @@ use CodeIgniter\Database\Migration;
class Migration_taxgroupconstraint extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('tax_jurisdictions') . ' ADD CONSTRAINT tax_jurisdictions_uq1 UNIQUE (tax_group)');
}
/**
* Revert a migration step.
*/
public function down(): void
{
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('tax_jurisdictions') . ' DROP INDEX tax_jurisdictions_uq1');
}
}
}

View File

@@ -6,6 +6,9 @@ use CodeIgniter\Database\Migration;
class Migration_image_upload_defaults extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
$image_values = [
@@ -19,10 +22,13 @@ class Migration_image_upload_defaults extends Migration
$builder->insertBatch($image_values);
}
/**
* Revert a migration step.
*/
public function down(): void
{
$builder = $this->db->table('app_config');
$builder->whereIn('key', ['image_allowed_types','image_max_height','image_max_size','image_max_width']);
$builder->delete();
}
}
}

View File

@@ -6,6 +6,9 @@ use CodeIgniter\Database\Migration;
class Migration_modify_attr_links_constraint extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
error_log('Migrating modify_attr_links_constraint');
@@ -16,6 +19,9 @@ class Migration_modify_attr_links_constraint extends Migration
error_log('Migrating modify_attr_links_constraint');
}
/**
* Revert a migration step.
*/
public function down(): void
{
}

View File

@@ -6,13 +6,19 @@ use CodeIgniter\Database\Migration;
class Migration_cashrounding extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('sales_payments') . ' ADD COLUMN `cash_adjustment` tinyint NOT NULL DEFAULT 0 AFTER `cash_refund`');
}
/**
* Revert a migration step.
*/
public function down(): void
{
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('sales_payments') . ' DROP COLUMN `cash_adjustment`');
}
}
}

View File

@@ -6,6 +6,9 @@ use CodeIgniter\Database\Migration;
class Migration_add_item_kit_number extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
error_log('Migrating add_item_kit_number');
@@ -16,6 +19,9 @@ class Migration_add_item_kit_number extends Migration
error_log('Migrating add_item_kit_number');
}
/**
* Revert a migration step.
*/
public function down(): void
{
}

View File

@@ -6,6 +6,9 @@ use CodeIgniter\Database\Migration;
class Migration_modify_session_datatype extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
error_log('Migrating modify_session_datatype');
@@ -16,6 +19,9 @@ class Migration_modify_session_datatype extends Migration
error_log('Migrating modify_session_datatype');
}
/**
* Revert a migration step.
*/
public function down(): void
{
}

View File

@@ -10,6 +10,9 @@ use DateTime;
class Migration_database_optimizations extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
error_log('Migrating database_optimizations');
@@ -110,8 +113,8 @@ class Migration_database_optimizations extends Migration
/**
* Updates the attribute_id in all attribute_link rows with duplicated attribute_ids then deletes unneeded rows from attribute_values
*
* @param ResultInterface $attribute_ids_to_fix
* @param array $attribute_value
* @param ResultInterface $attribute_ids_to_fix All attribute_ids that need to parsed
* @param array $attribute_value The attribute value in question.
*/
private function reassign_duplicate_attribute_values(ResultInterface $attribute_ids_to_fix, array $attribute_value)
{
@@ -131,6 +134,9 @@ class Migration_database_optimizations extends Migration
}
}
/**
* Revert a migration step.
*/
public function down(): void
{
}

View File

@@ -7,6 +7,9 @@ use App\Models\Attribute;
class Migration_remove_duplicate_links extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
error_log('Migrating remove_duplicate_links');
@@ -55,7 +58,10 @@ class Migration_remove_duplicate_links extends Migration
$this->db->transComplete();
}
/**
* Revert a migration step.
*/
public function down(): void
{
}
}
}

View File

@@ -6,6 +6,9 @@ use CodeIgniter\Database\Migration;
class Migration_move_expenses_categories extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
error_log('Migrating expense categories module');
@@ -15,6 +18,9 @@ class Migration_move_expenses_categories extends Migration
error_log('Migrating expense categories module completed');
}
/**
* Revert a migration step.
*/
public function down(): void
{

View File

@@ -5,18 +5,25 @@ namespace App\Database\Migrations;
use App\Models\Appconfig;
use CodeIgniter\Database\Forge;
use CodeIgniter\Database\Migration;
use CodeIgniter\HTTP\RedirectResponse;
use CodeIgniter\Router\Exceptions\RedirectException;
use Config\Encryption;
use Config\Services;
class Convert_to_ci4 extends Migration
{
/**
* Constructor.
*/
public function __construct(?Forge $forge = null)
{
parent::__construct($forge);
helper('security');
}
/**
* Perform a migration step.
*/
public function up(): void
{
error_log('Migrating database to CodeIgniter4 formats');
@@ -38,11 +45,18 @@ class Convert_to_ci4 extends Migration
error_log('Migrating to CodeIgniter4 formats completed');
}
/**
* Revert a migration step.
*/
public function down(): void
{
}
/**
* @return RedirectResponse|void
* @throws \ReflectionException
*/
private function convert_ci3_encrypted_data()
{
$appconfig = model(Appconfig::class);
@@ -84,8 +98,10 @@ class Convert_to_ci4 extends Migration
}
/**
* @param array $encrypted_data
* @return array
* Decrypts CI3 encrypted data and returns the plaintext values.
*
* @param array $encrypted_data Data encrypted using CI3 methodology.
* @return array Plaintext, unencrypted data.
*/
private function decrypt_ci3_data(array $encrypted_data): array
{
@@ -108,6 +124,12 @@ class Convert_to_ci4 extends Migration
return $decrypted_data;
}
/**
* Encrypts data using CI4 algorithms.
*
* @param array $plain_data Data to be encrypted.
* @return array Encrypted data.
*/
private function encrypt_data(array $plain_data): array
{
$encrypter = Services::encrypter();
@@ -121,6 +143,12 @@ class Convert_to_ci4 extends Migration
return $encrypted_data;
}
/**
* Decrypts data using CI4 algorithms.
*
* @param array $encrypted_data Data to be decrypted.
* @return array Decrypted data.
*/
private function decrypt_data(array $encrypted_data): array
{
$encrypter = Services::encrypter();

View File

@@ -6,12 +6,18 @@ use CodeIgniter\Database\Migration;
class IntToTinyint extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('customers') . ' MODIFY `consent` tinyint NOT NULL DEFAULT 0');
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('cash_up') . ' MODIFY `note` tinyint NOT NULL DEFAULT 0');
}
/**
* Revert a migration step.
*/
public function down()
{
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('customers') . ' MODIFY `consent` int NOT NULL DEFAULT 0');

View File

@@ -6,6 +6,9 @@ use CodeIgniter\Database\Migration;
class Migration_add_missing_config extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
$image_values = [
@@ -22,6 +25,9 @@ class Migration_add_missing_config extends Migration
$this->db->table('app_config')->ignore(true)->insertBatch($image_values);
}
/**
* Revert a migration step.
*/
public function down(): void
{
// no need to remove necessary config values.

View File

@@ -6,12 +6,18 @@ use CodeIgniter\Database\Migration;
class Migration_drop_account_number_index extends Migration
{
/**
* Perform a migration step.
*/
public function up(): void
{
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('customers') . ' DROP INDEX account_number');
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('customers') . ' ADD INDEX account_number (account_number)');
}
/**
* Revert a migration step.
*/
public function down(): void
{
$this->db->query('ALTER TABLE ' . $this->db->prefixTable('customers') . ' DROP INDEX account_number');

View File

@@ -9,6 +9,9 @@ class Db_log
{
private App $config;
/**
* @return void
*/
public function db_log_queries(): void
{
$this->config = config('App');
@@ -29,6 +32,9 @@ class Db_log
}
}
/**
* @return string
*/
private function generate_message(): string
{
$db = Database::connect();
@@ -50,6 +56,10 @@ class Db_log
return $this->config->db_log_only_long && !$long_query ? '' : $message;
}
/**
* @param float $time
* @return array
*/
private function convert_time(float $time): array
{
$unit = 's';

View File

@@ -4,6 +4,9 @@ namespace App\Events;
class Method
{
/**
* @return void
*/
public static function validate_method()
{
$url = $_SERVER['REQUEST_URI'];

View File

@@ -1,5 +1,10 @@
<?php
/**
* @param array $stock_locations
* @param array $attributes
* @return string
*/
function generate_import_items_csv(array $stock_locations, array $attributes): string
{
$csv_headers = pack('CCC',0xef,0xbb,0xbf); //Encode the Byte-Order Mark (BOM) so that UTF-8 File headers display properly in Microsoft Excel
@@ -10,6 +15,10 @@ function generate_import_items_csv(array $stock_locations, array $attributes): s
return $csv_headers;
}
/**
* @param array $locations
* @return string
*/
function generate_stock_location_headers(array $locations): string
{
$location_headers = '';
@@ -22,6 +31,10 @@ function generate_stock_location_headers(array $locations): string
return $location_headers;
}
/**
* @param array $attribute_names
* @return string
*/
function generate_attribute_headers(array $attribute_names): string
{
$attribute_headers = '';
@@ -35,6 +48,10 @@ function generate_attribute_headers(array $attribute_names): string
return $attribute_headers;
}
/**
* @param string $file_name
* @return array
*/
function get_csv_file(string $file_name): array
{
//TODO: current implementation reads the entire file in. This is memory intensive for large files.
@@ -73,6 +90,10 @@ function get_csv_file(string $file_name): array
return $csv_rows;
}
/**
* @param $file_handle
* @return bool
*/
function bom_exists(&$file_handle): bool
{
$result = false;

View File

@@ -37,6 +37,10 @@ function current_language_code(bool $load_system_language = false): string
return empty($language_code) ? DEFAULT_LANGUAGE_CODE : $language_code;
}
/**
* @param bool $load_system_language
* @return string
*/
function current_language(bool $load_system_language = false): string
{
$employee = model(Employee::class);
@@ -58,6 +62,9 @@ function current_language(bool $load_system_language = false): string
return empty($language) ? DEFAULT_LANGUAGE : $language;
}
/**
* @return string[]
*/
function get_languages(): array
{
return [
@@ -106,6 +113,9 @@ function get_languages(): array
];
}
/**
* @return string[]
*/
function get_timezones(): array
{
return [
@@ -205,6 +215,9 @@ function get_timezones(): array
];
}
/**
* @return string[]
*/
function get_dateformats(): array
{
return [
@@ -218,6 +231,9 @@ function get_dateformats(): array
];
}
/**
* @return string[]
*/
function get_timeformats(): array
{
return [
@@ -280,6 +296,9 @@ function get_payment_options(): array
return $payments;
}
/**
* @return bool
*/
function is_right_side_currency_symbol(): bool
{
$config = config(OSPOS::class)->settings;
@@ -289,52 +308,84 @@ function is_right_side_currency_symbol(): bool
return !preg_match('/^¤/', $fmt->getPattern());
}
/**
* @return int
*/
function quantity_decimals(): int
{
$config = config(OSPOS::class)->settings;
return $config['quantity_decimals'] ? $config['quantity_decimals'] : 0;
}
/**
* @return int
*/
function totals_decimals(): int
{
$config = config(OSPOS::class)->settings;
return $config['currency_decimals'] ? (int)$config['currency_decimals'] : 0;
}
/**
* @return int
*/
function cash_decimals(): int
{
$config = config(OSPOS::class)->settings;
return $config['cash_decimals'] ? $config['cash_decimals'] : 0;
}
/**
* @return int
*/
function tax_decimals(): int
{
$config = config(OSPOS::class)->settings;
return $config['tax_decimals'] ? $config['tax_decimals'] : 0;
}
/**
* @param int $date
* @return string
*/
function to_date(int $date = DEFAULT_DATE): string
{
$config = config(OSPOS::class)->settings;
return date($config['dateformat'], $date);
}
/**
* @param int $datetime
* @return string
*/
function to_datetime(int $datetime = DEFAULT_DATETIME): string
{
$config = config(OSPOS::class)->settings;
return date($config['dateformat'] . ' ' . $config['timeformat'], $datetime);
}
/**
* @param float|null $number
* @return string
*/
function to_currency(?float $number): string
{
return to_decimals($number, 'currency_decimals', NumberFormatter::CURRENCY);
}
/**
* @param float|null $number
* @return string
*/
function to_currency_no_money(?float $number): string
{
return to_decimals($number, 'currency_decimals');
}
/**
* @param float|null $number
* @return string
*/
function to_currency_tax(?float $number): string
{
$config = config(OSPOS::class)->settings;
@@ -349,6 +400,10 @@ function to_currency_tax(?float $number): string
}
}
/**
* @param $number
* @return 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
@@ -366,11 +421,21 @@ function to_tax_decimals($number): string
return to_decimals($number, 'tax_decimals');
}
/**
* @param float|null $number
* @return string
*/
function to_quantity_decimals(?float $number): string
{
return to_decimals($number, 'quantity_decimals');
}
/**
* @param float|null $number
* @param string|null $decimals
* @param int $type
* @return string
*/
function to_decimals(?float $number, string $decimals = null, int $type = NumberFormatter::DECIMAL): string
{
// ignore empty strings and return
@@ -508,6 +573,9 @@ function dateformat_momentjs(string $php_format): string
return strtr($php_format, $SYMBOLS_MATCHING);
}
/**
* @return string
*/
function dateformat_mysql(): string
{
$config = config(OSPOS::class)->settings;
@@ -552,6 +620,10 @@ function dateformat_mysql(): string
return strtr($php_format, $SYMBOLS_MATCHING);
}
/**
* @param string $php_format
* @return string
*/
function dateformat_bootstrap(string $php_format): string
{
$SYMBOLS_MATCHING = [
@@ -593,17 +665,29 @@ function dateformat_bootstrap(string $php_format): string
return strtr($php_format, $SYMBOLS_MATCHING);
}
/**
* @param string $date
* @return bool
*/
function valid_date(string $date): bool //TODO: need a better name for $date. Perhaps $candidate. Also the function name would be better as is_valid_date()
{
$config = config(OSPOS::class)->settings;
return (DateTime::createFromFormat($config['dateformat'], $date));
}
/**
* @param string $decimal
* @return bool
*/
function valid_decimal(string $decimal): bool //TODO: need a better name for $decimal. Perhaps $candidate. Also the function name would be better as is_valid_decimal()
{
return (preg_match('/^(\d*\.)?\d+$/', $decimal) === 1);
}
/**
* @param array $data
* @return array
*/
function encode_array(array $data): array
{
array_walk($data, function(&$value, $key) { $value = rawurlencode($value);});
@@ -611,6 +695,10 @@ function encode_array(array $data): array
return $data;
}
/**
* @param array $data
* @return array
*/
function decode_array(array $data): array
{
array_walk($data, function(&$value, $key) { $value = rawurldecode($value);});

View File

@@ -1,5 +1,11 @@
<?php
/**
* @param string $report_name
* @param string $report_prefix
* @param string $lang_key
* @return array
*/
function get_report_link(string $report_name, string $report_prefix = '', string $lang_key = ''): array
{
$path = 'reports/';

View File

@@ -63,6 +63,9 @@ function check_encryption(): bool
return true;
}
/**
* @return void
*/
function abort_encryption_conversion()
{
$config_path = ROOTPATH . '.env';
@@ -91,6 +94,9 @@ function abort_encryption_conversion()
}
}
/**
* @return void
*/
function remove_backup()
{
$backup_path = WRITEPATH . '/backup/.env.bak';

View File

@@ -605,6 +605,11 @@ function get_item_kit_data_row(object $item_kit): array
];
}
/**
* @param array $columns
* @param array $row
* @return array
*/
function parse_attribute_values(array $columns, array $row): array
{
$attribute_values = [];
@@ -619,6 +624,11 @@ function parse_attribute_values(array $columns, array $row): array
return $attribute_values;
}
/**
* @param array $definition_names
* @param array $row
* @return array
*/
function expand_attribute_values(array $definition_names, array $row): array
{
$values = parse_attribute_values(['attribute_values', 'attribute_dtvalues', 'attribute_dvalues'], $row);
@@ -646,6 +656,9 @@ function expand_attribute_values(array $definition_names, array $row): array
return $attribute_values;
}
/**
* @return string
*/
function get_attribute_definition_manage_table_headers(): string
{
$headers = [
@@ -659,6 +672,10 @@ function get_attribute_definition_manage_table_headers(): string
return transform_headers($headers);
}
/**
* @param object $attribute_row
* @return array
*/
function get_attribute_definition_data_row(object $attribute_row): array
{

View File

@@ -24,11 +24,17 @@ class Barcode_lib
'Ean13' => 'EAN 13'
];
/**
* @return array|string[]
*/
public function get_list_barcodes(): array
{
return $this->supported_barcodes;
}
/**
* @return array
*/
public function get_barcode_config(): array
{
$config = config(OSPOS::class)->settings;
@@ -52,6 +58,11 @@ class Barcode_lib
return $data;
}
/**
* @param array $item
* @param array $barcode_config
* @return object|Code128|Code39|Ean13|Ean8
*/
public static function barcode_instance(array $item, array $barcode_config): object
{
$barcode_instance = Barcode_lib::get_barcode_instance($barcode_config['barcode_type']);
@@ -71,6 +82,10 @@ class Barcode_lib
return $barcode_instance;
}
/**
* @param string $barcode_type
* @return Code128|Code39|Ean13|Ean8
*/
private static function get_barcode_instance(string $barcode_type = 'Code128'): object
{
switch($barcode_type)
@@ -90,6 +105,12 @@ class Barcode_lib
}
}
/**
* @param array $item
* @param object $barcode_instance
* @param array $barcode_config
* @return mixed
*/
private static function barcode_seed(array $item, object $barcode_instance, array $barcode_config)
{
$seed = $barcode_config['barcode_content'] !== "id" && !empty($item['item_number'])
@@ -115,6 +136,11 @@ class Barcode_lib
return $seed;
}
/**
* @param array $item
* @param array $barcode_config
* @return string
*/
private function generate_barcode(array $item, array $barcode_config): string
{
try
@@ -134,6 +160,10 @@ class Barcode_lib
}
}
/**
* @param $barcode_content
* @return string
*/
public function generate_receipt_barcode($barcode_content): string
{
try
@@ -181,6 +211,12 @@ class Barcode_lib
return $display_table;
}
/**
* @param $layout_type
* @param array $item
* @param array $barcode_config
* @return string
*/
private function manage_display_layout($layout_type, array $item, array $barcode_config): string
{
$result = '';

View File

@@ -54,21 +54,21 @@ abstract class BarcodeBase
*/
protected $jpgQuality = 85;
/*
/**
* (Abstract) Set the data
*
* @param mixed data - (int or string) Data to be encoded
* @return instance of \emberlabs\Barcode\BarcodeInterface
* @return throws \OverflowException
* @param mixed $data - (int or string) Data to be encoded
* @return void
* @throws OverflowException
*/
abstract public function setData($data);
abstract public function setData(mixed $data): void;
/*
/**
* Get the data
*
* @param mixed data - (int or string) Data to be encoded
* @return instance of \emberlabs\Barcode\BarcodeInterface
* @return throws \OverflowException
* @throws OverflowException
*/
public function getData()
{
@@ -77,6 +77,7 @@ abstract class BarcodeBase
/**
* Validate the given barcode.
*
* @param $barcode The barcode to validate
* @return bool true if it complies with the barcode formatting
*/
@@ -96,19 +97,19 @@ abstract class BarcodeBase
return $number;
}
/*
/**
* (Abstract) Draw the image
*
* @return void
*/
abstract public function draw();
/*
/**
* Set the Dimensions
*
* @param int x
* @param int y
* @return instance of \emberlabs\Barcode\BarcodeBase
* @param int $x
* @param int $y
* @return BarcodeBase
*/
public function setDimensions($x, $y)
{
@@ -118,10 +119,11 @@ abstract class BarcodeBase
return $this;
}
/*
/**
* Set Quality
* @param int q - jpeg quality
* @return instance of \emberlabs\Barcode\BarcodeBase
*
* @param int $q - jpeg quality
* @return BarcodeBase
*/
public function setQuality($q)
{
@@ -130,10 +132,11 @@ abstract class BarcodeBase
return $this;
}
/*
/**
* Display human readable text below the code
* @param boolean enable - Enable the human readable text
* @return instance of \emberlabs\Barcode\BarcodeBase
*
* @param boolean $enable - Enable the human readable text
* @return BarcodeBase
*/
public function enableHumanText($enable = true)
{
@@ -142,12 +145,13 @@ abstract class BarcodeBase
return $this;
}
/*
/**
* Output Image to the buffer
*
* @param $type
* @return void
*/
public function output($type = 'png')
public function output($type = 'png'): void
{
switch($type)
{
@@ -167,16 +171,14 @@ abstract class BarcodeBase
}
}
/*
/**
* Save Image
*
* @param string filename - File to write to (needs to have .png, .gif, or
* .jpg extension)
* @param string $filename - File to write to (needs to have .png, .gif, or .jpg extension)
* @return void
* @throws \RuntimeException - If the file could not be written or some
* other I/O error.
* @throws RuntimeException - If the file could not be written or some other I/O error.
*/
public function save($filename)
public function save($filename): void
{
$type = strtolower(substr(strrchr($filename, '.'), 1));
@@ -200,12 +202,13 @@ abstract class BarcodeBase
}
}
/*
/**
* Base64 Encoded
* For ouput in-page
* @return void
*
* @return string
*/
public function base64()
public function base64(): string
{
ob_start();
$this->output();

View File

@@ -121,36 +121,40 @@ class Code128 extends BarcodeBase
/*
* Subtypes
*/
const TYPE_AUTO = 0; // Automatically detect the best code
const TYPE_A = 1; // ASCII 00-95 (0-9, A-Z, Control codes, and some special chars)
const TYPE_B = 2; // ASCII 32-127 (0-9, A-Z, a-z, special chars)
const TYPE_C = 3; // Numbers 00-99 (two digits per code)
public const TYPE_AUTO = 0; // Automatically detect the best code
public const TYPE_A = 1; // ASCII 00-95 (0-9, A-Z, Control codes, and some special chars)
public const TYPE_B = 2; // ASCII 32-127 (0-9, A-Z, a-z, special chars)
public const TYPE_C = 3; // Numbers 00-99 (two digits per code)
/*
/**
* Set the data
*
* @param mixed data - (int or string) Data to be encoded
* @return instance of \emberlabs\Barcode\BarcodeInterface
* @return throws \OverflowException
* @param mixed $data - (int or string) Data to be encoded
* @return void
* @throws OverflowException
*/
public function setData($data)
public function setData(mixed $data): void
{
$this->data = $data;
}
/*
/**
* Set the subtype
* Defaults to Autodetect
* @param int type - Const flag for the type
*
* @param int $type - Const flag for the type
* @return void
*/
public function setSubType($type)
{
$this->type = ($type < 1 || $type > 3) ? self::TYPE_AUTO : (int) $type;
}
/*
/**
* Get they key (value of the character)
* @return int - pattern
*
* @param $char
* @return false|int|string pattern
*/
private function getKey($char)
{
@@ -173,12 +177,14 @@ class Code128 extends BarcodeBase
default:
$this->resolveSubtype();
return $this->getKey($char); // recursion!
return $this->getKey($char);
}
}
/*
/**
* Get the bar
*
* @param $char
* @return int - pattern
*/
private function getBar($char)
@@ -188,12 +194,12 @@ class Code128 extends BarcodeBase
return self::$barMap[($key !== false) ? $key : 0];
}
/*
/**
* Resolve subtype
* @todo - Do some better charset checking and enforcement
*
* @return void
*/
private function resolveSubtype()
private function resolveSubtype() //TODO: Do some better charset checking and enforcement
{
if ($this->type == self::TYPE_AUTO)
{

View File

@@ -11,6 +11,8 @@
namespace App\Libraries\Barcodes;
use OverflowException;
/**
* emberlabs Barcode Creator - Code39
* Generate Code39 Barcodes
@@ -21,7 +23,7 @@ namespace App\Libraries\Barcodes;
*/
class Code39 extends BarcodeBase
{
/*
/**
* Binary map
* @var array binMap
*/
@@ -73,51 +75,55 @@ class Code39 extends BarcodeBase
'Z' => '011010000',
);
/*
/**
* const bar proportions
*/
const NARROW_BAR = 20;
const WIDE_BAR = 55;
const QUIET_BAR = 35;
public const NARROW_BAR = 20;
public const WIDE_BAR = 55;
public const QUIET_BAR = 35;
/*
/**
* Set the data
*
* @param mixed data - (int or string) Data to be encoded
* @return instance of \emberlabs\Barcode\BarcodeInterface
* @return throws \OverflowException
* @param mixed $data - (int or string) Data to be encoded
* @return void
* @throws OverflowException
*/
public function setData($data)
public function setData(mixed $data): void
{
$this->data = $data;
}
/*
/**
* Get a binary map value
*/
/**
* @param $char
* @return string
*/
private function getMap($char)
{
return self::$binMap[$char] ?: self::$this->binMap[' '];
}
/*
/**
* Draw the image
*
* Based on the implentation PHP Barcode Image Generator v1.0
* Based on the implentation PHP Barcode Image Generator v1.0
* by Charles J. Scheffold - cs@sid6581.net
* It was released into the Public Domain by its creator.
*
* @return void
*/
public function draw()
public function draw(): void
{
// I know, lots of junk.
$data = '*' . strtoupper(ltrim(rtrim(trim($this->data), '*'), '*')) . '*';
// Length of data X [ 6 narrow bars + 3 wide bars + A single Quiet stop ] - a single quiet stop
$pxPerChar = (strlen($data) * ((6 * self::NARROW_BAR) + (3 * self::WIDE_BAR) + self::QUIET_BAR)) - self::QUIET_BAR;
$widthQuotient = $this->x / $pxPerChar;
// Lengths per type
$narrowBar = (int) (self::NARROW_BAR * $widthQuotient);
$wideBar = (int) (self::WIDE_BAR * $widthQuotient);
@@ -128,7 +134,7 @@ class Code39 extends BarcodeBase
// Do we have degenerate rectangles?
if ($narrowBar < 1 || $wideBar < 1 || $quietBar < 1 || $narrowBar == $quietBar || $narrowBar == $wideBar || $wideBar == $quietBar)
{
throw new \OverflowException("You need to specify a bigger width to properly display this barcode");
throw new OverflowException("You need to specify a bigger width to properly display this barcode");
}
$currentBarX = (int)(($this->x - $imageWidth) / 2);
@@ -140,7 +146,7 @@ class Code39 extends BarcodeBase
{
throw new \RuntimeException("Code39: Image failed to initialize");
}
// Grab our colors
$white = imagecolorallocate($this->img, 255, 255, 255);
$black = imagecolorallocate($this->img, 0, 0, 0);
@@ -149,7 +155,7 @@ class Code39 extends BarcodeBase
foreach($charAry as $_k => $char)
{
$code = str_split($this->getMap($char));
$color = $black;
$color = $black;
foreach($code as $k => $bit)
{
@@ -169,7 +175,7 @@ class Code39 extends BarcodeBase
$color = ($color == $black) ? $white : $black;
}
// Skip the spacer on the last run
// Skip the spacer on the last run
if ($_k == (sizeof($charAry) - 1))
{
break;

View File

@@ -8,7 +8,7 @@
*
* Minimum Requirement: PHP 5.3.0
*/
/**
* Image_Barcode2_Driver_Ean13 class
*
@@ -44,7 +44,7 @@ class Ean13 extends BarcodeBase
{
/*
* Coding map
* @var array
* @var array
*/
private $_codingmap = array(
'0' => array(
@@ -99,9 +99,9 @@ class Ean13 extends BarcodeBase
)
);
/*
/**
* Coding map left
* @var array
* @var array
*/
private $_codingmapleft = array(
'0' => array('A','A','A','A','A','A'),
@@ -116,31 +116,31 @@ class Ean13 extends BarcodeBase
'9' => array('A','B','B','A','B','A')
);
/*
/**
* Set the data
*
* @param mixed data - (int or string) Data to be encoded
* @return instance of \emberlabs\Barcode\BarcodeInterface
* @param mixed $data - (int or string) Data to be encoded
* @return void
*/
public function setData($data)
public function setData(mixed $data): void
{
$this->data = $data;
}
/*
/**
* Generate EAN13 code out of a provided number
* Code taken from http://stackoverflow.com/questions/19890144/generate-valid-ean13-in-php (unknown copyright / license claims)
*
* @param number is the internal code you want to have EANed. The prefix, zero-padding and checksum are added by the function.
* @param $number is the internal code you want to have EANed. The prefix, zero-padding and checksum are added by the function.
* @return string with complete EAN13 code
*/
public function generate($number)
public function generate($number): string
{
$number = '200' . str_pad($number, 9, '0', STR_PAD_LEFT);
$weightflag = true;
$sum = 0;
// Weight for a digit in the checksum is 3, 1, 3.. starting from the last digit.
// Weight for a digit in the checksum is 3, 1, 3... starting from the last digit.
// loop backwards to make the loop length-agnostic. The same basic functionality
// will work for codes of different lengths.
for ($i = strlen($number) - 1; $i >= 0; --$i)
@@ -153,7 +153,11 @@ class Ean13 extends BarcodeBase
return $number;
}
public function validate($barcode)
/**
* @param $barcode
* @return bool
*/
public function validate($barcode): bool
{
// check to see if barcode is 13 digits long
if (!preg_match("/^[0-9]{13}$/", $barcode)) {
@@ -192,35 +196,40 @@ class Ean13 extends BarcodeBase
return false;
}
/*
/**
* Draw the image
*
* @return void
*/
/**
* (Abstract) Draw the image
*
* @return void
*/
public function draw()
{
// Bars is in reference to a single, 1-level bar
$pxPerBar = 2;
// Calculate the barcode width
$barcodewidth = (strlen($this->data)) * (7 * $pxPerBar)
$barcodewidth = (strlen($this->data)) * (7 * $pxPerBar)
+ 3 * $pxPerBar // left
+ 5 * $pxPerBar // center
+ 3 * $pxPerBar // right
;
$this->x = ($this->x == 0) ? $barcodewidth : $this->x;
$this->img = @imagecreate($this->x, $this->y);
if (!$this->img)
{
throw new \RuntimeException("Ean13: Image failed to initialize");
}
$white = imagecolorallocate($this->img, 255, 255, 255);
$black = imagecolorallocate($this->img, 0, 0, 0);
// Fill image with white color
imagefill($this->img, 0, 0, $white);
@@ -229,7 +238,7 @@ class Ean13 extends BarcodeBase
// Initiate x position centering the bar
$xpos = ($this->x - $barcodewidth) / 2;
// Draws the left guard pattern (bar-space-bar)
// bar
imagefilledrectangle(
@@ -237,7 +246,7 @@ class Ean13 extends BarcodeBase
$xpos,
0,
$xpos + $pxPerBar - 1,
$this->y,
$this->y,
$black
);

View File

@@ -8,7 +8,7 @@
*
* Minimum Requirement: PHP 5.3.0
*/
/**
* Image_Barcode2_Driver_Ean8 class
*
@@ -44,7 +44,7 @@ class Ean8 extends BarcodeBase
{
/*
* Coding map
* @var array
* @var array
*/
private $_codingmap = array(
'0' => array(
@@ -89,12 +89,13 @@ class Ean8 extends BarcodeBase
)
);
/*
/**
* Calculate EAN8 or EAN13 automatically
* set $len = 8 for EAN8, $len = 13 for EAN13
*
* @param number is the internal code you want to have EANed. The prefix, zero-padding and checksum are added by the function.
* @return string with complete EAN code
* @param $number The internal code you want to have EANed. The prefix, zero-padding and checksum are added by the function.
* @param $len
* @return string|null Complete EAN code
*/
public function generate($number, $len = 8)
{
@@ -145,7 +146,7 @@ class Ean8 extends BarcodeBase
}
elseif ($r !== intval($barcode[$data_len]))
{
// wrong checkdigit
// wrong check digit
$barcode = null;
}
}
@@ -153,7 +154,11 @@ class Ean8 extends BarcodeBase
return $barcode;
}
public function validate($barcode)
/**
* @param $barcode
* @return bool
*/
public function validate($barcode): bool
{
$ean = str_replace(array("-","/"," ","\t","\n"), "", $barcode); // make a clean ean
$len = strlen($ean);
@@ -183,27 +188,27 @@ class Ean8 extends BarcodeBase
return false;
}
/*
/**
* Set the data
*
* @param mixed data - (int or string) Data to be encoded
* @return instance of \emberlabs\Barcode\BarcodeInterface
* @param mixed $data - (int or string) Data to be encoded
* @return void
*/
public function setData($data)
public function setData(mixed $data): void
{
$this->data = $data;
}
/*
/**
* Draw the image
*
* @return void
*/
public function draw()
public function draw(): void
{
// Bars is in reference to a single, 1-level bar
$pxPerBar = 2;
// Calculate the barcode width
$barcodewidth = (strlen($this->data)) * (7 * $pxPerBar)
+ 3 * $pxPerBar // left
@@ -212,17 +217,17 @@ class Ean8 extends BarcodeBase
;
$this->x = ($this->x == 0) ? $barcodewidth : $this->x;
$this->img = @imagecreate($this->x, $this->y);
if (!$this->img)
{
throw new \RuntimeException("Ean8: Image failed to initialize");
}
$white = imagecolorallocate($this->img, 255, 255, 255);
$black = imagecolorallocate($this->img, 0, 0, 0);
// Fill image with white color
imagefill($this->img, 0, 0, $white);
@@ -231,7 +236,7 @@ class Ean8 extends BarcodeBase
// Initiate x position centering the bar
$xpos = ($this->x - $barcodewidth) / 2;
// Draws the left guard pattern (bar-space-bar)
// bar
imagefilledrectangle(
@@ -239,7 +244,7 @@ class Ean8 extends BarcodeBase
$xpos,
0,
$xpos + $pxPerBar - 1,
$this->y,
$this->y,
$black
);

View File

@@ -10,7 +10,7 @@ use App\Models\Stock_location;
* Item library
*
* Library with utilities to manage items
**/
*/
class Item_lib
{
@@ -23,6 +23,9 @@ class Item_lib
$this->stock_location = model(Stock_location::class);
}
/**
* @return string
*/
public function get_item_location(): string
{
if(!$this->session->get('item_location'))
@@ -34,11 +37,18 @@ class Item_lib
return $this->session->get('item_location');
}
/**
* @param string|null $location
* @return void
*/
public function set_item_location(?string $location): void
{
$this->session->set('item_location',$location);
}
/**
* @return void
*/
public function clear_item_location(): void //TODO: This isn't called from anywhere in the code.
{
$this->session->remove('item_location');

View File

@@ -11,23 +11,37 @@ class MY_Email extends Email
var $default_sender_address = "";
var $default_bounce_address = "";
function __construct($config = [])
/**
* @param array $config
*/
public function __construct(array $config = [])
{
parent::__construct($config);
}
function sendMail(string $subject, string $body, string $to = null, string $reply_name = null, string $reply_mail = null, string $attachment = null): bool
/**
* @param string $subject
* @param string $body
* @param string|null $to
* @param string|null $reply_name
* @param string|null $reply_mail
* @param string|null $attachment
* @return bool
*/
public function sendMail(string $subject, string $body, string $to = null, string $reply_name = null, string $reply_mail = null, string $attachment = null): bool
{
$this->setReplyTo($reply_mail, $reply_name);
$this->setFrom($this->default_sender_address, $this->default_sender_name, $this->default_bounce_address);
$this->setMailtype('html');
$this->setSubject($subject);
$this->setMessage($body);
if ($to == null) {
if($to == null)
{
$to = $this->default_email_address;
$this->setCc($this->default_cc_address);
}
if ($attachment) {
if($attachment)
{
$this->attach($attachment);
}
$this->setTo($to);

View File

@@ -8,6 +8,9 @@ use stdClass;
class MY_Migration extends MigrationRunner
{
/**
* @return bool
*/
public function is_latest(): bool
{
$latest_version = $this->get_latest_migration();
@@ -16,6 +19,9 @@ class MY_Migration extends MigrationRunner
return $latest_version === $current_version;
}
/**
* @return int
*/
public function get_latest_migration(): int
{
$migrations = $this->findMigrations();
@@ -40,6 +46,9 @@ class MY_Migration extends MigrationRunner
return 0;
}
/**
* @return void
*/
public function migrate_to_ci4(): void
{
$ci3_migrations_version = $this->ci3_migrations_exists();
@@ -66,6 +75,10 @@ class MY_Migration extends MigrationRunner
return false;
}
/**
* @param string $ci3_migrations_version
* @return void
*/
private function migrate_table(string $ci3_migrations_version)
{
$this->convert_table();
@@ -88,16 +101,25 @@ class MY_Migration extends MigrationRunner
}
}
/**
* @return void
*/
public function up(): void
{
// TODO: Implement up() method.
}
/**
* @return void
*/
public function down(): void
{
// TODO: Implement down() method.
}
/**
* @return array
*/
private function get_available_migrations(): array
{
$migrations = $this->findMigrations();

View File

@@ -144,6 +144,9 @@ class Mailchimp_lib //TODO: IMO We need to stick to the one class per file princ
{
private $_connector; //TODO: Hungarian notation
/**
* @param array $params
*/
public function __construct(array $params = [])
{
$api_key = (count($params) > 0 && !empty($params['api_key'])) ? $params['api_key'] : '';

View File

@@ -39,6 +39,9 @@ class Receiving_lib
$this->session = session();
}
/**
* @return array
*/
public function get_cart(): array
{
if(!$this->session->get('recv_cart'))
@@ -49,16 +52,26 @@ class Receiving_lib
return $this->session->get('recv_cart');
}
/**
* @param array $cart_data
* @return void
*/
public function set_cart(array $cart_data): void
{
$this->session->set('recv_cart', $cart_data);
}
/**
* @return void
*/
public function empty_cart(): void
{
$this->session->remove('recv_cart');
}
/**
* @return int
*/
public function get_supplier(): int
{
if(!$this->session->get('recv_supplier'))
@@ -69,16 +82,26 @@ class Receiving_lib
return $this->session->get('recv_supplier');
}
/**
* @param int $supplier_id
* @return void
*/
public function set_supplier(int $supplier_id): void
{
$this->session->set('recv_supplier', $supplier_id);
}
/**
* @return void
*/
public function remove_supplier(): void
{
$this->session->remove('recv_supplier');
}
/**
* @return string
*/
public function get_mode(): string
{
if(!$this->session->get('recv_mode'))
@@ -89,16 +112,26 @@ class Receiving_lib
return $this->session->get('recv_mode');
}
/**
* @param string $mode
* @return void
*/
public function set_mode(string $mode): void
{
$this->session->set('recv_mode', $mode);
}
/**
* @return void
*/
public function clear_mode(): void //TODO: This function verb is inconsistent from the others. Consider refactoring to remove_mode()
{
$this->session->remove('recv_mode');
}
/**
* @return int
*/
public function get_stock_source(): int
{
if(!$this->session->get('recv_stock_source'))
@@ -109,6 +142,9 @@ class Receiving_lib
return $this->session->get('recv_stock_source');
}
/**
* @return string
*/
public function get_comment(): string
{
$comment = $this->session->get('recv_comment');
@@ -116,52 +152,86 @@ class Receiving_lib
return empty($comment) ? '' : $comment;
}
/**
* @param string $comment
* @return void
*/
public function set_comment(string $comment): void
{
$this->session->set('recv_comment', $comment);
}
/**
* @return void
*/
public function clear_comment(): void //TODO: This function verb is inconsistent from the others. Consider refactoring to remove_comment()
{
$this->session->remove('recv_comment');
}
/**
* @return string|null
*/
public function get_reference(): ?string
{
return $this->session->get('recv_reference');
}
/**
* @param string $reference
* @return void
*/
public function set_reference(string $reference): void
{
$this->session->set('recv_reference', $reference);
}
/**
* @return void
*/
public function clear_reference(): void //TODO: This function verb is inconsistent from the others. Consider refactoring to remove_reference()
{
$this->session->remove('recv_reference');
}
/**
* @return bool
*/
public function is_print_after_sale(): bool
{
return $this->session->get('recv_print_after_sale') == 'true'
|| $this->session->get('recv_print_after_sale') == '1';
}
/**
* @param bool $print_after_sale
* @return void
*/
public function set_print_after_sale(bool $print_after_sale): void
{
$this->session->set('recv_print_after_sale', $print_after_sale);
}
/**
* @param int $stock_source
* @return void
*/
public function set_stock_source(int $stock_source): void
{
$this->session->set('recv_stock_source', $stock_source);
}
/**
* @return void
*/
public function clear_stock_source(): void
{
$this->session->remove('recv_stock_source');
}
/**
* @return string
*/
public function get_stock_destination(): string
{
if(!$this->session->get('recv_stock_destination'))
@@ -172,16 +242,38 @@ class Receiving_lib
return $this->session->get('recv_stock_destination');
}
/**
* @param string $stock_destination
* @return void
*/
public function set_stock_destination(string $stock_destination): void
{
$this->session->set('recv_stock_destination', $stock_destination);
}
/**
* @return void
*/
public function clear_stock_destination(): void
{
$this->session->remove('recv_stock_destination');
}
//TODO: This array signature needs to be reworked. It's way too long. Perhaps an object needs to be passed rather than these?
/**
* @param int $item_id
* @param int $quantity
* @param int|null $item_location
* @param float $discount
* @param int $discount_type
* @param float|null $price
* @param string|null $description
* @param string|null $serialnumber
* @param float|null $receiving_quantity
* @param int|null $receiving_id
* @param bool $include_deleted
* @return bool
*/
public function add_item(int $item_id, int $quantity = 1, int $item_location = null, float $discount = 0, int $discount_type = 0, float $price = null, string $description = null, string $serialnumber = null, float $receiving_quantity = null, int $receiving_id = null, bool $include_deleted = false): bool
{
$config = config(OSPOS::class)->settings;
@@ -301,6 +393,17 @@ class Receiving_lib
return true;
}
/**
* @param $line
* @param string $description
* @param string $serialnumber
* @param float $quantity
* @param float $discount
* @param int $discount_type
* @param float $price
* @param float $receiving_quantity
* @return bool
*/
public function edit_item($line, string $description, string $serialnumber, float $quantity, float $discount, int $discount_type, float $price, float $receiving_quantity): bool
{
$items = $this->get_cart();
@@ -336,6 +439,10 @@ class Receiving_lib
$this->set_cart($items);
}
/**
* @param int $receipt_receiving_id
* @return void
*/
public function return_entire_receiving(int $receipt_receiving_id): void
{
//RECV #
@@ -362,6 +469,13 @@ class Receiving_lib
$this->set_supplier($this->receiving->get_supplier($receiving_id)->person_id);
}
/**
* @param string $external_item_kit_id
* @param int $item_location
* @param float $discount
* @param int $discount_type
* @return void
*/
public function add_item_kit(string $external_item_kit_id, int $item_location, float $discount, int $discount_type): void
{
//KIT #
@@ -374,6 +488,10 @@ class Receiving_lib
}
}
/**
* @param int $receiving_id
* @return void
*/
public function copy_entire_receiving(int $receiving_id): void
{
$this->empty_cart();
@@ -388,6 +506,9 @@ class Receiving_lib
//$this->set_reference($this->receiving->get_info($receiving_id)->getRow()->reference); //TODO: If this code won't be added back in, then let's delete it.
}
/**
* @return void
*/
public function clear_all(): void
{
$this->clear_mode();
@@ -397,6 +518,14 @@ class Receiving_lib
$this->clear_reference();
}
/**
* @param float $quantity
* @param float $price
* @param float $discount
* @param int $discount_type
* @param float $receiving_quantity
* @return string
*/
public function get_item_total(float $quantity, float $price, float $discount, int $discount_type, float $receiving_quantity): string
{
$extended_quantity = bcmul($quantity, $receiving_quantity);
@@ -412,6 +541,9 @@ class Receiving_lib
return bcsub($total, $discount_amount);
}
/**
* @return string
*/
public function get_total(): string
{
$total = 0;

View File

@@ -20,7 +20,7 @@ use ReflectionException;
* Sale library
*
* Library with utilities to manage sales
**/
*/
class Sale_lib
{
private Attribute $attribute;
@@ -51,6 +51,9 @@ class Sale_lib
$this->config = config(OSPOS::class)->settings;
}
/**
* @return array
*/
public function get_line_sequence_options(): array
{
return [
@@ -60,6 +63,9 @@ class Sale_lib
];
}
/**
* @return array
*/
public function get_register_mode_options(): array
{
$register_modes = [];
@@ -86,6 +92,9 @@ class Sale_lib
return $register_modes;
}
/**
* @return array
*/
public function get_invoice_type_options(): array
{
$invoice_types = [];
@@ -96,6 +105,9 @@ class Sale_lib
return $invoice_types;
}
/**
* @return array
*/
public function get_cart(): array
{
if(!$this->session->get('sales_cart'))
@@ -106,6 +118,10 @@ class Sale_lib
return $this->session->get('sales_cart');
}
/**
* @param array $cart
* @return array
*/
public function sort_and_filter_cart(array $cart): array
{
if(empty($cart))
@@ -176,16 +192,27 @@ class Sale_lib
return $filtered_cart;
}
/**
* @param array $cart_data
* @return void
*/
public function set_cart(array $cart_data): void
{
$this->session->set('sales_cart', $cart_data);
}
/**
* @return void
*/
public function empty_cart(): void
{
$this->session->remove('sales_cart');
}
/**
* @return void
* @throws ReflectionException
*/
public function remove_temp_items(): void
{
// Loop through the cart items and delete temporary items specific to this sale
@@ -199,6 +226,9 @@ class Sale_lib
}
}
/**
* @return string
*/
public function get_comment(): string
{
// avoid returning a null that results in a 0 in the comment if nothing is set/available
@@ -207,36 +237,60 @@ class Sale_lib
return empty($comment) ? '' : $comment;
}
/**
* @param string $comment
* @return void
*/
public function set_comment(string $comment): void
{
$this->session->set('sales_comment', $comment);
}
/**
* @return void
*/
public function clear_comment(): void
{
$this->session->remove('sales_comment');
}
/**
* @return string|null
*/
public function get_invoice_number(): ?string
{
return $this->session->get('sales_invoice_number');
}
/**
* @return string|null
*/
public function get_quote_number(): ?string
{
return $this->session->get('sales_quote_number');
}
/**
* @return string|null
*/
public function get_work_order_number(): ?string
{
return $this->session->get('sales_work_order_number');
}
/**
* @return int
*/
public function get_sale_type(): int
{
return $this->session->get('sale_type');
}
/**
* @param int $invoice_number
* @param bool $keep_custom
* @return void
*/
public function set_invoice_number(int $invoice_number, bool $keep_custom = false): void
{
$current_invoice_number = $this->session->get('sales_invoice_number');
@@ -247,6 +301,11 @@ class Sale_lib
}
}
/**
* @param string $quote_number
* @param bool $keep_custom
* @return void
*/
public function set_quote_number(string $quote_number, bool $keep_custom = false): void
{
$current_quote_number = $this->session->get('sales_quote_number');
@@ -257,6 +316,11 @@ class Sale_lib
}
}
/**
* @param string $work_order_number
* @param bool $keep_custom
* @return void
*/
public function set_work_order_number(string $work_order_number, bool $keep_custom = false): void
{
$current_work_order_number = $this->session->get('sales_work_order_number');
@@ -267,6 +331,11 @@ class Sale_lib
}
}
/**
* @param int $sale_type
* @param bool $keep_custom
* @return void
*/
public function set_sale_type(int $sale_type, bool $keep_custom = false): void
{
$current_sale_type = $this->session->get('sale_type');
@@ -277,77 +346,125 @@ class Sale_lib
}
}
/**
* @return void
*/
public function clear_invoice_number(): void
{
$this->session->remove('sales_invoice_number');
}
/**
* @return void
*/
public function clear_quote_number(): void
{
$this->session->remove('sales_quote_number');
}
/**
* @return void
*/
public function clear_work_order_number(): void
{
$this->session->remove('sales_work_order_number');
}
/**
* @return void
*/
public function clear_sale_type(): void
{
$this->session->remove('sale_type');
}
/**
* @param int $suspended_id
* @return void
*/
public function set_suspended_id(int $suspended_id): void
{
$this->session->set('suspended_id', $suspended_id);
}
/**
* @return int
*/
public function get_suspended_id(): int
{
return $this->session->get('suspended_id');
}
/**
* @return bool
*/
public function is_invoice_mode(): bool
{
return ($this->session->get('sales_mode') == 'sale_invoice' && $this->config['invoice_enable']);
}
/**
* @return bool
*/
public function is_sale_by_receipt_mode(): bool //TODO: This function is not called anywhere in the code.
{
return ($this->session->get('sales_mode') == 'sale'); //TODO: === ?
}
/**
* @return bool
*/
public function is_quote_mode(): bool
{
return ($this->session->get('sales_mode') == 'sale_quote'); //TODO: === ?
}
/**
* @return bool
*/
public function is_return_mode(): bool
{
return ($this->session->get('sales_mode') == 'return'); //TODO: === ?
}
/**
* @return bool
*/
public function is_work_order_mode(): bool
{
return ($this->session->get('sales_mode') == 'sale_work_order'); //TODO: === ?
}
/**
* @param string $price_work_orders
* @return void
*/
public function set_price_work_orders(string $price_work_orders): void
{
$this->session->set('sales_price_work_orders', $price_work_orders);
}
/**
* @return bool
*/
public function is_price_work_orders(): bool
{
return ($this->session->get('sales_price_work_orders') == 'true' //TODO: === ?
|| $this->session->get('sales_price_work_orders') == '1'); //TODO: === ?
}
/**
* @param bool $print_after_sale
* @return void
*/
public function set_print_after_sale(bool $print_after_sale): void
{
$this->session->set('sales_print_after_sale', $print_after_sale);
}
/**
* @return bool
*/
public function is_print_after_sale(): bool
{//TODO: this needs to be converted to a switch statement
if($this->config['print_receipt_check_behaviour'] == 'always') //TODO: 'behaviour' is the british spelling, but the rest of the code is in American English. Not a big deal, but noticed. Also ===
@@ -365,16 +482,26 @@ class Sale_lib
}
}
/**
* @param string $email_receipt
* @return void
*/
public function set_email_receipt(string $email_receipt): void
{
$this->session->set('sales_email_receipt', $email_receipt);
}
/**
* @return void
*/
public function clear_email_receipt(): void
{
$this->session->remove('sales_email_receipt');
}
/**
* @return bool
*/
public function is_email_receipt(): bool
{//TODO: this needs to be converted to a switch statement
if($this->config['email_receipt_check_behaviour'] == 'always') //TODO: 'behaviour' is the british spelling, but the rest of the code is in American English. Not a big deal, but noticed. Also ===
@@ -392,7 +519,9 @@ class Sale_lib
}
}
// Multiple Payments
/**
* Multiple Payments
*/
public function get_payments(): array
{
if(!$this->session->get('sales_payments'))
@@ -403,7 +532,9 @@ class Sale_lib
return $this->session->get('sales_payments');
}
// Multiple Payments
/**
* Multiple Payments
*/
public function set_payments(array $payments_data): void
{
$this->session->set('sales_payments', $payments_data);
@@ -450,7 +581,9 @@ class Sale_lib
$this->set_payments($payments);
}
// Multiple Payments
/**
* Multiple Payments
*/
public function edit_payment(string $payment_id, float $payment_amount): bool
{
$payments = $this->get_payments();
@@ -495,7 +628,9 @@ class Sale_lib
$this->set_payments($payments);
}
// Multiple Payments
/**
* Multiple Payments
*/
public function empty_payments(): void //TODO: function verbs are very inconsistent in these libraries.
{
$this->session->remove('sales_payments');
@@ -641,7 +776,9 @@ class Sale_lib
return $totals;
}
// Multiple Payments
/**
* Multiple Payments
*/
public function get_amount_due(): string
{
// Payment totals need to be identified first so that we know whether or not there is a non-cash payment involved
@@ -655,6 +792,9 @@ class Sale_lib
return $rounded_due == 0 ? '0' : $amount_due; //TODO: ===
}
/**
* @return int
*/
public function get_customer(): int
{
if(!$this->session->get('sales_customer'))
@@ -665,16 +805,26 @@ class Sale_lib
return $this->session->get('sales_customer');
}
/**
* @param int $customer_id
* @return void
*/
public function set_customer(int $customer_id): void
{
$this->session->set('sales_customer', $customer_id);
}
/**
* @return void
*/
public function remove_customer(): void
{
$this->session->remove('sales_customer');
}
/**
* @return int
*/
public function get_employee(): int
{
if(!$this->session->get('sales_employee'))
@@ -685,16 +835,26 @@ class Sale_lib
return $this->session->get('sales_employee');
}
/**
* @param int $employee_id
* @return void
*/
public function set_employee(int $employee_id): void
{
$this->session->set('sales_employee', $employee_id);
}
/**
* @return void
*/
public function remove_employee(): void
{
$this->session->remove('sales_employee');
}
/**
* @return string
*/
public function get_mode(): string
{
if(!$this->session->get('sales_mode'))
@@ -704,16 +864,26 @@ class Sale_lib
return $this->session->get('sales_mode');
}
/**
* @param string $mode
* @return void
*/
public function set_mode(string $mode): void
{
$this->session->set('sales_mode', $mode);
}
/**
* @return void
*/
public function clear_mode(): void
{
$this->session->remove('sales_mode');
}
/**
* @return int|null
*/
public function get_dinner_table(): ?int
{
if(!$this->session->get('dinner_table'))
@@ -727,16 +897,26 @@ class Sale_lib
return $this->session->get('dinner_table');
}
/**
* @param int $dinner_table
* @return void
*/
public function set_dinner_table(int $dinner_table): void
{
$this->session->set('dinner_table', $dinner_table);
}
/**
* @return void
*/
public function clear_table(): void
{
$this->session->remove('dinner_table');
}
/**
* @return int
*/
public function get_sale_location(): int
{
if(!$this->session->get('sales_location'))
@@ -747,57 +927,110 @@ class Sale_lib
return $this->session->get('sales_location');
}
/**
* @param int $location
* @return void
*/
public function set_sale_location(int $location): void
{
$this->session->set('sales_location', $location);
}
/**
* @param string $payment_type
* @return void
*/
public function set_payment_type(string $payment_type): void
{
$this->session->set('payment_type', $payment_type);
}
/**
* @return string|null
*/
public function get_payment_type(): ?string
{
return $this->session->get('payment_type');
}
/**
* @return void
*/
public function clear_sale_location(): void
{
$this->session->remove('sales_location');
}
/**
* @param string $value
* @return void
*/
public function set_giftcard_remainder(string $value): void
{
$this->session->set('sales_giftcard_remainder', $value);
}
/**
* @return string|null
*/
public function get_giftcard_remainder(): ?string
{
return $this->session->get('sales_giftcard_remainder');
}
/**
* @return void
*/
public function clear_giftcard_remainder(): void
{
$this->session->remove('sales_giftcard_remainder');
}
/**
* @param string $value
* @return void
*/
public function set_rewards_remainder(string $value): void
{
$this->session->set('sales_rewards_remainder', $value);
}
/**
* @return string|null
*/
public function get_rewards_remainder(): ?string
{
return $this->session->get('sales_rewards_remainder');
}
/**
* @return void
*/
public function clear_rewards_remainder(): void
{
$this->session->remove('sales_rewards_remainder');
}
//TODO: this function needs to be reworked... way too many parameters. Also, optional parameters must go after mandatory parameters.
/**
* @param int $item_id
* @param int $item_location
* @param string $quantity
* @param string $discount
* @param int $discount_type
* @param int $price_mode
* @param int|null $kit_price_option
* @param int|null $kit_print_option
* @param string|null $price_override
* @param string|null $description
* @param string|null $serialnumber
* @param int|null $sale_id
* @param bool $include_deleted
* @param bool|null $print_option
* @param bool|null $line
* @return bool
*/
public function add_item(int &$item_id, int $item_location, string $quantity = '1', string &$discount = '0.0', int $discount_type = 0, int $price_mode = PRICE_MODE_STANDARD, int $kit_price_option = null, int $kit_print_option = null, string $price_override = null, string $description = null, string $serialnumber = null, int $sale_id = null, bool $include_deleted = false, bool $print_option = null, bool $line = null): bool
{
$item_info = $this->item->get_info_by_id_or_number($item_id, $include_deleted);
@@ -981,6 +1214,11 @@ class Sale_lib
return true;
}
/**
* @param int $item_id
* @param int $item_location
* @return string
*/
public function out_of_stock(int $item_id, int $item_location): string
{
//make sure item exists
@@ -1007,6 +1245,11 @@ class Sale_lib
return '';
}
/**
* @param int $item_id
* @param int $item_location
* @return string
*/
public function get_quantity_already_added(int $item_id, int $item_location): string
{
$items = $this->get_cart();
@@ -1022,6 +1265,10 @@ class Sale_lib
return $quantity_already_added;
}
/**
* @param string $line_to_get
* @return int
*/
public function get_item_id(string $line_to_get): int
{
$items = $this->get_cart();
@@ -1097,6 +1344,10 @@ class Sale_lib
$this->set_cart($items);
}
/**
* @param string $receipt_sale_id
* @return void
*/
public function return_entire_sale(string $receipt_sale_id): void
{
//POS #
@@ -1114,6 +1365,16 @@ class Sale_lib
$this->set_customer($this->sale->get_customer($sale_id)->person_id);
}
/**
* @param string $external_item_kit_id
* @param int $item_location
* @param float $discount
* @param string $discount_type
* @param bool $kit_price_option
* @param bool $kit_print_option
* @param string $stock_warning
* @return bool
*/
public function add_item_kit(string $external_item_kit_id, int $item_location, float $discount, string $discount_type, bool $kit_price_option, bool $kit_print_option, string &$stock_warning): bool
{
//KIT #
@@ -1135,6 +1396,10 @@ class Sale_lib
return $result;
}
/**
* @param int $sale_id
* @return void
*/
public function copy_entire_sale(int $sale_id): void
{
$this->empty_cart();
@@ -1189,11 +1454,17 @@ class Sale_lib
$this->session->set('sale_id', $sale_id);
}
/**
* @return int
*/
public function get_sale_id(): int
{
return $this->session->get('sale_id');
}
/**
* @return void
*/
public function clear_all(): void
{
$this->session->set('sale_id', -1); //TODO: Replace -1 with constant
@@ -1212,6 +1483,9 @@ class Sale_lib
$this->clear_cash_flags();
}
/**
* @return void
*/
public function clear_cash_flags(): void
{
$this->session->remove('cash_rounding');
@@ -1242,6 +1516,9 @@ class Sale_lib
return $cash_rounding;
}
/**
* @return bool
*/
public function is_customer_taxable(): bool //TODO: This function is never called in the code
{
$customer_id = $this->get_customer();
@@ -1251,6 +1528,11 @@ class Sale_lib
return $customer->taxable or $customer_id == -1; //TODO: Replace with constant. Also, I'm not sure we should be using the or operator instead of || here. $a || $b guarantees that the result of those two get returned. It's possible that return $a or $b could return just the result of $a since `or` has a lower precedence.
}
/**
* @param string $discount
* @param int $discount_type
* @return void
*/
public function apply_customer_discount(string $discount, int $discount_type): void
{
// Get all items in the cart so far...
@@ -1273,6 +1555,9 @@ class Sale_lib
$this->set_cart($items);
}
/**
* @return string
*/
public function get_discount(): string
{
$discount = '0.0';
@@ -1288,11 +1573,25 @@ class Sale_lib
return $discount;
}
/**
* @param bool $include_discount
* @param bool $exclude_tax
* @return string
*/
public function get_subtotal(bool $include_discount = false, bool $exclude_tax = false): string
{
return $this->calculate_subtotal($include_discount, $exclude_tax);
}
/**
* @param int $item_id
* @param string $quantity
* @param string $price
* @param string $discount
* @param int $discount_type
* @param bool $include_discount
* @return string
*/
public function get_item_total_tax_exclusive(int $item_id, string $quantity, string $price, string $discount, int $discount_type, bool $include_discount = false): string
{
$tax_info = $this->item_taxes->get_info($item_id);
@@ -1309,6 +1608,16 @@ class Sale_lib
}
//TODO: This function doesn't seem to be called anywhere in the code.
/**
* @param int $item_id
* @param string $discounted_extended_amount
* @param string $quantity
* @param string $price
* @param string $discount
* @param int $discount_type
* @return string
*/
public function get_extended_total_tax_exclusive(int $item_id, string $discounted_extended_amount, string $quantity, string $price, string $discount = '0.0', int $discount_type = 0): string
{
$tax_info = $this->item_taxes->get_info($item_id);
@@ -1323,6 +1632,14 @@ class Sale_lib
return $discounted_extended_amount;
}
/**
* @param string $quantity
* @param string $price
* @param string $discount
* @param int $discount_type
* @param bool $include_discount
* @return string
*/
public function get_item_total(string $quantity, string $price, string $discount, int $discount_type, bool $include_discount = false): string
{
$total = bcmul($quantity, $price);
@@ -1348,6 +1665,12 @@ class Sale_lib
return bcdiv($total, $price, quantity_decimals());
}
/**
* @param string $quantity
* @param string $price
* @param string $discount_amount
* @return string
*/
public function get_extended_amount(string $quantity, string $price, string $discount_amount = '0.0'): string
{
$extended_amount = bcmul($quantity, $price);
@@ -1355,6 +1678,13 @@ class Sale_lib
return bcsub($extended_amount, $discount_amount);
}
/**
* @param string $quantity
* @param string $price
* @param string $discount
* @param int $discount_type
* @return string
*/
public function get_item_discount(string $quantity, string $price, string $discount, int $discount_type): string
{
$total = bcmul($quantity, $price);
@@ -1370,6 +1700,14 @@ class Sale_lib
return (string)round((float)$discount, totals_decimals(), PHP_ROUND_HALF_UP); //TODO: is this safe with monetary amounts?
}
/**
* @param string $quantity
* @param string $price
* @param string $discount
* @param int $discount_type
* @param string $tax_percentage
* @return string
*/
public function get_item_tax(string $quantity, string $price, string $discount, int $discount_type, string $tax_percentage): string
{
$item_total = $this->get_item_total($quantity, $price, $discount, $discount_type, true);
@@ -1387,6 +1725,11 @@ class Sale_lib
return bcmul($item_total, $tax_fraction);
}
/**
* @param bool $include_discount
* @param bool $exclude_tax
* @return string
*/
public function calculate_subtotal(bool $include_discount = false, bool $exclude_tax = false): string
{
$subtotal = '0.0';
@@ -1435,11 +1778,19 @@ class Sale_lib
return $total;
}
/**
* @param int|null $current_dinner_table_id
* @return array
*/
public function get_empty_tables(?int $current_dinner_table_id): array
{
return $this->dinner_table->get_empty_tables($current_dinner_table_id);
}
/**
* @param string $total
* @return string
*/
public function check_for_cash_rounding(string $total): string
{
$cash_decimals = cash_decimals();

View File

@@ -19,7 +19,7 @@ class Sms_lib
/**
* SMS sending function
* Example of use: $response = sendSMS('4477777777', 'My test message');
**/
*/
public function sendSMS(int $phone, string $message): bool
{
$config = config(OSPOS::class)->settings;

View File

@@ -17,11 +17,11 @@ use Config\OSPOS;
* Tax library
*
* Library with utilities to manage taxes
**/
*/
class Tax_lib
{
const TAX_TYPE_EXCLUDED = '1'; //TODO: These constants need to be moved to constants.php
const TAX_TYPE_INCLUDED = '0';
public const TAX_TYPE_EXCLUDED = '1'; //TODO: These constants need to be moved to constants.php
public const TAX_TYPE_INCLUDED = '0';
private Sale_lib $sale_lib;
private Customer $customer;
private Item_taxes $item_taxes;
@@ -46,6 +46,9 @@ class Tax_lib
$this->config = config(OSPOS::class)->settings;
}
/**
* @return array
*/
public function get_tax_types(): array
{
return [
@@ -184,6 +187,16 @@ class Tax_lib
return $tax_details;
}
/**
* @param string $quantity
* @param string $price
* @param string $discount_percentage
* @param int $discount_type
* @param string $tax_percentage
* @param $tax_decimal
* @param $rounding_code
* @return string
*/
public function get_included_tax(string $quantity, string $price, string $discount_percentage, int $discount_type, string $tax_percentage, $tax_decimal, $rounding_code): string //TODO: $tax_decimal and $rounding_code are in the signature but never used in the function.
{
$item_total = $this->sale_lib->get_item_total($quantity, $price, $discount_percentage, $discount_type, true);
@@ -399,6 +412,13 @@ class Tax_lib
return $taxed;
}
/**
* @param string $register_mode
* @param string $city
* @param string $state
* @param int $sales_tax_code_id
* @return int
*/
public function get_applicable_tax_code(string $register_mode, string $city, string $state, int $sales_tax_code_id): int
{
if($register_mode == 'sale')
@@ -421,6 +441,10 @@ class Tax_lib
return $sales_tax_code_id;
}
/**
* @param string $string
* @return string
*/
public function clean(string $string): string //TODO: $string is not a good choice of variable name here.
{
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
@@ -428,6 +452,9 @@ class Tax_lib
return preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
}
/**
* @return array
*/
public function get_tax_code_options(): array
{
$tax_codes = $this->tax_code->get_all()->getResultArray();
@@ -444,6 +471,9 @@ class Tax_lib
return $tax_code_options;
}
/**
* @return array
*/
public function get_tax_jurisdiction_options(): array
{
$tax_jurisdictions = $this->tax_jurisdiction->get_all()->getResultArray();
@@ -460,6 +490,9 @@ class Tax_lib
return $tax_jurisdiction_options;
}
/**
* @return array
*/
public function get_tax_category_options(): array
{
$tax_categories = $this->tax_category->get_all()->getResultArray();
@@ -477,6 +510,10 @@ class Tax_lib
return $tax_category_options;
}
/**
* @param string $selected_tax_type
* @return string
*/
public function get_tax_type_options(string $selected_tax_type): string
{
$selected = 'selected=\"selected\" ';

View File

@@ -73,7 +73,13 @@ 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
/**
* @param string|null $quantity
* @param string|null $price
* @param string|null $item_id_or_number_or_item_kit_or_receipt
* @return void
*/
public function parse_barcode(?string &$quantity, ?string &$price, ?string &$item_id_or_number_or_item_kit_or_receipt): void
{
$config = config(OSPOS::class)->settings;
$barcode_formats = json_decode($config['barcode_formats']);
@@ -96,6 +102,12 @@ class Token_lib
}
}
/**
* @param string $string
* @param string $pattern
* @param array $tokens
* @return array
*/
public function parse(string $string, string $pattern, array $tokens = []): array //TODO: $string is a poor name for this parameter.
{
$token_tree = $this->scan($pattern);
@@ -130,6 +142,14 @@ class Token_lib
return $results;
}
/**
* @param array $used_tokens
* @param array $tokens_to_replace
* @param array $token_values
* @param array $tokens
* @param bool $save
* @return array
*/
public function generate(array $used_tokens, array &$tokens_to_replace, array &$token_values, array $tokens, bool $save = true): array //TODO: $tokens
{
foreach($used_tokens as $token_code => $token_info)
@@ -154,6 +174,12 @@ class Token_lib
return $token_values;
}
/**
* @param $token_code
* @param array $tokens
* @param $save
* @return string
*/
private function resolve_token($token_code, array $tokens = [], $save = true): string
{
foreach(array_merge($tokens, Token::get_tokens()) as $token)

View File

@@ -23,6 +23,12 @@ class Appconfig extends Model
'value'
];
/**
* Checks to see if a given configuration exists in the database.
*
* @param string $key Key name to be searched.
* @return bool True if the key is found in the database or false if it does not exist.
*/
public function exists(string $key): bool
{
$builder = $this->db->table('app_config');
@@ -31,6 +37,11 @@ class Appconfig extends Model
return ($builder->get()->getNumRows() === 1);
}
/**
* Get all OpenSourcePOS configuration values from the database.
*
* @return ResultInterface
*/
public function get_all(): ResultInterface
{
$builder = $this->db->table('app_config');
@@ -39,6 +50,11 @@ class Appconfig extends Model
return $builder->get();
}
/**
* @param string $key
* @param string $default
* @return string
*/
public function get_value(string $key, string $default = ''): string
{
$builder = $this->db->table('app_config');
@@ -56,7 +72,7 @@ class Appconfig extends Model
* Calls the parent save() from BaseModel and updates the cached reference.
*
* @param array|object $data
* @return bool
* @return bool true when the save was successful and false if the save failed.
* @throws ReflectionException
*/
public function save($data): bool
@@ -96,12 +112,23 @@ class Appconfig extends Model
return $success;
}
/**
* Deletes a row from the Appconfig table given the name of the setting to delete.
*
* @param ?string $id The field name to be deleted in the Appconfig table.
* @param bool $purge A hard delete is conducted if true and soft delete on false.
* @return bool Result of the delete operation.
*/
public function delete($id = null, bool $purge = false)
{
$builder = $this->db->table('app_config');
return $builder->delete(['key' => $id]);
}
/**
* @return bool
*/
public function delete_all(): bool //TODO: This function is never used in the code. Consider removing it.
{
$builder = $this->db->table('app_config');

View File

@@ -2,6 +2,8 @@
namespace App\Models;
use CodeIgniter\Database\BaseResult;
use CodeIgniter\Database\Query;
use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Model;
use CodeIgniter\Database\RawSql;
@@ -35,10 +37,13 @@ class Attribute extends Model
'attribute_decimal'
];
const SHOW_IN_ITEMS = 1; //TODO: These need to be moved to constants.php
const SHOW_IN_SALES = 2;
const SHOW_IN_RECEIVINGS = 4;
public const SHOW_IN_ITEMS = 1; //TODO: These need to be moved to constants.php
public const SHOW_IN_SALES = 2;
public const SHOW_IN_RECEIVINGS = 4;
/**
* @return array
*/
public static function get_definition_flags(): array
{
$class = new ReflectionClass(__CLASS__);
@@ -60,9 +65,9 @@ class Attribute extends Model
/**
* Returns whether an attribute_link row exists given an item_id and optionally a definition_id
* @param int $item_id
* @param bool $definition_id
* @return bool returns true if at least one attribute_link exists or false if no attributes exist.
* @param int $item_id ID of the item to check for an associated attribute.
* @param bool $definition_id Attribute definition ID to check.
* @return bool returns true if at least one attribute_link exists or false if no attributes exist for that item and attribute.
*/
public function link_exists(int $item_id, bool $definition_id = false): bool
{
@@ -84,8 +89,12 @@ class Attribute extends Model
return ($builder->get()->getNumRows() > 0); //TODO: This is returning a result of 1 on dropdown
}
/*
/**
* Determines if a given attribute_value exists in the attribute_values table and returns the attribute_id if it does
*
* @param string|float $attribute_value The value to search for in the attribute values table.
* @param string $definition_type The definition type which will dictate which column is searched.
* @return int|bool The attribute ID of the found row or false if no attribute value was found.
*/
public function value_exists($attribute_value, string $definition_type = TEXT)
{
@@ -119,8 +128,8 @@ class Attribute extends Model
return false;
}
/*
Gets information about a particular attribute definition
/**
* Gets information about a particular attribute definition
*/
public function get_info(int $definition_id): object
{
@@ -150,8 +159,8 @@ class Attribute extends Model
}
}
/*
Performs a search on attribute definitions
/**
* 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
{
@@ -184,8 +193,8 @@ class Attribute extends Model
/**
* Gets all attributes connected to an item given the item_id
*
* @param int $item_id
* @return array
* @param int $item_id Item to retrieve attributes for.
* @return array Attributes for the item.
*/
public function get_attributes_by_item(int $item_id): array
{
@@ -202,6 +211,10 @@ class Attribute extends Model
return $this->to_array($results, 'definition_id');
}
/**
* @param array|null $definition_ids
* @return array
*/
public function get_values_by_definitions(?array $definition_ids): array
{
if(count($definition_ids ? : []))
@@ -223,6 +236,11 @@ class Attribute extends Model
return [];
}
/**
* @param string $attribute_type
* @param int $definition_id
* @return array
*/
public function get_definitions_by_type(string $attribute_type, int $definition_id = NO_DEFINITION_ID): array
{
$builder = $this->db->table('attribute_definitions');
@@ -240,6 +258,10 @@ class Attribute extends Model
return $this->to_array($results, 'definition_id', 'definition_name');
}
/**
* @param int $definition_flags
* @return array
*/
public function get_definitions_by_flags(int $definition_flags): array
{
$builder = $this->db->table('attribute_definitions');
@@ -276,6 +298,10 @@ class Attribute extends Model
return $definition_name + $this->to_array($results, 'definition_id', 'definition_name');
}
/**
* @param int $definition_id
* @return array
*/
public function get_definition_values(int $definition_id): array
{
$attribute_values = [];
@@ -296,6 +322,12 @@ class Attribute extends Model
return $attribute_values;
}
/**
* @param array $results
* @param string $key
* @param string $value
* @return array
*/
private function to_array(array $results, string $key, string $value = ''): array
{
return array_column(array_map(function($result) use ($key, $value){
@@ -303,8 +335,8 @@ class Attribute extends Model
}, $results), 1, 0);
}
/*
Gets total of rows
/**
* Gets total of rows
*/
public function get_total_rows(): int
{
@@ -314,14 +346,20 @@ class Attribute extends Model
return $builder->countAllResults();
}
/*
Get number of rows
/**
* Get number of rows
*/
public function get_found_rows(string $search): int
{
return $this->search($search)->getNumRows();
}
/**
* @param int $definition_id
* @param string $from
* @param string $to
* @return bool
*/
private function check_data_validity(int $definition_id, string $from, string $to): bool
{
$success = false;
@@ -365,9 +403,10 @@ class Attribute extends Model
/**
* Returns all item_ids with a specific attribute_value and attribute_definition
* @param string $attribute_value
* @param int $definition_id
* @return array
*
* @param string $attribute_value Attribute value to be searched
* @param int $definition_id ID of the specific attribute to return items for.
* @return array Item_ids matching the given parameters
*/
private function get_items_by_value(string $attribute_value, int $definition_id): array
{
@@ -382,9 +421,10 @@ class Attribute extends Model
/**
* Converts data in attribute_values and attribute_links tables associated with the conversion of one attribute type to another.
*
* @param int $definition_id
* @param string $from_type
* @param string $to_type
* @param string $from_type
* @param string $to_type
* @return boolean
*/
private function convert_definition_data(int $definition_id, string $from_type, string $to_type): bool
@@ -453,6 +493,10 @@ class Attribute extends Model
return $success;
}
/**
* @param int $definition_id
* @return array
*/
private function checkbox_attribute_values(int $definition_id): array
{
$zero_attribute_id = $this->value_exists('0');
@@ -472,8 +516,8 @@ class Attribute extends Model
return [$zero_attribute_id, $one_attribute_id];
}
/*
Inserts or updates a definition
/**
* Inserts or updates a definition
*/
public function save_definition(array &$definition_data, int $definition_id = NO_DEFINITION_ID): bool
{
@@ -529,6 +573,11 @@ class Attribute extends Model
return $success;
}
/**
* @param string $definition_name
* @param $definition_type
* @return array
*/
public function get_definition_by_name(string $definition_name, $definition_type = false): array
{
$builder = $this->db->table('attribute_definitions');
@@ -579,6 +628,11 @@ class Attribute extends Model
return $this->db->transStatus();
}
/**
* @param int $item_id
* @param bool $definition_id
* @return bool
*/
public function delete_link(int $item_id, bool $definition_id = false): bool
{
$delete_data = ['item_id' => $item_id];
@@ -596,6 +650,11 @@ class Attribute extends Model
return $builder->delete($delete_data);
}
/**
* @param int $item_id
* @param int|null $definition_id
* @return object|stdClass|null
*/
public function get_link_value(int $item_id, ?int $definition_id): ?object
{
$builder = $this->db->table('attribute_links');
@@ -610,6 +669,13 @@ class Attribute extends Model
return $builder->get()->getRowObject();
}
/**
* @param int $item_id
* @param string $sale_receiving_fk
* @param int|null $id
* @param int|null $definition_flags
* @return 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());
@@ -643,6 +709,11 @@ class Attribute extends Model
return $result;
}
/**
* @param int $item_id
* @param int $definition_id
* @return object|array|stdClass|null
*/
public function get_attribute_value(int $item_id, int $definition_id): ?object
{
$builder = $this->db->table('attribute_values');
@@ -690,6 +761,11 @@ class Attribute extends Model
return $empty_obj;
}
/**
* @param int $item_id
* @return array
*/
public function get_attribute_values(int $item_id): array //TODO: Is this function used anywhere in the code?
{
$builder = $this->db->table('attribute_links');
@@ -702,6 +778,12 @@ class Attribute extends Model
return $this->to_array($results, 'definition_id');
}
/**
* @param int $item_id
* @param string $sale_receiving_fk
* @param int $id
* @return void
*/
public function copy_attribute_links(int $item_id, string $sale_receiving_fk, int $id): void
{
$query = 'SELECT ' . $this->db->escape($item_id) . ', definition_id, attribute_id, ' . $this->db->escape($id);
@@ -825,6 +907,11 @@ class Attribute extends Model
return $attribute_id;
}
/**
* @param string $attribute_value
* @param int $definition_id
* @return bool|BaseResult|Query
*/
public function delete_value(string $attribute_value, int $definition_id)
{
$query = 'DELETE atrv, atrl ';
@@ -848,6 +935,10 @@ class Attribute extends Model
return $builder->update(['deleted' => DELETED]);
}
/**
* @param array $definition_ids
* @return bool
*/
public function delete_definition_list(array $definition_ids): bool
{
$builder = $this->db->table('attribute_definitions');

View File

@@ -58,6 +58,10 @@ class Cashup extends Model
return $employee->get_info($builder->get()->getRow()->employee_id);
}
/**
* @param string $cashup_ids
* @return ResultInterface
*/
public function get_multiple_info(string $cashup_ids): ResultInterface
{
$builder = $this->db->table('cash_up');

View File

@@ -264,6 +264,11 @@ class Customer extends Person
$builder->update(['points' => $value]);
}
/**
* @param $customer_id
* @param bool $purge
* @return bool
*/
public function delete($customer_id = null, bool $purge = false): bool
{
$result = true;

View File

@@ -20,6 +20,10 @@ class Customer_rewards extends Model
'deleted'
];
/**
* @param int $package_id
* @return bool
*/
public function exists(int $package_id): bool
{
$builder = $this->db->table('customers_packages');
@@ -28,6 +32,11 @@ class Customer_rewards extends Model
return ($builder->get()->getNumRows() >= 1);
}
/**
* @param array $package_data
* @param int $package_id
* @return bool
*/
public function save_value(array $package_data, int $package_id): bool
{
$package_data_to_save = [
@@ -48,6 +57,10 @@ class Customer_rewards extends Model
return $builder->update($package_data_to_save);
}
/**
* @param int $package_id
* @return string
*/
public function get_name(int $package_id): string
{
$builder = $this->db->table('customers_packages');
@@ -56,6 +69,10 @@ class Customer_rewards extends Model
return $builder->get()->getRow()->package_name;
}
/**
* @param int $package_id
* @return float
*/
public function get_points_percent(int $package_id): float
{
$builder = $this->db->table('customers_packages');
@@ -64,6 +81,9 @@ class Customer_rewards extends Model
return $builder->get()->getRow()->points_percent;
}
/**
* @return ResultInterface
*/
public function get_all(): ResultInterface
{
$builder = $this->db->table('customers_packages');

View File

@@ -20,6 +20,10 @@ class Dinner_table extends Model
'deleted'
];
/**
* @param int $dinner_table_id
* @return bool
*/
public function exists(int $dinner_table_id): bool
{
$builder = $this->db->table('dinner_tables');
@@ -28,6 +32,11 @@ class Dinner_table extends Model
return ($builder->get()->getNumRows() >= 1);
}
/**
* @param array $table_data
* @param int $dinner_table_id
* @return bool
*/
public function save_value(array $table_data, int $dinner_table_id): bool
{
$table_data_to_save = ['name' => $table_data['name'], 'deleted' => 0];
@@ -64,6 +73,10 @@ class Dinner_table extends Model
return $empty_tables_array;
}
/**
* @param int $dinner_table_id
* @return string
*/
public function get_name(int $dinner_table_id): string
{
if(empty($dinner_table_id))
@@ -79,6 +92,10 @@ class Dinner_table extends Model
}
}
/**
* @param int $dinner_table_id
* @return bool
*/
public function is_occupied(int $dinner_table_id): bool
{
if(empty($dinner_table_id))
@@ -94,6 +111,9 @@ class Dinner_table extends Model
}
}
/**
* @return ResultInterface
*/
public function get_all(): ResultInterface
{
$builder = $this->db->table('dinner_tables');

View File

@@ -45,6 +45,11 @@ class Employee extends Person
return ($builder->get()->getNumRows() == 1); //TODO: ===
}
/**
* @param int $employee_id
* @param string $username
* @return bool
*/
public function username_exists(int $employee_id, string $username): bool
{
$builder = $this->db->table('employees');

View File

@@ -6,19 +6,22 @@ use ReflectionClass;
class Rounding_mode
{
const HALF_UP = PHP_ROUND_HALF_UP; //TODO: These constants need to be moved to constants.php
const HALF_DOWN = PHP_ROUND_HALF_DOWN;
const HALF_EVEN = PHP_ROUND_HALF_EVEN;
const HALF_ODD = PHP_ROUND_HALF_ODD;
const ROUND_UP = 5;
const ROUND_DOWN = 6;
const HALF_FIVE = 7;
public const HALF_UP = PHP_ROUND_HALF_UP; //TODO: These constants need to be moved to constants.php
public const HALF_DOWN = PHP_ROUND_HALF_DOWN;
public const HALF_EVEN = PHP_ROUND_HALF_EVEN;
public const HALF_ODD = PHP_ROUND_HALF_ODD;
public const ROUND_UP = 5;
public const ROUND_DOWN = 6;
public const HALF_FIVE = 7;
public function __construct()
{
helper('language');
}
/**
* @return array
*/
public static function get_rounding_options(): array
{
$class = new ReflectionClass(__CLASS__);
@@ -32,6 +35,10 @@ class Rounding_mode
return $result;
}
/**
* @param int $code
* @return string
*/
public static function get_rounding_code_name(int $code): string
{
if(empty($code))
@@ -42,6 +49,9 @@ class Rounding_mode
return Rounding_mode::get_rounding_options()[$code];
}
/**
* @return string
*/
public static function get_html_rounding_options(): string
{
$x = '';
@@ -54,6 +64,12 @@ class Rounding_mode
return $x;
}
/**
* @param int $rounding_mode
* @param float $amount
* @param int $decimals
* @return string
*/
public static function round_number(int $rounding_mode, float $amount, int $decimals): string
{//TODO: this needs to be replaced with a switch statement
if($rounding_mode == Rounding_mode::ROUND_UP)

View File

@@ -65,6 +65,10 @@ class Expense extends Model
return $employee->get_info($builder->get()->getRow()->employee_id); //TODO: refactor out the nested function call.
}
/**
* @param array $expense_ids
* @return ResultInterface
*/
public function get_multiple_info(array $expense_ids): ResultInterface
{
$builder = $this->db->table('expenses');

View File

@@ -2,6 +2,7 @@
namespace App\Models;
use CodeIgniter\Database\BaseResult;
use CodeIgniter\Database\ResultInterface;
use CodeIgniter\Model;
use ReflectionException;
@@ -27,13 +28,25 @@ class Inventory extends Model
'trans_location'
];
/**
* Insert new data into the Inventory table.
*
* @param array|null|object $inventory_data Data to be inserted into the inventory table.
* @param bool $returnID Returns the value of the ID column for the inserted row.
* @return int|string|bool The ID of the inserted row on success or false on failure
*/
public function insert($inventory_data = null, bool $returnID = true)
{
$builder = $this->db->table('inventory');
return $builder->insert($inventory_data);
return $builder->insert($inventory_data, $returnID);
}
/**
* @param $comment
* @param $inventory_data
* @return bool
*/
public function update($comment = null, $inventory_data = null): bool
{
$builder = $this->db->table('inventory');
@@ -88,6 +101,10 @@ class Inventory extends Model
return true;
}
/**
* @param int $item_id
* @return array
*/
public function get_inventory_sum(int $item_id): array
{
$builder = $this->db->table('inventory');

View File

@@ -79,7 +79,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') //TODO: !==
if(ctype_digit($item_id) && substr($item_id, 0, 1) != '0') //TODO: !==
{
$builder->where('item_id !=', intval($item_id));
}
@@ -97,7 +97,11 @@ class Item extends Model
return $builder->countAllResults();
}
public function get_tax_category_usage(int $tax_category_id): int //TODO: This function is never called in the code.
/**
* @param int $tax_category_id
* @return int
*/
public function get_tax_category_usage(int $tax_category_id): int //TODO: This function is never called in the code.
{
$builder = $this->db->table('items');
$builder->where('tax_category_id', $tax_category_id);
@@ -119,14 +123,29 @@ class Item extends Model
public function search(string $search, array $filters, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'items.name', ?string $order = 'asc', ?bool $count_only = false)
{
// 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;
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::class)->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
$builder = $this->db->table('items AS items'); //TODO: I'm not sure if it's needed to write items AS items... I think you can just get away with items
// get_found_rows case
if($count_only)
@@ -183,7 +202,7 @@ class Item extends Model
$builder->where('location_id', $filters['stock_location_id']);
}
if(empty($config['date_or_time_format'])) //TODO: This needs to be replaced with Ternary notation
if(empty($config['date_or_time_format'])) //TODO: This needs to be replaced with Ternary notation
{
$builder->where('DATE_FORMAT(trans_date, "%Y-%m-%d") BETWEEN ' . $this->db->escape($filters['start_date']) . ' AND ' . $this->db->escape($filters['end_date']));
}
@@ -196,7 +215,7 @@ class Item extends Model
if(!empty($search))
{
if ($attributes_enabled && $filters['search_custom'])
if($attributes_enabled && $filters['search_custom'])
{
$builder->having("attribute_values LIKE '%$search%'");
$builder->orHaving("attribute_dtvalues LIKE '%$search%'");
@@ -205,11 +224,11 @@ class Item extends Model
else
{
$builder->groupStart();
$builder->like('name', $search);
$builder->orLike('item_number', $search);
$builder->orLike('items.item_id', $search);
$builder->orLike('company_name', $search);
$builder->orLike('items.category', $search);
$builder->like('name', $search);
$builder->orLike('item_number', $search);
$builder->orLike('items.item_id', $search);
$builder->orLike('company_name', $search);
$builder->orLike('items.category', $search);
$builder->groupEnd();
}
}
@@ -336,7 +355,8 @@ class Item extends Model
// Iterate through field definitions to determine how the fields should be initialized
foreach($this->db->getFieldData($table_name) as $field) {
foreach($this->db->getFieldData($table_name) as $field)
{
$field_name = $field->name;
@@ -406,7 +426,7 @@ class Item extends Model
$query = $builder->get();
if($query->getNumRows() == 1) //TODO: ===
if($query->getNumRows() == 1) //TODO: ===
{
return $query->getRow()->item_id;
}
@@ -445,7 +465,7 @@ class Item extends Model
/**
* Inserts or updates an item
*/
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
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');
@@ -556,7 +576,11 @@ class Item extends Model
return $success;
}
function get_search_suggestion_format(string $seed = null): string
/**
* @param string|null $seed
* @return string
*/
public function get_search_suggestion_format(string $seed = null): string
{
$config = config(OSPOS::class)->settings;
$seed .= ',' . $config['suggestions_first_column'];
@@ -574,7 +598,11 @@ class Item extends Model
return $seed;
}
function get_search_suggestion_label($result_row): string
/**
* @param $result_row
* @return string
*/
public function get_search_suggestion_label($result_row): string
{
$config = config(OSPOS::class)->settings;
$label = '';
@@ -607,15 +635,21 @@ class Item extends Model
return $label;
}
/**
* @param string $label
* @param string $item_field_name
* @param object $item_info
* @return void
*/
private function append_label(string &$label, string $item_field_name, object $item_info): void
{
if($item_field_name !== '')
{
if($label == '')
{
if($item_field_name == 'name') //TODO: This needs to be replaced with Ternary notation if possible
if($item_field_name == 'name') //TODO: This needs to be replaced with Ternary notation if possible
{
$label .= implode(NAME_SEPARATOR, [$item_info->name, $item_info->pack_name]); //TODO: no need for .= operator. If it gets here then that means label is an empty string.
$label .= implode(NAME_SEPARATOR, [$item_info->name, $item_info->pack_name]); //TODO: no need for .= operator. If it gets here then that means label is an empty string.
}
else
{
@@ -636,6 +670,13 @@ class Item extends Model
}
}
/**
* @param string $search
* @param array $filters
* @param bool $unique
* @param int $limit
* @return array
*/
public function get_search_suggestions(string $search, array $filters = ['is_deleted' => false, 'search_custom' => false], bool $unique = false, int $limit = 25): array
{
$suggestions = [];
@@ -671,7 +712,7 @@ class Item extends Model
$builder = $this->db->table('items');
$builder->select('category');
$builder->where('deleted', $filters['is_deleted']);
$builder->distinct(); //TODO: duplicate code. Refactor method.
$builder->distinct(); //TODO: duplicate code. Refactor method.
$builder->like('category', $search);
$builder->orderBy('category', 'asc');
@@ -700,14 +741,17 @@ class Item extends Model
$builder = $this->db->table('items');
$builder->select($this->get_search_suggestion_format('item_id, name, pack_name, description'));
$builder->where('deleted', $filters['is_deleted']);
$builder->like('description', $search); //TODO: duplicate code, refactor method.
$builder->like('description', $search); //TODO: duplicate code, refactor method.
$builder->orderBy('description', 'asc');
foreach($builder->get()->getResult() as $row)
{
$entry = ['value' => $row->item_id, 'label' => $this->get_search_suggestion_label($row)];
if(!array_walk($suggestions, function($value, $label) use ($entry) { return $entry['label'] != $label; } ))
if(!array_walk($suggestions, function ($value, $label) use ($entry)
{
return $entry['label'] != $label;
}))
{
$suggestions[] = $entry;
}
@@ -741,6 +785,13 @@ class Item extends Model
}
/**
* @param string $search
* @param array $filters
* @param bool $unique
* @param int $limit
* @return array
*/
public function get_stock_search_suggestions(string $search, array $filters = ['is_deleted' => false, 'search_custom' => false], bool $unique = false, int $limit = 25): array
{
$suggestions = [];
@@ -810,20 +861,23 @@ class Item extends Model
$builder->where('deleted', $filters['is_deleted']);
$builder->whereIn('item_type', $non_kit); // standard, exclude kit items since kits will be picked up later
$builder->where('stock_type', '0'); // stocked items only
$builder->like('description', $search); //TODO: duplicated code, refactor method.
$builder->like('description', $search); //TODO: duplicated code, refactor method.
$builder->orderBy('description', 'asc');
foreach($builder->get()->getResult() as $row)
{
$entry = ['value' => $row->item_id, 'label' => $this->get_search_suggestion_label($row)];
if(!array_walk($suggestions, function($value, $label) use ($entry) { return $entry['label'] != $label; } ))
if(!array_walk($suggestions, function ($value, $label) use ($entry)
{
return $entry['label'] != $label;
}))
{
$suggestions[] = $entry;
}
}
//Search by custom fields
if($filters['search_custom'] !== false) //TODO: duplicated code. We should refactor out a method... this can be replaced with `if($filters['search_custom']`... no need for the double negative
if($filters['search_custom'] !== false) //TODO: duplicated code. We should refactor out a method... this can be replaced with `if($filters['search_custom']`... no need for the double negative
{
$builder = $this->db->table('attribute_links');
$builder->join('attribute_values', 'attribute_links.attribute_id = attribute_values.attribute_id');
@@ -849,10 +903,17 @@ class Item extends Model
return array_unique($suggestions, SORT_REGULAR);
}
/**
* @param string $search
* @param array $filters
* @param bool $unique
* @param int $limit
* @return array
*/
public function get_kit_search_suggestions(string $search, array $filters = ['is_deleted' => false, 'search_custom' => false], bool $unique = false, int $limit = 25): array
{
$suggestions = [];
$non_kit = [ITEM, ITEM_AMOUNT_ENTRY]; //TODO: This variable is never used.
$non_kit = [ITEM, ITEM_AMOUNT_ENTRY]; //TODO: This variable is never used.
$builder = $this->db->table('items');
$builder->select('item_id, name');
@@ -920,14 +981,17 @@ class Item extends Model
foreach($builder->get()->getResult() as $row)
{
$entry = ['value' => $row->item_id, 'label' => $row->name];
if(!array_walk($suggestions, function($value, $label) use ($entry) { return $entry['label'] != $label; } ))
if(!array_walk($suggestions, function ($value, $label) use ($entry)
{
return $entry['label'] != $label;
}))
{
$suggestions[] = $entry;
}
}
//Search in attributes
if($filters['search_custom'] !== false) //TODO: Duplicate code... same as above... no double negatives
if($filters['search_custom'] !== false) //TODO: Duplicate code... same as above... no double negatives
{
$builder = $this->db->table('attribute_links');
$builder->join('attribute_values', 'attribute_links.attribute_id = attribute_values.attribute_id');
@@ -953,6 +1017,10 @@ class Item extends Model
return array_unique($suggestions, SORT_REGULAR);
}
/**
* @param string $search
* @return array
*/
public function get_low_sell_suggestions(string $search): array
{
$suggestions = [];
@@ -972,6 +1040,10 @@ class Item extends Model
return $suggestions;
}
/**
* @param string $search
* @return array
*/
public function get_category_suggestions(string $search): array
{
$suggestions = [];
@@ -991,6 +1063,10 @@ class Item extends Model
return $suggestions;
}
/**
* @param string $search
* @return array
*/
public function get_location_suggestions(string $search): array
{
$suggestions = [];
@@ -1009,7 +1085,10 @@ class Item extends Model
return $suggestions;
}
public function get_categories() //TODO: This function is never called in the code.
/**
* @return ResultInterface|false|string
*/
public function get_categories() //TODO: This function is never called in the code.
{
$builder = $this->db->table('items');
$builder->select('category');
@@ -1055,21 +1134,36 @@ class Item extends Model
return $this->save_value($data, $item_id);
}
/**
* @param int $item_id
* @param string $item_number
* @return void
*/
public function update_item_number(int $item_id, string $item_number): void
{
$builder = $this->db->table('items');
$builder->where('item_id', $item_id);
$builder->update(['item_number' => $item_number]); //TODO: this function should probably return the result of update() and add ": bool" to the function signature
$builder->update(['item_number' => $item_number]); //TODO: this function should probably return the result of update() and add ": bool" to the function signature
}
public function update_item_name(int $item_id, string $item_name): void //TODO: this function should probably return the result of update() and add ": bool" to the function signature
/**
* @param int $item_id
* @param string $item_name
* @return void
*/
public function update_item_name(int $item_id, string $item_name): void //TODO: this function should probably return the result of update() and add ": bool" to the function signature
{
$builder = $this->db->table('items');
$builder->where('item_id', $item_id);
$builder->update(['name' => $item_name]);
}
public function update_item_description(int $item_id, string $item_description): void //TODO: this function should probably return the result of update() and add ": bool" to the function signature
/**
* @param int $item_id
* @param string $item_description
* @return void
*/
public function update_item_description(int $item_id, string $item_description): void //TODO: this function should probably return the result of update() and add ": bool" to the function signature
{
$builder = $this->db->table('items');
$builder->where('item_id', $item_id);
@@ -1081,11 +1175,11 @@ class Item extends Model
* for a multipack environment then the item name should have the
* pack appended to it
*/
function get_item_name(string $as_name = null): string
public function get_item_name(string $as_name = null): string
{
$config = config(OSPOS::class)->settings;
if($as_name == null) //TODO: Replace with ternary notation
if($as_name == null) //TODO: Replace with ternary notation
{
$as_name = '';
}
@@ -1094,7 +1188,7 @@ class Item extends Model
$as_name = ' AS ' . $as_name;
}
if($config['multi_pack_enabled']) //TODO: Replace with ternary notation
if($config['multi_pack_enabled']) //TODO: Replace with ternary notation
{
$item_name = "concat(items.name,'" . NAME_SEPARATOR . '\', items.pack_name)' . $as_name;
}

View File

@@ -209,6 +209,11 @@ class Item_kit extends Model
return $builder->delete();
}
/**
* @param string $search
* @param int $limit
* @return array
*/
public function get_search_suggestions(string $search, int $limit = 25): array
{
$suggestions = [];

View File

@@ -18,7 +18,12 @@ class Item_quantity extends Model
'quantity'
];
public function exists(int $item_id, int $location_id): bool
/**
* @param int $item_id
* @param int $location_id
* @return bool
*/
public function exists(int $item_id, int $location_id): bool
{
$builder = $this->db->table('item_quantities');
$builder->where('item_id', $item_id);
@@ -27,7 +32,13 @@ class Item_quantity extends Model
return ($builder->get()->getNumRows() == 1); //TODO: ===
}
public function save_value(array $location_detail, int $item_id, int $location_id): bool
/**
* @param array $location_detail
* @param int $item_id
* @param int $location_id
* @return bool
*/
public function save_value(array $location_detail, int $item_id, int $location_id): bool
{
if(!$this->exists($item_id, $location_id))
{
@@ -42,7 +53,12 @@ class Item_quantity extends Model
return $builder->update($location_detail);
}
public function get_item_quantity(int $item_id, int $location_id)
/**
* @param int $item_id
* @param int $location_id
* @return array|object|stdClass|null
*/
public function get_item_quantity(int $item_id, int $location_id)
{
$builder = $this->db->table('item_quantities');
$builder->where('item_id', $item_id);

View File

@@ -20,6 +20,10 @@ class Module extends Model
'sort'
];
/**
* @param string $module_id
* @return string
*/
public function get_module_name(string $module_id): string
{
$builder = $this->db->table('modules');
@@ -35,6 +39,10 @@ class Module extends Model
return lang('Errors.unknown');
}
/**
* @param string $module_id
* @return string
*/
public function get_module_desc(string $module_id): string //TODO: This method doesn't seem to be called in the code. Is it needed? Also, probably should change the name to get_module_description()
{
$builder = $this->db->table('modules');
@@ -50,6 +58,9 @@ class Module extends Model
return lang('Errors.unknown');
}
/**
* @return ResultInterface
*/
public function get_all_permissions(): ResultInterface
{
$builder = $this->db->table('permissions');
@@ -57,6 +68,9 @@ class Module extends Model
return $builder->get();
}
/**
* @return ResultInterface
*/
public function get_all_subpermissions(): ResultInterface
{
$builder = $this->db->table('permissions');
@@ -68,6 +82,9 @@ class Module extends Model
return $builder->get();
}
/**
* @return ResultInterface
*/
public function get_all_modules(): ResultInterface
{
$builder = $this->db->table('modules');
@@ -76,6 +93,10 @@ class Module extends Model
return $builder->get();
}
/**
* @param int $person_id
* @return ResultInterface
*/
public function get_allowed_home_modules(int $person_id): ResultInterface
{
$menus = ['home', 'both'];
@@ -90,6 +111,10 @@ class Module extends Model
return $builder->get();
}
/**
* @param int $person_id
* @return ResultInterface
*/
public function get_allowed_office_modules(int $person_id): ResultInterface
{
$menus = ['office', 'both'];

View File

@@ -26,6 +26,10 @@ class Receiving extends Model
'reference'
];
/**
* @param int $receiving_id
* @return ResultInterface
*/
public function get_info(int $receiving_id): ResultInterface
{
$builder = $this->db->table('receivings');
@@ -36,6 +40,10 @@ class Receiving extends Model
return $builder->get();
}
/**
* @param string $reference
* @return ResultInterface
*/
public function get_receiving_by_reference(string $reference): ResultInterface
{
$builder = $this->db->table('receivings');
@@ -44,6 +52,10 @@ class Receiving extends Model
return $builder->get();
}
/**
* @param string $receipt_receiving_id
* @return bool
*/
public function is_valid_receipt(string $receipt_receiving_id): bool //TODO: maybe receipt_receiving_id should be an array rather than a space delimited string
{
if(!empty($receipt_receiving_id))
@@ -64,6 +76,10 @@ class Receiving extends Model
return false;
}
/**
* @param int $receiving_id
* @return bool
*/
public function exists(int $receiving_id): bool
{
$builder = $this->db->table('receivings');
@@ -72,6 +88,11 @@ class Receiving extends Model
return ($builder->get()->getNumRows() == 1);
}
/**
* @param $receiving_id
* @param $receiving_data
* @return bool
*/
public function update($receiving_id = null, $receiving_data = null): bool
{
$builder = $this->db->table('receivings');
@@ -247,6 +268,10 @@ class Receiving extends Model
return $this->db->transStatus();
}
/**
* @param int $receiving_id
* @return ResultInterface
*/
public function get_receiving_items(int $receiving_id): ResultInterface
{
$builder = $this->db->table('receivings_items');
@@ -255,6 +280,10 @@ class Receiving extends Model
return $builder->get();
}
/**
* @param int $receiving_id
* @return object|array|\stdClass|null
*/
public function get_supplier(int $receiving_id): object
{
$builder = $this->db->table('receivings');
@@ -264,6 +293,9 @@ class Receiving extends Model
return $supplier->get_info($builder->get()->getRow()->supplier_id);
}
/**
* @return array
*/
public function get_payment_options(): array
{
return [

View File

@@ -5,13 +5,17 @@ namespace App\Models\Reports;
use App\Models\Receiving;
/**
*
*
*
*
* @property receiving receiving
*
*
*/
class Detailed_receivings extends Report
{
/**
* @param array $inputs
* @return void
*/
public function create(array $inputs): void
{
//Create our temp tables to work with the data in our report
@@ -19,6 +23,9 @@ class Detailed_receivings extends Report
$receiving->create_temp_table($inputs);
}
/**
* @return array
*/
public function getDataColumns(): array
{
return [
@@ -44,6 +51,10 @@ class Detailed_receivings extends Report
];
}
/**
* @param string $receiving_id
* @return array
*/
public function getDataByReceivingId(string $receiving_id): array
{
$builder = $this->db->table('receivings_items_temp');
@@ -66,6 +77,10 @@ class Detailed_receivings extends Report
return $builder->get()->getRowArray();
}
/**
* @param array $inputs
* @return array
*/
public function getData(array $inputs): array
{
$builder = $this->db->table('receivings_items_temp AS receivings_items_temp');
@@ -142,6 +157,10 @@ class Detailed_receivings extends Report
return $data;
}
/**
* @param array $inputs
* @return array
*/
public function getSummaryData(array $inputs): array
{
$builder = $this->db->table('receivings_items_temp');

View File

@@ -12,6 +12,10 @@ use App\Models\Sale;
*/
class Detailed_sales extends Report
{
/**
* @param array $inputs
* @return void
*/
public function create(array $inputs): void
{
//Create our temp tables to work with the data in our report
@@ -19,6 +23,9 @@ class Detailed_sales extends Report
$sale->create_temp_table($inputs);
}
/**
* @return array
*/
public function getDataColumns(): array
{
return [ //TODO: Duplicated code
@@ -57,6 +64,10 @@ class Detailed_sales extends Report
];
}
/**
* @param int $sale_id
* @return array
*/
public function getDataBySaleId(int $sale_id): array
{
$builder = $this->db->table('sales_items_temp');
@@ -78,6 +89,10 @@ class Detailed_sales extends Report
return $builder->get()->getRowArray();
}
/**
* @param array $inputs
* @return array
*/
public function getData(array $inputs): array
{
$builder = $this->db->table('sales_items_temp');
@@ -197,6 +212,10 @@ class Detailed_sales extends Report
return $data;
}
/**
* @param array $inputs
* @return array
*/
public function getSummaryData(array $inputs): array
{
$builder = $this->db->table('sales_items_temp');

View File

@@ -12,6 +12,9 @@ use App\Models\Item;
*/
class Inventory_low extends Report
{
/**
* @return array[]
*/
public function getDataColumns(): array
{
return [
@@ -23,6 +26,10 @@ class Inventory_low extends Report
];
}
/**
* @param array $inputs
* @return array
*/
public function getData(array $inputs): array
{//TODO: we need to see if this can be converted into using QueryBuilder
$item = model(Item::class);
@@ -43,8 +50,12 @@ class Inventory_low extends Report
return $query->getResultArray();
}
/**
* @param array $inputs
* @return array
*/
public function getSummaryData(array $inputs): array
{
return [];
}
}
}

Some files were not shown because too many files have changed in this diff Show More