
Hi All,
I had written the code to create inventory registration and after that post the product receipt. However, when posting the transaction, it mentioned error that warehouse, location and batch must specified. Note that these 3 value is coming from some customized table from integration point.
The code to register inventory seem running fine no error occured and inventtrans table is having a new line with Registered status and the rest of information. Not sure why when posting, it keep saying that the warehouse, location and batch dimension must be specified.
Wondering this issue was due to inventory registration issue or when posting issue. 1 thing that I noticed, when the posting is failed, I tried to go into that PO and try to do manual posting, when the parameter was set to Registered Quantity there is no line appear in the grid.
Below is the posting code.
public static boolean postProductReceipt(ProductReceiptHeaderInterfaceEntity _prcHeaderInterfaceEntity)
{
boolean poReceiptPosted;
PurchFormLetter purchFormLetter;
PurchFormletterParmData purchFormLetterParmData;
PurchParmUpdate purchParmUpdate;
PurchParmTable purchParmTable;
PurchParmLine purchParmLine;
PurchTable purchTable;
PurchLine purchLine;
PurchId purchId;
Num packingSlipId;
VendPackingSlipJour vendPackingSlipJour;
InventTrans inventTrans;
InventTransOrigin inventTransOrigin;
ProductReceiptLineInterfaceEntity prcLineInterfaceEntity;
purchId = _prcHeaderInterfaceEntity.PurchaseOrderNumber;
packingSlipId = _prcHeaderInterfaceEntity.ProductReceiptNumber;
purchTable = PurchTable::find(purchId);
ttsBegin;
purchFormLetterParmData = PurchFormletterParmData::newData(
DocumentStatus::PackingSlip,
VersioningUpdateType::Initial);
purchFormLetterParmData.parmOnlyCreateParmUpdate(true);
purchFormLetterParmData.createData(false);
purchParmUpdate = purchFormLetterParmData.parmParmUpdate();
// Set PurchParmTable table
purchParmTable.clear();
purchParmTable.initValue();
purchParmTable.TransDate = _prcHeaderInterfaceEntity.ProductReceiptDate;//SystemDateGet();
purchParmTable.Ordering = DocumentStatus::PackingSlip;
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();
while select purchLine join inventTrans Join inventTransOrigin
where purchLine.PurchId == purchTable.purchId
&& inventTransOrigin.InventTransId == purchLine.InventTransId
&& inventTrans.InventTransOrigin == inventTransOrigin.RecId
&& inventTrans.StatusReceipt == StatusReceipt::Registered
{
purchParmLine.InitFromPurchLine(purchLine);
purchParmLine.ReceiveNow = purchLine.registered();
purchParmLine.ParmId = purchParmTable.ParmId;
purchParmLine.TableRefId = purchParmTable.TableRefId;
purchParmLine.setQty(DocumentStatus::PackingSlip, false, true);
purchParmLine.setLineAmount();
purchParmLine.insert();
}
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);
purchFormLetter.transDate(systemDateGet());
purchFormLetter.proforma(false);
purchFormLetter.specQty(PurchUpdate::Recorded);
purchFormLetter.purchTable(purchTable);
purchFormLetter.parmParmTableNum(purchParmTable.ParmId);
purchFormLetter.parmId(purchParmTable.ParmId);
purchFormLetter.purchParmUpdate(purchFormLetterParmData.parmParmUpdate());
purchFormLetter.run();
ttsCommit;
////FIND POSTED PRODUCT RECEIPT. SUCCESSFUL IF EXIST, ELSE FALSE
select firstonly vendPackingSlipJour where vendPackingSlipJour.PurchId == _prcHeaderInterfaceEntity.PurchaseOrderNumber
&& vendPackingSlipJour.PackingSlipId == _prcHeaderInterfaceEntity.ProductReceiptNumber
&& vendPackingSlipJour.DeliveryDate == _prcHeaderInterfaceEntity.ProductReceiptDate;
if(vendPackingSlipJour)
poReceiptPosted = true;
else
poReceiptPosted = checkFailed('Posting not successful.');
return poReceiptPosted;
}
Below is the code to perform inventory registration.
public static boolean registerPurchLine(ProductReceiptHeaderInterfaceEntity _prcHeaderInterfaceEntity)
{
ProductReceiptLineInterfaceEntity prcLineInterfaceEntity;
PurchLine purchLine;
InventTrans inventTrans;
InventTransOrigin inventTransOrigin;
InventDim inventDim;
InventTransWMS_Register inventTransWMS_register;
TmpInventTransWMS tmpInventTransWMS;
boolean registered;
InventSiteId _inventSiteId;
InventLocationId _inventLocationId;
WMSLocationId _wmsLocationId;
InventBatchSerialId _batchNo;
InventBatchSerialId _serialNo;
InventSite inventSite; //Site
InventLocation inventLocation; //Warehouse
WMSLocation wmsLocation; //Location
InventBatch inventBatch; //Batch number
InventSerial inventSerial; //Serial number
while select prcLineInterfaceEntity where prcLineInterfaceEntity.PurchaseOrderNumber == _prcHeaderInterfaceEntity.PurchaseOrderNumber
&& prcLineInterfaceEntity.ProductReceiptNumber == _prcHeaderInterfaceEntity.ProductReceiptNumber
&& prcLineInterfaceEntity.ProductReceiptDate == _prcHeaderInterfaceEntity.ProductReceiptDate
&& prcLineInterfaceEntity.InterfaceStatus != InterfaceStatus::Completed
{
str errorMessage = "";
registered = false;
try
{
select firstonly purchLine where purchLine.PurchId == prcLineInterfaceEntity.PurchaseOrderNumber
&& purchLine.LineNumber == prcLineInterfaceEntity.PurchaseOrderLineNumber
&& purchLine.ItemId == prcLineInterfaceEntity.ItemNumber
&& purchLine.IsDeleted == NoYes::No;
if(purchLine)
{
_inventSiteId = prcLineInterfaceEntity.ReceivingSiteId;
_inventLocationId = prcLineInterfaceEntity.ReceivingWarehouseId;
_wmsLocationId = prcLineInterfaceEntity.ReceivingWarehouseLocationId;
_batchNo = prcLineInterfaceEntity.ItemBatchNumber;
_serialNo = prcLineInterfaceEntity.ItemSerialNumber;
inventTrans = InventTrans::findTransId(purchLine.InventTransId);
if(inventTrans)
{
inventDim = inventTrans.inventDim();
tmpInventTransWMS.clear();
tmpInventTransWMS.initFromInventTrans(inventTrans);
tmpInventTransWMS.InventQty = prcLineInterfaceEntity.ReceivedPurchaseQuantity;
if(_inventSiteId)
{
inventSite = InventSite::find(_inventSiteId);
inventDim.InventSiteId = inventSite.SiteId;
}
if(_inventLocationId)
{
inventLocation = InventLocation::find(_inventLocationId);
inventDim.InventLocationId = inventLocation.InventLocationId;
}
if(_wmsLocationId)
{
wmsLocation = WMSLocation::find(_wmsLocationId, _inventLocationId);
if(wmsLocation)
inventDim.wMSLocationId = wmsLocation.wMSLocationId;
else
error(strFmt('Location %1 not exist in warehouse %2.', _wmsLocationId, _inventLocationId));
}
if(_batchNo)
{
inventBatch = InventBatch::findOrCreate(_batchNo, inventTrans.ItemId);
inventDim.inventBatchId = inventBatch.inventBatchId;
}
if(_serialNo)
{
inventSerial = InventSerial::findOrCreate(_serialNo, inventTrans.ItemId);
inventDim.inventSerialId = inventSerial.InventSerialId;
}
InventDim _inventDim=inventDim::FindOrCreate(inventDim);
tmpInventTransWMS.InventDimId = inventDim::findOrCreate(inventDim).inventDimId;
tmpInventTransWMS.insert();
inventTrans.Qty = prcLineInterfaceEntity.ReceivedPurchaseQuantity;
inventTrans.inventDimId = inventDim::findOrCreate(inventDim).inventDimId;
inventTransWMS_register = inventTransWMS_register::newStandard(tmpInventTransWMS);
inventTransWMS_Register.createFromInventTrans(inventTrans,_inventDim);
inventTransWMS_register.writeTmpInventTransWMS(tmpInventTransWMS, inventTrans,_inventDim);
registered = inventTransWMS_register.updateInvent(purchLine);
if(registered)
{
ttsbegin;
prcLineInterfaceEntity.selectForUpdate(true);
prcLineInterfaceEntity.InterfaceStatus = InterfaceStatus::Completed;
prcLineInterfaceEntity.InterfaceTxt = "";
prcLineInterfaceEntity.update();
ttscommit;
Info(strFmt('%1 of item %2 in PurchId %3 registered with Batch: %4 Location: %5',
tmpInventTransWMS.InventQty,
purchLine.ItemId,
purchLine.PurchId, _batchNo, _wmsLocationId));
}
}
}
else
{
throw error(strFmt("Matching PurchLine not found for PO: %1 LineNum: %2",
prcLineInterfaceEntity.PurchaseOrderNumber,
prcLineInterfaceEntity.PurchaseOrderLineNumber));
}
}
catch
{
errorMessage = infolog.text(infologLine());
ttsbegin;
prcLineInterfaceEntity.selectForUpdate(true);
prcLineInterfaceEntity.InterfaceStatus = InterfaceStatus::Failed;
prcLineInterfaceEntity.InterfaceTxt = errorMessage;
prcLineInterfaceEntity.update();
ttscommit;
}
}
return registered;
}
Any advice is much appreciated.
Thanks.
Regards,
Teh
Hi YA TEH,
Have you debug to find the exact code that is reporting the error and then analyse the cause of the error?