Topic: Customer Payment allocation error when customer invoices fail to load
In a situation where the user's internet is not stable and the user is trying to post a customer payment, and changes the customer from customer list but the system fails to populate customer invoices for the selected customer. Since the customer selected and invoices do not match, the system will allocate the payment wrongly i.e customer payment to the right customer but wrong invoices. This has happened to our organisation already.
To solve this, I would like to change the check_allocations() function in frontaccounting\includes\ui\allocation_cart.inc as follows:
=>check that all allocations match the customer selected
NB: I would like this fix to be included in the next release.
/************************Add this code to the function:***********************/
if($_SESSION['alloc']->person_type == PT_CUSTOMER){
if($_SESSION['alloc']->allocs[$counter]->type == ST_SALESINVOICE)
$trans = get_customer_trans($_SESSION['alloc']->allocs[$counter]->type_no, $_SESSION['alloc']->allocs[$counter]->type);
else if ($_SESSION['alloc']->allocs[$counter]->type == ST_SALESORDER)
$trans = get_sales_order_header($_SESSION['alloc']->allocs[$counter]->type_no, $_SESSION['alloc']->allocs[$counter]->type);
if($trans['debtor_no'] != $_SESSION['alloc']->person_id){
display_error(_("Cannot allocate to different persons."));
set_focus('amount'.$counter);
return false;
}
}
/*************************finally the function will be:************************/
function check_allocations()
{
global $SysPrefs;
$total_allocated = 0;
for ($counter = 0; $counter < get_post("TotalNumberOfAllocs"); $counter++)
{
if (!isset($_POST['amount'.$counter])) continue;
if (!check_num('amount' . $counter, 0))
{
display_error(_("The entry for one or more amounts is invalid or negative."));
set_focus('amount'.$counter);
return false;
}
/* Now check to see that the AllocAmt is no greater than the
amount left to be allocated against the transaction under review;
skip check if no allocation is set to avoid deadlock on mistakenly overallocated transactions*/
$allocated = input_num('amount' . $counter);
if ($allocated && ($allocated > input_num('un_allocated' . $counter)))
{
display_error(_("At least one transaction is overallocated."));
set_focus('amount'.$counter);
return false;
}
if($_SESSION['alloc']->person_type == PT_CUSTOMER){
if($_SESSION['alloc']->allocs[$counter]->type == ST_SALESINVOICE)
$trans = get_customer_trans($_SESSION['alloc']->allocs[$counter]->type_no, $_SESSION['alloc']->allocs[$counter]->type);
else if ($_SESSION['alloc']->allocs[$counter]->type == ST_SALESORDER)
$trans = get_sales_order_header($_SESSION['alloc']->allocs[$counter]->type_no, $_SESSION['alloc']->allocs[$counter]->type);
if($trans['debtor_no'] != $_SESSION['alloc']->person_id){
display_error(_("Cannot allocate to different persons."));
set_focus('amount'.$counter);
return false;
}
}
$_SESSION['alloc']->allocs[$counter]->current_allocated = input_num('amount' . $counter);
$total_allocated += input_num('amount' . $counter);
}
$amount = abs($_SESSION['alloc']->amount);
if ($total_allocated - ($amount + input_num('discount') + input_num('whtax')) > $SysPrefs->allocation_settled_allowance())
{
display_error(_("These allocations cannot be processed because the amount allocated is more than the total amount left to allocate."));
return false;
}
return true;
}