mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-05-24 08:20:54 -04:00
fix wrong behaviour with due amount and Complete button on "sale" <=0 and "return" >=0 (#116)
This commit is contained in:
@@ -230,7 +230,7 @@ class Sales extends Secure_area
|
||||
$new_giftcard_value = ( $new_giftcard_value >= 0 ) ? $new_giftcard_value : 0;
|
||||
$this->sale_lib->set_giftcard_remainder($new_giftcard_value);
|
||||
$data['warning'] = $this->lang->line('giftcards_remaining_balance', $this->input->post('amount_tendered'), to_currency( $new_giftcard_value, TRUE ));
|
||||
$payment_amount = min( $this->sale_lib->get_amount_due( ), $this->Giftcard->get_giftcard_value( $this->input->post('amount_tendered') ) );
|
||||
$payment_amount = min( $this->sale_lib->get_amount_due(), $this->Giftcard->get_giftcard_value( $this->input->post('amount_tendered') ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -669,6 +669,25 @@ class Sales extends Secure_area
|
||||
}
|
||||
}
|
||||
|
||||
private function _payments_cover_total()
|
||||
{
|
||||
// Changed the conditional to account for floating point rounding
|
||||
|
||||
// "sale" amount due needs to be <=0 to state it's fine
|
||||
if( ($this->sale_lib->get_mode() == 'sale') && $this->sale_lib->get_amount_due() > 1e-6 )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// "return" amount due needs to be >=0 to state it's fine
|
||||
if( ($this->sale_lib->get_mode() == 'return') && $this->sale_lib->get_amount_due() < -(1e-6) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function _reload($data=array())
|
||||
{
|
||||
$person_info = $this->Employee->get_logged_in_employee_info();
|
||||
@@ -735,6 +754,7 @@ class Sales extends Secure_area
|
||||
$data['invoice_number'] = $this->_substitute_invoice_number($cust_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->_payments_cover_total();
|
||||
|
||||
$this->load->view("sales/register", $data);
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ class Sale_lib
|
||||
$this->CI->session->unset_userdata('email_receipt');
|
||||
}
|
||||
|
||||
function add_payment( $payment_id, $payment_amount )
|
||||
function add_payment($payment_id, $payment_amount)
|
||||
{
|
||||
$payments = $this->get_payments();
|
||||
if( isset( $payments[$payment_id] ) )
|
||||
@@ -122,22 +122,22 @@ class Sale_lib
|
||||
{
|
||||
//add to existing array
|
||||
$payment = array( $payment_id=>
|
||||
array(
|
||||
'payment_type' => $payment_id,
|
||||
'payment_amount' => $payment_amount
|
||||
)
|
||||
array(
|
||||
'payment_type' => $payment_id,
|
||||
'payment_amount' => $payment_amount
|
||||
)
|
||||
);
|
||||
|
||||
$payments += $payment;
|
||||
}
|
||||
|
||||
$this->set_payments( $payments );
|
||||
$this->set_payments($payments);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Multiple Payments
|
||||
function edit_payment($payment_id,$payment_amount)
|
||||
function edit_payment($payment_id, $payment_amount)
|
||||
{
|
||||
$payments = $this->get_payments();
|
||||
if(isset($payments[$payment_id]))
|
||||
@@ -151,7 +151,7 @@ class Sale_lib
|
||||
}
|
||||
|
||||
// Multiple Payments
|
||||
function delete_payment( $payment_id )
|
||||
function delete_payment($payment_id)
|
||||
{
|
||||
$payments = $this->get_payments();
|
||||
unset( $payments[urldecode( $payment_id )] );
|
||||
@@ -172,17 +172,17 @@ class Sale_lib
|
||||
{
|
||||
$subtotal = bcadd($payments['payment_amount'], $subtotal, PRECISION);
|
||||
}
|
||||
|
||||
return to_currency_no_money($subtotal);
|
||||
}
|
||||
|
||||
// Multiple Payments
|
||||
function get_amount_due()
|
||||
{
|
||||
$amount_due=0;
|
||||
$payment_total = $this->get_payments_total();
|
||||
$sales_total=$this->get_total();
|
||||
$amount_due=to_currency_no_money(bcsub($sales_total, $payment_total, PRECISION));
|
||||
return $amount_due;
|
||||
$sales_total = $this->get_total();
|
||||
|
||||
return to_currency_no_money(bcsub($sales_total, $payment_total, PRECISION));
|
||||
}
|
||||
|
||||
function get_customer()
|
||||
@@ -218,6 +218,7 @@ class Sale_lib
|
||||
$location_id = $this->CI->Stock_location->get_default_location_id();
|
||||
$this->set_sale_location($location_id);
|
||||
}
|
||||
|
||||
return $this->CI->session->userdata('sale_location');
|
||||
}
|
||||
|
||||
@@ -246,7 +247,7 @@ class Sale_lib
|
||||
$this->CI->session->unset_userdata('giftcard_remainder');
|
||||
}
|
||||
|
||||
function add_item($item_id,$quantity=1,$item_location,$discount=0,$price=null,$description=null,$serialnumber=null)
|
||||
function add_item($item_id, $quantity=1, $item_location, $discount=0, $price=null, $description=null, $serialnumber=null)
|
||||
{
|
||||
//make sure item exists
|
||||
if($this->validate_item($item_id) == false)
|
||||
@@ -334,7 +335,7 @@ class Sale_lib
|
||||
return true;
|
||||
}
|
||||
|
||||
function out_of_stock($item_id,$item_location)
|
||||
function out_of_stock($item_id, $item_location)
|
||||
{
|
||||
//make sure item exists
|
||||
if($this->validate_item($item_id) == false)
|
||||
@@ -359,7 +360,7 @@ class Sale_lib
|
||||
return false;
|
||||
}
|
||||
|
||||
function get_quantity_already_added($item_id,$item_location)
|
||||
function get_quantity_already_added($item_id, $item_location)
|
||||
{
|
||||
$items = $this->get_cart();
|
||||
$quanity_already_added = 0;
|
||||
@@ -389,7 +390,7 @@ class Sale_lib
|
||||
return -1;
|
||||
}
|
||||
|
||||
function edit_item($line,$description,$serialnumber,$quantity,$discount,$price)
|
||||
function edit_item($line, $description, $serialnumber, $quantity, $discount, $price)
|
||||
{
|
||||
$items = $this->get_cart();
|
||||
if(isset($items[$line]))
|
||||
|
||||
@@ -341,7 +341,7 @@ if (isset($success))
|
||||
<?php echo form_open("sales/add_payment", array('id'=>'add_payment_form', 'class'=>'form-horizontal')); ?>
|
||||
<?php
|
||||
// Show Complete sale button instead of Add Payment if there is no amount due left
|
||||
if( $amount_due == 0 )
|
||||
if( $payments_cover_total )
|
||||
{
|
||||
?>
|
||||
<table class="sales_table_100">
|
||||
|
||||
Reference in New Issue
Block a user