Override violate Credit Limit Control and Overdue Limit

From AutoCount Resource Center

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.

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

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.

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

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 System internal Credit Control Rule

Hook credit control event to a document (eg. Invoice)

AutoCount.Invoicing.Sales.Invoice.InvoiceCommand cmd = AutoCount.Invoicing.Sales.Invoice.InvoiceCommand.Create(usrSession, usrSession.DBSetting);
AutoCount.Invoicing.Sales.Invoice.Invoice iv = cmd.AddNew();
iv.ViolateCreditLimitEvent += Invoice_ViolateCreditLimitEvent;
iv.ViolateOverdueLimitEvent += Invoice_ViolateOverdueLimitEvent;

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;

Return system's credit control logic

To apply system logic of AutoCount Accounting to credit rules, simply return creditcontrol.UseSystemLogic in the credit control event.

private bool Invoice_ViolateOverdueLimitEvent(AutoCount.Invoicing.Sales.CreditControl creditcontrol, AutoCount.Invoicing.InvoicingDocument doc)
{
    return creditcontrol.OverdueLimitExceed <= 0;
}

private bool Invoice_ViolateCreditLimitEvent(AutoCount.Invoicing.Sales.CreditControl creditcontrol, AutoCount.Invoicing.InvoicingDocument doc)
{
    return creditcontrol.CreditLimitExceed <= 0;
}

private bool Invoice_ViolateOverdueLimitEvent(BCE.AutoCount.Invoicing.Sales.CreditControl creditcontrol, BCE.AutoCount.Invoicing.InvoicingDocument doc)
{
    return creditcontrol.OverdueLimitExceed <= 0;
}

private bool Invoice_ViolateCreditLimitEvent(BCE.AutoCount.Invoicing.Sales.CreditControl creditcontrol, BCE.AutoCount.Invoicing.InvoicingDocument doc)
{
    return creditcontrol.CreditLimitExceed <= 0;
}

Credit control event on script event (eg. Invoice)

Generally, programmer only require to write credit control logic in script event when programmer plans to overwrite system credit control logic.

public void SetCreditControl(AutoCount.Invoicing.Sales.Invoice.FormInvoiceEntry.SetCreditControlEventArgs e)
{
    if (creditcontrol.OverdueLimitExceed <= 0) //Using system checking
    {
        //Not violate
    }
    else
    {
        //Violated
        e.CreditControl.AbortSave = true;
    }
}

public void SetCreditControl(BCE.AutoCount.Invoicing.Sales.Invoice.FormInvoiceEntry.SetCreditControlEventArgs e)
{
    if (creditcontrol.OverdueLimitExceed <= 0) //Using system checking
    {
        //Not violate
    }
    else
    {
        //Violated
        e.CreditControl.AbortSave = true;
    }
}

Implement Custom Credit Control Rule

This example shows how to implement your own credit control rule.
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 return the 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(AutoCount.Authentication.UserSession usrSession, DataTable mastSource, DataTable dtlSource)
{
    AutoCount.Invoicing.Sales.Invoice.InvoiceCommand cmd = AutoCount.Invoicing.Sales.Invoice.InvoiceCommand.Create(usrSession, usrSession.DBSetting);
    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, AutoCount.Invoicing.Sales.Invoice.Invoice iv)
{
    DataRow row = mastSource.Rows[0];
    iv.DocDate = AutoCount.Converter.ToNullableDateTime(row["DocDate"]);
    iv.DebtorCode = row["CustomerCode"].ToString();
    iv.Description = "SALES";
    iv.RoundingMethod = AutoCount.Document.DocumentRoundingMethod.LineByLine_Ver2;
    iv.InclusiveTax = true;
    iv.IsRoundAdj = true;
}

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

private bool Invoice_ViolateCreditLimitEvent(AutoCount.Invoicing.Sales.CreditControl creditcontrol, 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);
}

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

Go to top
Resources For AutoCount Software Developers