mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-07-11 07:26:18 -04:00
Bulk Model changes.
This commit is contained in:
@@ -215,9 +215,9 @@ class Cashup extends Model
|
||||
/**
|
||||
* Inserts or updates a cashup
|
||||
*/
|
||||
public function save_value(array &$cash_up_data, $cashup_id = FALSE): bool
|
||||
public function save_value(array &$cash_up_data, $cashup_id = NEW_ITEM): bool
|
||||
{
|
||||
if(!$cashup_id == -1 || !$this->exists($cashup_id)) //TODO: Replace -1 with constant
|
||||
if(!$cashup_id == NEW_ITEM || !$this->exists($cashup_id))
|
||||
{
|
||||
$builder = $this->db->table('cash_up');
|
||||
if($builder->insert($cash_up_data))
|
||||
|
||||
@@ -95,13 +95,13 @@ class Employee extends Person
|
||||
}
|
||||
|
||||
//Get empty base parent object, as $employee_id is NOT an employee
|
||||
$person_obj = parent::get_info(-1); //TODO: Replace -1 with a constant
|
||||
$person_obj = parent::get_info(NEW_ITEM);
|
||||
|
||||
//Get all the fields from employee table
|
||||
//append those fields to base parent object, we have a complete empty object
|
||||
foreach($this->db->getFieldNames('employees') as $field)
|
||||
{
|
||||
$person_obj->$field = '';
|
||||
$person_obj->$field = null;
|
||||
}
|
||||
|
||||
return $person_obj;
|
||||
|
||||
@@ -280,11 +280,11 @@ class Item extends Model
|
||||
/**
|
||||
* Returns all the items
|
||||
*/
|
||||
public function get_all(int $stock_location_id = -1, int $rows = 0, int $limit_from = 0): ResultInterface //TODO: Replace -1 with a constant
|
||||
public function get_all(int $stock_location_id = NEW_ENTRY, int $rows = 0, int $limit_from = 0): ResultInterface
|
||||
{
|
||||
$builder = $this->db->table('items');
|
||||
|
||||
if($stock_location_id > -1) //TODO: Replace -1 with a constant
|
||||
if($stock_location_id > -1)
|
||||
{
|
||||
$builder->join('item_quantities', 'item_quantities.item_id = items.item_id');
|
||||
$builder->where('location_id', $stock_location_id);
|
||||
@@ -438,7 +438,7 @@ class Item extends Model
|
||||
if($builder->insert($item_data))
|
||||
{
|
||||
$item_data['item_id'] = $this->db->insertID();
|
||||
if($item_data['low_sell_item_id'] == -1) //TODO: Replace -1 with a constant... === ?
|
||||
if($item_data['low_sell_item_id'] == NEW_ENTRY)
|
||||
{
|
||||
$builder = $this->db->table('items');
|
||||
$builder->where('item_id', $item_data['item_id']);
|
||||
|
||||
@@ -592,7 +592,7 @@ class Sale extends Model
|
||||
$cash_adjustment = $payment['cash_adjustment'];
|
||||
$employee_id = $payment['employee_id'];
|
||||
|
||||
if($payment_id == -1 && $payment_amount != 0)
|
||||
if($payment_id == NEW_ENTRY && $payment_amount != 0)
|
||||
{
|
||||
// Add a new payment transaction
|
||||
$sales_payments_data = [
|
||||
@@ -605,7 +605,7 @@ class Sale extends Model
|
||||
];
|
||||
$success = $builder->insert($sales_payments_data);
|
||||
}
|
||||
elseif($payment_id != -1)
|
||||
elseif($payment_id != NEW_ENTRY)
|
||||
{
|
||||
if($payment_amount != 0)
|
||||
{
|
||||
@@ -651,7 +651,7 @@ class Sale extends Model
|
||||
$item = model(Item::class);
|
||||
$item_quantity = model(Item_quantity::class);
|
||||
|
||||
if($sale_id != -1)
|
||||
if($sale_id != NEW_ENTRY)
|
||||
{
|
||||
$this->clear_suspended_sale_detail($sale_id);
|
||||
}
|
||||
@@ -681,7 +681,7 @@ class Sale extends Model
|
||||
|
||||
$builder = $this->db->table('sales');
|
||||
|
||||
if($sale_id == -1) //TODO: I think we have a constant for this and the -1 needs to be replaced with the constant in constants.php... something like NEW_SALE
|
||||
if($sale_id == NEW_ENTRY)
|
||||
{
|
||||
$builder->insert($sales_data);
|
||||
$sale_id = $this->db->insertID();
|
||||
@@ -795,7 +795,7 @@ class Sale extends Model
|
||||
$attribute->copy_attribute_links($item_data['item_id'], 'sale_id', $sale_id);
|
||||
}
|
||||
|
||||
if($customer_id == -1 || $customer->taxable) //TODO: Need a NEW_CUSTOMER constant in constants.php instead of -1
|
||||
if($customer_id == NEW_ENTRY || $customer->taxable)
|
||||
{
|
||||
$this->save_sales_tax($sale_id, $sales_taxes[0]);
|
||||
$this->save_sales_items_taxes($sale_id, $sales_taxes[1]);
|
||||
@@ -1341,7 +1341,7 @@ class Sale extends Model
|
||||
*/
|
||||
public function get_all_suspended(int $customer_id = NULL): array
|
||||
{
|
||||
if($customer_id == -1) //TODO: This should be converted to a global constant and stored in constants.php
|
||||
if($customer_id == NEW_ENTRY)
|
||||
{
|
||||
$query = $this->db->query("SELECT sale_id, case when sale_type = '".SALE_TYPE_QUOTE."' THEN quote_number WHEN sale_type = '".SALE_TYPE_WORK_ORDER."' THEN work_order_number else sale_id end as doc_id, sale_id as suspended_sale_id, sale_status, sale_time, dinner_table_id, customer_id, employee_id, comment FROM "
|
||||
. $this->db->prefixTable('sales') . ' where sale_status = ' . SUSPENDED);
|
||||
@@ -1360,7 +1360,7 @@ class Sale extends Model
|
||||
*/
|
||||
public function get_dinner_table(int $sale_id) //TODO: this is returning NULL or the table_id. We can keep it this way but multiple return types can't be declared until PHP 8.x
|
||||
{
|
||||
if($sale_id == -1)
|
||||
if($sale_id == NEW_ENTRY)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class Stock_location extends Model
|
||||
|
||||
$this->session = session();
|
||||
}
|
||||
public function exists(int $location_id = -1): bool //TODO: Replace -1 with a constant
|
||||
public function exists(int $location_id = NEW_ENTRY): bool
|
||||
{
|
||||
$builder = $this->db->table('stock_locations');
|
||||
$builder->where('location_id', $location_id);
|
||||
|
||||
@@ -81,7 +81,7 @@ class Supplier extends Person
|
||||
else
|
||||
{
|
||||
//Get empty base parent object, as $supplier_id is NOT a supplier
|
||||
$person_obj = parent::get_info(-1); //TODO: need to replace with a constant instead of -1
|
||||
$person_obj = parent::get_info(NEW_ENTRY);
|
||||
|
||||
//Get all the fields from supplier table
|
||||
//append those fields to base parent object, we have a complete empty object
|
||||
|
||||
@@ -163,7 +163,7 @@ class Tax extends Model
|
||||
/**
|
||||
Inserts or updates a tax_rates entry
|
||||
*/
|
||||
public function save_value(array &$tax_rate_data, int $tax_rate_id = -1): bool //TODO: the default value for $tax_rate_id should be made a constant and replaced here.
|
||||
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))
|
||||
|
||||
@@ -150,7 +150,7 @@ class Tax_category extends Model
|
||||
|
||||
$this->save_value($tax_category_data, $value['tax_category_id']);
|
||||
|
||||
if($value['tax_category_id'] == -1) //TODO: -1 should be converted into a constant for code readability. Perhaps NO_TAX_CATEGORY?
|
||||
if($value['tax_category_id'] == NEW_ENTRY)
|
||||
{
|
||||
$not_to_delete[] = $tax_category_data['tax_category_id'];
|
||||
}
|
||||
@@ -270,7 +270,7 @@ class Tax_category extends Model
|
||||
{
|
||||
return [
|
||||
'0' => [
|
||||
'tax_category_id' => -1, //TODO: This should probably be a Constant instead of -1
|
||||
'tax_category_id' => NEW_ENTRY,
|
||||
'tax_category' => '',
|
||||
'tax_group_sequence' => '',
|
||||
'deleted' => ''
|
||||
|
||||
@@ -313,7 +313,7 @@ class Tax_code extends Model
|
||||
{
|
||||
return [
|
||||
'0' => [
|
||||
'tax_code_id' => -1,
|
||||
'tax_code_id' => NEW_ENTRY,
|
||||
'tax_code' => '',
|
||||
'tax_code_name' => '',
|
||||
'city' => '',
|
||||
|
||||
@@ -155,7 +155,7 @@ class Tax_jurisdiction extends Model
|
||||
|
||||
$this->save_value($tax_jurisdiction_data, $value['jurisdiction_id']);
|
||||
|
||||
if($value['jurisdiction_id'] == -1) //TODO: replace -1 with a constant. Also === ?. Also replace this with ternary notation.
|
||||
if($value['jurisdiction_id'] == NEW_ENTRY)
|
||||
{
|
||||
$not_to_delete[] = $tax_jurisdiction_data['jurisdiction_id'];
|
||||
}
|
||||
@@ -256,7 +256,7 @@ class Tax_jurisdiction extends Model
|
||||
{
|
||||
return [
|
||||
'0' => [
|
||||
'jurisdiction_id' => -1, //TODO: Replace -1 with a constant
|
||||
'jurisdiction_id' => NEW_ENTRY,
|
||||
'jurisdiction_name' => '',
|
||||
'tax_group' => '',
|
||||
'tax_type' => '1',
|
||||
|
||||
@@ -34,7 +34,7 @@ class Token_customer extends Token
|
||||
{
|
||||
//substitute customer info
|
||||
$customer_id = $this->sale_lib->get_customer();
|
||||
if($customer_id != -1 && empty($this->customer_info)) //TODO: Replace -1 with a Constant
|
||||
if($customer_id != NEW_ITEM && empty($this->customer_info))
|
||||
{
|
||||
$customer = model(Customer::class);
|
||||
$customer_info = $customer->get_info($customer_id);
|
||||
|
||||
Reference in New Issue
Block a user