From 02d7588e59a08f52db9004aec5fbd1d4c88117ec Mon Sep 17 00:00:00 2001 From: jekkos Date: Thu, 10 Jan 2019 19:19:04 +0100 Subject: [PATCH] Add config item for default order discount --- application/controllers/Config.php | 2 ++ application/controllers/Receivings.php | 7 +++-- application/controllers/Sales.php | 8 +----- application/language/en-GB/config_lang.php | 5 +++- application/language/en-US/common_lang.php | 2 +- application/language/en-US/config_lang.php | 5 +++- application/language/nl-BE/config_lang.php | 5 +++- application/libraries/Receiving_lib.php | 10 +++---- .../migrations/sqlscripts/3.2.1_to_3.3.0.sql | 12 +++++--- application/views/configs/general_config.php | 28 +++++++++++++++++++ 10 files changed, 61 insertions(+), 23 deletions(-) diff --git a/application/controllers/Config.php b/application/controllers/Config.php index 8a7e91f4f..4dd1f8cae 100644 --- a/application/controllers/Config.php +++ b/application/controllers/Config.php @@ -276,6 +276,8 @@ class Config extends Secure_Controller 'theme' => $this->input->post('theme'), 'default_sales_discount_type' => $this->input->post('default_sales_discount_type') != NULL, 'default_sales_discount' => $this->input->post('default_sales_discount'), + 'default_receivings_discount_type' => $this->input->post('default_receivings_discount_type') != NULL, + 'default_receivings_discount' => $this->input->post('default_receivings_discount'), 'enforce_privacy' => $this->input->post('enforce_privacy'), 'receiving_calculate_average_price' => $this->input->post('receiving_calculate_average_price') != NULL, 'lines_per_page' => $this->input->post('lines_per_page'), diff --git a/application/controllers/Receivings.php b/application/controllers/Receivings.php index 10eec315a..7872eff29 100644 --- a/application/controllers/Receivings.php +++ b/application/controllers/Receivings.php @@ -93,7 +93,8 @@ class Receivings extends Secure_Controller $this->barcode_lib->parse_barcode_fields($quantity, $item_id_or_number_or_item_kit_or_receipt); $quantity = ($mode == 'receive' || $mode == 'requisition') ? $quantity : -$quantity; $item_location = $this->receiving_lib->get_stock_source(); - $discount_type = $this->config->item('default_sales_discount_type'); + $discount = $this->config->item('default_receivings_discount'); + $discount_type = $this->config->item('default_receivings_discount_type'); if($mode == 'return' && $this->Receiving->is_valid_receipt($item_id_or_number_or_item_kit_or_receipt)) { @@ -101,9 +102,9 @@ class Receivings extends Secure_Controller } elseif($this->Item_kit->is_valid_item_kit($item_id_or_number_or_item_kit_or_receipt)) { - $this->receiving_lib->add_item_kit($item_id_or_number_or_item_kit_or_receipt, $item_location, $discount_type); + $this->receiving_lib->add_item_kit($item_id_or_number_or_item_kit_or_receipt, $item_location, $discount, $discount_type); } - elseif(!$this->receiving_lib->add_item($item_id_or_number_or_item_kit_or_receipt, $quantity, $item_location, $discount_type)) + elseif(!$this->receiving_lib->add_item($item_id_or_number_or_item_kit_or_receipt, $quantity, $item_location, $discount, $discount_type)) { $data['error'] = $this->lang->line('receivings_unable_to_add_item'); } diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index 19fb36873..731991390 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -367,7 +367,7 @@ class Sales extends Secure_Controller { $data = array(); - $discount = 0.0; + $discount = $this->config->item('default_sales_discount'); $discount_type = $this->config->item('default_sales_discount_type'); // check if any discount is assigned to the selected customer @@ -384,12 +384,6 @@ class Sales extends Secure_Controller } } - // if the customer discount is 0 or no customer is selected apply the default sales discount - if($discount == 0) - { - $discount = $this->config->item('default_sales_discount'); - } - $item_id_or_number_or_item_kit_or_receipt = $this->input->post('item'); $this->barcode_lib->parse_barcode_fields($quantity, $item_id_or_number_or_item_kit_or_receipt); $mode = $this->sale_lib->get_mode(); diff --git a/application/language/en-GB/config_lang.php b/application/language/en-GB/config_lang.php index d367425cc..3ed2bee2a 100644 --- a/application/language/en-GB/config_lang.php +++ b/application/language/en-GB/config_lang.php @@ -68,7 +68,10 @@ $lang["config_default_barcode_width_number"] = "Default Barcode Width must be a $lang["config_default_barcode_width_required"] = "Default Barcode Width is a required field"; $lang["config_default_item_columns"] = "Default Visible Item Columns"; $lang["config_default_origin_tax_code"] = "Default Origin Tax Code"; -$lang["config_default_sales_discount"] = "Default Sales Discount %"; +$lang["config_default_receivings_discount"] = "Default Receivings Discount"; +$lang["config_default_receivings_discount_number"] = "Default Receivings Discount must be a number"; +$lang["config_default_receivings_discount_required"] = "Default Receivings Discount is a required field"; +$lang["config_default_sales_discount"] = "Default Sales Discount"; $lang["config_default_sales_discount_number"] = "Default Sales Discount must be a number"; $lang["config_default_sales_discount_required"] = "Default Sales Discount is a required field"; $lang["config_default_tax_category"] = "Default Tax Category"; diff --git a/application/language/en-US/common_lang.php b/application/language/en-US/common_lang.php index d88c26d58..c6e36926e 100644 --- a/application/language/en-US/common_lang.php +++ b/application/language/en-US/common_lang.php @@ -42,7 +42,7 @@ $lang["common_logout"] = "Logout"; $lang["common_migration_needed"] = "A database migration to %1 will start after login."; $lang["common_new"] = "New"; $lang["common_no_persons_to_display"] = "There are no people to display."; -$lang["common_none_selected_text"] = "[Select]"; +$lang["common_none_selected_text"] = "Nothing selected"; $lang["common_or"] = "OR"; $lang["common_phone_number"] = "Phone Number"; $lang["common_phone_number_required"] = ""; diff --git a/application/language/en-US/config_lang.php b/application/language/en-US/config_lang.php index 32a1b7cb1..d21c10978 100644 --- a/application/language/en-US/config_lang.php +++ b/application/language/en-US/config_lang.php @@ -69,7 +69,10 @@ $lang["config_default_barcode_width_number"] = "Default Barcode Width must be a $lang["config_default_barcode_width_required"] = "Default Barcode Width is a required field."; $lang["config_default_item_columns"] = "Default Visible Item Columns"; $lang["config_default_origin_tax_code"] = "Default Origin Tax Code"; -$lang["config_default_sales_discount"] = "Default Sales Discount %"; +$lang["config_default_receivings_discount"] = "Default Receivings Discount"; +$lang["config_default_receivings_discount_number"] = "Default Receivings Discount must be a number."; +$lang["config_default_receivings_discount_required"] = "Default Receivings Discount is a required field."; +$lang["config_default_sales_discount"] = "Default Sales Discount"; $lang["config_default_sales_discount_number"] = "Default Sales Discount must be a number."; $lang["config_default_sales_discount_required"] = "Default Sales Discount is a required field."; $lang["config_default_tax_category"] = "Default Tax Category"; diff --git a/application/language/nl-BE/config_lang.php b/application/language/nl-BE/config_lang.php index 8c211347c..36f3ed26e 100755 --- a/application/language/nl-BE/config_lang.php +++ b/application/language/nl-BE/config_lang.php @@ -68,7 +68,10 @@ $lang["config_default_barcode_width_number"] = "De breedte van de barcode moet e $lang["config_default_barcode_width_required"] = "De breedte van de barcode is een verplicht veld."; $lang["config_default_item_columns"] = "Standaard Zichtbaarheid Kolommen"; $lang["config_default_origin_tax_code"] = "Standaard VAT code"; -$lang["config_default_sales_discount"] = "Standaard Korting %"; +$lang["config_default_receivings_discount"] = "Standaard Korting Orders"; +$lang["config_default_receivings_discount_number"] = "De korting moet een getal zijn."; +$lang["config_default_receivings_discount_required"] = "De korting is een verplicht veld."; +$lang["config_default_sales_discount"] = "Standaard Korting Verkoop"; $lang["config_default_sales_discount_number"] = "De korting moet een getal zijn."; $lang["config_default_sales_discount_required"] = "De korting is een verplicht veld."; $lang["config_default_tax_category"] = "Standaard Tax Categorie"; diff --git a/application/libraries/Receiving_lib.php b/application/libraries/Receiving_lib.php index 132bb6d35..a7982d6c3 100644 --- a/application/libraries/Receiving_lib.php +++ b/application/libraries/Receiving_lib.php @@ -159,7 +159,7 @@ class Receiving_lib $this->CI->session->unset_userdata('recv_stock_destination'); } - public function add_item($item_id, $quantity = 1, $item_location = NULL, $discount_type = 0, $discount = 0, $price = NULL, $description = NULL, $serialnumber = NULL, $receiving_quantity = NULL, $receiving_id = NULL, $include_deleted = FALSE) + public function add_item($item_id, $quantity = 1, $item_location = NULL, $discount = 0, $discount_type = 0, $price = NULL, $description = NULL, $serialnumber = NULL, $receiving_quantity = NULL, $receiving_id = NULL, $include_deleted = FALSE) { //make sure item exists in database. if(!$this->CI->Item->exists($item_id, $include_deleted)) @@ -320,13 +320,13 @@ class Receiving_lib foreach($this->CI->Receiving->get_receiving_items($receiving_id)->result() as $row) { - $this->add_item($row->item_id, -$row->quantity_purchased, $row->item_location, $row->discount_type, $row->discount, $row->item_unit_price, $row->description, $row->serialnumber, $receiving_id, $row->receiving_quantity, TRUE); + $this->add_item($row->item_id, -$row->quantity_purchased, $row->item_location, $row->discount, $row->discount_type, $row->item_unit_price, $row->description, $row->serialnumber, $receiving_id, $row->receiving_quantity, TRUE); } $this->set_supplier($this->CI->Receiving->get_supplier($receiving_id)->person_id); } - public function add_item_kit($external_item_kit_id, $item_location, $discount_type) + public function add_item_kit($external_item_kit_id, $item_location, $discount, $discount_type) { //KIT # $pieces = explode(' ',$external_item_kit_id); @@ -334,7 +334,7 @@ class Receiving_lib foreach($this->CI->Item_kit_items->get_info($item_kit_id) as $item_kit_item) { - $this->add_item($item_kit_item['item_id'],$item_kit_item['quantity'], $item_location, $discount_type); + $this->add_item($item_kit_item['item_id'], $item_kit_item['quantity'], $item_location, $discount, $discount_type); } } @@ -345,7 +345,7 @@ class Receiving_lib foreach($this->CI->Receiving->get_receiving_items($receiving_id)->result() as $row) { - $this->add_item($row->item_id, $row->quantity_purchased, $row->item_location, $row->discount_type, $row->discount, $row->item_unit_price, $row->description, $row->serialnumber, $row->receiving_quantity, $receiving_id, TRUE); + $this->add_item($row->item_id, $row->quantity_purchased, $row->item_location, $row->discount, $row->discount_type, $row->item_unit_price, $row->description, $row->serialnumber, $row->receiving_quantity, $receiving_id, TRUE); } $this->set_supplier($this->CI->Receiving->get_supplier($receiving_id)->person_id); 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 313f25291..e99727b23 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 @@ -132,15 +132,19 @@ SET `ospos_expenses`.`supplier_id` = `ospos_suppliers`.`person_id`; -- Save name in description for those expenses whose supplier isn't registered UPDATE `ospos_expenses` -SET `description` = CONCAT(`description`, CONCAT('\nSupplier name: ', `supplier_name`)) -WHERE `supplier_id` is NULL; + SET `description` = CONCAT(`description`, CONCAT('\nSupplier name: ', `supplier_name`)) + WHERE `supplier_id` is NULL; -- Add foreign key ALTER TABLE `ospos_expenses` -ADD CONSTRAINT `ospos_expenses_ibfk_3` FOREIGN KEY (`supplier_id`) REFERENCES `ospos_suppliers` (`person_id`); + ADD CONSTRAINT `ospos_expenses_ibfk_3` FOREIGN KEY (`supplier_id`) REFERENCES `ospos_suppliers` (`person_id`); -- Delete supplier name ALTER TABLE `ospos_expenses` -DROP COLUMN `supplier_name`; + DROP COLUMN `supplier_name`; + +INSERT INTO `ospos_app_config` (`key`, `value`) VALUES + ('default_receivings_discount_type', '0'), + ('default_receivings_discount', '0'); diff --git a/application/views/configs/general_config.php b/application/views/configs/general_config.php index 598bec6c8..e84edcfc7 100644 --- a/application/views/configs/general_config.php +++ b/application/views/configs/general_config.php @@ -39,6 +39,34 @@ +
+ lang->line('config_default_receivings_discount'), 'default_receivings_discount', array('class' => 'control-label col-xs-2 required')); ?> +
+
+ 'default_receivings_discount', + 'id' => 'default_receivings_discount', + 'class' => 'form-control input-sm required', + 'type' => 'number', + 'min' => 0, + 'max' => 100, + 'value' => $this->config->item('default_receivings_discount'))); ?> + + 'default_receivings_discount_type', + 'name' => 'default_receivings_discount_type', + 'value' => 1, + 'data-toggle' => 'toggle', + 'data-size' => 'normal', + 'data-onstyle' => 'success', + 'data-on' => ''.$this->config->item('currency_symbol').'', + 'data-off' => '%', + 'checked' => $this->config->item('default_receivings_discount_type'))); ?> + +
+
+
+
lang->line('config_enforce_privacy'), 'enforce_privacy', array('class' => 'control-label col-xs-2')); ?>