C Customer Allocations

From Sage Evolution SDK | Documentation Portal
Revision as of 09:48, 6 June 2016 by Admin (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Customer Transactions like Invoices can be allocated to Contra Customer Transactions like Invoice Payments(Receipts). All Customer related transactions will appear in the PostAR table. In PostAR Accountlink determines which Customer Account the transaction is for and the outstanding field determines what amount can still be allocated. A fully Allocated transaction will have a outstanding value of 0.

The callocs field contains the allocation to the related transaction an example would be I=6;A=50;D=20150622 where I = Autoidx , A = Amount Allocated , D = Allocation Date

To Allocate two transactions you would require the Autoidx of the transaction in the PostAR for both transactions as follows:

CustomerTransaction invoice = new CustomerTransaction(5);// AutoIdx of debit transaction in PostAR table
CustomerTransaction payment = new CustomerTransaction(8);// AutoIdx of credit transaction in PostAR table
invoice.Allocations.Add(payment);
invoice.Allocations.Save();

Allocations can also be done at the time of posting as folows:

//An invoice is posted.
CustomerTransaction invoice = new CustomerTransaction();
invoice.Account = new Customer("Customer1");
invoice.TransactionCode = new TransactionCode(Module.AR, "IN");
invoice.Amount = 500.50;
invoice.TaxRate = new TaxRate(7);
invoice.Reference = "INV12348902";
invoice.Description = "Customer Invoice";
invoice.Post();
 
//A payment(receipt) is posted.
CustomerTransaction payment = new CustomerTransaction();
payment.Account = new Customer("Customer1");
payment.TransactionCode = new TransactionCode(Module.AR, "PM");
payment.Amount = 1000.00;
payment.Reference = "EFT";
payment.Description = "Payment";
payment.Post();
 
//We allocate the in-memory payment object to the invoice object
invoice.Allocations.Add(payment);
//Don't forget to call save!
invoice.Allocations.Save();

The Following example allocates a Customer payment to a existing sales order invoice by creating and using the allocateorder method to get the Customer transaction id

{
    //Post a Customer payment
    CustomerTransaction payment = new CustomerTransaction();
    payment.Account = new Customer("Customer1");
    payment.TransactionCode = new TransactionCode(Module.AR, "PM");
    payment.OrderNo = "SO0018";
    payment.Amount = 20;
    payment.Reference = "PM123";
    payment.Description = "Payment Made";
    payment.Post();
    //Use method allocateOrder to find order number and allocate to payment
    allocateOrder(payment);
}
 
private void allocateOrder(DrCrTransaction transaction)
{
    string criteria = string.Format("Order_No = '{0}'", transaction.OrderNo);
    if (transaction.Outstanding == 0)
        return;
    if (transaction.Outstanding > 0)
        criteria += " and Outstanding  0";
    DataTable matches = CustomerTransaction.List(transaction.Account, criteria);
    if (matches.Rows.Count > 0)
    {
        foreach (DataRow match in matches.Rows)
        {
            //terminate if satisfied
            if (transaction.Outstanding == 0)
                break;
            CustomerTransaction relatedTran = new CustomerTransaction((Int64)match["Autoidx"]);
            transaction.Allocations.Add(relatedTran);
        }
        transaction.Allocations.Save();
    }
}