hi I am trying to single pending vendor invoice by x++ for multiple PO for same vendor but while invocing it says error
public void CreateVendinvoiceForPosting(SON_SummaryInvoice _poHeaderSummaryInvIB)
{
Name son_EANCode;
PurchTable purchTable;
PurchLine purchLine;
VendPackingSlipJour vendPackingSlipJour,vendPackingSlipJourloc;
VendPackingSlipTrans vendPackingSlipTrans,vendPackingSlipTransloc;
VendInvoiceInfoTable vendInvoiceInfoTable;
VendInvoiceInfoLine vendInvoiceInfoLine;
VendInvoiceInfoSubTable vendInvoiceInfoSubTable;
VendInvoiceInfoSubLine vendInvoiceInfoSubLine;
PurchId purchId;
PackingSlipId packingSlipId;
rAXItemEANCode rAXItemEANCode;
PurchParmUpdate activePurchParmUpdate;
VendInvoiceInfoTable activeVendInvoiceInfoTable;
VendInvoiceInfoTable savedVendInvoiceInfoTable;
SON_AttachmentInvoice attachmentDDInvoice;
SON_AttachmentInvoice SON_AttachmentDDInvoiceloc;
int64 LineNumber;
VendBankAccount VendBankAccount;
str invoicenumber;
MarkupTrans markupTrans,markupTransloc;
;
select DeliveryNote,AXPONumber from attachmentDDInvoice
where attachmentDDInvoice.IsInvoicedCreated == NoYes::No
&& attachmentDDInvoice.SummaryInvoiceNumber == _poHeaderSummaryInvIB.InvoiceNumber;
purchId = attachmentDDInvoice.AXPONumber;
packingSlipId = attachmentDDInvoice.DeliveryNote;
invoicenumber = poHeaderSummaryInvIB.InvoiceNumber;
ttsBegin;
purchTable = PurchTable::find(purchId);
packingSlipId = packingSlipId;
while select vendPackingSlipJour
where vendPackingSlipJour.PurchId == purchTable.PurchId
&& vendPackingSlipJour.PackingSlipId == packingSlipId
{
//Generate Pending Invoice Header
vendInvoiceInfoTable.clear();
vendInvoiceInfoTable.initValue();
vendInvoiceInfoTable.initFromPurchTable(purchTable);
vendInvoiceInfoTable.DocumentOrigin = DocumentOrigin::Manual;
vendInvoiceInfoTable.CurrencyCode = purchTable.CurrencyCode;
vendInvoiceInfoTable.DeliveryName = purchTable.DeliveryName;
vendInvoiceInfoTable.Num = _poHeaderSummaryInvIB.InvoiceNumber; //add invoice number in here
vendInvoiceInfoTable.PurchName = purchTable.PurchName;
vendInvoiceInfoTable.VendInvoiceSaveStatus = VendInvoiceSaveStatus::Pending;
vendInvoiceInfoTable.DocumentDate =_poHeaderSummaryInvIB.InvoiceDate;
vendInvoiceInfoTable.TransDate = _poHeaderSummaryInvIB.InvoiceDate;
vendInvoiceInfoTable.LastMatchVariance = LastMatchVarianceOptions::OK;
vendInvoiceInfoTable.ParmJobStatus = ParmJobStatus::Waiting;
vendInvoiceInfoTable.PaymMode=VendTable::find(purchTable.OrderAccount).PaymMode;
vendInvoiceInfoTable.Payment=VendTable::find(purchTable.OrderAccount).PaymTermId;
vendInvoiceInfoTable.TaxGroup = VendTable::find(purchTable.OrderAccount).TaxGroup;
vendInvoiceInfoTable.PostingProfile =purchTable.PostingProfile;
vendInvoiceInfoTable.VATNum = purchTable.VATNum;
select AccountID from VendBankAccount where VendBankAccount.VendAccount == purchTable.OrderAccount;
vendInvoiceInfoTable.VendBankAccountID = VendBankAccount.AccountID;
vendInvoiceInfoTable.Approved = NoYes::Yes;
vendInvoiceInfoTable.Approver = DirPersonUser::currentWorker();
// vendInvoiceInfoTable.DefaultDimension = vendInvoiceInfoTable.copyDimension(purchTable.DefaultDimension);
vendInvoiceInfoTable.defaultField(fieldNum(VendInvoiceInfoTable,RemittanceLocation),null,purchTable);
vendInvoiceInfoTable.defaultField(fieldNum(VendInvoiceInfoTable,FixedDueDate),null,purchTable);
vendInvoiceInfoTable.defaultField(fieldNum(VendInvoiceInfoTable,ExchRate),null,purchTable);
vendInvoiceInfoTable.defaultField(fieldNum(VendInvoiceInfoTable,TransDate),null,purchTable);
vendInvoiceInfoTable.defaultField(fieldNum(VendInvoiceInfoTable,PaymMode),null,purchTable);
vendInvoiceInfoTable.insert();
attachmentDDInvoice.clear();
while select attachmentDDInvoice group by AXPONumber
where attachmentDDInvoice.SummaryInvoiceNumber == poHeaderSummaryInvIB.InvoiceNumber
//Generate Vend Invoice Info reference
if(vendInvoiceInfoTable)
{
vendInvoiceInfoSubTable.clear();
vendInvoiceInfoSubTable.initValue();
vendInvoiceInfoSubTable.defaultRow();
vendInvoiceInfoSubTable.ParmId = vendInvoiceInfoTable.ParmId;
vendInvoiceInfoSubTable.OrigPurchId = attachmentDDInvoice.AXPONumber;//vendInvoiceInfoTable.PurchId;
vendInvoiceInfoSubTable.PurchName = vendInvoiceInfoTable.PurchName;
vendInvoiceInfoSubTable.TableRefId = vendInvoiceInfoTable.TableRefId;
vendInvoiceInfoSubTable.insert();
}
attachmentDDInvoice.clear();
while select attachmentDDInvoice where attachmentDDInvoice.IsInvoicedCreated ==NoYes::No
&& attachmentDDInvoice.SummaryInvoiceNumber == _poHeaderSummaryInvIB.InvoiceNumber
{
if(attachmentDDInvoice.AXPOLineNumber != 0)
{
select vendPackingSlipTrans where vendPackingSlipTrans.PackingSlipId == attachmentDDInvoice.DeliveryNote;
LineNumber = (attachmentDDInvoice.AxPoLineNumber);
select purchLine where purchLine.PurchId == attachmentDDInvoice.AXPONumber
&& purchLine.LineNumber == LineNumber;
}
else
{
select vendPackingSlipTrans where vendPackingSlipTrans.PackingSlipId == attachmentDDInvoice.DeliveryNote;
// LineNumber = (attachmentDDInvoice.AxPoLineNumber);
select purchLine where purchLine.PurchId == attachmentDDInvoice.AXPONumber
&& purchLine.LineNumber == this.getpurchaseline(attachmentDDInvoice).LineNumber;
LineNumber = purchLine.LineNumber;
}
vendInvoiceInfoLine.clear();
vendInvoiceInfoLine.initValue();
vendInvoiceInfoLine.defaultRow(null,purchLine);
vendInvoiceInfoLine.initFromPurchLine(purchLine);
vendInvoiceInfoLine.DeliveryName = vendInvoiceInfoTable.DeliveryName;
vendInvoiceInfoLine.ParmId = vendInvoiceInfoTable.ParmId;
vendInvoiceInfoLine.TableRefId = vendInvoiceInfoTable.TableRefId;
vendInvoiceInfoLine.currencyCode = vendInvoiceInfoTable.CurrencyCode;
vendInvoiceInfoLine.LineNum = any2int(purchLine.LineNumber);
vendInvoiceInfoLine.InvoiceAccount = vendInvoiceInfoTable.InvoiceAccount;
vendInvoiceInfoLine.InventDimId = purchLine.InventDimId;
vendInvoiceInfoLine.OrderAccount = vendInvoiceInfoTable.OrderAccount;
vendInvoiceInfoLine.ItemId = purchLine.ItemId;
vendInvoiceInfoLine.InventTransId = purchLine.InventTransId;
vendInvoiceInfoLine.OrigPurchId = attachmentDDInvoice.AXPONumber;
vendInvoiceInfoLine.DocumentOrigin = DocumentOrigin::Manual;
select firstonly ItemId, EanCode, SON_PurchaseEAN from rAXItemEANCode
where rAXItemEANCode.ItemId == vendPackingSlipTrans.ItemId
&& rAXItemEANCode.SON_PurchaseEAN == noyes::Yes;
if(rAXItemEANCode)
{
SON_EANCode = rAXItemEANCode.EANCode;
}
{
vendInvoiceInfoLine.ReceiveNow = attachmentDDInvoice.InvoicedQty;
vendInvoiceInfoLine.RemainBefore = attachmentDDInvoice.InvoicedQty;
vendInvoiceInfoLine.RemainBeforeInvent =attachmentDDInvoice.InvoicedQty;
vendInvoiceInfoLine.PurchPrice = purchLine.PurchPrice;
vendInvoiceInfoLine.InventNow = attachmentDDInvoice.InvoicedQty;
vendInvoiceInfoLine.LineAmount = attachmentDDInvoice.VendorInvoiceAmt;
}
vendInvoiceInfoLine.DefaultDimension = purchLine.DefaultDimension;
vendInvoiceInfoLine.insert();
//
//insert maisc charges
while select markupTrans where markupTrans.TransRecId == attachmentDDInvoice.RecId
&& markupTrans.TransTableId == attachmentDDInvoice.TableId
{
markupTransloc.clear();
markupTransloc.initFromVendInvoiceInfoLine(vendInvoiceInfoLine);
markupTransloc.Value = markupTrans.Value;
markupTransloc.MarkupCode = markupTrans.MarkupCode;
markupTransloc.Txt = markupTrans.Txt;
markupTransloc.insert();
}
markupTrans = null;
while select markupTrans where markupTrans.TransRecId == purchLine.RecId
&& markupTrans.TransTableId == purchLine.TableId
{
markupTransloc.clear();
markupTransloc.initFromVendInvoiceInfoLine(vendInvoiceInfoLine);
markupTransloc.Value = markupTrans.Value;
markupTransloc.MarkupCode = markupTrans.MarkupCode;
markupTransloc.Txt = markupTrans.Txt;
markupTransloc.insert();
}
//Generate Vend Invoice Info reference from packing slip
if(vendInvoiceInfoLine.RecId)
{
vendInvoiceInfoSubLine.clear();
vendInvoiceInfoSubLine.initValue();
vendInvoiceInfoSubLine.defaultRow();
vendInvoiceInfoSubLine.ParmId = vendInvoiceInfoTable.ParmId;
vendInvoiceInfoSubLine.LineRefRecId = vendInvoiceInfoLine.RecId;
vendInvoiceInfoSubLine.ReceiveNow = purchLine.PurchQty;
vendInvoiceInfoSubLine.InventNow = purchLine.PurchQty;
vendInvoiceInfoSubLine.JournalRefRecId = vendPackingSlipTrans.RecId;
vendInvoiceInfoSubLine.JournalRefTableId = vendPackingSlipTrans.TableId;
vendInvoiceInfoSubLine.DocumentId = vendPackingSlipTrans.PackingSlipId;
vendInvoiceInfoSubLine.insert();
}
}
}
ttsCommit;
info(strFmt("Vendor invoice is created for %1 ",vendInvoiceInfoTable.Num));
}
above is my code while invoving some times it throws error like "
insufficient inventory transaction with status purchased""
how ever manually when i create a pending vendor invoice with multiple PO for same vendor it has no issue it gets invoiced also, how ever when i do it from my code it is throwing error while invoicing.
"
The purchase order or product receipt was corrected after the vendor invoice was created. All accounting distributions must be re-created to reflect any changes to the purchase order's or product receipt's accounting distr"
*This post is locked for comments