X++ code to correct the product receipt in Microsoft Dynamics AX 2012 R3
private void cancelProductReceipt(Filename _fileName)
{
#File
IO iO;
Container con;
boolean first = true;
PurchFormLetter purchFormLetter;
PurchFormletterParmData purchFormLetterParmData;
PurchParmUpdate purchParmUpdate;
PurchParmTable purchParmTable;
PurchParmLine purchParmLine;
PurchTable purchTable;
PurchLine purchLine;
PurchId purchId;
Num packingSlipId;
VendPackingSlipJour vendPackingSlipJour;
VendPackingSlipTrans vendPackingSlipTrans;
ItemId itemId;
Qty qty;
FileIoPermission perm;
Line lineNumber;
;
perm = new FileIoPermission(_fileName, #IO_Read);
perm.assert();
iO = new CommaTextIo(_fileName,#IO_Read);
if (! iO || iO.status() != IO_Status::Ok)
{
throw error("@SYS19358");
}
while (iO.status() == IO_Status::Ok)
{
con = iO.read();// read file
if (con)
{
if (first) //skip header
{
first = false;
}
else
{
purchId = conPeek(con, 1);
packingSlipId = conPeek(con, 2);
itemId = conPeek(con, 3);
qty = conPeek(con, 4);
lineNumber = conPeek(con, 5);
purchTable = PurchTable::find(purchId);
select firstOnly vendPackingSlipJour
where vendPackingSlipJour.PurchId == purchId
&& vendPackingSlipJour.PackingSlipId == packingSlipId;
ttsBegin;
// Instantiate PurchFormLetterParmData
purchFormLetterParmData = PurchFormletterParmData::newData(
DocumentStatus::PackingSlip,
VersioningUpdateType::Correction);
purchFormLetterParmData.parmOnlyCreateParmUpdate(true);
purchFormLetterParmData.createData(false);
purchParmUpdate = purchFormLetterParmData.parmParmUpdate();
// Set PurchParmTable table
purchParmTable.clear();
// purchParmTable.TransDate = SystemDateGet();
purchParmTable.Ordering = DocumentStatus::PackingSlip;
purchParmTable.ParmJobStatus = ParmJobStatus::Waiting;
purchParmTable.ParmId = purchParmUpdate.ParmId;
purchParmTable.Num = packingSlipId;
purchParmTable.ReCalculate = true;
purchParmTable.PurchId = purchTable.PurchId;
purchParmTable.PurchName = purchTable.PurchName;
purchParmTable.DeliveryName = purchTable.DeliveryName;
purchParmTable.OrderAccount = purchTable.OrderAccount;
purchParmTable.InvoiceAccount = purchTable.InvoiceAccount;
purchParmTable.CurrencyCode = purchTable.CurrencyCode;
purchParmTable.DeliveryPostalAddress = purchTable.DeliveryPostalAddress;
purchParmTable.VendPackingSlipJour = vendPackingSlipJour.RecId;
purchParmTable.insert();
// Set PurchParmLine table
select purchLine
where purchLine.PurchId == purchTable.purchId
&& purchLine.ItemId == itemId
&& PurchLine.LineNumber == 1;
if (purchLine.PurchId)
{
select firstOnly OrigPurchid,PurchaseLineLineNumber,Qty,InventQty from vendPackingSlipTrans
where vendPackingSlipTrans.OrigPurchid == purchLine.PurchId
&& vendPackingSlipTrans.PurchaseLineLineNumber == purchLine.LineNumber;
purchParmLine.ParmId = purchParmTable.ParmId;
purchParmLine.TableRefId = purchParmTable.TableRefId;
purchParmLine.InitFromPurchLine(purchLine);
purchParmLine.ReceiveNow = -qty;
purchParmLine.modifiedReceiveNow();
purchParmLine.PreviousReceiveNow = vendPackingSlipTrans.Qty;
purchParmLine.PreviousInventNow = vendPackingSlipTrans.InventQty;
purchParmLine.setQty(DocumentStatus::PackingSlip, false);
purchParmLine.setLineAmount();
purchParmLine.insert();
}
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);
purchFormLetter.parmVersioningUpdateType(VersioningUpdateType::Correction);
purchFormLetter.purchParmUpdate(purchFormLetterParmData.parmParmUpdate());
purchFormLetter.parmCallerTable(vendPackingSlipJour);
purchFormLetter.parmParmTableNum(purchParmTable.ParmId);
purchFormLetter.parmId(purchParmTable.ParmId);
purchFormLetter.specQty(PurchUpdate::ReceiveNow);
// purchFormLetter.transDate(systemDateGet());
purchFormLetter.proforma(false);
purchFormLetter.run();
ttsCommit;
}
}
}
}
No comments:
Post a Comment