Tuesday, January 12, 2010

How to Create A/P Invoice SAP B1 using SDK

What is an A/P Invoice?
A/P Invoice is abbreviations from Account Payable Invoice. Its account or the bill must be paid to vendor based on the goods we buy. Many vendor allowing to pay after product or service already been received.
To generate document A/P Invoice in SAP B1 is using oPurchaseInvoice object.
Here is the code:
Dim oAPInvoice As sapbobscom.Documents
Set oAPInvoice = oCompany.GetBusinessObject(sapbobscom.BoObjectTypes.oPurchaseInvoices)
With oAPInvoice
‘Header area
.CardCode = your vendor code
.NumAtCard = your reference no
.DocDate = your posting date
.TaxDate = your document date
.DocType = sapbobscom.BoDocumentTypes.dDocument_Items
.Comments = your remarks
‘Detail area
.Lines.SetCurrentLine (detail rows)
.Lines.itemCode = your item code
.Lines.WarehouseCode = your warehouse code
.Lines.Quantity = your qty
.Lines.VatGroup = "ZI"
.Lines.UnitPrice = F_Price
.Lines.LineTotal = F_Amount
LngErr = .Add()
If LngErr <> 0 Then
oCompany.GetLastError(LngErr, sErrMsg)
Msgbox SErrMsg
Else
MsgBox “Create A/P Invoice Data Success”
End with
Note: If your vendor use Tax amount, you can setup first on Business partner master - allowed tax

2 comments:

  1. hi,
    i have almost the sale code but with C#
    the subject is that :
    - i read invoices form a CSV file
    - i save them in SAP B1
    my problem is that it takes just the first invoice
    help me plz
    here is my code :
    try
    {
    SAPbobsCOM.Documents ofact;
    //globals_Renamed.InitializeCompany();
    //SAPbobsCOM.Company oCompany = new SAPbobsCOM.Company();
    ofact = (SAPbobsCOM.Documents)globals_Renamed.oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oInvoices);
    csvDataSet = new DataSet(_root);
    csvDataTable = new DataTable(_node);
    stream = new System.IO.StreamReader("C:/factures1.csv", true);
    sLigne = stream.ReadLine();
    sLigne = stream.ReadLine();
    saEntetes = sLigne.Split(_separator);
    while (sLigne != null )
    {

    ofact.NumAtCard = saEntetes[0];
    ofact.DocDate = Convert.ToDateTime(saEntetes[1]);
    ofact.DocDueDate = Convert.ToDateTime(saEntetes[2]);
    ofact.CardCode = saEntetes[3];

    string bcl = ofact.NumAtCard;
    while (saEntetes[0] == bcl)
    {

    ofact.Lines.ItemCode = saEntetes[4];
    ofact.Lines.Quantity = Convert.ToDouble(saEntetes[5]);
    ofact.Lines.Price = Convert.ToDouble(saEntetes[6]);
    ofact.Lines.DiscountPercent = Convert.ToInt64(saEntetes[7]);
    ofact.Lines.VatGroup = saEntetes[9];
    ofact.Lines.Add();
    ofact.Lines.SetCurrentLine(ofact.Lines.Count - 1);
    sLigne = stream.ReadLine();
    saEntetes = sLigne.Split(_separator);
    }
    sLigne = stream.ReadLine();
    //lRetCode = globals_Renamed.oCompany.Connect();
    lRetCode = ofact.Add();
    string ErMsg;
    globals_Renamed.oCompany.GetLastError(out lRetCode, out ErMsg);
    MessageBox.Show(lRetCode + "-" + ErMsg );


    }


    }
    catch (Exception ex)
    {
    MessageBox.Show(ex.Message);
    }

    ReplyDelete
  2. Hi, please I need help ,

    when I add the Sales Order via the DI API, Do I have to substract the quantity in OITW and OITM or sap will make the adjustment itself

    ReplyDelete