Merge pull request #2091 from erastus/master

Discount on Sales
This commit is contained in:
FrancescoUK
2018-09-03 21:48:14 +01:00
committed by GitHub
59 changed files with 515 additions and 177 deletions

View File

@@ -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

View File

@@ -60,10 +60,12 @@ $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';
$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';

View File

@@ -285,6 +285,7 @@ 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'),
'enforce_privacy' => $this->input->post('enforce_privacy'),
'receiving_calculate_average_price' => $this->input->post('receiving_calculate_average_price') != NULL,

View File

@@ -248,7 +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' => $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'),
@@ -403,8 +404,9 @@ class Customers extends Persons
$customer_data = array(
'consent' => $consent,
'company_name' => $data[13],
'discount_percent' => $data[15],
'taxable' => $data[16] == '' ? 0 : 1,
'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
);

View File

@@ -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,13 @@ 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);
$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;
}
@@ -129,7 +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' => $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')

View File

@@ -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,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_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_type, $price, $receiving_quantity);
}
else
{
@@ -264,8 +266,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();

View File

@@ -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']
));
}
@@ -706,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;
@@ -722,7 +737,7 @@ class Reports extends Secure_Controller
{
$row = $this->xss_clean($row);
$labels[] = $row['discount_percent'];
$labels[] = $row['discount'];
$series[] = $row['count'];
}
@@ -734,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
);
@@ -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_type'] == PERCENT)? $drow['discount'].'%':to_currency($drow['discount'])));
}
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_type'] == PERCENT)? $drow['discount'].'%':to_currency($drow['discount'])));
}
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_type'] == PERCENT)? $drow['discount'].'%':to_currency($drow['discount'])));
}
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_type'] == PERCENT)? $drow['discount'].'%':to_currency($drow['discount'])));
}
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_type'] == PERCENT)? $drow['discount'].'%':to_currency($drow['discount'])));
}
}

View File

@@ -136,12 +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 = $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 != '')
if($discount != '')
{
$this->sale_lib->apply_customer_discount($discount_percent);
$this->sale_lib->apply_customer_discount($discount, $discount_type);
}
}
@@ -367,16 +368,19 @@ class Sales extends Secure_Controller
$data = array();
$discount = 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();
if($customer_id != -1)
{
// load the customer discount if any
$discount_percent = $this->Customer->get_info($customer_id)->discount_percent;
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 = $customer_discount;
$discount_type = $customer_discount_type;
}
}
@@ -406,9 +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;
$discount = $item_kit_info->kit_discount;
$discount_type = $item_kit_info->kit_discount_type;
}
$price = NULL;
@@ -416,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, 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');
}
@@ -428,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, $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');
}
@@ -439,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, 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');
}
@@ -464,12 +469,14 @@ class Sales 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_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_type, $price, $discounted_total);
}
else
{
@@ -861,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)
{

View File

@@ -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.";

View File

@@ -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";

View File

@@ -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";

View File

@@ -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";

View File

@@ -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";

View File

@@ -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";

View File

@@ -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.";

View File

@@ -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";

View File

@@ -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";

View File

@@ -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";

View File

@@ -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";

View File

@@ -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";

View File

@@ -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, $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,11 @@ 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,
@@ -239,11 +244,12 @@ class Receiving_lib
'is_serialized' => $item_info->is_serialized,
'quantity' => $quantity,
'discount' => $discount,
'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_type, $receiving_quantity)
)
);
@@ -251,7 +257,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_type, $items[$updatekey]['receiving_quantity']);
}
else
{
@@ -264,7 +270,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_type, $price, $receiving_quantity)
{
$items = $this->get_cart();
if(isset($items[$line]))
@@ -275,8 +281,12 @@ class Receiving_lib
$line['quantity'] = $quantity;
$line['receiving_quantity'] = $receiving_quantity;
$line['discount'] = $discount;
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_type, $receiving_quantity);
$this->set_cart($items);
}
@@ -309,13 +319,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, $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);
@@ -323,7 +333,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);
}
}
@@ -334,7 +344,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, $row->item_unit_price, $row->description, $row->serialnumber, $row->receiving_quantity, TRUE);
}
$this->set_supplier($this->CI->Receiving->get_supplier($receiving_id)->person_id);
@@ -350,12 +360,16 @@ 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, $discount_type, $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 = $discount;
if($discount_type == PERCENT)
{
$discount_fraction = bcdiv($discount, 100);
$discount_amount = bcmul($total, $discount_fraction);
}
return bcsub($total, $discount_amount);
}
@@ -365,7 +379,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_type'], $item['receiving_quantity']));
}
return $total;

View File

@@ -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_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']));
$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, $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);
@@ -825,8 +825,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_type);
$discounted_total = $this->get_item_total($quantity, $price, $discount, $discount_type, TRUE);
if($this->CI->config->item('multi_pack_enabled') == '1')
{
@@ -850,6 +850,7 @@ class Sale_lib
'is_serialized' => $item_info->is_serialized,
'quantity' => $quantity,
'discount' => $discount,
'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 +934,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_type, $price, $discounted_total=NULL)
{
$items = $this->get_cart();
if(isset($items[$line]))
@@ -948,9 +949,13 @@ class Sale_lib
$line['serialnumber'] = $serialnumber;
$line['quantity'] = $quantity;
$line['discount'] = $discount;
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, $line['discount_type']);
$line['discounted_total'] = $this->get_item_total($quantity, $price, $discount, $line['discount_type'], TRUE);
$this->set_cart($items);
}
@@ -981,13 +986,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, $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_type, $kit_price_option, $kit_print_option, &$stock_warning)
{
//KIT #
$pieces = explode(' ', $external_item_kit_id);
@@ -996,7 +1001,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_type, PRICE_MODE_KIT, $kit_price_option, $kit_print_option, NULL, NULL, NULL, NULL);
if($stock_warning == NULL)
{
@@ -1014,7 +1019,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, $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 +1047,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, $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 +1132,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_type'], 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_type'], $tax['percent']);
}
elseif($this->CI->config->item('customer_sales_tax_support') == '0')
{
@@ -1166,7 +1171,7 @@ class Sale_lib
return $sales_taxes;
}
public function apply_customer_discount($discount_percent)
public function apply_customer_discount($discount, $discount_type)
{
// Get all items in the cart so far...
$items = $this->get_cart();
@@ -1179,9 +1184,9 @@ class Sale_lib
// set a new discount only if the current one is 0
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'] = $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);
}
}
@@ -1195,7 +1200,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_type']);
$discount = bcadd($discount, $item_discount);
}
}
@@ -1208,39 +1213,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, $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, $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, $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)
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, $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, $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_amount = $this->get_item_discount($quantity, $price, $discount, $discount_type);
return bcsub($total, $discount_amount);
}
@@ -1269,17 +1274,21 @@ 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, $discount_type)
{
$total = bcmul($quantity, $price);
$discount_fraction = bcdiv($discount_percentage, 100);
return round(bcmul($total, $discount_fraction), 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, $tax_percentage)
public function get_item_tax($quantity, $price, $discount, $discount_type, $tax_percentage)
{
$price = $this->get_item_total($quantity, $price, $discount_percentage, 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);
@@ -1300,11 +1309,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_type'], $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_type'], $include_discount));
}
}

View File

@@ -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, $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, 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'], 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;

View File

@@ -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`;

View File

@@ -104,7 +104,7 @@ class Customer extends Person
(
SELECT
sales.sale_id AS sale_id,
AVG(sales_items.discount_percent) AS avg_discount,
AVG(sales_items.discount) AS avg_discount,
SUM(sales_items.quantity_purchased) AS quantity
FROM ' . $this->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,

View File

@@ -58,7 +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,
kit_discount_type,
price_option,
print_option,
category,

View File

@@ -93,7 +93,8 @@ class Receiving extends CI_Model
'serialnumber' => $item['serialnumber'],
'quantity_purchased' => $item['quantity'],
'receiving_quantity' => $item['receiving_quantity'],
'discount_percent' => $item['discount'],
'discount' => $item['discount'],
'discount_type' => $item['discount_type'],
'item_cost_price' => $cur_item_info->cost_price,
'item_unit_price' => $item['price'],
'item_location' => $item['item_location']
@@ -265,13 +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) 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) 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(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

View File

@@ -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)';
$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)';
$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,7 +654,8 @@ 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' => $item['discount'],
'discount_type' => $item['discount_type'],
'item_cost_price' => $item['cost_price'],
'item_unit_price' => $item['price'],
'item_location' => $item['item_location'],
@@ -703,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;
@@ -725,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')
{
@@ -927,7 +930,8 @@ class Sale extends CI_Model
quantity_purchased,
item_cost_price,
item_unit_price,
discount_percent,
discount,
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 = '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)';
@@ -1190,7 +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) 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,

View File

@@ -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, 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']);

View File

@@ -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, 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();

View File

@@ -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();

View File

@@ -70,7 +70,9 @@ 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']);
$this->db->where('discount >=', $inputs['discount']);
$this->db->where('discount_type',$inputs['discount_type']);
if($inputs['sale_type'] == 'complete')
{
@@ -119,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');
$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();
@@ -136,7 +138,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');
$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')
{

View File

@@ -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, discount_type');
$this->db->from('sales_items_temp');
$this->db->where('sale_id', $value['sale_id']);
$data['details'][$key] = $this->db->get()->result_array();

View File

@@ -13,17 +13,27 @@ 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'] == 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');
$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();
}
}

View File

@@ -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(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');

View File

@@ -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 = '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)';

View File

@@ -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();

View File

@@ -23,7 +23,19 @@
'min' => 0,
'max' => 100,
'value' => $this->config->item('default_sales_discount'))); ?>
<span class="input-group-addon input-sm">%</span>
<span class="input-group-btn">
<?php echo form_checkbox(array(
'id'=>'default_sales_discount_type',
'name'=>'default_sales_discount_type',
'value'=>1,
'data-toggle'=>"toggle",
'data-size'=>'small',
'data-onstyle'=>'success',
'data-on'=>'<b>'.$this->config->item('currency_symbol').'</b>',
'data-off'=>'<b>%</b>',
'checked'=>$this->config->item('default_sales_discount_type'))
); ?>
</span>
</div>
</div>
</div>

View File

@@ -40,18 +40,41 @@
</div>
<?php $this->load->view("people/form_basic_info"); ?>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('customers_discount_type'), 'discount_type', array('class'=>'control-label col-xs-3')); ?>
<div class="col-xs-8">
<label class="radio-inline">
<?php echo form_radio(array(
'name'=>'discount_type',
'type'=>'radio',
'id'=>'discount_type',
'value'=>0,
'checked'=>$person_info->discount_type == PERCENT)
); ?> <?php echo $this->lang->line('customers_discount_percent'); ?>
</label>
<label class="radio-inline">
<?php echo form_radio(array(
'name'=>'discount_type',
'type'=>'radio',
'id'=>'discount_type',
'value'=>1,
'checked'=>$person_info->discount_type == FIXED)
); ?> <?php echo $this->lang->line('customers_discount_fixed'); ?>
</label>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('customers_discount'), 'discount_percent', array('class' => 'control-label col-xs-3')); ?>
<?php echo form_label($this->lang->line('customers_discount'), 'discount', array('class' => 'control-label col-xs-3')); ?>
<div class='col-xs-3'>
<div class="input-group input-group-sm">
<?php echo form_input(array(
'name'=>'discount_percent',
'id'=>'discount_percent',
'name'=>'discount',
'id'=>'discount',
'class'=>'form-control input-sm',
'value'=>$person_info->discount_percent)
'value'=>$person_info->discount)
); ?>
<span class="input-group-addon input-sm"><b>%</b></span>
</div>
</div>
</div>

View File

@@ -34,18 +34,41 @@
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('item_kits_discount_percent'), 'kit_discount_percent', array('class' => 'control-label col-xs-3')); ?>
<?php echo form_label($this->lang->line('item_kits_discount_type'), 'kit_discount_type', array('class'=>'control-label col-xs-3')); ?>
<div class="col-xs-8">
<label class="radio-inline">
<?php echo form_radio(array(
'name'=>'kit_discount_type',
'type'=>'radio',
'id'=>'kit_discount_type',
'value'=>0,
'checked'=>$item_kit_info->kit_discount_type == PERCENT)
); ?> <?php echo $this->lang->line('item_kits_discount_percent'); ?>
</label>
<label class="radio-inline">
<?php echo form_radio(array(
'name'=>'kit_discount_type',
'type'=>'radio',
'id'=>'kit_discount_type',
'value'=>1,
'checked'=>$item_kit_info->kit_discount_type == FIXED)
); ?> <?php echo $this->lang->line('item_kits_discount_fixed'); ?>
</label>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('item_kits_discount'), 'kit_discount', array('class' => 'control-label col-xs-3')); ?>
<div class='col-xs-3'>
<div class="input-group input-group-sm">
<?php echo form_input(array(
'name'=>'kit_discount_percent',
'name'=>'kit_discount',
'size'=>'5',
'maxlength'=>'5',
'id'=>'kit_discount_percent',
'id'=>'kit_discount',
'class'=>'form-control input-sm',
'value'=>$item_kit_info->kit_discount_percent)
'value'=>$item_kit_info->kit_discount)
);?>
<span class="input-group-addon input-sm"><b>%</b></span>
</div>
</div>
</div>

View File

@@ -20,6 +20,7 @@
<link rel="stylesheet" href="bower_components/chartist/dist/chartist.min.css" />
<link rel="stylesheet" href="bower_components/chartist-plugin-tooltip/dist/chartist-plugin-tooltip.css" />
<link rel="stylesheet" href="bower_components/bootstrap-tagsinput/dist/bootstrap-tagsinput.css" />
<link rel="stylesheet" href="bower_components/bootstrap-toggle/css/bootstrap-toggle.min.css" />
<!-- endbower -->
<!-- start css template tags -->
<link rel="stylesheet" type="text/css" href="css/bootstrap.autocomplete.css"/>
@@ -60,6 +61,7 @@
<script src="bower_components/remarkable-bootstrap-notify/bootstrap-notify.js"></script>
<script src="bower_components/js-cookie/src/js.cookie.js"></script>
<script src="bower_components/bootstrap-tagsinput/dist/bootstrap-tagsinput.js"></script>
<script src="bower_components/bootstrap-toggle/js/bootstrap-toggle.min.js"></script>
<!-- endbower -->
<!-- start js template tags -->
<script type="text/javascript" src="js/imgpreview.full.jquery.js"></script>
@@ -72,10 +74,10 @@
<![endif]-->
<!-- start mincss template tags -->
<link rel="stylesheet" type="text/css" href="dist/jquery-ui/jquery-ui.min.css"/>
<link rel="stylesheet" type="text/css" href="dist/opensourcepos.min.css?rel=84371241b2"/>
<link rel="stylesheet" type="text/css" href="dist/opensourcepos.min.css?rel=88039333a5"/>
<!-- end mincss template tags -->
<!-- start minjs template tags -->
<script type="text/javascript" src="dist/opensourcepos.min.js?rel=5facd00267"></script>
<script type="text/javascript" src="dist/opensourcepos.min.js?rel=11c54984ca"></script>
<!-- end minjs template tags -->
<?php endif; ?>

View File

@@ -92,7 +92,20 @@
{
?>
<tr>
<td colspan="3" style="font-weight: bold;"> <?php echo number_format($item['discount'], 0) . " " . $this->lang->line("sales_discount_included")?> </td>
<?php
if($item['discount_type'] == FIXED)
{
?>
<td colspan="3" class="discount"><?php echo to_currency($item['discount']) . " " . $this->lang->line("sales_discount") ?></td>
<?php
}
elseif($item['discount_type'] == PERCENT)
{
?>
<td colspan="3" class="discount"><?php echo number_format($item['discount'], 0) . " " . $this->lang->line("sales_discount_included") ?></td>
<?php
}
?>
</tr>
<?php
}

View File

@@ -104,11 +104,11 @@ if (isset($success))
<tr>
<th style="width:5%;"><?php echo $this->lang->line('common_delete'); ?></th>
<th style="width:15%;"><?php echo $this->lang->line('sales_item_number'); ?></th>
<th style="width:30%;"><?php echo $this->lang->line('receivings_item_name'); ?></th>
<th style="width:23%;"><?php echo $this->lang->line('receivings_item_name'); ?></th>
<th style="width:10%;"><?php echo $this->lang->line('receivings_cost'); ?></th>
<th style="width:10%;"><?php echo $this->lang->line('receivings_quantity'); ?></th>
<th style="width:10%;"><?php echo $this->lang->line('receivings_ship_pack'); ?></th>
<th style="width:5%;"><?php echo $this->lang->line('receivings_discount'); ?></th>
<th style="width:7%;"><?php echo $this->lang->line('receivings_ship_pack'); ?></th>
<th style="width:15%;"><?php echo $this->lang->line('receivings_discount'); ?></th>
<th style="width:10%;"><?php echo $this->lang->line('receivings_total'); ?></th>
<th style="width:5%;"><?php echo $this->lang->line('receivings_update'); ?></th>
</tr>
@@ -165,18 +165,26 @@ if (isset($success))
if ($items_module_allowed && $mode!='requisition')
{
?>
<td><?php echo form_input(array('name'=>'discount', 'class'=>'form-control input-sm', 'value'=>$item['discount']));?></td>
<td>
<div class="input-group">
<?php echo form_input(array('name'=>'discount', 'class'=>'form-control input-sm', 'value'=>to_decimals($item['discount'], 0), 'onClick'=>'this.select();')); ?>
<span class="input-group-btn">
<?php echo form_checkbox(array('id'=>'discount_toggle', 'name'=>'discount_toggle', 'value'=>1, 'data-toggle'=>"toggle",'data-size'=>'small', 'data-onstyle'=>'success', 'data-on'=>'<b>'.$this->config->item('currency_symbol').'</b>', 'data-off'=>'<b>%</b>', 'data-line'=>$line, 'checked'=>$item['discount_type'])); ?>
</span>
</div>
</td>
<?php
}
else
{
?>
<td><?php echo $item['discount']; ?></td>
<td><?php echo $item['discount'];?></td>
<?php echo form_hidden('discount',$item['discount']); ?>
<?php
}
?>
<td><?php echo to_currency($item['price']*$item['quantity']*$item['receiving_quantity']-$item['price']*$item['quantity']*$item['receiving_quantity']*$item['discount']/100); ?></td>
<td>
<?php echo to_currency(($item['discount_type'] == PERCENT) ? $item['price']*$item['quantity']*$item['receiving_quantity'] - $item['price'] * $item['quantity'] * $item['receiving_quantity'] * $item['discount'] / 100 : $item['price']*$item['quantity']*$item['receiving_quantity'] - $item['discount']); ?></td>
<td><a href="javascript:$('#<?php echo 'cart_'.$line ?>').submit();" title=<?php echo $this->lang->line('receivings_update')?> ><span class="glyphicon glyphicon-refresh"></span></a></td>
</tr>
<tr>
@@ -509,6 +517,12 @@ $(document).ready(function()
$(this).parents("tr").prevAll("form:first").submit()
});
$('[name="discount_toggle"]').change(function() {
var input = $("<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();
});
});
</script>

View File

@@ -55,6 +55,20 @@ if(isset($error))
}
?>
<?php
if (isset($discount_type_options))
{
?>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('reports_discount_type'), 'reports_discount_type_label', array('class'=>'required control-label col-xs-2')); ?>
<div id='report_discount_type' class="col-xs-3">
<?php echo form_dropdown('discount_type', $discount_type_options, $this->config->item('default_sales_discount_type'), array('id'=>'discount_type_id', 'class'=>'form-control')); ?>
</div>
</div>
<?php
}
?>
<?php
if (!empty($stock_locations) && count($stock_locations) > 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("/");
});
});
</script>

View File

@@ -22,11 +22,42 @@ if(isset($error))
</div>
</div>
<?php
if (isset($discount_type_options))
{
?>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('reports_discount_type'), 'reports_discount_type_label', array('class'=>'required control-label col-xs-2')); ?>
<div id='report_discount_type' class="col-xs-3">
<?php echo form_dropdown('discount_type', $discount_type_options, $this->config->item('default_sales_discount_type'), array('id'=>'discount_type_id', 'class'=>'form-control')); ?>
</div>
</div>
<?php
}
?>
<div class="form-group form-group-sm" id="report_specific_input_data">
<?php echo form_label($specific_input_name, 'specific_input_name_label', array('class'=>'required control-label col-xs-2')); ?>
<div class="col-xs-3">
<div class="col-xs-3 discount_percent">
<?php echo form_dropdown('specific_input_data', $specific_input_data, '', 'id="specific_input_data" class="form-control"'); ?>
</div>
<?php
if (isset($discount_type_options))
{
?>
<div class="col-xs-3 discount_fixed">
<?php echo form_input(array(
'name' => 'discount_fixed',
'id' => 'discount_fixed',
'class' => 'form-control input-sm required',
'type' => 'number',
'min' => 0,
'value' => $this->config->item('default_sales_discount'))); ?>
</div>
<?php
}
?>
</div>
<div class="form-group form-group-sm">
@@ -51,11 +82,38 @@ if(isset($error))
<script type="text/javascript">
$(document).ready(function()
{
<?php
if (isset($discount_type_options))
{
?>
$("#discount_type_id").change(check_discount_type).ready(check_discount_type);
<?php
}
?>
<?php $this->load->view('partial/daterangepicker'); ?>
$("#generate_report").click(function()
{
window.location = [window.location, start_date, end_date, $('#specific_input_data').val(), $("#input_type").val() || 0].join("/");
var specific_input_data = $('#specific_input_data').val();
if(!$(".discount_percent").is(":visible")){
specific_input_data = $('#discount_fixed').val();
}
window.location = [window.location, start_date, end_date, specific_input_data, $("#input_type").val() || 0, $("#discount_type_id").val() || 0].join("/");
});
});
function check_discount_type()
{
var discount_type = $("#discount_type_id").val();
if(discount_type==1){
$(".discount_percent").hide();
$(".discount_fixed").show();
}else{
$(".discount_percent").show();
$(".discount_fixed").hide();
}
}
</script>

View File

@@ -133,7 +133,7 @@ $(document).ready(function()
<td style='text-align:center;'><textarea rows="5" cols="6"><?php echo to_quantity_decimals($item['quantity']); ?></textarea>
</td>
<td><textarea rows="4" cols="6"><?php echo to_currency($item['price']); ?></textarea></td>
<td style='text-align:center;'><textarea rows="4" cols="6"><?php echo $item['discount'] . '%'; ?></textarea>
<td style='text-align:center;'><textarea rows="4" cols="6"><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):$item['discount'] . '%';?></textarea>
</td>
<?php if($discount > 0): ?>
<td style='text-align:center;'><textarea rows="4" cols="6"><?php echo to_currency($item['discounted_total'] / $item['quantity']); ?></textarea>

View File

@@ -96,7 +96,7 @@
<td class="item-name"><?php echo $item['name']; ?></td>
<td><?php echo to_quantity_decimals($item['quantity']); ?></td>
<td><?php echo to_currency($item['price']); ?></td>
<td><?php echo $item['discount'] . '%'; ?></td>
<td><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):$item['discount'] . '%';?></td>
<?php if ($item['discount'] > 0): ?>
<td><?php echo to_currency($item['discounted_total'] / $item['quantity']); ?></td>
<?php endif; ?>

View File

@@ -135,7 +135,7 @@ if (isset($error_message))
</td>
<td><textarea rows="4" cols="6"><?php echo to_currency($item['price']); ?></textarea></td>
<td style='text-align:center;'><textarea rows="4"
cols="6"><?php echo $item['discount'] . '%'; ?></textarea></td>
cols="6"><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):$item['discount'] . '%';?></textarea></td>
<?php if($discount > 0): ?>
<td style='text-align:center;'><textarea rows="4"
cols="6"><?php echo to_currency($item['discounted_total'] / $item['quantity']); ?></textarea>

View File

@@ -96,7 +96,7 @@
<td class="item-name"><?php echo $item['name']; ?></td>
<td><?php echo to_quantity_decimals($item['quantity']); ?></td>
<td><?php echo to_currency($item['price']); ?></td>
<td><?php echo $item['discount'] . '%'; ?></td>
<td><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):$item['discount'] . '%';?></td>
<?php if($discount > 0): ?>
<td><?php echo to_currency($item['discounted_total'] / $item['quantity']); ?></td>
<?php endif; ?>

View File

@@ -96,8 +96,20 @@
{
?>
<tr>
<td colspan="3"
class="discount"><?php echo number_format($item['discount'], 0) . " " . $this->lang->line("sales_discount_included") ?></td>
<?php
if($item['discount_type'] == FIXED)
{
?>
<td colspan="3" class="discount"><?php echo to_currency($item['discount']) . " " . $this->lang->line("sales_discount") ?></td>
<?php
}
elseif($item['discount_type'] == PERCENT)
{
?>
<td colspan="3" class="discount"><?php echo number_format($item['discount'], 0) . " " . $this->lang->line("sales_discount_included") ?></td>
<?php
}
?>
<td class="total-value"><?php echo to_currency($item['discounted_total']); ?></td>
</tr>
<?php

View File

@@ -91,8 +91,21 @@
{
?>
<tr>
<td colspan="3" style="font-weight: bold;"><?php echo number_format($item['discount'], 0) . " " . $this->lang->line("sales_discount_included") ?></td>
<td style="text-align:right;"><?php echo to_currency($item['discounted_total']); ?></td>
<?php
if($item['discount_type'] == FIXED)
{
?>
<td colspan="3" class="discount"><?php echo to_currency($item['discount']) . " " . $this->lang->line("sales_discount") ?></td>
<?php
}
elseif($item['discount_type'] == PERCENT)
{
?>
<td colspan="3" class="discount"><?php echo number_format($item['discount'], 0) . " " . $this->lang->line("sales_discount_included") ?></td>
<?php
}
?>
<td class="total-value"><?php echo to_currency($item['discounted_total']); ?></td>
</tr>
<?php
}

View File

@@ -93,12 +93,26 @@
{
?>
<tr>
<td colspan="2" class="discount"><?php echo number_format($item['discount'], 0) . " " . $this->lang->line("sales_discount_included")?></td>
<td class="total-value"><?php echo to_currency($item['discounted_total']) ; ?></td>
<?php
if($item['discount_type'] == FIXED)
{
?>
<td colspan="3" class="discount"><?php echo to_currency($item['discount']) . " " . $this->lang->line("sales_discount") ?></td>
<?php
}
elseif($item['discount_type'] == PERCENT)
{
?>
<td colspan="3" class="discount"><?php echo number_format($item['discount'], 0) . " " . $this->lang->line("sales_discount_included") ?></td>
<?php
}
?>
<td class="total-value"><?php echo to_currency($item['discounted_total']); ?></td>
</tr>
<?php
}
?>
<?php
}
?>

View File

@@ -107,10 +107,10 @@ if(isset($success))
<tr>
<th style="width: 5%;"><?php echo $this->lang->line('common_delete'); ?></th>
<th style="width: 15%;"><?php echo $this->lang->line('sales_item_number'); ?></th>
<th style="width: 35%;"><?php echo $this->lang->line('sales_item_name'); ?></th>
<th style="width: 30%;"><?php echo $this->lang->line('sales_item_name'); ?></th>
<th style="width: 10%;"><?php echo $this->lang->line('sales_price'); ?></th>
<th style="width: 10%;"><?php echo $this->lang->line('sales_quantity'); ?></th>
<th style="width: 10%;"><?php echo $this->lang->line('sales_discount'); ?></th>
<th style="width: 15%;"><?php echo $this->lang->line('sales_discount'); ?></th>
<th style="width: 10%;"><?php echo $this->lang->line('sales_total'); ?></th>
<th style="width: 5%;"><?php echo $this->lang->line('sales_update'); ?></th>
</tr>
@@ -195,7 +195,15 @@ if(isset($success))
?>
</td>
<td><?php echo form_input(array('name'=>'discount', 'class'=>'form-control input-sm', 'value'=>to_decimals($item['discount'], 0), 'tabindex'=>++$tabindex, 'onClick'=>'this.select();'));?></td>
<td>
<div class="input-group">
<?php echo form_input(array('name'=>'discount', 'class'=>'form-control input-sm', 'value'=>to_decimals($item['discount'], 0), 'tabindex'=>++$tabindex, 'onClick'=>'this.select();')); ?>
<span class="input-group-btn">
<?php echo form_checkbox(array('id'=>'discount_toggle', 'name'=>'discount_toggle', 'value'=>1, 'data-toggle'=>"toggle",'data-size'=>'small', 'data-onstyle'=>'success', 'data-on'=>'<b>'.$this->config->item('currency_symbol').'</b>', 'data-off'=>'<b>%</b>', 'data-line'=>$line, 'checked'=>$item['discount_type'])); ?>
</span>
</div>
</td>
<td>
<?php
if($item['item_type'] == ITEM_AMOUNT_ENTRY)
@@ -208,7 +216,8 @@ if(isset($success))
}
?>
</td>
<td><a href="javascript:document.getElementById("<?php echo 'cart_'.$line ?>").submit();" title=<?php echo $this->lang->line('sales_update')?> ><span class="glyphicon glyphicon-refresh"></span></a></td>
<td><a href="javascript:document.getElementById('<?php echo 'cart_'.$line ?>').submit();" title=<?php echo $this->lang->line('sales_update')?> ><span class="glyphicon glyphicon-refresh"></span></a></td>
</tr>
<tr>
<?php
@@ -340,7 +349,7 @@ if(isset($success))
?>
<tr>
<th style='width: 55%;'><?php echo $this->lang->line("sales_customer_discount"); ?></th>
<th style="width: 45%; text-align: right;"><?php echo $customer_discount_percent . ' %'; ?></th>
<th style="width: 45%; text-align: right;"><?php echo ($customer_discount_type == FIXED)?to_currency($customer_discount):$customer_discount . '%'; ?></th>
</tr>
<?php if($this->config->item('customer_reward_enable') == TRUE): ?>
<?php
@@ -895,6 +904,12 @@ $(document).ready(function()
$('[name="price"],[name="quantity"],[name="discount"],[name="description"],[name="serialnumber"],[name="discounted_total"]').change(function() {
$(this).parents("tr").prevAll("form:first").submit()
});
$('[name="discount_toggle"]').change(function() {
var input = $("<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();
});
});
function check_payment_type()

View File

@@ -123,7 +123,7 @@ if(isset($error_message))
<td class="item-name"><textarea rows="4" cols="6"><?php echo $item['name']; ?></textarea></td>
<td style='text-align:center;'><textarea rows="5" cols="6"><?php echo to_quantity_decimals($item['quantity']); ?></textarea></td>
<td><textarea rows="4" cols="6"><?php if($print_price_info) echo to_currency($item['price']); ?></textarea></td>
<td style='text-align:center;'><textarea rows="4" cols="6"><?php echo $item['discount'] . '%'; ?></textarea></td>
<td style='text-align:center;'><textarea rows="4" cols="6"><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):$item['discount'] . '%';?></textarea></td>
<td style='border-right: solid 1px; text-align:right;'><textarea rows="4" cols="6"><?php if($print_price_info) echo to_currency($item['discounted_total']); ?></textarea></td>
</tr>

View File

@@ -87,7 +87,7 @@
<td class="item-name"><?php echo $item['name']; ?></td>
<td><?php echo to_quantity_decimals($item['quantity']); ?></td>
<td><?php echo to_currency($item['price']); ?></td>
<td><?php echo $item['discount'] . '%'; ?></td>
<td><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):$item['discount'] . '%';?></td>
<td class="total-line"><?php echo to_currency($item['discounted_total']); ?></td>
</tr>
<?php

View File

@@ -43,7 +43,8 @@
"chartist-plugin-barlabels": "https://github.com/mtgibbs/chartist-plugin-barlabels.git#~0.0.5",
"remarkable-bootstrap-notify": "~3.1.3",
"js-cookie": "~2.1.4",
"bootstrap-tagsinput": "~0.8.0"
"bootstrap-tagsinput": "~0.8.0",
"bootstrap-toggle": "^2.2.2"
},
"overrides": {
"jquery-ui": {

View File

@@ -1,2 +1,2 @@
First Name,Last Name,Gender,Consent,Email,Phone Number,Address 1,Address2,City,State,Zip,Country,Comments,Company,Account Number,Discount,Taxable
Bob,Smith,1,y,bsmith@nowhere.com,585-555-1111,123 Nowhere Street,Apt 4,Awesome,NY,11111,USA,Awesome guy,,,5,y
First Name,Last Name,Gender,Consent,Email,Phone Number,Address 1,Address2,City,State,Zip,Country,Comments,Company,Account Number,Discount,Discount_Type,Taxable
Bob,Smith,1,y,bsmith@nowhere.com,585-555-1111,123 Nowhere Street,Apt 4,Awesome,NY,11111,USA,Awesome guy,,,5,0,y
1 First Name Last Name Gender Consent Email Phone Number Address 1 Address2 City State Zip Country Comments Company Account Number Discount Discount_Type Taxable
2 Bob Smith 1 y bsmith@nowhere.com 585-555-1111 123 Nowhere Street Apt 4 Awesome NY 11111 USA Awesome guy 5 0 y

View File

@@ -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