Difference between revisions of "Override violate Credit Limit Control and Overdue Limit"

From AutoCount Resource Center
Jump to navigation Jump to search
m
 
(13 intermediate revisions by the same user not shown)
Line 9: Line 9:
 
==Enable Credit Control==
 
==Enable Credit Control==
 
EnableCreditControl() will enable both Credit Limit & Overdue Limit control.
 
EnableCreditControl() will enable both Credit Limit & Overdue Limit control.
 +
<tabber>
 +
AutoCount Accounting 2.0 =
 +
<syntaxhighlight lang="csharp" highlight="3">
 +
AutoCount.Invoicing.Sales.Invoice.InvoiceCommand cmd = AutoCount.Invoicing.Sales.Invoice.InvoiceCommand.Create(dbset);
 +
AutoCount.Invoicing.Sales.Invoice.Invoice iv = cmd.AddNew();
 +
iv.EnableCreditControl();
 +
</syntaxhighlight>
 +
|-|
 +
AutoCount Accounting 1.9 =
 
<syntaxhighlight lang="csharp" highlight="3">
 
<syntaxhighlight lang="csharp" highlight="3">
 
BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceCommand cmd = BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceCommand.Create(dbset);
 
BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceCommand cmd = BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceCommand.Create(dbset);
Line 14: Line 23:
 
iv.EnableCreditControl();
 
iv.EnableCreditControl();
 
</syntaxhighlight>
 
</syntaxhighlight>
 
+
</tabber>
 
==Disable Credit Control==
 
==Disable Credit Control==
 
DisableCreditControl() will disable both Credit Limit & Overdue Limit control.
 
DisableCreditControl() will disable both Credit Limit & Overdue Limit control.
 +
<tabber>
 +
AutoCount Accounting 2.0 =
 +
<syntaxhighlight lang="csharp" highlight="3">
 +
AutoCount.Invoicing.Sales.Invoice.InvoiceCommand cmd = AutoCount.Invoicing.Sales.Invoice.InvoiceCommand.Create(dbset);
 +
AutoCount.Invoicing.Sales.Invoice.Invoice iv = cmd.AddNew();
 +
iv.DisableCreditControl();
 +
</syntaxhighlight>
 +
|-|
 +
AutoCount Accounting 1.9 =
 
<syntaxhighlight lang="csharp" highlight="3">
 
<syntaxhighlight lang="csharp" highlight="3">
 
BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceCommand cmd = BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceCommand.Create(dbset);
 
BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceCommand cmd = BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceCommand.Create(dbset);
Line 22: Line 40:
 
iv.DisableCreditControl();
 
iv.DisableCreditControl();
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
</tabber>
 +
 +
==Implement System internal Credit Control Rule==
 +
===Hook credit control event to a document (eg. Invoice)===
 +
<tabber>
 +
AutoCount Accounting 2.0 =
 +
<syntaxhighlight lang="csharp">
 +
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;
 +
</syntaxhighlight>
 +
|-|
 +
AutoCount Accounting 1.9 =
 +
<syntaxhighlight lang="csharp">
 +
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;
 +
</syntaxhighlight>
 +
</tabber>
 +
 +
===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.
 +
<tabber>
 +
AutoCount Accounting 2.0 =
 +
<syntaxhighlight lang="csharp">
 +
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;
 +
}
 +
</syntaxhighlight>
 +
|-|
 +
AutoCount Accounting 1.9 =
 +
<syntaxhighlight lang="csharp">
 +
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;
 +
}
 +
</syntaxhighlight>
 +
</tabber>
  
 +
==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.<br/>
 +
<tabber>
 +
AutoCount Accounting 2.0 =
 +
<syntaxhighlight lang="csharp">
 +
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;
 +
    }
 +
}
 +
</syntaxhighlight>
 +
|-|
 +
AutoCount Accounting 1.9 =
 +
<syntaxhighlight lang="csharp">
 +
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;
 +
    }
 +
}
 +
</syntaxhighlight>
 +
</tabber>
  
 
==Implement Custom Credit Control Rule==
 
==Implement Custom Credit Control Rule==
 
  This example shows how to implement your own 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".<br />
 
  Event '''Invoice_ViolateOverdueLimitEvent''' is triggered when the customer has overdue amount that has exceeded "Overdue Limit".<br />
 
  Event '''Invoice_ViolateCreditLimitEvent''' is triggered when the customer has outstanding that has exceeded "Credit Limit".
 
  Event '''Invoice_ViolateCreditLimitEvent''' is triggered when the customer has outstanding that has exceeded "Credit Limit".
*Both events have a return value of Boolean.
+
*Both events return the value of Boolean.
 
**false = Return false, document do not allow to be saved, after processed by custom credit control rule.
 
**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.
+
**true = Return true, document allows to be saved, after processed by custom credit control rules.<br/><br/>
 +
<tabber>
 +
AutoCount Accounting 2.0 =
 +
<syntaxhighlight lang="csharp">
 +
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();
 +
    }
 +
}
 +
</syntaxhighlight>
 +
<syntaxhighlight lang="csharp" highlight="3,8">
 +
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;
 +
}
 +
</syntaxhighlight>
 +
<br /><br />
 +
===Table source for testing purpose===
 +
 +
<syntaxhighlight lang="csharp">
 +
//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);
 +
}
 +
</syntaxhighlight>
 +
<syntaxhighlight lang="csharp">
 +
//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);
 +
}
 +
</syntaxhighlight>
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
 +
|-|
 +
AutoCount Accounting 1.9 =
 
<syntaxhighlight lang="csharp">
 
<syntaxhighlight lang="csharp">
 
public void CreateNewInvoice(BCE.Data.DBSetting dbset, DataTable mastSource, DataTable dtlSource)
 
public void CreateNewInvoice(BCE.Data.DBSetting dbset, DataTable mastSource, DataTable dtlSource)
Line 146: Line 378:
 
}
 
}
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
</tabber>
 +
 +
 
<br />
 
<br />
  

Latest revision as of 04:18, 10 April 2020

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

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