Override violate Credit Limit Control and Overdue Limit

From AutoCount Resource Center
Jump to navigation Jump to search

When do import or posting document, there are times the new transaction is blocked by Credit Control in AutoCount Accounting. AutoCount Accounting provides several ways to overwrite or disable the Credit Control for during import document.

There are two types of Credit Control in AutoCount Accounting

  1. Credit Limit
  2. Overdue Limit

Enable Credit Control

EnableCreditControl() will enable both Credit Limit & Overdue Limit control.

BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceCommand cmd = BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceCommand.Create(dbset);
BCE.AutoCount.Invoicing.Sales.Invoice.Invoice iv = cmd.AddNew();
iv.EnableCreditControl();

Disable Credit Control

DisableCreditControl() will disable both Credit Limit & Overdue Limit control.

BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceCommand cmd = BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceCommand.Create(dbset);
BCE.AutoCount.Invoicing.Sales.Invoice.Invoice iv = cmd.AddNew();
iv.DisableCreditControl();


Implement Custom Credit Control Rule

This example shows how to implement your own credit control rule.
However, these events are triggered when Credit Limit or Overdue Limit is violated.
Event Invoice_ViolateOverdueLimitEvent is triggered when the customer has overdue amount that has exceeded "Overdue Limit".
Event Invoice_ViolateCreditLimitEvent is triggered when the customer has outstanding that has exceeded "Credit Limit".
  • Both events have a return value of Boolean.
    • false = Return false, document do not allow to be saved, after processed by custom credit control rule.
    • true = Return true, document allows to be saved, after processed by custom credit control rules.
public void CreateNewInvoice(BCE.Data.DBSetting dbset, DataTable mastSource, DataTable dtlSource)
{
    BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceCommand cmd = BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceCommand.Create(dbset);
    BCE.AutoCount.Invoicing.Sales.Invoice.Invoice iv = cmd.AddNew();
    iv.ViolateCreditLimitEvent += Invoice_ViolateCreditLimitEvent;
    iv.ViolateOverdueLimitEvent += Invoice_ViolateOverdueLimitEvent;

    AssignMaster(mastSource, iv);
    AddDetailRows(dtlSource, () => iv.AddDetail());

    iv.Save();
}

private void AssignMaster(DataTable mastSource, BCE.AutoCount.Invoicing.Sales.Invoice.Invoice iv)
{
    DataRow row = mastSource.Rows[0];
    iv.DocDate = BCE.Data.Convert.ToDateTime(row["DocDate"]);
    iv.DebtorCode = row["CustomerCode"].ToString();
    iv.Description = "SALES";
    iv.RoundingMethod = BCE.AutoCount.Document.DocumentRoundingMethod.LineByLine_Ver2;
    iv.InclusiveTax = true;
    iv.IsRoundAdj = true;
}

private void AddDetailRows(DataTable dtlSource, Func<BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceDetail> newDetail)
{
    BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceDetail dtl;
    foreach (DataRow row in dtlSource.Rows)
    {
        dtl = newDetail();
        dtl.ItemCode = BCE.Data.Convert.ToDBString(row["ItemCode"]);
        dtl.Description = BCE.Data.Convert.ToDBString(row["Description"]);
        dtl.Qty = BCE.Data.Convert.ToDBDecimal(row["Qty"]);
        dtl.UnitPrice = BCE.Data.Convert.ToDBDecimal(row["Price"]);
        dtl.TaxType = BCE.Data.Convert.ToDBString(row["GSTCode"]);
    }
}
private bool Invoice_ViolateOverdueLimitEvent(BCE.AutoCount.Invoicing.Sales.CreditControl creditcontrol, BCE.AutoCount.Invoicing.InvoicingDocument doc)
{
    return CustomApproveCreditControl(d => ExceededCredit(creditcontrol.AROutstanding, d));
}

private bool Invoice_ViolateCreditLimitEvent(BCE.AutoCount.Invoicing.Sales.CreditControl creditcontrol, BCE.AutoCount.Invoicing.InvoicingDocument doc)
{
    return CustomApproveCreditControl(d => ExceededCredit(creditcontrol.AROutstanding, d));
}

private bool CustomApproveCreditControl(Predicate<decimal> exceedCredit)
{
    return !exceedCredit(50000); //Reverse the result of true & false
}

private bool ExceededCredit(decimal outstanding, decimal limitAmount)
{
    return outstanding >= limitAmount;
}



Table source for testing purpose

//Master Table
DataTable tblMast = new DataTable();
DataTable tblDtl = new DataTable();
tblMast.Columns.Add("DocDate", typeof(DateTime));
tblMast.Columns.Add("CustomerCode", typeof(string));
tblDtl.Columns.Add("ItemCode", typeof(string));
tblDtl.Columns.Add("Description", typeof(string));
tblDtl.Columns.Add("Qty", typeof(decimal));
tblDtl.Columns.Add("Price", typeof(decimal));
tblDtl.Columns.Add("GSTCode", typeof(string));

DataRow row = tblMast.NewRow();
row["DocDate"] = DateTime.Today.Date;
row["CustomerCode"] = e.MasterRecord.DebtorCode;
tblMast.Rows.Add(row);

for (int i = 0; i < 5; i++)
{
    row = tblDtl.NewRow();
    row["Description"] = string.Format("Item {0}", i);
    row["Qty"] = i + 1;
    row["Price"] = 10;
    row["GSTCode"] = null;
    tblDtl.Rows.Add(row);
}
//Detail Table
DataRow row;
DataTable tblDtl = new DataTable();
tblDtl.Columns.Add("ItemCode", typeof(string));
tblDtl.Columns.Add("Description", typeof(string));
tblDtl.Columns.Add("Qty", typeof(decimal));
tblDtl.Columns.Add("Price", typeof(decimal));
tblDtl.Columns.Add("GSTCode", typeof(string));

for (int i = 1; i <= 5; i++)
{
    row = tblDtl.NewRow();
    row["ItemCode"] = null;
    row["Description"] = string.Format("Item {0}", i);
    row["Qty"] = i;
    row["Price"] = 10;
    row["GSTCode"] = "SR-S";  //Output Tax - Standard Rated Supplies
    tblDtl.Rows.Add(row);
}


Go to menu

IconAC81.png Go to top
ProgrammerGo.jpg Resources For AutoCount Software Developers