static void ProductMastersXppImport(Args _args)
{
EcoResProductMaster ecoResProductMaster,ecoResProductMasterLoc;
EcoResProductIdentifier ecoResProductIdentifier;
EcoResProductDimensionGroupProduct ecoResProductDimensionGroupProduct;
EcoResProductMasterModelingPolicy ecoResProductMasterModelingPolicy;
EcoResStorageDimensionGroupProduct ecoResStorageDimensionGroupProduct;
EcoResTrackingDimensionGroupProduct ecoResTrackingDimensionGroupProduct;
EcoResConfiguration ecoResConfiguration;
EcoResProductMasterConfiguration ecoResProductMasterConfiguration;
EcoResDistinctProductVariant ecoResDistinctProductVariant;
EcoResProductVariantConfiguration ecoResProductVariantConfiguration;
InventTable inventTable;
InventTableModule inventTableModule;
InventItemSetupSupplyType inventItemSetupSupplyType;
EcoResStorageDimensionGroupItem ecoResStorageDimensionGroupItem;
EcoResTrackingDimensionGroupItem ecoResTrackingDimensionGroupItem;
InventModelGroupItem inventModelGroupItem;
InventItemGroupItem inventItemGroupItem;
InventDim inventDim;
InventDimCombination inventDimCombination;
//New
EcoResColor ecoResColor;
EcoResProductMasterColor ecoResProductMasterColor;
EcoResStyle ecoResStyle;
EcoResProductMasterStyle ecoResProductMasterStyle;
EcoResProductVariantColor ecoResProductVariantColor;
EcoResProductVariantStyle ecoResProductVariantStyle;
EcoResProduct ecoResProduct;
LTItemMasterImport ltItemMasterImport;
while select ltItemMasterImport
where ltItemMasterImport.LTItemIntegrationId == 'IMP002'
{ //1
try
{ //2
//ProductMaster
ecoResProductMaster.clear();
ecoResProductMaster.initValue();
ecoResProductMaster.ProductType = EcoResProductType::Item;
ecoResProductMaster.DisplayProductNumber = ltItemMasterImport.ItemId;//"AlexMaster";
ecoResProductMaster.SearchName = ltItemMasterImport.ItemName;//"AlexMaster";
ecoResProductMaster.VariantConfigurationTechnology = EcoResVariantConfigurationTechnologyType::PredefinedVariants;
select ecoResProductMasterLoc
where ecoResProductMasterLoc.DisplayProductNumber == ltItemMasterImport.ItemId;
if (!ecoResProductMasterLoc.RecId && ecoResProductMaster.validateWrite())
{ //3
ecoResProductMaster.insert();
//////////////
select forUpdate ecoResProduct
where ecoResProduct.RecId == ecoResProductMaster.RecId;
if (ecoResProduct.RecId)
{
ecoResProduct.TEC_InventType = ltItemMasterImport.TEC_InventType;
ecoResProduct.TEC_FamilyId = ltItemMasterImport.TEC_FamilyId;
ecoResProduct.TEC_SubFamilyID = ltItemMasterImport.TEC_SubFamilyID;
ecoResProduct.TEC_ItemVocation = ltItemMasterImport.TEC_ItemVocation;
ecoResProduct.TEC_DualColorItem = ltItemMasterImport.TEC_DualColorItem;
ecoResProduct.Tec_Proforma = ltItemMasterImport.Tec_Proforma;
ecoResProduct.TEC_Conceptor = ltItemMasterImport.TEC_Conceptor;
ecoResProduct.TEC_DiscountItem = ltItemMasterImport.TEC_DiscountItem;
ecoResProduct.Tec_MinOrderWeight = ltItemMasterImport.Tec_MinOrderWeight;
ecoResProduct.Tec_MetalNonMetal = ltItemMasterImport.Tec_MetalNonMetal;
//ecoResProduct.StandardConfigId = ltItemMasterImport.StandardConfigId;
//ecoResProduct.StandardInventStyleId = ltItemMasterImport.StandardInventStyleId;
ecoResProduct.TEC_PurchCalcUnit = ltItemMasterImport.TEC_PurchCalcUnit;
ecoResProduct.TEC_SalesCalcUnit = ltItemMasterImport.TEC_SalesCalcUnit;
ecoResProduct.TEC_PurchCalcUnit_TMB = ltItemMasterImport.TEC_PurchCalcUnit_TMB;
ecoResProduct.TEC_ItemType = ltItemMasterImport.TEC_ItemType;
ecoResProduct.Tec_ProductType = ltItemMasterImport.Tec_ProductType;
ecoResProduct.doUpdate();
//EcoResStorageDimensionGroupName
}
/////////////
ecoResProductIdentifier.clear();
ecoResProductIdentifier.initValue();
ecoResProductIdentifier.ProductNumber = ltItemMasterImport.ItemId;//"AlexMaster";
ecoResProductIdentifier.Product = ecoResProductMaster.RecId;
ecoResProductIdentifier.insert();
//Product dimension group
ecoResProductDimensionGroupProduct.clear();
ecoResProductDimensionGroupProduct.initValue();
ecoResProductDimensionGroupProduct.initFromProduct(ecoResProductMaster);
ecoResProductDimensionGroupProduct.ProductDimensionGroup = EcoResProductDimensionGroup::findByDimensionGroupName(ltItemMasterImport.EcoResProductDimensionGroupName).RecId; //new
if (ecoResProductDimensionGroupProduct.validateWrite())
{
ecoResProductDimensionGroupProduct.insert();
}
//Storage dimension group
ecoResStorageDimensionGroupProduct.clear();
ecoResStorageDimensionGroupProduct.initValue();
ecoResStorageDimensionGroupProduct.Product = ecoResProductMaster.RecId;
ecoResStorageDimensionGroupProduct.StorageDimensionGroup = EcoResStorageDimensionGroup::findByDimensionGroupName(ltItemMasterImport.EcoResStorageDimensionGroupName).RecId;
if (ecoResStorageDimensionGroupProduct.validateWrite())
{
ecoResStorageDimensionGroupProduct.insert();
}
//Tracking dimension group
ecoResTrackingDimensionGroupProduct.clear();
ecoResTrackingDimensionGroupProduct.initValue();
ecoResTrackingDimensionGroupProduct.Product = ecoResProductMaster.RecId;
ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup = EcoResTrackingDimensionGroup::findByDimensionGroupName(ltItemMasterImport.EcoResTrackingDimensionGroupName).RecId;
if (ecoResTrackingDimensionGroupProduct.validateWrite())
{
ecoResTrackingDimensionGroupProduct.insert();
}
//Product modeling policy
ecoResProductMasterModelingPolicy.clear();
ecoResProductMasterModelingPolicy.initValue();
ecoResProductMasterModelingPolicy.ProductMaster = ecoResProductMaster.RecId;
if (ecoResProductMasterModelingPolicy.validateWrite())
{
ecoResProductMasterModelingPolicy.insert();
}
//Product translation
EcoResProductTranslation::createOrUpdateTranslation(ecoResProductMaster.RecId, ltItemMasterImport.ItemId, ltItemMasterImport.ItemId); //New
}//3
//else
//{//3
//Configuration
if (!ecoResProductMaster.RecId)
{
select ecoResProductMaster
where ecoResProductMaster.DisplayProductNumber == ltItemMasterImport.ItemId;
}
if (ltItemMasterImport.LTEcoResConfigurationName)
{
ecoResConfiguration = EcoResConfiguration::findByName(ltItemMasterImport.LTEcoResConfigurationName); //"Alex-1"); new
if (!ecoResConfiguration)
{
ecoResConfiguration.clear();
ecoResConfiguration.initValue();
ecoResConfiguration.Name = ltItemMasterImport.LTEcoResConfigurationName; // "Alex-1"; new
ecoResConfiguration.insert();
}
//Configuration assigned to product master
ecoResProductMasterConfiguration = EcoResProductMasterConfiguration::find(ecoResProductMaster.RecId,
ecoResConfiguration.RecId);
if (!ecoResProductMasterConfiguration.RecId)
{
ecoResProductMasterConfiguration.clear();
ecoResProductMasterConfiguration.initValue();
ecoResProductMasterConfiguration.Configuration = ecoResConfiguration.RecId;
ecoResProductMasterConfiguration.Description = ltItemMasterImport.LTEcoResConfigurationName; //"Alex-1"; new
ecoResProductMasterConfiguration.ConfigProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, ConfigId));
ecoResProductMasterConfiguration.ConfigProductMaster = ecoResProductMaster.RecId;
ecoResProductMasterConfiguration.insert();
}
}
//new dim starts
//Color
if (ltItemMasterImport.LTEcoResColorName)
{
ecoResColor = EcoResColor::findByName(ltItemMasterImport.LTEcoResColorName);
if (!ecoResColor)
{
ecoResColor.clear();
ecoResColor.initValue();
ecoResColor.Name = ltItemMasterImport.LTEcoResColorName;
ecoResColor.insert();
}
//Color assigned to product master
select firstOnly ecoResProductMasterColor
where ecoResProductMasterColor.ColorProductMaster == ecoResProductMaster.RecId &&
ecoResProductMasterColor.Color == ecoResColor.RecId;
if (!ecoResProductMasterColor.RecId)
{
ecoResProductMasterColor.clear();
ecoResProductMasterColor.initValue();
ecoResProductMasterColor.Color = ecoResColor.RecId;
ecoResProductMasterColor.Description = ltItemMasterImport.LTEcoResColorName;
ecoResProductMasterColor.ColorProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventColorId));
ecoResProductMasterColor.ColorProductMaster = ecoResProductMaster.RecId;
ecoResProductMasterColor.insert();
}
}
//Style
if (ltItemMasterImport.LTEcoResStyleName)
{
ecoResStyle = EcoResStyle::findByName(ltItemMasterImport.LTEcoResStyleName);
if (!ecoResStyle)
{
ecoResStyle.clear();
ecoResStyle.initValue();
ecoResStyle.Name = ltItemMasterImport.LTEcoResStyleName;
ecoResStyle.insert();
}
//Color assigned to product master
select firstOnly ecoResProductMasterStyle
where ecoResProductMasterStyle.StyleProductMaster == ecoResProductMaster.RecId &&
ecoResProductMasterStyle.Style == ecoResStyle.RecId;
if (!ecoResProductMasterStyle.RecId)
{
ecoResProductMasterStyle.clear();
ecoResProductMasterStyle.initValue();
ecoResProductMasterStyle.Style = ecoResStyle.RecId;
ecoResProductMasterStyle.Description = ltItemMasterImport.LTEcoResStyleName;
ecoResProductMasterStyle.StyleProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventStyleId));
ecoResProductMasterStyle.StyleProductMaster = ecoResProductMaster.RecId;
ecoResProductMasterStyle.insert();
}
}
//new dim ends
//Product variant
ecoResDistinctProductVariant.clear();
ecoResDistinctProductVariant.initValue();
ecoResDistinctProductVariant.DisplayProductNumber =
EcoResProductNumberBuilderVariant::buildFromProductNumberAndDimensions(
ltItemMasterImport.ItemId,
//ecoResProductMaster.productNumber(),
EcoResProductVariantDimValue::getDimensionValuesContainer(ltItemMasterImport.LTEcoResConfigurationName, "", ltItemMasterImport.LTEcoResColorName, ltItemMasterImport.LTEcoResStyleName)); //ltItemMasterImport.LTEcoResColorName, ltItemMasterImport.LTEcoResStyleName)); //("Alex-1", "", "")); new
if (!ecoResProductMaster.RecId)
{
select ecoResProductMaster
where ecoResProductMaster.DisplayProductNumber == ltItemMasterImport.ItemId;
}
ecoResDistinctProductVariant.SearchName = ecoResProductMaster.SearchName +
ltItemMasterImport.LTEcoResConfigurationName +
ltItemMasterImport.LTEcoResColorName +
ltItemMasterImport.LTEcoResStyleName; //"Alex-1"/*ConfigId*/; new
ecoResDistinctProductVariant.ProductType = ecoResProductMaster.ProductType;
ecoResDistinctProductVariant.ProductMaster = ecoResProductMaster.RecId;
select forUpdate ecoResProduct
where ecoResProduct.RecId == ecoResProductMaster.RecId;
if (ecoResProduct.RecId)
{
ecoResDistinctProductVariant.TEC_InventType = ecoResProduct.TEC_InventType;
ecoResDistinctProductVariant.TEC_FamilyId = ecoResProduct.TEC_FamilyId;
ecoResDistinctProductVariant.TEC_SubFamilyID = ecoResProduct.TEC_SubFamilyID;
ecoResDistinctProductVariant.TEC_ItemVocation = ecoResProduct.TEC_ItemVocation;
ecoResDistinctProductVariant.TEC_DualColorItem = ecoResProduct.TEC_DualColorItem;
ecoResDistinctProductVariant.Tec_Proforma = ecoResProduct.Tec_Proforma;
ecoResDistinctProductVariant.TEC_Conceptor = ecoResProduct.TEC_Conceptor;
ecoResDistinctProductVariant.TEC_DiscountItem = ecoResProduct.TEC_DiscountItem;
ecoResDistinctProductVariant.Tec_MinOrderWeight = ecoResProduct.Tec_MinOrderWeight;
ecoResDistinctProductVariant.Tec_MetalNonMetal = ecoResProduct.Tec_MetalNonMetal;
//ecoResProduct.StandardConfigId = masterImport.StandardConfigId;
//ecoResProduct.StandardInventStyleId = masterImport.StandardInventStyleId;
ecoResDistinctProductVariant.TEC_PurchCalcUnit = ecoResProduct.TEC_PurchCalcUnit;
ecoResDistinctProductVariant.TEC_SalesCalcUnit = ecoResProduct.TEC_SalesCalcUnit;
ecoResDistinctProductVariant.TEC_PurchCalcUnit_TMB = ecoResProduct.TEC_PurchCalcUnit_TMB;
ecoResDistinctProductVariant.TEC_ItemType = ecoResProduct.TEC_ItemType;
ecoResDistinctProductVariant.Tec_ProductType = ecoResProduct.Tec_ProductType;
//ecoResProduct.doUpdate();
//EcoResStorageDimensionGroupName
}
ecoResDistinctProductVariant.insert();
//Product variant configuration
if (ecoResConfiguration.RecId)
{
ecoResProductVariantConfiguration.clear();
ecoResProductVariantConfiguration.initValue();
ecoResProductVariantConfiguration.initFromDistinctProductVariant(ecoResDistinctProductVariant);
ecoResProductVariantConfiguration.ProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, ConfigId));
ecoResProductVariantConfiguration.Configuration = ecoResConfiguration.RecId;
ecoResProductVariantConfiguration.insert();
}
//Product Variant color
if (ecoResColor.RecId)
{
ecoResProductVariantColor.clear();
ecoResProductVariantColor.initValue();
ecoResProductVariantColor.initFromDistinctProductVariant(ecoResDistinctProductVariant);
ecoResProductVariantColor.ProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventColorId));
ecoResProductVariantColor.Color = ecoResColor.RecId;
ecoResProductVariantColor.insert();
}
//Product Variant Style
if (ecoResStyle.RecId)
{
ecoResProductVariantStyle.clear();
ecoResProductVariantStyle.initValue();
ecoResProductVariantStyle.initFromDistinctProductVariant(ecoResDistinctProductVariant);
ecoResProductVariantStyle.ProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventStyleId));
ecoResProductVariantStyle.Style = ecoResStyle.RecId;
ecoResProductVariantStyle.insert();
}
//Product variant translation
EcoResProductTranslation::createOrUpdateTranslation(ecoResDistinctProductVariant.RecId, ltItemMasterImport.ItemId, ltItemMasterImport.ItemId); //"AlexMaster", "AlexMaster"); new
//Released product
inventTable = InventTable::find(ltItemMasterImport.ItemId);
if (!inventTable.RecId)
{
inventTable.clear();
inventTable.initValue();
//new st
select forUpdate ecoResProduct
where ecoResProduct.RecId == ecoResProductMaster.RecId;
//new en
inventTable.initFromEcoResProduct(ecoResProduct);
inventTable.ItemId = ltItemMasterImport.ItemId; //"AlexMaster"; new
inventTable.NameAlias = ltItemMasterImport.ItemName; //"AlexMaster"; new
if (ecoResProduct.RecId)
{
inventTable.TEC_InventType = ecoResProduct.TEC_InventType;
inventTable.TEC_FamilyId = ecoResProduct.TEC_FamilyId;
inventTable.TEC_SubFamilyID = ecoResProduct.TEC_SubFamilyID;
inventTable.TEC_ItemVocation = ecoResProduct.TEC_ItemVocation;
inventTable.TEC_DualColorItem = ecoResProduct.TEC_DualColorItem;
inventTable.Tec_Proforma = ecoResProduct.Tec_Proforma;
inventTable.TEC_Conceptor = ecoResProduct.TEC_Conceptor;
inventTable.TEC_DiscountItem = ecoResProduct.TEC_DiscountItem;
inventTable.Tec_MinOrderWeight = ecoResProduct.Tec_MinOrderWeight;
inventTable.Tec_MetalNonMetal = ecoResProduct.Tec_MetalNonMetal;
//inventTable.StandardConfigId = ltItemMasterImport.StandardConfigId;
//inventTable.StandardInventStyleId = ltItemMasterImport.StandardInventStyleId;
inventTable.TEC_PurchCalcUnit = ecoResProduct.TEC_PurchCalcUnit;
inventTable.TEC_SalesCalcUnit = ecoResProduct.TEC_SalesCalcUnit;
inventTable.TEC_PurchCalcUnit_TMB = ecoResProduct.TEC_PurchCalcUnit_TMB;
inventTable.TEC_ItemType = ecoResProduct.TEC_ItemType;
inventTable.Tec_ProductType = ecoResProduct.Tec_ProductType;
inventTable.TaxPackagingQty = ltItemMasterImport.TaxPackagingQty;
inventTable.NetWeight = ltItemMasterImport.NetWeight;
//ecoResProduct.doUpdate();
//EcoResStorageDimensionGroupName
}
if (inventTable.validateWrite())
{
inventTable.insert();
//Inventory model group
inventModelGroupItem.clear();
inventModelGroupItem.initValue();
inventModelGroupItem.ItemDataAreaId = inventTable.dataAreaId;
inventModelGroupItem.ItemId = inventTable.ItemId;
inventModelGroupItem.ModelGroupId = ltItemMasterImport.InventModelGroupId; //"FIFO"; new
inventModelGroupItem.ModelGroupDataAreaId = curext();
inventModelGroupItem.insert();
//Item group
inventItemGroupItem.clear();
inventItemGroupItem.initValue();
inventItemGroupItem.ItemDataAreaId = inventTable.dataAreaId;
inventItemGroupItem.ItemId = inventTable.ItemId;
inventItemGroupItem.ItemGroupId = ltItemMasterImport.ItemGroupId; //"Parts"; new
inventItemGroupItem.ItemGroupDataAreaId = curext();
inventItemGroupItem.insert();
//Extended product details - Inventory
inventTableModule.clear();
inventTableModule.initValue();
inventTableModule.ItemId = inventTable.ItemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Invent;
inventTableModule.insert();
//Extended product details - Purchase
inventTableModule.clear();
inventTableModule.initValue();
inventTableModule.ItemId = inventTable.ItemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Purch;
inventTableModule.insert();
//Extended product details - Sales
inventTableModule.clear();
inventTableModule.initValue();
inventTableModule.ItemId = inventTable.ItemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Sales;
inventTableModule.insert();
//Warehouse items
InventItemLocation::createDefault(inventTable.ItemId);
//Supply type setup
inventItemSetupSupplyType.clear();
inventItemSetupSupplyType.initValue();
inventItemSetupSupplyType.ItemId = inventTable.ItemId;
inventItemSetupSupplyType.ItemDataAreaId = inventTable.DataAreaId;
inventItemSetupSupplyType.insert();
//Product storage dimension group
ecoResStorageDimensionGroupProduct = EcoResStorageDimensionGroupProduct::findByProduct(ecoResProductMaster.RecId);
if (ecoResStorageDimensionGroupProduct.RecId)
{
ecoResStorageDimensionGroupItem.clear();
ecoResStorageDimensionGroupItem.initValue();
ecoResStorageDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
ecoResStorageDimensionGroupItem.ItemId = inventTable.ItemId;
ecoResStorageDimensionGroupItem.StorageDimensionGroup = ecoResStorageDimensionGroupProduct.StorageDimensionGroup;
ecoResStorageDimensionGroupItem.insert();
}
//Product tracking dimension group
ecoResTrackingDimensionGroupProduct = EcoResTrackingDimensionGroupProduct::findByProduct(ecoResProductMaster.RecId);
if (ecoResTrackingDimensionGroupProduct.RecId)
{
ecoResTrackingDimensionGroupItem.clear();
ecoResTrackingDimensionGroupItem.initValue();
ecoResTrackingDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
ecoResTrackingDimensionGroupItem.ItemId = inventTable.ItemId;
ecoResTrackingDimensionGroupItem.TrackingDimensionGroup = ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup;
ecoResTrackingDimensionGroupItem.insert();
}
}
}
inventDim.clear();
inventDim.ConfigId = ltItemMasterImport.LTEcoResConfigurationName;
inventDim.InventColorId = ltItemMasterImport.LTEcoResColorName;
inventDim.InventStyleId = ltItemMasterImport.LTEcoResStyleName;
inventDim = InventDim::findOrCreate(inventDim);
//Released product variant
inventDimCombination.clear();
inventDimCombination.initValue();
inventDimCombination.DistinctProductVariant = ecoResDistinctProductVariant.RecId;
inventDimCombination.ItemId = inventTable.ItemId;
inventDimCombination.InventDimId = inventDim.InventDimId;
inventDimCombination.insert();
//}
}
catch
{
error("Error!");
return;
}
}
info("Done!");
}
{
EcoResProductMaster ecoResProductMaster,ecoResProductMasterLoc;
EcoResProductIdentifier ecoResProductIdentifier;
EcoResProductDimensionGroupProduct ecoResProductDimensionGroupProduct;
EcoResProductMasterModelingPolicy ecoResProductMasterModelingPolicy;
EcoResStorageDimensionGroupProduct ecoResStorageDimensionGroupProduct;
EcoResTrackingDimensionGroupProduct ecoResTrackingDimensionGroupProduct;
EcoResConfiguration ecoResConfiguration;
EcoResProductMasterConfiguration ecoResProductMasterConfiguration;
EcoResDistinctProductVariant ecoResDistinctProductVariant;
EcoResProductVariantConfiguration ecoResProductVariantConfiguration;
InventTable inventTable;
InventTableModule inventTableModule;
InventItemSetupSupplyType inventItemSetupSupplyType;
EcoResStorageDimensionGroupItem ecoResStorageDimensionGroupItem;
EcoResTrackingDimensionGroupItem ecoResTrackingDimensionGroupItem;
InventModelGroupItem inventModelGroupItem;
InventItemGroupItem inventItemGroupItem;
InventDim inventDim;
InventDimCombination inventDimCombination;
//New
EcoResColor ecoResColor;
EcoResProductMasterColor ecoResProductMasterColor;
EcoResStyle ecoResStyle;
EcoResProductMasterStyle ecoResProductMasterStyle;
EcoResProductVariantColor ecoResProductVariantColor;
EcoResProductVariantStyle ecoResProductVariantStyle;
EcoResProduct ecoResProduct;
LTItemMasterImport ltItemMasterImport;
while select ltItemMasterImport
where ltItemMasterImport.LTItemIntegrationId == 'IMP002'
{ //1
try
{ //2
//ProductMaster
ecoResProductMaster.clear();
ecoResProductMaster.initValue();
ecoResProductMaster.ProductType = EcoResProductType::Item;
ecoResProductMaster.DisplayProductNumber = ltItemMasterImport.ItemId;//"AlexMaster";
ecoResProductMaster.SearchName = ltItemMasterImport.ItemName;//"AlexMaster";
ecoResProductMaster.VariantConfigurationTechnology = EcoResVariantConfigurationTechnologyType::PredefinedVariants;
select ecoResProductMasterLoc
where ecoResProductMasterLoc.DisplayProductNumber == ltItemMasterImport.ItemId;
if (!ecoResProductMasterLoc.RecId && ecoResProductMaster.validateWrite())
{ //3
ecoResProductMaster.insert();
//////////////
select forUpdate ecoResProduct
where ecoResProduct.RecId == ecoResProductMaster.RecId;
if (ecoResProduct.RecId)
{
ecoResProduct.TEC_InventType = ltItemMasterImport.TEC_InventType;
ecoResProduct.TEC_FamilyId = ltItemMasterImport.TEC_FamilyId;
ecoResProduct.TEC_SubFamilyID = ltItemMasterImport.TEC_SubFamilyID;
ecoResProduct.TEC_ItemVocation = ltItemMasterImport.TEC_ItemVocation;
ecoResProduct.TEC_DualColorItem = ltItemMasterImport.TEC_DualColorItem;
ecoResProduct.Tec_Proforma = ltItemMasterImport.Tec_Proforma;
ecoResProduct.TEC_Conceptor = ltItemMasterImport.TEC_Conceptor;
ecoResProduct.TEC_DiscountItem = ltItemMasterImport.TEC_DiscountItem;
ecoResProduct.Tec_MinOrderWeight = ltItemMasterImport.Tec_MinOrderWeight;
ecoResProduct.Tec_MetalNonMetal = ltItemMasterImport.Tec_MetalNonMetal;
//ecoResProduct.StandardConfigId = ltItemMasterImport.StandardConfigId;
//ecoResProduct.StandardInventStyleId = ltItemMasterImport.StandardInventStyleId;
ecoResProduct.TEC_PurchCalcUnit = ltItemMasterImport.TEC_PurchCalcUnit;
ecoResProduct.TEC_SalesCalcUnit = ltItemMasterImport.TEC_SalesCalcUnit;
ecoResProduct.TEC_PurchCalcUnit_TMB = ltItemMasterImport.TEC_PurchCalcUnit_TMB;
ecoResProduct.TEC_ItemType = ltItemMasterImport.TEC_ItemType;
ecoResProduct.Tec_ProductType = ltItemMasterImport.Tec_ProductType;
ecoResProduct.doUpdate();
//EcoResStorageDimensionGroupName
}
/////////////
ecoResProductIdentifier.clear();
ecoResProductIdentifier.initValue();
ecoResProductIdentifier.ProductNumber = ltItemMasterImport.ItemId;//"AlexMaster";
ecoResProductIdentifier.Product = ecoResProductMaster.RecId;
ecoResProductIdentifier.insert();
//Product dimension group
ecoResProductDimensionGroupProduct.clear();
ecoResProductDimensionGroupProduct.initValue();
ecoResProductDimensionGroupProduct.initFromProduct(ecoResProductMaster);
ecoResProductDimensionGroupProduct.ProductDimensionGroup = EcoResProductDimensionGroup::findByDimensionGroupName(ltItemMasterImport.EcoResProductDimensionGroupName).RecId; //new
if (ecoResProductDimensionGroupProduct.validateWrite())
{
ecoResProductDimensionGroupProduct.insert();
}
//Storage dimension group
ecoResStorageDimensionGroupProduct.clear();
ecoResStorageDimensionGroupProduct.initValue();
ecoResStorageDimensionGroupProduct.Product = ecoResProductMaster.RecId;
ecoResStorageDimensionGroupProduct.StorageDimensionGroup = EcoResStorageDimensionGroup::findByDimensionGroupName(ltItemMasterImport.EcoResStorageDimensionGroupName).RecId;
if (ecoResStorageDimensionGroupProduct.validateWrite())
{
ecoResStorageDimensionGroupProduct.insert();
}
//Tracking dimension group
ecoResTrackingDimensionGroupProduct.clear();
ecoResTrackingDimensionGroupProduct.initValue();
ecoResTrackingDimensionGroupProduct.Product = ecoResProductMaster.RecId;
ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup = EcoResTrackingDimensionGroup::findByDimensionGroupName(ltItemMasterImport.EcoResTrackingDimensionGroupName).RecId;
if (ecoResTrackingDimensionGroupProduct.validateWrite())
{
ecoResTrackingDimensionGroupProduct.insert();
}
//Product modeling policy
ecoResProductMasterModelingPolicy.clear();
ecoResProductMasterModelingPolicy.initValue();
ecoResProductMasterModelingPolicy.ProductMaster = ecoResProductMaster.RecId;
if (ecoResProductMasterModelingPolicy.validateWrite())
{
ecoResProductMasterModelingPolicy.insert();
}
//Product translation
EcoResProductTranslation::createOrUpdateTranslation(ecoResProductMaster.RecId, ltItemMasterImport.ItemId, ltItemMasterImport.ItemId); //New
}//3
//else
//{//3
//Configuration
if (!ecoResProductMaster.RecId)
{
select ecoResProductMaster
where ecoResProductMaster.DisplayProductNumber == ltItemMasterImport.ItemId;
}
if (ltItemMasterImport.LTEcoResConfigurationName)
{
ecoResConfiguration = EcoResConfiguration::findByName(ltItemMasterImport.LTEcoResConfigurationName); //"Alex-1"); new
if (!ecoResConfiguration)
{
ecoResConfiguration.clear();
ecoResConfiguration.initValue();
ecoResConfiguration.Name = ltItemMasterImport.LTEcoResConfigurationName; // "Alex-1"; new
ecoResConfiguration.insert();
}
//Configuration assigned to product master
ecoResProductMasterConfiguration = EcoResProductMasterConfiguration::find(ecoResProductMaster.RecId,
ecoResConfiguration.RecId);
if (!ecoResProductMasterConfiguration.RecId)
{
ecoResProductMasterConfiguration.clear();
ecoResProductMasterConfiguration.initValue();
ecoResProductMasterConfiguration.Configuration = ecoResConfiguration.RecId;
ecoResProductMasterConfiguration.Description = ltItemMasterImport.LTEcoResConfigurationName; //"Alex-1"; new
ecoResProductMasterConfiguration.ConfigProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, ConfigId));
ecoResProductMasterConfiguration.ConfigProductMaster = ecoResProductMaster.RecId;
ecoResProductMasterConfiguration.insert();
}
}
//new dim starts
//Color
if (ltItemMasterImport.LTEcoResColorName)
{
ecoResColor = EcoResColor::findByName(ltItemMasterImport.LTEcoResColorName);
if (!ecoResColor)
{
ecoResColor.clear();
ecoResColor.initValue();
ecoResColor.Name = ltItemMasterImport.LTEcoResColorName;
ecoResColor.insert();
}
//Color assigned to product master
select firstOnly ecoResProductMasterColor
where ecoResProductMasterColor.ColorProductMaster == ecoResProductMaster.RecId &&
ecoResProductMasterColor.Color == ecoResColor.RecId;
if (!ecoResProductMasterColor.RecId)
{
ecoResProductMasterColor.clear();
ecoResProductMasterColor.initValue();
ecoResProductMasterColor.Color = ecoResColor.RecId;
ecoResProductMasterColor.Description = ltItemMasterImport.LTEcoResColorName;
ecoResProductMasterColor.ColorProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventColorId));
ecoResProductMasterColor.ColorProductMaster = ecoResProductMaster.RecId;
ecoResProductMasterColor.insert();
}
}
//Style
if (ltItemMasterImport.LTEcoResStyleName)
{
ecoResStyle = EcoResStyle::findByName(ltItemMasterImport.LTEcoResStyleName);
if (!ecoResStyle)
{
ecoResStyle.clear();
ecoResStyle.initValue();
ecoResStyle.Name = ltItemMasterImport.LTEcoResStyleName;
ecoResStyle.insert();
}
//Color assigned to product master
select firstOnly ecoResProductMasterStyle
where ecoResProductMasterStyle.StyleProductMaster == ecoResProductMaster.RecId &&
ecoResProductMasterStyle.Style == ecoResStyle.RecId;
if (!ecoResProductMasterStyle.RecId)
{
ecoResProductMasterStyle.clear();
ecoResProductMasterStyle.initValue();
ecoResProductMasterStyle.Style = ecoResStyle.RecId;
ecoResProductMasterStyle.Description = ltItemMasterImport.LTEcoResStyleName;
ecoResProductMasterStyle.StyleProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventStyleId));
ecoResProductMasterStyle.StyleProductMaster = ecoResProductMaster.RecId;
ecoResProductMasterStyle.insert();
}
}
//new dim ends
//Product variant
ecoResDistinctProductVariant.clear();
ecoResDistinctProductVariant.initValue();
ecoResDistinctProductVariant.DisplayProductNumber =
EcoResProductNumberBuilderVariant::buildFromProductNumberAndDimensions(
ltItemMasterImport.ItemId,
//ecoResProductMaster.productNumber(),
EcoResProductVariantDimValue::getDimensionValuesContainer(ltItemMasterImport.LTEcoResConfigurationName, "", ltItemMasterImport.LTEcoResColorName, ltItemMasterImport.LTEcoResStyleName)); //ltItemMasterImport.LTEcoResColorName, ltItemMasterImport.LTEcoResStyleName)); //("Alex-1", "", "")); new
if (!ecoResProductMaster.RecId)
{
select ecoResProductMaster
where ecoResProductMaster.DisplayProductNumber == ltItemMasterImport.ItemId;
}
ecoResDistinctProductVariant.SearchName = ecoResProductMaster.SearchName +
ltItemMasterImport.LTEcoResConfigurationName +
ltItemMasterImport.LTEcoResColorName +
ltItemMasterImport.LTEcoResStyleName; //"Alex-1"/*ConfigId*/; new
ecoResDistinctProductVariant.ProductType = ecoResProductMaster.ProductType;
ecoResDistinctProductVariant.ProductMaster = ecoResProductMaster.RecId;
select forUpdate ecoResProduct
where ecoResProduct.RecId == ecoResProductMaster.RecId;
if (ecoResProduct.RecId)
{
ecoResDistinctProductVariant.TEC_InventType = ecoResProduct.TEC_InventType;
ecoResDistinctProductVariant.TEC_FamilyId = ecoResProduct.TEC_FamilyId;
ecoResDistinctProductVariant.TEC_SubFamilyID = ecoResProduct.TEC_SubFamilyID;
ecoResDistinctProductVariant.TEC_ItemVocation = ecoResProduct.TEC_ItemVocation;
ecoResDistinctProductVariant.TEC_DualColorItem = ecoResProduct.TEC_DualColorItem;
ecoResDistinctProductVariant.Tec_Proforma = ecoResProduct.Tec_Proforma;
ecoResDistinctProductVariant.TEC_Conceptor = ecoResProduct.TEC_Conceptor;
ecoResDistinctProductVariant.TEC_DiscountItem = ecoResProduct.TEC_DiscountItem;
ecoResDistinctProductVariant.Tec_MinOrderWeight = ecoResProduct.Tec_MinOrderWeight;
ecoResDistinctProductVariant.Tec_MetalNonMetal = ecoResProduct.Tec_MetalNonMetal;
//ecoResProduct.StandardConfigId = masterImport.StandardConfigId;
//ecoResProduct.StandardInventStyleId = masterImport.StandardInventStyleId;
ecoResDistinctProductVariant.TEC_PurchCalcUnit = ecoResProduct.TEC_PurchCalcUnit;
ecoResDistinctProductVariant.TEC_SalesCalcUnit = ecoResProduct.TEC_SalesCalcUnit;
ecoResDistinctProductVariant.TEC_PurchCalcUnit_TMB = ecoResProduct.TEC_PurchCalcUnit_TMB;
ecoResDistinctProductVariant.TEC_ItemType = ecoResProduct.TEC_ItemType;
ecoResDistinctProductVariant.Tec_ProductType = ecoResProduct.Tec_ProductType;
//ecoResProduct.doUpdate();
//EcoResStorageDimensionGroupName
}
ecoResDistinctProductVariant.insert();
//Product variant configuration
if (ecoResConfiguration.RecId)
{
ecoResProductVariantConfiguration.clear();
ecoResProductVariantConfiguration.initValue();
ecoResProductVariantConfiguration.initFromDistinctProductVariant(ecoResDistinctProductVariant);
ecoResProductVariantConfiguration.ProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, ConfigId));
ecoResProductVariantConfiguration.Configuration = ecoResConfiguration.RecId;
ecoResProductVariantConfiguration.insert();
}
//Product Variant color
if (ecoResColor.RecId)
{
ecoResProductVariantColor.clear();
ecoResProductVariantColor.initValue();
ecoResProductVariantColor.initFromDistinctProductVariant(ecoResDistinctProductVariant);
ecoResProductVariantColor.ProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventColorId));
ecoResProductVariantColor.Color = ecoResColor.RecId;
ecoResProductVariantColor.insert();
}
//Product Variant Style
if (ecoResStyle.RecId)
{
ecoResProductVariantStyle.clear();
ecoResProductVariantStyle.initValue();
ecoResProductVariantStyle.initFromDistinctProductVariant(ecoResDistinctProductVariant);
ecoResProductVariantStyle.ProductDimensionAttribute = EcoResProductDimensionAttribute::inventDimFieldId2DimensionAttributeRecId(fieldNum(InventDim, InventStyleId));
ecoResProductVariantStyle.Style = ecoResStyle.RecId;
ecoResProductVariantStyle.insert();
}
//Product variant translation
EcoResProductTranslation::createOrUpdateTranslation(ecoResDistinctProductVariant.RecId, ltItemMasterImport.ItemId, ltItemMasterImport.ItemId); //"AlexMaster", "AlexMaster"); new
//Released product
inventTable = InventTable::find(ltItemMasterImport.ItemId);
if (!inventTable.RecId)
{
inventTable.clear();
inventTable.initValue();
//new st
select forUpdate ecoResProduct
where ecoResProduct.RecId == ecoResProductMaster.RecId;
//new en
inventTable.initFromEcoResProduct(ecoResProduct);
inventTable.ItemId = ltItemMasterImport.ItemId; //"AlexMaster"; new
inventTable.NameAlias = ltItemMasterImport.ItemName; //"AlexMaster"; new
if (ecoResProduct.RecId)
{
inventTable.TEC_InventType = ecoResProduct.TEC_InventType;
inventTable.TEC_FamilyId = ecoResProduct.TEC_FamilyId;
inventTable.TEC_SubFamilyID = ecoResProduct.TEC_SubFamilyID;
inventTable.TEC_ItemVocation = ecoResProduct.TEC_ItemVocation;
inventTable.TEC_DualColorItem = ecoResProduct.TEC_DualColorItem;
inventTable.Tec_Proforma = ecoResProduct.Tec_Proforma;
inventTable.TEC_Conceptor = ecoResProduct.TEC_Conceptor;
inventTable.TEC_DiscountItem = ecoResProduct.TEC_DiscountItem;
inventTable.Tec_MinOrderWeight = ecoResProduct.Tec_MinOrderWeight;
inventTable.Tec_MetalNonMetal = ecoResProduct.Tec_MetalNonMetal;
//inventTable.StandardConfigId = ltItemMasterImport.StandardConfigId;
//inventTable.StandardInventStyleId = ltItemMasterImport.StandardInventStyleId;
inventTable.TEC_PurchCalcUnit = ecoResProduct.TEC_PurchCalcUnit;
inventTable.TEC_SalesCalcUnit = ecoResProduct.TEC_SalesCalcUnit;
inventTable.TEC_PurchCalcUnit_TMB = ecoResProduct.TEC_PurchCalcUnit_TMB;
inventTable.TEC_ItemType = ecoResProduct.TEC_ItemType;
inventTable.Tec_ProductType = ecoResProduct.Tec_ProductType;
inventTable.TaxPackagingQty = ltItemMasterImport.TaxPackagingQty;
inventTable.NetWeight = ltItemMasterImport.NetWeight;
//ecoResProduct.doUpdate();
//EcoResStorageDimensionGroupName
}
if (inventTable.validateWrite())
{
inventTable.insert();
//Inventory model group
inventModelGroupItem.clear();
inventModelGroupItem.initValue();
inventModelGroupItem.ItemDataAreaId = inventTable.dataAreaId;
inventModelGroupItem.ItemId = inventTable.ItemId;
inventModelGroupItem.ModelGroupId = ltItemMasterImport.InventModelGroupId; //"FIFO"; new
inventModelGroupItem.ModelGroupDataAreaId = curext();
inventModelGroupItem.insert();
//Item group
inventItemGroupItem.clear();
inventItemGroupItem.initValue();
inventItemGroupItem.ItemDataAreaId = inventTable.dataAreaId;
inventItemGroupItem.ItemId = inventTable.ItemId;
inventItemGroupItem.ItemGroupId = ltItemMasterImport.ItemGroupId; //"Parts"; new
inventItemGroupItem.ItemGroupDataAreaId = curext();
inventItemGroupItem.insert();
//Extended product details - Inventory
inventTableModule.clear();
inventTableModule.initValue();
inventTableModule.ItemId = inventTable.ItemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Invent;
inventTableModule.insert();
//Extended product details - Purchase
inventTableModule.clear();
inventTableModule.initValue();
inventTableModule.ItemId = inventTable.ItemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Purch;
inventTableModule.insert();
//Extended product details - Sales
inventTableModule.clear();
inventTableModule.initValue();
inventTableModule.ItemId = inventTable.ItemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Sales;
inventTableModule.insert();
//Warehouse items
InventItemLocation::createDefault(inventTable.ItemId);
//Supply type setup
inventItemSetupSupplyType.clear();
inventItemSetupSupplyType.initValue();
inventItemSetupSupplyType.ItemId = inventTable.ItemId;
inventItemSetupSupplyType.ItemDataAreaId = inventTable.DataAreaId;
inventItemSetupSupplyType.insert();
//Product storage dimension group
ecoResStorageDimensionGroupProduct = EcoResStorageDimensionGroupProduct::findByProduct(ecoResProductMaster.RecId);
if (ecoResStorageDimensionGroupProduct.RecId)
{
ecoResStorageDimensionGroupItem.clear();
ecoResStorageDimensionGroupItem.initValue();
ecoResStorageDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
ecoResStorageDimensionGroupItem.ItemId = inventTable.ItemId;
ecoResStorageDimensionGroupItem.StorageDimensionGroup = ecoResStorageDimensionGroupProduct.StorageDimensionGroup;
ecoResStorageDimensionGroupItem.insert();
}
//Product tracking dimension group
ecoResTrackingDimensionGroupProduct = EcoResTrackingDimensionGroupProduct::findByProduct(ecoResProductMaster.RecId);
if (ecoResTrackingDimensionGroupProduct.RecId)
{
ecoResTrackingDimensionGroupItem.clear();
ecoResTrackingDimensionGroupItem.initValue();
ecoResTrackingDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
ecoResTrackingDimensionGroupItem.ItemId = inventTable.ItemId;
ecoResTrackingDimensionGroupItem.TrackingDimensionGroup = ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup;
ecoResTrackingDimensionGroupItem.insert();
}
}
}
inventDim.clear();
inventDim.ConfigId = ltItemMasterImport.LTEcoResConfigurationName;
inventDim.InventColorId = ltItemMasterImport.LTEcoResColorName;
inventDim.InventStyleId = ltItemMasterImport.LTEcoResStyleName;
inventDim = InventDim::findOrCreate(inventDim);
//Released product variant
inventDimCombination.clear();
inventDimCombination.initValue();
inventDimCombination.DistinctProductVariant = ecoResDistinctProductVariant.RecId;
inventDimCombination.ItemId = inventTable.ItemId;
inventDimCombination.InventDimId = inventDim.InventDimId;
inventDimCombination.insert();
//}
}
catch
{
error("Error!");
return;
}
}
info("Done!");
}