Validate Order Unit and calculate Total Price
// 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';
}
}Last updated
