diff --git a/application/controllers/Sales.php b/application/controllers/Sales.php
index b33be1da6..4e99ebc3c 100644
--- a/application/controllers/Sales.php
+++ b/application/controllers/Sales.php
@@ -280,7 +280,6 @@ class Sales extends Secure_Controller
}
elseif($this->Item_kit->is_valid_item_kit($item_id_or_number_or_item_kit_or_receipt))
{
-
// Add kit item to order if one is assigned
$pieces = explode(' ', $item_id_or_number_or_item_kit_or_receipt);
$item_kit_id = $pieces[1];
@@ -290,7 +289,7 @@ class Sales extends Secure_Controller
$stock_type = $item_kit_info->stock_type;
$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_percent != 0 && $item_kit_info->kit_discount_percent > $discount)
{
$discount = $item_kit_info->kit_discount_percent;
}
@@ -298,7 +297,7 @@ class Sales extends Secure_Controller
$price = null;
$print_option = 0; // Always include in list of items on invoice
- if ($kit_item_id !== '' && $kit_item_id != 0)
+ if(!empty($kit_item_id))
{
if(!$this->sale_lib->add_item($kit_item_id, $quantity, $item_location, $discount, $price, null, null, null, $print_option))
{
@@ -310,8 +309,6 @@ 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, $price_option, $kit_print_option, $stock_warning))
@@ -322,7 +319,6 @@ class Sales extends Secure_Controller
{
$data['warning'] = $stock_warning;
}
-
}
else
{
@@ -694,7 +690,7 @@ class Sales extends Secure_Controller
$data['invoice_number'] = $this->_substitute_invoice_number($customer_info);
$data['invoice_number_enabled'] = $this->sale_lib->is_invoice_number_enabled();
$data['print_after_sale'] = $this->sale_lib->is_print_after_sale();
- $data['payments_cover_total'] = $this->sale_lib->get_amount_due() <= 0;
+ $data['payments_cover_total'] = $this->sale_lib->is_payment_covering_total();
$data = $this->xss_clean($data);
diff --git a/application/libraries/Sale_lib.php b/application/libraries/Sale_lib.php
index 21545008f..6422baae0 100644
--- a/application/libraries/Sale_lib.php
+++ b/application/libraries/Sale_lib.php
@@ -201,7 +201,15 @@ class Sale_lib
$precision = $this->CI->config->item('currency_decimals');
$rounded_due = bccomp(round($amount_due, $precision, PHP_ROUND_HALF_EVEN), 0, $precision);
// take care of rounding error introduced by round tripping payment amount to the browser
- return $rounded_due == 0 ? 0 : $amount_due;
+ return $rounded_due == 0 ? 0 : $amount_due;
+ }
+
+ public function is_payment_covering_total()
+ {
+ $amount_due = $this->get_amount_due();
+ // 0 decimal -> 1 / 2 = 0.5, 1 decimals -> 0.1 / 2 = 0.05, 2 decimals -> 0.01 / 2 = 0.005
+ $threshold = bcpow(10, -$this->CI->config->item('currency_decimals')) / 2;
+ return ($amount_due > -$threshold && $amount_due < $threshold);
}
public function get_customer()
@@ -301,11 +309,11 @@ class Sale_lib
public function add_item(&$item_id, $quantity = 1, $item_location, $discount = 0, $price = NULL, $description = NULL, $serialnumber = NULL, $include_deleted = FALSE, $print_option = '0')
{
-
$item_info = $this->CI->Item->get_info_by_id_or_number($item_id);
//make sure item exists
- if (empty($item_info)) {
+ if(empty($item_info))
+ {
$item_id = -1;
return FALSE;
}
@@ -332,11 +340,13 @@ class Sale_lib
//We primed the loop so maxkey is 0 the first time.
//Also, we have stored the key in the element itself so we can compare.
- if ($maxkey <= $item['line']) {
+ if($maxkey <= $item['line'])
+ {
$maxkey = $item['line'];
}
- if ($item['item_id'] == $item_id && $item['item_location'] == $item_location) {
+ if($item['item_id'] == $item_id && $item['item_location'] == $item_location)
+ {
$itemalreadyinsale = TRUE;
$updatekey = $item['line'];
if(!$item_info->is_serialized)
@@ -349,11 +359,11 @@ class Sale_lib
$insertkey = $maxkey + 1;
//array/cart records are identified by $insertkey and item_id is just another field.
- if (is_null($price))
+ if(is_null($price))
{
$price = $item_info->unit_price;
}
- elseif ($price == 0)
+ elseif($price == 0)
{
$price = 0.00;
$discount = 0.00;
diff --git a/application/views/sales/register.php b/application/views/sales/register.php
index 50cede8c7..4ab4b31db 100644
--- a/application/views/sales/register.php
+++ b/application/views/sales/register.php
@@ -350,55 +350,55 @@ if (isset($success))
-
- 'add_payment_form', 'class'=>'form-horizontal')); ?>
-
-
- | lang->line('sales_payment');?> |
-
- 'payment_types', 'class'=>'selectpicker show-menu-arrow', 'data-style'=>'btn-default btn-sm', 'data-width'=>'auto', 'disabled'=>'disabled')); ?>
- |
-
-
- | lang->line('sales_amount_tendered'); ?> |
-
- 'amount_tendered', 'id'=>'amount_tendered', 'class'=>'form-control input-sm disabled', 'disabled'=>'disabled', 'value'=>'0', 'size'=>'5', 'tabindex'=>++$tabindex)); ?>
- |
-
-
-
+
+ 'add_payment_form', 'class'=>'form-horizontal')); ?>
+
+
+ | lang->line('sales_payment');?> |
+
+ 'payment_types', 'class'=>'selectpicker show-menu-arrow', 'data-style'=>'btn-default btn-sm', 'data-width'=>'auto', 'disabled'=>'disabled')); ?>
+ |
+
+
+ | lang->line('sales_amount_tendered'); ?> |
+
+ 'amount_tendered', 'id'=>'amount_tendered', 'class'=>'form-control input-sm disabled', 'disabled'=>'disabled', 'value'=>'0', 'size'=>'5', 'tabindex'=>++$tabindex)); ?>
+ |
+
+
+
-
 lang->line('sales_complete_sale'); ?>
-
- 'add_payment_form', 'class'=>'form-horizontal')); ?>
-
-
- | lang->line('sales_payment');?> |
-
- 'payment_types', 'class'=>'selectpicker show-menu-arrow', 'data-style'=>'btn-default btn-sm', 'data-width'=>'auto')); ?>
- |
-
-
- | lang->line('sales_amount_tendered'); ?> |
-
- 'amount_tendered', 'id'=>'amount_tendered', 'class'=>'form-control input-sm', 'value'=>to_currency_no_money($amount_due), 'size'=>'5', 'tabindex'=>++$tabindex)); ?>
- |
-
-
-
+
 lang->line('sales_complete_sale'); ?>
+
+ 'add_payment_form', 'class'=>'form-horizontal')); ?>
+
+
+ | lang->line('sales_payment');?> |
+
+ 'payment_types', 'class'=>'selectpicker show-menu-arrow', 'data-style'=>'btn-default btn-sm', 'data-width'=>'auto')); ?>
+ |
+
+
+ | lang->line('sales_amount_tendered'); ?> |
+
+ 'amount_tendered', 'id'=>'amount_tendered', 'class'=>'form-control input-sm', 'value'=>to_currency_no_money($amount_due), 'size'=>'5', 'tabindex'=>++$tabindex)); ?>
+ |
+
+
+
-
 lang->line('sales_add_payment'); ?>
-
+
 lang->line('sales_add_payment'); ?>
+