Tables:
InventTableModule
InventItemGroupItem
class TestDialog extends RunBase
{
DialogField itemId,itemGroupId;
ItemGroupId _groupId;
Amount _updateAmount;
}
protected Object dialog()
{
Dialog dialog;
dialog = super();
dialog.caption("@MAD16");
itemGroupId = dialog.addField(extendedTypeStr(ItemGroupId),"@SYS4922");
itemId = dialog.addField(extendedTypeStr(Amount),"@MAD17");
return dialog;
}
public void run()
{
_updateAmount=itemId.value();
_groupId=itemGroupId.value();
if(_updateAmount==0 && _groupId=="")
{
Box::info("@MAD19");
}
else
{
if(_groupId=="")
{
error("@MAD20");
}
else
if(_updateAmount==0)
{
error("@MAD21");
}
else
{
TestDialog::UpdateSalesPrice(_groupId,_updateAmount);
}
}
}public boolean validate(Object calledFrom = null)
{
boolean ret;
ret = super(calledFrom);
_updateAmount=itemId.value();
_groupId=itemGroupId.value();
if(_updateAmount==0 && _groupId=="")
{
Box::info("@MAD19");
}
else
{
if(_groupId=="")
{
error("@MAD20");
}
else
if(_updateAmount==0)
{
error("@MAD21");
}
else
{
TestDialog::UpdateSalesPrice(_groupId,_updateAmount);
return true;
}
}
return false;
}
public static void main(Args args)
{
TestDialog testDialog = new TestDialog();
if(testDialog.prompt())
{
testDialog.run();
}
}
public static void UpdateSalesPrice(ItemGroupId _itemGroupId,Amount _amount)
{
InventTableModule inventTableModule;
InventItemGroupItem inventItemGroupItem;
Amount oldPrice,newPrice;
while select ItemId from inventItemGroupItem where inventItemGroupItem.ItemGroupId==_itemGroupId
{
while select forupdate * from inventTableModule where inventTableModule.ItemId==inventItemGroupItem.ItemId && inventTableModule.ModuleType==ModuleInventPurchSales::Sales
{
oldPrice=inventTableModule.Price;
newPrice=(oldPrice+((oldPrice*_amount)/100));
inventTableModule.Price=newPrice;
inventTableModule.update();
UpdateSalesPrice::WriteToFile(inventItemGroupItem.ItemId,oldPrice,newPrice);
}
}
info(strFmt("Sales prices are updated for %1 group with %2 percent increment",_itemGroupId,_amount));
}
public static void WriteToFile(ItemId _itemId, Amount _oldPrice, Amount _newPrice)
{
CommaIO commaIO;
#define.fileName("D:\\Customers.csv")
#File
;
commaIO = new CommaIO(#fileName, #io_append);
commaIO.outFieldDelimiter(",");
commaIO.outRecordDelimiter("\r\n");
if(commaIO)
{
commaIO.write(_itemId, _oldPrice, _newPrice);
}
}
InventTableModule
InventItemGroupItem
class TestDialog extends RunBase
{
DialogField itemId,itemGroupId;
ItemGroupId _groupId;
Amount _updateAmount;
}
protected Object dialog()
{
Dialog dialog;
dialog = super();
dialog.caption("@MAD16");
itemGroupId = dialog.addField(extendedTypeStr(ItemGroupId),"@SYS4922");
itemId = dialog.addField(extendedTypeStr(Amount),"@MAD17");
return dialog;
}
public void run()
{
_updateAmount=itemId.value();
_groupId=itemGroupId.value();
if(_updateAmount==0 && _groupId=="")
{
Box::info("@MAD19");
}
else
{
if(_groupId=="")
{
error("@MAD20");
}
else
if(_updateAmount==0)
{
error("@MAD21");
}
else
{
TestDialog::UpdateSalesPrice(_groupId,_updateAmount);
}
}
}public boolean validate(Object calledFrom = null)
{
boolean ret;
ret = super(calledFrom);
_updateAmount=itemId.value();
_groupId=itemGroupId.value();
if(_updateAmount==0 && _groupId=="")
{
Box::info("@MAD19");
}
else
{
if(_groupId=="")
{
error("@MAD20");
}
else
if(_updateAmount==0)
{
error("@MAD21");
}
else
{
TestDialog::UpdateSalesPrice(_groupId,_updateAmount);
return true;
}
}
return false;
}
public static void main(Args args)
{
TestDialog testDialog = new TestDialog();
if(testDialog.prompt())
{
testDialog.run();
}
}
public static void UpdateSalesPrice(ItemGroupId _itemGroupId,Amount _amount)
{
InventTableModule inventTableModule;
InventItemGroupItem inventItemGroupItem;
Amount oldPrice,newPrice;
while select ItemId from inventItemGroupItem where inventItemGroupItem.ItemGroupId==_itemGroupId
{
while select forupdate * from inventTableModule where inventTableModule.ItemId==inventItemGroupItem.ItemId && inventTableModule.ModuleType==ModuleInventPurchSales::Sales
{
oldPrice=inventTableModule.Price;
newPrice=(oldPrice+((oldPrice*_amount)/100));
inventTableModule.Price=newPrice;
inventTableModule.update();
UpdateSalesPrice::WriteToFile(inventItemGroupItem.ItemId,oldPrice,newPrice);
}
}
info(strFmt("Sales prices are updated for %1 group with %2 percent increment",_itemGroupId,_amount));
}
public static void WriteToFile(ItemId _itemId, Amount _oldPrice, Amount _newPrice)
{
CommaIO commaIO;
#define.fileName("D:\\Customers.csv")
#File
;
commaIO = new CommaIO(#fileName, #io_append);
commaIO.outFieldDelimiter(",");
commaIO.outRecordDelimiter("\r\n");
if(commaIO)
{
commaIO.write(_itemId, _oldPrice, _newPrice);
}
}
No comments:
Post a Comment