//http://daxtechies.blogspot.com.tr/2013/12/ax2012-r2-creating-product-or-product.html
if ( InventTable::find(itemId).ItemId != "" )
this.updateProduct();
else
this.newProduct();
itemRecId = EcoResProduct::findByDisplayProductNumber(itemId).RecId;
this.updateInventTable();
private void newProduct(EcoResProductSubtype _subType = EcoResProductSubtype::Product)
{
EcoResProductService erProdSvc;
EcoResEcoResProduct ecoResProd;
EcoResEcoResProduct_Product_Master prodMaster;
EcoResEcoResProduct_Translation translation;
EcoResEcoResProduct_Identifier identifier;
EcoResEcoResProduct_ProductDimGroup prodDimGroup;
EcoResEcoResProduct_Product_Distinct distMaster;
EcoResEcoResProduct_StorageDimGroup storDimGroup;
EcoResEcoResProduct_TrackingDimGroup tracDimGroup;
InventTable inventTable;
erProdSvc = EcoResProductService::construct();
ecoResProd = new EcoResEcoResProduct();
if (_subType == EcoResProductSubtype::ProductMaster) //varianted product
{
prodMaster = new EcoResEcoResProduct_Product_Master();
prodMaster.parmDisplayProductNumber(itemId);
prodMaster.parmProductType(EcoResProductType::Item);
prodMaster.parmSearchName(nameAlias);
prodMaster.parmVariantConfigurationTechnology(EcoResVariantConfigurationTechnologyType::PredefinedVariants);
translation = prodMaster.createTranslation().addNew();
identifier = prodMaster.createIdentifier().addNew();
prodDimGroup = prodMaster.createProductDimGroup().addNew();
prodDimGroup.parmProduct(itemId);
prodDimGroup.parmProductDimensionGroup(dimGroup);
storDimGroup = prodMaster.createStorageDimGroup().addNew();
tracDimGroup = prodMaster.createTrackingDimGroup().addNew();
}
if (_subType == EcoResProductSubtype::Product) //product
{
distMaster = new EcoResEcoResProduct_Product_Distinct();
distMaster.parmDisplayProductNumber(itemId);
distMaster.parmProductType(EcoResProductType::Item);
distMaster.parmSearchName(nameAlias);
translation = distMaster.createTranslation().addNew();
identifier = distMaster.createIdentifier().addNew();
storDimGroup = distMaster.createStorageDimGroup().addNew();
tracDimGroup = distMaster.createTrackingDimGroup().addNew();
}
translation.parmDescription(itemName);
translation.parmLanguageId(SystemParameters::getSystemLanguageId());
translation.parmName(itemName);
storDimGroup.parmProduct(itemId);
storDimGroup.parmStorageDimensionGroup(storeGroup);
tracDimGroup.parmProduct(itemId);
tracDimGroup.parmTrackingDimensionGroup(trackingGroup);
identifier.parmProductNumber(itemId);
if (_subType == EcoResProductSubtype::ProductMaster) //varianted product
ecoResProd.createProduct().add(prodMaster);
if (_subType == EcoResProductSubtype::Product) //product
ecoResProd.createProduct().add(distMaster);
erProdSvc.create(ecoResProd);
EcoResProductReleaseManagerBase::releaseProduct(EcoResProduct::findByProductNumber(itemId).RecId,CompanyInfo::find().RecId);
}
private void updateProduct()
{
InventTableModule inventModule;
EcoResProductTranslation translation;
update_recordSet inventModule setting unitId = unitId
where inventModule.ItemId == itemId;
update_recordSet translation
setting Description = itemName,
Name = itemName
where translation.Product == itemRecId &&
translation.LanguageId == SystemParameters::getSystemLanguageId();
}
private void updateInventTable()
{
InventTable inventTable;
InventModelGroupItem modelGroup;
update_recordSet inventTable
setting NetWeight = netWeight,
TaraWeight = taraWeight,
GrossDepth = depth,
GrossWidth = width,
GrossHeight = height,
UnitVolume = volume
where
inventTable.Product == itemRecId;
if (inventModelGroupId == "")
delete_from modelGroup
where modelGroup.ItemId == itemId && modelGroup.ItemDataAreaId == curext() &&
modelGroup.ModelGroupDataAreaId == curext();
else
{
select firstOnly forUpdate modelGroup
where modelGroup.ItemId == itemId && modelGroup.ItemDataAreaId == curext() &&
modelGroup.ModelGroupDataAreaId == curext();
modelGroup.ItemId = itemId;
modelGroup.ItemDataAreaId = curext();
modelGroup.ModelGroupDataAreaId = curext();
modelGroup.ModelGroupId = inventModelGroupId;
if (modelGroup.RecId == 0)
modelGroup.insert();
else
modelGroup.update();
}
}
Hiç yorum yok:
Yorum Gönder