mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-10-20 07:14:33 -04:00
Discount on Sales
This commit is contained in:
1 parent
909cd52d56
commit
85bbbe835c
48 files changed
+508
-119
No files matched your search
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user