Mupltiple purchase orders on a single invoice

Hi All,
I need to consolidate the purchase order invoice i.e. one invoice can contain multiple purchase orders, for that I am using the below code but don't know what's wrong, it's not grouping the PO.
Please see the description.

static void InvoiceConsolidation(Args _args)
{
PurchFormLetter purchFormLetter;
PurchFormletterParmData purchFormLetterParmData;
PurchParmUpdate purchParmUpdate;
PurchParmTable purchParmTable;
PurchParmLine purchParmLine;
PurchTable purchTable;
PurchLine purchLine;
PurchId purchId;
Num packingSlipId;
Num invoiceId;

VendInvoiceInfoTable vendInvoiceInfoTable;
VendInvoiceInfoLine vendInvoiceInfoLine;
VendInvoiceInfoSubTable vendInvoiceInfoSubTable;

 

purchId = "PO0000223";
packingSlipId = "PS000006";
//invoiceId = "PS005" ;

purchTable = PurchTable::find(purchId);

ttsBegin;
// Create PurchParamUpdate table
purchFormLetterParmData = PurchFormletterParmData::newData(
DocumentStatus::PackingSlip,
VersioningUpdateType::Initial);

purchFormLetterParmData.parmOnlyCreateParmUpdate(true);
purchFormLetterParmData.createData(false);
purchParmUpdate = purchFormLetterParmData.parmParmUpdate();

// Set PurchParmTable table
purchParmTable.clear();
purchParmTable.initValue(); //Change
purchParmTable.TransDate = SystemDateGet();
purchParmTable.Ordering = DocumentStatus::Invoice;
purchParmTable.DocumentDate = systemDateGet();
purchParmTable.ParmJobStatus = ParmJobStatus::Waiting;
purchParmTable.Num = packingSlipId;
purchParmTable.PurchId = purchTable.PurchId;
purchParmTable.PurchName = purchTable.PurchName;
purchParmTable.DeliveryName = purchTable.DeliveryName;
purchParmTable.DeliveryPostalAddress = purchTable.DeliveryPostalAddress;
purchParmTable.OrderAccount = purchTable.OrderAccount;
purchParmTable.CurrencyCode = purchTable.CurrencyCode;
purchParmTable.InvoiceAccount = purchTable.InvoiceAccount;
purchParmTable.ParmId = purchParmUpdate.ParmId;
purchParmTable.insert();


vendInvoiceInfoTable.initFromPurchTable(purchTable);
vendInvoiceInfoTable.ParmId = purchParmTable.ParmId;
vendInvoiceInfoTable.DocumentDate = systemDateGet();
vendInvoiceInfoTable.Num = "Inv_" + purchTable.PurchId;
vendInvoiceInfoTable.insert();

// Set PurchParmLine table
while select purchLine
where purchLine.PurchId == 'PO0000223'
{
purchParmLine.InitFromPurchLine(purchLine);

purchParmLine.ReceiveNow = PurchLine.PurchReceivedNow;
purchParmLine.ParmId = purchParmTable.ParmId;
purchParmLine.TableRefId = purchParmTable.TableRefId;
purchParmLine.setQty(DocumentStatus::Invoice, false, true);
purchParmLine.setLineAmount();
purchParmLine.insert();

vendInvoiceInfoLine.clear();
vendInvoiceInfoLine.initFromPurchLine(purchLine);
vendInvoiceInfoLine.ParmId = vendInvoiceInfoTable.ParmId;
vendInvoiceInfoLine.TableRefId = vendInvoiceInfoTable.TableRefId;
vendInvoiceInfoLine.insert();
}

// Set PurchParmLine table
while select purchLine
where purchLine.PurchId == 'PO0000222'
{
purchParmLine.InitFromPurchLine(purchLine);
purchParmLine.OrigPurchId = 'PO0000223';
purchParmLine.ReceiveNow = PurchLine.PurchReceivedNow;
purchParmLine.ParmId = purchParmTable.ParmId;
purchParmLine.TableRefId = purchParmTable.TableRefId;
purchParmLine.setQty(DocumentStatus::Invoice, false, true);
purchParmLine.setLineAmount();
purchParmLine.insert();

vendInvoiceInfoLine.clear();
vendInvoiceInfoLine.initFromPurchLine(purchLine);
//vendInvoiceInfoLine.OrigPurchId = 'PO0000215';
vendInvoiceInfoLine.ParmId = vendInvoiceInfoTable.ParmId;
vendInvoiceInfoLine.TableRefId = vendInvoiceInfoTable.TableRefId;
vendInvoiceInfoLine.insert();
}

vendInvoiceInfoSubTable.clear();
vendInvoiceInfoSubTable.OrigPurchId = 'PO0000223';
vendInvoiceInfoSubTable.ParmId = vendInvoiceInfoTable.ParmId;
vendInvoiceInfoSubTable.TableRefId = vendInvoiceInfoTable.TableRefId;
vendInvoiceInfoSubTable.insert();

vendInvoiceInfoSubTable.clear();
vendInvoiceInfoSubTable.OrigPurchId = 'PO0000222';
vendInvoiceInfoSubTable.ParmId = vendInvoiceInfoTable.ParmId;
vendInvoiceInfoSubTable.TableRefId = vendInvoiceInfoTable.TableRefId;
vendInvoiceInfoSubTable.insert();

purchFormLetter = PurchFormLetter::construct(DocumentStatus::Invoice);
purchFormLetter.transDate(systemDateGet());
purchFormLetter.proforma(false);
purchFormLetter.specQty(PurchUpdate::ReceiveNow);
purchFormLetter.purchTable(purchTable);
purchFormLetter.purchParmUpdate(purchParmUpdate);

purchFormLetter.reArrange(true,true,true);


//purchFormLetter.update(purchtable, vendInvoiceInfoTable.Num , systemdateget());

// This is the ID we hard code as the product receipt ID, if we do the posting via UI
// user would have the option to manually enter this value
//purchFormLetter.parmParmTableNum(purchParmTable.ParmId);
//purchFormLetter.parmId(purchParmTable.ParmId);
//purchFormLetter.purchParmUpdate(purchFormLetterParmData.parmParmUpdate());
//
//purchFormLetter.update(purchtable, vendInvoiceInfoTable.Num, systemdateget());

//purchFormLetter.run();

//purchFormLetter.update(purchtable, "Inv_" + purchTable.PurchId, systemdateget());
ttsCommit;
}

 

Best Regards

Pranav Gupta

Parents
No Data
Reply Children
Related
Recommended