Learn about step to summary data by using Ajax.

Requirement

System must summary Total Price of all Supplier records to Summary Price of Oder Request Item.

Procedure

  1. From ONEWEB workspace, create java file name "com.manual.doc.order.ajax.CalculateOrderRequestItemSummaryPrice" in MasterWeb and override method "processManual()" with coding below.


package com.manual.doc.order.ajax;


import java.util.HashMap;

import java.util.Vector;


import javax.servlet.http.HttpServletRequest;


import org.jboss.logging.Logger;

import org.json.JSONObject;


import com.master.form.MasterFormHandler;

import com.master.util.EAFManualUtil;

import com.master.util.ManualInterface;


public class CalculateOrderRequestItemSummaryPrice implements ManualInterface {

       static Logger logger = Logger.getLogger(CalculateOrderRequestItemSummaryPrice.class);

       HttpServletRequest request;

       @Override

       public String processManual() {

               try {

                       MasterFormHandler FormData = (MasterFormHandler)request.getSession().getAttribute("MD8321225761_session");

                       Vector vForm = FormData.getStoreActionList();

                       logger.debug("#####vForm#####"+vForm);

                       double sumPrice = 0;

                       for (int i=0; i<vForm.size(); i++) {

                               HashMap hData = EAFManualUtil.getDataHashMapFromSession("MD8321225761", request, i);

                               logger.debug("#####hData#####"+hData);

                               

                               String totalPrice = (String)hData.get("TOTAL_PRICE");

                               if(totalPrice != null && !"".equals(totalPrice)){

                                       sumPrice += Double.parseDouble(totalPrice);

                               }

                               logger.debug("#####totalPrice#####"+totalPrice);

                               logger.debug("#####sumPrice#####"+sumPrice);                        

                       }

                       JSONObject jobj = new JSONObject();

                       jobj.put("SUM_PRICE", sumPrice);

                       return jobj.toString();

               }catch(Exception e) {

                       e.printStackTrace();

                       return "error|" + e.getMessage();

               }

       }


       @Override

       public void setRequest(HttpServletRequest arg0) {

               this.request = arg0;

       }


}


    • Go to App Designer and open entity "Doc Order Request Item - Back Office" then click edit at module "Supplier" and find module id at property name "Module ID"
    • Replace "MD8321225761_session" with module id from step 1.1 (concate module id with "_session")


  1. From ONEWEB workspace, open java file name "/MasterWeb/WebContent/manual/js/doc/order/order_request_item_back_office_update_mode.js" and add new function with coding below.


function MD8321225761manualJS(){

       var dataString = '';

       var uri = "/MasterWeb/ManualServlet?className=com.manual.doc.order.ajax.CalculateOrderRequestItemSummaryPrice";

       jQuery.ajax({

               type : "POST",

               url : uri,

               data : dataString,

               async : false,

               success : function(data) {

                       var obj = JSON.parse(data);

                       console.log('#####MD5801448545manualJS Ajax Success obj#####', obj);

                       $('#MD9443222701_SUMMARY_PRICE_InputField [name="SUMMARY_PRICE"]').val(moneyFormat(obj.SUM_PRICE));

               }

       });

}


    • Replace "MD8321225761" at function name with module id from step 1.1
    • 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"
    • Replace  "MD9443222701" with module id from step 2.2


  1. From ONEWEB workspace, export EafMasterEar.ear and deploy update to server. The class name "com.manual.doc.order.ajax.CalculateOrderRequestItemSummaryPrice" and java script file name "/MasterWeb/WebContent/manual/js/doc/order/order_request_item_back_office_update_mode.js" will update to server.


  1. Test by log in to FrontWeb.
    • Login with Back Office user.
    • Go to To Do List and claim job.
    • Click edit Order Item.
    • Click edit Supplier and save.
    • The system must calculate summary to Summary Price.