Fix missing cash refund in sale edit form

This commit is contained in:
FrancescoUK
2020-01-19 18:24:11 +00:00
parent 40d8ea0268
commit b4eabd2265
5 changed files with 66 additions and 27 deletions

View File

@@ -1215,10 +1215,10 @@ class Sales extends Secure_Controller
$data['balance_due'] = $balance_due != 0;
// don't allow gift card to be a payment option in a sale transaction edit because it's a complex change
$data['payment_options'] = $this->xss_clean($this->Sale->get_payment_options(FALSE));
$new_payment_options = $this->xss_clean($this->Sale->get_payment_options(FALSE));
$data['payment_options'] = $new_payment_options;
// Set up a slightly modified list of payment types for new payment entry
$new_payment_options = $this->Sale->get_payment_options(FALSE);
$new_payment_options["--"] = $this->lang->line('common_none_selected_text');
$data['new_payment_options'] = $this->xss_clean($new_payment_options);
@@ -1301,12 +1301,27 @@ class Sales extends Secure_Controller
for($i = 0; $i < $number_of_payments; ++$i)
{
$payment_id = $this->input->post('payment_id_' . $i);
$payment_amount = $this->input->post('payment_amount_' . $i);
$payment_type = $this->input->post('payment_type_' . $i);
$cash_refund = 0.00;
$payment_amount = $this->input->post('payment_amount_' . $i);
$refund_type = $this->input->post('refund_type_' . $i);
$cash_refund = $this->input->post('refund_amount_' . $i);
// To maintain tradition we will also delete any payments with 0 amount assuming these are mistakes
// introduced at sale time. This is now done in Sale.php
// if the refund is not cash ...
if(empty(strstr($refund_type, $this->lang->line('sales_cash'))))
{
// ... and it's positive ...
if($cash_refund > 0)
{
// ... change it to be a new negative payment (a "non-cash refund")
$payment_type = $refund_type;
$payment_amount = $payment_amount - $cash_refund;
$cash_refund = 0.00;
}
}
// To maintain tradition we will also delete any payments with 0 amount
// assuming these are mistakes introduced at sale time.
// This is now done in models/Sale.php
$payments[] = array('payment_id' => $payment_id, 'payment_type' => $payment_type, 'payment_amount' => $payment_amount, 'cash_refund' => $cash_refund, 'employee_id' => $employee_id);
}

View File

@@ -121,6 +121,7 @@ $lang["sales_receipt_no_email"] = "This customer does not have a valid email add
$lang["sales_receipt_number"] = "Sale #";
$lang["sales_receipt_sent"] = "Receipt sent to";
$lang["sales_receipt_unsent"] = "Receipt failed to be sent to";
$lang["sales_refund"] = "Refund Type";
$lang["sales_register"] = "Sales Register";
$lang["sales_remove_customer"] = "Remove Customer";
$lang["sales_return"] = "Return";

View File

@@ -121,6 +121,7 @@ $lang["sales_receipt_no_email"] = "This customer does not have a valid email add
$lang["sales_receipt_number"] = "Sale #";
$lang["sales_receipt_sent"] = "Receipt sent to";
$lang["sales_receipt_unsent"] = "Receipt failed to be sent to";
$lang["sales_refund"] = "Refund Type";
$lang["sales_register"] = "Sales Register";
$lang["sales_remove_customer"] = "Remove Customer";
$lang["sales_return"] = "Return";

View File

@@ -549,7 +549,7 @@ class Sale extends CI_Model
$cash_refund = $payment['cash_refund'];
$employee_id = $payment['employee_id'];
if($payment_id == - 1 && $payment_amount > 0)
if($payment_id == -1 && $payment_amount != 0)
{
// Add a new payment transaction
$sales_payments_data = array(
@@ -561,21 +561,22 @@ class Sale extends CI_Model
);
$success = $this->db->insert('sales_payments', $sales_payments_data);
}
if($payment_id != - 1)
elseif($payment_id != -1)
{
if($payment_amount > 0)
if($payment_amount != 0)
{
// Update existing payment transactions (payment_type only)
$sales_payments_data = array(
'payment_type' => $payment_type
'payment_type' => $payment_type,
'payment_amount' => $payment_amount,
'cash_refund' => $cash_refund
);
$this->db->where('payment_id',$payment_id);
$this->db->where('payment_id', $payment_id);
$success = $this->db->update('sales_payments', $sales_payments_data);
}
else
{
// Remove existing payment transactions with a payment amount of zero
// Remove existing payment transactions with a payment amount of zero
$success = $this->db->delete('sales_payments', array('payment_id' => $payment_id));
}
}
@@ -589,7 +590,6 @@ class Sale extends CI_Model
return $success;
}
/**
* Save the sale information after the sales is complete but before the final document is printed
* The sales_taxes variable needs to be initialized to an empty array before calling
@@ -640,17 +640,15 @@ class Sale extends CI_Model
$total_amount_used = 0;
foreach($payments as $payment_id=>$payment)
{
if( substr( $payment['payment_type'], 0, strlen( $this->lang->line('sales_giftcard') ) ) == $this->lang->line('sales_giftcard') )
if(!empty(strstr($payment['payment_type'], $this->lang->line('sales_giftcard'))))
{
// We have a gift card and we have to deduct the used value from the total value of the card.
$splitpayment = explode( ':', $payment['payment_type'] );
$cur_giftcard_value = $this->Giftcard->get_giftcard_value( $splitpayment[1] );
$this->Giftcard->update_giftcard_value( $splitpayment[1], $cur_giftcard_value - $payment['payment_amount'] );
}
if( substr( $payment['payment_type'], 0, strlen( $this->lang->line('sales_rewards') ) ) == $this->lang->line('sales_rewards') )
elseif(!empty(strstr($payment['payment_type'], $this->lang->line('sales_rewards'))))
{
$cur_rewards_value = $this->Customer->get_info($customer_id)->points;
$this->Customer->update_reward_points_value($customer_id, $cur_rewards_value - $payment['payment_amount'] );
$total_amount_used = floatval($total_amount_used) + floatval($payment['payment_amount']);
@@ -1398,6 +1396,7 @@ class Sale extends CI_Model
return $this->db->trans_status();
}
/**
* Gets suspended sale info
*/

View File

@@ -50,7 +50,7 @@
<span class="input-group-addon input-sm"><b><?php echo $this->config->item('currency_symbol'); ?></b></span>
<?php endif; ?>
<?php echo form_input(array('name'=>'payment_amount_new', 'value'=>$payment_amount_new, 'id'=>'payment_amount_new', 'class'=>'form-control input-sm'));?>
<?php if (currency_side()): ?>
<?php if(currency_side()): ?>
<span class="input-group-addon input-sm"><b><?php echo $this->config->item('currency_symbol'); ?></b></span>
<?php endif; ?>
</div>
@@ -68,13 +68,13 @@
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('sales_payment'), 'payment_'.$i, array('class'=>'control-label col-xs-3')); ?>
<div class='col-xs-4'>
<?php // no editing of Gift Card payments as it's a complex change ?>
<?php echo form_hidden('payment_id_'.$i, $row->payment_id); ?>
<?php if( !empty(strstr($row->payment_type, $this->lang->line('sales_giftcard'))) ): ?>
<?php echo form_input(array('name'=>'payment_type_'.$i, 'value'=>$row->payment_type, 'id'=>'payment_type_'.$i, 'class'=>'form-control input-sm', 'readonly'=>'true'));?>
<?php else: ?>
<?php echo form_dropdown('payment_type_'.$i, $payment_options, $row->payment_type, array('id'=>'payment_types_'.$i, 'class'=>'form-control')); ?>
<?php endif; ?>
<?php // no editing of Gift Card payments as it's a complex change ?>
<?php echo form_hidden('payment_id_'.$i, $row->payment_id); ?>
<?php if( !empty(strstr($row->payment_type, $this->lang->line('sales_giftcard'))) ): ?>
<?php echo form_input(array('name'=>'payment_type_'.$i, 'value'=>$row->payment_type, 'id'=>'payment_type_'.$i, 'class'=>'form-control input-sm', 'readonly'=>'true'));?>
<?php else: ?>
<?php echo form_dropdown('payment_type_'.$i, $payment_options, $row->payment_type, array('id'=>'payment_types_'.$i, 'class'=>'form-control')); ?>
<?php endif; ?>
</div>
<div class='col-xs-4'>
<div class="input-group input-group-sm">
@@ -82,7 +82,30 @@
<span class="input-group-addon input-sm"><b><?php echo $this->config->item('currency_symbol'); ?></b></span>
<?php endif; ?>
<?php echo form_input(array('name'=>'payment_amount_'.$i, 'value'=>$row->payment_amount, 'id'=>'payment_amount_'.$i, 'class'=>'form-control input-sm', 'readonly'=>'true'));?>
<?php if (currency_side()): ?>
<?php if(currency_side()): ?>
<span class="input-group-addon input-sm"><b><?php echo $this->config->item('currency_symbol'); ?></b></span>
<?php endif; ?>
</div>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('sales_refund'), 'refund_'.$i, array('class'=>'control-label col-xs-3')); ?>
<div class='col-xs-4'>
<?php // no editing of Gift Card payments as it's a complex change ?>
<?php if( !empty(strstr($row->payment_type, $this->lang->line('sales_giftcard'))) ): ?>
<?php echo form_input(array('name'=>'refund_type_'.$i, 'value'=>$this->lang->line('sales_cash'), 'id'=>'refund_type_'.$i, 'class'=>'form-control input-sm', 'readonly'=>'true'));?>
<?php else: ?>
<?php echo form_dropdown('refund_type_'.$i, $payment_options, $this->lang->line('sales_cash'), array('id'=>'refund_types_'.$i, 'class'=>'form-control')); ?>
<?php endif; ?>
</div>
<div class='col-xs-4'>
<div class="input-group input-group-sm">
<?php if(!currency_side()): ?>
<span class="input-group-addon input-sm"><b><?php echo $this->config->item('currency_symbol'); ?></b></span>
<?php endif; ?>
<?php echo form_input(array('name'=>'refund_amount_'.$i, 'value'=>$row->cash_refund, 'id'=>'refund_amount_'.$i, 'class'=>'form-control input-sm', 'readonly'=>'true'));?>
<?php if(currency_side()): ?>
<span class="input-group-addon input-sm"><b><?php echo $this->config->item('currency_symbol'); ?></b></span>
<?php endif; ?>
</div>