From 006ee224352bbf6a2b71fe3037bc3c20935c5e51 Mon Sep 17 00:00:00 2001 From: FrancescoUK Date: Sun, 7 Oct 2018 15:45:20 +0100 Subject: [PATCH] Add Supplier Category (#2088) --- application/controllers/Suppliers.php | 6 +++- application/helpers/tabular_helper.php | 2 ++ application/language/en-GB/suppliers_lang.php | 3 ++ application/language/en-US/suppliers_lang.php | 3 ++ ...hp => 20181007120000_upgrade_to_3_3_0.php} | 0 .../migrations/sqlscripts/3.2.1_to_3.3.0.sql | 11 +++++- application/models/Supplier.php | 36 +++++++++++++++++-- application/views/suppliers/form.php | 7 ++++ 8 files changed, 63 insertions(+), 5 deletions(-) rename application/migrations/{20181003120000_upgrade_to_3_3_0.php => 20181007120000_upgrade_to_3_3_0.php} (100%) diff --git a/application/controllers/Suppliers.php b/application/controllers/Suppliers.php index b07218866..44ba50821 100644 --- a/application/controllers/Suppliers.php +++ b/application/controllers/Suppliers.php @@ -43,7 +43,9 @@ class Suppliers extends Persons $data_rows = array(); foreach($suppliers->result() as $supplier) { - $data_rows[] = $this->xss_clean(get_supplier_data_row($supplier)); + $row = $this->xss_clean(get_supplier_data_row($supplier)); + $row['category'] = $this->Supplier->get_category_name($row['category']); + $data_rows[] = $row; } echo json_encode(array('total' => $total_rows, 'rows' => $data_rows)); @@ -77,6 +79,7 @@ class Suppliers extends Persons $info->$property = $this->xss_clean($value); } $data['person_info'] = $info; + $data['categories'] = $this->Supplier->get_categories(); $this->load->view("suppliers/form", $data); } @@ -112,6 +115,7 @@ class Suppliers extends Persons $supplier_data = array( 'company_name' => $this->input->post('company_name'), 'agency_name' => $this->input->post('agency_name'), + 'category' => $this->input->post('category'), 'account_number' => $this->input->post('account_number') == '' ? NULL : $this->input->post('account_number') ); diff --git a/application/helpers/tabular_helper.php b/application/helpers/tabular_helper.php index 1a791403a..770037081 100644 --- a/application/helpers/tabular_helper.php +++ b/application/helpers/tabular_helper.php @@ -274,6 +274,7 @@ function get_suppliers_manage_table_headers() array('people.person_id' => $CI->lang->line('common_id')), array('company_name' => $CI->lang->line('suppliers_company_name')), array('agency_name' => $CI->lang->line('suppliers_agency_name')), + array('category' => $CI->lang->line('suppliers_category')), array('last_name' => $CI->lang->line('common_last_name')), array('first_name' => $CI->lang->line('common_first_name')), array('email' => $CI->lang->line('common_email')), @@ -300,6 +301,7 @@ function get_supplier_data_row($supplier) 'people.person_id' => $supplier->person_id, 'company_name' => $supplier->company_name, 'agency_name' => $supplier->agency_name, + 'category' => $supplier->category, 'last_name' => $supplier->last_name, 'first_name' => $supplier->first_name, 'email' => empty($supplier->email) ? '' : mailto($supplier->email, $supplier->email), diff --git a/application/language/en-GB/suppliers_lang.php b/application/language/en-GB/suppliers_lang.php index 1c9a1f051..c44c09b81 100644 --- a/application/language/en-GB/suppliers_lang.php +++ b/application/language/en-GB/suppliers_lang.php @@ -3,11 +3,14 @@ $lang["suppliers_account_number"] = "Account #"; $lang["suppliers_agency_name"] = "Agency Name"; $lang["suppliers_cannot_be_deleted"] = "Could not delete the selected Supplier(s). One or more have Sales"; +$lang["suppliers_category"] = "Category"; +$lang["suppliers_cost"] = "Cost Supplier"; $lang["suppliers_company_name"] = "Company Name"; $lang["suppliers_company_name_required"] = "Company Name is a required field"; $lang["suppliers_confirm_delete"] = "Are you sure you want to delete the selected Supplier(s)?"; $lang["suppliers_confirm_restore"] = "Are you sure you want to restore the selected Supplier(s)?"; $lang["suppliers_error_adding_updating"] = "Supplier update or add failed"; +$lang["suppliers_goods"] = "Goods Supplier"; $lang["suppliers_new"] = "New Supplier"; $lang["suppliers_none_selected"] = "You have not selected any Supplier(s) to delete"; $lang["suppliers_one_or_multiple"] = "Supplier(s)"; diff --git a/application/language/en-US/suppliers_lang.php b/application/language/en-US/suppliers_lang.php index 8e62cf7ca..58c3ab55d 100644 --- a/application/language/en-US/suppliers_lang.php +++ b/application/language/en-US/suppliers_lang.php @@ -3,11 +3,14 @@ $lang["suppliers_account_number"] = "Account Number"; $lang["suppliers_agency_name"] = "Agency Name"; $lang["suppliers_cannot_be_deleted"] = "Could not delete selected Supplier(s). One or more have Sales."; +$lang["suppliers_category"] = "Category"; +$lang["suppliers_cost"] = "Cost Supplier"; $lang["suppliers_company_name"] = "Company Name"; $lang["suppliers_company_name_required"] = "Company Name is a required field."; $lang["suppliers_confirm_delete"] = "Are you sure you want to delete the selected Supplier(s)?"; $lang["suppliers_confirm_restore"] = "Are you sure you want to restore selected Supplier(s)?"; $lang["suppliers_error_adding_updating"] = "Supplier update or add failed."; +$lang["suppliers_goods"] = "Goods Supplier"; $lang["suppliers_new"] = "New Supplier"; $lang["suppliers_none_selected"] = "You have not selected Supplier(s) to delete."; $lang["suppliers_one_or_multiple"] = "Supplier(s)"; diff --git a/application/migrations/20181003120000_upgrade_to_3_3_0.php b/application/migrations/20181007120000_upgrade_to_3_3_0.php similarity index 100% rename from application/migrations/20181003120000_upgrade_to_3_3_0.php rename to application/migrations/20181007120000_upgrade_to_3_3_0.php diff --git a/application/migrations/sqlscripts/3.2.1_to_3.3.0.sql b/application/migrations/sqlscripts/3.2.1_to_3.3.0.sql index 1a1591e16..4f4b01154 100644 --- a/application/migrations/sqlscripts/3.2.1_to_3.3.0.sql +++ b/application/migrations/sqlscripts/3.2.1_to_3.3.0.sql @@ -37,7 +37,6 @@ ALTER TABLE `ospos_receivings_items` CHANGE COLUMN `discount_percent` `discount` DECIMAL(15,2) NOT NULL DEFAULT 0 AFTER `item_unit_price`, ADD COLUMN `discount_type` TINYINT(2) NOT NULL DEFAULT '0' AFTER `discount`; - -- -- Add support for module cashups -- @@ -102,3 +101,13 @@ ALTER TABLE ospos_expenses CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci ALTER TABLE `ospos_cash_up` ADD `closed_amount_due` decimal(15,2) NOT NULL; + +-- +-- Add Suppliers category +-- + +ALTER TABLE `ospos_suppliers` + ADD COLUMN `category` TINYINT NOT NULL; + +UPDATE `ospos_suppliers` + SET `category` = 0; diff --git a/application/models/Supplier.php b/application/models/Supplier.php index 5d9b728fe..05ef4d458 100644 --- a/application/models/Supplier.php +++ b/application/models/Supplier.php @@ -5,7 +5,10 @@ */ class Supplier extends Person -{ +{ + const GOODS_SUPPLIER = 0; + const COST_SUPPLIER = 1; + /* Determines if a given person_id is a customer */ @@ -32,10 +35,11 @@ class Supplier extends Person /* Returns all the suppliers */ - public function get_all($limit_from = 0, $rows = 0) + public function get_all($category = self::GOODS_SUPPLIER, $limit_from = 0, $rows = 0) { $this->db->from('suppliers'); - $this->db->join('people', 'suppliers.person_id = people.person_id'); + $this->db->join('people', 'suppliers.person_id = people.person_id'); + $this->db->where('category', $category); $this->db->where('deleted', 0); $this->db->order_by('company_name', 'asc'); if($rows > 0) @@ -273,5 +277,31 @@ class Supplier extends Person return $this->db->get(); } + + /* + Return supplier categories + */ + public function get_categories() + { + return array( + self::GOODS_SUPPLIER => $this->lang->line('suppliers_goods'), + self::COST_SUPPLIER => $this->lang->line('suppliers_cost') + ); + } + + /* + Return a category name given its id + */ + public function get_category_name($id) + { + if($id == self::GOODS_SUPPLIER) + { + return $this->lang->line('suppliers_goods'); + } + elseif($id == self::COST_SUPPLIER) + { + return $this->lang->line('suppliers_cost'); + } + } } ?> diff --git a/application/views/suppliers/form.php b/application/views/suppliers/form.php index ab610072d..b38697efb 100644 --- a/application/views/suppliers/form.php +++ b/application/views/suppliers/form.php @@ -16,6 +16,13 @@ +
+ lang->line('suppliers_category'), 'category', array('class'=>'required control-label col-xs-3')); ?> +
+ category, array('class'=>'form-control', 'id'=>'category'));?> +
+
+
lang->line('suppliers_agency_name'), 'agency_name', array('class'=>'control-label col-xs-3')); ?>