/// <summary>
///
/// </summary>
class IHSProductMasterInsertManager extends RunBaseBatch
{
/// <summary>
///
/// </summary>
public void run()
{
IHSProductMasterTable ihsProductMasterTable;
EcoResProduct ecoResProduct;
RefRecId ecoResDistinctProductVariantRecId;
InventTable inventTable;
InventDimCombination inventDimCombination;
str messageBody;
int i, j = 1, errorCount = 0, successCount = 0;
while select ihsProductMasterTable
order by ihsProductMasterTable.ProductNumber, ihsProductMasterTable.EntityId
where ihsProductMasterTable.ItemProcessStatus == IHSItemProcessStatus::Unprocessed
{
try
{
ttsbegin;
//Create product
if (!this.checkIfProductNumberExists(ihsProductMasterTable.ProductNumber))
{
this.createProduct(ihsProductMasterTable);
}
//Release product
changecompany(ihsProductMasterTable.EntityId)
{
if (!InventTable::exist(ihsProductMasterTable.ItemNumber))
{
this.releaseProduct(ihsProductMasterTable);
}
//Update tracking details
if (!ihsProductMasterTable.ProductStyleVariant)
{
select firstonly RecId, TableId
from inventTable
where inventTable.ItemId == ihsProductMasterTable.ItemNumber;
this.assignTrackingDetails(ihsProductMasterTable, inventTable.TableId, inventTable.RecId);
}
}
//Create prodct variant
if (ihsProductMasterTable.ProductSubtype == EcoResProductSubtype::ProductMaster && ihsProductMasterTable.ProductStyleVariant)
{
ecoResProduct = EcoResProduct::findByProductNumber(ihsProductMasterTable.ProductNumber);
ecoResDistinctProductVariantRecId = this.createProductVariant(ecoResProduct, ihsProductMasterTable.ProductStyleVariant);
//Release product variant
changecompany (ihsProductMasterTable.EntityId)
{
this.releaseProductVariant(ecoResDistinctProductVariantRecId);
//Update tracking details
select firstonly RecId, TableId
from inventDimCombination
where inventDimCombination.DistinctProductVariant == ecoResDistinctProductVariantRecId;
this.assignTrackingDetails(ihsProductMasterTable, inventDimCombination.TableId, inventDimCombination.RecId);
}
}
successCount ++;
ihsProductMasterTable.selectForUpdate(true);
ihsProductMasterTable.update();
ttscommit;
}
catch
{
errorCount ++;
messageBody = '';
for (i = j; i <= infolog.line(); i++)
{
messageBody += infolog.text(i);
}
j = i;
ttsbegin;
ihsProductMasterTable.ItemProcessStatus = IHSItemProcessStatus::Error;
ihsProductMasterTable.ErrorTxt = messageBody;
ihsProductMasterTable.selectForUpdate(true);
ihsProductMasterTable.update();
ttscommit;
continue;
}
}
info (strFmt("Item master import completed with %1 success and %2 errors", successCount, errorCount));
}
/// <summary>
///
/// </summary>
/// <param name = "_productNumber"></param>
/// <returns></returns>
public boolean checkIfProductNumberExists(EcoResProductNumber _productNumber)
{
return EcoResProductIdentifier::existsByProductNumber(_productNumber);
}
/// <summary>
///
/// </summary>
/// <param name = "ihsProductMasterTable"></param>
public void createProduct(IHSProductMasterTable ihsProductMasterTable)
{
EcoResProductV2Entity ecoResProductV2Entity;
ecoResProductV2Entity.clear();
ecoResProductV2Entity.initValue();
ecoResProductV2Entity.ProductNumber = ihsProductMasterTable.ProductNumber;
ecoResProductV2Entity.ProductName = ihsProductMasterTable.ProductName;
ecoResProductV2Entity.ProductSearchName = ihsProductMasterTable.ProductSearchName;
// ecoResProductV2Entity.SearchName = ihsProductMasterTable.ProductSearchName;
// ecoResProductV2Entity.ItemNumber = ihsProductMasterTable.ItemNumber;
ecoResProductV2Entity.ProductType = ihsProductMasterTable.ProductType;
ecoResProductV2Entity.ProductSubType = ihsProductMasterTable.ProductSubtype;
if (ecoResProductV2Entity.ProductSubType == EcoResProductSubtype::ProductMaster)
{
ecoResProductV2Entity.VariantConfigurationTechnology = EcoResVariantConfigurationTechnologyType::PredefinedVariants;
ecoResProductV2Entity.ProductDimensionGroupName = ihsProductMasterTable.ProductDimensionGroup;
}
// ecoResProductV2Entity.ItemModelGroupId = ihsProductMasterTable.ItemModelGroupId;
//ecoResProductV2Entity.ProductGroupId = ihsProductMasterTable.ItemGroupId;
// ecoResProductV2Entity.InventoryUnitSymbol = ihsProductMasterTable.UnitId;
//ecoResProductV2Entity.BOMUnitSymbol = ihsProductMasterTable.UnitI;
//ecoResProductV2Entity.SalesUnitSymbol = ihsProductMasterTable.UnitId;
//ecoResProductV2Entity.PurchaseUnitSymbol = ihsProductMasterTable.UnitId;
ecoResProductV2Entity.TrackingDimensionGroupName = ihsProductMasterTable.TrackingDimensionGroup;
ecoResProductV2Entity.StorageDimensionGroupName = ihsProductMasterTable.StorageDimensionGroup;
ecoResProductV2Entity.insert();
}
/// <summary>
///
/// </summary>
/// <param name = "_ecoResProduct"></param>
/// <param name = "_styleName"></param>
/// <returns></returns>
public RefRecId createProductVariant(EcoResProduct _ecoResProduct, EcoResStyleName _styleName)
{
EcoResProductMasterStyle productMasterStyle;
EcoResStyle ecoResStyle;
EcoResProductDimensionAttribute prodDimensionAttribute;
container productDimensions;
ecoResDistinctProductVariant ecoResDistinctProductVariant;
RefRecId ecoResDistinctProductVariantRecId;
//Create a container to hold dimension values
productDimensions = EcoResProductVariantDimValue::getDimensionValuesContainer('','','',_styleName);
ecoResDistinctProductVariantRecId = EcoResProductVariantManager::findDistinctProductVariant(_ecoResProduct.RecId, productDimensions).RecId;
if (ecoResDistinctProductVariantRecId)
{
return ecoResDistinctProductVariantRecId;
}
//Style - Start
ecoResStyle = EcoResStyle::findByName(_styleName);
if (!ecoResStyle.RecId)
{
ecoResStyle.Name = _styleName;
ecoResStyle.insert();
}
select * from productMasterStyle
where productMasterStyle.Style == ecoResStyle.RecId
&& productMasterStyle.StyleProductMaster == _ecoResProduct.RecId;
if(!productMasterStyle.RecId)
{
select RecId from prodDimensionAttribute
where prodDimensionAttribute.DimensionTableId == tableNum(EcoResStyle);
productMasterStyle.Style = ecoResStyle.RecId;
productMasterStyle.StyleProductDimensionAttribute = prodDimensionAttribute.RecId;
productMasterStyle.StyleProductMaster = _ecoResProduct.RecId;
productMasterStyle.insert();
}
//Create Product search name
//ecoResDistinctProductVariant.DisplayProductNumber = EcoResProductNumberBuilderVariant::buildFromProductNumberAndDimensions(_ecoResProduct.productNumber(), productDimensions);
ecoResDistinctProductVariant.DisplayProductNumber = _ecoResProduct.productNumber() + "-" + _styleName;
productDimensions = EcoResProductVariantDimValue::getDimensionValuesContainer('','','',_styleName);
//Create Product variant with Product and dimensions provided
ecoResDistinctProductVariantRecId = EcoResProductVariantManager::createProductVariant(_ecoResProduct.RecId,
ecoResDistinctProductVariant.DisplayProductNumber,
productDimensions,ecoResDistinctProductVariant.DisplayProductNumber);
return ecoResDistinctProductVariantRecId;
}
/// <summary>
///
/// </summary>
/// <param name = "ihsProductMasterTable"></param>
public void releaseProduct(IHSProductMasterTable ihsProductMasterTable)
{
EcoResReleasedProductV2Entity ecoResReleasedProductCreationV2Entity;
ecoResReleasedProductCreationV2Entity.clear();
ecoResReleasedProductCreationV2Entity.initValue();
ecoResReleasedProductCreationV2Entity.ProductNumber = ihsProductMasterTable.ProductNumber;
//ecoResReleasedProductCreationV2Entity.ProductName = ihsProductMasterTable.ProductName;
ecoResReleasedProductCreationV2Entity.ProductSearchName = ihsProductMasterTable.ProductSearchName;
ecoResReleasedProductCreationV2Entity.SearchName = ihsProductMasterTable.ProductSearchName;
ecoResReleasedProductCreationV2Entity.ItemNumber = ihsProductMasterTable.ItemNumber;
ecoResReleasedProductCreationV2Entity.ProductType = ihsProductMasterTable.ProductType;
ecoResReleasedProductCreationV2Entity.ProductSubType = ihsProductMasterTable.ProductSubtype;
ecoResReleasedProductCreationV2Entity.ItemModelGroupId = ihsProductMasterTable.ItemModelGroupId;
ecoResReleasedProductCreationV2Entity.ProductGroupId = ihsProductMasterTable.ItemGroupId;
ecoResReleasedProductCreationV2Entity.InventoryUnitSymbol = ihsProductMasterTable.UnitId;
//ecoResReleasedProductCreationV2Entity.BOMUnitSymbol = ihsProductMasterTable.UnitI;
ecoResReleasedProductCreationV2Entity.SalesUnitSymbol = ihsProductMasterTable.UnitId;
ecoResReleasedProductCreationV2Entity.PurchaseUnitSymbol = ihsProductMasterTable.UnitId;
ecoResReleasedProductCreationV2Entity.TrackingDimensionGroupName = ihsProductMasterTable.TrackingDimensionGroup;
ecoResReleasedProductCreationV2Entity.StorageDimensionGroupName = ihsProductMasterTable.StorageDimensionGroup;
ecoResReleasedProductCreationV2Entity.insert();
}
/// <summary>
///
/// </summary>
/// <param name = "_ecoResDistinctProductVariantRecId"></param>
public void releaseProductVariant(RefRecId _ecoResDistinctProductVariantRecId)
{
EcoResDistinctProductVariant ecoResDistinctProductVariant;
EcoResProductReleaseManagerBase releaseManager;
if (!InventDimCombination::findByDistinctProductVariant(_ecoResDistinctProductVariantRecId))
{
ecoResDistinctProductVariant = EcoResDistinctProductVariant::find(_ecoResDistinctProductVariantRecId);
//Now release the Product variant
releaseManager = EcoResProductReleaseManagerBase::newFromProduct(ecoResDistinctProductVariant);
releaseManager.release();
}
}
public void assignTrackingDetails(IHSProductMasterTable ihsProductMasterTable, RefTableId _refTableId, RefRecId _refRecId)
{
ihsProductMasterTable.RefTableId = _refTableId;
ihsProductMasterTable.RefRecId = _refRecId;
ihsProductMasterTable.ItemProcessStatus = IHSItemProcessStatus::Processed;
}
/// <summary>
///
/// </summary>
/// <param name = "calledFrom"></param>
/// <returns></returns>
public boolean validate(Object calledFrom = null)
{
boolean ret;
IHSProductMasterTable ihsProductMasterTable, ihsProductMasterTableGroup;
InventModelGroup inventModelGroup;
InventItemGroup inventItemGroup;
EcoResProductDimensionGroup ecoResProductDimensionGroup;
EcoResStorageDimensionGroup ecoResStorageDimensionGroup;
EcoResTrackingDimensionGroup ecoResTrackingDimensionGroup;
UnitOfMeasure unitOfMeasure;
ret = super(calledFrom);
while select ihsProductMasterTableGroup
index hint EntityIdx
group by ihsProductMasterTableGroup.EntityId
where ihsProductMasterTableGroup.ItemProcessStatus == IHSItemProcessStatus::Unprocessed
{
changecompany (ihsProductMasterTableGroup.EntityId)
{
//Item model group
while select forupdate ItemModelGroupId
from ihsProductMasterTable
where ihsProductMasterTable.EntityId == ihsProductMasterTableGroup.EntityId
&& ihsProductMasterTable.ItemProcessStatus == IHSItemProcessStatus::Unprocessed
notexists join inventModelGroup
where inventModelGroup.ModelGroupId == ihsProductMasterTable.ItemModelGroupId
&& inventModelGroup.DataAreaId == ihsProductMasterTable.EntityId
{
ttsbegin;
ihsProductMasterTable.ItemProcessStatus = IHSItemProcessStatus::Error;
ihsProductMasterTable.ErrorTxt = strFmt("The Item model group Id %1 does not exists", ihsProductMasterTable.ItemModelGroupId);
ihsProductMasterTable.update();
ttscommit;
ret = false;
}
//Item Group
if (ret)
{
while select forupdate ItemGroupId
from ihsProductMasterTable
where ihsProductMasterTable.EntityId == ihsProductMasterTableGroup.EntityId
&& ihsProductMasterTable.ItemProcessStatus == IHSItemProcessStatus::Unprocessed
notexists join inventItemGroup
where inventItemGroup.ItemGroupId == ihsProductMasterTable.ItemGroupId
&& inventItemGroup.DataAreaId == ihsProductMasterTable.EntityId
{
ttsbegin;
ihsProductMasterTable.ItemProcessStatus = IHSItemProcessStatus::Error;
ihsProductMasterTable.ErrorTxt += strFmt("The Item group %1 does not exists", ihsProductMasterTable.ItemGroupId);
ihsProductMasterTable.update();
ttscommit;
ret = false;
}
}
}
//ProductDimensionGroup
if (ret)
{
while select forupdate ProductDimensionGroup
from ihsProductMasterTable
where ihsProductMasterTable.ProductDimensionGroup
&& ihsProductMasterTable.ItemProcessStatus == IHSItemProcessStatus::Unprocessed
notexists join ecoResProductDimensionGroup
where ecoResProductDimensionGroup.Name == ihsProductMasterTable.ProductDimensionGroup
{
ttsbegin;
ihsProductMasterTable.ItemProcessStatus = IHSItemProcessStatus::Error;
ihsProductMasterTable.ErrorTxt += strFmt("The Product Dimension group %1 does not exists", ihsProductMasterTable.ProductDimensionGroup);
ihsProductMasterTable.update();
ttscommit;
ret = false;
}
}
//StorageDimesionGroup
if (ret)
{
while select forupdate StorageDimensionGroup
from ihsProductMasterTable
where ihsProductMasterTable.StorageDimensionGroup
&& ihsProductMasterTable.ItemProcessStatus == IHSItemProcessStatus::Unprocessed
notexists join ecoResStorageDimensionGroup
where ecoResStorageDimensionGroup.Name == ihsProductMasterTable.StorageDimensionGroup
{
ttsbegin;
ihsProductMasterTable.ItemProcessStatus = IHSItemProcessStatus::Error;
ihsProductMasterTable.ErrorTxt += strFmt("The Storage Dimension group %1 does not exists", ihsProductMasterTable.StorageDimensionGroup);
ihsProductMasterTable.update();
ttscommit;
ret = false;
}
}
//TrackingDimesionGroup
if (ret)
{
while select forupdate TrackingDimensionGroup
from ihsProductMasterTable
where ihsProductMasterTable.TrackingDimensionGroup
&& ihsProductMasterTable.ItemProcessStatus == IHSItemProcessStatus::Unprocessed
notexists join ecoResTrackingDimensionGroup
where ecoResTrackingDimensionGroup.Name == ihsProductMasterTable.TrackingDimensionGroup
{
ttsbegin;
ihsProductMasterTable.ItemProcessStatus = IHSItemProcessStatus::Error;
ihsProductMasterTable.ErrorTxt += strFmt("The Storage Dimension group %1 does not exists", ihsProductMasterTable.TrackingDimensionGroup);
ihsProductMasterTable.update();
ttscommit;
ret = false;
}
}
//Unit
if (ret)
{
while select forupdate UnitId
from ihsProductMasterTable
where ihsProductMasterTable.UnitId
&& ihsProductMasterTable.ItemProcessStatus == IHSItemProcessStatus::Unprocessed
notexists join unitOfMeasure
where unitOfMeasure.Symbol == ihsProductMasterTable.UnitId
{
ttsbegin;
ihsProductMasterTable.ItemProcessStatus = IHSItemProcessStatus::Error;
ihsProductMasterTable.ErrorTxt += strFmt("The Unit Id %1 does not exists", ihsProductMasterTable.UnitId);
ihsProductMasterTable.update();
ttscommit;
ret = false;
}
}
//Product number and Item master mismatch
if (ret)
{
while select forupdate ProductNumber, ItemNumber
from ihsProductMasterTable
where ihsProductMasterTable.ItemProcessStatus == IHSItemProcessStatus::Unprocessed
&& ihsProductMasterTable.ProductNumber != ihsProductMasterTable.ItemNumber
{
ttsbegin;
ihsProductMasterTable.ItemProcessStatus = IHSItemProcessStatus::Error;
ihsProductMasterTable.ErrorTxt += strFmt("Product number %1 and Item number %2 does not match", ihsProductMasterTable.UnitId);
ihsProductMasterTable.update();
ttscommit;
ret = false;
}
}
}
if (!ret)
{
warning("Validations are failed. Click on cancel and check error log for more details");
}
return ret;
}
/// <summary>
///
/// </summary>
///
public static void main(Args _args)
{
IHSProductMasterInsertManager ihsProductMasterInsertManager = IHSProductMasterInsertManager::construct();
if (ihsProductMasterInsertManager.prompt())
{
ihsProductMasterInsertManager.run();
}
}
public static IHSProductMasterInsertManager construct()
{
return new IHSProductMasterInsertManager();
}
/// <summary>
///
/// </summary>
/// <returns></returns>
public ClassDescription caption()
{
ClassDescription ret;
ret = super();
ret = "Import Item master";
return ret;
}
}