Create Purchase order from Sales order through X++
public boolean modified()
{
boolean ret;
PurchCreateFromSalesOrder purchCreateFromSalesOrder = PurchCreateFromSalesOrder::construct();
//purchCreateFromSalesOrder.parm
FormControl buttonControl = any2Object(this) as FormControl;
FormRun formRun = buttonControl.formRun();
TmpPurchLinePrice tmpPurchLinePrice;
SalesLine salesLine, salesLineIterate;
SalesTable salesTable;
ret = next modified();
salesTable = formRun.dataSource(formDataSourceStr(SalesTable, SalesTable)).cursor();
salesLine = formRun.dataSource(formDataSourceStr(SalesTable, SalesLine)).cursor();
if (SalesType::Sales == salesTable.SalesType)
{
while select salesLineIterate
where salesLineIterate.SalesId == salesLine.SalesId
{
tmpPurchLinePrice.clear();
InventTable inventTable = salesLineIterate.inventTable();
tmpPurchLinePrice.SalesId = salesLineIterate.SalesId;
tmpPurchLinePrice.LineNum = salesLineIterate.LineNum;
tmpPurchLinePrice.SalesLineRefRecId = salesLineIterate.RecId;
tmpPurchLinePrice.AccountNum = inventTable.PrimaryVendorId;
tmpPurchLinePrice.Included = NoYes::Yes;
tmpPurchLinePrice.ItemId = salesLineIterate.ItemId;
tmpPurchLinePrice.InventDimId = salesLineIterate.InventDimId;
tmpPurchLinePrice.initFromInventTable(inventTable);
tmpPurchLinePrice.PurchUnit = salesLineIterate.SalesUnit;
if (salesTable.SalesType == SalesType::ReturnItem)
{
tmpPurchLinePrice.PurchQty = salesLineIterate.ExpectedRetQty;
tmpPurchLinePrice.PdsCWQty = salesLineIterate.PdsCWExpectedRetQty;
}
else
{
tmpPurchLinePrice.PurchQty = salesLineIterate.RemainSalesPhysical;
tmpPurchLinePrice.PdsCWQty = salesLineIterate.PdsCWRemainInventPhysical;
}
tmpPurchLinePrice.PurchUnit = salesLineIterate.SalesUnit;
tmpPurchLinePrice.PurchQty = EcoResProductUnitConverter::convertGivenUnitSymbolsForReleasedProduct(tmpPurchLinePrice.ItemId,
tmpPurchLinePrice.InventDimId,
tmpPurchLinePrice.PurchQty,
salesLine.SalesUnit,
tmpPurchLinePrice.PurchUnit,
NoYes::Yes);
tmpPurchLinePrice.PriceSearched = NoYes::No;
if (tmpPurchLinePrice.validateWrite())
{
tmpPurchLinePrice.insert();
}
}
purchCreateFromSalesOrder = PurchCreateFromSalesOrder::construct();
purchCreateFromSalesOrder.parmCallerRecord(salesTable);
purchCreateFromSalesOrder.parmTmpPurchLinePrice(tmpPurchLinePrice);
purchCreateFromSalesOrder.parmSalesTable(salesTable);
purchCreateFromSalesOrder.tradeLineDlvType(tradeLineDlvType::None);
purchCreateFromSalesOrder.run();
}
return ret;
}
No comments:
Post a Comment