# Summary Price per Request

In the Order Management App, one **Order Request** may contain multiple **Order Request Items**, and each item may already have its own **Summary Price** calculated from supplier data.

After saving a child entity (Order Request Item), the system must automatically **recalculate the total amount at the Order Request level** by summing the **Summary Price of all Order Request Items**.

This section explains how to implement **cross‑module aggregation logic** using **Java customization** so that the **Total Amount (TOTAL\_AMT)** of an Order Request is always up‑to‑date.

***

### Requirement

The system must calculate:

```
Total Amount (Order Request)
= Sum of SUMMARY_PRICE from all Order Request Item records
```

The calculation must occur **after saving a child entity** (Order Request Item).

***

### Objective

By completing this section, you will learn how to:

* Access data from multiple one‑to‑many modules in Java
* Aggregate summary values across child records
* Update parent entity data programmatically
* Integrate aggregation logic with App Designer entity actions

***

### Step 1: Update Java Customization Class

Open the existing Java class:

```
com.manual.doc.order.java.OrderRequestItemBackOfficeUpdateMode
```

Override the `modifyResult()` method with the following code.

#### Java Aggregation Logic

```
@Override
public Vector modifyResult() {

    // Current Order Request Item being edited
    HashMap currentRequestItemData =
        EAFManualUtil.getDataHashMapFromSession("MD9443222701", request);

    String currentOrderItemID =
        (String) currentRequestItemData.get("ORDER_ITEM_ID");

    String currentOrderItemSummary =
        (String) currentRequestItemData.get("SUMMARY_PRICE");

    // Order Request Item list (before editing)
    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);

        String recordOrderItemId =
            (String) hData.get("ORDER_ITEM_ID");

        String recordSummary =
            (String) hData.get("SUMMARY_PRICE");

        // Sum all records except the currently edited one
        if (!currentOrderItemID.equals(recordOrderItemId)) {

            if (recordSummary != null && !"".equals(recordSummary)) {
                sumPrice += Double.parseDouble(recordSummary);
            }
        }
    }

    // Add summary of the current editing record
    sumPrice += Double.parseDouble(currentOrderItemSummary);

    // Parent Order Request data
    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();
}
```

This logic recalculates and updates the **Total Amount** at the Order Request level every time an Order Request Item is saved.

***

### Step 1.1–1.7: Replace Module IDs

The code uses placeholder module IDs. Replace them with actual module IDs from App Designer as follows.

1. Open entity **Doc Order Request – Back Office**
2. Edit module **Order Request Item**
3. Find **Module ID**
4. Replace:
   * `MD1290242832_session` → `<OrderRequestItemModuleID>_session`
   * `MD1290242832` → `<OrderRequestItemModuleID>`
5. Edit module **Order Request**
6. Find **Module ID**
7. Replace:
   * `MD7333074691` → `<OrderRequestModuleID>`
8. Open entity **Doc Order Request Item – Back Office**
9. Edit module **Order Item**
10. Replace:
    * `MD9443222701` → `<OrderItemModuleID>`

This ensures the calculation references the correct modules.

***

### Step 2: Configure Entity Action in App Designer

1. Open **App Designer**
2. Edit entity:

   ```
   Doc Order Request - Back Office
   ```
3. Edit **Entity Action** with Process Name `UPDATE`

In **Action Field Configuration**:

* **Class Action**:

  ```
  com.manual.doc.order.java.OrderRequestItemBackOfficeUpdateMode
  ```

1. Click **OK**
2. Click **Save this Entity**

***

### Step 3: Deploy Updated Java Class

1. From the **ONEWEB workspace**, export `EafMasterEar.ear`
2. Deploy the updated EAR file to the server

The updated class will now be active.

***

### Step 4: Test the Calculation

1. Log in to **FrontWeb** as a **Back Office user**
2. Go to **To Do List** and claim a job
3. Open **Order Item**
4. Click **Edit Supplier** and save
5. Click **Save** on the **Order Request Item** screen

#### Expected Result

* The system recalculates the **Summary Price** for the edited Order Request Item
* The system recalculates **Total Amount (TOTAL\_AMT)** at the Order Request level
* Total Amount reflects the sum of all Order Request Item Summary Prices

***

### Summary

In this section, you have:

* Implemented aggregation logic across one‑to‑many records
* Ensured Total Amount is always consistent with child item data
* Updated parent entity data automatically after child save
* Integrated Java customization with App Designer entity actions

This customization ensures **accurate financial aggregation** and completes the **end‑to‑end calculation flow** for the **Order Management App (Web)**, from Supplier → Order Item → Order Request.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.onewebstack.com/oneweb-platform-th/tutorials-examples/order-management-app-web/app-designer-customize/summary-price-per-request.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
