Importing Sales Order & Sales Lines from CSV file

In below code I have taken two CSV files one for Sales Order & another for Sales Lines:

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;
// Order header
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)
{
//Order line
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!");
}
Advertisements

2 thoughts on “Importing Sales Order & Sales Lines from CSV file

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s