From dd3b7330d3afa61dd0bc5388928c6a0ed6b0698d Mon Sep 17 00:00:00 2001 From: objecttothis Date: Sun, 26 Feb 2023 00:56:33 +0400 Subject: [PATCH] Added protected fields for CI4 models - primary table - primary key - useAutoIncrement - useSoftDeletes --- app/Models/Appconfig.php | 4 ++++ app/Models/Attribute.php | 6 +++++- app/Models/Cashup.php | 4 ++++ app/Models/Customer.php | 4 ++++ app/Models/Customer_rewards.php | 4 ++++ app/Models/Dinner_table.php | 4 ++++ app/Models/Employee.php | 4 ++++ app/Models/Expense.php | 4 ++++ app/Models/Expense_category.php | 4 ++++ app/Models/Giftcard.php | 4 ++++ app/Models/Inventory.php | 4 ++++ app/Models/Item.php | 4 ++++ app/Models/Item_kit.php | 4 ++++ app/Models/Item_kit_items.php | 4 ++++ app/Models/Item_quantity.php | 4 ++++ app/Models/Item_taxes.php | 4 ++++ app/Models/Module.php | 4 ++++ app/Models/Person.php | 4 ++++ app/Models/Receiving.php | 4 ++++ app/Models/Rewards.php | 4 ++++ app/Models/Sale.php | 4 ++++ app/Models/Stock_location.php | 4 ++++ app/Models/Supplier.php | 4 ++++ app/Models/Tax.php | 4 ++++ app/Models/Tax_category.php | 4 ++++ app/Models/Tax_code.php | 4 ++++ app/Models/Tax_jurisdiction.php | 4 ++++ 27 files changed, 109 insertions(+), 1 deletion(-) diff --git a/app/Models/Appconfig.php b/app/Models/Appconfig.php index 1e65f93c2..d59b26a68 100644 --- a/app/Models/Appconfig.php +++ b/app/Models/Appconfig.php @@ -15,6 +15,10 @@ use ReflectionException; */ class Appconfig extends Model { + protected $table = 'app_config'; + protected $primaryKey = 'key'; + protected $useAutoIncrement = false; + protected $useSoftDeletes = false; protected $allowedFields = [ 'key', 'value' diff --git a/app/Models/Attribute.php b/app/Models/Attribute.php index 8e39f7e57..38d12ea10 100644 --- a/app/Models/Attribute.php +++ b/app/Models/Attribute.php @@ -13,7 +13,11 @@ use ReflectionClass; */ class Attribute extends Model { - protected $allowedFields = [ //TODO: This model may not be well designed... The model accesses three different tables (attribute_definitions, attribute_links, attribute_values). Should that be more than one model? + protected $table = 'attribute_definitions'; + protected $primaryKey = 'definition_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; + protected $allowedFields = [ //TODO: This model may not be well designed... The model accesses three different tables (attribute_definitions, attribute_links, attribute_values). Should that be more than one model? According to CodeIgniter, these are meant to model a single table https://codeigniter.com/user_guide/models/model.html#models 'definition_name', 'definition_type', 'definition_unit', diff --git a/app/Models/Cashup.php b/app/Models/Cashup.php index cf6c44021..3dc3ba351 100644 --- a/app/Models/Cashup.php +++ b/app/Models/Cashup.php @@ -14,6 +14,10 @@ use stdClass; class Cashup extends Model { + protected $table = 'cash_up'; + protected $primaryKey = 'cashup_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; protected $allowedFields = [ 'open_date', 'close_date', diff --git a/app/Models/Customer.php b/app/Models/Customer.php index 77dc3ca25..629a2deec 100644 --- a/app/Models/Customer.php +++ b/app/Models/Customer.php @@ -9,6 +9,10 @@ use CodeIgniter\Database\ResultInterface; */ class Customer extends Person { + protected $table = 'customers'; + protected $primaryKey = 'person_id'; + protected $useAutoIncrement = false; + protected $useSoftDeletes = false; protected $allowedFields = [ 'account_number', 'taxable', diff --git a/app/Models/Customer_rewards.php b/app/Models/Customer_rewards.php index 4c2e57ee8..a68415a59 100644 --- a/app/Models/Customer_rewards.php +++ b/app/Models/Customer_rewards.php @@ -10,6 +10,10 @@ use CodeIgniter\Model; */ class Customer_rewards extends Model { + protected $table = 'customer_packages'; + protected $primaryKey = 'package_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; protected $allowedFields = [ 'package_name', 'points_percent', diff --git a/app/Models/Dinner_table.php b/app/Models/Dinner_table.php index d76c0e6f8..5715cf28e 100644 --- a/app/Models/Dinner_table.php +++ b/app/Models/Dinner_table.php @@ -10,6 +10,10 @@ use CodeIgniter\Model; */ class Dinner_table extends Model { + protected $table = 'dinner_tables'; + protected $primaryKey = 'dinner_table_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; protected $allowedFields = [ 'name', 'status', diff --git a/app/Models/Employee.php b/app/Models/Employee.php index df6aa4e3d..4e7cf35e1 100644 --- a/app/Models/Employee.php +++ b/app/Models/Employee.php @@ -14,6 +14,10 @@ use CodeIgniter\Session\Session; */ class Employee extends Person { + protected $table = 'Employees'; + protected $primaryKey = 'person_id'; + protected $useAutoIncrement = false; + protected $useSoftDeletes = false; protected $allowedFields = [ 'username', 'password', diff --git a/app/Models/Expense.php b/app/Models/Expense.php index 725228e2f..b11a69f93 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -14,6 +14,10 @@ use stdClass; */ class Expense extends Model { + protected $table = 'expenses'; + protected $primaryKey = 'expense_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; protected $allowedFields = [ 'date', 'amount', diff --git a/app/Models/Expense_category.php b/app/Models/Expense_category.php index 2ee23d944..1ddd7011a 100644 --- a/app/Models/Expense_category.php +++ b/app/Models/Expense_category.php @@ -11,6 +11,10 @@ use stdClass; */ class Expense_category extends Model { + protected $table = 'expense_categories'; + protected $primaryKey = 'expense_category_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; protected $allowedFields = [ 'category_name', 'category_description', diff --git a/app/Models/Giftcard.php b/app/Models/Giftcard.php index e3c356be9..f5075b097 100644 --- a/app/Models/Giftcard.php +++ b/app/Models/Giftcard.php @@ -11,6 +11,10 @@ use stdClass; */ class Giftcard extends Model { + protected $table = 'giftcards'; + protected $primaryKey = 'giftcard_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; protected $allowedFields = [ 'giftcard_number', 'value', diff --git a/app/Models/Inventory.php b/app/Models/Inventory.php index 2cd2bb039..03845db8a 100644 --- a/app/Models/Inventory.php +++ b/app/Models/Inventory.php @@ -14,6 +14,10 @@ use ReflectionException; */ class Inventory extends Model { + protected $table = 'inventory'; + protected $primaryKey = 'trans_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; protected $allowedFields = [ 'trans_items', 'trans_user', diff --git a/app/Models/Item.php b/app/Models/Item.php index d090e61a3..954e33ab0 100644 --- a/app/Models/Item.php +++ b/app/Models/Item.php @@ -15,6 +15,10 @@ use stdClass; */ class Item extends Model { + protected $table = 'items'; + protected $primaryKey = 'item_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; protected $allowedFields = [ 'name', 'category', diff --git a/app/Models/Item_kit.php b/app/Models/Item_kit.php index 4a5abaca3..a7df759c0 100644 --- a/app/Models/Item_kit.php +++ b/app/Models/Item_kit.php @@ -11,6 +11,10 @@ use stdClass; */ class Item_kit extends Model { + protected $table = 'item_kits'; + protected $primaryKey = 'item_kit_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; protected $allowedFields = [ 'item_kit_number', 'name', diff --git a/app/Models/Item_kit_items.php b/app/Models/Item_kit_items.php index ba608d835..13fcb0c88 100644 --- a/app/Models/Item_kit_items.php +++ b/app/Models/Item_kit_items.php @@ -9,6 +9,10 @@ use CodeIgniter\Model; */ class Item_kit_items extends Model { + protected $table = 'item_kit_items'; + protected $primaryKey = 'item_kit_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; protected $allowedFields = [ 'kit_sequence' ]; diff --git a/app/Models/Item_quantity.php b/app/Models/Item_quantity.php index ba1738506..9775f2c6a 100644 --- a/app/Models/Item_quantity.php +++ b/app/Models/Item_quantity.php @@ -10,6 +10,10 @@ use stdClass; */ class Item_quantity extends Model { + protected $table = 'item_quantities'; + protected $primaryKey = 'item_id'; + protected $useAutoIncrement = false; + protected $useSoftDeletes = false; protected $allowedFields = [ 'quantity' ]; diff --git a/app/Models/Item_taxes.php b/app/Models/Item_taxes.php index 5b9f7dd03..3a5acc9c3 100644 --- a/app/Models/Item_taxes.php +++ b/app/Models/Item_taxes.php @@ -9,6 +9,10 @@ use CodeIgniter\Model; */ class Item_taxes extends Model { + protected $table = 'item_taxes'; + protected $primaryKey = 'item_id'; + protected $useAutoIncrement = false; + protected $useSoftDeletes = false; protected $allowedFields = [ 'name', 'percent' diff --git a/app/Models/Module.php b/app/Models/Module.php index f9a769088..bbc2fd4ba 100644 --- a/app/Models/Module.php +++ b/app/Models/Module.php @@ -10,6 +10,10 @@ use CodeIgniter\Model; */ class Module extends Model { + protected $table = 'modules'; + protected $primaryKey = 'module_id'; + protected $useAutoIncrement = false; + protected $useSoftDeletes = false; protected $allowedFields = [ 'name_lang_key', 'desc_lang_key', diff --git a/app/Models/Person.php b/app/Models/Person.php index 5790867a1..007924604 100644 --- a/app/Models/Person.php +++ b/app/Models/Person.php @@ -11,6 +11,10 @@ use stdClass; */ class Person extends Model { + protected $table = 'people'; + protected $primaryKey = 'person_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; protected $allowedFields = [ 'first_name', 'last_name', diff --git a/app/Models/Receiving.php b/app/Models/Receiving.php index 2ab37697e..af8618673 100644 --- a/app/Models/Receiving.php +++ b/app/Models/Receiving.php @@ -17,6 +17,10 @@ use ReflectionException; */ class Receiving extends Model { + protected $table = 'receivings'; + protected $primaryKey = 'receiving_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; protected $allowedFields = [ 'receiving_time', 'supplier_id', diff --git a/app/Models/Rewards.php b/app/Models/Rewards.php index 4b7b6df75..0afbee8ee 100644 --- a/app/Models/Rewards.php +++ b/app/Models/Rewards.php @@ -10,6 +10,10 @@ use CodeIgniter\Model; class Rewards extends Model //TODO: This class is named with plural while the general practice is to name models singular { + protected $table = 'sales_reward_points'; + protected $primaryKey = 'id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; protected $allowedFields = [ 'sale_id', 'earned', diff --git a/app/Models/Sale.php b/app/Models/Sale.php index 649170ba1..c716a546d 100644 --- a/app/Models/Sale.php +++ b/app/Models/Sale.php @@ -25,6 +25,10 @@ use ReflectionException; */ class Sale extends Model { + protected $table = 'sales'; + protected $primaryKey = 'sale_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; protected $allowedFields = [ 'sale_time', 'customer_id', diff --git a/app/Models/Stock_location.php b/app/Models/Stock_location.php index 0f47622f9..67d5c7e17 100644 --- a/app/Models/Stock_location.php +++ b/app/Models/Stock_location.php @@ -16,6 +16,10 @@ use CodeIgniter\Session\Session; */ class Stock_location extends Model { + protected $table = 'stock_locations'; + protected $primaryKey = 'location_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; protected $allowedFields = [ 'location_name', 'deleted' diff --git a/app/Models/Supplier.php b/app/Models/Supplier.php index 212c0538f..cdc9e1451 100644 --- a/app/Models/Supplier.php +++ b/app/Models/Supplier.php @@ -9,6 +9,10 @@ use CodeIgniter\Database\ResultInterface; */ class Supplier extends Person { + protected $table = 'suppliers'; + protected $primaryKey = 'person_id'; + protected $useAutoIncrement = false; + protected $useSoftDeletes = false; protected $allowedFields = [ 'company_name', 'account_number', diff --git a/app/Models/Tax.php b/app/Models/Tax.php index e4a45355d..cc124a064 100644 --- a/app/Models/Tax.php +++ b/app/Models/Tax.php @@ -11,6 +11,10 @@ use stdClass; */ class Tax extends Model { + protected $table = 'tax_rates'; + protected $primaryKey = 'tax_rate_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; protected $allowedFields = [ 'rate_tax_code_id', 'rate_tax_category_id', diff --git a/app/Models/Tax_category.php b/app/Models/Tax_category.php index 3699b2096..da8a49352 100644 --- a/app/Models/Tax_category.php +++ b/app/Models/Tax_category.php @@ -12,6 +12,10 @@ use stdClass; class Tax_category extends Model { + protected $table = 'tax_categories'; + protected $primaryKey = 'tax_category_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; protected $allowedFields = [ 'tax_category', 'tax_group_sequence', diff --git a/app/Models/Tax_code.php b/app/Models/Tax_code.php index 2af0ae4ac..37c6773d0 100644 --- a/app/Models/Tax_code.php +++ b/app/Models/Tax_code.php @@ -11,6 +11,10 @@ use stdClass; */ class Tax_code extends Model { + protected $table = 'tax_codes'; + protected $primaryKey = 'tax_code_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; protected $allowedFields = [ 'tax_code', 'tax_code_name', diff --git a/app/Models/Tax_jurisdiction.php b/app/Models/Tax_jurisdiction.php index 5662a3d0d..aa93c77b9 100644 --- a/app/Models/Tax_jurisdiction.php +++ b/app/Models/Tax_jurisdiction.php @@ -12,6 +12,10 @@ use stdClass; class Tax_jurisdiction extends Model { + protected $table = 'tax_jurisdictions'; + protected $primaryKey = 'cashup_id'; + protected $useAutoIncrement = true; + protected $useSoftDeletes = false; protected $allowedFields = [ 'jurisdiction_name', 'tax_group',