Learn about step to validate Order Unit and auto calculate Total Price after changing Order Unit.

Requirement

  1. Order Unit must <= In Stock and Order Unit must <= Remain Order Unit.
  2. Auto calculate Total Price after changed Order Unit.

Procedure

  1. From ONEWEB workspace, create javascript file name "/MasterWeb/WebContent/manual/js/doc/order/order_request_item_back_office_update_mode.js" 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';

       }        

}


  1. From ONEWEB workspace, export EafMasterEar.ear and deploy update to server. The javascript file name "/MasterWeb/WebContent/manual/js/doc/order/order_request_item_back_office_update_mode.js" will update to server.


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


  1. 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.
    • Change Process Name to "UPDATE".
    • Put "/MasterWeb/manual/js/doc/order/order_request_item_back_office_update_mode.js" to Script File.
    • Click OK.


  1. Click Save this Entity.


  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.
    • The system must calculate remain order unit.