In the below example we are going to create a credit note for a Sale order which is already invoiced.
For this, we need to create a class and add the below method.
In this method, we are getting the data from a temp table mkCreditNote or any other source like CSV, WCF etc.
public void postCreditnote( RecId _creditnoteRecid)
{
CustInvoiceTrans custInvoiceTrans;
SalesCopying salesCopying;
boolean isCreditNoteCreated,isCreditNotePosted;
SalesId salesid;
SalesTable salesTable;
MKCreditNote mkCreditNote;
TmpFrmVirtual tmpFrmVirtualHeader;
TmpFrmVirtual tmpFrmVirtualLines;
void loadTmpVirtualTableAndCreateCN(CustInvoiceTrans _custInvoiceTrans,MKCreditNote _mkCreditNote,SalesTable _salesTable)
{
delete_from tmpFrmVirtualLines;
tmpFrmVirtualLines.TableNum = _custInvoiceTrans.TableId;
tmpFrmVirtualLines.RecordNo = _custInvoiceTrans.RecId;
tmpFrmVirtualLines.Id = _custInvoiceTrans.SalesId;
tmpFrmVirtualLines.LineNum = _custInvoiceTrans.LineNum;
tmpFrmVirtualLines.TransDate = _custInvoiceTrans.InvoiceDate;
tmpFrmVirtualLines.Qty = _mkCreditNote.Qty;
tmpFrmVirtualLines.write();
salesCopying = SalesCopying::construct(SalesPurchCopy::CreditNoteLines);
salesCopying.initParameters(_salesTable,
tmpFrmVirtualLines,
tmpFrmVirtualHeader,
1,
true,
false,
true,
true,
false);
salesCopying.copy();
}
select firstOnly salesid, RecId from mkCreditNote
where mkCreditNote.RecId == _creditnoteRecid;
if (mkCreditNote.RecId)
{
salesTable = SalesTable::find(amsCreditNote.SalesId,false);
if (salesTable.RecId)
{
while select amsCreditNote
join custInvoiceTrans
where custInvoiceTrans.SalesId == mkCreditNote.SalesId
&& custInvoiceTrans.ItemId == mkCreditNote.ItemId
&& custInvoiceTrans.InventDimId == mkCreditNote.InventDimId
&& custInvoiceTrans.InventTransId == mkCreditNote.InventTransId
&& amsCreditNote.RecId == _creditnoteRecid
{
isCreditNoteCreated = true;
loadTmpVirtualTableAndCreateCN(custInvoiceTrans,mkCreditNote,salesTable);
}
}
}
}
For this, we need to create a class and add the below method.
In this method, we are getting the data from a temp table mkCreditNote or any other source like CSV, WCF etc.
public void postCreditnote( RecId _creditnoteRecid)
{
CustInvoiceTrans custInvoiceTrans;
SalesCopying salesCopying;
boolean isCreditNoteCreated,isCreditNotePosted;
SalesId salesid;
SalesTable salesTable;
MKCreditNote mkCreditNote;
TmpFrmVirtual tmpFrmVirtualHeader;
TmpFrmVirtual tmpFrmVirtualLines;
void loadTmpVirtualTableAndCreateCN(CustInvoiceTrans _custInvoiceTrans,MKCreditNote _mkCreditNote,SalesTable _salesTable)
{
delete_from tmpFrmVirtualLines;
tmpFrmVirtualLines.TableNum = _custInvoiceTrans.TableId;
tmpFrmVirtualLines.RecordNo = _custInvoiceTrans.RecId;
tmpFrmVirtualLines.Id = _custInvoiceTrans.SalesId;
tmpFrmVirtualLines.LineNum = _custInvoiceTrans.LineNum;
tmpFrmVirtualLines.TransDate = _custInvoiceTrans.InvoiceDate;
tmpFrmVirtualLines.Qty = _mkCreditNote.Qty;
tmpFrmVirtualLines.write();
salesCopying = SalesCopying::construct(SalesPurchCopy::CreditNoteLines);
salesCopying.initParameters(_salesTable,
tmpFrmVirtualLines,
tmpFrmVirtualHeader,
1,
true,
false,
true,
true,
false);
salesCopying.copy();
}
select firstOnly salesid, RecId from mkCreditNote
where mkCreditNote.RecId == _creditnoteRecid;
if (mkCreditNote.RecId)
{
salesTable = SalesTable::find(amsCreditNote.SalesId,false);
if (salesTable.RecId)
{
while select amsCreditNote
join custInvoiceTrans
where custInvoiceTrans.SalesId == mkCreditNote.SalesId
&& custInvoiceTrans.ItemId == mkCreditNote.ItemId
&& custInvoiceTrans.InventDimId == mkCreditNote.InventDimId
&& custInvoiceTrans.InventTransId == mkCreditNote.InventTransId
&& amsCreditNote.RecId == _creditnoteRecid
{
isCreditNoteCreated = true;
loadTmpVirtualTableAndCreateCN(custInvoiceTrans,mkCreditNote,salesTable);
}
}
}
}
No comments:
Post a Comment