From 85bbbe835c1a5580bd166d8833602c8df0ae7c15 Mon Sep 17 00:00:00 2001 From: Erastus Date: Mon, 20 Aug 2018 13:41:56 -0500 Subject: [PATCH 01/10] Discount on Sales --- application/config/config.php | 2 +- application/config/routes.php | 1 + application/controllers/Config.php | 2 + application/controllers/Customers.php | 4 +- application/controllers/Item_kits.php | 5 +- application/controllers/Receivings.php | 13 +-- application/controllers/Reports.php | 40 ++++++--- application/controllers/Sales.php | 39 +++++++-- application/language/en-US/sales_lang.php | 2 +- application/language/es/config_lang.php | 1 + application/language/es/reports_lang.php | 2 + application/language/es/sales_lang.php | 2 +- application/libraries/Receiving_lib.php | 36 +++++--- application/libraries/Sale_lib.php | 83 ++++++++++++------- .../20180820100000_upgrade_to_3_4_0.php | 20 +++++ .../migrations/sqlscripts/3.3.0_to_3.4.0.sql | 22 +++++ application/models/Item_kit.php | 1 + application/models/Receiving.php | 9 +- application/models/Sale.php | 11 ++- .../models/reports/Detailed_receivings.php | 2 +- application/models/reports/Detailed_sales.php | 2 +- .../models/reports/Specific_customer.php | 2 +- .../models/reports/Specific_discount.php | 16 +++- .../models/reports/Specific_employee.php | 2 +- .../models/reports/Summary_discounts.php | 18 ++-- .../models/reports/Summary_payments.php | 2 +- application/models/reports/Summary_report.php | 2 +- application/views/configs/general_config.php | 23 +++++ application/views/customers/form.php | 15 ++++ application/views/item_kits/form.php | 15 ++++ application/views/partial/header.php | 6 +- application/views/receivings/receipt.php | 10 +++ application/views/receivings/receiving.php | 47 +++++++++-- application/views/reports/date_input.php | 16 +++- application/views/reports/specific_input.php | 62 +++++++++++++- application/views/sales/invoice.php | 2 +- application/views/sales/invoice_email.php | 2 +- application/views/sales/quote.php | 2 +- application/views/sales/quote_email.php | 2 +- application/views/sales/receipt_default.php | 11 +++ application/views/sales/receipt_email.php | 11 +++ application/views/sales/receipt_short.php | 12 +++ application/views/sales/register.php | 37 +++++++-- application/views/sales/work_order.php | 2 +- application/views/sales/work_order_email.php | 2 +- bower.json | 3 +- import_customers.csv | 4 +- public/license/LICENSE | 2 + 48 files changed, 508 insertions(+), 119 deletions(-) create mode 100644 application/migrations/20180820100000_upgrade_to_3_4_0.php create mode 100644 application/migrations/sqlscripts/3.3.0_to_3.4.0.sql diff --git a/application/config/config.php b/application/config/config.php index 3a345c88d..8e9161fe5 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -8,7 +8,7 @@ | | */ -$config['application_version'] = '3.3.0'; +$config['application_version'] = '3.4.0'; /* |-------------------------------------------------------------------------- diff --git a/application/config/routes.php b/application/config/routes.php index 223598214..125471bd8 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -60,6 +60,7 @@ $route['sales/index/([^/]+)/([^/]+)/([^/]+)'] = 'sales/manage/$1/$2/$3'; $route['reports/(summary_:any)/([^/]+)/([^/]+)'] = 'reports/$1/$2/$3/$4'; $route['reports/summary_expenses_categories'] = 'reports/date_input_only'; +$route['reports/summary_discounts'] = 'reports/summary_discounts_input'; $route['reports/summary_:any'] = 'reports/date_input'; $route['reports/(graphical_:any)/([^/]+)/([^/]+)'] = 'reports/$1/$2/$3/$4'; diff --git a/application/controllers/Config.php b/application/controllers/Config.php index 9c08478be..673abf527 100644 --- a/application/controllers/Config.php +++ b/application/controllers/Config.php @@ -285,7 +285,9 @@ class Config extends Secure_Controller { $batch_save_data = array( '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_sales_discount_fixed' => $this->input->post('default_sales_discount_fixed'), '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/Customers.php b/application/controllers/Customers.php index b9cbae6e8..30b409c6d 100644 --- a/application/controllers/Customers.php +++ b/application/controllers/Customers.php @@ -249,6 +249,7 @@ class Customers extends Persons 'account_number' => $this->input->post('account_number') == '' ? NULL : $this->input->post('account_number'), 'company_name' => $this->input->post('company_name') == '' ? NULL : $this->input->post('company_name'), 'discount_percent' => $this->input->post('discount_percent') == '' ? 0.00 : $this->input->post('discount_percent'), + 'discount_fixed' => $this->input->post('discount_fixed') == '' ? 0.00 : $this->input->post('discount_fixed'), 'package_id' => $this->input->post('package_id') == '' ? NULL : $this->input->post('package_id'), 'taxable' => $this->input->post('taxable') != NULL, 'date' => $date_formatter->format('Y-m-d H:i:s'), @@ -404,7 +405,8 @@ class Customers extends Persons 'consent' => $consent, 'company_name' => $data[13], 'discount_percent' => $data[15], - 'taxable' => $data[16] == '' ? 0 : 1, + 'discount_fixed' => $data[16], + 'taxable' => $data[17] == '' ? 0 : 1, 'date' => date('Y-m-d H:i:s'), 'employee_id' => $this->Employee->get_logged_in_employee_info()->person_id ); diff --git a/application/controllers/Item_kits.php b/application/controllers/Item_kits.php index c7621e537..31fdcf638 100644 --- a/application/controllers/Item_kits.php +++ b/application/controllers/Item_kits.php @@ -18,6 +18,7 @@ class Item_kits extends Secure_Controller $item_kit->total_cost_price = 0; $item_kit->total_unit_price = (float)$kit_item_info->unit_price; + $total_quantity = 0; foreach($this->Item_kit_items->get_info($item_kit->item_kit_id) as $item_kit_item) { @@ -32,11 +33,12 @@ class Item_kits extends Secure_Controller if($item_kit->price_option == PRICE_OPTION_ALL || ($item_kit->price_option == PRICE_OPTION_KIT_STOCK && $item_info->stock_type == HAS_STOCK )) { $item_kit->total_unit_price += $item_info->unit_price * $item_kit_item['quantity']; + $total_quantity += $item_kit_item['quantity']; } } $discount_fraction = bcdiv($item_kit->kit_discount_percent, 100); - $item_kit->total_unit_price = $item_kit->total_unit_price - round(bcmul($item_kit->total_unit_price, $discount_fraction), totals_decimals(), PHP_ROUND_HALF_UP); + $item_kit->total_unit_price = $item_kit->total_unit_price - round(bcadd(bcmul($item_kit->total_unit_price, $discount_fraction),bcmul($item_kit->kit_discount_fixed,$total_quantity)), totals_decimals(), PHP_ROUND_HALF_UP); return $item_kit; } @@ -130,6 +132,7 @@ class Item_kits extends Secure_Controller 'name' => $this->input->post('name'), 'item_id' => $this->input->post('kit_item_id'), 'kit_discount_percent' => $this->input->post('kit_discount_percent'), + 'kit_discount_fixed' => $this->input->post('kit_discount_fixed'), 'price_option' => $this->input->post('price_option'), 'print_option' => $this->input->post('print_option'), 'description' => $this->input->post('description') diff --git a/application/controllers/Receivings.php b/application/controllers/Receivings.php index 8972b85ec..ab77a5cfa 100644 --- a/application/controllers/Receivings.php +++ b/application/controllers/Receivings.php @@ -93,6 +93,7 @@ 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'); if($mode == 'return' && $this->Receiving->is_valid_receipt($item_id_or_number_or_item_kit_or_receipt)) { @@ -100,9 +101,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); + $this->receiving_lib->add_item_kit($item_id_or_number_or_item_kit_or_receipt, $item_location, $discount_type); } - elseif(!$this->receiving_lib->add_item($item_id_or_number_or_item_kit_or_receipt, $quantity, $item_location)) + elseif(!$this->receiving_lib->add_item($item_id_or_number_or_item_kit_or_receipt, $quantity, $item_location, $discount_type)) { $data['error'] = $this->lang->line('receivings_unable_to_add_item'); } @@ -123,12 +124,14 @@ class Receivings extends Secure_Controller $price = parse_decimals($this->input->post('price')); $quantity = parse_decimals($this->input->post('quantity')); $discount = parse_decimals($this->input->post('discount')); + $discount_fixed = parse_decimals($this->input->post('discount_fixed')); + $discount_type = parse_decimals($this->input->post('discount_type')); $item_location = $this->input->post('location'); $receiving_quantity = $this->input->post('receiving_quantity'); if($this->form_validation->run() != FALSE) { - $this->receiving_lib->edit_item($item_id, $description, $serialnumber, $quantity, $discount, $price, $receiving_quantity); + $this->receiving_lib->edit_item($item_id, $description, $serialnumber, $quantity, $discount, $discount_fixed, $discount_type, $price, $receiving_quantity); } else { @@ -264,8 +267,8 @@ class Receivings extends Secure_Controller foreach($this->receiving_lib->get_cart() as $item) { $this->receiving_lib->delete_item($item['line']); - $this->receiving_lib->add_item($item['item_id'], $item['quantity'], $this->receiving_lib->get_stock_destination()); - $this->receiving_lib->add_item($item['item_id'], -$item['quantity'], $this->receiving_lib->get_stock_source()); + $this->receiving_lib->add_item($item['item_id'], $item['quantity'], $this->receiving_lib->get_stock_destination(), $item['discount_type']); + $this->receiving_lib->add_item($item['item_id'], -$item['quantity'], $this->receiving_lib->get_stock_source(), $item['discount_type']); } $this->complete(); diff --git a/application/controllers/Reports.php b/application/controllers/Reports.php index 82b4b9eff..daf0c0704 100644 --- a/application/controllers/Reports.php +++ b/application/controllers/Reports.php @@ -318,10 +318,25 @@ class Reports extends Secure_Controller $this->load->view('reports/tabular', $data); } - //Summary Discounts report - public function summary_discounts($start_date, $end_date, $sale_type, $location_id = 'all') + public function summary_discounts_input() { - $inputs = array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type, 'location_id' => $location_id); + $data = array(); + $stock_locations = $data = $this->xss_clean($this->Stock_location->get_allowed_locations('sales')); + $stock_locations['all'] = $this->lang->line('reports_all'); + $data['stock_locations'] = array_reverse($stock_locations, TRUE); + $data['mode'] = 'sale'; + $data['discount_type_options'] = array( + '0' => $this->lang->line('reports_discount_percent'), + '1'=> $this->lang->line('reports_discount_fixed')); + $data['sale_type_options'] = $this->get_sale_type_options(); + + $this->load->view('reports/date_input', $data); + } + + //Summary Discounts report + public function summary_discounts($start_date, $end_date, $sale_type, $location_id = 'all', $discount_type=0) + { + $inputs = array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type, 'location_id' => $location_id,'discount_type'=>$discount_type); $this->load->model('reports/Summary_discounts'); $model = $this->Summary_discounts; @@ -333,7 +348,7 @@ class Reports extends Secure_Controller foreach($report_data as $row) { $tabular_data[] = $this->xss_clean(array( - 'discount' => $row['discount_percent'], + 'discount' => $row['discount'], 'count' => $row['count'] )); } @@ -869,7 +884,7 @@ class Reports extends Secure_Controller to_currency($drow['total']), to_currency($drow['cost']), to_currency($drow['profit']), - $drow['discount_percent'].'%')); + $drow['discount_percent'].'% | '.to_currency($drow['discount_fixed']))); } if(isset($report_data['rewards'][$key])) @@ -980,7 +995,7 @@ class Reports extends Secure_Controller to_currency($drow['total']), to_currency($drow['cost']), to_currency($drow['profit']), - $drow['discount_percent'].'%')); + $drow['discount_percent'].'% | '.to_currency($drow['discount_fixed']))); } if(isset($report_data['rewards'][$key])) @@ -1018,6 +1033,9 @@ class Reports extends Secure_Controller $discounts[$i] = $i . '%'; } $data['specific_input_data'] = $discounts; + $data['discount_type_options'] = array( + '0' => $this->lang->line('reports_discount_percent'), + '1'=> $this->lang->line('reports_discount_fixed')); $data['sale_type_options'] = $this->get_sale_type_options(); $data = $this->xss_clean($data); @@ -1025,9 +1043,9 @@ class Reports extends Secure_Controller $this->load->view('reports/specific_input', $data); } - public function specific_discount($start_date, $end_date, $discount, $sale_type) + public function specific_discount($start_date, $end_date, $discount, $sale_type, $discount_type) { - $inputs = array('start_date' => $start_date, 'end_date' => $end_date, 'discount' => $discount, 'sale_type' => $sale_type); + $inputs = array('start_date' => $start_date, 'end_date' => $end_date, 'discount' => $discount, 'sale_type' => $sale_type, 'discount_type' => $discount_type); $this->load->model('reports/Specific_discount'); $model = $this->Specific_discount; @@ -1085,7 +1103,7 @@ class Reports extends Secure_Controller to_currency($drow['total']), to_currency($drow['cost']), to_currency($drow['profit']), - $drow['discount_percent'].'%')); + $drow['discount_percent'].'% | '.to_currency($drow['discount_fixed']))); } if(isset($report_data['rewards'][$key])) @@ -1238,7 +1256,7 @@ class Reports extends Secure_Controller to_currency($drow['total']), to_currency($drow['cost']), to_currency($drow['profit']), - $drow['discount_percent'].'%')); + $drow['discount_percent'].'% | '.to_currency($drow['discount_fixed']))); } if(isset($report_data['rewards'][$key])) @@ -1340,7 +1358,7 @@ class Reports extends Secure_Controller $drow['category'], $quantity_purchased, to_currency($drow['total']), - $drow['discount_percent'].'%')); + $drow['discount_percent'].'% | '.to_currency($drow['discount_fixed']))); } } diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index 556aabc50..32ea7350f 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -137,11 +137,12 @@ class Sales extends Secure_Controller { $this->sale_lib->set_customer($customer_id); $discount_percent = $this->Customer->get_info($customer_id)->discount_percent; + $discount_fixed = $this->Customer->get_info($customer_id)->discount_fixed; // apply customer default discount to items that have 0 discount - if($discount_percent != '') + if($discount_percent != '' OR $discount_fixed != '') { - $this->sale_lib->apply_customer_discount($discount_percent); + $this->sale_lib->apply_customer_discount($discount_percent, $discount_fixed); } } @@ -367,6 +368,8 @@ class Sales extends Secure_Controller $data = array(); $discount = 0; + $discount_fixed = 0; + $discount_type = $this->config->item('default_sales_discount_type'); // check if any discount is assigned to the selected customer $customer_id = $this->sale_lib->get_customer(); @@ -374,18 +377,31 @@ class Sales extends Secure_Controller { // load the customer discount if any $discount_percent = $this->Customer->get_info($customer_id)->discount_percent; + $discount_cash = $this->Customer->get_info($customer_id)->discount_fixed; if($discount_percent != '') { $discount = $discount_percent; + $discount_type = 0; + } + + if($discount_cash != '') + { + $discount_fixed = $discount_cash; + $discount_type = 1; } } // if the customer discount is 0 or no customer is selected apply the default sales discount - if($discount == 0) + if($discount == 0 ) { $discount = $this->config->item('default_sales_discount'); } + if($discount_fixed == 0) + { + $discount_fixed = $this->config->item('default_sales_discount_fixed'); + } + $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(); @@ -411,12 +427,17 @@ class Sales extends Secure_Controller $discount = $item_kit_info->kit_discount_percent; } + if($item_kit_info->kit_discount_fixed != 0 && $item_kit_info->kit_discount_fixed > $discount_fixed) + { + $discount_fixed = $item_kit_info->kit_discount_fixed; + } + $price = NULL; $print_option = PRINT_ALL; // Always include in list of items on invoice if(!empty($kit_item_id)) { - if(!$this->sale_lib->add_item($kit_item_id, $quantity, $item_location, $discount, PRICE_MODE_STANDARD)) + if(!$this->sale_lib->add_item($kit_item_id, $quantity, $item_location, $discount, $discount_fixed, $discount_type, PRICE_MODE_STANDARD)) { $data['error'] = $this->lang->line('sales_unable_to_add_item'); } @@ -428,7 +449,7 @@ class Sales extends Secure_Controller // Add item kit items to order $stock_warning = NULL; - if(!$this->sale_lib->add_item_kit($item_id_or_number_or_item_kit_or_receipt, $item_location, $discount, $kit_price_option, $kit_print_option, $stock_warning)) + if(!$this->sale_lib->add_item_kit($item_id_or_number_or_item_kit_or_receipt, $item_location, $discount, $discount_fixed, $discount_type, $kit_price_option, $kit_print_option, $stock_warning)) { $data['error'] = $this->lang->line('sales_unable_to_add_item'); } @@ -439,7 +460,7 @@ class Sales extends Secure_Controller } else { - if(!$this->sale_lib->add_item($item_id_or_number_or_item_kit_or_receipt, $quantity, $item_location, $discount, PRICE_MODE_STANDARD)) + if(!$this->sale_lib->add_item($item_id_or_number_or_item_kit_or_receipt, $quantity, $item_location, $discount, $discount_fixed, $discount_type, PRICE_MODE_STANDARD)) { $data['error'] = $this->lang->line('sales_unable_to_add_item'); } @@ -458,18 +479,22 @@ class Sales extends Secure_Controller $this->form_validation->set_rules('price', 'lang:sales_price', 'required|callback_numeric'); $this->form_validation->set_rules('quantity', 'lang:sales_quantity', 'required|callback_numeric'); $this->form_validation->set_rules('discount', 'lang:sales_discount', 'required|callback_numeric'); + $this->form_validation->set_rules('discount_fixed', 'lang:sales_discount', 'required|callback_numeric'); $description = $this->input->post('description'); $serialnumber = $this->input->post('serialnumber'); $price = parse_decimals($this->input->post('price')); $quantity = parse_decimals($this->input->post('quantity')); $discount = parse_decimals($this->input->post('discount')); + $discount_fixed = parse_decimals($this->input->post('discount_fixed')); + $discount_type = $this->input->post('discount_type'); + $item_location = $this->input->post('location'); $discounted_total = $this->input->post('discounted_total') != '' ? $this->input->post('discounted_total') : NULL; if($this->form_validation->run() != FALSE) { - $this->sale_lib->edit_item($item_id, $description, $serialnumber, $quantity, $discount, $price, $discounted_total); + $this->sale_lib->edit_item($item_id, $description, $serialnumber, $quantity, $discount, $discount_fixed, $discount_type, $price, $discounted_total); } else { diff --git a/application/language/en-US/sales_lang.php b/application/language/en-US/sales_lang.php index 7b1efb4df..2bcebf17e 100644 --- a/application/language/en-US/sales_lang.php +++ b/application/language/en-US/sales_lang.php @@ -44,7 +44,7 @@ $lang["sales_delete_unsuccessful"] = "Sale delete failed."; $lang["sales_description_abbrv"] = "Desc."; $lang["sales_discard"] = "Discard"; $lang["sales_discard_quote"] = ""; -$lang["sales_discount"] = "Disc %"; +$lang["sales_discount"] = "Disc"; $lang["sales_discount_included"] = "% Discount"; $lang["sales_discount_short"] = "%"; $lang["sales_due"] = "Due"; diff --git a/application/language/es/config_lang.php b/application/language/es/config_lang.php index 830e726f1..f23f04eba 100644 --- a/application/language/es/config_lang.php +++ b/application/language/es/config_lang.php @@ -271,3 +271,4 @@ $lang["config_top"] = "Arriba"; $lang["config_website"] = "Sitio Web"; $lang["config_work_order_enable"] = "Soporte Ordenes de Trabajo"; $lang["config_work_order_format"] = "Formato Ordenes de trabajo"; +$lang["config_default_sales_discount_type"] = "Descuento Fijo en Ventas predeterminado"; \ No newline at end of file diff --git a/application/language/es/reports_lang.php b/application/language/es/reports_lang.php index 5759602a0..080aef237 100644 --- a/application/language/es/reports_lang.php +++ b/application/language/es/reports_lang.php @@ -121,3 +121,5 @@ $lang["reports_unit_price"] = "Precio de Venta"; $lang["reports_used"] = "Puntos usados"; $lang["reports_work_orders"] = "Ordenes"; $lang["reports_zero_and_less"] = "Cero y negativos"; +$lang["reports_discount_type"] = "Tipo de Descuento"; +$lang["reports_discount_fixed"] = "Descuento Fijo"; diff --git a/application/language/es/sales_lang.php b/application/language/es/sales_lang.php index 3f3650d10..1b10f2dc5 100644 --- a/application/language/es/sales_lang.php +++ b/application/language/es/sales_lang.php @@ -44,7 +44,7 @@ $lang["sales_delete_unsuccessful"] = "Venta no borrada, fallida."; $lang["sales_description_abbrv"] = "Descrp."; $lang["sales_discard"] = "Descartar"; $lang["sales_discard_quote"] = "Descartar"; -$lang["sales_discount"] = "% Descuento"; +$lang["sales_discount"] = "Descuento"; $lang["sales_discount_included"] = "% Descuento"; $lang["sales_discount_short"] = "%"; $lang["sales_due"] = "Deudado"; diff --git a/application/libraries/Receiving_lib.php b/application/libraries/Receiving_lib.php index 4c01e9bbc..5e78c9df3 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 = 0, $price = NULL, $description = NULL, $serialnumber = NULL, $receiving_quantity = NULL, $include_deleted = FALSE) + public function add_item($item_id, $quantity = 1, $item_location = NULL, $discount_type = 0, $discount = 0, $discount_fixed = 0, $price = NULL, $description = NULL, $serialnumber = NULL, $receiving_quantity = NULL, $include_deleted = FALSE) { //make sure item exists in database. if(!$this->CI->Item->exists($item_id, $include_deleted)) @@ -226,6 +226,10 @@ class Receiving_lib 1 => 'x1'); } + if(is_null($receiving_quantity)){ + $receiving_quantity = $item_info->receiving_quantity; + } + $item = array($insertkey => array( 'item_id' => $item_id, 'item_location' => $item_location, @@ -238,11 +242,13 @@ class Receiving_lib 'is_serialized' => $item_info->is_serialized, 'quantity' => $quantity, 'discount' => $discount, + 'discount_fixed' => $discount_fixed, + 'discount_type' => $discount_type, 'in_stock' => $this->CI->Item_quantity->get_item_quantity($item_id, $item_location)->quantity, 'price' => $price, - 'receiving_quantity' => $item_info->receiving_quantity, + 'receiving_quantity' => $receiving_quantity, 'receiving_quantity_choices' => $receiving_quantity_choices, - 'total' => $this->get_item_total($quantity, $price, $discount, $item_info->receiving_quantity) + 'total' => $this->get_item_total($quantity, $price, $discount, $discount_fixed, $receiving_quantity) ) ); @@ -250,7 +256,7 @@ class Receiving_lib if($itemalreadyinsale) { $items[$updatekey]['quantity'] += $quantity; - $items[$updatekey]['total'] = $this->get_item_total($items[$updatekey]['quantity'], $price, $discount, $items[$updatekey]['receiving_quantity']); + $items[$updatekey]['total'] = $this->get_item_total($items[$updatekey]['quantity'], $price, $discount, $discount_fixed, $items[$updatekey]['receiving_quantity']); } else { @@ -263,7 +269,7 @@ class Receiving_lib return TRUE; } - public function edit_item($line, $description, $serialnumber, $quantity, $discount, $price, $receiving_quantity) + public function edit_item($line, $description, $serialnumber, $quantity, $discount, $discount_fixed, $discount_type, $price, $receiving_quantity) { $items = $this->get_cart(); if(isset($items[$line])) @@ -274,8 +280,12 @@ class Receiving_lib $line['quantity'] = $quantity; $line['receiving_quantity'] = $receiving_quantity; $line['discount'] = $discount; + $line['discount_fixed'] = $discount_fixed; + if(!is_null($discount_type)){ + $line['discount_type'] = $discount_type; + } $line['price'] = $price; - $line['total'] = $this->get_item_total($quantity, $price, $discount, $receiving_quantity); + $line['total'] = $this->get_item_total($quantity, $price, $discount, $discount_fixed, $receiving_quantity); $this->set_cart($items); } @@ -308,13 +318,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_percent, $row->item_unit_price, $row->description, $row->serialnumber, $row->receiving_quantity, TRUE); + $this->add_item($row->item_id, -$row->quantity_purchased, $row->item_location, $row->discount_type, $row->discount_percent, $row->discount_fixed, $row->item_unit_price, $row->description, $row->serialnumber, $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) + public function add_item_kit($external_item_kit_id, $item_location, $discount_type) { //KIT # $pieces = explode(' ',$external_item_kit_id); @@ -322,7 +332,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); + $this->add_item($item_kit_item['item_id'],$item_kit_item['quantity'], $item_location, $discount_type); } } @@ -333,7 +343,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_percent, $row->item_unit_price, $row->description, $row->serialnumber, $row->receiving_quantity, TRUE); + $this->add_item($row->item_id, $row->quantity_purchased, $row->item_location, $row->discount_type, $row->discount_percent, $row->discount_fixed, $row->item_unit_price, $row->description, $row->serialnumber, $row->receiving_quantity, TRUE); } $this->set_supplier($this->CI->Receiving->get_supplier($receiving_id)->person_id); @@ -349,12 +359,12 @@ class Receiving_lib $this->clear_reference(); } - public function get_item_total($quantity, $price, $discount_percentage, $receiving_quantity) + public function get_item_total($quantity, $price, $discount_percentage, $discount_fixed, $receiving_quantity) { $extended_quantity = bcmul($quantity, $receiving_quantity); $total = bcmul($extended_quantity, $price); $discount_fraction = bcdiv($discount_percentage, 100); - $discount_amount = bcmul($total, $discount_fraction); + $discount_amount = bcadd(bcmul($total, $discount_fraction), $discount_fixed); return bcsub($total, $discount_amount); } @@ -364,7 +374,7 @@ class Receiving_lib $total = 0; foreach($this->get_cart() as $item) { - $total = bcadd($total, $this->get_item_total(($item['quantity']), $item['price'], $item['discount'], $item['receiving_quantity'])); + $total = bcadd($total, $this->get_item_total(($item['quantity']), $item['price'], $item['discount'], $item['discount_fixed'], $item['receiving_quantity'])); } return $total; diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index 35d033c0c..cad4ce1f6 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -450,7 +450,7 @@ class Sale_lib $item_count++; $total_units += $item['quantity']; } - $discount_amount = $this->get_item_discount($item['quantity'], $item['price'], $item['discount']); + $discount_amount = $this->get_item_discount($item['quantity'], $item['price'], $item['discount'], $item['discount_fixed']); $total_discount = bcadd($total_discount, $discount_amount); $extended_amount = $this->get_extended_amount($item['quantity'], $item['price']); @@ -460,7 +460,7 @@ class Sale_lib if($this->CI->config->item('tax_included')) { - $subtotal = bcadd($subtotal, $this->get_extended_total_tax_exclusive($item['item_id'], $extended_discounted_amount, $item['quantity'], $item['price'], $item['discount'])); + $subtotal = bcadd($subtotal, $this->get_extended_total_tax_exclusive($item['item_id'], $extended_discounted_amount, $item['quantity'], $item['price'], $item['discount'],$item['discount_fixed'])); } else { @@ -696,7 +696,7 @@ class Sale_lib $this->CI->session->unset_userdata('sales_rewards_remainder'); } - public function add_item(&$item_id, $quantity = 1, $item_location, $discount = 0, $price_mode = PRICE_MODE_STANDARD, $kit_price_option = NULL, $kit_print_option = NULL, $price_override = NULL, $description = NULL, $serialnumber = NULL, $include_deleted = FALSE, $print_option = NULL ) + public function add_item(&$item_id, $quantity = 1, $item_location, $discount = 0, $discount_fixed = 0, $discount_type = 0, $price_mode = PRICE_MODE_STANDARD, $kit_price_option = NULL, $kit_print_option = NULL, $price_override = NULL, $description = NULL, $serialnumber = NULL, $include_deleted = FALSE, $print_option = NULL ) { $item_info = $this->CI->Item->get_info_by_id_or_number($item_id); @@ -753,6 +753,7 @@ class Sale_lib if($price == 0.00) { $discount = 0.00; + $discount_fixed = 0.00; } // Serialization and Description @@ -825,8 +826,8 @@ class Sale_lib } } - $total = $this->get_item_total($quantity, $price, $discount); - $discounted_total = $this->get_item_total($quantity, $price, $discount, TRUE); + $total = $this->get_item_total($quantity, $price, $discount, $discount_fixed); + $discounted_total = $this->get_item_total($quantity, $price, $discount, $discount_fixed, TRUE); if($this->CI->config->item('multi_pack_enabled') == '1') { @@ -850,6 +851,8 @@ class Sale_lib 'is_serialized' => $item_info->is_serialized, 'quantity' => $quantity, 'discount' => $discount, + 'discount_fixed' => $discount_fixed, + 'discount_type' => $discount_type, 'in_stock' => $this->CI->Item_quantity->get_item_quantity($item_id, $item_location)->quantity, 'price' => $price, 'cost_price' => $cost_price, @@ -933,7 +936,7 @@ class Sale_lib return -1; } - public function edit_item($line, $description, $serialnumber, $quantity, $discount, $price, $discounted_total=NULL) + public function edit_item($line, $description, $serialnumber, $quantity, $discount, $discount_fixed, $discount_type, $price, $discounted_total=NULL) { $items = $this->get_cart(); if(isset($items[$line])) @@ -948,9 +951,13 @@ class Sale_lib $line['serialnumber'] = $serialnumber; $line['quantity'] = $quantity; $line['discount'] = $discount; + $line['discount_fixed'] = $discount_fixed; + if(!is_null($discount_type)){ + $line['discount_type'] = $discount_type; + } $line['price'] = $price; - $line['total'] = $this->get_item_total($quantity, $price, $discount); - $line['discounted_total'] = $this->get_item_total($quantity, $price, $discount, TRUE); + $line['total'] = $this->get_item_total($quantity, $price, $discount, $discount_fixed); + $line['discounted_total'] = $this->get_item_total($quantity, $price, $discount, $discount_fixed, TRUE); $this->set_cart($items); } @@ -981,13 +988,13 @@ class Sale_lib foreach($this->CI->Sale->get_sale_items_ordered($sale_id)->result() as $row) { - $this->add_item($row->item_id, -$row->quantity_purchased, $row->item_location, $row->discount_percent, PRICE_MODE_STANDARD, NULL, NULL, $row->item_unit_price, $row->description, $row->serialnumber, TRUE); + $this->add_item($row->item_id, -$row->quantity_purchased, $row->item_location, $row->discount_percent, $row->discount_fixed, $row->discount_type, PRICE_MODE_STANDARD, NULL, NULL, $row->item_unit_price, $row->description, $row->serialnumber, TRUE); } $this->set_customer($this->CI->Sale->get_customer($sale_id)->person_id); } - public function add_item_kit($external_item_kit_id, $item_location, $discount, $kit_price_option, $kit_print_option, &$stock_warning) + public function add_item_kit($external_item_kit_id, $item_location, $discount, $discount_fixed, $discount_type, $kit_price_option, $kit_print_option, &$stock_warning) { //KIT # $pieces = explode(' ', $external_item_kit_id); @@ -996,7 +1003,7 @@ class Sale_lib foreach($this->CI->Item_kit_items->get_info($item_kit_id) as $item_kit_item) { - $result &= $this->add_item($item_kit_item['item_id'], $item_kit_item['quantity'], $item_location, $discount, PRICE_MODE_KIT, $kit_price_option, $kit_print_option, NULL, NULL, NULL, NULL); + $result &= $this->add_item($item_kit_item['item_id'], $item_kit_item['quantity'], $item_location, $discount, $discount_fixed, $discount_type, PRICE_MODE_KIT, $kit_price_option, $kit_print_option, NULL, NULL, NULL, NULL); if($stock_warning == NULL) { @@ -1014,7 +1021,7 @@ class Sale_lib foreach($this->CI->Sale->get_sale_items_ordered($sale_id)->result() as $row) { - $this->add_item($row->item_id, $row->quantity_purchased, $row->item_location, $row->discount_percent, PRICE_MODE_STANDARD, NULL, NULL, $row->item_unit_price, $row->description, $row->serialnumber, TRUE, $row->print_option); + $this->add_item($row->item_id, $row->quantity_purchased, $row->item_location, $row->discount_percent, $row->discount_fixed, $row->discount_type, PRICE_MODE_STANDARD, NULL, NULL, $row->item_unit_price, $row->description, $row->serialnumber, TRUE, $row->print_option); } foreach($this->CI->Sale->get_sale_payments($sale_id)->result() as $row) @@ -1042,7 +1049,7 @@ class Sale_lib $this->empty_cart(); foreach($this->CI->Sale->get_sale_items_ordered($sale_id)->result() as $row) { - $this->add_item($row->item_id, $row->quantity_purchased, $row->item_location, $row->discount_percent, PRICE_MODE_STANDARD, NULL, NULL, $row->item_unit_price, $row->description, $row->serialnumber, TRUE, $row->print_option); + $this->add_item($row->item_id, $row->quantity_purchased, $row->item_location, $row->discount_percent, $row->discount_fixed, $row->discount_type, PRICE_MODE_STANDARD, NULL, NULL, $row->item_unit_price, $row->description, $row->serialnumber, TRUE, $row->print_option); } return $this->CI->session->userdata('sales_cart'); @@ -1127,12 +1134,12 @@ class Sale_lib // This computes tax for each line item and adds it to the tax type total $tax_group = (float)$tax['percent'] . '% ' . $tax['name']; $tax_type = Tax_lib::TAX_TYPE_VAT; - $tax_basis = $this->get_item_total($item['quantity'], $item['price'], $item['discount'], TRUE); + $tax_basis = $this->get_item_total($item['quantity'], $item['price'], $item['discount'], $item['discount_fixed'], TRUE); $tax_amount = 0; if($this->CI->config->item('tax_included')) { - $tax_amount = $this->get_item_tax($item['quantity'], $item['price'], $item['discount'], $tax['percent']); + $tax_amount = $this->get_item_tax($item['quantity'], $item['price'], $item['discount'], $item['discount_fixed'], $tax['percent']); } elseif($this->CI->config->item('customer_sales_tax_support') == '0') { @@ -1166,7 +1173,7 @@ class Sale_lib return $sales_taxes; } - public function apply_customer_discount($discount_percent) + public function apply_customer_discount($discount_percent, $discount_fixed) { // Get all items in the cart so far... $items = $this->get_cart(); @@ -1180,8 +1187,17 @@ class Sale_lib if($item['discount'] == 0) { $item['discount'] = $discount_percent; - $item['total'] = $this->get_item_total($quantity, $price, $discount_percent); - $item['discounted_total'] = $this->get_item_total($quantity, $price, $discount_percent, TRUE); + $item['discount_fixed'] = $discount_fixed; + $item['total'] = $this->get_item_total($quantity, $price, $discount_percent, $discount_fixed); + $item['discounted_total'] = $this->get_item_total($quantity, $price, $discount_percent, $discount_fixed, TRUE); + } + + if($item['discount_fixed'] == 0) + { + $item['discount'] = $discount_percent; + $item['discount_fixed'] = $discount_fixed; + $item['total'] = $this->get_item_total($quantity, $price, $discount_percent, $discount_fixed); + $item['discounted_total'] = $this->get_item_total($quantity, $price, $discount_percent, $discount_fixed, TRUE); } } @@ -1195,7 +1211,7 @@ class Sale_lib { if($item['discount'] > 0) { - $item_discount = $this->get_item_discount($item['quantity'], $item['price'], $item['discount']); + $item_discount = $this->get_item_discount($item['quantity'], $item['price'], $item['discount'], $item['discount_fixed']); $discount = bcadd($discount, $item_discount); } } @@ -1208,39 +1224,39 @@ class Sale_lib return $this->calculate_subtotal($include_discount, $exclude_tax); } - public function get_item_total_tax_exclusive($item_id, $quantity, $price, $discount_percentage, $include_discount = FALSE) + public function get_item_total_tax_exclusive($item_id, $quantity, $price, $discount_percentage, $discount_fixed, $include_discount = FALSE) { $tax_info = $this->CI->Item_taxes->get_info($item_id); - $item_total = $this->get_item_total($quantity, $price, $discount_percentage, $include_discount); + $item_total = $this->get_item_total($quantity, $price, $discount_percentage, $discount_fixed, $include_discount); // only additive tax here foreach($tax_info as $tax) { $tax_percentage = $tax['percent']; - $item_total = bcsub($item_total, $this->get_item_tax($quantity, $price, $discount_percentage, $tax_percentage)); + $item_total = bcsub($item_total, $this->get_item_tax($quantity, $price, $discount_percentage, $discount_fixed, $tax_percentage)); } return $item_total; } - public function get_extended_total_tax_exclusive($item_id, $discounted_extended_amount, $quantity, $price, $discount_percentage = 0) + public function get_extended_total_tax_exclusive($item_id, $discounted_extended_amount, $quantity, $price, $discount_percentage = 0, $discount_fixed = 0) { $tax_info = $this->CI->Item_taxes->get_info($item_id); // only additive tax here foreach($tax_info as $tax) { $tax_percentage = $tax['percent']; - $discounted_extended_amount = bcsub($discounted_extended_amount, $this->get_item_tax($quantity, $price, $discount_percentage, $tax_percentage)); + $discounted_extended_amount = bcsub($discounted_extended_amount, $this->get_item_tax($quantity, $price, $discount_percentage, $discount_fixed, $tax_percentage)); } return $discounted_extended_amount; } - public function get_item_total($quantity, $price, $discount_percentage, $include_discount = FALSE) + public function get_item_total($quantity, $price, $discount_percentage, $discount_fixed, $include_discount = FALSE) { $total = bcmul($quantity, $price); if($include_discount) { - $discount_amount = $this->get_item_discount($quantity, $price, $discount_percentage); + $discount_amount = $this->get_item_discount($quantity, $price, $discount_percentage, $discount_fixed); return bcsub($total, $discount_amount); } @@ -1269,17 +1285,20 @@ class Sale_lib return bcsub($extended_amount, $discount_amount); } - public function get_item_discount($quantity, $price, $discount_percentage) + public function get_item_discount($quantity, $price, $discount_percentage, $discount_fixed) { $total = bcmul($quantity, $price); $discount_fraction = bcdiv($discount_percentage, 100); - return round(bcmul($total, $discount_fraction), totals_decimals(), PHP_ROUND_HALF_UP); + $discount_amount=bcadd(bcmul($total, $discount_fraction), $discount_fixed); + + return round($discount_amount, totals_decimals(), PHP_ROUND_HALF_UP); + } - public function get_item_tax($quantity, $price, $discount_percentage, $tax_percentage) + public function get_item_tax($quantity, $price, $discount_percentage, $discount_fixed, $tax_percentage) { - $price = $this->get_item_total($quantity, $price, $discount_percentage, TRUE); + $price = $this->get_item_total($quantity, $price, $discount_percentage, $discount_fixed, TRUE); if($this->CI->config->item('tax_included')) { $tax_fraction = bcadd(100, $tax_percentage); @@ -1300,11 +1319,11 @@ class Sale_lib { if($exclude_tax && $this->CI->config->item('tax_included')) { - $subtotal = bcadd($subtotal, $this->get_item_total_tax_exclusive($item['item_id'], $item['quantity'], $item['price'], $item['discount'], $include_discount)); + $subtotal = bcadd($subtotal, $this->get_item_total_tax_exclusive($item['item_id'], $item['quantity'], $item['price'], $item['discount'], $item['discount_fixed'], $include_discount)); } else { - $subtotal = bcadd($subtotal, $this->get_item_total($item['quantity'], $item['price'], $item['discount'], $include_discount)); + $subtotal = bcadd($subtotal, $this->get_item_total($item['quantity'], $item['price'], $item['discount'], $item['discount_fixed'], $include_discount)); } } diff --git a/application/migrations/20180820100000_upgrade_to_3_4_0.php b/application/migrations/20180820100000_upgrade_to_3_4_0.php new file mode 100644 index 000000000..677bad041 --- /dev/null +++ b/application/migrations/20180820100000_upgrade_to_3_4_0.php @@ -0,0 +1,20 @@ + diff --git a/application/migrations/sqlscripts/3.3.0_to_3.4.0.sql b/application/migrations/sqlscripts/3.3.0_to_3.4.0.sql new file mode 100644 index 000000000..7fe49d194 --- /dev/null +++ b/application/migrations/sqlscripts/3.3.0_to_3.4.0.sql @@ -0,0 +1,22 @@ +-- +-- Add support for Discount on Sales Fixed +-- + +INSERT INTO `ospos_app_config` (`key`, `value`) VALUES +('default_sales_discount_fixed', '0'), +('default_sales_discount_type', '0'); + +ALTER TABLE `ospos_item_kits` + ADD COLUMN `kit_discount_fixed` DECIMAL(15,2) NOT NULL DEFAULT '0.00' AFTER `kit_discount_percent`; + +ALTER TABLE `ospos_customers` + ADD COLUMN `discount_fixed` DECIMAL(15,2) NOT NULL DEFAULT '0.00' AFTER `discount_percent`; + + +ALTER TABLE `ospos_sales_items` + ADD COLUMN `discount_fixed` DECIMAL(15,2) NOT NULL DEFAULT '0.00' AFTER `discount_percent`, + ADD COLUMN `discount_type` TINYINT(2) NOT NULL DEFAULT '0' AFTER `discount_fixed`; + +ALTER TABLE `ospos_receivings_items` + ADD COLUMN `discount_fixed` DECIMAL(15,2) NOT NULL DEFAULT '0.00' AFTER `discount_percent`, + ADD COLUMN `discount_type` TINYINT(2) NOT NULL DEFAULT '0' AFTER `discount_fixed`; diff --git a/application/models/Item_kit.php b/application/models/Item_kit.php index ea62998eb..96aca7b05 100644 --- a/application/models/Item_kit.php +++ b/application/models/Item_kit.php @@ -59,6 +59,7 @@ class Item_kit extends CI_Model items.description as item_description, item_kits.item_id as kit_item_id, kit_discount_percent, + kit_discount_fixed, price_option, print_option, category, diff --git a/application/models/Receiving.php b/application/models/Receiving.php index db3419b01..4e1402e8c 100644 --- a/application/models/Receiving.php +++ b/application/models/Receiving.php @@ -94,6 +94,8 @@ class Receiving extends CI_Model 'quantity_purchased' => $item['quantity'], 'receiving_quantity' => $item['receiving_quantity'], 'discount_percent' => $item['discount'], + 'discount_fixed' => $item['discount_fixed'], + 'discount_type' => $item['discount_type'], 'item_cost_price' => $cur_item_info->cost_price, 'item_unit_price' => $item['price'], 'item_location' => $item['item_location'] @@ -266,12 +268,13 @@ class Receiving extends CI_Model MAX(item_cost_price) AS item_cost_price, MAX(item_unit_price) AS item_unit_price, MAX(discount_percent) AS discount_percent, + MAX(discount_fixed) AS discount_fixed, receivings_items.line, MAX(serialnumber) AS serialnumber, MAX(receivings_items.description) AS description, - MAX(item_unit_price * quantity_purchased * receivings_items.receiving_quantity - item_unit_price * quantity_purchased * receivings_items.receiving_quantity * discount_percent / 100) AS subtotal, - MAX(item_unit_price * quantity_purchased * receivings_items.receiving_quantity - item_unit_price * quantity_purchased * receivings_items.receiving_quantity * discount_percent / 100) AS total, - MAX((item_unit_price * quantity_purchased * receivings_items.receiving_quantity - item_unit_price * quantity_purchased * receivings_items.receiving_quantity * discount_percent / 100) - (item_cost_price * quantity_purchased)) AS profit, + MAX(item_unit_price * quantity_purchased * receivings_items.receiving_quantity - item_unit_price * quantity_purchased * receivings_items.receiving_quantity * discount_percent / 100) - discount_fixed AS subtotal, + MAX(item_unit_price * quantity_purchased * receivings_items.receiving_quantity - item_unit_price * quantity_purchased * receivings_items.receiving_quantity * discount_percent / 100) - discount_fixed AS total, + MAX((item_unit_price * quantity_purchased * receivings_items.receiving_quantity - item_unit_price * quantity_purchased * receivings_items.receiving_quantity * discount_percent / 100) - discount_fixed - (item_cost_price * quantity_purchased)) AS profit, MAX(item_cost_price * quantity_purchased * receivings_items.receiving_quantity ) AS cost FROM ' . $this->db->dbprefix('receivings_items') . ' AS receivings_items INNER JOIN ' . $this->db->dbprefix('receivings') . ' AS receivings diff --git a/application/models/Sale.php b/application/models/Sale.php index a82e9be69..65afec976 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -38,7 +38,7 @@ class Sale extends CI_Model $decimals = totals_decimals(); - $sale_price = 'sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)'; + $sale_price = 'sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)-sales_items.discount_fixed'; $tax = 'ROUND(IFNULL(SUM(sales_items_taxes.tax), 0), ' . $decimals . ')'; if($this->config->item('tax_included')) @@ -152,7 +152,7 @@ class Sale extends CI_Model $decimals = totals_decimals(); - $sale_price = 'sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)'; + $sale_price = 'sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)-sales_items.discount_fixed'; $sale_cost = 'SUM(sales_items.item_cost_price * sales_items.quantity_purchased)'; $tax = 'IFNULL(SUM(sales_items_taxes.tax), 0)'; @@ -653,6 +653,8 @@ class Sale extends CI_Model 'serialnumber' => character_limiter($item['serialnumber'], 30), 'quantity_purchased'=> $item['quantity'], 'discount_percent' => $item['discount'], + 'discount_fixed' => $item['discount_fixed'], + 'discount_type' => $item['discount_type'], 'item_cost_price' => $item['cost_price'], 'item_unit_price' => $item['price'], 'item_location' => $item['item_location'], @@ -928,6 +930,8 @@ class Sale extends CI_Model item_cost_price, item_unit_price, discount_percent, + discount_fixed, + discount_type, item_location, print_option, ' . $this->Item->get_item_name('name') . ', @@ -1113,7 +1117,7 @@ class Sale extends CI_Model $decimals = totals_decimals(); - $sale_price = 'sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)'; + $sale_price = 'sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)-sales_items.discount_fixed'; $sale_cost = 'SUM(sales_items.item_cost_price * sales_items.quantity_purchased)'; $tax = 'IFNULL(SUM(sales_items_taxes.tax), 0)'; @@ -1191,6 +1195,7 @@ class Sale extends CI_Model MAX(sales_items.item_cost_price) AS item_cost_price, MAX(sales_items.item_unit_price) AS item_unit_price, MAX(sales_items.discount_percent) AS discount_percent, + MAX(sales_items.discount_fixed) AS discount_fixed, sales_items.line AS line, MAX(sales_items.serialnumber) AS serialnumber, MAX(sales_items.item_location) AS item_location, diff --git a/application/models/reports/Detailed_receivings.php b/application/models/reports/Detailed_receivings.php index 62700d2c4..88e0e4317 100644 --- a/application/models/reports/Detailed_receivings.php +++ b/application/models/reports/Detailed_receivings.php @@ -97,7 +97,7 @@ class Detailed_receivings extends Report foreach($data['summary'] as $key=>$value) { - $this->db->select('name, item_number, category, quantity_purchased, serialnumber,total, discount_percent, item_location, receivings_items_temp.receiving_quantity'); + $this->db->select('name, item_number, category, quantity_purchased, serialnumber,total, discount_percent, discount_fixed, item_location, receivings_items_temp.receiving_quantity'); $this->db->from('receivings_items_temp'); $this->db->join('items', 'receivings_items_temp.item_id = items.item_id'); $this->db->where('receiving_id = '.$value['receiving_id']); diff --git a/application/models/reports/Detailed_sales.php b/application/models/reports/Detailed_sales.php index 79645af2c..ab3579640 100644 --- a/application/models/reports/Detailed_sales.php +++ b/application/models/reports/Detailed_sales.php @@ -144,7 +144,7 @@ class Detailed_sales extends Report foreach($data['summary'] as $key=>$value) { - $this->db->select('name, category, quantity_purchased, item_location, serialnumber, description, subtotal, tax, total, cost, profit, discount_percent, sale_status'); + $this->db->select('name, category, quantity_purchased, item_location, serialnumber, description, subtotal, tax, total, cost, profit, discount_percent, discount_fixed, sale_status'); $this->db->from('sales_items_temp'); $this->db->where('sale_id', $value['sale_id']); $data['details'][$key] = $this->db->get()->result_array(); diff --git a/application/models/reports/Specific_customer.php b/application/models/reports/Specific_customer.php index 54623489c..ad7f57a2f 100644 --- a/application/models/reports/Specific_customer.php +++ b/application/models/reports/Specific_customer.php @@ -127,7 +127,7 @@ class Specific_customer extends Report foreach($data['summary'] as $key=>$value) { - $this->db->select('name, category, serialnumber, description, quantity_purchased, subtotal, tax, total, cost, profit, discount_percent'); + $this->db->select('name, category, serialnumber, description, quantity_purchased, subtotal, tax, total, cost, profit, discount_percent, discount_fixed'); $this->db->from('sales_items_temp'); $this->db->where('sale_id', $value['sale_id']); $data['details'][$key] = $this->db->get()->result_array(); diff --git a/application/models/reports/Specific_discount.php b/application/models/reports/Specific_discount.php index 91bc2be3c..ab8a059e5 100755 --- a/application/models/reports/Specific_discount.php +++ b/application/models/reports/Specific_discount.php @@ -70,7 +70,12 @@ class Specific_discount extends Report MAX(payment_type) AS payment_type, MAX(comment) AS comment'); $this->db->from('sales_items_temp'); - $this->db->where('discount_percent >=', $inputs['discount']); + + if($inputs['discount_type']==1){ + $this->db->where('discount_fixed >=', $inputs['discount']); + }else{ + $this->db->where('discount_percent >=', $inputs['discount']); + } if($inputs['sale_type'] == 'complete') { @@ -119,7 +124,7 @@ class Specific_discount extends Report foreach($data['summary'] as $key=>$value) { - $this->db->select('name, category, serialnumber, description, quantity_purchased, subtotal, tax, total, cost, profit, discount_percent'); + $this->db->select('name, category, serialnumber, description, quantity_purchased, subtotal, tax, total, cost, profit, discount_percent, discount_fixed'); $this->db->from('sales_items_temp'); $this->db->where('sale_id', $value['sale_id']); $data['details'][$key] = $this->db->get()->result_array(); @@ -136,7 +141,12 @@ class Specific_discount extends Report { $this->db->select('SUM(subtotal) AS subtotal, SUM(tax) AS tax, SUM(total) AS total, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); - $this->db->where('discount_percent >=', $inputs['discount']); + + if($inputs['discount_type']==1){ + $this->db->where('discount_fixed >=', $inputs['discount']); + }else{ + $this->db->where('discount_percent >=', $inputs['discount']); + } if($inputs['sale_type'] == 'complete') { diff --git a/application/models/reports/Specific_employee.php b/application/models/reports/Specific_employee.php index 1b4484227..0243d7f1f 100644 --- a/application/models/reports/Specific_employee.php +++ b/application/models/reports/Specific_employee.php @@ -117,7 +117,7 @@ class Specific_employee extends Report foreach($data['summary'] as $key=>$value) { - $this->db->select('name, category, serialnumber, description, quantity_purchased, subtotal, tax, total, cost, profit, discount_percent'); + $this->db->select('name, category, serialnumber, description, quantity_purchased, subtotal, tax, total, cost, profit, discount_percent, discount_fixed'); $this->db->from('sales_items_temp'); $this->db->where('sale_id', $value['sale_id']); $data['details'][$key] = $this->db->get()->result_array(); diff --git a/application/models/reports/Summary_discounts.php b/application/models/reports/Summary_discounts.php index e94119f6d..606f79f9c 100644 --- a/application/models/reports/Summary_discounts.php +++ b/application/models/reports/Summary_discounts.php @@ -13,17 +13,23 @@ class Summary_discounts extends Summary_report public function getData(array $inputs) { - $this->db->select('MAX(CONCAT(sales_items.discount_percent, "%")) AS discount_percent, count(*) AS count'); + if($inputs['discount_type']==1){ + $this->db->select('MAX(CONCAT("'.$this->config->item('currency_symbol').'",sales_items.discount_fixed)) AS discount, count(*) AS count'); + $this->db->where('discount_fixed > 0'); + $this->db->group_by('sales_items.discount_fixed'); + $this->db->order_by('sales_items.discount_fixed'); + }else{ + $this->db->select('MAX(CONCAT(sales_items.discount_percent, "%")) AS discount, count(*) AS count'); + $this->db->where('discount_percent > 0'); + $this->db->group_by('sales_items.discount_percent'); + $this->db->order_by('sales_items.discount_percent'); + } + $this->db->from('sales_items AS sales_items'); $this->db->join('sales AS sales', 'sales_items.sale_id = sales.sale_id', 'inner'); - $this->db->where('discount_percent > 0'); - $this->_where($inputs); - $this->db->group_by('sales_items.discount_percent'); - $this->db->order_by('sales_items.discount_percent'); - return $this->db->get()->result_array(); } } diff --git a/application/models/reports/Summary_payments.php b/application/models/reports/Summary_payments.php index 84ca25002..cbb842b4f 100644 --- a/application/models/reports/Summary_payments.php +++ b/application/models/reports/Summary_payments.php @@ -14,7 +14,7 @@ class Summary_payments extends Summary_report public function getData(array $inputs) { - $this->db->select('sales_payments.payment_type, COUNT(DISTINCT sales_payments.sale_id) AS count, SUM(sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)) AS payment_amount'); + $this->db->select('sales_payments.payment_type, COUNT(DISTINCT sales_payments.sale_id) AS count, SUM(sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)-sales_items.discount_fixed) AS payment_amount'); $this->db->from('sales_payments AS sales_payments'); $this->db->join('sales AS sales', 'sales.sale_id = sales_payments.sale_id'); $this->db->join('sales_items AS sales_items', 'sales_items.sale_id = sales_payments.sale_id', 'left'); diff --git a/application/models/reports/Summary_report.php b/application/models/reports/Summary_report.php index a974336e4..9315361d0 100644 --- a/application/models/reports/Summary_report.php +++ b/application/models/reports/Summary_report.php @@ -23,7 +23,7 @@ abstract class Summary_report extends Report $decimals = totals_decimals(); - $sale_price = 'sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)'; + $sale_price = 'sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)-sales_items.discount_fixed'; $sale_cost = 'SUM(sales_items.item_cost_price * sales_items.quantity_purchased)'; $tax = 'IFNULL(SUM(sales_items_taxes.tax), 0)'; diff --git a/application/views/configs/general_config.php b/application/views/configs/general_config.php index 0a470281c..2ea8a1029 100644 --- a/application/views/configs/general_config.php +++ b/application/views/configs/general_config.php @@ -11,6 +11,17 @@ +
+ lang->line('config_default_sales_discount_type'), 'default_sales_discount_type', array('class' => 'control-label col-xs-2')); ?> +
+ 'default_sales_discount_type', + 'id' => 'default_sales_discount_type', + 'value' => 'default_sales_discount_type', + 'checked' => $this->config->item('default_sales_discount_type'))); ?> +
+
+
lang->line('config_default_sales_discount'), 'default_sales_discount', array('class' => 'control-label col-xs-2 required')); ?>
@@ -26,6 +37,18 @@ %
+
+
+ config->item('currency_symbol'); ?> + 'default_sales_discount_fixed', + 'id' => 'default_sales_discount_fixed', + 'class' => 'form-control input-sm required', + 'type' => 'number', + 'min' => 0, + 'value' => $this->config->item('default_sales_discount_fixed'))); ?> +
+
diff --git a/application/views/customers/form.php b/application/views/customers/form.php index 13600af9c..1b32fb78f 100644 --- a/application/views/customers/form.php +++ b/application/views/customers/form.php @@ -53,6 +53,21 @@ ); ?> %
+ + +
+
+ config->item('currency_symbol'); ?> + 'discount_fixed', + 'size'=>'5', + 'maxlength'=>'5', + 'id'=>'discount_fixed', + 'class'=>'form-control input-sm', + 'value'=>$person_info->discount_fixed) + );?> + +
diff --git a/application/views/item_kits/form.php b/application/views/item_kits/form.php index 72dc17e87..e767346a7 100644 --- a/application/views/item_kits/form.php +++ b/application/views/item_kits/form.php @@ -48,6 +48,21 @@ % + +
+
+ config->item('currency_symbol'); ?> + 'kit_discount_fixed', + 'size'=>'5', + 'maxlength'=>'5', + 'id'=>'kit_discount_fixed', + 'class'=>'form-control input-sm', + 'value'=>$item_kit_info->kit_discount_fixed) + );?> + +
+
diff --git a/application/views/partial/header.php b/application/views/partial/header.php index dd8be8928..f9b66606c 100644 --- a/application/views/partial/header.php +++ b/application/views/partial/header.php @@ -20,6 +20,7 @@ + @@ -60,6 +61,7 @@ + @@ -72,10 +74,10 @@ - + - + diff --git a/application/views/receivings/receipt.php b/application/views/receivings/receipt.php index 0d3d4bfde..b14a71a50 100644 --- a/application/views/receivings/receipt.php +++ b/application/views/receivings/receipt.php @@ -97,6 +97,16 @@ + 0 ) + { + ?> + + lang->line("sales_discount")?> + + diff --git a/application/views/receivings/receiving.php b/application/views/receivings/receiving.php index ae131f6bf..7baf6cf7a 100644 --- a/application/views/receivings/receiving.php +++ b/application/views/receivings/receiving.php @@ -103,11 +103,11 @@ if (isset($success)) lang->line('common_delete'); ?> - lang->line('receivings_item_name'); ?> + lang->line('receivings_item_name'); ?> lang->line('receivings_cost'); ?> lang->line('receivings_quantity'); ?> lang->line('receivings_ship_pack'); ?> - lang->line('receivings_discount'); ?> + lang->line('receivings_discount'); ?> lang->line('receivings_total'); ?> lang->line('receivings_update'); ?> @@ -163,18 +163,46 @@ if (isset($success)) if ($items_module_allowed && $mode!='requisition') { ?> - 'discount', 'class'=>'form-control input-sm', 'value'=>$item['discount']));?> + +
+ 'discount_fixed', 'class'=>'form-control input-sm', 'value'=>to_decimals($item['discount_fixed'], 0), 'onClick'=>'this.select();')); + echo form_hidden('discount', $item['discount']); + } + else + { + echo form_input(array('name'=>'discount', 'class'=>'form-control input-sm', 'value'=>to_decimals($item['discount'], 0), 'onClick'=>'this.select();')); + echo form_hidden('discount_fixed', $item['discount_fixed']); + } + ?> + + 'discount_toggle', 'name'=>'discount_toggle', 'value'=>1, 'data-toggle'=>"toggle",'data-size'=>'small', 'data-onstyle'=>'success', 'data-on'=>''.$this->config->item('currency_symbol').'', 'data-off'=>'%', 'data-line'=>$line, 'checked'=>$item['discount_type'])); ?> + + + +
+ - + + - + lang->line('receivings_update')?> > @@ -503,10 +531,17 @@ $(document).ready(function() } } - $('[name="price"],[name="quantity"],[name="receiving_quantity"],[name="discount"],[name="description"],[name="serialnumber"]').change(function() { + $('[name="price"],[name="quantity"],[name="receiving_quantity"],[name="discount"],[name="discount_fixed"],[name="description"],[name="serialnumber"]').change(function() { $(this).parents("tr").prevAll("form:first").submit() }); + $('[name="discount_toggle"]').change(function() { + + var input = $("").attr("type", "hidden").attr("name", "discount_type").val(($(this).prop('checked'))?1:0); + $('#cart_'+ $(this).attr('data-line')).append($(input)); + $('#cart_'+ $(this).attr('data-line')).submit(); + }); + }); diff --git a/application/views/reports/date_input.php b/application/views/reports/date_input.php index ee70710bc..979375bb7 100644 --- a/application/views/reports/date_input.php +++ b/application/views/reports/date_input.php @@ -55,6 +55,20 @@ if(isset($error)) } ?> + +
+ lang->line('reports_discount_type'), 'reports_discount_type_label', array('class'=>'required control-label col-xs-2')); ?> +
+ config->item('default_sales_discount_type'), array('id'=>'discount_type_id', 'class'=>'form-control')); ?> +
+
+ + 1) { @@ -88,7 +102,7 @@ $(document).ready(function() $("#generate_report").click(function() { - window.location = [window.location, start_date, end_date, $("#input_type").val() || 0, $("#location_id").val()].join("/"); + window.location = [window.location, start_date, end_date, $("#input_type").val() || 0, $("#location_id").val(), $("#discount_type_id").val() || 0 ].join("/"); }); }); diff --git a/application/views/reports/specific_input.php b/application/views/reports/specific_input.php index 1d368fa92..b31bfda1b 100644 --- a/application/views/reports/specific_input.php +++ b/application/views/reports/specific_input.php @@ -22,11 +22,42 @@ if(isset($error))
+ +
+ lang->line('reports_discount_type'), 'reports_discount_type_label', array('class'=>'required control-label col-xs-2')); ?> +
+ config->item('default_sales_discount_type'), array('id'=>'discount_type_id', 'class'=>'form-control')); ?> +
+
+ +
'required control-label col-xs-2')); ?> -
+
+ + +
+ 'discount_fixed', + 'id' => 'discount_fixed', + 'class' => 'form-control input-sm required', + 'type' => 'number', + 'min' => 0, + 'value' => $this->config->item('default_sales_discount_fixed'))); ?> +
+
@@ -51,11 +82,38 @@ if(isset($error)) diff --git a/application/views/sales/invoice.php b/application/views/sales/invoice.php index 96642a7c6..c1a6018ba 100755 --- a/application/views/sales/invoice.php +++ b/application/views/sales/invoice.php @@ -133,7 +133,7 @@ $(document).ready(function() - + 0): ?> diff --git a/application/views/sales/invoice_email.php b/application/views/sales/invoice_email.php index 8c75369b7..72c0c6259 100644 --- a/application/views/sales/invoice_email.php +++ b/application/views/sales/invoice_email.php @@ -96,7 +96,7 @@ - + 0): ?> diff --git a/application/views/sales/quote.php b/application/views/sales/quote.php index 49d28e5c5..a37acd8bf 100644 --- a/application/views/sales/quote.php +++ b/application/views/sales/quote.php @@ -135,7 +135,7 @@ if (isset($error_message)) + cols="6"> 0): ?> diff --git a/application/views/sales/quote_email.php b/application/views/sales/quote_email.php index 164062c35..051801575 100644 --- a/application/views/sales/quote_email.php +++ b/application/views/sales/quote_email.php @@ -96,7 +96,7 @@ - + 0): ?> diff --git a/application/views/sales/receipt_default.php b/application/views/sales/receipt_default.php index f2cbc2407..9192f4f86 100644 --- a/application/views/sales/receipt_default.php +++ b/application/views/sales/receipt_default.php @@ -102,6 +102,17 @@ 0) + { + ?> + + lang->line("sales_discount") ?> + + + diff --git a/application/views/sales/receipt_email.php b/application/views/sales/receipt_email.php index a8e0c04b1..7cbef7fed 100644 --- a/application/views/sales/receipt_email.php +++ b/application/views/sales/receipt_email.php @@ -96,6 +96,17 @@ 0) + { + ?> + + lang->line("sales_discount") ?> + + + 0) + { ?> + + lang->line("sales_discount") ?> + + + + diff --git a/application/views/sales/register.php b/application/views/sales/register.php index 26852456a..71d9bdd5e 100644 --- a/application/views/sales/register.php +++ b/application/views/sales/register.php @@ -107,10 +107,10 @@ if(isset($success)) lang->line('common_delete'); ?> lang->line('sales_item_number'); ?> - lang->line('sales_item_name'); ?> + lang->line('sales_item_name'); ?> lang->line('sales_price'); ?> lang->line('sales_quantity'); ?> - lang->line('sales_discount'); ?> + lang->line('sales_discount'); ?> lang->line('sales_total'); ?> lang->line('sales_update'); ?> @@ -195,7 +195,27 @@ if(isset($success)) ?> - 'discount', 'class'=>'form-control input-sm', 'value'=>to_decimals($item['discount'], 0), 'tabindex'=>++$tabindex, 'onClick'=>'this.select();'));?> + +
+ 'discount_fixed', 'class'=>'form-control input-sm', 'value'=>to_decimals($item['discount_fixed'], 0), 'tabindex'=>++$tabindex, 'onClick'=>'this.select();')); + echo form_hidden('discount', $item['discount']); + } + else + { + echo form_input(array('name'=>'discount', 'class'=>'form-control input-sm', 'value'=>to_decimals($item['discount'], 0), 'tabindex'=>++$tabindex, 'onClick'=>'this.select();')); + echo form_hidden('discount_fixed', $item['discount_fixed']); + } + ?> + + 'discount_toggle', 'name'=>'discount_toggle', 'value'=>1, 'data-toggle'=>"toggle",'data-size'=>'small', 'data-onstyle'=>'success', 'data-on'=>''.$this->config->item('currency_symbol').'', 'data-off'=>'%', 'data-line'=>$line, 'checked'=>$item['discount_type'])); ?> + + + +
+ - ").submit();" title=lang->line('sales_update')?> > + lang->line('sales_update')?> > ").attr("type", "hidden").attr("name", "discount_type").val(($(this).prop('checked'))?1:0); + $('#cart_'+ $(this).attr('data-line')).append($(input)); + $('#cart_'+ $(this).attr('data-line')).submit(); + }); }); function check_payment_type() diff --git a/application/views/sales/work_order.php b/application/views/sales/work_order.php index 47d5de5a4..e4c2a01a1 100644 --- a/application/views/sales/work_order.php +++ b/application/views/sales/work_order.php @@ -123,7 +123,7 @@ if(isset($error_message)) - + diff --git a/application/views/sales/work_order_email.php b/application/views/sales/work_order_email.php index 29aac70b9..0e68305ce 100644 --- a/application/views/sales/work_order_email.php +++ b/application/views/sales/work_order_email.php @@ -87,7 +87,7 @@ - + Date: Mon, 20 Aug 2018 15:03:09 -0500 Subject: [PATCH 02/10] Change to 3.3.0 --- application/config/config.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/config/config.php b/application/config/config.php index 8e9161fe5..3a345c88d 100644 --- a/application/config/config.php +++ b/application/config/config.php @@ -8,7 +8,7 @@ | | */ -$config['application_version'] = '3.4.0'; +$config['application_version'] = '3.3.0'; /* |-------------------------------------------------------------------------- From 8b29fc7fea328ca9d3631245c15c6f95b274032e Mon Sep 17 00:00:00 2001 From: Erastus Date: Mon, 20 Aug 2018 23:42:47 -0500 Subject: [PATCH 03/10] reports graphical discount --- application/config/routes.php | 1 + application/controllers/Reports.php | 8 ++++---- application/libraries/Sale_lib.php | 11 +++++++---- application/views/sales/register.php | 2 -- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/application/config/routes.php b/application/config/routes.php index 125471bd8..70dfe3d41 100644 --- a/application/config/routes.php +++ b/application/config/routes.php @@ -65,6 +65,7 @@ $route['reports/summary_:any'] = 'reports/date_input'; $route['reports/(graphical_:any)/([^/]+)/([^/]+)'] = 'reports/$1/$2/$3/$4'; $route['reports/graphical_summary_expenses_categories'] = 'reports/date_input_only'; +$route['reports/graphical_summary_discounts'] = 'reports/summary_discounts_input'; $route['reports/graphical_:any'] = 'reports/date_input'; $route['reports/(inventory_:any)/([^/]+)'] = 'reports/$1/$2'; diff --git a/application/controllers/Reports.php b/application/controllers/Reports.php index daf0c0704..703a3f521 100644 --- a/application/controllers/Reports.php +++ b/application/controllers/Reports.php @@ -721,9 +721,9 @@ class Reports extends Secure_Controller } //Graphical summary discounts report - public function graphical_summary_discounts($start_date, $end_date, $sale_type, $location_id = 'all') + public function graphical_summary_discounts($start_date, $end_date, $sale_type, $location_id = 'all', $discount_type=0) { - $inputs = array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type, 'location_id' => $location_id); + $inputs = array('start_date' => $start_date, 'end_date' => $end_date, 'sale_type' => $sale_type, 'location_id' => $location_id,'discount_type'=>$discount_type); $this->load->model('reports/Summary_discounts'); $model = $this->Summary_discounts; @@ -737,7 +737,7 @@ class Reports extends Secure_Controller { $row = $this->xss_clean($row); - $labels[] = $row['discount_percent']; + $labels[] = $row['discount']; $series[] = $row['count']; } @@ -749,7 +749,7 @@ class Reports extends Secure_Controller 'series_data_1' => $series, 'summary_data_1' => $summary, 'yaxis_title' => $this->lang->line('reports_count'), - 'xaxis_title' => $this->lang->line('reports_discount_percent'), + 'xaxis_title' => $this->lang->line('reports_discount'), 'show_currency' => FALSE ); diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index cad4ce1f6..e1ee8a512 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -1214,6 +1214,12 @@ class Sale_lib $item_discount = $this->get_item_discount($item['quantity'], $item['price'], $item['discount'], $item['discount_fixed']); $discount = bcadd($discount, $item_discount); } + + if($item['discount_fixed'] > 0) + { + $item_discount = $this->get_item_discount($item['quantity'], $item['price'], $item['discount'], $item['discount_fixed']); + $discount = bcadd($discount, $item_discount); + } } return $discount; @@ -1290,10 +1296,7 @@ class Sale_lib $total = bcmul($quantity, $price); $discount_fraction = bcdiv($discount_percentage, 100); - $discount_amount=bcadd(bcmul($total, $discount_fraction), $discount_fixed); - - return round($discount_amount, totals_decimals(), PHP_ROUND_HALF_UP); - + return round(bcadd(bcmul($total, $discount_fraction),$discount_fixed), totals_decimals(), PHP_ROUND_HALF_UP); } public function get_item_tax($quantity, $price, $discount_percentage, $discount_fixed, $tax_percentage) diff --git a/application/views/sales/register.php b/application/views/sales/register.php index 71d9bdd5e..6ce1ca99d 100644 --- a/application/views/sales/register.php +++ b/application/views/sales/register.php @@ -211,8 +211,6 @@ if(isset($success)) ?> 'discount_toggle', 'name'=>'discount_toggle', 'value'=>1, 'data-toggle'=>"toggle",'data-size'=>'small', 'data-onstyle'=>'success', 'data-on'=>''.$this->config->item('currency_symbol').'', 'data-off'=>'%', 'data-line'=>$line, 'checked'=>$item['discount_type'])); ?> - -
From 3b9f52de1843c2365ca89ea2c4c1452da6db7764 Mon Sep 17 00:00:00 2001 From: Erastus Date: Tue, 21 Aug 2018 01:09:57 -0500 Subject: [PATCH 04/10] update LICENSE --- LICENSE | 1 + public/license/LICENSE | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index dcea0bfc2..382f165e9 100644 --- a/LICENSE +++ b/LICENSE @@ -18,6 +18,7 @@ Copyright (c) 2017 Deep Shah (aka deepshah) Copyright (c) 2017 Joshua Fernandez (aka joshua1234511) Copyright (c) 2017 odiea Copyright (c) 2017 asadjaved63 +Copyright (c) 2018 Erasto Marroquin (aka Erastus) Copyright (c) 2018 WebShells/Shady Sh Permission is hereby granted, free of charge, to any person obtaining a copy of diff --git a/public/license/LICENSE b/public/license/LICENSE index be8743d59..382f165e9 100644 --- a/public/license/LICENSE +++ b/public/license/LICENSE @@ -18,7 +18,7 @@ Copyright (c) 2017 Deep Shah (aka deepshah) Copyright (c) 2017 Joshua Fernandez (aka joshua1234511) Copyright (c) 2017 odiea Copyright (c) 2017 asadjaved63 -Copyright (c) 2018 Erasto Marroquín (aka Erastus) +Copyright (c) 2018 Erasto Marroquin (aka Erastus) Copyright (c) 2018 WebShells/Shady Sh Permission is hereby granted, free of charge, to any person obtaining a copy of From a5f0c83e87523000f5a08b88d355983433eea0c3 Mon Sep 17 00:00:00 2001 From: Erastus Date: Tue, 21 Aug 2018 10:57:50 -0500 Subject: [PATCH 05/10] update Tax_lib --- application/libraries/Tax_lib.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/application/libraries/Tax_lib.php b/application/libraries/Tax_lib.php index 7713f62e4..6b1f987c7 100644 --- a/application/libraries/Tax_lib.php +++ b/application/libraries/Tax_lib.php @@ -31,12 +31,12 @@ class Tax_lib /* * Compute the tax basis and returns the tax amount */ - public function get_item_sales_tax($quantity, $price, $discount_percentage, $tax_percentage, $rounding_code) + public function get_item_sales_tax($quantity, $price, $discount_percentage, $discount_fixed, $tax_percentage, $rounding_code) { $decimals = tax_decimals(); // The tax basis should be returned at the currency scale - $tax_basis = $this->CI->sale_lib->get_item_total($quantity, $price, $discount_percentage, TRUE); + $tax_basis = $this->CI->sale_lib->get_item_total($quantity, $price, $discount_percentage, $discount_fixed, TRUE); return $this->get_sales_tax_for_amount($tax_basis, $tax_percentage, $rounding_code, $decimals); } @@ -223,7 +223,7 @@ class Tax_lib $decimals = tax_decimals(); // The tax basis should be returned at the currency scale - $tax_basis = $this->CI->sale_lib->get_item_total($item['quantity'], $item['price'], $item['discount'], TRUE); + $tax_basis = $this->CI->sale_lib->get_item_total($item['quantity'], $item['price'], $item['discount'], $item['discount_fixed'], TRUE); $tax_amount = $this->get_sales_tax_for_amount($tax_basis, $tax_rate, $rounding_code, $decimals); $tax_group = (float)$tax_rate . '% ' . $tax_category; From a6b11e6f482bfb4641e14fb9e45bb484f71f15e1 Mon Sep 17 00:00:00 2001 From: Erastus Date: Fri, 31 Aug 2018 15:27:44 -0500 Subject: [PATCH 06/10] new discount on sales --- application/controllers/Config.php | 1 - application/controllers/Customers.php | 8 +- application/controllers/Receivings.php | 3 +- application/controllers/Reports.php | 10 +- application/controllers/Sales.php | 53 ++++------- application/language/en-US/config_lang.php | 2 +- application/language/en-US/customers_lang.php | 3 + .../language/en-US/receivings_lang.php | 2 +- application/language/en-US/reports_lang.php | 2 + application/language/es/config_lang.php | 3 +- application/language/es/customers_lang.php | 3 + application/language/es/receivings_lang.php | 2 +- application/libraries/Receiving_lib.php | 29 +++--- application/libraries/Sale_lib.php | 92 ++++++++----------- application/libraries/Tax_lib.php | 6 +- ...p => 20180820100000_discount_on_sales.php} | 4 +- .../migrations/sqlscripts/3.3.0_to_3.4.0.sql | 22 ----- .../sqlscripts/discount_on_sales.sql | 24 +++++ application/models/Customer.php | 5 +- application/models/Receiving.php | 13 ++- application/models/Sale.php | 24 ++--- .../models/reports/Detailed_receivings.php | 2 +- application/models/reports/Detailed_sales.php | 2 +- .../models/reports/Specific_discount.php | 17 ++-- .../models/reports/Specific_employee.php | 2 +- .../models/reports/Summary_discounts.php | 24 +++-- .../models/reports/Summary_payments.php | 2 +- application/models/reports/Summary_report.php | 2 +- application/models/reports/Summary_taxes.php | 8 +- application/views/configs/general_config.php | 37 +++----- application/views/customers/form.php | 48 ++++++---- application/views/receivings/receipt.php | 25 ++--- application/views/receivings/receiving.php | 30 +----- application/views/sales/invoice.php | 2 +- application/views/sales/invoice_email.php | 2 +- application/views/sales/quote.php | 2 +- application/views/sales/quote_email.php | 2 +- application/views/sales/receipt_default.php | 27 +++--- application/views/sales/receipt_email.php | 26 +++--- application/views/sales/receipt_short.php | 26 +++--- application/views/sales/register.php | 19 +--- application/views/sales/work_order.php | 2 +- application/views/sales/work_order_email.php | 2 +- import_customers.csv | 2 +- 44 files changed, 288 insertions(+), 334 deletions(-) rename application/migrations/{20180820100000_upgrade_to_3_4_0.php => 20180820100000_discount_on_sales.php} (61%) delete mode 100644 application/migrations/sqlscripts/3.3.0_to_3.4.0.sql create mode 100644 application/migrations/sqlscripts/discount_on_sales.sql diff --git a/application/controllers/Config.php b/application/controllers/Config.php index 673abf527..6bc838c7e 100644 --- a/application/controllers/Config.php +++ b/application/controllers/Config.php @@ -287,7 +287,6 @@ 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_sales_discount_fixed' => $this->input->post('default_sales_discount_fixed'), '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/Customers.php b/application/controllers/Customers.php index 30b409c6d..68f0f5318 100644 --- a/application/controllers/Customers.php +++ b/application/controllers/Customers.php @@ -248,8 +248,8 @@ class Customers extends Persons 'consent' => $this->input->post('consent') != NULL, 'account_number' => $this->input->post('account_number') == '' ? NULL : $this->input->post('account_number'), 'company_name' => $this->input->post('company_name') == '' ? NULL : $this->input->post('company_name'), - 'discount_percent' => $this->input->post('discount_percent') == '' ? 0.00 : $this->input->post('discount_percent'), - 'discount_fixed' => $this->input->post('discount_fixed') == '' ? 0.00 : $this->input->post('discount_fixed'), + 'discount' => $this->input->post('discount') == '' ? 0.00 : $this->input->post('discount'), + 'discount_type' => $this->input->post('discount_type') == NULL ? PERCENT : $this->input->post('discount_type'), 'package_id' => $this->input->post('package_id') == '' ? NULL : $this->input->post('package_id'), 'taxable' => $this->input->post('taxable') != NULL, 'date' => $date_formatter->format('Y-m-d H:i:s'), @@ -404,8 +404,8 @@ class Customers extends Persons $customer_data = array( 'consent' => $consent, 'company_name' => $data[13], - 'discount_percent' => $data[15], - 'discount_fixed' => $data[16], + 'discount' => $data[15], + 'discount_type' => $data[16], 'taxable' => $data[17] == '' ? 0 : 1, 'date' => date('Y-m-d H:i:s'), 'employee_id' => $this->Employee->get_logged_in_employee_info()->person_id diff --git a/application/controllers/Receivings.php b/application/controllers/Receivings.php index ab77a5cfa..10eec315a 100644 --- a/application/controllers/Receivings.php +++ b/application/controllers/Receivings.php @@ -124,14 +124,13 @@ class Receivings extends Secure_Controller $price = parse_decimals($this->input->post('price')); $quantity = parse_decimals($this->input->post('quantity')); $discount = parse_decimals($this->input->post('discount')); - $discount_fixed = parse_decimals($this->input->post('discount_fixed')); $discount_type = parse_decimals($this->input->post('discount_type')); $item_location = $this->input->post('location'); $receiving_quantity = $this->input->post('receiving_quantity'); if($this->form_validation->run() != FALSE) { - $this->receiving_lib->edit_item($item_id, $description, $serialnumber, $quantity, $discount, $discount_fixed, $discount_type, $price, $receiving_quantity); + $this->receiving_lib->edit_item($item_id, $description, $serialnumber, $quantity, $discount, $discount_type, $price, $receiving_quantity); } else { diff --git a/application/controllers/Reports.php b/application/controllers/Reports.php index 703a3f521..3466d1ba3 100644 --- a/application/controllers/Reports.php +++ b/application/controllers/Reports.php @@ -884,7 +884,7 @@ class Reports extends Secure_Controller to_currency($drow['total']), to_currency($drow['cost']), to_currency($drow['profit']), - $drow['discount_percent'].'% | '.to_currency($drow['discount_fixed']))); + ($drow['discount_type'] == PERCENT)? $drow['discount'].'%':to_currency($drow['discount']))); } if(isset($report_data['rewards'][$key])) @@ -995,7 +995,7 @@ class Reports extends Secure_Controller to_currency($drow['total']), to_currency($drow['cost']), to_currency($drow['profit']), - $drow['discount_percent'].'% | '.to_currency($drow['discount_fixed']))); + ($drow['discount_type'] == PERCENT)? $drow['discount'].'%':to_currency($drow['discount']))); } if(isset($report_data['rewards'][$key])) @@ -1103,7 +1103,7 @@ class Reports extends Secure_Controller to_currency($drow['total']), to_currency($drow['cost']), to_currency($drow['profit']), - $drow['discount_percent'].'% | '.to_currency($drow['discount_fixed']))); + ($drow['discount_type'] == PERCENT)? $drow['discount'].'%':to_currency($drow['discount']))); } if(isset($report_data['rewards'][$key])) @@ -1256,7 +1256,7 @@ class Reports extends Secure_Controller to_currency($drow['total']), to_currency($drow['cost']), to_currency($drow['profit']), - $drow['discount_percent'].'% | '.to_currency($drow['discount_fixed']))); + ($drow['discount_type'] == PERCENT)? $drow['discount'].'%':to_currency($drow['discount']))); } if(isset($report_data['rewards'][$key])) @@ -1358,7 +1358,7 @@ class Reports extends Secure_Controller $drow['category'], $quantity_purchased, to_currency($drow['total']), - $drow['discount_percent'].'% | '.to_currency($drow['discount_fixed']))); + ($drow['discount_type'] == PERCENT)? $drow['discount'].'%':to_currency($drow['discount']))); } } diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index 32ea7350f..f157f45c0 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -136,13 +136,13 @@ class Sales extends Secure_Controller if($this->Customer->exists($customer_id)) { $this->sale_lib->set_customer($customer_id); - $discount_percent = $this->Customer->get_info($customer_id)->discount_percent; - $discount_fixed = $this->Customer->get_info($customer_id)->discount_fixed; + $discount = $this->Customer->get_info($customer_id)->discount; + $discount_type = $this->Customer->get_info($customer_id)->discount_type; // apply customer default discount to items that have 0 discount - if($discount_percent != '' OR $discount_fixed != '') + if($discount != '') { - $this->sale_lib->apply_customer_discount($discount_percent, $discount_fixed); + $this->sale_lib->apply_customer_discount($discount, $discount_type); } } @@ -368,7 +368,6 @@ class Sales extends Secure_Controller $data = array(); $discount = 0; - $discount_fixed = 0; $discount_type = $this->config->item('default_sales_discount_type'); // check if any discount is assigned to the selected customer @@ -376,18 +375,12 @@ class Sales extends Secure_Controller if($customer_id != -1) { // load the customer discount if any - $discount_percent = $this->Customer->get_info($customer_id)->discount_percent; - $discount_cash = $this->Customer->get_info($customer_id)->discount_fixed; - if($discount_percent != '') + $customer_discount = $this->Customer->get_info($customer_id)->discount; + $customer_discount_type = $this->Customer->get_info($customer_id)->discount_type; + if($customer_discount != '') { - $discount = $discount_percent; - $discount_type = 0; - } - - if($discount_cash != '') - { - $discount_fixed = $discount_cash; - $discount_type = 1; + $discount = $customer_discount; + $discount_type = $customer_discount_type; } } @@ -397,11 +390,6 @@ class Sales extends Secure_Controller $discount = $this->config->item('default_sales_discount'); } - if($discount_fixed == 0) - { - $discount_fixed = $this->config->item('default_sales_discount_fixed'); - } - $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(); @@ -422,14 +410,10 @@ 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_percent != 0 && $item_kit_info->kit_discount_percent > $discount) + if($item_kit_info->kit_discount != 0 && $item_kit_info->kit_discount > $discount) { - $discount = $item_kit_info->kit_discount_percent; - } - - if($item_kit_info->kit_discount_fixed != 0 && $item_kit_info->kit_discount_fixed > $discount_fixed) - { - $discount_fixed = $item_kit_info->kit_discount_fixed; + $discount = $item_kit_info->kit_discount; + $discount_type = $item_kit_info->discount_type; } $price = NULL; @@ -437,7 +421,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_fixed, $discount_type, PRICE_MODE_STANDARD)) + if(!$this->sale_lib->add_item($kit_item_id, $quantity, $item_location, $discount, $discount_type, PRICE_MODE_STANDARD)) { $data['error'] = $this->lang->line('sales_unable_to_add_item'); } @@ -449,7 +433,7 @@ class Sales extends Secure_Controller // Add item kit items to order $stock_warning = NULL; - if(!$this->sale_lib->add_item_kit($item_id_or_number_or_item_kit_or_receipt, $item_location, $discount, $discount_fixed, $discount_type, $kit_price_option, $kit_print_option, $stock_warning)) + if(!$this->sale_lib->add_item_kit($item_id_or_number_or_item_kit_or_receipt, $item_location, $discount, $discount_type, $kit_price_option, $kit_print_option, $stock_warning)) { $data['error'] = $this->lang->line('sales_unable_to_add_item'); } @@ -460,7 +444,7 @@ class Sales extends Secure_Controller } else { - if(!$this->sale_lib->add_item($item_id_or_number_or_item_kit_or_receipt, $quantity, $item_location, $discount, $discount_fixed, $discount_type, PRICE_MODE_STANDARD)) + if(!$this->sale_lib->add_item($item_id_or_number_or_item_kit_or_receipt, $quantity, $item_location, $discount, $discount_type, PRICE_MODE_STANDARD)) { $data['error'] = $this->lang->line('sales_unable_to_add_item'); } @@ -479,14 +463,12 @@ class Sales extends Secure_Controller $this->form_validation->set_rules('price', 'lang:sales_price', 'required|callback_numeric'); $this->form_validation->set_rules('quantity', 'lang:sales_quantity', 'required|callback_numeric'); $this->form_validation->set_rules('discount', 'lang:sales_discount', 'required|callback_numeric'); - $this->form_validation->set_rules('discount_fixed', 'lang:sales_discount', 'required|callback_numeric'); $description = $this->input->post('description'); $serialnumber = $this->input->post('serialnumber'); $price = parse_decimals($this->input->post('price')); $quantity = parse_decimals($this->input->post('quantity')); $discount = parse_decimals($this->input->post('discount')); - $discount_fixed = parse_decimals($this->input->post('discount_fixed')); $discount_type = $this->input->post('discount_type'); $item_location = $this->input->post('location'); @@ -494,7 +476,7 @@ class Sales extends Secure_Controller if($this->form_validation->run() != FALSE) { - $this->sale_lib->edit_item($item_id, $description, $serialnumber, $quantity, $discount, $discount_fixed, $discount_type, $price, $discounted_total); + $this->sale_lib->edit_item($item_id, $description, $serialnumber, $quantity, $discount, $discount_type, $price, $discounted_total); } else { @@ -886,7 +868,8 @@ class Sales extends Secure_Controller $data['customer_location'] = ''; } $data['customer_account_number'] = $customer_info->account_number; - $data['customer_discount_percent'] = $customer_info->discount_percent; + $data['customer_discount'] = $customer_info->discount; + $data['customer_discount_type'] = $customer_info->discount_type; $package_id = $this->Customer->get_info($customer_id)->package_id; if($package_id != NULL) { diff --git a/application/language/en-US/config_lang.php b/application/language/en-US/config_lang.php index a1ac16e7b..c8ac08139 100644 --- a/application/language/en-US/config_lang.php +++ b/application/language/en-US/config_lang.php @@ -78,7 +78,7 @@ $lang["config_default_barcode_page_width_required"] = "Default Barcode Page Widt $lang["config_default_barcode_width_number"] = "Default Barcode Width must be a number."; $lang["config_default_barcode_width_required"] = "Default Barcode Width is a required field."; $lang["config_default_origin_tax_code"] = "Default Origin Tax Code"; -$lang["config_default_sales_discount"] = "Default Sales Discount %"; +$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_name_number"] = "Default Tax Name must be a string."; diff --git a/application/language/en-US/customers_lang.php b/application/language/en-US/customers_lang.php index 8f3d9f26f..c98bbdcc6 100644 --- a/application/language/en-US/customers_lang.php +++ b/application/language/en-US/customers_lang.php @@ -48,3 +48,6 @@ $lang["customers_taxable"] = "Taxable"; $lang["customers_total"] = "Total spent"; $lang["customers_update"] = "Update Customer"; $lang["rewards_package"] = "Rewards Package"; +$lang["customers_discount_type"] = "Discount Type"; +$lang["customers_discount_fixed"] = "Fixed Discount"; +$lang["customers_discount_percent"] = "Percentage Discount"; \ No newline at end of file diff --git a/application/language/en-US/receivings_lang.php b/application/language/en-US/receivings_lang.php index 0f4138555..ee234e76a 100644 --- a/application/language/en-US/receivings_lang.php +++ b/application/language/en-US/receivings_lang.php @@ -12,7 +12,7 @@ $lang["receivings_date"] = "Receiving Date"; $lang["receivings_date_required"] = "A correct date must be entered."; $lang["receivings_date_type"] = "Date is a required field."; $lang["receivings_delete_entire_sale"] = "Delete Entire Sale"; -$lang["receivings_discount"] = "Discount %"; +$lang["receivings_discount"] = "Discount"; $lang["receivings_edit"] = "Edit"; $lang["receivings_edit_sale"] = "Edit Receiving"; $lang["receivings_employee"] = "Employee"; diff --git a/application/language/en-US/reports_lang.php b/application/language/en-US/reports_lang.php index 4563efcb4..8d03ffa46 100644 --- a/application/language/en-US/reports_lang.php +++ b/application/language/en-US/reports_lang.php @@ -123,3 +123,5 @@ $lang["reports_unit_price"] = "Retail Price"; $lang["reports_used"] = "Points Used"; $lang["reports_work_orders"] = "Work Orders"; $lang["reports_zero_and_less"] = "Zero and less"; +$lang["reports_discount_type"] = "Discount Type"; +$lang["reports_discount_fixed"] = "Fixed Discount"; \ No newline at end of file diff --git a/application/language/es/config_lang.php b/application/language/es/config_lang.php index f23f04eba..c16e03c01 100644 --- a/application/language/es/config_lang.php +++ b/application/language/es/config_lang.php @@ -78,7 +78,7 @@ $lang["config_default_barcode_page_width_required"] = "Ancho de página del cód $lang["config_default_barcode_width_number"] = "Ancho del código de barras debe ser número."; $lang["config_default_barcode_width_required"] = "Ancho del código de barras es requerido."; $lang["config_default_origin_tax_code"] = "Código de impuesto por defecto"; -$lang["config_default_sales_discount"] = "% de Descuento en Ventas predeterminado"; +$lang["config_default_sales_discount"] = "Descuento en Ventas predeterminado"; $lang["config_default_sales_discount_number"] = "Descuento en ventas predeterminado debe ser un número."; $lang["config_default_sales_discount_required"] = "Descuento en ventas predeterminado es requerido."; $lang["config_default_tax_name_number"] = "El nombre de el impuesto debe ser letras."; @@ -271,4 +271,3 @@ $lang["config_top"] = "Arriba"; $lang["config_website"] = "Sitio Web"; $lang["config_work_order_enable"] = "Soporte Ordenes de Trabajo"; $lang["config_work_order_format"] = "Formato Ordenes de trabajo"; -$lang["config_default_sales_discount_type"] = "Descuento Fijo en Ventas predeterminado"; \ No newline at end of file diff --git a/application/language/es/customers_lang.php b/application/language/es/customers_lang.php index b91aaeb99..86dd81f9c 100644 --- a/application/language/es/customers_lang.php +++ b/application/language/es/customers_lang.php @@ -48,3 +48,6 @@ $lang["customers_taxable"] = "Gravable"; $lang["customers_total"] = "Total"; $lang["customers_update"] = "Actualizar Cliente"; $lang["rewards_package"] = "Paquete de premios"; +$lang["customers_discount_type"] = "Tipo de Descuento"; +$lang["customers_discount_fixed"] = "Descuento Fijo"; +$lang["customers_discount_percent"] = "Descuento en Porcentaje"; diff --git a/application/language/es/receivings_lang.php b/application/language/es/receivings_lang.php index c64755aed..b9f5227d4 100644 --- a/application/language/es/receivings_lang.php +++ b/application/language/es/receivings_lang.php @@ -12,7 +12,7 @@ $lang["receivings_date"] = "Fecha de Recepción"; $lang["receivings_date_required"] = "Una fecha correcta debe ser ingresada."; $lang["receivings_date_type"] = "Campo Fecha es requerido."; $lang["receivings_delete_entire_sale"] = "Borrar venta completa"; -$lang["receivings_discount"] = "Descuento %"; +$lang["receivings_discount"] = "Descuento"; $lang["receivings_edit"] = "Editar"; $lang["receivings_edit_sale"] = "Editar Recepción"; $lang["receivings_employee"] = "Empleado"; diff --git a/application/libraries/Receiving_lib.php b/application/libraries/Receiving_lib.php index 5e78c9df3..218cc1242 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, $discount_fixed = 0, $price = NULL, $description = NULL, $serialnumber = NULL, $receiving_quantity = NULL, $include_deleted = FALSE) + 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, $include_deleted = FALSE) { //make sure item exists in database. if(!$this->CI->Item->exists($item_id, $include_deleted)) @@ -242,13 +242,12 @@ class Receiving_lib 'is_serialized' => $item_info->is_serialized, 'quantity' => $quantity, 'discount' => $discount, - 'discount_fixed' => $discount_fixed, 'discount_type' => $discount_type, 'in_stock' => $this->CI->Item_quantity->get_item_quantity($item_id, $item_location)->quantity, 'price' => $price, 'receiving_quantity' => $receiving_quantity, 'receiving_quantity_choices' => $receiving_quantity_choices, - 'total' => $this->get_item_total($quantity, $price, $discount, $discount_fixed, $receiving_quantity) + 'total' => $this->get_item_total($quantity, $price, $discount, $discount_type, $receiving_quantity) ) ); @@ -256,7 +255,7 @@ class Receiving_lib if($itemalreadyinsale) { $items[$updatekey]['quantity'] += $quantity; - $items[$updatekey]['total'] = $this->get_item_total($items[$updatekey]['quantity'], $price, $discount, $discount_fixed, $items[$updatekey]['receiving_quantity']); + $items[$updatekey]['total'] = $this->get_item_total($items[$updatekey]['quantity'], $price, $discount, $discount_type, $items[$updatekey]['receiving_quantity']); } else { @@ -269,7 +268,7 @@ class Receiving_lib return TRUE; } - public function edit_item($line, $description, $serialnumber, $quantity, $discount, $discount_fixed, $discount_type, $price, $receiving_quantity) + public function edit_item($line, $description, $serialnumber, $quantity, $discount, $discount_type, $price, $receiving_quantity) { $items = $this->get_cart(); if(isset($items[$line])) @@ -280,12 +279,11 @@ class Receiving_lib $line['quantity'] = $quantity; $line['receiving_quantity'] = $receiving_quantity; $line['discount'] = $discount; - $line['discount_fixed'] = $discount_fixed; if(!is_null($discount_type)){ $line['discount_type'] = $discount_type; } $line['price'] = $price; - $line['total'] = $this->get_item_total($quantity, $price, $discount, $discount_fixed, $receiving_quantity); + $line['total'] = $this->get_item_total($quantity, $price, $discount, $discount_type, $receiving_quantity); $this->set_cart($items); } @@ -318,7 +316,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_percent, $row->discount_fixed, $row->item_unit_price, $row->description, $row->serialnumber, $row->receiving_quantity, TRUE); + $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, TRUE); } $this->set_supplier($this->CI->Receiving->get_supplier($receiving_id)->person_id); @@ -343,7 +341,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_percent, $row->discount_fixed, $row->item_unit_price, $row->description, $row->serialnumber, $row->receiving_quantity, TRUE); + $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, TRUE); } $this->set_supplier($this->CI->Receiving->get_supplier($receiving_id)->person_id); @@ -359,12 +357,17 @@ class Receiving_lib $this->clear_reference(); } - public function get_item_total($quantity, $price, $discount_percentage, $discount_fixed, $receiving_quantity) + public function get_item_total($quantity, $price, $discount, $discount_type, $receiving_quantity) { $extended_quantity = bcmul($quantity, $receiving_quantity); $total = bcmul($extended_quantity, $price); - $discount_fraction = bcdiv($discount_percentage, 100); - $discount_amount = bcadd(bcmul($total, $discount_fraction), $discount_fixed); + $discount_amount = $discount; + if($discount_type == PERCENT) + { + $discount_fraction = bcdiv($discount, 100); + $discount_amount = bcmul($total, $discount_fraction); + } + return bcsub($total, $discount_amount); } @@ -374,7 +377,7 @@ class Receiving_lib $total = 0; foreach($this->get_cart() as $item) { - $total = bcadd($total, $this->get_item_total(($item['quantity']), $item['price'], $item['discount'], $item['discount_fixed'], $item['receiving_quantity'])); + $total = bcadd($total, $this->get_item_total(($item['quantity']), $item['price'], $item['discount'], $item['discount_type'], $item['receiving_quantity'])); } return $total; diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index e1ee8a512..528459fa6 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -450,7 +450,7 @@ class Sale_lib $item_count++; $total_units += $item['quantity']; } - $discount_amount = $this->get_item_discount($item['quantity'], $item['price'], $item['discount'], $item['discount_fixed']); + $discount_amount = $this->get_item_discount($item['quantity'], $item['price'], $item['discount'], $item['discount_type']); $total_discount = bcadd($total_discount, $discount_amount); $extended_amount = $this->get_extended_amount($item['quantity'], $item['price']); @@ -460,7 +460,7 @@ class Sale_lib if($this->CI->config->item('tax_included')) { - $subtotal = bcadd($subtotal, $this->get_extended_total_tax_exclusive($item['item_id'], $extended_discounted_amount, $item['quantity'], $item['price'], $item['discount'],$item['discount_fixed'])); + $subtotal = bcadd($subtotal, $this->get_extended_total_tax_exclusive($item['item_id'], $extended_discounted_amount, $item['quantity'], $item['price'], $item['discount'],$item['discount_type'])); } else { @@ -696,7 +696,7 @@ class Sale_lib $this->CI->session->unset_userdata('sales_rewards_remainder'); } - public function add_item(&$item_id, $quantity = 1, $item_location, $discount = 0, $discount_fixed = 0, $discount_type = 0, $price_mode = PRICE_MODE_STANDARD, $kit_price_option = NULL, $kit_print_option = NULL, $price_override = NULL, $description = NULL, $serialnumber = NULL, $include_deleted = FALSE, $print_option = NULL ) + public function add_item(&$item_id, $quantity = 1, $item_location, $discount = 0, $discount_type = 0, $price_mode = PRICE_MODE_STANDARD, $kit_price_option = NULL, $kit_print_option = NULL, $price_override = NULL, $description = NULL, $serialnumber = NULL, $include_deleted = FALSE, $print_option = NULL ) { $item_info = $this->CI->Item->get_info_by_id_or_number($item_id); @@ -753,7 +753,6 @@ class Sale_lib if($price == 0.00) { $discount = 0.00; - $discount_fixed = 0.00; } // Serialization and Description @@ -826,8 +825,8 @@ class Sale_lib } } - $total = $this->get_item_total($quantity, $price, $discount, $discount_fixed); - $discounted_total = $this->get_item_total($quantity, $price, $discount, $discount_fixed, TRUE); + $total = $this->get_item_total($quantity, $price, $discount, $discount_type); + $discounted_total = $this->get_item_total($quantity, $price, $discount, $discount_type, TRUE); if($this->CI->config->item('multi_pack_enabled') == '1') { @@ -851,7 +850,6 @@ class Sale_lib 'is_serialized' => $item_info->is_serialized, 'quantity' => $quantity, 'discount' => $discount, - 'discount_fixed' => $discount_fixed, 'discount_type' => $discount_type, 'in_stock' => $this->CI->Item_quantity->get_item_quantity($item_id, $item_location)->quantity, 'price' => $price, @@ -936,7 +934,7 @@ class Sale_lib return -1; } - public function edit_item($line, $description, $serialnumber, $quantity, $discount, $discount_fixed, $discount_type, $price, $discounted_total=NULL) + public function edit_item($line, $description, $serialnumber, $quantity, $discount, $discount_type, $price, $discounted_total=NULL) { $items = $this->get_cart(); if(isset($items[$line])) @@ -951,13 +949,12 @@ class Sale_lib $line['serialnumber'] = $serialnumber; $line['quantity'] = $quantity; $line['discount'] = $discount; - $line['discount_fixed'] = $discount_fixed; if(!is_null($discount_type)){ $line['discount_type'] = $discount_type; } $line['price'] = $price; - $line['total'] = $this->get_item_total($quantity, $price, $discount, $discount_fixed); - $line['discounted_total'] = $this->get_item_total($quantity, $price, $discount, $discount_fixed, TRUE); + $line['total'] = $this->get_item_total($quantity, $price, $discount, $line['discount_type']); + $line['discounted_total'] = $this->get_item_total($quantity, $price, $discount, $line['discount_type'], TRUE); $this->set_cart($items); } @@ -988,13 +985,13 @@ class Sale_lib foreach($this->CI->Sale->get_sale_items_ordered($sale_id)->result() as $row) { - $this->add_item($row->item_id, -$row->quantity_purchased, $row->item_location, $row->discount_percent, $row->discount_fixed, $row->discount_type, PRICE_MODE_STANDARD, NULL, NULL, $row->item_unit_price, $row->description, $row->serialnumber, TRUE); + $this->add_item($row->item_id, -$row->quantity_purchased, $row->item_location, $row->discount, $row->discount_type, PRICE_MODE_STANDARD, NULL, NULL, $row->item_unit_price, $row->description, $row->serialnumber, TRUE); } $this->set_customer($this->CI->Sale->get_customer($sale_id)->person_id); } - public function add_item_kit($external_item_kit_id, $item_location, $discount, $discount_fixed, $discount_type, $kit_price_option, $kit_print_option, &$stock_warning) + public function add_item_kit($external_item_kit_id, $item_location, $discount, $discount_type, $kit_price_option, $kit_print_option, &$stock_warning) { //KIT # $pieces = explode(' ', $external_item_kit_id); @@ -1003,7 +1000,7 @@ class Sale_lib foreach($this->CI->Item_kit_items->get_info($item_kit_id) as $item_kit_item) { - $result &= $this->add_item($item_kit_item['item_id'], $item_kit_item['quantity'], $item_location, $discount, $discount_fixed, $discount_type, PRICE_MODE_KIT, $kit_price_option, $kit_print_option, NULL, NULL, NULL, NULL); + $result &= $this->add_item($item_kit_item['item_id'], $item_kit_item['quantity'], $item_location, $discount, $discount_type, PRICE_MODE_KIT, $kit_price_option, $kit_print_option, NULL, NULL, NULL, NULL); if($stock_warning == NULL) { @@ -1021,7 +1018,7 @@ class Sale_lib foreach($this->CI->Sale->get_sale_items_ordered($sale_id)->result() as $row) { - $this->add_item($row->item_id, $row->quantity_purchased, $row->item_location, $row->discount_percent, $row->discount_fixed, $row->discount_type, PRICE_MODE_STANDARD, NULL, NULL, $row->item_unit_price, $row->description, $row->serialnumber, TRUE, $row->print_option); + $this->add_item($row->item_id, $row->quantity_purchased, $row->item_location, $row->discount, $row->discount_type, PRICE_MODE_STANDARD, NULL, NULL, $row->item_unit_price, $row->description, $row->serialnumber, TRUE, $row->print_option); } foreach($this->CI->Sale->get_sale_payments($sale_id)->result() as $row) @@ -1049,7 +1046,7 @@ class Sale_lib $this->empty_cart(); foreach($this->CI->Sale->get_sale_items_ordered($sale_id)->result() as $row) { - $this->add_item($row->item_id, $row->quantity_purchased, $row->item_location, $row->discount_percent, $row->discount_fixed, $row->discount_type, PRICE_MODE_STANDARD, NULL, NULL, $row->item_unit_price, $row->description, $row->serialnumber, TRUE, $row->print_option); + $this->add_item($row->item_id, $row->quantity_purchased, $row->item_location, $row->discount, $row->discount_type, PRICE_MODE_STANDARD, NULL, NULL, $row->item_unit_price, $row->description, $row->serialnumber, TRUE, $row->print_option); } return $this->CI->session->userdata('sales_cart'); @@ -1134,12 +1131,12 @@ class Sale_lib // This computes tax for each line item and adds it to the tax type total $tax_group = (float)$tax['percent'] . '% ' . $tax['name']; $tax_type = Tax_lib::TAX_TYPE_VAT; - $tax_basis = $this->get_item_total($item['quantity'], $item['price'], $item['discount'], $item['discount_fixed'], TRUE); + $tax_basis = $this->get_item_total($item['quantity'], $item['price'], $item['discount'], $item['discount_type'], TRUE); $tax_amount = 0; if($this->CI->config->item('tax_included')) { - $tax_amount = $this->get_item_tax($item['quantity'], $item['price'], $item['discount'], $item['discount_fixed'], $tax['percent']); + $tax_amount = $this->get_item_tax($item['quantity'], $item['price'], $item['discount'], $item['discount_type'], $tax['percent']); } elseif($this->CI->config->item('customer_sales_tax_support') == '0') { @@ -1173,7 +1170,7 @@ class Sale_lib return $sales_taxes; } - public function apply_customer_discount($discount_percent, $discount_fixed) + public function apply_customer_discount($discount, $discount_type) { // Get all items in the cart so far... $items = $this->get_cart(); @@ -1186,18 +1183,9 @@ class Sale_lib // set a new discount only if the current one is 0 if($item['discount'] == 0) { - $item['discount'] = $discount_percent; - $item['discount_fixed'] = $discount_fixed; - $item['total'] = $this->get_item_total($quantity, $price, $discount_percent, $discount_fixed); - $item['discounted_total'] = $this->get_item_total($quantity, $price, $discount_percent, $discount_fixed, TRUE); - } - - if($item['discount_fixed'] == 0) - { - $item['discount'] = $discount_percent; - $item['discount_fixed'] = $discount_fixed; - $item['total'] = $this->get_item_total($quantity, $price, $discount_percent, $discount_fixed); - $item['discounted_total'] = $this->get_item_total($quantity, $price, $discount_percent, $discount_fixed, TRUE); + $item['discount'] = $discount; + $item['total'] = $this->get_item_total($quantity, $price, $discount, $discount_type); + $item['discounted_total'] = $this->get_item_total($quantity, $price, $discount, $discount_type, TRUE); } } @@ -1211,13 +1199,7 @@ class Sale_lib { if($item['discount'] > 0) { - $item_discount = $this->get_item_discount($item['quantity'], $item['price'], $item['discount'], $item['discount_fixed']); - $discount = bcadd($discount, $item_discount); - } - - if($item['discount_fixed'] > 0) - { - $item_discount = $this->get_item_discount($item['quantity'], $item['price'], $item['discount'], $item['discount_fixed']); + $item_discount = $this->get_item_discount($item['quantity'], $item['price'], $item['discount'], $item['discount_type']); $discount = bcadd($discount, $item_discount); } } @@ -1230,39 +1212,39 @@ class Sale_lib return $this->calculate_subtotal($include_discount, $exclude_tax); } - public function get_item_total_tax_exclusive($item_id, $quantity, $price, $discount_percentage, $discount_fixed, $include_discount = FALSE) + public function get_item_total_tax_exclusive($item_id, $quantity, $price, $discount, $discount_type, $include_discount = FALSE) { $tax_info = $this->CI->Item_taxes->get_info($item_id); - $item_total = $this->get_item_total($quantity, $price, $discount_percentage, $discount_fixed, $include_discount); + $item_total = $this->get_item_total($quantity, $price, $discount, $discount_type, $include_discount); // only additive tax here foreach($tax_info as $tax) { $tax_percentage = $tax['percent']; - $item_total = bcsub($item_total, $this->get_item_tax($quantity, $price, $discount_percentage, $discount_fixed, $tax_percentage)); + $item_total = bcsub($item_total, $this->get_item_tax($quantity, $price, $discount, $discount_type, $tax_percentage)); } return $item_total; } - public function get_extended_total_tax_exclusive($item_id, $discounted_extended_amount, $quantity, $price, $discount_percentage = 0, $discount_fixed = 0) + public function get_extended_total_tax_exclusive($item_id, $discounted_extended_amount, $quantity, $price, $discount = 0, $discount_type = 0) { $tax_info = $this->CI->Item_taxes->get_info($item_id); // only additive tax here foreach($tax_info as $tax) { $tax_percentage = $tax['percent']; - $discounted_extended_amount = bcsub($discounted_extended_amount, $this->get_item_tax($quantity, $price, $discount_percentage, $discount_fixed, $tax_percentage)); + $discounted_extended_amount = bcsub($discounted_extended_amount, $this->get_item_tax($quantity, $price, $discount, $discount_type, $tax_percentage)); } return $discounted_extended_amount; } - public function get_item_total($quantity, $price, $discount_percentage, $discount_fixed, $include_discount = FALSE) + public function get_item_total($quantity, $price, $discount, $discount_type, $include_discount = FALSE) { $total = bcmul($quantity, $price); if($include_discount) { - $discount_amount = $this->get_item_discount($quantity, $price, $discount_percentage, $discount_fixed); + $discount_amount = $this->get_item_discount($quantity, $price, $discount, $discount_type); return bcsub($total, $discount_amount); } @@ -1291,17 +1273,21 @@ class Sale_lib return bcsub($extended_amount, $discount_amount); } - public function get_item_discount($quantity, $price, $discount_percentage, $discount_fixed) + public function get_item_discount($quantity, $price, $discount, $discount_type) { $total = bcmul($quantity, $price); - $discount_fraction = bcdiv($discount_percentage, 100); - - return round(bcadd(bcmul($total, $discount_fraction),$discount_fixed), totals_decimals(), PHP_ROUND_HALF_UP); + if($discount_type == PERCENT) + { + $discount_fraction = bcdiv($discount, 100); + $discount=bcmul($total,$discount_fraction); + } + + return round($discount, totals_decimals(), PHP_ROUND_HALF_UP); } - public function get_item_tax($quantity, $price, $discount_percentage, $discount_fixed, $tax_percentage) + public function get_item_tax($quantity, $price, $discount, $discount_type, $tax_percentage) { - $price = $this->get_item_total($quantity, $price, $discount_percentage, $discount_fixed, TRUE); + $price = $this->get_item_total($quantity, $price, $discount, $discount_type, TRUE); if($this->CI->config->item('tax_included')) { $tax_fraction = bcadd(100, $tax_percentage); @@ -1322,11 +1308,11 @@ class Sale_lib { if($exclude_tax && $this->CI->config->item('tax_included')) { - $subtotal = bcadd($subtotal, $this->get_item_total_tax_exclusive($item['item_id'], $item['quantity'], $item['price'], $item['discount'], $item['discount_fixed'], $include_discount)); + $subtotal = bcadd($subtotal, $this->get_item_total_tax_exclusive($item['item_id'], $item['quantity'], $item['price'], $item['discount'], $item['discount_type'], $include_discount)); } else { - $subtotal = bcadd($subtotal, $this->get_item_total($item['quantity'], $item['price'], $item['discount'], $item['discount_fixed'], $include_discount)); + $subtotal = bcadd($subtotal, $this->get_item_total($item['quantity'], $item['price'], $item['discount'], $item['discount_type'], $include_discount)); } } diff --git a/application/libraries/Tax_lib.php b/application/libraries/Tax_lib.php index 6b1f987c7..e36758b3a 100644 --- a/application/libraries/Tax_lib.php +++ b/application/libraries/Tax_lib.php @@ -31,12 +31,12 @@ class Tax_lib /* * Compute the tax basis and returns the tax amount */ - public function get_item_sales_tax($quantity, $price, $discount_percentage, $discount_fixed, $tax_percentage, $rounding_code) + public function get_item_sales_tax($quantity, $price, $discount, $discount_type, $tax_percentage, $rounding_code) { $decimals = tax_decimals(); // The tax basis should be returned at the currency scale - $tax_basis = $this->CI->sale_lib->get_item_total($quantity, $price, $discount_percentage, $discount_fixed, TRUE); + $tax_basis = $this->CI->sale_lib->get_item_total($quantity, $price, $discount, $discount_type, TRUE); return $this->get_sales_tax_for_amount($tax_basis, $tax_percentage, $rounding_code, $decimals); } @@ -223,7 +223,7 @@ class Tax_lib $decimals = tax_decimals(); // The tax basis should be returned at the currency scale - $tax_basis = $this->CI->sale_lib->get_item_total($item['quantity'], $item['price'], $item['discount'], $item['discount_fixed'], TRUE); + $tax_basis = $this->CI->sale_lib->get_item_total($item['quantity'], $item['price'], $item['discount'], $item['discount_type'], TRUE); $tax_amount = $this->get_sales_tax_for_amount($tax_basis, $tax_rate, $rounding_code, $decimals); $tax_group = (float)$tax_rate . '% ' . $tax_category; diff --git a/application/migrations/20180820100000_upgrade_to_3_4_0.php b/application/migrations/20180820100000_discount_on_sales.php similarity index 61% rename from application/migrations/20180820100000_upgrade_to_3_4_0.php rename to application/migrations/20180820100000_discount_on_sales.php index 677bad041..d0c6e401a 100644 --- a/application/migrations/20180820100000_upgrade_to_3_4_0.php +++ b/application/migrations/20180820100000_discount_on_sales.php @@ -1,6 +1,6 @@ db->dbprefix('sales') . ' AS sales INNER JOIN ' . $this->db->dbprefix('sales_items') . ' AS sales_items @@ -252,7 +252,8 @@ class Customer extends Person 'company_name' => NULL, 'account_number' => NULL, 'taxable' => 0, - 'discount_percent' => 0.00, + 'discount' => 0.00, + 'discount_type' => 0, 'package_id' => NULL, 'points' => NULL, 'sales_tax_code' => 1, diff --git a/application/models/Receiving.php b/application/models/Receiving.php index 4e1402e8c..b9c87047a 100644 --- a/application/models/Receiving.php +++ b/application/models/Receiving.php @@ -93,8 +93,7 @@ class Receiving extends CI_Model 'serialnumber' => $item['serialnumber'], 'quantity_purchased' => $item['quantity'], 'receiving_quantity' => $item['receiving_quantity'], - 'discount_percent' => $item['discount'], - 'discount_fixed' => $item['discount_fixed'], + 'discount' => $item['discount'], 'discount_type' => $item['discount_type'], 'item_cost_price' => $cur_item_info->cost_price, 'item_unit_price' => $item['price'], @@ -267,14 +266,14 @@ class Receiving extends CI_Model MAX(receivings_items.receiving_quantity) AS receiving_quantity, MAX(item_cost_price) AS item_cost_price, MAX(item_unit_price) AS item_unit_price, - MAX(discount_percent) AS discount_percent, - MAX(discount_fixed) AS discount_fixed, + MAX(discount) AS discount, + discount_type as discount_type, receivings_items.line, MAX(serialnumber) AS serialnumber, MAX(receivings_items.description) AS description, - MAX(item_unit_price * quantity_purchased * receivings_items.receiving_quantity - item_unit_price * quantity_purchased * receivings_items.receiving_quantity * discount_percent / 100) - discount_fixed AS subtotal, - MAX(item_unit_price * quantity_purchased * receivings_items.receiving_quantity - item_unit_price * quantity_purchased * receivings_items.receiving_quantity * discount_percent / 100) - discount_fixed AS total, - MAX((item_unit_price * quantity_purchased * receivings_items.receiving_quantity - item_unit_price * quantity_purchased * receivings_items.receiving_quantity * discount_percent / 100) - discount_fixed - (item_cost_price * quantity_purchased)) AS profit, + MAX(CASE WHEN receivings_items.discount_type = ' . PERCENT . ' THEN item_unit_price * quantity_purchased * receivings_items.receiving_quantity - item_unit_price * quantity_purchased * receivings_items.receiving_quantity * discount / 100 ELSE item_unit_price * quantity_purchased * receivings_items.receiving_quantity - discount END) AS subtotal, + MAX(CASE WHEN receivings_items.discount_type = ' . PERCENT . ' THEN item_unit_price * quantity_purchased * receivings_items.receiving_quantity - item_unit_price * quantity_purchased * receivings_items.receiving_quantity * discount / 100 ELSE item_unit_price * quantity_purchased * receivings_items.receiving_quantity - discount END) AS total, + MAX((CASE WHEN receivings_items.discount_type = ' . PERCENT . ' THEN item_unit_price * quantity_purchased * receivings_items.receiving_quantity - item_unit_price * quantity_purchased * receivings_items.receiving_quantity * discount / 100 ELSE item_unit_price * quantity_purchased * receivings_items.receiving_quantity - discount END) - (item_cost_price * quantity_purchased)) AS profit, MAX(item_cost_price * quantity_purchased * receivings_items.receiving_quantity ) AS cost FROM ' . $this->db->dbprefix('receivings_items') . ' AS receivings_items INNER JOIN ' . $this->db->dbprefix('receivings') . ' AS receivings diff --git a/application/models/Sale.php b/application/models/Sale.php index 65afec976..6a19f7fba 100644 --- a/application/models/Sale.php +++ b/application/models/Sale.php @@ -10,6 +10,8 @@ define('SALE_TYPE_WORK_ORDER', 2); define('SALE_TYPE_QUOTE', 3); define('SALE_TYPE_RETURN', 4); +define('PERCENT', 0); +define('FIXED', 1); /** * Sale class */ @@ -38,7 +40,7 @@ class Sale extends CI_Model $decimals = totals_decimals(); - $sale_price = 'sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)-sales_items.discount_fixed'; + $sale_price = 'CASE WHEN sales_items.discount_type = ' . PERCENT . ' THEN sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount / 100) ELSE sales_items.item_unit_price * sales_items.quantity_purchased - sales_items.discount END'; $tax = 'ROUND(IFNULL(SUM(sales_items_taxes.tax), 0), ' . $decimals . ')'; if($this->config->item('tax_included')) @@ -152,7 +154,7 @@ class Sale extends CI_Model $decimals = totals_decimals(); - $sale_price = 'sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)-sales_items.discount_fixed'; + $sale_price = 'CASE WHEN sales_items.discount_type = ' . PERCENT . ' THEN sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount / 100) ELSE sales_items.item_unit_price * sales_items.quantity_purchased - sales_items.discount END'; $sale_cost = 'SUM(sales_items.item_cost_price * sales_items.quantity_purchased)'; $tax = 'IFNULL(SUM(sales_items_taxes.tax), 0)'; @@ -652,8 +654,7 @@ class Sale extends CI_Model 'description' => character_limiter($item['description'], 255), 'serialnumber' => character_limiter($item['serialnumber'], 30), 'quantity_purchased'=> $item['quantity'], - 'discount_percent' => $item['discount'], - 'discount_fixed' => $item['discount_fixed'], + 'discount' => $item['discount'], 'discount_type' => $item['discount_type'], 'item_cost_price' => $item['cost_price'], 'item_unit_price' => $item['price'], @@ -705,7 +706,7 @@ class Sale extends CI_Model } $rounding_code = Rounding_mode::HALF_UP; // half adjust $tax_group_sequence = 0; - $item_total = $this->sale_lib->get_item_total($item['quantity'], $item['price'], $item['discount'], TRUE); + $item_total = $this->sale_lib->get_item_total($item['quantity'], $item['price'], $item['discount'], $item['discount_type'], TRUE); $tax_basis = $item_total; $item_tax_amount = 0; @@ -727,12 +728,12 @@ class Sale extends CI_Model // This computes tax for each line item and adds it to the tax type total $tax_group = (float)$row['percent'] . '% ' . $row['name']; - $tax_basis = $this->sale_lib->get_item_total($item['quantity'], $item['price'], $item['discount'], TRUE); + $tax_basis = $this->sale_lib->get_item_total($item['quantity'], $item['price'], $item['discount'], $item['discount_type'], TRUE); if($this->config->item('tax_included')) { $tax_type = Tax_lib::TAX_TYPE_VAT; - $item_tax_amount = $this->sale_lib->get_item_tax($item['quantity'], $item['price'], $item['discount'],$row['percent']); + $item_tax_amount = $this->sale_lib->get_item_tax($item['quantity'], $item['price'], $item['discount'], $item['discount_type'], $row['percent']); } elseif($this->config->item('customer_sales_tax_support') == '0') { @@ -929,8 +930,7 @@ class Sale extends CI_Model quantity_purchased, item_cost_price, item_unit_price, - discount_percent, - discount_fixed, + discount, discount_type, item_location, print_option, @@ -1117,7 +1117,7 @@ class Sale extends CI_Model $decimals = totals_decimals(); - $sale_price = 'sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)-sales_items.discount_fixed'; + $sale_price = 'CASE WHEN sales_items.discount_type = ' . PERCENT . ' THEN sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount / 100) ELSE sales_items.item_unit_price * sales_items.quantity_purchased - sales_items.discount END'; $sale_cost = 'SUM(sales_items.item_cost_price * sales_items.quantity_purchased)'; $tax = 'IFNULL(SUM(sales_items_taxes.tax), 0)'; @@ -1194,8 +1194,8 @@ class Sale extends CI_Model MAX(sales_items.quantity_purchased) AS quantity_purchased, MAX(sales_items.item_cost_price) AS item_cost_price, MAX(sales_items.item_unit_price) AS item_unit_price, - MAX(sales_items.discount_percent) AS discount_percent, - MAX(sales_items.discount_fixed) AS discount_fixed, + MAX(sales_items.discount) AS discount, + sales_items.discount_type AS discount_type, sales_items.line AS line, MAX(sales_items.serialnumber) AS serialnumber, MAX(sales_items.item_location) AS item_location, diff --git a/application/models/reports/Detailed_receivings.php b/application/models/reports/Detailed_receivings.php index 88e0e4317..695eb7498 100644 --- a/application/models/reports/Detailed_receivings.php +++ b/application/models/reports/Detailed_receivings.php @@ -97,7 +97,7 @@ class Detailed_receivings extends Report foreach($data['summary'] as $key=>$value) { - $this->db->select('name, item_number, category, quantity_purchased, serialnumber,total, discount_percent, discount_fixed, item_location, receivings_items_temp.receiving_quantity'); + $this->db->select('name, item_number, category, quantity_purchased, serialnumber,total, discount, discount_type, item_location, receivings_items_temp.receiving_quantity'); $this->db->from('receivings_items_temp'); $this->db->join('items', 'receivings_items_temp.item_id = items.item_id'); $this->db->where('receiving_id = '.$value['receiving_id']); diff --git a/application/models/reports/Detailed_sales.php b/application/models/reports/Detailed_sales.php index ab3579640..36ad0234c 100644 --- a/application/models/reports/Detailed_sales.php +++ b/application/models/reports/Detailed_sales.php @@ -144,7 +144,7 @@ class Detailed_sales extends Report foreach($data['summary'] as $key=>$value) { - $this->db->select('name, category, quantity_purchased, item_location, serialnumber, description, subtotal, tax, total, cost, profit, discount_percent, discount_fixed, sale_status'); + $this->db->select('name, category, quantity_purchased, item_location, serialnumber, description, subtotal, tax, total, cost, profit, discount, discount_type, sale_status'); $this->db->from('sales_items_temp'); $this->db->where('sale_id', $value['sale_id']); $data['details'][$key] = $this->db->get()->result_array(); diff --git a/application/models/reports/Specific_discount.php b/application/models/reports/Specific_discount.php index ab8a059e5..d46e6f037 100755 --- a/application/models/reports/Specific_discount.php +++ b/application/models/reports/Specific_discount.php @@ -71,11 +71,8 @@ class Specific_discount extends Report MAX(comment) AS comment'); $this->db->from('sales_items_temp'); - if($inputs['discount_type']==1){ - $this->db->where('discount_fixed >=', $inputs['discount']); - }else{ - $this->db->where('discount_percent >=', $inputs['discount']); - } + $this->db->where('discount >=', $inputs['discount']); + $this->db->where('discount_type',$inputs['discount_type']); if($inputs['sale_type'] == 'complete') { @@ -124,7 +121,7 @@ class Specific_discount extends Report foreach($data['summary'] as $key=>$value) { - $this->db->select('name, category, serialnumber, description, quantity_purchased, subtotal, tax, total, cost, profit, discount_percent, discount_fixed'); + $this->db->select('name, category, serialnumber, description, quantity_purchased, subtotal, tax, total, cost, profit, discount, discount_type'); $this->db->from('sales_items_temp'); $this->db->where('sale_id', $value['sale_id']); $data['details'][$key] = $this->db->get()->result_array(); @@ -142,11 +139,9 @@ class Specific_discount extends Report $this->db->select('SUM(subtotal) AS subtotal, SUM(tax) AS tax, SUM(total) AS total, SUM(cost) AS cost, SUM(profit) AS profit'); $this->db->from('sales_items_temp'); - if($inputs['discount_type']==1){ - $this->db->where('discount_fixed >=', $inputs['discount']); - }else{ - $this->db->where('discount_percent >=', $inputs['discount']); - } + $this->db->where('discount >=', $inputs['discount']); + $this->db->where('discount_type',$inputs['discount_type']); + if($inputs['sale_type'] == 'complete') { diff --git a/application/models/reports/Specific_employee.php b/application/models/reports/Specific_employee.php index 0243d7f1f..36bdc0957 100644 --- a/application/models/reports/Specific_employee.php +++ b/application/models/reports/Specific_employee.php @@ -117,7 +117,7 @@ class Specific_employee extends Report foreach($data['summary'] as $key=>$value) { - $this->db->select('name, category, serialnumber, description, quantity_purchased, subtotal, tax, total, cost, profit, discount_percent, discount_fixed'); + $this->db->select('name, category, serialnumber, description, quantity_purchased, subtotal, tax, total, cost, profit, discount, discount_type'); $this->db->from('sales_items_temp'); $this->db->where('sale_id', $value['sale_id']); $data['details'][$key] = $this->db->get()->result_array(); diff --git a/application/models/reports/Summary_discounts.php b/application/models/reports/Summary_discounts.php index 606f79f9c..3c94829fb 100644 --- a/application/models/reports/Summary_discounts.php +++ b/application/models/reports/Summary_discounts.php @@ -13,17 +13,21 @@ class Summary_discounts extends Summary_report public function getData(array $inputs) { - if($inputs['discount_type']==1){ - $this->db->select('MAX(CONCAT("'.$this->config->item('currency_symbol').'",sales_items.discount_fixed)) AS discount, count(*) AS count'); - $this->db->where('discount_fixed > 0'); - $this->db->group_by('sales_items.discount_fixed'); - $this->db->order_by('sales_items.discount_fixed'); - }else{ - $this->db->select('MAX(CONCAT(sales_items.discount_percent, "%")) AS discount, count(*) AS count'); - $this->db->where('discount_percent > 0'); - $this->db->group_by('sales_items.discount_percent'); - $this->db->order_by('sales_items.discount_percent'); + if($inputs['discount_type'] == FIXED) + { + $this->db->select('MAX(CONCAT("'.$this->config->item('currency_symbol').'",sales_items.discount)) AS discount, count(*) AS count'); + $this->db->where('discount_type',FIXED); } + elseif($inputs['discount_type'] == PERCENT) + { + $this->db->select('MAX(CONCAT(sales_items.discount, "%")) AS discount, count(*) AS count'); + $this->db->where('discount_type',PERCENT); + } + + $this->db->where('discount > 0'); + $this->db->group_by('sales_items.discount'); + $this->db->order_by('sales_items.discount'); + $this->db->from('sales_items AS sales_items'); $this->db->join('sales AS sales', 'sales_items.sale_id = sales.sale_id', 'inner'); diff --git a/application/models/reports/Summary_payments.php b/application/models/reports/Summary_payments.php index cbb842b4f..79e82a03c 100644 --- a/application/models/reports/Summary_payments.php +++ b/application/models/reports/Summary_payments.php @@ -14,7 +14,7 @@ class Summary_payments extends Summary_report public function getData(array $inputs) { - $this->db->select('sales_payments.payment_type, COUNT(DISTINCT sales_payments.sale_id) AS count, SUM(sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)-sales_items.discount_fixed) AS payment_amount'); + $this->db->select('sales_payments.payment_type, COUNT(DISTINCT sales_payments.sale_id) AS count, SUM(CASE WHEN sales_items.discount_type = ' . PERCENT . ' THEN sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount / 100) ELSE sales_items.item_unit_price * sales_items.quantity_purchased - sales_items.discount END) AS payment_amount'); $this->db->from('sales_payments AS sales_payments'); $this->db->join('sales AS sales', 'sales.sale_id = sales_payments.sale_id'); $this->db->join('sales_items AS sales_items', 'sales_items.sale_id = sales_payments.sale_id', 'left'); diff --git a/application/models/reports/Summary_report.php b/application/models/reports/Summary_report.php index 9315361d0..2511f85bd 100644 --- a/application/models/reports/Summary_report.php +++ b/application/models/reports/Summary_report.php @@ -23,7 +23,7 @@ abstract class Summary_report extends Report $decimals = totals_decimals(); - $sale_price = 'sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100)-sales_items.discount_fixed'; + $sale_price = 'CASE WHEN sales_items.discount_type = ' . PERCENT . ' THEN sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount / 100) ELSE sales_items.item_unit_price * sales_items.quantity_purchased - sales_items.discount END'; $sale_cost = 'SUM(sales_items.item_cost_price * sales_items.quantity_purchased)'; $tax = 'IFNULL(SUM(sales_items_taxes.tax), 0)'; diff --git a/application/models/reports/Summary_taxes.php b/application/models/reports/Summary_taxes.php index d57a61510..11ab9f343 100644 --- a/application/models/reports/Summary_taxes.php +++ b/application/models/reports/Summary_taxes.php @@ -41,13 +41,13 @@ class Summary_taxes extends Summary_report if($this->config->item('tax_included')) { - $sale_total = '(sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100))'; - $sale_subtotal = '(sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100) * (100 / (100 + sales_items_taxes.percent)))'; + $sale_total = '(CASE WHEN sales_items.discount_type = ' . PERCENT . ' THEN sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount / 100) ELSE sales_items.item_unit_price * sales_items.quantity_purchased - sales_items.discount END)'; + $sale_subtotal = '(CASE WHEN sales_items.discount_type = ' . PERCENT . ' THEN sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount / 100) ELSE sales_items.item_unit_price * sales_items.quantity_purchased - sales_items.discount END * (100 / (100 + sales_items_taxes.percent)))'; } else { - $sale_total = '(sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100) * (1 + (sales_items_taxes.percent / 100)))'; - $sale_subtotal = '(sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount_percent / 100))'; + $sale_total = '(CASE WHEN sales_items.discount_type = ' . PERCENT . ' THEN sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount / 100) ELSE sales_items.item_unit_price * sales_items.quantity_purchased - sales_items.discount END * (1 + (sales_items_taxes.percent / 100)))'; + $sale_subtotal = '(CASE WHEN sales_items.discount_type = ' . PERCENT . ' THEN sales_items.item_unit_price * sales_items.quantity_purchased * (1 - sales_items.discount / 100) ELSE sales_items.item_unit_price * sales_items.quantity_purchased - sales_items.discount END)'; } $decimals = totals_decimals(); diff --git a/application/views/configs/general_config.php b/application/views/configs/general_config.php index 2ea8a1029..304f521c1 100644 --- a/application/views/configs/general_config.php +++ b/application/views/configs/general_config.php @@ -11,17 +11,6 @@
-
- lang->line('config_default_sales_discount_type'), 'default_sales_discount_type', array('class' => 'control-label col-xs-2')); ?> -
- 'default_sales_discount_type', - 'id' => 'default_sales_discount_type', - 'value' => 'default_sales_discount_type', - 'checked' => $this->config->item('default_sales_discount_type'))); ?> -
-
-
lang->line('config_default_sales_discount'), 'default_sales_discount', array('class' => 'control-label col-xs-2 required')); ?>
@@ -34,19 +23,19 @@ 'min' => 0, 'max' => 100, 'value' => $this->config->item('default_sales_discount'))); ?> - % -
-
-
-
- config->item('currency_symbol'); ?> - 'default_sales_discount_fixed', - 'id' => 'default_sales_discount_fixed', - 'class' => 'form-control input-sm required', - 'type' => 'number', - 'min' => 0, - 'value' => $this->config->item('default_sales_discount_fixed'))); ?> + + 'default_sales_discount_type', + 'name'=>'default_sales_discount_type', + 'value'=>1, + 'data-toggle'=>"toggle", + 'data-size'=>'small', + 'data-onstyle'=>'success', + 'data-on'=>''.$this->config->item('currency_symbol').'', + 'data-off'=>'%', + 'checked'=>$this->config->item('default_sales_discount_type')) + ); ?> +
diff --git a/application/views/customers/form.php b/application/views/customers/form.php index 1b32fb78f..6583cbf1a 100644 --- a/application/views/customers/form.php +++ b/application/views/customers/form.php @@ -40,33 +40,41 @@ load->view("people/form_basic_info"); ?> + +
+ lang->line('customers_discount_type'), 'discount_type', array('class'=>'control-label col-xs-3')); ?> +
+ + +
+
- lang->line('customers_discount'), 'discount_percent', array('class' => 'control-label col-xs-3')); ?> + lang->line('customers_discount'), 'discount', array('class' => 'control-label col-xs-3')); ?>
'discount_percent', - 'id'=>'discount_percent', + 'name'=>'discount', + 'id'=>'discount', 'class'=>'form-control input-sm', - 'value'=>$person_info->discount_percent) + 'value'=>$person_info->discount) ); ?> - % -
-
- -
-
- config->item('currency_symbol'); ?> - 'discount_fixed', - 'size'=>'5', - 'maxlength'=>'5', - 'id'=>'discount_fixed', - 'class'=>'form-control input-sm', - 'value'=>$person_info->discount_fixed) - );?> -
diff --git a/application/views/receivings/receipt.php b/application/views/receivings/receipt.php index b14a71a50..f28296538 100644 --- a/application/views/receivings/receipt.php +++ b/application/views/receivings/receipt.php @@ -92,17 +92,20 @@ { ?> - lang->line("sales_discount_included")?> - - - 0 ) - { - ?> - - lang->line("sales_discount")?> + + lang->line("sales_discount") ?> + + lang->line("sales_discount_included") ?> +
- 'discount_fixed', 'class'=>'form-control input-sm', 'value'=>to_decimals($item['discount_fixed'], 0), 'onClick'=>'this.select();')); - echo form_hidden('discount', $item['discount']); - } - else - { - echo form_input(array('name'=>'discount', 'class'=>'form-control input-sm', 'value'=>to_decimals($item['discount'], 0), 'onClick'=>'this.select();')); - echo form_hidden('discount_fixed', $item['discount_fixed']); - } - ?> + 'discount', 'class'=>'form-control input-sm', 'value'=>to_decimals($item['discount'], 0), 'onClick'=>'this.select();')); ?> 'discount_toggle', 'name'=>'discount_toggle', 'value'=>1, 'data-toggle'=>"toggle",'data-size'=>'small', 'data-onstyle'=>'success', 'data-on'=>''.$this->config->item('currency_symbol').'', 'data-off'=>'%', 'data-line'=>$line, 'checked'=>$item['discount_type'])); ?> - -
@@ -189,20 +176,13 @@ if (isset($success)) else { ?> - + - - + + lang->line('receivings_update')?> > @@ -531,7 +511,7 @@ $(document).ready(function() } } - $('[name="price"],[name="quantity"],[name="receiving_quantity"],[name="discount"],[name="discount_fixed"],[name="description"],[name="serialnumber"]').change(function() { + $('[name="price"],[name="quantity"],[name="receiving_quantity"],[name="discount"],[name="description"],[name="serialnumber"]').change(function() { $(this).parents("tr").prevAll("form:first").submit() }); diff --git a/application/views/sales/invoice.php b/application/views/sales/invoice.php index c1a6018ba..85ac25149 100755 --- a/application/views/sales/invoice.php +++ b/application/views/sales/invoice.php @@ -133,7 +133,7 @@ $(document).ready(function() - + 0): ?> diff --git a/application/views/sales/invoice_email.php b/application/views/sales/invoice_email.php index 72c0c6259..c69ed99fb 100644 --- a/application/views/sales/invoice_email.php +++ b/application/views/sales/invoice_email.php @@ -96,7 +96,7 @@ - + 0): ?> diff --git a/application/views/sales/quote.php b/application/views/sales/quote.php index a37acd8bf..acf29976d 100644 --- a/application/views/sales/quote.php +++ b/application/views/sales/quote.php @@ -135,7 +135,7 @@ if (isset($error_message)) + cols="6"> 0): ?> diff --git a/application/views/sales/quote_email.php b/application/views/sales/quote_email.php index 051801575..cf6b211fb 100644 --- a/application/views/sales/quote_email.php +++ b/application/views/sales/quote_email.php @@ -96,7 +96,7 @@ - + 0): ?> diff --git a/application/views/sales/receipt_default.php b/application/views/sales/receipt_default.php index 9192f4f86..4197e4985 100644 --- a/application/views/sales/receipt_default.php +++ b/application/views/sales/receipt_default.php @@ -96,19 +96,20 @@ { ?> - lang->line("sales_discount_included") ?> - - - 0) - { - ?> - - lang->line("sales_discount") ?> + + lang->line("sales_discount") ?> + + lang->line("sales_discount_included") ?> + - lang->line("sales_discount_included") ?> - - - 0) - { - ?> - - lang->line("sales_discount") ?> + + lang->line("sales_discount") ?> + + lang->line("sales_discount_included") ?> + - lang->line("sales_discount_included")?> - - - 0) - { - ?> - - lang->line("sales_discount") ?> + + lang->line("sales_discount") ?> + + lang->line("sales_discount_included") ?> +
- 'discount_fixed', 'class'=>'form-control input-sm', 'value'=>to_decimals($item['discount_fixed'], 0), 'tabindex'=>++$tabindex, 'onClick'=>'this.select();')); - echo form_hidden('discount', $item['discount']); - } - else - { - echo form_input(array('name'=>'discount', 'class'=>'form-control input-sm', 'value'=>to_decimals($item['discount'], 0), 'tabindex'=>++$tabindex, 'onClick'=>'this.select();')); - echo form_hidden('discount_fixed', $item['discount_fixed']); - } - ?> + 'discount', 'class'=>'form-control input-sm', 'value'=>to_decimals($item['discount'], 0), 'tabindex'=>++$tabindex, 'onClick'=>'this.select();')); ?> 'discount_toggle', 'name'=>'discount_toggle', 'value'=>1, 'data-toggle'=>"toggle",'data-size'=>'small', 'data-onstyle'=>'success', 'data-on'=>''.$this->config->item('currency_symbol').'', 'data-off'=>'%', 'data-line'=>$line, 'checked'=>$item['discount_type'])); ?>
+ + lang->line('sales_update')?> > @@ -358,7 +349,7 @@ if(isset($success)) ?> lang->line("sales_customer_discount"); ?> - + config->item('customer_reward_enable') == TRUE): ?> - + diff --git a/application/views/sales/work_order_email.php b/application/views/sales/work_order_email.php index 0e68305ce..cd71a1a1e 100644 --- a/application/views/sales/work_order_email.php +++ b/application/views/sales/work_order_email.php @@ -87,7 +87,7 @@ - + Date: Fri, 31 Aug 2018 16:01:34 -0500 Subject: [PATCH 07/10] default_sales_discount_fixed deleted --- application/migrations/sqlscripts/discount_on_sales.sql | 1 - 1 file changed, 1 deletion(-) diff --git a/application/migrations/sqlscripts/discount_on_sales.sql b/application/migrations/sqlscripts/discount_on_sales.sql index e0bf9dad4..05d61f922 100644 --- a/application/migrations/sqlscripts/discount_on_sales.sql +++ b/application/migrations/sqlscripts/discount_on_sales.sql @@ -3,7 +3,6 @@ -- INSERT INTO `ospos_app_config` (`key`, `value`) VALUES -('default_sales_discount_fixed', '0'), ('default_sales_discount_type', '0'); ALTER TABLE `ospos_item_kits` From 53efbdb3b778d35a3f8ac6d3cba4830a110f3c6b Mon Sep 17 00:00:00 2001 From: Erastus Date: Fri, 31 Aug 2018 23:05:32 -0500 Subject: [PATCH 08/10] reports discount fixed --- application/views/reports/specific_input.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/views/reports/specific_input.php b/application/views/reports/specific_input.php index b31bfda1b..d9f1c1c77 100644 --- a/application/views/reports/specific_input.php +++ b/application/views/reports/specific_input.php @@ -53,7 +53,7 @@ if(isset($error)) 'class' => 'form-control input-sm required', 'type' => 'number', 'min' => 0, - 'value' => $this->config->item('default_sales_discount_fixed'))); ?> + 'value' => $this->config->item('default_sales_discount'))); ?> Date: Sun, 2 Sep 2018 17:58:41 -0500 Subject: [PATCH 09/10] cleaning spaces --- application/controllers/Sales.php | 2 +- application/libraries/Receiving_lib.php | 7 +++--- application/libraries/Sale_lib.php | 3 ++- .../20180820100000_discount_on_sales.php | 20 ---------------- ...hp => 20180830100000_upgrade_to_3_3_0.php} | 0 .../migrations/sqlscripts/3.2.1_to_3.3.0.sql | 23 ++++++++++++++++++- .../sqlscripts/discount_on_sales.sql | 23 ------------------- .../models/reports/Specific_discount.php | 1 - application/views/item_kits/form.php | 3 +-- application/views/receivings/receiving.php | 1 - application/views/sales/register.php | 1 - 11 files changed, 30 insertions(+), 54 deletions(-) delete mode 100644 application/migrations/20180820100000_discount_on_sales.php rename application/migrations/{20180610100000_upgrade_to_3_3_0.php => 20180830100000_upgrade_to_3_3_0.php} (100%) delete mode 100644 application/migrations/sqlscripts/discount_on_sales.sql diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index f157f45c0..dffb26d81 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -385,7 +385,7 @@ class Sales extends Secure_Controller } // if the customer discount is 0 or no customer is selected apply the default sales discount - if($discount == 0 ) + if($discount == 0) { $discount = $this->config->item('default_sales_discount'); } diff --git a/application/libraries/Receiving_lib.php b/application/libraries/Receiving_lib.php index 218cc1242..53ba67bfd 100644 --- a/application/libraries/Receiving_lib.php +++ b/application/libraries/Receiving_lib.php @@ -226,7 +226,8 @@ class Receiving_lib 1 => 'x1'); } - if(is_null($receiving_quantity)){ + if(is_null($receiving_quantity)) + { $receiving_quantity = $item_info->receiving_quantity; } @@ -279,7 +280,8 @@ class Receiving_lib $line['quantity'] = $quantity; $line['receiving_quantity'] = $receiving_quantity; $line['discount'] = $discount; - if(!is_null($discount_type)){ + if(!is_null($discount_type)) + { $line['discount_type'] = $discount_type; } $line['price'] = $price; @@ -367,7 +369,6 @@ class Receiving_lib $discount_fraction = bcdiv($discount, 100); $discount_amount = bcmul($total, $discount_fraction); } - return bcsub($total, $discount_amount); } diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php index 528459fa6..6e98c0918 100644 --- a/application/libraries/Sale_lib.php +++ b/application/libraries/Sale_lib.php @@ -949,7 +949,8 @@ class Sale_lib $line['serialnumber'] = $serialnumber; $line['quantity'] = $quantity; $line['discount'] = $discount; - if(!is_null($discount_type)){ + if(!is_null($discount_type)) + { $line['discount_type'] = $discount_type; } $line['price'] = $price; diff --git a/application/migrations/20180820100000_discount_on_sales.php b/application/migrations/20180820100000_discount_on_sales.php deleted file mode 100644 index d0c6e401a..000000000 --- a/application/migrations/20180820100000_discount_on_sales.php +++ /dev/null @@ -1,20 +0,0 @@ - diff --git a/application/migrations/20180610100000_upgrade_to_3_3_0.php b/application/migrations/20180830100000_upgrade_to_3_3_0.php similarity index 100% rename from application/migrations/20180610100000_upgrade_to_3_3_0.php rename to application/migrations/20180830100000_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 0cc3bd68d..8f32dbb51 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 @@ -3,7 +3,8 @@ -- INSERT INTO `ospos_app_config` (`key`, `value`) VALUES -('multi_pack_enabled', '0'); +('multi_pack_enabled', '0'), +('default_sales_discount_type', '0'); ALTER TABLE `ospos_items` ADD COLUMN `qty_per_pack` decimal(15,3) NOT NULL DEFAULT 1, @@ -13,3 +14,23 @@ ALTER TABLE `ospos_items` UPDATE `ospos_items` SET `low_sell_item_id` = `item_id` WHERE `low_sell_item_id` = 0; + +-- +-- Add support for Discount on Sales Fixed +-- + +ALTER TABLE `ospos_item_kits` + CHANGE COLUMN `kit_discount_percent` `kit_discount` DECIMAL(15,2) NOT NULL DEFAULT 0 AFTER `item_id`, + ADD COLUMN `kit_discount_type` TINYINT(2) NOT NULL DEFAULT '0' AFTER `kit_discount`; + +ALTER TABLE `ospos_customers` + CHANGE COLUMN `discount_percent` `discount` DECIMAL(15,2) NOT NULL DEFAULT 0 AFTER `sales_tax_code`, + ADD COLUMN `discount_type` TINYINT(2) NOT NULL DEFAULT '0' AFTER `discount`; + +ALTER TABLE `ospos_sales_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`; + +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`; diff --git a/application/migrations/sqlscripts/discount_on_sales.sql b/application/migrations/sqlscripts/discount_on_sales.sql deleted file mode 100644 index 05d61f922..000000000 --- a/application/migrations/sqlscripts/discount_on_sales.sql +++ /dev/null @@ -1,23 +0,0 @@ --- --- Add support for Discount on Sales Fixed --- - -INSERT INTO `ospos_app_config` (`key`, `value`) VALUES -('default_sales_discount_type', '0'); - -ALTER TABLE `ospos_item_kits` - CHANGE COLUMN `kit_discount_percent` `kit_discount` DECIMAL(15,2) NOT NULL DEFAULT '0.00' AFTER `item_id`, - ADD COLUMN `kit_discount_type` TINYINT(2) NOT NULL DEFAULT '0' AFTER `kit_discount`; - -ALTER TABLE `ospos_customers` - CHANGE COLUMN `discount_percent` `discount` DECIMAL(15,2) NOT NULL DEFAULT '0.00' AFTER `sales_tax_code`, - ADD COLUMN `discount_type` TINYINT(2) NOT NULL DEFAULT '0' AFTER `discount`; - - -ALTER TABLE `ospos_sales_items` - CHANGE COLUMN `discount_percent` `discount` DECIMAL(15,2) NOT NULL DEFAULT '0.00' AFTER `item_unit_price`, - ADD COLUMN `discount_type` TINYINT(2) NOT NULL DEFAULT '0' AFTER `discount`; - -ALTER TABLE `ospos_receivings_items` - CHANGE COLUMN `discount_percent` `discount` DECIMAL(15,2) NOT NULL DEFAULT '0.00' AFTER `item_unit_price`, - ADD COLUMN `discount_type` TINYINT(2) NOT NULL DEFAULT '0' AFTER `discount`; diff --git a/application/models/reports/Specific_discount.php b/application/models/reports/Specific_discount.php index d46e6f037..03f05623d 100755 --- a/application/models/reports/Specific_discount.php +++ b/application/models/reports/Specific_discount.php @@ -141,7 +141,6 @@ class Specific_discount extends Report $this->db->where('discount >=', $inputs['discount']); $this->db->where('discount_type',$inputs['discount_type']); - if($inputs['sale_type'] == 'complete') { diff --git a/application/views/item_kits/form.php b/application/views/item_kits/form.php index e767346a7..711c35350 100644 --- a/application/views/item_kits/form.php +++ b/application/views/item_kits/form.php @@ -59,8 +59,7 @@ 'id'=>'kit_discount_fixed', 'class'=>'form-control input-sm', 'value'=>$item_kit_info->kit_discount_fixed) - );?> - + );?> diff --git a/application/views/receivings/receiving.php b/application/views/receivings/receiving.php index f4d6946f7..5c2b934e7 100644 --- a/application/views/receivings/receiving.php +++ b/application/views/receivings/receiving.php @@ -516,7 +516,6 @@ $(document).ready(function() }); $('[name="discount_toggle"]').change(function() { - var input = $("").attr("type", "hidden").attr("name", "discount_type").val(($(this).prop('checked'))?1:0); $('#cart_'+ $(this).attr('data-line')).append($(input)); $('#cart_'+ $(this).attr('data-line')).submit(); diff --git a/application/views/sales/register.php b/application/views/sales/register.php index 8c20bd4d1..7fde2d58c 100644 --- a/application/views/sales/register.php +++ b/application/views/sales/register.php @@ -906,7 +906,6 @@ $(document).ready(function() }); $('[name="discount_toggle"]').change(function() { - var input = $("").attr("type", "hidden").attr("name", "discount_type").val(($(this).prop('checked'))?1:0); $('#cart_'+ $(this).attr('data-line')).append($(input)); $('#cart_'+ $(this).attr('data-line')).submit(); From c57d8ef536552821081f7c375d7cb359a0d9951a Mon Sep 17 00:00:00 2001 From: Erastus Date: Mon, 3 Sep 2018 00:51:34 -0500 Subject: [PATCH 10/10] discount in item_kits --- application/controllers/Item_kits.php | 9 ++-- application/controllers/Sales.php | 2 +- application/language/en-US/item_kits_lang.php | 4 ++ application/language/es/item_kits_lang.php | 4 ++ application/models/Item_kit.php | 4 +- application/views/item_kits/form.php | 47 +++++++++++-------- 6 files changed, 44 insertions(+), 26 deletions(-) diff --git a/application/controllers/Item_kits.php b/application/controllers/Item_kits.php index 31fdcf638..050689ae6 100644 --- a/application/controllers/Item_kits.php +++ b/application/controllers/Item_kits.php @@ -37,8 +37,9 @@ class Item_kits extends Secure_Controller } } - $discount_fraction = bcdiv($item_kit->kit_discount_percent, 100); - $item_kit->total_unit_price = $item_kit->total_unit_price - round(bcadd(bcmul($item_kit->total_unit_price, $discount_fraction),bcmul($item_kit->kit_discount_fixed,$total_quantity)), totals_decimals(), PHP_ROUND_HALF_UP); + $discount_fraction = bcdiv($item_kit->kit_discount, 100); + + $item_kit->total_unit_price = $item_kit->total_unit_price - round(($item_kit->kit_discount_type == PERCENT)?bcmul($item_kit->total_unit_price, $discount_fraction): $item_kit->kit_discount, totals_decimals(), PHP_ROUND_HALF_UP); return $item_kit; } @@ -131,8 +132,8 @@ class Item_kits extends Secure_Controller $item_kit_data = array( 'name' => $this->input->post('name'), 'item_id' => $this->input->post('kit_item_id'), - 'kit_discount_percent' => $this->input->post('kit_discount_percent'), - 'kit_discount_fixed' => $this->input->post('kit_discount_fixed'), + 'kit_discount' => $this->input->post('kit_discount'), + 'kit_discount_type' => $this->input->post('kit_discount_type') == NULL ? PERCENT : $this->input->post('kit_discount_type'), 'price_option' => $this->input->post('price_option'), 'print_option' => $this->input->post('print_option'), 'description' => $this->input->post('description') diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php index dffb26d81..754e0861d 100644 --- a/application/controllers/Sales.php +++ b/application/controllers/Sales.php @@ -413,7 +413,7 @@ class Sales extends Secure_Controller if($item_kit_info->kit_discount != 0 && $item_kit_info->kit_discount > $discount) { $discount = $item_kit_info->kit_discount; - $discount_type = $item_kit_info->discount_type; + $discount_type = $item_kit_info->kit_discount_type; } $price = NULL; diff --git a/application/language/en-US/item_kits_lang.php b/application/language/en-US/item_kits_lang.php index ba6bae908..a6ef53155 100644 --- a/application/language/en-US/item_kits_lang.php +++ b/application/language/en-US/item_kits_lang.php @@ -30,3 +30,7 @@ $lang["item_kits_successful_adding"] = "You have successfully added Item Kit"; $lang["item_kits_successful_deleted"] = "You have successfully deleted"; $lang["item_kits_successful_updating"] = "You have successfully updated Item Kit"; $lang["item_kits_update"] = "Update Item Kit"; +$lang["item_kits_discount"] = "Discount"; +$lang["item_kits_discount_type"] = "Discount Type"; +$lang["item_kits_discount_fixed"] = "Fixed Discount"; +$lang["item_kits_discount_percent"] = "Percentage Discount"; diff --git a/application/language/es/item_kits_lang.php b/application/language/es/item_kits_lang.php index 9c7fa4b1f..fc2bb6a58 100644 --- a/application/language/es/item_kits_lang.php +++ b/application/language/es/item_kits_lang.php @@ -30,3 +30,7 @@ $lang["item_kits_successful_adding"] = "Has agregado satisfactoriamente un Kit d $lang["item_kits_successful_deleted"] = "Has borrado satisfactoriamente"; $lang["item_kits_successful_updating"] = "Has actualizado satisfactoriamente un Kit de Artículos"; $lang["item_kits_update"] = "Actualizar Kit de Artículos"; +$lang["item_kits_discount"] = "Descuento"; +$lang["item_kits_discount_type"] = "Tipo de Descuento"; +$lang["item_kits_discount_fixed"] = "Descuento Fijo"; +$lang["item_kits_discount_percent"] = "Descuento en Porcentaje"; diff --git a/application/models/Item_kit.php b/application/models/Item_kit.php index 96aca7b05..06c3ed9dc 100644 --- a/application/models/Item_kit.php +++ b/application/models/Item_kit.php @@ -58,8 +58,8 @@ class Item_kit extends CI_Model item_kits.description, items.description as item_description, item_kits.item_id as kit_item_id, - kit_discount_percent, - kit_discount_fixed, + kit_discount, + kit_discount_type, price_option, print_option, category, diff --git a/application/views/item_kits/form.php b/application/views/item_kits/form.php index 711c35350..bf7c80f3b 100644 --- a/application/views/item_kits/form.php +++ b/application/views/item_kits/form.php @@ -34,32 +34,41 @@
- lang->line('item_kits_discount_percent'), 'kit_discount_percent', array('class' => 'control-label col-xs-3')); ?> -
-
- 'kit_discount_percent', - 'size'=>'5', - 'maxlength'=>'5', - 'id'=>'kit_discount_percent', - 'class'=>'form-control input-sm', - 'value'=>$item_kit_info->kit_discount_percent) - );?> - % -
+ lang->line('item_kits_discount_type'), 'kit_discount_type', array('class'=>'control-label col-xs-3')); ?> +
+ +
- +
+ +
+ lang->line('item_kits_discount'), 'kit_discount', array('class' => 'control-label col-xs-3')); ?>
- config->item('currency_symbol'); ?> 'kit_discount_fixed', + 'name'=>'kit_discount', 'size'=>'5', 'maxlength'=>'5', - 'id'=>'kit_discount_fixed', + 'id'=>'kit_discount', 'class'=>'form-control input-sm', - 'value'=>$item_kit_info->kit_discount_fixed) - );?> + 'value'=>$item_kit_info->kit_discount) + );?>