From 0147c3a80e7332debb4980d2de292480fb8ff213 Mon Sep 17 00:00:00 2001 From: Steve Ireland Date: Sun, 23 May 2021 18:30:31 -0400 Subject: [PATCH] Fix Discounted Item Kit bug #3129 (#3186) --- application/controllers/Sales.php | 11 +++- application/language/en-US/sales_lang.php | 2 +- application/language/es/sales_lang.php | 2 +- application/language/es_MX/sales_lang.php | 2 +- application/language/id/sales_lang.php | 2 +- application/language/ta/sales_lang.php | 2 +- application/language/uk-UA/sales_lang.php | 2 +- application/libraries/Sale_lib.php | 66 +++++++++++++---------- 8 files changed, 52 insertions(+), 37 deletions(-) diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index 7c0c891ad..2bdf80a90 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -418,7 +418,14 @@ class Sales extends Secure_Controller $kit_price_option = $item_kit_info->price_option; $kit_print_option = $item_kit_info->print_option; // 0-all, 1-priced, 2-kit-only - if($item_kit_info->kit_discount != 0 && $item_kit_info->kit_discount > $discount) + if($discount_type == $item_kit_info->kit_discount_type) + { + if($item_kit_info->kit_discount > $discount) + { + $discount = $item_kit_info->kit_discount; + } + } + else { $discount = $item_kit_info->kit_discount; $discount_type = $item_kit_info->kit_discount_type; @@ -428,7 +435,7 @@ class Sales extends Secure_Controller if(!empty($kit_item_id)) { - if(!$this->sale_lib->add_item($kit_item_id, $quantity, $item_location, $discount, $discount_type, PRICE_MODE_STANDARD, NULL, NULL, $price)) + if(!$this->sale_lib->add_item($kit_item_id, $quantity, $item_location, $discount, $discount_type, PRICE_MODE_KIT, $kit_price_option, $kit_print_option, $price)) { $data['error'] = $this->lang->line('sales_unable_to_add_item'); } diff --git a/application/language/en-US/sales_lang.php b/application/language/en-US/sales_lang.php index 51d41a53a..5ed65553c 100644 --- a/application/language/en-US/sales_lang.php +++ b/application/language/en-US/sales_lang.php @@ -161,7 +161,7 @@ $lang["sales_tax"] = "Tax"; $lang["sales_tax_id"] = "Tax Id"; $lang["sales_tax_invoice"] = "Tax Invoice"; $lang["sales_tax_percent"] = "Tax %"; -$lang["sales_taxed_ind"] = "Sales tax ind"; +$lang["sales_taxed_ind"] = "T"; $lang["sales_total"] = "Total"; $lang["sales_total_tax_exclusive"] = "Tax excluded"; $lang["sales_transaction_failed"] = "Sales Transaction failed."; diff --git a/application/language/es/sales_lang.php b/application/language/es/sales_lang.php index 4e3ddc9f3..3f4663914 100644 --- a/application/language/es/sales_lang.php +++ b/application/language/es/sales_lang.php @@ -161,7 +161,7 @@ $lang["sales_tax"] = "Imp"; $lang["sales_tax_id"] = "Identificador del Impuesto"; $lang["sales_tax_invoice"] = "Impuesto de la Factura"; $lang["sales_tax_percent"] = "% de Imp"; -$lang["sales_taxed_ind"] = "Ventas gravadas"; +$lang["sales_taxed_ind"] = "I"; $lang["sales_total"] = "Total"; $lang["sales_total_tax_exclusive"] = "Sin impuesto"; $lang["sales_transaction_failed"] = "La transacción de venta falló."; diff --git a/application/language/es_MX/sales_lang.php b/application/language/es_MX/sales_lang.php index d9a0b1016..3420dcc74 100644 --- a/application/language/es_MX/sales_lang.php +++ b/application/language/es_MX/sales_lang.php @@ -161,7 +161,7 @@ $lang["sales_tax"] = "Impuestos"; $lang["sales_tax_id"] = "ID Impuesto"; $lang["sales_tax_invoice"] = "Impuesto de la factura"; $lang["sales_tax_percent"] = "Impuesto %"; -$lang["sales_taxed_ind"] = "Ventas con impuestos"; +$lang["sales_taxed_ind"] = "I"; $lang["sales_total"] = "Total"; $lang["sales_total_tax_exclusive"] = "Sin impuesto"; $lang["sales_transaction_failed"] = "Ha fallado la venta."; diff --git a/application/language/id/sales_lang.php b/application/language/id/sales_lang.php index 9782da82a..8e3e835c1 100644 --- a/application/language/id/sales_lang.php +++ b/application/language/id/sales_lang.php @@ -160,7 +160,7 @@ $lang["sales_tax"] = "Pajak"; $lang["sales_tax_id"] = "ID Pajak"; $lang["sales_tax_invoice"] = "Faktur Pajak"; $lang["sales_tax_percent"] = "Pajak %"; -$lang["sales_taxed_ind"] = "Ind pajak penjualan"; +$lang["sales_taxed_ind"] = "P"; $lang["sales_total"] = "Total"; $lang["sales_total_tax_exclusive"] = "Tidak termasuk pajak"; $lang["sales_transaction_failed"] = "Transaksi Penjualan gagal."; diff --git a/application/language/ta/sales_lang.php b/application/language/ta/sales_lang.php index a7d4cfba9..88a3063b3 100644 --- a/application/language/ta/sales_lang.php +++ b/application/language/ta/sales_lang.php @@ -161,7 +161,7 @@ $lang["sales_tax"] = "Tax"; $lang["sales_tax_id"] = "Tax Id"; $lang["sales_tax_invoice"] = "Tax Invoice"; $lang["sales_tax_percent"] = "Tax %"; -$lang["sales_taxed_ind"] = "விற்பனை வரி குறியீடு"; +$lang["sales_taxed_ind"] = "வ"; $lang["sales_total"] = "Total"; $lang["sales_total_tax_exclusive"] = "Tax excluded"; $lang["sales_transaction_failed"] = "Sales Transaction failed."; diff --git a/application/language/uk-UA/sales_lang.php b/application/language/uk-UA/sales_lang.php index 6630ab85c..702d0ef1c 100644 --- a/application/language/uk-UA/sales_lang.php +++ b/application/language/uk-UA/sales_lang.php @@ -130,7 +130,7 @@ $lang["sales_sale_by_invoice"] = "Продаж за рахунком"; $lang["sales_sale_for_customer"] = "Клієнт:"; $lang["sales_sale_time"] = "Час продажу"; $lang["sales_sales_tax"] = "Податок з продажів"; -$lang["sales_taxed_ind"] = "Ідентифікатор оподаткування"; +$lang["sales_taxed_ind"] = "П"; $lang["sales_select_customer"] = "Оберіть клієнта"; $lang["sales_send_invoice"] = "Відправити рахунок-фактуру"; $lang["sales_send_quote"] = "Надіслати котирвання продажів"; diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index 2fde857fc..80a5ef993 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -743,7 +743,7 @@ class Sale_lib $this->CI->session->unset_userdata('sales_rewards_remainder'); } - public function add_item(&$item_id, $quantity = 1, $item_location, $discount = 0.0, $discount_type = 0, $price_mode = PRICE_MODE_STANDARD, $kit_price_option = NULL, $kit_print_option = NULL, $price_override = NULL, $description = NULL, $serialnumber = NULL, $sale_id = NULL, $include_deleted = FALSE, $print_option = NULL, $line = NULL) + public function add_item(&$item_id, $quantity = 1, $item_location, &$discount = 0.0, $discount_type = 0, $price_mode = PRICE_MODE_STANDARD, $kit_price_option = NULL, $kit_print_option = NULL, $price_override = NULL, $description = NULL, $serialnumber = NULL, $sale_id = NULL, $include_deleted = FALSE, $print_option = NULL, $line = NULL) { $item_info = $this->CI->Item->get_info_by_id_or_number($item_id, $include_deleted); //make sure item exists @@ -753,40 +753,47 @@ class Sale_lib return FALSE; } - $cost_price = 0.00; + $applied_discount = $discount; $item_id = $item_info->item_id; $item_type = $item_info->item_type; $stock_type = $item_info->stock_type; - if($price_mode == PRICE_MODE_STANDARD) - { - $price = $item_info->unit_price; - $cost_price = $item_info->cost_price; - } - elseif($price_mode == PRICE_MODE_KIT) - { - if($kit_price_option == PRICE_OPTION_ALL) - { - $price = $item_info->unit_price; - $cost_price = $item_info->cost_price; - } - elseif($kit_price_option == PRICE_OPTION_KIT && $item_type == ITEM_KIT) - { - $price = $item_info->unit_price; - $cost_price = $item_info->cost_price; - } - elseif($kit_price_option == PRICE_OPTION_KIT_STOCK && $stock_type == HAS_STOCK) - { - $price = $item_info->unit_price; - $cost_price = $item_info->cost_price; - } - } - + $price = $item_info->unit_price; + $cost_price = $item_info->cost_price; if($price_override != NULL) { $price = $price_override; } + if($price_mode == PRICE_MODE_KIT) + { + if(!($kit_price_option == PRICE_OPTION_ALL + || $kit_price_option == PRICE_OPTION_KIT && $item_type == ITEM_KIT + || $kit_price_option == PRICE_OPTION_KIT_STOCK && $stock_type == HAS_STOCK)) + { + $price = 0.00; + $applied_discount = 0.00; + } + // If price is zero do not include a discount regardless of type + if($price == 0.00) + { + $applied_discount = 0.00; + } + // If fixed discount then apply no more than the item price + if($discount_type == FIXED) + { + if($applied_discount > $price) + { + $applied_discount = $price; + $discount -= $applied_discount; + } + else + { + $discount = 0; + } + } + } + // Serialization and Description //Get all items in the cart so far... @@ -857,8 +864,8 @@ class Sale_lib } } - $total = $this->get_item_total($quantity, $price, $discount, $discount_type); - $discounted_total = $this->get_item_total($quantity, $price, $discount, $discount_type, TRUE); + $total = $this->get_item_total($quantity, $price, $applied_discount, $discount_type); + $discounted_total = $this->get_item_total($quantity, $price, $applied_discount, $discount_type, TRUE); if($this->CI->config->item('multi_pack_enabled') == '1') { @@ -884,7 +891,7 @@ class Sale_lib 'allow_alt_description' => $item_info->allow_alt_description, 'is_serialized' => $item_info->is_serialized, 'quantity' => $quantity, - 'discount' => $discount, + 'discount' => $applied_discount, 'discount_type' => $discount_type, 'in_stock' => $this->CI->Item_quantity->get_item_quantity($item_id, $item_location)->quantity, 'price' => $price, @@ -1034,6 +1041,7 @@ class Sale_lib $pieces = explode(' ', $external_item_kit_id); $item_kit_id = (count($pieces) > 1) ? $pieces[1] : $external_item_kit_id; $result = TRUE; + $applied_discount = $discount; foreach($this->CI->Item_kit_items->get_info($item_kit_id) as $item_kit_item) {