mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-07-12 07:56:34 -04:00
This cleans up a few more things.
This commit is contained in:
@@ -79,7 +79,7 @@ class Cashup extends Model
|
||||
/**
|
||||
* Searches cashups
|
||||
*/
|
||||
public function search(string $search, array $filters, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'cashup_id', ?string $order = 'asc', ?bool $count_only = FALSE): ResultInterface
|
||||
public function search(string $search, array $filters, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'cashup_id', ?string $order = 'asc', ?bool $count_only = FALSE)
|
||||
{
|
||||
// Set default values
|
||||
if($rows == null) $rows = 0;
|
||||
@@ -215,9 +215,9 @@ class Cashup extends Model
|
||||
/**
|
||||
* Inserts or updates a cashup
|
||||
*/
|
||||
public function save_value(array &$cash_up_data, $cashup_id = NEW_ITEM): bool
|
||||
public function save_value(array &$cash_up_data, $cashup_id = NEW_ENTRY): bool
|
||||
{
|
||||
if(!$cashup_id == NEW_ITEM || !$this->exists($cashup_id))
|
||||
if(!$cashup_id == NEW_ENTRY || !$this->exists($cashup_id))
|
||||
{
|
||||
$builder = $this->db->table('cash_up');
|
||||
if($builder->insert($cash_up_data))
|
||||
|
||||
@@ -123,7 +123,7 @@ class Employee extends Person
|
||||
/**
|
||||
* Inserts or updates an employee
|
||||
*/
|
||||
public function save_employee(array &$person_data, array &$employee_data, array &$grants_data, bool $employee_id = FALSE): bool
|
||||
public function save_employee(array &$person_data, array &$employee_data, array &$grants_data, int $employee_id = NEW_ENTRY): bool
|
||||
{
|
||||
$success = FALSE;
|
||||
|
||||
@@ -133,7 +133,7 @@ class Employee extends Person
|
||||
if(ENVIRONMENT != 'testing' && parent::save_value($person_data, $employee_id))
|
||||
{
|
||||
$builder = $this->db->table('employees');
|
||||
if(!$employee_id || !$this->exists($employee_id))
|
||||
if($employee_id == NEW_ENTRY || !$this->exists($employee_id))
|
||||
{
|
||||
$employee_data['person_id'] = $employee_id = $person_data['person_id'];
|
||||
$success = $builder->insert($employee_data);
|
||||
@@ -335,7 +335,7 @@ class Employee extends Person
|
||||
/**
|
||||
* Performs a search on employees
|
||||
*/
|
||||
public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'last_name', ?string $order = 'asc', ?bool $count_only = FALSE): ResultInterface
|
||||
public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'last_name', ?string $order = 'asc', ?bool $count_only = FALSE)
|
||||
{
|
||||
// Set default values
|
||||
if($rows == null) $rows = 0;
|
||||
|
||||
@@ -87,7 +87,7 @@ class Expense extends Model
|
||||
/**
|
||||
* Searches expenses
|
||||
*/
|
||||
public function search(string $search, array $filters, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'expense_id', ?string $order = 'asc', ?bool $count_only = FALSE): ResultInterface
|
||||
public function search(string $search, array $filters, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'expense_id', ?string $order = 'asc', ?bool $count_only = FALSE)
|
||||
{
|
||||
// Set default values
|
||||
if($rows == null) $rows = 0;
|
||||
@@ -227,35 +227,56 @@ class Expense extends Model
|
||||
|
||||
$query = $builder->get();
|
||||
|
||||
if($query->getNumRows() == 1) //TODO: ===
|
||||
if ($query->getNumRows() == 1) //TODO: ===
|
||||
{
|
||||
return $query->getRow();
|
||||
}
|
||||
else //TODO: No need for this else statement. Just put it's contents outside of the else since the if has a return in it.
|
||||
{
|
||||
//Get empty base parent object
|
||||
$expenses_obj = new stdClass();
|
||||
|
||||
//Get all the fields from expenses table
|
||||
foreach($this->db->getFieldNames('expenses') as $field)
|
||||
$empty_obj = $this->getEmptyObject('expenses');
|
||||
$empty_obj->supplier_name = NULL;
|
||||
$empty_obj->first_name = NULL;
|
||||
$empty_obj->last_name = NULL;
|
||||
|
||||
return $empty_obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes an empty object based on database definitions
|
||||
* @param string $table_name
|
||||
* @return object
|
||||
*/
|
||||
private function getEmptyObject(string $table_name): object
|
||||
{
|
||||
// Return an empty base parent object, as $item_id is NOT an item
|
||||
$empty_obj = new stdClass();
|
||||
|
||||
// Iterate through field definitions to determine how the fields should be initialized
|
||||
|
||||
foreach($this->db->getFieldData($table_name) as $field) {
|
||||
|
||||
$field_name = $field->name;
|
||||
|
||||
if(in_array($field->type, array('int', 'tinyint', 'decimal')))
|
||||
{
|
||||
$expenses_obj->$field = '';
|
||||
$empty_obj->$field_name = ($field->primary_key == 1) ? NEW_ENTRY : 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
$empty_obj->$field_name = NULL;
|
||||
}
|
||||
|
||||
$expenses_obj->supplier_name = '';
|
||||
|
||||
return $expenses_obj;
|
||||
}
|
||||
|
||||
return $empty_obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts or updates an expense
|
||||
*/
|
||||
public function save_value(array &$expense_data, bool $expense_id = FALSE): bool
|
||||
public function save_value(array &$expense_data, int $expense_id = NEW_ENTRY): bool
|
||||
{
|
||||
$builder = $this->db->table('expenses');
|
||||
|
||||
if(!$expense_id || !$this->exists($expense_id))
|
||||
if($expense_id == NEW_ENTRY || !$this->exists($expense_id))
|
||||
{
|
||||
if($builder->insert($expense_data))
|
||||
{
|
||||
|
||||
@@ -109,11 +109,11 @@ class Expense_category extends Model
|
||||
/**
|
||||
* Inserts or updates an expense_category
|
||||
*/
|
||||
public function save_value(array &$expense_category_data, bool $expense_category_id = FALSE): bool
|
||||
public function save_value(array &$expense_category_data, int $expense_category_id = NEW_ENTRY): bool
|
||||
{
|
||||
$builder = $this->db->table('expense_categories');
|
||||
|
||||
if(!$expense_category_id || !$this->exists($expense_category_id))
|
||||
if($expense_category_id == NEW_ENTRY || !$this->exists($expense_category_id))
|
||||
{
|
||||
if($builder->insert($expense_category_data))
|
||||
{
|
||||
@@ -152,7 +152,7 @@ class Expense_category extends Model
|
||||
/**
|
||||
* Perform a search on expense_category
|
||||
*/
|
||||
public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'category_name', ?string $order='asc', ?bool $count_only = FALSE): ResultInterface
|
||||
public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'category_name', ?string $order='asc', ?bool $count_only = FALSE)
|
||||
{
|
||||
// Set default values
|
||||
if($rows == null) $rows = 0;
|
||||
|
||||
@@ -126,11 +126,11 @@ class Giftcard extends Model
|
||||
/**
|
||||
* Inserts or updates a giftcard
|
||||
*/
|
||||
public function save_value(array &$giftcard_data, $giftcard_id = FALSE): bool
|
||||
public function save_value(array &$giftcard_data, int $giftcard_id = NEW_ENTRY): bool
|
||||
{
|
||||
$builder = $this->db->table('giftcards');
|
||||
|
||||
if(!$giftcard_id || !$this->exists($giftcard_id))
|
||||
if($giftcard_id == NEW_ENTRY || !$this->exists($giftcard_id))
|
||||
{
|
||||
if($builder->insert($giftcard_data))
|
||||
{
|
||||
@@ -233,7 +233,7 @@ class Giftcard extends Model
|
||||
/**
|
||||
* Performs a search on giftcards
|
||||
*/
|
||||
public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'giftcard_number', ?string $order = 'asc', ?bool $count_only = FALSE): ResultInterface
|
||||
public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'giftcard_number', ?string $order = 'asc', ?bool $count_only = FALSE)
|
||||
{
|
||||
// Set default values
|
||||
if($rows == null) $rows = 0;
|
||||
|
||||
@@ -167,10 +167,10 @@ class Item_kit extends Model
|
||||
/**
|
||||
* Inserts or updates an item kit
|
||||
*/
|
||||
public function save_value(array &$item_kit_data, bool $item_kit_id = FALSE): bool
|
||||
public function save_value(array &$item_kit_data, int $item_kit_id = NEW_ENTRY): bool
|
||||
{
|
||||
$builder = $this->db->table('item_kits');
|
||||
if(!$item_kit_id || !$this->exists($item_kit_id))
|
||||
if($item_kit_id == NEW_ENTRY || !$this->exists($item_kit_id))
|
||||
{
|
||||
if($builder->insert($item_kit_data))
|
||||
{
|
||||
@@ -257,7 +257,7 @@ class Item_kit extends Model
|
||||
/**
|
||||
* Perform a search on items
|
||||
*/
|
||||
public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'name', ?string $order = 'asc', ?bool $count_only = FALSE): ResultInterface
|
||||
public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'name', ?string $order = 'asc', ?bool $count_only = FALSE)
|
||||
{
|
||||
// Set default values
|
||||
if($rows == null) $rows = 0;
|
||||
@@ -271,7 +271,7 @@ class Item_kit extends Model
|
||||
// get_found_rows case
|
||||
if($count_only)
|
||||
{
|
||||
$builder->select('COUNT(item_kits.item_kit_id) as count');
|
||||
$builder->select('COUNT(item_kit_id) as count');
|
||||
}
|
||||
|
||||
$builder->like('name', $search);
|
||||
|
||||
@@ -88,7 +88,7 @@ class Receiving extends Model
|
||||
/**
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function save_value(array $items, int $supplier_id, int $employee_id, string $comment, string $reference, string $payment_type, bool $receiving_id = FALSE): int //TODO: $receiving_id gets overwritten before it's evaluated. It doesn't make sense to pass this here.
|
||||
public function save_value(array $items, int $supplier_id, int $employee_id, string $comment, string $reference, string $payment_type, int $receiving_id = NEW_ENTRY): int //TODO: $receiving_id gets overwritten before it's evaluated. It doesn't make sense to pass this here.
|
||||
{
|
||||
$attribute = model(Attribute::class);
|
||||
$inventory = model('Inventory');
|
||||
|
||||
@@ -126,7 +126,7 @@ class Sale extends Model
|
||||
/**
|
||||
* Get the sales data for the takings (sales/manage) view
|
||||
*/
|
||||
public function search(string $search, array $filters, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'sales.sale_time', ?string $order = 'desc', ?bool $count_only = FALSE): ResultInterface
|
||||
public function search(string $search, array $filters, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'sales.sale_time', ?string $order = 'desc', ?bool $count_only = FALSE)
|
||||
{
|
||||
// Set default values
|
||||
if($rows == null) $rows = 0;
|
||||
|
||||
@@ -110,7 +110,7 @@ class Supplier extends Person
|
||||
/**
|
||||
* Inserts or updates a suppliers
|
||||
*/
|
||||
public function save_supplier(array &$person_data, array &$supplier_data, bool $supplier_id = FALSE): bool
|
||||
public function save_supplier(array &$person_data, array &$supplier_data, int $supplier_id = NEW_ENTRY): bool
|
||||
{
|
||||
$success = FALSE;
|
||||
|
||||
@@ -120,7 +120,7 @@ class Supplier extends Person
|
||||
if(parent::save_value($person_data,$supplier_id))
|
||||
{
|
||||
$builder = $this->db->table('suppliers');
|
||||
if(!$supplier_id || !$this->exists($supplier_id))
|
||||
if($supplier_id == NEW_ENTRY || !$this->exists($supplier_id))
|
||||
{
|
||||
$supplier_data['person_id'] = $person_data['person_id'];
|
||||
$success = $builder->insert($supplier_data);
|
||||
@@ -263,7 +263,7 @@ class Supplier extends Person
|
||||
/**
|
||||
* Perform a search on suppliers
|
||||
*/
|
||||
public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'last_name', ?string $order = 'asc', ?bool $count_only = FALSE): ResultInterface
|
||||
public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'last_name', ?string $order = 'asc', ?bool $count_only = FALSE)
|
||||
{
|
||||
// Set default values
|
||||
if($rows == null) $rows = 0;
|
||||
|
||||
@@ -166,7 +166,7 @@ class Tax extends Model
|
||||
public function save_value(array &$tax_rate_data, int $tax_rate_id = NEW_ENTRY): bool
|
||||
{
|
||||
$builder = $this->db->table('tax_rates');
|
||||
if(!$this->exists($tax_rate_id))
|
||||
if($tax_rate_id == NEW_ENTRY || !$this->exists($tax_rate_id))
|
||||
{
|
||||
if($builder->insert($tax_rate_data))
|
||||
{
|
||||
@@ -220,7 +220,7 @@ class Tax extends Model
|
||||
/**
|
||||
* Performs a search on tax_rates
|
||||
*/
|
||||
public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'tax_code_name', ?string $order = 'asc', ?bool $count_only = FALSE): ResultInterface
|
||||
public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'tax_code_name', ?string $order = 'asc', ?bool $count_only = FALSE)
|
||||
{
|
||||
// Set default values
|
||||
if($rows == null) $rows = 0;
|
||||
|
||||
@@ -109,11 +109,11 @@ class Tax_category extends Model
|
||||
/**
|
||||
* Inserts or updates a row
|
||||
*/
|
||||
public function save_value(array &$tax_category_data, bool $tax_category_id = FALSE): bool
|
||||
public function save_value(array &$tax_category_data, int $tax_category_id = NEW_ENTRY): bool
|
||||
{
|
||||
$builder = $this->db->table('tax_categories');
|
||||
|
||||
if(!$tax_category_id || !$this->exists($tax_category_id))
|
||||
if($tax_category_id == NEW_ENTRY || !$this->exists($tax_category_id))
|
||||
{
|
||||
if($builder->insert($tax_category_data))
|
||||
{
|
||||
@@ -208,7 +208,7 @@ class Tax_category extends Model
|
||||
/**
|
||||
* Perform a search for a set of rows
|
||||
*/
|
||||
public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'tax_category', ?string $order = 'asc', ?bool $count_only = FALSE): ResultInterface
|
||||
public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'tax_category', ?string $order = 'asc', ?bool $count_only = FALSE)
|
||||
{
|
||||
// Set default values
|
||||
if($rows == null) $rows = 0;
|
||||
|
||||
@@ -202,7 +202,7 @@ class Tax_code extends Model
|
||||
/**
|
||||
* Perform a search for a set of rows
|
||||
*/
|
||||
public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'tax_code_name', ?string $order = 'asc', ?bool $count_only = FALSE): ResultInterface
|
||||
public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'tax_code_name', ?string $order = 'asc', ?bool $count_only = FALSE)
|
||||
{
|
||||
// Set default values
|
||||
if($rows == null) $rows = 0;
|
||||
|
||||
@@ -113,10 +113,10 @@ class Tax_jurisdiction extends Model
|
||||
/**
|
||||
* Inserts or updates a row
|
||||
*/
|
||||
public function save_value(array &$jurisdiction_data, bool $jurisdiction_id = FALSE): bool
|
||||
public function save_value(array &$jurisdiction_data, int $jurisdiction_id = NEW_ENTRY): bool
|
||||
{
|
||||
$builder = $this->db->table('tax_jurisdictions');
|
||||
if(!$jurisdiction_id || !$this->exists($jurisdiction_id))
|
||||
if($jurisdiction_id == NEW_ENTRY || !$this->exists($jurisdiction_id))
|
||||
{
|
||||
if($builder->insert($jurisdiction_data)) //TODO: Replace this with simply a return of the result of insert()... see update() below.
|
||||
{
|
||||
@@ -213,7 +213,7 @@ class Tax_jurisdiction extends Model
|
||||
/**
|
||||
* Perform a search for a set of rows
|
||||
*/
|
||||
public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'jurisdiction_name', ?string $order = 'asc', ?bool $count_only = FALSE): ResultInterface
|
||||
public function search(string $search, ?int $rows = 0, ?int $limit_from = 0, ?string $sort = 'jurisdiction_name', ?string $order = 'asc', ?bool $count_only = FALSE)
|
||||
{
|
||||
// Set default values
|
||||
if($rows == null) $rows = 0;
|
||||
|
||||
Reference in New Issue
Block a user