Creating Purchase Invoice through OData Web Service

Hi,

I am trying to create a purchase invoice through OData WebService.

I am able to create the header but not able to create the lines.

Is there any sample code to demonstrate the same.

Here is what I am doing:-


string serviceUri = “192.168.10.63:7048/…/Company(‘CRONUS India Ltd.’)”;

ServiceReference1.NAV theNav = new ServiceReference1.NAV(new Uri(serviceUri.ToString()));
theNav.Credentials=new System.Net.NetworkCredential(“Administrator”, “*******”, “WorkGroup”);

ServiceReference1.Purchase_Invoice PurInvoice = new ServiceReference1.Purchase_Invoice();

PurInvoice.Document_Type = “2”;
PurInvoice.No = “1076”;
PurInvoice.Buy_from_Vendor_No = “10000”;
PurInvoice.Status = “Open”;
PurInvoice.Document_Date = new DateTime(2015,1,22);
PurInvoice.Posting_Date = new DateTime(2015, 1, 22);
PurInvoice.Expected_Receipt_Date = new DateTime(2015, 1, 22);
PurInvoice.Vendor_Invoice_No = “DP/test/01076”;

theNav.AddToPurchase_Invoice(PurInvoice);

System.Data.Services.Client.DataServiceResponse res = theNav.SaveChanges();

ServiceReference1.Purchase_InvoicePurchLines PurInvoiceLines = new ServiceReference1.Purchase_InvoicePurchLines();

PurInvoiceLines.Document_Type = “2”;
PurInvoiceLines.Document_No = “1076”;
PurInvoiceLines.Line_No = 10000;
PurInvoiceLines.Type = “Item”;
PurInvoiceLines.No = “1000”;
PurInvoiceLines.Qty_Assigned = 0;
PurInvoiceLines.Qty_to_Assign = 0;
PurInvoiceLines.Quantity = 10;
PurInvoiceLines.Line_Amount = 100;
PurInvoiceLines.Direct_Unit_Cost = 10;

PurInvoice.Purchase_InvoicePurchLines.Load(PurInvoiceLines);
theNav.UpdateObject(PurInvoice);
System.Data.Services.Client.DataServiceResponse res1 = theNav.SaveChanges();