/*
***********************************************************************
* Copyright (c) ACL Digital
* IBC Knowledge Park, Tower D, 4/1, Bannerghatta Main Rd, S.G. Palya, Bengaluru,
Karnataka 560029
* All Rights Reserved.
*
* The following JavaScript source code is created by ACL Digital and
* is intended for use on the NetSuite (www.netsuite.com) platform.
* The code is provided "as is": ACL Digital shall not be liable for any
* damages arising out the intended use or if the code is modified
* after delivery.
*
* Company: ACL Digital (https://www.acldigital.com/)
* Author: Sambit
* Date: March 04, 2024
* Module Description: Clinet script for check the amounts of vendor bill and
assosiated PO
*
* @history
* Version Date Author Description
* 1.0 04-March-2024 Sridhar Initial
Release
*
***********************************************************************/
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
*/
define(['N/log', 'N/currentRecord', 'N/search', 'N/record'], function(log,
currentRecord, search, record) {
function saveRecord(scriptContext) {
var currentRecordObj = currentRecord.get();
var billAmount = parseFloat(currentRecordObj.getValue({fieldId:
'usertotal'}));
var poNumber = currentRecordObj.getValue({fieldId: 'custbody_cf_po_no'});
if (poNumber) {
var poSearch = search.create({
type: search.Type.PURCHASE_ORDER,
filters: ['tranid', search.Operator.IS, poNumber]
});
var poSearchResults = poSearch.run().getRange({start: 0, end: 1});
if (poSearchResults.length > 0) {
var poInternalId = poSearchResults[0].id;
var poRecord = record.load({
type: record.Type.PURCHASE_ORDER,
id: poInternalId
});
var poTotal = parseFloat(poRecord.getValue({fieldId: 'total'}));
log.debug({
title: 'Bill Save Event',
details: 'Bill record entered. Amount: ' + billAmount + ', PO
Number: ' + poNumber + ', PO Total: ' + poTotal
});
if (poTotal !== billAmount) {
alert("Bill Amount doesn't match with Purchase Order!");
return false;
}
}
}
return true;
}
return {
saveRecord: saveRecord
};
});