
While importing sales order using the custom entity, if the last sales order line is created,
new purchase order will be created for the sales lines which having the ‘Auto created
purchase order’ setup in Item master. The PO should be auto confirmed.
ï‚· Even if one sales order line does not have a primary vendor associated with the item, then
the PO should not be created, and the details will get stored to the error log table.
this is my requirement
public static void postTargetProcess(DMFDefinitionGroupExecution _dmfDefinitionGroupExecution)
{
PurchCreateFromSalesOrder purchCreateFromSalesOrder;
PurchAutoCreate purchAutoCreate;
NumberSeq numberSeq;
TmpPurchLinePrice tplP;
VendAccount prevVendAccount;
InventTableModule inventTableMod;
SalesTable salesTable;
SalesLine salesLine;
PurchTable purchTable;
InventTable inventTable;
DirPartyTable party;
CustTable custTable;
IMPDAutoPOErrors autoPoErrors;
LineNum lineNumber = 0;
IMPDSalesLineStaging salesLineStaging;
NoYesId noyes;
DMFDefinitionGroupName definitionGroup = _dmfDefinitionGroupExecution.DefinitionGroup;
DMFExecutionId executionId = _dmfDefinitionGroupExecution.ExecutionId;
DMFEntityName entityName = _dmfDefinitionGroupExecution.Entity;
DMFDefinitionGroupExecution currentExecution;
if (_dmfDefinitionGroupExecution.StagingStatus == DMFBatchJobStatus::Finished)
{
ttsbegin;
while select salesLineStaging
where salesLineStaging.DefinitionGroup == _dmfDefinitionGroupExecution.DefinitionGroup
&& salesLineStaging.ExecutionId == _dmfDefinitionGroupExecution.ExecutionId
&& salesLineStaging.TransferStatus == DMFTransferStatus::Completed
{
while select SalesId from salesLineStaging
group by SalesId
where salesLineStaging.DefinitionGroup == definitionGroup
&& salesLineStaging.ExecutionId == executionId
{
salesTable = SalesTable::find(salesLineStaging.SalesId);
if(salesTable)
{
while select salesLine
order by inventTable.PrimaryVendorId
where salesLine.SalesId == salesTable.SalesId
join inventTable
where inventTable.ItemId == salesLine.ItemId
join inventTableMod
where inventTableMod.ItemId == inventTable.ItemId
{
if ( !inventTable.PrimaryVendorId)
{
numberSeq=NumberSeq::newGetNum(PurchParameters::numRefPurchId());
numberSeq.used();
purchTable.PurchId = numberSeq.num();
autoPoErrors.PurchaseOrder = purchTable.PurchId;
autoPoErrors.SalesOrder = salesLine.SalesId;
autoPoErrors.ItemNumber = salesLine.ItemId;
autoPoErrors.insert();
delete_from tplP;
lineNumber = 0;
}
salesTable = salesLine.salesTable();
tplP.clear();
lineNumber = 1;
tplP.SalesId = salesLine.SalesId;
tplP.LineNum = lineNumber;
tplP.SalesLineRefRecId = salesLine.RecId;
tplP.AccountNum = inventTable.PrimaryVendorId;
tplP.ItemId = salesLine.ItemId;
tplP.InventDimId = salesLine.InventDimId;
tplP.Included = NoYes::Yes;
tplP.PurchQty = salesLine.SalesQty;
tplP.QtyOrdered = salesLine.QtyOrdered;
tplP.PurchUnit = salesLine.SalesUnit;
tplP.LineAmount = salesLine.LineAmount;
tplP.LineDisc = salesLine.LineDisc;
tplP.LinePercent = salesLine.LinePercent;
tplP.MultiLineDisc = salesLine.MultiLnDisc;
tplP.MultiLinePercent = salesLine.MultiLnPercent;
//tplP.Price = salesLine.SalesPrice;
tplP.PriceUnit = salesLine.PriceUnit;
tplP.CurrencyCode = salesLine.CurrencyCode;
tplP.Markup = salesLine.SalesMarkup;
tplP.insert();
prevVendAccount = tplP.AccountNum;
noyes =inventTableMod.AutoCreatePurchaseOrder;
if (prevVendAccount && salesTable.SalesStatus == SalesStatus::Backorder )
{
purchAutoCreate = PurchAutoCreate::construct(tplP,PurchCreateFromSalesOrder);
purchAutoCreate.create();
delete_from tplP;
}
}
}
}
}
ttscommit;
}
}
Please describe your problem. "this code is not working" might mean anything.
Post your code with line indentation - your current version is very difficult to follow. Always use Insert > Code (in the rich formatting view) to paste source code to this forum.
By the way, I moved your question from the AX forum, because I think it's actually about F&O.