public void Create_Product(ItemId _itemid,ItemName _itemname,Name _searchname,Name _name,ProductType _ProductType)
{
//Classes
EcoResProductService ecoResProdService;
EcoResEcoResProduct ecoResEcoResProduct;
EcoResEcoResProduct_Product_Distinct ecoResEcoResProduct_Product_Distinct;
EcoResEcoResProduct_Translation ecoResEcoResProduct_Translation;
EcoResEcoResProduct_Identifier ecoResEcoResProduct_Identifier;
//Tables
InventTable inventTable;
InventTableModule inventTableModule;
InventItemSetupSupplyType inventItemSetupSupplyType;
InventModelGroupItem inventModelGroupItem;
InventItemGroupItem inventItemGroupItem;
NumberSequenceTable numberSequenceTable;
EcoResProduct ecoResProduct;
EcoResStorageDimensionGroupProduct ecoResStorageDimensionGroupProduct;
EcoResTrackingDimensionGroupProduct ecoResTrackingDimensionGroupProduct;
EcoResStorageDimensionGroupItem ecoResStorageDimensionGroupItem;
EcoResTrackingDimensionGroupItem ecoResTrackingDimensionGroupItem;
DataAreaId _dataAreaId=curext();
//Object Creating Class
ecoResProdService = EcoResProductService::construct();
ecoResEcoResProduct = new EcoResEcoResProduct();
ecoResEcoResProduct_Product_Distinct = new EcoResEcoResProduct_Product_Distinct();
//Newly created and initialize product
ecoResEcoResProduct_Product_Distinct.parmDisplayProductNumber(_itemid);
ecoResEcoResProduct_Product_Distinct.parmProductType(EcoResProductType::Item);
ecoResEcoResProduct_Product_Distinct.parmSearchName(_searchname);
//Create a new translation object:
ecoResEcoResProduct_Translation = ecoResEcoResProduct_Product_Distinct.createTranslation().addNew();
ecoResEcoResProduct_Translation.parmDescription(_searchname);
ecoResEcoResProduct_Translation.parmLanguageId(CompanyInfo::languageId());
ecoResEcoResProduct_Translation.parmName(_itemname);
//Create a new Identifier object:
ecoResEcoResProduct_Identifier = ecoResEcoResProduct_Product_Distinct.createIdentifier().addNew();
ecoResEcoResProduct_Identifier.parmProductNumber(_itemid);
//Assign Product Class to table
ecoResEcoResProduct.createProduct().add(ecoResEcoResProduct_Product_Distinct);
ecoResProdService.create(ecoResEcoResProduct);
info("Product is Creted");
//Realsed Product
select firstOnly ecoResProduct where EcoResProduct.DisplayProductNumber == _itemid;
//Storage dimension group
ecoResStorageDimensionGroupProduct.clear();
ecoResStorageDimensionGroupProduct.initValue();
ecoResStorageDimensionGroupProduct.Product = ecoResProduct.RecId;
ecoResStorageDimensionGroupProduct.StorageDimensionGroup = EcoResStorageDimensionGroup::findByDimensionGroupName("Site").RecId;
if (ecoResStorageDimensionGroupProduct.validateWrite())
{
ecoResStorageDimensionGroupProduct.insert();
}
//Tracking dimension group
ecoResTrackingDimensionGroupProduct.clear();
ecoResTrackingDimensionGroupProduct.initValue();
ecoResTrackingDimensionGroupProduct.Product = ecoResProduct.RecId;
ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup = EcoResTrackingDimensionGroup::findByDimensionGroupName("Serial").RecId;
if (ecoResTrackingDimensionGroupProduct.validateWrite())
{
ecoResTrackingDimensionGroupProduct.insert();
}
if (!numberSequenceTable.RecId || numberSequenceTable.Manual)
{
itemId = ecoResProduct.productNumber();
}
else //number sequence auto, get a number
{
itemId = NumberSeq::newGetNumFromId(numberSequenceTable.RecId).num();
}
inventTable.clear();
inventTable.initValue();
inventTable.initFromEcoResProduct(ecoResProduct);
inventTable.ItemId = ItemId;
inventTable.NameAlias = ecoResProduct.SearchName;
inventTable.insert(true);
// Create inventTableModules
inventTableModule.clear();
inventTableModule.initValue();
inventTableModule.ItemId = inventTable.ItemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Invent;
inventTableModule.insert();
inventTableModule.clear();
inventTableModule.initValue();
inventTableModule.ItemId = inventTable.ItemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Purch;
inventTableModule.insert();
inventTableModule.clear();
inventTableModule.initValue();
inventTableModule.ItemId = inventTable.ItemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Sales;
inventTableModule.insert();
//Inventory model group
inventModelGroupItem.clear();
inventModelGroupItem.initValue();
inventModelGroupItem.ItemDataAreaId = inventTable.dataAreaId;
inventModelGroupItem.ItemId = inventTable.ItemId;
inventModelGroupItem.ModelGroupId = "FIFO";
inventModelGroupItem.ModelGroupDataAreaId = curext();
inventModelGroupItem.insert();
//Item group
inventItemGroupItem.clear();
inventItemGroupItem.initValue();
inventItemGroupItem.ItemDataAreaId = inventTable.dataAreaId;
inventItemGroupItem.ItemId = inventTable.ItemId;
inventItemGroupItem.ItemGroupId = "Sevices";
inventItemGroupItem.ItemGroupDataAreaId = curext();
inventItemGroupItem.insert();
//Create inventItemLocation
InventItemLocation::createDefault(inventTable.ItemId);
// Creates a new item default order type for the product that is released.
inventItemSetupSupplyType.clear();
inventItemSetupSupplyType.initValue();
inventItemSetupSupplyType.ItemId = inventTable.ItemId;
inventItemSetupSupplyType.ItemDataAreaId = inventTable.DataAreaId;
inventItemSetupSupplyType.insert();
//create relationship tables to dimension groups.
ecoResStorageDimensionGroupProduct = EcoResStorageDimensionGroupProduct::findByProduct(ecoResProduct.RecId);
ecoResTrackingDimensionGroupProduct = EcoResTrackingDimensionGroupProduct::findByProduct(ecoResProduct.RecId);
// mandatory storage dimension group for the product
if (ecoResStorageDimensionGroupProduct.RecId)
{
ecoResStorageDimensionGroupItem.clear();
ecoResStorageDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
ecoResStorageDimensionGroupItem.ItemId = inventTable.ItemId;
ecoResStorageDimensionGroupItem.StorageDimensionGroup = ecoResStorageDimensionGroupProduct.StorageDimensionGroup;
ecoResStorageDimensionGroupItem.insert();
}
// mandatory tracking dimension group for the product
if (ecoResTrackingDimensionGroupProduct.RecId)
{
ecoResTrackingDimensionGroupItem.clear();
ecoResTrackingDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
ecoResTrackingDimensionGroupItem.ItemId = inventTable.ItemId;
ecoResTrackingDimensionGroupItem.TrackingDimensionGroup = ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup;
ecoResTrackingDimensionGroupItem.insert();
}
info(strfmt("Product successfully released to UsMf legal entity"));
}
{
//Classes
EcoResProductService ecoResProdService;
EcoResEcoResProduct ecoResEcoResProduct;
EcoResEcoResProduct_Product_Distinct ecoResEcoResProduct_Product_Distinct;
EcoResEcoResProduct_Translation ecoResEcoResProduct_Translation;
EcoResEcoResProduct_Identifier ecoResEcoResProduct_Identifier;
//Tables
InventTable inventTable;
InventTableModule inventTableModule;
InventItemSetupSupplyType inventItemSetupSupplyType;
InventModelGroupItem inventModelGroupItem;
InventItemGroupItem inventItemGroupItem;
NumberSequenceTable numberSequenceTable;
EcoResProduct ecoResProduct;
EcoResStorageDimensionGroupProduct ecoResStorageDimensionGroupProduct;
EcoResTrackingDimensionGroupProduct ecoResTrackingDimensionGroupProduct;
EcoResStorageDimensionGroupItem ecoResStorageDimensionGroupItem;
EcoResTrackingDimensionGroupItem ecoResTrackingDimensionGroupItem;
DataAreaId _dataAreaId=curext();
//Object Creating Class
ecoResProdService = EcoResProductService::construct();
ecoResEcoResProduct = new EcoResEcoResProduct();
ecoResEcoResProduct_Product_Distinct = new EcoResEcoResProduct_Product_Distinct();
//Newly created and initialize product
ecoResEcoResProduct_Product_Distinct.parmDisplayProductNumber(_itemid);
ecoResEcoResProduct_Product_Distinct.parmProductType(EcoResProductType::Item);
ecoResEcoResProduct_Product_Distinct.parmSearchName(_searchname);
//Create a new translation object:
ecoResEcoResProduct_Translation = ecoResEcoResProduct_Product_Distinct.createTranslation().addNew();
ecoResEcoResProduct_Translation.parmDescription(_searchname);
ecoResEcoResProduct_Translation.parmLanguageId(CompanyInfo::languageId());
ecoResEcoResProduct_Translation.parmName(_itemname);
//Create a new Identifier object:
ecoResEcoResProduct_Identifier = ecoResEcoResProduct_Product_Distinct.createIdentifier().addNew();
ecoResEcoResProduct_Identifier.parmProductNumber(_itemid);
//Assign Product Class to table
ecoResEcoResProduct.createProduct().add(ecoResEcoResProduct_Product_Distinct);
ecoResProdService.create(ecoResEcoResProduct);
info("Product is Creted");
//Realsed Product
select firstOnly ecoResProduct where EcoResProduct.DisplayProductNumber == _itemid;
//Storage dimension group
ecoResStorageDimensionGroupProduct.clear();
ecoResStorageDimensionGroupProduct.initValue();
ecoResStorageDimensionGroupProduct.Product = ecoResProduct.RecId;
ecoResStorageDimensionGroupProduct.StorageDimensionGroup = EcoResStorageDimensionGroup::findByDimensionGroupName("Site").RecId;
if (ecoResStorageDimensionGroupProduct.validateWrite())
{
ecoResStorageDimensionGroupProduct.insert();
}
//Tracking dimension group
ecoResTrackingDimensionGroupProduct.clear();
ecoResTrackingDimensionGroupProduct.initValue();
ecoResTrackingDimensionGroupProduct.Product = ecoResProduct.RecId;
ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup = EcoResTrackingDimensionGroup::findByDimensionGroupName("Serial").RecId;
if (ecoResTrackingDimensionGroupProduct.validateWrite())
{
ecoResTrackingDimensionGroupProduct.insert();
}
if (!numberSequenceTable.RecId || numberSequenceTable.Manual)
{
itemId = ecoResProduct.productNumber();
}
else //number sequence auto, get a number
{
itemId = NumberSeq::newGetNumFromId(numberSequenceTable.RecId).num();
}
inventTable.clear();
inventTable.initValue();
inventTable.initFromEcoResProduct(ecoResProduct);
inventTable.ItemId = ItemId;
inventTable.NameAlias = ecoResProduct.SearchName;
inventTable.insert(true);
// Create inventTableModules
inventTableModule.clear();
inventTableModule.initValue();
inventTableModule.ItemId = inventTable.ItemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Invent;
inventTableModule.insert();
inventTableModule.clear();
inventTableModule.initValue();
inventTableModule.ItemId = inventTable.ItemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Purch;
inventTableModule.insert();
inventTableModule.clear();
inventTableModule.initValue();
inventTableModule.ItemId = inventTable.ItemId;
inventTableModule.ModuleType = ModuleInventPurchSales::Sales;
inventTableModule.insert();
//Inventory model group
inventModelGroupItem.clear();
inventModelGroupItem.initValue();
inventModelGroupItem.ItemDataAreaId = inventTable.dataAreaId;
inventModelGroupItem.ItemId = inventTable.ItemId;
inventModelGroupItem.ModelGroupId = "FIFO";
inventModelGroupItem.ModelGroupDataAreaId = curext();
inventModelGroupItem.insert();
//Item group
inventItemGroupItem.clear();
inventItemGroupItem.initValue();
inventItemGroupItem.ItemDataAreaId = inventTable.dataAreaId;
inventItemGroupItem.ItemId = inventTable.ItemId;
inventItemGroupItem.ItemGroupId = "Sevices";
inventItemGroupItem.ItemGroupDataAreaId = curext();
inventItemGroupItem.insert();
//Create inventItemLocation
InventItemLocation::createDefault(inventTable.ItemId);
// Creates a new item default order type for the product that is released.
inventItemSetupSupplyType.clear();
inventItemSetupSupplyType.initValue();
inventItemSetupSupplyType.ItemId = inventTable.ItemId;
inventItemSetupSupplyType.ItemDataAreaId = inventTable.DataAreaId;
inventItemSetupSupplyType.insert();
//create relationship tables to dimension groups.
ecoResStorageDimensionGroupProduct = EcoResStorageDimensionGroupProduct::findByProduct(ecoResProduct.RecId);
ecoResTrackingDimensionGroupProduct = EcoResTrackingDimensionGroupProduct::findByProduct(ecoResProduct.RecId);
// mandatory storage dimension group for the product
if (ecoResStorageDimensionGroupProduct.RecId)
{
ecoResStorageDimensionGroupItem.clear();
ecoResStorageDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
ecoResStorageDimensionGroupItem.ItemId = inventTable.ItemId;
ecoResStorageDimensionGroupItem.StorageDimensionGroup = ecoResStorageDimensionGroupProduct.StorageDimensionGroup;
ecoResStorageDimensionGroupItem.insert();
}
// mandatory tracking dimension group for the product
if (ecoResTrackingDimensionGroupProduct.RecId)
{
ecoResTrackingDimensionGroupItem.clear();
ecoResTrackingDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
ecoResTrackingDimensionGroupItem.ItemId = inventTable.ItemId;
ecoResTrackingDimensionGroupItem.TrackingDimensionGroup = ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup;
ecoResTrackingDimensionGroupItem.insert();
}
info(strfmt("Product successfully released to UsMf legal entity"));
}
No comments:
Post a Comment