Summary Price per order item

Learn about step to summary data by using Ajax.

Requirement

System must calculate 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;
	}

}

1.1. 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" 1.2. Replace "MD8321225761_session" with module id from step 1.1 (concate module id with "_session")

2. 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));
		}
	});
}

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

3. 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.

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. The system must calculate summary to Summary Price.

Last updated