Difference between revisions of "Programmer:Sales Invoice"

Jump to navigation Jump to search
no edit summary
m (Protected "Programmer:Sales Invoice" ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite) [Delete=Allow only administrators] (indefinite)))
{{NavigateDeveloper}}
===Rules in Sale Invoice===
# NetTotal must not be negative amount
 
===Assemblies version 1.8===
<pre>
BCE.AutoCount.Invoicing.dll
BCE.AutoCount.Invoicing.Sales.dll
</pre>
 
===Create New Sale Invoice===
<syntaxhighlight lang="csharp">
public void NewSaleInvoice(BCE.Data.DBSetting dbSetting, SaleInvoiceSource source)
{
BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceCommand cmd = BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceCommand.Create(dbSetting);
BCE.AutoCount.Invoicing.Sales.Invoice.Invoice doc = cmd.AddNew();
 
doc.DebtorCode = source.CustomerCode;
doc.DocNo = source.DocumentNo;
doc.DocDate = source.DocumentDate;
doc.Description = source.Description;
doc.CurrencyRate = source.CurrencyRate;
doc.Agent = source.SalesPerson;
//Set whether to apply which rounding methodo of either Document or Each Line,
//this may affect different result in GST Calculation due to decimal point.
doc.RoundingMethod = source.RoundMethod;
//Document Level Inclusive Tax
doc.InclusiveTax = source.Inclusive;
 
source.Details.ForEach(s => AddSaleInvoiceDetail(s, doc.AddDetail));
 
try
{
doc.Save();
//log success
BCE.Application.AppMessage.ShowMessage(string.Format("{0} is created.", doc.DocNo));
}
catch (BCE.Application.AppException ex)
{
//log ex.Message
BCE.Application.AppMessage.ShowMessage(ex.Message);
}
}
 
private void AddSaleInvoiceDetail(SaleInvoiceDetail sourceDtl,
Func<BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceDetail> addToDoc)
{
BCE.AutoCount.Invoicing.Sales.Invoice.InvoiceDetail dtl = addToDoc();
 
dtl.AccNo = sourceDtl.Account;
//When ItemCode is assigned, AccNo will be refreshed based on ItemGroup's SaleAccNo;
//If ItemGroup is not maintained, then default Sale AccNo will be assigned.
dtl.ItemCode = sourceDtl.ItemCode;
dtl.Description = sourceDtl.Description ?? dtl.Description;
if (sourceDtl.Project != null)
dtl.ProjNo = sourceDtl.Project;
if (sourceDtl.Department != null)
dtl.DeptNo = sourceDtl.Department;
if (sourceDtl.Location != null)
dtl.Location = sourceDtl.Location;
dtl.Qty = sourceDtl.Quantity ?? dtl.Qty;
dtl.UOM = sourceDtl.Uom ?? dtl.UOM;
dtl.UnitPrice = sourceDtl.UnitPrice ?? dtl.UnitPrice;
dtl.Discount = sourceDtl.Discount ?? dtl.Discount;
dtl.SubTotal = sourceDtl.Amount ?? dtl.SubTotal;
if (sourceDtl.GSTCode != null)
dtl.TaxType = sourceDtl.GSTCode;
dtl.TaxAdjustment = sourceDtl.GSTAdjustment;
}
</syntaxhighlight>
 
===Classes of source===
<syntaxhighlight lang="csharp">
public class SaleInvoiceSource
{
public string CustomerCode { get; set; }
public string DocumentNo { get; set; }
public DateTime DocumentDate { get; set; }
public string Description { get; set; }
public decimal CurrencyRate { get; set; } = 1;
public string SalesPerson { get; set; }
public BCE.AutoCount.Document.DocumentRoundingMethod RoundMethod { get; set; } =
BCE.AutoCount.Document.DocumentRoundingMethod.LineByLine_Ver2;
public bool Inclusive { get; set; } = false;
public List<SaleInvoiceDetail> Details { get; set; } = new List<SaleInvoiceDetail>();
}
 
public class SaleInvoiceDetail
{
public string Account { get; set; }
public string ItemCode { get; set; }
public string Description { get; set; }
public string Location { get; set; }
public string Project { get; set; }
public string Department { get; set; }
public decimal? Quantity { get; set; }
public string Uom { get; set; }
public decimal? UnitPrice { get; set; }
public string Discount { get; set; }
public decimal? Amount { get; set; }
public string GSTCode { get; set; }
public decimal GSTAdjustment { get; set; }
}
</syntaxhighlight>
 
===Implementation===
[[File:SALEInvoiceGenerate01.PNG|link=]]
<syntaxhighlight lang="csharp">
public void MainEntry(BCE.Data.DBSetting dbSetting)
{
SaleInvoiceSource newDoc = new SaleInvoiceSource()
{
CustomerCode = "300-A001",
Description = "SALES INVOICE GENERATED",
DocumentNo = "<<New>>",
DocumentDate = new DateTime(2017, 11, 30),
Inclusive = true
};
 
//There are many ways which data input can be entered into details, here are some of the common input.
newDoc.Details.Add(new SaleInvoiceDetail() { Description = "Particulars" });
newDoc.Details.Add(new SaleInvoiceDetail(){ ItemCode = "FG00001", Quantity = 1, UnitPrice = 50.20M, GSTCode = "SR-S" });
newDoc.Details.Add(new SaleInvoiceDetail(){ ItemCode = "FG00001", Quantity = 2, UnitPrice = 50.20M, Discount = "5%", GSTCode = "SR-S" });
newDoc.Details.Add(new SaleInvoiceDetail(){ ItemCode = "FG00001", Quantity = 1, GSTCode = "SR-S", Amount = 50.20M });
 
newDoc.Details.Add(new SaleInvoiceDetail() { Description = "Non-Stock Items" });
//When AccNo & ItemCode both are not defined, system will retrieve from default Sale Account.
//If default Sale Account is not maintained in Tools | Options, system will throw error on saving.
newDoc.Details.Add(new SaleInvoiceDetail(){ Description = "Misc. Charges", GSTCode = "SR-S", Amount = 30 });
newDoc.Details.Add(new SaleInvoiceDetail(){ Account = "500-0000", Description = "Transport", Amount = 50, GSTCode = "SR-S" });
 
NewSaleInvoice(dbSetting, newDoc);
}
</syntaxhighlight>
 
[[Category:Programmer]]
[[Category:API]]
authors, Bureaucrats, Confirmed users, Rollbackers, Administrators
2,374
edits
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu