> For the complete documentation index, see [llms.txt](https://docs.oneweb.tech/oneweb/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.oneweb.tech/oneweb/sample-apps/order-management-app-web/app-designer-customize/validate-order-unit-and-calculate-total-price.md).

# Validate Order Unit and calculate Total Price

Learn about step to validate Order Unit and auto calculate Total Price after changing Order Unit. \
**Requirement** \
&#x20;     1\. Order Unit must <= In Stock and Order Unit must <= Remain Order Unit. \
&#x20;     2\. Auto calculate Total Price after changed Order Unit.

**Procedure** \
1\. From ONEWEB workspace, create javascript file name "<mark style="background-color:blue;">/MasterWeb/WebContent/manual/js/doc/order/order\_request\_item\_back\_office\_update\_mode.js</mark>" in MasterWeb and override method "modifyInsertMany(String moduleID, HashMap hStoreHashMap, String processMode, int row)" with coding below.

```
// Auto script when open popup
function loadUpdateManyManual(){
	calPriceByInputUnit();
}

// Auto calculate field on popup
function calPriceByInputUnit(){
	$("[name=UNIT_BY_BACK_OFFICE]").change(function(){
		var stock = parseInt($("[name=IN_STOCK]").val());
		var remain = parseInt($("[name=REMAIN_ORDER_UNIT]").val());
		var getUnitBackofc = parseInt($("[name=UNIT_BY_BACK_OFFICE]").val());
		
		if(getUnitBackofc > stock || getUnitBackofc > remain){
			alert('Unit choose by backoffice must less than stock and remain');
			$("[name=UNIT_BY_BACK_OFFICE]").val('');
			$("[name=UNIT_BY_BACK_OFFICE]").focus();
		}else{
			var pricePerUnit = $("[name=UNIT_PRICE]").val();
			var totalPrice = getUnitBackofc*pricePerUnit;
			console.log('totalPrice: '+totalPrice) ;
			$('[name=TOTAL_PRICE]').val(moneyFormat(totalPrice));
		}
	});
}

// Change to money format
function moneyFormat(strMoneyA) {
	var strMoney = new String(strMoneyA);
	if(strMoney != undefined && strMoney != 'null' && strMoney != ''){
		strMoney  = strMoney.replace(/\,/g,'');
		strMoney = parseFloat(strMoney).toFixed(2);
		strMoney += '';
		x = strMoney.split('.');
		x1 = x[0];
		x2 = x.length > 1 ? '.' + x[1] : '';
		var rgx = /(\d+)(\d{3})/;
		while (rgx.test(x1)) {
			x1 = x1.replace(rgx, '$1' + ',' + '$2');
		}
		return x1 + x2;
	}else{
		return '0.00';
	}	
}
```

2\. From ONEWEB workspace, export EafMasterEar.ear and deploy update to server. The javascript file name "<mark style="background-color:blue;">/MasterWeb/WebContent/manual/js/doc/order/order\_request\_item\_back\_office\_update\_mode.js</mark>" will update to server.

3\. Go to App Designer and open entity name "**Doc Order Request Item - Back Office**" to edit.

4\. From **Tools > Action** drag **Entity Action** to the box under entity name. The action name "SEARCH" shows then click icon pencil to edit it. The dialog of Action Field Configuration opens. \
&#x20;     Change Process Name to "UPDATE". \
&#x20;     Put "<mark style="background-color:blue;">/MasterWeb/manual/js/doc/order/order\_request\_item\_back\_office\_update\_mode.js</mark>" to Script File. \
&#x20;     Click **OK**.

5\. Click **Save this Entity**.

6\. Test by log in to FrontWeb. \
&#x20;     Login with Back Office user. \
&#x20;     Go to To Do List and claim job. \
&#x20;     Click edit Order Item. \
&#x20;     Click edit Supplier. \
&#x20;     The system must calculate remain order unit.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.oneweb.tech/oneweb/sample-apps/order-management-app-web/app-designer-customize/validate-order-unit-and-calculate-total-price.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
