Post Reply 
 
Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Credit Note Allocations off
01-17-2020, 04:36 AM
Post: #1
Credit Note Allocations off
When I create a credit note for a customer who has returned a item in debtortrans it post ovamount correct and ovgst amount correct then when I go ahead and allocate the amount the ovamount is correct but the ovgst amount is rounded off here is an example
the original oavamount was -288.65 and ovgst amount was -23.813625 then after allocation of the amount the alloc in debtortrans is -312.46 and should have been 312.463625.
In turn this may show a customer balance being off .01 or -.01
Any help would be greatly appreciated.
Note the version is 4.12.3
Thanks
Find all posts by this user
Quote this message in a reply
01-17-2020, 08:43 AM
Post: #2
RE: Credit Note Allocations off
It appears from looking at the code that the invoicing script (ConfirmDispatch_Invoice.php) is not rounding the tax figures to the required decimal places, whereas the crediting script (Credit_Invoice.php) is rounding the tax amount on line 542 of the current version. Does this agree with your findings?

If yes, then the answer is to the problem is to insert the lines:

$_SESSION['Items' . $identifier]->total = round($_SESSION['Items' . $identifier]->total, $_SESSION['Items' . $identifier]->CurrDecimalPlaces);
$TaxTotal = round($TaxTotal, $_SESSION['Items' . $identifier]->CurrDecimalPlaces);

at around line 813 of ConfirmDispatch_Invoice.php

It's late and so I haven't had the time to test this but it should work.

Tim
Visit this user's website Find all posts by this user
Quote this message in a reply
01-18-2020, 08:39 PM
Post: #3
RE: Credit Note Allocations off
Well I have run my own tests which appear to corroborate what I said, and in the absence of any reaction to my proposed fix I assume nobody disagrees so I have committed this change.

Tim
Visit this user's website Find all posts by this user
Quote this message in a reply
01-19-2020, 02:27 AM
Post: #4
RE: Credit Note Allocations off
Thanks Tim, change pulled.
Find all posts by this user
Quote this message in a reply
01-20-2020, 12:43 PM
Post: #5
RE: Credit Note Allocations off
(01-18-2020 08:39 PM)falkoner Wrote:  Well I have run my own tests which appear to corroborate what I said, and in the absence of any reaction to my proposed fix I assume nobody disagrees so I have committed this change.

Tim

Thanks
I applied and all worked well.
Find all posts by this user
Quote this message in a reply
01-21-2020, 02:16 PM
Post: #6
RE: Credit Note Allocations off
(01-17-2020 08:43 AM)falkoner Wrote:  It appears from looking at the code that the invoicing script (ConfirmDispatch_Invoice.php) is not rounding the tax figures to the required decimal places, whereas the crediting script (Credit_Invoice.php) is rounding the tax amount on line 542 of the current version. Does this agree with your findings?

If yes, then the answer is to the problem is to insert the lines:

$_SESSION['Items' . $identifier]->total = round($_SESSION['Items' . $identifier]->total, $_SESSION['Items' . $identifier]->CurrDecimalPlaces);
$TaxTotal = round($TaxTotal, $_SESSION['Items' . $identifier]->CurrDecimalPlaces);

at around line 813 of ConfirmDispatch_Invoice.php

It's late and so I haven't had the time to test this but it should work.

Tim

Tim
After updating the script and testing for a couple days I have a issue with rounding, debtortrans alloc is not rounding this happens when I credit an invoice with Credit_Invoice.php it post ovamount and ovgst rounded correctly I think it may be this line '" . -$Allocate_amount . "',
any thoughts.
Thanks
Dave
Find all posts by this user
Quote this message in a reply
01-21-2020, 08:17 PM
Post: #7
RE: Credit Note Allocations off
(01-21-2020 02:16 PM)daveparrish Wrote:  Tim
After updating the script and testing for a couple days I have a issue with rounding, debtortrans alloc is not rounding this happens when I credit an invoice with Credit_Invoice.php it post ovamount and ovgst rounded correctly I think it may be this line '" . -$Allocate_amount . "',
any thoughts.
Thanks
Dave

Dave, does this credit note have freight on, or maybe the invoice was partially allocated? Anyway, can you replace the block of code (it starts at line 539 on the latest version) with the following:

PHP Code:
    /*Do some rounding */

    
$_SESSION['CreditItems' $identifier]->FreightCost round($_SESSION['CreditItems' $identifier]->FreightCost$_SESSION['CreditItems' $identifier]->CurrDecimalPlaces);
    
$_SESSION['CreditItems' $identifier]->total round($_SESSION['CreditItems' $identifier]->total$_SESSION['CreditItems' $identifier]->CurrDecimalPlaces);
    
$TaxTotal round($TaxTotal$_SESSION['CreditItems' $identifier]->CurrDecimalPlaces);

    
$Allocate_amount 0;
    
$Settled 0;
    
$SettledInvoice 0;
    
$MyRow[0] = round($MyRow[0], $_SESSION['CreditItems' $identifier]->CurrDecimalPlaces););
    if (
$MyRow[0] > 0) { /*the invoice is not already fully allocated */

        
if ($MyRow[0] > ($_SESSION['CreditItems' $identifier]->total $_SESSION['CreditItems' $identifier]->FreightCost $TaxTotal)) {

            
$Allocate_amount $_SESSION['CreditItems' $identifier]->total $_SESSION['CreditItems' $identifier]->FreightCost $TaxTotal;
            
$SettledInvoice 0;
            
$Settled 1;
        } else if (
$MyRow[0] < ($_SESSION['CreditItems' $identifier]->total $_SESSION['CreditItems' $identifier]->FreightCost $TaxTotal)) {
            
/*the balance left to allocate is less than the credit note value */
            
$Allocate_amount $MyRow[0];
            
$SettledInvoice 1;
            
$Settled 0;
        } else {
            
$Allocate_amount $MyRow[0];
            
$SettledInvoice 1;
            
$Settled 1;
        }

        
/*Now need to update the invoice DebtorTrans record for the amount to be allocated and if the invoice is now settled*/

        
$SQL "UPDATE debtortrans
                SET alloc = alloc + " 
$Allocate_amount ",
                    settled='" 
$SettledInvoice "'
                WHERE transno = '" 
$_SESSION['ProcessingCredit'] . "'
                AND type=10"
;

        
$ErrMsg _('CRITICAL ERROR') . '! ' _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' _('The alteration to the invoice record to reflect the allocation of the credit note to the invoice could not be done because');
        
$DbgMsg _('The following SQL to update the invoice allocation was used');
        
$Result DB_query($SQL$ErrMsg$DbgMsgtrue);
    } 

Thanks
Tim[/php]
Visit this user's website Find all posts by this user
Quote this message in a reply
01-22-2020, 12:10 AM
Post: #8
RE: Credit Note Allocations off
(01-21-2020 08:17 PM)falkoner Wrote:  
(01-21-2020 02:16 PM)daveparrish Wrote:  Tim
After updating the script and testing for a couple days I have a issue with rounding, debtortrans alloc is not rounding this happens when I credit an invoice with Credit_Invoice.php it post ovamount and ovgst rounded correctly I think it may be this line '" . -$Allocate_amount . "',
any thoughts.
Thanks
Dave

Dave, does this credit note have freight on, or maybe the invoice was partially allocated? Anyway, can you replace the block of code (it starts at line 539 on the latest version) with the following:

PHP Code:
    /*Do some rounding */

    
$_SESSION['CreditItems' $identifier]->FreightCost round($_SESSION['CreditItems' $identifier]->FreightCost$_SESSION['CreditItems' $identifier]->CurrDecimalPlaces);
    
$_SESSION['CreditItems' $identifier]->total round($_SESSION['CreditItems' $identifier]->total$_SESSION['CreditItems' $identifier]->CurrDecimalPlaces);
    
$TaxTotal round($TaxTotal$_SESSION['CreditItems' $identifier]->CurrDecimalPlaces);

    
$Allocate_amount 0;
    
$Settled 0;
    
$SettledInvoice 0;
    
$MyRow[0] = round($MyRow[0], $_SESSION['CreditItems' $identifier]->CurrDecimalPlaces););
    if (
$MyRow[0] > 0) { /*the invoice is not already fully allocated */

        
if ($MyRow[0] > ($_SESSION['CreditItems' $identifier]->total $_SESSION['CreditItems' $identifier]->FreightCost $TaxTotal)) {

            
$Allocate_amount $_SESSION['CreditItems' $identifier]->total $_SESSION['CreditItems' $identifier]->FreightCost $TaxTotal;
            
$SettledInvoice 0;
            
$Settled 1;
        } else if (
$MyRow[0] < ($_SESSION['CreditItems' $identifier]->total $_SESSION['CreditItems' $identifier]->FreightCost $TaxTotal)) {
            
/*the balance left to allocate is less than the credit note value */
            
$Allocate_amount $MyRow[0];
            
$SettledInvoice 1;
            
$Settled 0;
        } else {
            
$Allocate_amount $MyRow[0];
            
$SettledInvoice 1;
            
$Settled 1;
        }

        
/*Now need to update the invoice DebtorTrans record for the amount to be allocated and if the invoice is now settled*/

        
$SQL "UPDATE debtortrans
                SET alloc = alloc + " 
$Allocate_amount ",
                    settled='" 
$SettledInvoice "'
                WHERE transno = '" 
$_SESSION['ProcessingCredit'] . "'
                AND type=10"
;

        
$ErrMsg _('CRITICAL ERROR') . '! ' _('NOTE DOWN THIS ERROR AND SEEK ASSISTANCE') . ': ' _('The alteration to the invoice record to reflect the allocation of the credit note to the invoice could not be done because');
        
$DbgMsg _('The following SQL to update the invoice allocation was used');
        
$Result DB_query($SQL$ErrMsg$DbgMsgtrue);
    } 

Thanks
Tim[/php]
Tim
I dose have freight on it I tried the code and get error 500
Thanks
Find all posts by this user
Quote this message in a reply
01-22-2020, 12:19 AM (This post was last modified: 01-22-2020 12:43 AM by falkoner.)
Post: #9
RE: Credit Note Allocations off
Sorry my bad, the line

PHP Code:
$MyRow[0] = round($MyRow[0], $_SESSION['CreditItems' $identifier]->CurrDecimalPlaces);); 
has acquired an extra ); on the end. Just remove these.

Apologies,
Tim
Visit this user's website Find all posts by this user
Quote this message in a reply
01-28-2020, 07:27 PM
Post: #10
RE: Credit Note Allocations off
I am assuming from the non-reaction that this is OK, so I have committed it.

Tim
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:


User(s) browsing this thread: 1 Guest(s)