To be able to do partial invoicing where the invoice is linked to its corresponding Sales Order, do the following steps:
1. Initialize Invoice from Sales Order
2. Identify the line item that is to be invoiced
3. Set all line items that are not to be invoiced to null
4. Add Invoice
Below is a sample C# code for the solution:
public virtual void initializeInvoice()
{
// Get Internal ID of Sales Order to be Initialized
_out.write("\nEnter Internal ID for Sales Order record : ");
String invInternalId = _out.readLn().ToUpper();
InitializeRecord ir = new InitializeRecord();
ir.type = InitializeType.invoice;
InitializeRef iref = new InitializeRef();
iref.typeSpecified = true;
iref.type = InitializeRefType.salesOrder;
iref.internalId = invInternalId;
ir.reference = iref;
ReadResponse getInitResp = _service.initialize(ir);
if (getInitResp.status.isSuccess)
{
Invoice createInvoice = new Invoice();
createInvoice = (Invoice)getInitResp.record;
_service.preferences.ignoreReadOnlyFieldsSpecified = true;
_service.preferences.ignoreReadOnlyFields = true;
int itemlenght = createInvoice.itemList.item.Length;
Console.Write(itemlenght);
_out.write("\nEnter line item to retain: ");
Int32 retainLine = System.Int32.Parse(_out.readLn());
for (var i = 0; i < itemlenght; i++)
{
if (i != retainLine)
{
createInvoice.itemList.item[i] = null;
}
}
WriteResponse writeRes = _service.add(createInvoice);
if (writeRes.status.isSuccess)
{
_out.writeLn("\nSo initialized to Invoice# " + ((RecordRef)writeRes.baseRef).internalId);
}
else
{
_out.error(getStatusDetails(writeRes.status));
}
}
else
{
_out.error(getStatusDetails(getInitResp.status));
}
}
No comments:
Post a Comment