upload beging balance ax 2012
class ALE_BegingingBalanceUpload extends RunBase
{
JournalId journalId;
}
...............................................................
public static void main(Args _args)
{
JournalId journalId;
ProjJournalTable projJournalTable;
ALE_BegingingBalanceUpload begingingBalanceUpload = new ALE_BegingingBalanceUpload();
projJournalTable = _args.record();
journalId = projJournalTable.JournalId;
begingingBalanceUpload.getJournalId(journalId);
begingingBalanceUpload.DateImport();
}
............................................................................
public void getJournalId(JournalId journalIdB)
{
journalId = journalIdB;
}
.................................................................
private RefRecId createCategoryDefaultDimensions(CategoryId _categoryId,DimensionValue _workerDim, DimensionValue _vehicleDim)
{
DimensionAttributeValueSetStorage dimStorage;
RefRecId defaultDimensionLoc;
ProjTable projTable;
Counter i;
DimensionAttribute dimensionAttribute;
DimensionAttributeValue dimensionAttributeValue;
DimensionAttributeValueSetItem dimensionAttributeValueSetItem;
DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
DimensionDefault defaultDim;
container conAttribute, conAttributeValue;
DimensionValue ProjectcategoryItem,workerDim,vehicleDim;
ProjectcategoryItem = _categoryId;
workerDim = _workerDim;
vehicleDim = _vehicleDim;
conAttribute = conNull();
conAttributeValue = conNull();
conAttribute = conIns(conAttribute,1,'ProjectcategoryItem');
conAttributeValue = conIns(conAttributeValue, 1, ProjectcategoryItem);
conAttribute = conIns(conAttribute,2,'Vehicle');
conAttributeValue = conIns(conAttributeValue, 2, vehicleDim);
conAttribute = conIns(conAttribute,3,'Worker');
conAttributeValue = conIns(conAttributeValue, 3, workerDim);
for (i = 1; i <= conLen(conAttribute); i++)
{
dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttribute,i));
if (dimensionAttribute.RecId == 0)
{
continue;
}
if (conPeek(conAttributeValue,i) != "")
{
dimensionAttributeValue = dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,conPeek(conAttributeValue,i),false,true);
valueSetStorage.addItem(dimensionAttributeValue);
}
defaultDimensionLoc = valueSetStorage.save();
}
return defaultDimensionLoc;
}
...............................................................................
private void DateImport()
{
#File
Dialog dialog;
Filename filename;
DialogField dialogFilename;
container conFilter = ["Comma Seperated Value .txt ", "*.csv"];
// start object creating
ProjBegBalJournalTrans_CostSales projBegBalJournalTrans_CostSales;
BegBalProjTransTypeCost projTransType;
CategoryId categoryId;
str worker;
Qty qty;
JournalId jId;
//ProjId ProjId;
ProjCostPriceCost costPrice;
ProjSalesPriceCost salesPrice;
ProjSalesCurrencyCode currencyId;
str TransDate,ProjId;
str linePty;
int recCount;
DimensionValue dimCat,dimWorker,dimVehical;
ProjTable projTable;
DimensionDefault dimension,catDim,workerDim,vehDim,dim1,dim2;
DimAttributeProjCategory dimAttributeProjCategory;
ProjInvoiceProjId fundingId;
// End object creating
ALE_BegingingBalanceUpload begingingBalanceUpload = new ALE_BegingingBalanceUpload();
IO iO;
FilenameOpen filenameOpen;
Container record;
boolean first = true;
dialog = new dialog();
dialog.caption("Select File For begining balance Import");
dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
//To filter the files while selecting
dialog.filenameLookupFilter(conFilter);
dialog.run();
if(dialog.closedOk())
{
filename = dialogFileName.value();
}
iO = new CommaTextIo(filename,#IO_Read);
if (! iO || iO.status() != IO_Status::Ok)
{
throw error("@SYS19358");
}
recCount = 0;
ttsBegin;
while (iO.status() == IO_Status::Ok)
{
record = iO.read();// To read file
if (record)
{
if (first) //To skip header
{
first = false;
}
else
{
qty = 0; salesPrice = 0; costPrice = 0;
TransDate = conpeek(record, 1);
ProjID = conpeek(record, 2);
projTransType = conpeek(record, 3);
categoryId = conpeek(record, 4);
worker = conpeek(record, 5);
qty = conpeek(record, 6);
costPrice = conpeek(record, 7);
currencyId = conpeek(record, 8);
salesPrice = conpeek(record, 9);
linePty = conpeek(record, 10);
fundingId = conpeek(record, 11);
dimCat = conpeek(record, 12);
dimWorker = conpeek(record, 13);
dimVehical = conpeek(record, 14);
projBegBalJournalTrans_CostSales.JournalId = journalId;
projBegBalJournalTrans_CostSales.ProjTransDate = str2Date(TransDate,123);
projBegBalJournalTrans_CostSales.ProjId= ProjID;
projBegBalJournalTrans_CostSales.ProjTransType = projTransType;
projBegBalJournalTrans_CostSales.ProjCategoryId = categoryId;
projBegBalJournalTrans_CostSales.Quantity = qty;
projBegBalJournalTrans_CostSales.ProjSalesCurrencyId = currencyId;
projBegBalJournalTrans_CostSales.CostPrice = costPrice;
projBegBalJournalTrans_CostSales.SalesPrice = salesPrice;
projBegBalJournalTrans_CostSales.ProjLedgerCostStatus = 0;
projBegBalJournalTrans_CostSales.ProjTransStatusPostedInvoiced = ProjTransStatusPostedInvoiced::Invoiced;
projBegBalJournalTrans_CostSales.Worker = HcmWorker::findByPersonnelNumber(worker).RecId;
projBegBalJournalTrans_CostSales.CostAmount = qty * costPrice;
projBegBalJournalTrans_CostSales.ProjSalesAmount = qty * salesPrice;
projBegBalJournalTrans_CostSales.LinePropertyId = linePty;
projBegBalJournalTrans_CostSales.ProjFundingSource = ProjInvoiceTable::find(fundingId).RecId;
projBegBalJournalTrans_CostSales.TransId = ProjParameters::newTransId();
vehDim = 0; workerDim = 0; catDim = 0;
projTable = ProjTable::find(ProjID);
if(projTable)
{
dimension = begingingBalanceUpload.createCategoryDefaultDimensions(dimCat,dimWorker,dimVehical);
projBegBalJournalTrans_CostSales.DefaultDimension = projBegBalJournalTrans_CostSales.mergeDimension(projTable.DefaultDimension,dimension);
}
projBegBalJournalTrans_CostSales.insert();
recCount++;
}
}
}
ttsCommit;
info(strFmt(" %1 Record Insert successfully",recCount));
}
........................................................
class ALE_BegingingBalanceUpload extends RunBase
{
JournalId journalId;
}
...............................................................
public static void main(Args _args)
{
JournalId journalId;
ProjJournalTable projJournalTable;
ALE_BegingingBalanceUpload begingingBalanceUpload = new ALE_BegingingBalanceUpload();
projJournalTable = _args.record();
journalId = projJournalTable.JournalId;
begingingBalanceUpload.getJournalId(journalId);
begingingBalanceUpload.DateImport();
}
............................................................................
public void getJournalId(JournalId journalIdB)
{
journalId = journalIdB;
}
.................................................................
private RefRecId createCategoryDefaultDimensions(CategoryId _categoryId,DimensionValue _workerDim, DimensionValue _vehicleDim)
{
DimensionAttributeValueSetStorage dimStorage;
RefRecId defaultDimensionLoc;
ProjTable projTable;
Counter i;
DimensionAttribute dimensionAttribute;
DimensionAttributeValue dimensionAttributeValue;
DimensionAttributeValueSetItem dimensionAttributeValueSetItem;
DimensionAttributeValueSetStorage valueSetStorage = new DimensionAttributeValueSetStorage();
DimensionDefault defaultDim;
container conAttribute, conAttributeValue;
DimensionValue ProjectcategoryItem,workerDim,vehicleDim;
ProjectcategoryItem = _categoryId;
workerDim = _workerDim;
vehicleDim = _vehicleDim;
conAttribute = conNull();
conAttributeValue = conNull();
conAttribute = conIns(conAttribute,1,'ProjectcategoryItem');
conAttributeValue = conIns(conAttributeValue, 1, ProjectcategoryItem);
conAttribute = conIns(conAttribute,2,'Vehicle');
conAttributeValue = conIns(conAttributeValue, 2, vehicleDim);
conAttribute = conIns(conAttribute,3,'Worker');
conAttributeValue = conIns(conAttributeValue, 3, workerDim);
for (i = 1; i <= conLen(conAttribute); i++)
{
dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttribute,i));
if (dimensionAttribute.RecId == 0)
{
continue;
}
if (conPeek(conAttributeValue,i) != "")
{
dimensionAttributeValue = dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,conPeek(conAttributeValue,i),false,true);
valueSetStorage.addItem(dimensionAttributeValue);
}
defaultDimensionLoc = valueSetStorage.save();
}
return defaultDimensionLoc;
}
...............................................................................
private void DateImport()
{
#File
Dialog dialog;
Filename filename;
DialogField dialogFilename;
container conFilter = ["Comma Seperated Value .txt ", "*.csv"];
// start object creating
ProjBegBalJournalTrans_CostSales projBegBalJournalTrans_CostSales;
BegBalProjTransTypeCost projTransType;
CategoryId categoryId;
str worker;
Qty qty;
JournalId jId;
//ProjId ProjId;
ProjCostPriceCost costPrice;
ProjSalesPriceCost salesPrice;
ProjSalesCurrencyCode currencyId;
str TransDate,ProjId;
str linePty;
int recCount;
DimensionValue dimCat,dimWorker,dimVehical;
ProjTable projTable;
DimensionDefault dimension,catDim,workerDim,vehDim,dim1,dim2;
DimAttributeProjCategory dimAttributeProjCategory;
ProjInvoiceProjId fundingId;
// End object creating
ALE_BegingingBalanceUpload begingingBalanceUpload = new ALE_BegingingBalanceUpload();
IO iO;
FilenameOpen filenameOpen;
Container record;
boolean first = true;
dialog = new dialog();
dialog.caption("Select File For begining balance Import");
dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
//To filter the files while selecting
dialog.filenameLookupFilter(conFilter);
dialog.run();
if(dialog.closedOk())
{
filename = dialogFileName.value();
}
iO = new CommaTextIo(filename,#IO_Read);
if (! iO || iO.status() != IO_Status::Ok)
{
throw error("@SYS19358");
}
recCount = 0;
ttsBegin;
while (iO.status() == IO_Status::Ok)
{
record = iO.read();// To read file
if (record)
{
if (first) //To skip header
{
first = false;
}
else
{
qty = 0; salesPrice = 0; costPrice = 0;
TransDate = conpeek(record, 1);
ProjID = conpeek(record, 2);
projTransType = conpeek(record, 3);
categoryId = conpeek(record, 4);
worker = conpeek(record, 5);
qty = conpeek(record, 6);
costPrice = conpeek(record, 7);
currencyId = conpeek(record, 8);
salesPrice = conpeek(record, 9);
linePty = conpeek(record, 10);
fundingId = conpeek(record, 11);
dimCat = conpeek(record, 12);
dimWorker = conpeek(record, 13);
dimVehical = conpeek(record, 14);
projBegBalJournalTrans_CostSales.JournalId = journalId;
projBegBalJournalTrans_CostSales.ProjTransDate = str2Date(TransDate,123);
projBegBalJournalTrans_CostSales.ProjId= ProjID;
projBegBalJournalTrans_CostSales.ProjTransType = projTransType;
projBegBalJournalTrans_CostSales.ProjCategoryId = categoryId;
projBegBalJournalTrans_CostSales.Quantity = qty;
projBegBalJournalTrans_CostSales.ProjSalesCurrencyId = currencyId;
projBegBalJournalTrans_CostSales.CostPrice = costPrice;
projBegBalJournalTrans_CostSales.SalesPrice = salesPrice;
projBegBalJournalTrans_CostSales.ProjLedgerCostStatus = 0;
projBegBalJournalTrans_CostSales.ProjTransStatusPostedInvoiced = ProjTransStatusPostedInvoiced::Invoiced;
projBegBalJournalTrans_CostSales.Worker = HcmWorker::findByPersonnelNumber(worker).RecId;
projBegBalJournalTrans_CostSales.CostAmount = qty * costPrice;
projBegBalJournalTrans_CostSales.ProjSalesAmount = qty * salesPrice;
projBegBalJournalTrans_CostSales.LinePropertyId = linePty;
projBegBalJournalTrans_CostSales.ProjFundingSource = ProjInvoiceTable::find(fundingId).RecId;
projBegBalJournalTrans_CostSales.TransId = ProjParameters::newTransId();
vehDim = 0; workerDim = 0; catDim = 0;
projTable = ProjTable::find(ProjID);
if(projTable)
{
dimension = begingingBalanceUpload.createCategoryDefaultDimensions(dimCat,dimWorker,dimVehical);
projBegBalJournalTrans_CostSales.DefaultDimension = projBegBalJournalTrans_CostSales.mergeDimension(projTable.DefaultDimension,dimension);
}
projBegBalJournalTrans_CostSales.insert();
recCount++;
}
}
}
ttsCommit;
info(strFmt(" %1 Record Insert successfully",recCount));
}
........................................................
No comments:
Post a Comment