Learn about how to summary data from all one to many records after save child entity.
Requirement
System must calculate total amount of all Supplier records to Summary Price of Oder Request Item.
Procedure
1. From ONEWEB workspace, open java file name "com.manual.doc.order.java.OrderRequestItemBackOfficeUpdateMode" and override method "modifyResult()" with coding below.
@Override
public Vector modifyResult() {
//Current child entity
HashMap currentRequestItemData = EAFManualUtil.getDataHashMapFromSession("MD9443222701", request);
String currentOrderItemID = (String)currentRequestItemData.get("ORDER_ITEM_ID");
String currentOrderItemSummary = (String)currentRequestItemData.get("SUMMARY_PRICE");
//One to many before open child entity
MasterFormHandler orderItemForm = (MasterFormHandler)getRequest().getSession().getAttribute("MD1290242832_session");
Vector vForm = orderItemForm.getStoreActionList();
logger.debug("#####vForm#####"+vForm);
double sumPrice = 0;
for (int i=0; i<vForm.size(); i++) {
HashMap hData = EAFManualUtil.getDataHashMapFromSession("MD1290242832", request, i);
logger.debug("#####hData#####"+hData);
String recordOrderItemId = (String)hData.get("ORDER_ITEM_ID");
String recordSummary = (String)hData.get("SUMMARY_PRICE");
//Summary all record except editing record (current child entity is editing record)
if(!currentOrderItemID.equals(recordOrderItemId)){
if(recordSummary != null && !"".equals(recordSummary)){
sumPrice += Double.parseDouble(recordSummary);
}
}
logger.debug("#####recordSummary#####"+recordSummary);
logger.debug("#####sumPrice#####"+sumPrice);
}
//Plus editing data to summary
sumPrice += Double.parseDouble(currentOrderItemSummary);
HashMap mainRequestData = EAFManualUtil.getDataHashMapFromSession("MD7333074691", request);
Vector resultForProcess = getResultForProcess();
HashMap serviceRequestDataHash = new HashMap();
serviceRequestDataHash.put("TOTAL_AMT", String.valueOf(sumPrice));
serviceRequestDataHash.put("REQUEST_ID", mainRequestData.get("REQUEST_ID"));
Vector moduleKeyVect = new Vector();
moduleKeyVect.add("REQUEST_ID");
HashMap serviceRequestHash = new HashMap();
serviceRequestHash.put("WF_SERVICE_REQUEST", serviceRequestDataHash);
serviceRequestHash.put("MODULE_FIELD_KEY", moduleKeyVect);
HashMap updateServiceRequestHash = new HashMap();
updateServiceRequestHash.put("UPDATE", serviceRequestHash);
resultForProcess.add(updateServiceRequestHash);
logger.debug("#####resultForProcess#####"+resultForProcess);
return super.modifyResult();
}
1.1. Go to App Designer and open entity "Doc Order Request - Back Office" then click edit at module "Order Request Item" and find module id at property name "Module ID".
1.2. Replace "MD1290242832_session" with module id from step 1.1 (concatenate module id with "_session").
1.3. Replace "MD1290242832" with module id from step 1.1.
1.4. Go to App Designer and open entity "Doc Order Request - Back Office" then click edit at module "Order Request" and find module id at property name "Module ID".
1.5. Replace "MD7333074691" with module id from step 1.4.
1.6. Go to App Designer and open entity "Doc Order Request Item- Back Office" then click edit at module "Order Item" and find module id at property name "Module ID".
1.7. Replace "MD9443222701" with module id from step 1.6
2. Go to App Designer and open entity "Doc Order Request - Back Office" then click edit at entity action "UPDATE".
2.1. On Action Field Configuration put "com.manual.doc.order.java.OrderRequestItemBackOfficeUpdateMode" to Class Action.
2.2. Click OK.
2.3. Click Save this Entity.
3. From ONEWEB workspace, export EafMasterEar.ear and deploy update to server. The class name "com.manual.doc.order.java.OrderRequestItemBackOfficeUpdateMode" will update to server.
4. Test by log in to FrontWeb.
4.1. Login with Back Office user.
4.2. Go to To Do List and claim job.
4.3. Click edit Order Item.
4.4. Click edit Supplier and save.
4.5. Click save at child entity.
4.6. System must calculate Summary Price to Total Amt.