miercuri, 6 aprilie 2016

Check if customer is a vendor also


I've encountered this request, to find out if one of our vendors is a client also.

How to check that? Well, there is a field on CustTable named VendAccount. This is the starting point.

 To check all of the existing pairs I've tried this:

T-SQL:

SELECT ct.ACCOUNTNUM
    , ct.VENDACCOUNT
FROM CUSTTABLE AS ct
WHERE EXISTS (SELECT 1
                FROM VENDTABLE
                    WHERE ACCOUNTNUM = ct.VENDACCOUNT)

And in X++:

static void getCustVendAccount(Args _args)
{
    CustTable   custTable;
    VendTable   vendTable;

    while select AccountNum, VendAccount from custTable
        exists join vendTable
        where custTable.VendAccount == vendTable.AccountNum
    {
        info(strFmt("Custmer Id: %1 - Vendor Id: %2", custTable.AccountNum, custTable.VendAccount));
    }
}

For both of them i had to compute the balance. 

Using the above X++ code i wrote:

TmpCustVendTrans tmpCustVendTrans;
;

tmpCustVendTrans = TmpCustVendTrans::custTransBalanceCurrency(custTable.AccountNum);

and for vendor:

tmpCustVendTrans = TmpCustVendTrans::custTransBalanceCurrency(custTable.VendAccount);

then just read the tmpCustVendTrans.AmountCur.




Niciun comentariu:

Trimiteți un comentariu