static
void
MultiSalesOrdersLineImport(Args _args)
{
SalesTable salesTable;
SalesLine salesLine;
InventDim inventDim;
container readcon,readcon1;
NumberSeq num;
CommaIo commaIo,commaIo1;
commaIo =
new
CommaIo(
'C:\\Users\\ax.user01\\Desktop\\SalesOrder&Line.csv'
,
'r'
);
commaIo1 =
new
CommaIo(
'C:\\Users\\ax.user01\\Desktop\\SalesOrderNo.csv'
,
'r'
);
commaIo.infieldDelimiter(
','
);
try
{
ttsbegin;
salesTable.clear();
readcon1 = commaIo1.read();
salesTable.CustAccount = conpeek(readcon1,1);
num = NumberSeq::newGetNum(SalesParameters::numRefSalesId());
salesTable.SalesId = num.num();
salesTable.initValue(SalesType::Sales);
salesTable.initFromCustTable();
if
(salesTable.validateWrite())
{
salesTable.insert();
while
(commaIo.status() == IO_Status::OK)
{
readcon = commaIo.read();
salesLine.ItemId = conpeek(readcon,1);
if
(salesLine.ItemId ==
"0"
)
break
;
inventDim.clear();
inventDim.InventSiteId = conpeek(readcon,4);
inventDim.InventLocationId = conpeek(readcon,5);
salesLine.clear();
salesLine.initValue(salesTable.SalesType);
salesLine.initFromSalesTable(salesTable);
salesLine.ItemId = conpeek(readcon,1);
salesLine.initFromInventTable(InventTable::find(conpeek(readcon,1)));
salesLine.InventDimId = InventDim::findOrCreate(inventDim).inventDimId;
salesLine.SalesQty = conpeek(readcon,2);
salesLine.RemainSalesPhysical = salesLine.SalesQty;
salesLine.SalesUnit = conpeek(readcon,3);
salesLine.QtyOrdered = salesLine.calcQtyOrdered();
salesLine.RemainInventPhysical = salesLine.QtyOrdered;
salesLine.setPriceDisc(InventDim::find(salesLine.InventDimId));
if
(salesLine.validateWrite())
{
salesLine.insert();
}
else
throw
error(
"Order line"
);
}
}
else
throw
error(
"Order header"
);
ttscommit;
}
catch
{
error(
"Error!"
);
return
;
}
info(
"Done!"
);
}
No comments:
Post a Comment