import sales forecast using CSV file ax 2012
public void ImportDate()
{
#File
Dialog dialog;
Filename filename;
DialogField dialogFilename;
//To filter the files while selecting
container conFilter = ["Comma Seperated Value .txt ", "*.csv"];
IO iO;
FilenameOpen filenameOpen;
Container record;
ForecastSales forecastSales;
ForecastModel forecastModel;
CustTable custTable;
InventTable inventTable;
InventDim inventDim,inventDimLoc;
InventItemGroup inventItemGroup;
InventItemPrice inventItemPrice;
InventTableModule inventTableModule;
DefaultDimensionView defaultDimensionView;
boolean first = true;
RecId dd;
//name dcl
ForecastModelHeadId ModelId;
str StartDate;
str itemgroup,SalesUnit;
real priceunit,costprice;
CustAccount custAccountId;
SalesQty SalesQty;
ItemId ItemId;
CustGroupId custGroup;
InventSiteId InventSiteId;
RecId recIdDefaultDimension;
CustCurrencyCode Currency;
HcmPersonnelNumberId hcmPersonnelNumberId;
DF_Uploading projDimUpload = new DF_Uploading();
CostPrice cp;
InventLocationId inventLocationId;
dialog = new dialog();
dialog.caption("Select File For forecastSales Master Import");
dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
//To filter the files while selecting
dialog.filenameLookupFilter(conFilter);
dialog.run();
if(dialog.closedOk())
{
filename = dialogFileName.value();
//info(strFmt("%1", filename));
}
iO = new CommaTextIo(filename,#IO_Read);
if (! iO || iO.status() != IO_Status::Ok)
{
throw error("@SYS19358");
}
while (iO.status() == IO_Status::Ok)
{
record = iO.read();// To read file
if (record)
{
if (first) //To skip header
{
first = false;
}
else
{
ModelId = conpeek(record, 1);
StartDate = conpeek(record, 2);
custAccountId = conpeek(record, 3);
ItemId = conpeek(record, 4);
SalesQty = conpeek(record, 5);
priceunit = conpeek(record, 6);
// InventSiteId = conpeek(record, 7);
hcmPersonnelNumberId = conpeek(record, 8);
cp = conpeek(record, 9);
inventLocationId = conpeek(record, 10);
select forecastModel where forecastModel.ModelId == ModelId;
custGroup = CustTable::find(custAccountId).CustGroup;
Currency = CustTable::find(custAccountId).Currency;
select InventTable where InventTable.ItemId == ItemId;
//priceunit = any2real(InventTable.());
SalesUnit = any2str(InventTable.salesUnitId());
itemgroup = any2str(InventTable.itemGroupId());
//--> added msk for cost prices
//select inventItemPrice order by ActivationDate desc where inventItemPrice.ItemId == ItemId;
//costprice = inventItemPrice.Price;
//
InventSiteId = InventTable::find(ItemId).inventInventSiteId();
select inventDim where inventDim.InventSiteId == InventSiteId;
inventDim.InventLocationId =inventLocationId;
inventDimLoc = InventDim::findOrCreate(inventDim);
//
//if(costprice == 0 )
//{
//select inventTableModule where inventTableModule.ModuleType == ModuleInventPurchSales::Invent && inventTableModule.ItemId == ItemId;
//costprice= inventTableModule.Price;
//}
//--> added msk for cost prices end
forecastSales.Active =NoYes::Yes;
forecastSales.ModelId = ModelId;
forecastSales.StartDate = str2Date(StartDate,123);
forecastSales.CustAccountId = custAccountId;
forecastSales.CustGroupId = custGroup;
forecastSales.ItemId = ItemId;
forecastSales.ItemGroupId = itemgroup;
//forecastSales.DefaultDimension =dd ;//defaultDimensionView.DefaultDimension;
forecastSales.Currency = Currency;
forecastSales.PriceUnit = 1;
forecastSales.Comment = InventTable.ProductName;
forecastSales.InventDimId = inventDimLoc.inventDimId;
forecastSales.CostPrice = cp;//costprice;
forecastSales.SalesUnitId = SalesUnit;
forecastSales.SalesQty = SalesQty;
forecastSales.InventQty = SalesQty;
forecastSales.SalesPrice = priceunit;
forecastSales.Amount = priceunit * SalesQty;
forecastSales.insert();
projDimUpload.importProjDim(hcmPersonnelNumberId,forecastSales.CustAccountId);
}
}
}
info("Record insert successfully");
}
public void ImportDate()
{
#File
Dialog dialog;
Filename filename;
DialogField dialogFilename;
//To filter the files while selecting
container conFilter = ["Comma Seperated Value .txt ", "*.csv"];
IO iO;
FilenameOpen filenameOpen;
Container record;
ForecastSales forecastSales;
ForecastModel forecastModel;
CustTable custTable;
InventTable inventTable;
InventDim inventDim,inventDimLoc;
InventItemGroup inventItemGroup;
InventItemPrice inventItemPrice;
InventTableModule inventTableModule;
DefaultDimensionView defaultDimensionView;
boolean first = true;
RecId dd;
//name dcl
ForecastModelHeadId ModelId;
str StartDate;
str itemgroup,SalesUnit;
real priceunit,costprice;
CustAccount custAccountId;
SalesQty SalesQty;
ItemId ItemId;
CustGroupId custGroup;
InventSiteId InventSiteId;
RecId recIdDefaultDimension;
CustCurrencyCode Currency;
HcmPersonnelNumberId hcmPersonnelNumberId;
DF_Uploading projDimUpload = new DF_Uploading();
CostPrice cp;
InventLocationId inventLocationId;
dialog = new dialog();
dialog.caption("Select File For forecastSales Master Import");
dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
//To filter the files while selecting
dialog.filenameLookupFilter(conFilter);
dialog.run();
if(dialog.closedOk())
{
filename = dialogFileName.value();
//info(strFmt("%1", filename));
}
iO = new CommaTextIo(filename,#IO_Read);
if (! iO || iO.status() != IO_Status::Ok)
{
throw error("@SYS19358");
}
while (iO.status() == IO_Status::Ok)
{
record = iO.read();// To read file
if (record)
{
if (first) //To skip header
{
first = false;
}
else
{
ModelId = conpeek(record, 1);
StartDate = conpeek(record, 2);
custAccountId = conpeek(record, 3);
ItemId = conpeek(record, 4);
SalesQty = conpeek(record, 5);
priceunit = conpeek(record, 6);
// InventSiteId = conpeek(record, 7);
hcmPersonnelNumberId = conpeek(record, 8);
cp = conpeek(record, 9);
inventLocationId = conpeek(record, 10);
select forecastModel where forecastModel.ModelId == ModelId;
custGroup = CustTable::find(custAccountId).CustGroup;
Currency = CustTable::find(custAccountId).Currency;
select InventTable where InventTable.ItemId == ItemId;
//priceunit = any2real(InventTable.());
SalesUnit = any2str(InventTable.salesUnitId());
itemgroup = any2str(InventTable.itemGroupId());
//--> added msk for cost prices
//select inventItemPrice order by ActivationDate desc where inventItemPrice.ItemId == ItemId;
//costprice = inventItemPrice.Price;
//
InventSiteId = InventTable::find(ItemId).inventInventSiteId();
select inventDim where inventDim.InventSiteId == InventSiteId;
inventDim.InventLocationId =inventLocationId;
inventDimLoc = InventDim::findOrCreate(inventDim);
//
//if(costprice == 0 )
//{
//select inventTableModule where inventTableModule.ModuleType == ModuleInventPurchSales::Invent && inventTableModule.ItemId == ItemId;
//costprice= inventTableModule.Price;
//}
//--> added msk for cost prices end
forecastSales.Active =NoYes::Yes;
forecastSales.ModelId = ModelId;
forecastSales.StartDate = str2Date(StartDate,123);
forecastSales.CustAccountId = custAccountId;
forecastSales.CustGroupId = custGroup;
forecastSales.ItemId = ItemId;
forecastSales.ItemGroupId = itemgroup;
//forecastSales.DefaultDimension =dd ;//defaultDimensionView.DefaultDimension;
forecastSales.Currency = Currency;
forecastSales.PriceUnit = 1;
forecastSales.Comment = InventTable.ProductName;
forecastSales.InventDimId = inventDimLoc.inventDimId;
forecastSales.CostPrice = cp;//costprice;
forecastSales.SalesUnitId = SalesUnit;
forecastSales.SalesQty = SalesQty;
forecastSales.InventQty = SalesQty;
forecastSales.SalesPrice = priceunit;
forecastSales.Amount = priceunit * SalesQty;
forecastSales.insert();
projDimUpload.importProjDim(hcmPersonnelNumberId,forecastSales.CustAccountId);
}
}
}
info("Record insert successfully");
}
No comments:
Post a Comment