AP Invoice

From AutoCount Resource Center
Jump to navigation Jump to search

Technical Specification

  1. AccNo (Purchase A/C) cannot be empty or null.
  2. AccNo (Purchase A/C) cannot be Creditor Account No.
  3. NetTotal cannot be in negative value.
  4. NetTotal is the sum of amount & GST from details, this field is ReadOnly.
  5. Total GST is the sum of GST & GST Adjustment from details, this field is ReadOnly.
  6. Do not set empty string to ProjNo and DeptNo, when it is empty, set to DBNull.Value.

References of AutoCount Accounting version 1.8, 1.9

BCE.AutoCount.dll
BCE.AutoCount.CommonAccounting.dll
BCE.AutoCount.MainEntry.dll
BCE.Utils.dll
BCE.Utils.UI.dll
BCE.AutoCount.ARAP.dll


API Usage

New AP Invoice

public void NewAPInvoiceEntry(BCE.Data.DBSetting dbSetting)
{
	string userID = BCE.AutoCount.Authentication.UserAuthentication.GetOrCreate(dbSetting).LoginUserID;
	BCE.AutoCount.ARAP.APInvoice.APInvoiceDataAccess cmd = BCE.AutoCount.ARAP.APInvoice.APInvoiceDataAccess.Create(dbSetting);
	BCE.AutoCount.ARAP.APInvoice.APInvoiceEntity doc = cmd.NewAPInvoice();
	BCE.AutoCount.ARAP.APInvoice.APInvoiceDTLEntity dtl = null;

	doc.DocNo = "<<New>>";
	doc.CreditorCode = "400-X001";
	doc.DocDate = new DateTime(2018, 5, 28);
	doc.Description = "Purchase Generated";
	doc.PurchaseAgent = "TOM";
	doc.JournalType = "PURCHASE";

	doc.RoundingMethod = BCE.AutoCount.Document.DocumentRoundingMethod.LineByLine_Ver2;
	//Document Level Inclusive Tax
	doc.InclusiveTax = true;

	//Add two lines of detail
	dtl = doc.NewDetail();
	dtl.AccNo = "700-1010";
	dtl.Description = "Raw Material Metal";
	dtl.ProjNo = DBNull.Value;
	dtl.Amount = 1000.00M;

	dtl = doc.NewDetail();
	dtl.AccNo = "700-1010";
	dtl.Description = "Process Cost";
	dtl.ProjNo = DBNull.Value;
	dtl.Amount = 150.00M;

	try
	{
		cmd.SaveAPInvoice(doc, userID);
		//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);
	}
}

Edit AP Invoice

public void EditAPInvoiceEntry(BCE.Data.DBSetting dbSetting)
{
	string userID = BCE.AutoCount.Authentication.UserAuthentication.GetOrCreate(dbSetting).LoginUserID;
	BCE.AutoCount.ARAP.APInvoice.APInvoiceDataAccess cmd =
		BCE.AutoCount.ARAP.APInvoice.APInvoiceDataAccess.Create(dbSetting);

	BCE.AutoCount.ARAP.APInvoice.APInvoiceEntity doc = cmd.GetAPInvoice("PI-000001");
	BCE.AutoCount.ARAP.APInvoice.APInvoiceDTLEntity dtl = null;

	//if this AP Invoice has been knockoff(offset) with payment or credit note,
	//Changing of CreditorCode is not allowed.
	//Therefore, when such case arise, it is advised to issue Credit Note and issue a new AP Invoice
	//doc.CreditorCode = "400-X001";

	doc.DocDate = new DateTime(2018, 5, 28);
	doc.Description = "Purchase Generated";
	doc.PurchaseAgent = "TOM";
	doc.JournalType = "PURCHASE";

	doc.RoundingMethod = BCE.AutoCount.Document.DocumentRoundingMethod.LineByLine_Ver2;
	//Document Level Inclusive Tax
	doc.InclusiveTax = true;

	doc.ClearDetails();

	//Add two lines of detail
	dtl = doc.NewDetail();
	dtl.AccNo = "700-1010";
	dtl.Description = "Raw Material Metal";
	dtl.ProjNo = DBNull.Value;
	dtl.Amount = 1000.00M;

	dtl = doc.NewDetail();
	dtl.AccNo = "700-1010";
	dtl.Description = "Process Cost";
	dtl.ProjNo = "Project A";
	dtl.Amount = 150.00M;

	try
	{
		cmd.SaveAPInvoice(doc, userID);
		//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);
	}
}

Cancel (void) AP Invoice

public void CancelAPInvoice(BCE.Data.DBSetting dbSetting)
{
	string userID = BCE.AutoCount.Authentication.UserAuthentication.GetOrCreate(dbSetting).LoginUserID;
	BCE.AutoCount.ARAP.APInvoice.APInvoiceDataAccess cmd =
		BCE.AutoCount.ARAP.APInvoice.APInvoiceDataAccess.Create(dbSetting);

	try
	{
		cmd.CancelAPInvoice("PI-000001", userID);
	}
	catch (BCE.Application.AppException ex)
	{
		BCE.Application.AppMessage.ShowMessage(ex.Message);
	}
}

Delete AP Invoice

public void DeleteAPInvoice(BCE.Data.DBSetting dbSetting)
{
	string userID = BCE.AutoCount.Authentication.UserAuthentication.GetOrCreate(dbSetting).LoginUserID;
	BCE.AutoCount.ARAP.APInvoice.APInvoiceDataAccess cmd =
		BCE.AutoCount.ARAP.APInvoice.APInvoiceDataAccess.Create(dbSetting);

	try
	{
		cmd.DeleteAPInvoice("PI-000001");
	}
	catch (BCE.Application.AppException ex)
	{
		BCE.Application.AppMessage.ShowMessage(ex.Message);
	}
}

Sample

Create new AP Invoice from DataModel

public void NewAPInvoiceEntry(BCE.Data.DBSetting dbSetting, APInvoiceSource source)
{
	string userID = BCE.AutoCount.Authentication.UserAuthentication.GetOrCreate(dbSetting).LoginUserID;
	BCE.AutoCount.ARAP.APInvoice.APInvoiceDataAccess cmd =
		BCE.AutoCount.ARAP.APInvoice.APInvoiceDataAccess.Create(dbSetting);

	BCE.AutoCount.ARAP.APInvoice.APInvoiceEntity doc = cmd.NewAPInvoice();
	BCE.AutoCount.ARAP.APInvoice.APInvoiceDTLEntity dtl = null;

	doc.CreditorCode = source.SupplierCode;
	doc.DocNo = source.Document;
	doc.DocDate = source.Date;
	doc.CurrencyRate = source.CurrencyRate;

	doc.Description = source.Description;
	doc.PurchaseAgent = source.PurchaseAgent;
	doc.JournalType = source.JournalType;
	//Set whether to apply rounding method of either by Document or by Each Line,
	//this may affect different result in GST Calculation due to decimal point rounding.
	doc.RoundingMethod = source.RoundMethod;
	//Document Level Inclusive Tax
	doc.InclusiveTax = source.Inclusive;

	foreach (APInvoiceDetail ivDtl in source.Details)
	{
		dtl = doc.NewDetail();

		dtl.AccNo = ivDtl.Account;
		dtl.Description = ivDtl.Description;
		dtl.ProjNo = ivDtl.Project;
		dtl.DeptNo = ivDtl.Department;
		dtl.TaxType = ivDtl.GSTCode;
		dtl.Amount = ivDtl.Amount ?? 0;
		dtl.TaxAdjustment = ivDtl.GSTAdjustment;
	}

	try
	{
		cmd.SaveAPInvoice(doc, userID);
		//log success
		//AutoCount.AppMessage.ShowMessage(string.Format("{0} is created.", doc.DocNo));
	}
	catch (BCE.Application.AppException ex)
	{
		//log ex.Message
		//AutoCount.AppMessage.ShowMessage(ex.Message);
	}
}

Classes of Source (DataModel)

public class APInvoiceSource
{
    public string SupplierCode { get; set; }
    public string Description { get; set; }
    public decimal CurrencyRate { get; set; } = 1;
    public string Document { get; set; }
    public DateTime Date { get; set; }
    public string PurchaseAgent { get; set; }
    public string JournalType { get; set; } = "PURCHASE";
    public BCE.AutoCount.Document.DocumentRoundingMethod RoundMethod { get; set; } =
        BCE.AutoCount.Document.DocumentRoundingMethod.LineByLine_Ver2;
    public bool Inclusive { get; set; } = false;
    public List<APInvoiceDetail> Details { get; set; } = new List<APInvoiceDetail>();
}

public class APInvoiceDetail
{
    public string Account { get; set; }
    public string Description { get; set; }
    public string Project { get; set; }
    public string Department { get; set; }
    public decimal? Amount { get; set; }
    public string GSTCode { get; set; }
    public decimal GSTAdjustment { get; set; }
}

Implementation

public void MainEntry(BCE.Data.DBSetting dbSetting)
{
    APInvoiceSource newDoc = new APInvoiceSource()
    {
        SupplierCode = "400-X001",
        Description = "PURCHASE GENERATED",
        Document = "<<New>>",
        Date = new DateTime(2018, 5, 28),
	PurchaseAgent = "TOM",
	JournalType = "PURCHASE",
	RoundMethod = BCE.AutoCount.Document.DocumentRoundingMethod.LineByLine_Ver2,
        Inclusive = true
    };

    newDoc.Details.Add(new APInvoiceDetail() { Account = "700-1010", Description = "Raw Material Metal", Amount = 1000M });
    newDoc.Details.Add(new APInvoiceDetail() { Account = "700-1010", Description = "Process Cost", Project = "Project A", Amount = 150M});

    NewAPInvoiceEntry(dbSetting, newDoc);
}

See Also

AutoCount Accounting Account API
AR AP
Transactions Version Transactions Version
AR Debtor (Customer) 1.8, 1.9
2.0
AP Creditor (Supplier) 1.8, 1.9
2.0
AR Invoice 1.8, 1.9
2.0
AP Invoice 1.8, 1.9
2.0
AR Received Payment 1.8, 1.9
2.0
AP Payment 1.8, 1.9
2.0
AR Debit Note 1.8, 1.9
2.0
AP Debit Note 1.8, 1.9
2.0
AR Credit Note 1.8, 1.9
2.0
AP Credit Note 1.8, 1.9
2.0
AR Refund 1.8, 1.9
2.0
AP Refund 1.8, 1.9
2.0
AR Deposit 1.8, 1.9
2.0
AP Deposit 1.8, 1.9
2.0
AR Deposit - Create New or Update
with Refund & Forfeit
1.8, 1.9
2.0
A/R and A/P Contra Entry 1.8, 1.9
2.0

Go to menu

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