Topic: Bug in Customer Payments Recording

The bug I am going to detail here needs a scenario.

Using on Journal Entry I recorded the Opening Balances of all customers.
Upon recording payment for one out of those customers I encountered following error.

/PATH-TO-FA/includes/errors.inc:207:    trigger_error('DATABASE ERROR : duplicate debtor transactions found for given params
sql that failed was : SELECT trans.*,ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount AS Total,cust.name AS DebtorName, cust.address, cust.curr_code, cust.tax_id, trans.prep_amount>0 as prepaid,com.memo_, branch.* FROM debtor_trans trans LEFT JOIN comments com ON trans.type=com.type AND trans.trans_no=com.id LEFT JOIN shippers ON shippers.shipper_id=trans.ship_via, debtors_master cust, cust_branch branch WHERE trans.trans_no='96' AND trans.type='0' AND trans.debtor_no=cust.debtor_no AND branch.branch_code = trans.branch_code


','256')
/PATH-TO-FA/sales/includes/db/cust_trans_db.inc:214:    display_db_error('duplicate debtor transactions found for given params','SELECT trans.*,ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount AS Total,cust.name AS DebtorName, cust.address, cust.curr_code, cust.tax_id, trans.prep_amount>0 as prepaid,com.memo_, branch.* FROM &TB_PREF&debtor_trans trans LEFT JOIN &TB_PREF&comments com ON trans.type=com.type AND trans.trans_no=com.id LEFT JOIN &TB_PREF&shippers ON &TB_PREF&shippers.shipper_id=trans.ship_via, &TB_PREF&debtors_master cust, &TB_PREF&cust_branch branch WHERE trans.trans_no='96' AND trans.type='0' AND trans.debtor_no=cust.debtor_no AND branch.branch_code = trans.branch_code ','1')
/PATH-TO-FA/includes/ui/allocation_cart.inc:381:    get_customer_trans('96','0')
/PATH-TO-FA/sales/customer_payments.php:222:    check_allocations()
/PATH-TO-FA/sales/customer_payments.php:236:    can_process()

The reason for this bug is that multiple customer payments are recorded for One Transaction Number and Same Transaction Type.

I found the solution to this is to add 3rd argument in function call get_customer_trans() in /includes/ui/allocation_cart.inc as below on Line#399

                $trans = get_customer_trans($_SESSION['alloc']->allocs[$counter]->type_no, $_SESSION['alloc']->allocs[$counter]->type, $_SESSION['alloc']->person_id);

I hope this shall not cause any other bug.

www.boxygen.pk

Re: Bug in Customer Payments Recording

This line of code was modified a while ago in this topic:frontaccounting.com/punbb/viewtopic.php?id=8672
This code however throws an error on journal entries (As mentioned above), Prepaid sales Orders and purchase orders. To rectify all these I have modified the code as below:

if ($_SESSION['alloc']->person_type == PT_CUSTOMER) {
            if ($_SESSION['alloc']->allocs[$counter]->type == ST_SALESORDER)
                $trans = get_sales_order_header($_SESSION['alloc']->allocs[$counter]->type_no, $_SESSION['alloc']->allocs[$counter]->type);
            else if($_SESSION['alloc']->allocs[$counter]->type == ST_JOURNAL){
                            $trans['debtor_no'] = db_num_rows(get_gl_transactions($_SESSION['alloc']->allocs[$counter]->date_, $_SESSION['alloc']->allocs[$counter]->date_, $_SESSION['alloc']->allocs[$counter]->type_no,null, 0, 0, $_SESSION['alloc']->allocs[$counter]->type,null,null, PT_CUSTOMER, $_SESSION['alloc']->person_id))?$_SESSION['alloc']->person_id:0;
                        } else
                $trans = get_customer_trans($_SESSION['alloc']->allocs[$counter]->type_no, $_SESSION['alloc']->allocs[$counter]->type);

            if ($trans['debtor_no'] != $_SESSION['alloc']->person_id) {
                display_error(_("Allocated transaction allocated is not related to company selected."));
                set_focus('amount'.$counter);
                return false;
            }
        } elseif ($_SESSION['alloc']->person_type == PT_SUPPLIER) {
            if ($_SESSION['alloc']->allocs[$counter]->type == ST_PURCHORDER)
                $trans['supplier_id'] = $_SESSION['alloc']->person_id;
            else if($_SESSION['alloc']->allocs[$counter]->type == ST_JOURNAL){
                            $trans['supplier_id'] = db_num_rows(get_gl_transactions($_SESSION['alloc']->allocs[$counter]->date_, $_SESSION['alloc']->allocs[$counter]->date_, $_SESSION['alloc']->allocs[$counter]->type_no,null, 0, 0, $_SESSION['alloc']->allocs[$counter]->type,null,null, PT_SUPPLIER, $_SESSION['alloc']->person_id))?$_SESSION['alloc']->person_id:0;
                        } else 
                            $trans = get_supp_trans($_SESSION['alloc']->allocs[$counter]->type_no, $_SESSION['alloc']->allocs[$counter]->type);
            if ($trans['supplier_id'] != $_SESSION['alloc']->person_id) {
                display_error(_("Allocated transaction allocated is not related to company selected."));
                set_focus('amount'.$counter);
                return false;
            }
        }

@Administrators please re-look into this issue because this bug is serious

Re: Bug in Customer Payments Recording

@joe, @itronics: ??

Re: Bug in Customer Payments Recording

I will ask Janusz to look into this.

/Joe

Re: Bug in Customer Payments Recording

I also experience this issue where I had to do a journal entry to fix the Debtors control account and outstanding balances. Now because there is an unallocated journal entry, I cannot process the Allocate Customer Payment nor add Customer payment nor Bank Deposit.  When I process nothing happens. This means that the client account is stuck, but the debtor's control account balances is now correct.

How do we fix this issue?

Wynand

Re: Bug in Customer Payments Recording

boxygen wrote:

The bug I am going to detail here needs a scenario.

Using on Journal Entry I recorded the Opening Balances of all customers.
Upon recording payment for one out of those customers I encountered following error.

/PATH-TO-FA/includes/errors.inc:207:    trigger_error('DATABASE ERROR : duplicate debtor transactions found for given params
sql that failed was : SELECT trans.*,ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount AS Total,cust.name AS DebtorName, cust.address, cust.curr_code, cust.tax_id, trans.prep_amount>0 as prepaid,com.memo_, branch.* FROM debtor_trans trans LEFT JOIN comments com ON trans.type=com.type AND trans.trans_no=com.id LEFT JOIN shippers ON shippers.shipper_id=trans.ship_via, debtors_master cust, cust_branch branch WHERE trans.trans_no='96' AND trans.type='0' AND trans.debtor_no=cust.debtor_no AND branch.branch_code = trans.branch_code


','256')
/PATH-TO-FA/sales/includes/db/cust_trans_db.inc:214:    display_db_error('duplicate debtor transactions found for given params','SELECT trans.*,ov_amount+ov_gst+ov_freight+ov_freight_tax+ov_discount AS Total,cust.name AS DebtorName, cust.address, cust.curr_code, cust.tax_id, trans.prep_amount>0 as prepaid,com.memo_, branch.* FROM &TB_PREF&debtor_trans trans LEFT JOIN &TB_PREF&comments com ON trans.type=com.type AND trans.trans_no=com.id LEFT JOIN &TB_PREF&shippers ON &TB_PREF&shippers.shipper_id=trans.ship_via, &TB_PREF&debtors_master cust, &TB_PREF&cust_branch branch WHERE trans.trans_no='96' AND trans.type='0' AND trans.debtor_no=cust.debtor_no AND branch.branch_code = trans.branch_code ','1')
/PATH-TO-FA/includes/ui/allocation_cart.inc:381:    get_customer_trans('96','0')
/PATH-TO-FA/sales/customer_payments.php:222:    check_allocations()
/PATH-TO-FA/sales/customer_payments.php:236:    can_process()

The reason for this bug is that multiple customer payments are recorded for One Transaction Number and Same Transaction Type.

I found the solution to this is to add 3rd argument in function call get_customer_trans() in /includes/ui/allocation_cart.inc as below on Line#399

                $trans = get_customer_trans($_SESSION['alloc']->allocs[$counter]->type_no, $_SESSION['alloc']->allocs[$counter]->type, $_SESSION['alloc']->person_id);

I hope this shall not cause any other bug.

The suggested solution for line 399 worked. Will report if I find another issue as a result.

Wynand

7 (edited by boxygen 02/03/2021 09:57:54 am)

Re: Bug in Customer Payments Recording

The similar handling needs to be done for Supplier Transactions Allocation at Line # 410

                $trans = get_supp_trans($_SESSION['alloc']->allocs[$counter]->type_no, $_SESSION['alloc']->allocs[$counter]->type, $_SESSION['alloc']->person_id);            

I suggest to commit the core for this.

www.boxygen.pk

Re: Bug in Customer Payments Recording

Thank you guys for solving this. Will fix and commit the changes tonight.

Joe

Re: Bug in Customer Payments Recording

As I noted earlier, this fix will still throw an error when you have purchase orders on the supplier payment form. I still stand with the fix I provided. It will cater for all scenarios for both customer and supplier payments.

Re: Bug in Customer Payments Recording

This has now been fixed and committed to stable repo.

The fixed file can be downloaded here.

/Joe