public class ProductAttributeMasterUpload extends RunBase
{
CommaIo csvFile;
Filename filename;
DialogField dialogFilename,dialogcheckbox,dialogFromDate,dialogledger;
container readCon;
counter icount,inserted;
Amount amount;
int cutoffdays,prevcutoffdays;
currencycode currencycode;
Amount AmountDB,AmountCR,CrCutOffAmountCalc,DrCutOffAmountCalc;
str AccountNum,date1;
args args;
EcoResProductVariantDimensionValue EcoResProductVariantDimensionValue;
RefRecId ecoResDistinctProductVariantRecId;
EcoResProductReleaseManagerBase releaseManager;
container productDimensions;
#define.CurrentVersion(2)
#localmacro.CurrentList
filename,
insertIncorrectRecords,
#endmacro
#localmacro.ListVersion1
filename,
insertIncorrectRecords
#endmacro
#File
}
public Object dialog()
{
DialogRunbase dialog = super();
;
dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
dialogFilename.value(filename);
dialog.filenameLookupFilter(["All files", #AllFiles]);
return dialog;
}
public boolean getFromDialog()
{
filename = dialogFilename.value();
return true;
}
void ProductAttribute()
{
boolean first = true;
MainAccount mainAccount;
DimensionAttributeValueCombination dimensionAttributeValueCombination;
MainAccountNum mainAccountNum;
NumberSequenceTable numberSequenceTable;
LedgerJournalEngine_Daily ledgerJournalEngine_Daily;
Voucher voucher;
DimensionLedgerAccountType ledgerAccountType;
str accountType;
Amount amountCurDebit,amountCurCredit,amtcrdt,amtdebt,price;
container conSplitValue,dimm,offdim;
projTable projTable;
DimensionAttributeValueCombination ledgerDimension,dimensionAttributeValueCombinationrecid;
ProjId projid;
JournalTableData JournalTableData;
AxLedgerJournalTrans trans = new AxLedgerJournalTrans();
AxLedgerJournalTable header = new AxLedgerJournalTable();
str dimensn,offdimensn;
str 64 custAccount,ledgerAccount;
CustTable custtable;
dimensionAttribute dimensionAttribute;
dimensionAttributevalue dimensionAttributevalue;
DimensionAttributeValueSetStorage dimstorage;
int64 reccid;
Struct struct = new Struct();
container conledgerDimension;
DimensionDefault DimensionDefault;
str costcenter,department,revenueDimension,description;
LedgerJournalACTypE acctype,offacctype;
DimensionStorage DimensionStorage;
AssetTable assetTable;
AssetBook assetbook;
str 64 assetid;
transDate acqdate,rundate,lastrundt,placedinsev;
real acqprice,sevlife,reaming;
int lifetime;
InventTable InventTable;
str 64 itemid,stdconfig,stdsize,stdcolor,stdstyle,_attributename,_attributevalue;
RefRecId itemRecID;
EcoResProduct EcoResProduct,product;
EcoResProductCategory ecoResProductCategory;
EcoResCategory ecoResCategory;
EcoResCategoryAttributeLookup ecoResCategoryAttributeLookup;
EcoResAttribute ecoResAttribute;
EcoResAttributeValue ecoResAttributeValue;
EcoResProductInstanceValue ecoResProductInstanceValue;
EcoResTextValue ecoResTextValue, ecoResTextValue_ForUpdate, ecoResTextValue_ForValidation;
EcoResAttributeType EcoResAttributeType;
EcoResIntValue EcoResIntValue,ecoresIntValue_forupdate,ecoresIntValue_forValidation;
EcoResCurrencyValue ecoResCurrencyValue,ecoResCurrencyValue_forupdate,ecoResCurrencyValue_forvalidation;
EcoResDateTimeValue EcoResDateTimeValue,EcoResDateTimeValue_forupdate,EcoResDateTimeValue_forvalidation;
EcoResFloatValue EcoResFloatValue,EcoResFloatValue_forupdate,EcoResFloatValue_forvalidation;
EcoResBooleanValue EcoResBooleanValue,EcoResBooleanValue_forupdate,EcoResBooleanValue_forvalidation;
;
csvFile = new CommaIO(filename, 'r');
try
{
if (csvFile)
{
ttsbegin;
while (csvFile.status() == IO_Status::OK)
{
readCon = csvFile.read();
icount++;
if(icount == 1)
continue;
if (readCon && icount >1 )//dont insert first record of file : header
{
itemid = conPeek(readCon,1);
_attributename = conPeek(readCon,2);
_attributevalue = conPeek(readCon,3);
select ecoResAttribute where ecoResAttribute.Name == _attributename
join EcoResAttributeType where EcoResAttributeType.RecId == ecoResAttribute.AttributeType;
if(EcoResAttributeType.DataType == AttributeDataType::Integer)
this.setProductAttributeIntegerValue(itemid,_attributename,_attributevalue);
else if(EcoResAttributeType.DataType == AttributeDataType::Currency)
this.setProductAttributecurrencyValue(itemid,_attributename,any2real(_attributevalue));
// else if(EcoResAttributeType.DataType == AttributeDataType::DateTime)
// this.setProductAttributeDateTimeValue(itemid,_attributename,str2Date(_attributevalue,213));
else if(EcoResAttributeType.DataType == AttributeDataType::Decimal)
this.setProductAttributeDecimalValue(itemid,_attributename,any2real(_attributevalue));
else if(EcoResAttributeType.DataType == AttributeDataType::Text)
this.setProductAttributeTextValue(itemid,_attributename,_attributevalue);
else if(EcoResAttributeType.DataType == AttributeDataType::TrueFalse)
this.setProductAttributeTrueFalseValue(itemid,_attributename,str2num(_attributevalue));
}
}
inserted++;
ttsCommit;
}
icount--;//Remove header recount from total record count
}
catch(Exception::Error)
{
info(strFmt("%1 %2",Exception::Error,icount));
}
}
static void main(Args args)
{
ProductAttributeMasterUpload ProductAttributeMasterUpload;
ledgerJournalTrans ledgerJournalTrans;
;
ProductAttributeMasterUpload = new ProductAttributeMasterUpload();
if(ProductAttributeMasterUpload.prompt())
{
ProductAttributeMasterUpload.ProductAttribute();
}
}
void setProductAttributeCurrencyValue(itemID _itemid, str _attributeName , AttributeValueCurrency _attributeValue )
{
RefRecId itemRecID;
EcoResProduct product = EcoResProduct::find(InventTable::find(_itemId).Product);
EcoResProductCategory ecoResProductCategory;
EcoResCategory ecoResCategory;
EcoResCategoryAttributeLookup ecoResCategoryAttributeLookup;
EcoResAttribute ecoResAttribute;
EcoResAttributeValue ecoResAttributeValue;
EcoResProductInstanceValue ecoResProductInstanceValue;
EcoResTextValue ecoResTextValue, ecoResTextValue_ForUpdate, ecoResTextValue_ForValidation;
EcoResAttributeType EcoResAttributeType;
EcoResIntValue EcoResIntValue,ecoresIntValue_forupdate,ecoresIntValue_forValidation;
EcoResCurrencyValue ecoResCurrencyValue,ecoResCurrencyValue_forupdate,ecoResCurrencyValue_forvalidation;
EcoResDateTimeValue EcoResDateTimeValue,EcoResDateTimeValue_forupdate,EcoResDateTimeValue_forvalidation;
EcoResFloatValue EcoResFloatValue,EcoResFloatValue_forupdate,EcoResFloatValue_forvalidation;
EcoResBooleanValue EcoResBooleanValue,EcoResBooleanValue_forupdate,EcoResBooleanValue_forvalidation;
itemRecID = product.RecId;
//select EcoResProduct where EcoResProduct.DisplayProductNumber == _itemid;
while
select ecoResProductCategory where ecoResProductCategory.Product == itemRecID
join ecoResCategory where ecoResCategory.RecId == ecoResProductCategory.Category
{
while
select ecoResCategoryAttributeLookup where ecoResCategoryAttributeLookup.Category == ecoResCategory.RecId
join ecoResAttribute where ecoResAttribute.RecId == ecoResCategoryAttributeLookup.Attribute
{
select ecoResAttributeValue where ecoResAttributeValue.Attribute == ecoResAttribute.RecId
join ecoResProductInstanceValue where ecoResProductInstanceValue.RecId == ecoResAttributeValue.InstanceValue && ecoResProductInstanceValue.Product == itemRecID
join EcoRescurrencyValue where EcoRescurrencyValue.RecId == ecoResAttributeValue.Value;
if (strLwr(strLRTrim(ecoResAttribute.Name)) == strLwr(strLRTrim(_attributeName)))
{
ttsBegin;
while select forUpdate ecoRescurrencyValue_ForUpdate
where ecoRescurrencyValue_ForUpdate.RecId == ecoRescurrencyValue.RecId
{
ecoRescurrencyValue_ForUpdate.CurrencyValue = (_attributeValue);
ecoRescurrencyValue_ForUpdate.update();
}
ttsCommit;
select ecoRescurrencyValue_ForValidation where ecoRescurrencyValue_ForValidation.RecId == ecoRescurrencyValue.RecId;
if (ecoRescurrencyValue_ForValidation.CurrencyValue != (_attributeValue))
throw error('An exception was raised - could not update the attribute value. (ProductAttributesCopy/setProductAttributeValue)');
}
}
}
}
void setProductAttributeDateTimeValue(itemID _itemid, str _attributeName , utcdatetime _attributeValue)//attributevaluedatetime _attributeValue )
{
RefRecId itemRecID;
EcoResProduct product = EcoResProduct::find(InventTable::find(_itemId).Product);
EcoResProductCategory ecoResProductCategory;
EcoResCategory ecoResCategory;
EcoResCategoryAttributeLookup ecoResCategoryAttributeLookup;
EcoResAttribute ecoResAttribute;
EcoResAttributeValue ecoResAttributeValue;
EcoResProductInstanceValue ecoResProductInstanceValue;
EcoResTextValue ecoResTextValue, ecoResTextValue_ForUpdate, ecoResTextValue_ForValidation;
EcoResAttributeType EcoResAttributeType;
EcoResIntValue EcoResIntValue,ecoresIntValue_forupdate,ecoresIntValue_forValidation;
EcoResCurrencyValue ecoResCurrencyValue,ecoResCurrencyValue_forupdate,ecoResCurrencyValue_forvalidation;
EcoResDateTimeValue EcoResDateTimeValue,EcoResDateTimeValue_forupdate,EcoResDateTimeValue_forvalidation;
EcoResFloatValue EcoResFloatValue,EcoResFloatValue_forupdate,EcoResFloatValue_forvalidation;
EcoResBooleanValue EcoResBooleanValue,EcoResBooleanValue_forupdate,EcoResBooleanValue_forvalidation;
itemRecID = product.RecId;
//select EcoResProduct where EcoResProduct.DisplayProductNumber == _itemid;
while
select ecoResProductCategory where ecoResProductCategory.Product == itemRecID
join ecoResCategory where ecoResCategory.RecId == ecoResProductCategory.Category
{
while
select ecoResCategoryAttributeLookup where ecoResCategoryAttributeLookup.Category == ecoResCategory.RecId
join ecoResAttribute where ecoResAttribute.RecId == ecoResCategoryAttributeLookup.Attribute
{
select ecoResAttributeValue where ecoResAttributeValue.Attribute == ecoResAttribute.RecId
join ecoResProductInstanceValue where ecoResProductInstanceValue.RecId == ecoResAttributeValue.InstanceValue && ecoResProductInstanceValue.Product == itemRecID
join EcoResdatetimeValue where EcoResdatetimeValue.RecId == ecoResAttributeValue.Value;
if (strLwr(strLRTrim(ecoResAttribute.Name)) == strLwr(strLRTrim(_attributeName)))
{
ttsBegin;
while select forUpdate ecoResdatetimeValue_ForUpdate
where ecoResdatetimeValue_ForUpdate.RecId == ecoResdatetimeValue.RecId
{
ecoResdatetimeValue_ForUpdate.DateTimeValue = (_attributeValue);
ecoResdatetimeValue_ForUpdate.update();
}
ttsCommit;
select ecoResdatetimeValue_ForValidation where ecoResdatetimeValue_ForValidation.RecId == ecoResdatetimeValue.RecId;
if (ecoResdatetimeValue_ForValidation.DateTimeValue != (_attributeValue))
throw error('An exception was raised - could not update the attribute value. (ProductAttributesCopy/setProductAttributeValue)');
}
}
}
}
void setProductAttributeDecimalValue(itemID _itemid, str _attributeName , AttributeValueFloat _attributeValue )
{
RefRecId itemRecID;
EcoResProduct product = EcoResProduct::find(InventTable::find(_itemId).Product);
EcoResProductCategory ecoResProductCategory;
EcoResCategory ecoResCategory;
EcoResCategoryAttributeLookup ecoResCategoryAttributeLookup;
EcoResAttribute ecoResAttribute;
EcoResAttributeValue ecoResAttributeValue;
EcoResProductInstanceValue ecoResProductInstanceValue;
EcoResTextValue ecoResTextValue, ecoResTextValue_ForUpdate, ecoResTextValue_ForValidation;
EcoResAttributeType EcoResAttributeType;
EcoResIntValue EcoResIntValue,ecoresIntValue_forupdate,ecoresIntValue_forValidation;
EcoResCurrencyValue ecoResCurrencyValue,ecoResCurrencyValue_forupdate,ecoResCurrencyValue_forvalidation;
EcoResDateTimeValue EcoResDateTimeValue,EcoResDateTimeValue_forupdate,EcoResDateTimeValue_forvalidation;
EcoResFloatValue EcoResFloatValue,EcoResFloatValue_forupdate,EcoResFloatValue_forvalidation;
EcoResBooleanValue EcoResBooleanValue,EcoResBooleanValue_forupdate,EcoResBooleanValue_forvalidation;
itemRecID = product.RecId;
//select EcoResProduct where EcoResProduct.DisplayProductNumber == _itemid;
while
select ecoResProductCategory where ecoResProductCategory.Product == itemRecID
join ecoResCategory where ecoResCategory.RecId == ecoResProductCategory.Category
{
while
select ecoResCategoryAttributeLookup where ecoResCategoryAttributeLookup.Category == ecoResCategory.RecId
join ecoResAttribute where ecoResAttribute.RecId == ecoResCategoryAttributeLookup.Attribute
{
select ecoResAttributeValue where ecoResAttributeValue.Attribute == ecoResAttribute.RecId
join ecoResProductInstanceValue where ecoResProductInstanceValue.RecId == ecoResAttributeValue.InstanceValue && ecoResProductInstanceValue.Product == itemRecID
join EcoResfloatValue where EcoResfloatValue.RecId == ecoResAttributeValue.Value;
if (strLwr(strLRTrim(ecoResAttribute.Name)) == strLwr(strLRTrim(_attributeName)))
{
ttsBegin;
while select forUpdate ecoResfloatValue_ForUpdate
where ecoResfloatValue_ForUpdate.RecId == ecoResfloatValue.RecId
{
ecoResfloatValue_ForUpdate.FloatValue = any2real(_attributeValue);
ecoResfloatValue_ForUpdate.update();
}
ttsCommit;
select ecoResfloatValue_ForValidation where ecoResfloatValue_ForValidation.RecId == ecoResfloatValue.RecId;
if (ecoResfloatValue_ForValidation.FloatValue != any2real(_attributeValue))
throw error('An exception was raised - could not update the attribute value. (ProductAttributesCopy/setProductAttributeValue)');
}
}
}
}
void setProductAttributeIntegerValue(itemID _itemid, str _attributeName , str 1999 _attributeValue )
{
RefRecId itemRecID;
EcoResProduct product = EcoResProduct::find(InventTable::find(_itemId).Product);
EcoResProductCategory ecoResProductCategory;
EcoResCategory ecoResCategory;
EcoResCategoryAttributeLookup ecoResCategoryAttributeLookup;
EcoResAttribute ecoResAttribute;
EcoResAttributeValue ecoResAttributeValue;
EcoResProductInstanceValue ecoResProductInstanceValue;
EcoResTextValue ecoResTextValue, ecoResTextValue_ForUpdate, ecoResTextValue_ForValidation;
EcoResAttributeType EcoResAttributeType;
EcoResIntValue EcoResIntValue,ecoresIntValue_forupdate,ecoresIntValue_forValidation;
EcoResCurrencyValue ecoResCurrencyValue,ecoResCurrencyValue_forupdate,ecoResCurrencyValue_forvalidation;
EcoResDateTimeValue EcoResDateTimeValue,EcoResDateTimeValue_forupdate,EcoResDateTimeValue_forvalidation;
EcoResFloatValue EcoResFloatValue,EcoResFloatValue_forupdate,EcoResFloatValue_forvalidation;
EcoResBooleanValue EcoResBooleanValue,EcoResBooleanValue_forupdate,EcoResBooleanValue_forvalidation;
itemRecID = product.RecId;
//select EcoResProduct where EcoResProduct.DisplayProductNumber == _itemid;
while
select ecoResProductCategory where ecoResProductCategory.Product == itemRecID
join ecoResCategory where ecoResCategory.RecId == ecoResProductCategory.Category
{
while
select ecoResCategoryAttributeLookup where ecoResCategoryAttributeLookup.Category == ecoResCategory.RecId
join ecoResAttribute where ecoResAttribute.RecId == ecoResCategoryAttributeLookup.Attribute
{
select EcoResAttributeType where EcoResAttributeType.RecId == ecoResAttribute.AttributeType;
select ecoResAttributeValue where ecoResAttributeValue.Attribute == ecoResAttribute.RecId
join ecoResProductInstanceValue where ecoResProductInstanceValue.RecId == ecoResAttributeValue.InstanceValue && ecoResProductInstanceValue.Product == itemRecID
join EcoResIntValue where EcoResIntValue.RecId == ecoResAttributeValue.Value;
if (strLwr(strLRTrim(ecoResAttribute.Name)) == strLwr(strLRTrim(_attributeName)))
{
ttsBegin;
while select forUpdate ecoResintValue_ForUpdate
where ecoResIntValue_ForUpdate.RecId == ecoResIntValue.RecId
{
ecoResIntValue_ForUpdate.intValue = any2int(_attributeValue);
ecoResIntValue_ForUpdate.update();
}
ttsCommit;
select ecoResIntValue_ForValidation where ecoResIntValue_ForValidation.RecId == ecoResIntValue.RecId;
if (ecoResIntValue_ForValidation.IntValue != any2int(_attributeValue))
throw error('An exception was raised - could not update the attribute value. (ProductAttributesCopy/setProductAttributeValue)');
}
}
}
}
void setProductAttributeTextValue(itemID _itemid, str _attributeName , str 1999 _attributeValue )
{
RefRecId itemRecID;
EcoResProduct product = EcoResProduct::find(InventTable::find(_itemId).Product);
EcoResProductCategory ecoResProductCategory;
EcoResCategory ecoResCategory;
EcoResCategoryAttributeLookup ecoResCategoryAttributeLookup;
EcoResAttribute ecoResAttribute;
EcoResAttributeValue ecoResAttributeValue;
EcoResProductInstanceValue ecoResProductInstanceValue;
EcoResTextValue ecoResTextValue, ecoResTextValue_ForUpdate, ecoResTextValue_ForValidation;
EcoResAttributeType EcoResAttributeType;
EcoResIntValue EcoResIntValue,ecoresIntValue_forupdate,ecoresIntValue_forValidation;
EcoResCurrencyValue ecoResCurrencyValue,ecoResCurrencyValue_forupdate,ecoResCurrencyValue_forvalidation;
EcoResDateTimeValue EcoResDateTimeValue,EcoResDateTimeValue_forupdate,EcoResDateTimeValue_forvalidation;
EcoResFloatValue EcoResFloatValue,EcoResFloatValue_forupdate,EcoResFloatValue_forvalidation;
EcoResBooleanValue EcoResBooleanValue,EcoResBooleanValue_forupdate,EcoResBooleanValue_forvalidation;
itemRecID = product.RecId;
//select EcoResProduct where EcoResProduct.DisplayProductNumber == _itemid;
while
select ecoResProductCategory where ecoResProductCategory.Product == itemRecID
join ecoResCategory where ecoResCategory.RecId == ecoResProductCategory.Category
{
while
select ecoResCategoryAttributeLookup where ecoResCategoryAttributeLookup.Category == ecoResCategory.RecId
join ecoResAttribute where ecoResAttribute.RecId == ecoResCategoryAttributeLookup.Attribute
{
select ecoResAttributeValue where ecoResAttributeValue.Attribute == ecoResAttribute.RecId
join ecoResProductInstanceValue where ecoResProductInstanceValue.RecId == ecoResAttributeValue.InstanceValue && ecoResProductInstanceValue.Product == itemRecID
join EcoRestextValue where EcoRestextValue.RecId == ecoResAttributeValue.Value;
if (strLwr(strLRTrim(ecoResAttribute.Name)) == strLwr(strLRTrim(_attributeName)))
{
ttsBegin;
while select forUpdate ecoRestextValue_ForUpdate
where ecoRestextValue_ForUpdate.RecId == ecoRestextValue.RecId
{
ecoRestextValue_ForUpdate.textValue = (_attributeValue);
ecoRestextValue_ForUpdate.update();
}
ttsCommit;
select ecoRestextValue_ForValidation where ecoRestextValue_ForValidation.RecId == ecoRestextValue.RecId;
if (ecoRestextValue_ForValidation.textValue != (_attributeValue))
throw error('An exception was raised - could not update the attribute value. (ProductAttributesCopy/setProductAttributeValue)');
}
}
}
}
void setProductAttributeTrueFalseValue(itemID _itemid, str _attributeName , Attributevalueboolean _attributeValue )
{
RefRecId itemRecID;
EcoResProduct product = EcoResProduct::find(InventTable::find(_itemId).Product);
EcoResProductCategory ecoResProductCategory;
EcoResCategory ecoResCategory;
EcoResCategoryAttributeLookup ecoResCategoryAttributeLookup;
EcoResAttribute ecoResAttribute;
EcoResAttributeValue ecoResAttributeValue;
EcoResProductInstanceValue ecoResProductInstanceValue;
EcoResTextValue ecoResTextValue, ecoResTextValue_ForUpdate, ecoResTextValue_ForValidation;
EcoResAttributeType EcoResAttributeType;
EcoResIntValue EcoResIntValue,ecoresIntValue_forupdate,ecoresIntValue_forValidation;
EcoResCurrencyValue ecoResCurrencyValue,ecoResCurrencyValue_forupdate,ecoResCurrencyValue_forvalidation;
EcoResDateTimeValue EcoResDateTimeValue,EcoResDateTimeValue_forupdate,EcoResDateTimeValue_forvalidation;
EcoResFloatValue EcoResFloatValue,EcoResFloatValue_forupdate,EcoResFloatValue_forvalidation;
EcoResBooleanValue EcoResBooleanValue,EcoResBooleanValue_forupdate,EcoResBooleanValue_forvalidation;
itemRecID = product.RecId;
//select EcoResProduct where EcoResProduct.DisplayProductNumber == _itemid;
while
select ecoResProductCategory where ecoResProductCategory.Product == itemRecID
join ecoResCategory where ecoResCategory.RecId == ecoResProductCategory.Category
{
while
select ecoResCategoryAttributeLookup where ecoResCategoryAttributeLookup.Category == ecoResCategory.RecId
join ecoResAttribute where ecoResAttribute.RecId == ecoResCategoryAttributeLookup.Attribute
{
select ecoResAttributeValue where ecoResAttributeValue.Attribute == ecoResAttribute.RecId
join ecoResProductInstanceValue where ecoResProductInstanceValue.RecId == ecoResAttributeValue.InstanceValue && ecoResProductInstanceValue.Product == itemRecID
join EcoResbooleanValue where EcoResbooleanValue.RecId == ecoResAttributeValue.Value;
if (strLwr(strLRTrim(ecoResAttribute.Name)) == strLwr(strLRTrim(_attributeName)))
{
ttsBegin;
while select forUpdate EcoResbooleanValue_ForUpdate
where EcoResbooleanValue_ForUpdate.RecId == EcoResbooleanValue_ForUpdate.RecId
{
EcoResbooleanValue_ForUpdate.BooleanValue = (_attributeValue);
EcoResbooleanValue_ForUpdate.update();
}
ttsCommit;
select EcoResbooleanValue_ForValidation where EcoResbooleanValue_ForValidation.RecId == ecoResbooleanValue.RecId;
if (EcoResbooleanValue_ForValidation.BooleanValue != (_attributeValue))
throw error('An exception was raised - could not update the attribute value. (ProductAttributesCopy/setProductAttributeValue)');
}
}
}
}
{
CommaIo csvFile;
Filename filename;
DialogField dialogFilename,dialogcheckbox,dialogFromDate,dialogledger;
container readCon;
counter icount,inserted;
Amount amount;
int cutoffdays,prevcutoffdays;
currencycode currencycode;
Amount AmountDB,AmountCR,CrCutOffAmountCalc,DrCutOffAmountCalc;
str AccountNum,date1;
args args;
EcoResProductVariantDimensionValue EcoResProductVariantDimensionValue;
RefRecId ecoResDistinctProductVariantRecId;
EcoResProductReleaseManagerBase releaseManager;
container productDimensions;
#define.CurrentVersion(2)
#localmacro.CurrentList
filename,
insertIncorrectRecords,
#endmacro
#localmacro.ListVersion1
filename,
insertIncorrectRecords
#endmacro
#File
}
public Object dialog()
{
DialogRunbase dialog = super();
;
dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
dialogFilename.value(filename);
dialog.filenameLookupFilter(["All files", #AllFiles]);
return dialog;
}
public boolean getFromDialog()
{
filename = dialogFilename.value();
return true;
}
void ProductAttribute()
{
boolean first = true;
MainAccount mainAccount;
DimensionAttributeValueCombination dimensionAttributeValueCombination;
MainAccountNum mainAccountNum;
NumberSequenceTable numberSequenceTable;
LedgerJournalEngine_Daily ledgerJournalEngine_Daily;
Voucher voucher;
DimensionLedgerAccountType ledgerAccountType;
str accountType;
Amount amountCurDebit,amountCurCredit,amtcrdt,amtdebt,price;
container conSplitValue,dimm,offdim;
projTable projTable;
DimensionAttributeValueCombination ledgerDimension,dimensionAttributeValueCombinationrecid;
ProjId projid;
JournalTableData JournalTableData;
AxLedgerJournalTrans trans = new AxLedgerJournalTrans();
AxLedgerJournalTable header = new AxLedgerJournalTable();
str dimensn,offdimensn;
str 64 custAccount,ledgerAccount;
CustTable custtable;
dimensionAttribute dimensionAttribute;
dimensionAttributevalue dimensionAttributevalue;
DimensionAttributeValueSetStorage dimstorage;
int64 reccid;
Struct struct = new Struct();
container conledgerDimension;
DimensionDefault DimensionDefault;
str costcenter,department,revenueDimension,description;
LedgerJournalACTypE acctype,offacctype;
DimensionStorage DimensionStorage;
AssetTable assetTable;
AssetBook assetbook;
str 64 assetid;
transDate acqdate,rundate,lastrundt,placedinsev;
real acqprice,sevlife,reaming;
int lifetime;
InventTable InventTable;
str 64 itemid,stdconfig,stdsize,stdcolor,stdstyle,_attributename,_attributevalue;
RefRecId itemRecID;
EcoResProduct EcoResProduct,product;
EcoResProductCategory ecoResProductCategory;
EcoResCategory ecoResCategory;
EcoResCategoryAttributeLookup ecoResCategoryAttributeLookup;
EcoResAttribute ecoResAttribute;
EcoResAttributeValue ecoResAttributeValue;
EcoResProductInstanceValue ecoResProductInstanceValue;
EcoResTextValue ecoResTextValue, ecoResTextValue_ForUpdate, ecoResTextValue_ForValidation;
EcoResAttributeType EcoResAttributeType;
EcoResIntValue EcoResIntValue,ecoresIntValue_forupdate,ecoresIntValue_forValidation;
EcoResCurrencyValue ecoResCurrencyValue,ecoResCurrencyValue_forupdate,ecoResCurrencyValue_forvalidation;
EcoResDateTimeValue EcoResDateTimeValue,EcoResDateTimeValue_forupdate,EcoResDateTimeValue_forvalidation;
EcoResFloatValue EcoResFloatValue,EcoResFloatValue_forupdate,EcoResFloatValue_forvalidation;
EcoResBooleanValue EcoResBooleanValue,EcoResBooleanValue_forupdate,EcoResBooleanValue_forvalidation;
;
csvFile = new CommaIO(filename, 'r');
try
{
if (csvFile)
{
ttsbegin;
while (csvFile.status() == IO_Status::OK)
{
readCon = csvFile.read();
icount++;
if(icount == 1)
continue;
if (readCon && icount >1 )//dont insert first record of file : header
{
itemid = conPeek(readCon,1);
_attributename = conPeek(readCon,2);
_attributevalue = conPeek(readCon,3);
select ecoResAttribute where ecoResAttribute.Name == _attributename
join EcoResAttributeType where EcoResAttributeType.RecId == ecoResAttribute.AttributeType;
if(EcoResAttributeType.DataType == AttributeDataType::Integer)
this.setProductAttributeIntegerValue(itemid,_attributename,_attributevalue);
else if(EcoResAttributeType.DataType == AttributeDataType::Currency)
this.setProductAttributecurrencyValue(itemid,_attributename,any2real(_attributevalue));
// else if(EcoResAttributeType.DataType == AttributeDataType::DateTime)
// this.setProductAttributeDateTimeValue(itemid,_attributename,str2Date(_attributevalue,213));
else if(EcoResAttributeType.DataType == AttributeDataType::Decimal)
this.setProductAttributeDecimalValue(itemid,_attributename,any2real(_attributevalue));
else if(EcoResAttributeType.DataType == AttributeDataType::Text)
this.setProductAttributeTextValue(itemid,_attributename,_attributevalue);
else if(EcoResAttributeType.DataType == AttributeDataType::TrueFalse)
this.setProductAttributeTrueFalseValue(itemid,_attributename,str2num(_attributevalue));
}
}
inserted++;
ttsCommit;
}
icount--;//Remove header recount from total record count
}
catch(Exception::Error)
{
info(strFmt("%1 %2",Exception::Error,icount));
}
}
static void main(Args args)
{
ProductAttributeMasterUpload ProductAttributeMasterUpload;
ledgerJournalTrans ledgerJournalTrans;
;
ProductAttributeMasterUpload = new ProductAttributeMasterUpload();
if(ProductAttributeMasterUpload.prompt())
{
ProductAttributeMasterUpload.ProductAttribute();
}
}
void setProductAttributeCurrencyValue(itemID _itemid, str _attributeName , AttributeValueCurrency _attributeValue )
{
RefRecId itemRecID;
EcoResProduct product = EcoResProduct::find(InventTable::find(_itemId).Product);
EcoResProductCategory ecoResProductCategory;
EcoResCategory ecoResCategory;
EcoResCategoryAttributeLookup ecoResCategoryAttributeLookup;
EcoResAttribute ecoResAttribute;
EcoResAttributeValue ecoResAttributeValue;
EcoResProductInstanceValue ecoResProductInstanceValue;
EcoResTextValue ecoResTextValue, ecoResTextValue_ForUpdate, ecoResTextValue_ForValidation;
EcoResAttributeType EcoResAttributeType;
EcoResIntValue EcoResIntValue,ecoresIntValue_forupdate,ecoresIntValue_forValidation;
EcoResCurrencyValue ecoResCurrencyValue,ecoResCurrencyValue_forupdate,ecoResCurrencyValue_forvalidation;
EcoResDateTimeValue EcoResDateTimeValue,EcoResDateTimeValue_forupdate,EcoResDateTimeValue_forvalidation;
EcoResFloatValue EcoResFloatValue,EcoResFloatValue_forupdate,EcoResFloatValue_forvalidation;
EcoResBooleanValue EcoResBooleanValue,EcoResBooleanValue_forupdate,EcoResBooleanValue_forvalidation;
itemRecID = product.RecId;
//select EcoResProduct where EcoResProduct.DisplayProductNumber == _itemid;
while
select ecoResProductCategory where ecoResProductCategory.Product == itemRecID
join ecoResCategory where ecoResCategory.RecId == ecoResProductCategory.Category
{
while
select ecoResCategoryAttributeLookup where ecoResCategoryAttributeLookup.Category == ecoResCategory.RecId
join ecoResAttribute where ecoResAttribute.RecId == ecoResCategoryAttributeLookup.Attribute
{
select ecoResAttributeValue where ecoResAttributeValue.Attribute == ecoResAttribute.RecId
join ecoResProductInstanceValue where ecoResProductInstanceValue.RecId == ecoResAttributeValue.InstanceValue && ecoResProductInstanceValue.Product == itemRecID
join EcoRescurrencyValue where EcoRescurrencyValue.RecId == ecoResAttributeValue.Value;
if (strLwr(strLRTrim(ecoResAttribute.Name)) == strLwr(strLRTrim(_attributeName)))
{
ttsBegin;
while select forUpdate ecoRescurrencyValue_ForUpdate
where ecoRescurrencyValue_ForUpdate.RecId == ecoRescurrencyValue.RecId
{
ecoRescurrencyValue_ForUpdate.CurrencyValue = (_attributeValue);
ecoRescurrencyValue_ForUpdate.update();
}
ttsCommit;
select ecoRescurrencyValue_ForValidation where ecoRescurrencyValue_ForValidation.RecId == ecoRescurrencyValue.RecId;
if (ecoRescurrencyValue_ForValidation.CurrencyValue != (_attributeValue))
throw error('An exception was raised - could not update the attribute value. (ProductAttributesCopy/setProductAttributeValue)');
}
}
}
}
void setProductAttributeDateTimeValue(itemID _itemid, str _attributeName , utcdatetime _attributeValue)//attributevaluedatetime _attributeValue )
{
RefRecId itemRecID;
EcoResProduct product = EcoResProduct::find(InventTable::find(_itemId).Product);
EcoResProductCategory ecoResProductCategory;
EcoResCategory ecoResCategory;
EcoResCategoryAttributeLookup ecoResCategoryAttributeLookup;
EcoResAttribute ecoResAttribute;
EcoResAttributeValue ecoResAttributeValue;
EcoResProductInstanceValue ecoResProductInstanceValue;
EcoResTextValue ecoResTextValue, ecoResTextValue_ForUpdate, ecoResTextValue_ForValidation;
EcoResAttributeType EcoResAttributeType;
EcoResIntValue EcoResIntValue,ecoresIntValue_forupdate,ecoresIntValue_forValidation;
EcoResCurrencyValue ecoResCurrencyValue,ecoResCurrencyValue_forupdate,ecoResCurrencyValue_forvalidation;
EcoResDateTimeValue EcoResDateTimeValue,EcoResDateTimeValue_forupdate,EcoResDateTimeValue_forvalidation;
EcoResFloatValue EcoResFloatValue,EcoResFloatValue_forupdate,EcoResFloatValue_forvalidation;
EcoResBooleanValue EcoResBooleanValue,EcoResBooleanValue_forupdate,EcoResBooleanValue_forvalidation;
itemRecID = product.RecId;
//select EcoResProduct where EcoResProduct.DisplayProductNumber == _itemid;
while
select ecoResProductCategory where ecoResProductCategory.Product == itemRecID
join ecoResCategory where ecoResCategory.RecId == ecoResProductCategory.Category
{
while
select ecoResCategoryAttributeLookup where ecoResCategoryAttributeLookup.Category == ecoResCategory.RecId
join ecoResAttribute where ecoResAttribute.RecId == ecoResCategoryAttributeLookup.Attribute
{
select ecoResAttributeValue where ecoResAttributeValue.Attribute == ecoResAttribute.RecId
join ecoResProductInstanceValue where ecoResProductInstanceValue.RecId == ecoResAttributeValue.InstanceValue && ecoResProductInstanceValue.Product == itemRecID
join EcoResdatetimeValue where EcoResdatetimeValue.RecId == ecoResAttributeValue.Value;
if (strLwr(strLRTrim(ecoResAttribute.Name)) == strLwr(strLRTrim(_attributeName)))
{
ttsBegin;
while select forUpdate ecoResdatetimeValue_ForUpdate
where ecoResdatetimeValue_ForUpdate.RecId == ecoResdatetimeValue.RecId
{
ecoResdatetimeValue_ForUpdate.DateTimeValue = (_attributeValue);
ecoResdatetimeValue_ForUpdate.update();
}
ttsCommit;
select ecoResdatetimeValue_ForValidation where ecoResdatetimeValue_ForValidation.RecId == ecoResdatetimeValue.RecId;
if (ecoResdatetimeValue_ForValidation.DateTimeValue != (_attributeValue))
throw error('An exception was raised - could not update the attribute value. (ProductAttributesCopy/setProductAttributeValue)');
}
}
}
}
void setProductAttributeDecimalValue(itemID _itemid, str _attributeName , AttributeValueFloat _attributeValue )
{
RefRecId itemRecID;
EcoResProduct product = EcoResProduct::find(InventTable::find(_itemId).Product);
EcoResProductCategory ecoResProductCategory;
EcoResCategory ecoResCategory;
EcoResCategoryAttributeLookup ecoResCategoryAttributeLookup;
EcoResAttribute ecoResAttribute;
EcoResAttributeValue ecoResAttributeValue;
EcoResProductInstanceValue ecoResProductInstanceValue;
EcoResTextValue ecoResTextValue, ecoResTextValue_ForUpdate, ecoResTextValue_ForValidation;
EcoResAttributeType EcoResAttributeType;
EcoResIntValue EcoResIntValue,ecoresIntValue_forupdate,ecoresIntValue_forValidation;
EcoResCurrencyValue ecoResCurrencyValue,ecoResCurrencyValue_forupdate,ecoResCurrencyValue_forvalidation;
EcoResDateTimeValue EcoResDateTimeValue,EcoResDateTimeValue_forupdate,EcoResDateTimeValue_forvalidation;
EcoResFloatValue EcoResFloatValue,EcoResFloatValue_forupdate,EcoResFloatValue_forvalidation;
EcoResBooleanValue EcoResBooleanValue,EcoResBooleanValue_forupdate,EcoResBooleanValue_forvalidation;
itemRecID = product.RecId;
//select EcoResProduct where EcoResProduct.DisplayProductNumber == _itemid;
while
select ecoResProductCategory where ecoResProductCategory.Product == itemRecID
join ecoResCategory where ecoResCategory.RecId == ecoResProductCategory.Category
{
while
select ecoResCategoryAttributeLookup where ecoResCategoryAttributeLookup.Category == ecoResCategory.RecId
join ecoResAttribute where ecoResAttribute.RecId == ecoResCategoryAttributeLookup.Attribute
{
select ecoResAttributeValue where ecoResAttributeValue.Attribute == ecoResAttribute.RecId
join ecoResProductInstanceValue where ecoResProductInstanceValue.RecId == ecoResAttributeValue.InstanceValue && ecoResProductInstanceValue.Product == itemRecID
join EcoResfloatValue where EcoResfloatValue.RecId == ecoResAttributeValue.Value;
if (strLwr(strLRTrim(ecoResAttribute.Name)) == strLwr(strLRTrim(_attributeName)))
{
ttsBegin;
while select forUpdate ecoResfloatValue_ForUpdate
where ecoResfloatValue_ForUpdate.RecId == ecoResfloatValue.RecId
{
ecoResfloatValue_ForUpdate.FloatValue = any2real(_attributeValue);
ecoResfloatValue_ForUpdate.update();
}
ttsCommit;
select ecoResfloatValue_ForValidation where ecoResfloatValue_ForValidation.RecId == ecoResfloatValue.RecId;
if (ecoResfloatValue_ForValidation.FloatValue != any2real(_attributeValue))
throw error('An exception was raised - could not update the attribute value. (ProductAttributesCopy/setProductAttributeValue)');
}
}
}
}
void setProductAttributeIntegerValue(itemID _itemid, str _attributeName , str 1999 _attributeValue )
{
RefRecId itemRecID;
EcoResProduct product = EcoResProduct::find(InventTable::find(_itemId).Product);
EcoResProductCategory ecoResProductCategory;
EcoResCategory ecoResCategory;
EcoResCategoryAttributeLookup ecoResCategoryAttributeLookup;
EcoResAttribute ecoResAttribute;
EcoResAttributeValue ecoResAttributeValue;
EcoResProductInstanceValue ecoResProductInstanceValue;
EcoResTextValue ecoResTextValue, ecoResTextValue_ForUpdate, ecoResTextValue_ForValidation;
EcoResAttributeType EcoResAttributeType;
EcoResIntValue EcoResIntValue,ecoresIntValue_forupdate,ecoresIntValue_forValidation;
EcoResCurrencyValue ecoResCurrencyValue,ecoResCurrencyValue_forupdate,ecoResCurrencyValue_forvalidation;
EcoResDateTimeValue EcoResDateTimeValue,EcoResDateTimeValue_forupdate,EcoResDateTimeValue_forvalidation;
EcoResFloatValue EcoResFloatValue,EcoResFloatValue_forupdate,EcoResFloatValue_forvalidation;
EcoResBooleanValue EcoResBooleanValue,EcoResBooleanValue_forupdate,EcoResBooleanValue_forvalidation;
itemRecID = product.RecId;
//select EcoResProduct where EcoResProduct.DisplayProductNumber == _itemid;
while
select ecoResProductCategory where ecoResProductCategory.Product == itemRecID
join ecoResCategory where ecoResCategory.RecId == ecoResProductCategory.Category
{
while
select ecoResCategoryAttributeLookup where ecoResCategoryAttributeLookup.Category == ecoResCategory.RecId
join ecoResAttribute where ecoResAttribute.RecId == ecoResCategoryAttributeLookup.Attribute
{
select EcoResAttributeType where EcoResAttributeType.RecId == ecoResAttribute.AttributeType;
select ecoResAttributeValue where ecoResAttributeValue.Attribute == ecoResAttribute.RecId
join ecoResProductInstanceValue where ecoResProductInstanceValue.RecId == ecoResAttributeValue.InstanceValue && ecoResProductInstanceValue.Product == itemRecID
join EcoResIntValue where EcoResIntValue.RecId == ecoResAttributeValue.Value;
if (strLwr(strLRTrim(ecoResAttribute.Name)) == strLwr(strLRTrim(_attributeName)))
{
ttsBegin;
while select forUpdate ecoResintValue_ForUpdate
where ecoResIntValue_ForUpdate.RecId == ecoResIntValue.RecId
{
ecoResIntValue_ForUpdate.intValue = any2int(_attributeValue);
ecoResIntValue_ForUpdate.update();
}
ttsCommit;
select ecoResIntValue_ForValidation where ecoResIntValue_ForValidation.RecId == ecoResIntValue.RecId;
if (ecoResIntValue_ForValidation.IntValue != any2int(_attributeValue))
throw error('An exception was raised - could not update the attribute value. (ProductAttributesCopy/setProductAttributeValue)');
}
}
}
}
void setProductAttributeTextValue(itemID _itemid, str _attributeName , str 1999 _attributeValue )
{
RefRecId itemRecID;
EcoResProduct product = EcoResProduct::find(InventTable::find(_itemId).Product);
EcoResProductCategory ecoResProductCategory;
EcoResCategory ecoResCategory;
EcoResCategoryAttributeLookup ecoResCategoryAttributeLookup;
EcoResAttribute ecoResAttribute;
EcoResAttributeValue ecoResAttributeValue;
EcoResProductInstanceValue ecoResProductInstanceValue;
EcoResTextValue ecoResTextValue, ecoResTextValue_ForUpdate, ecoResTextValue_ForValidation;
EcoResAttributeType EcoResAttributeType;
EcoResIntValue EcoResIntValue,ecoresIntValue_forupdate,ecoresIntValue_forValidation;
EcoResCurrencyValue ecoResCurrencyValue,ecoResCurrencyValue_forupdate,ecoResCurrencyValue_forvalidation;
EcoResDateTimeValue EcoResDateTimeValue,EcoResDateTimeValue_forupdate,EcoResDateTimeValue_forvalidation;
EcoResFloatValue EcoResFloatValue,EcoResFloatValue_forupdate,EcoResFloatValue_forvalidation;
EcoResBooleanValue EcoResBooleanValue,EcoResBooleanValue_forupdate,EcoResBooleanValue_forvalidation;
itemRecID = product.RecId;
//select EcoResProduct where EcoResProduct.DisplayProductNumber == _itemid;
while
select ecoResProductCategory where ecoResProductCategory.Product == itemRecID
join ecoResCategory where ecoResCategory.RecId == ecoResProductCategory.Category
{
while
select ecoResCategoryAttributeLookup where ecoResCategoryAttributeLookup.Category == ecoResCategory.RecId
join ecoResAttribute where ecoResAttribute.RecId == ecoResCategoryAttributeLookup.Attribute
{
select ecoResAttributeValue where ecoResAttributeValue.Attribute == ecoResAttribute.RecId
join ecoResProductInstanceValue where ecoResProductInstanceValue.RecId == ecoResAttributeValue.InstanceValue && ecoResProductInstanceValue.Product == itemRecID
join EcoRestextValue where EcoRestextValue.RecId == ecoResAttributeValue.Value;
if (strLwr(strLRTrim(ecoResAttribute.Name)) == strLwr(strLRTrim(_attributeName)))
{
ttsBegin;
while select forUpdate ecoRestextValue_ForUpdate
where ecoRestextValue_ForUpdate.RecId == ecoRestextValue.RecId
{
ecoRestextValue_ForUpdate.textValue = (_attributeValue);
ecoRestextValue_ForUpdate.update();
}
ttsCommit;
select ecoRestextValue_ForValidation where ecoRestextValue_ForValidation.RecId == ecoRestextValue.RecId;
if (ecoRestextValue_ForValidation.textValue != (_attributeValue))
throw error('An exception was raised - could not update the attribute value. (ProductAttributesCopy/setProductAttributeValue)');
}
}
}
}
void setProductAttributeTrueFalseValue(itemID _itemid, str _attributeName , Attributevalueboolean _attributeValue )
{
RefRecId itemRecID;
EcoResProduct product = EcoResProduct::find(InventTable::find(_itemId).Product);
EcoResProductCategory ecoResProductCategory;
EcoResCategory ecoResCategory;
EcoResCategoryAttributeLookup ecoResCategoryAttributeLookup;
EcoResAttribute ecoResAttribute;
EcoResAttributeValue ecoResAttributeValue;
EcoResProductInstanceValue ecoResProductInstanceValue;
EcoResTextValue ecoResTextValue, ecoResTextValue_ForUpdate, ecoResTextValue_ForValidation;
EcoResAttributeType EcoResAttributeType;
EcoResIntValue EcoResIntValue,ecoresIntValue_forupdate,ecoresIntValue_forValidation;
EcoResCurrencyValue ecoResCurrencyValue,ecoResCurrencyValue_forupdate,ecoResCurrencyValue_forvalidation;
EcoResDateTimeValue EcoResDateTimeValue,EcoResDateTimeValue_forupdate,EcoResDateTimeValue_forvalidation;
EcoResFloatValue EcoResFloatValue,EcoResFloatValue_forupdate,EcoResFloatValue_forvalidation;
EcoResBooleanValue EcoResBooleanValue,EcoResBooleanValue_forupdate,EcoResBooleanValue_forvalidation;
itemRecID = product.RecId;
//select EcoResProduct where EcoResProduct.DisplayProductNumber == _itemid;
while
select ecoResProductCategory where ecoResProductCategory.Product == itemRecID
join ecoResCategory where ecoResCategory.RecId == ecoResProductCategory.Category
{
while
select ecoResCategoryAttributeLookup where ecoResCategoryAttributeLookup.Category == ecoResCategory.RecId
join ecoResAttribute where ecoResAttribute.RecId == ecoResCategoryAttributeLookup.Attribute
{
select ecoResAttributeValue where ecoResAttributeValue.Attribute == ecoResAttribute.RecId
join ecoResProductInstanceValue where ecoResProductInstanceValue.RecId == ecoResAttributeValue.InstanceValue && ecoResProductInstanceValue.Product == itemRecID
join EcoResbooleanValue where EcoResbooleanValue.RecId == ecoResAttributeValue.Value;
if (strLwr(strLRTrim(ecoResAttribute.Name)) == strLwr(strLRTrim(_attributeName)))
{
ttsBegin;
while select forUpdate EcoResbooleanValue_ForUpdate
where EcoResbooleanValue_ForUpdate.RecId == EcoResbooleanValue_ForUpdate.RecId
{
EcoResbooleanValue_ForUpdate.BooleanValue = (_attributeValue);
EcoResbooleanValue_ForUpdate.update();
}
ttsCommit;
select EcoResbooleanValue_ForValidation where EcoResbooleanValue_ForValidation.RecId == ecoResbooleanValue.RecId;
if (EcoResbooleanValue_ForValidation.BooleanValue != (_attributeValue))
throw error('An exception was raised - could not update the attribute value. (ProductAttributesCopy/setProductAttributeValue)');
}
}
}
}
Hi
ReplyDeleteThank you very much ..it working fine....