FIX_ADDITION_MINUS_SYMBOL

This commit is contained in:
VENKATESHWARAN 2025-11-12 18:47:14 +05:30
parent 8cfe1fb0b8
commit 4cde80ddaa

View File

@ -1534,18 +1534,51 @@
setCoPremiums(input); setCoPremiums(input);
// ✅ Apply deletion symbols last (safely); // ✅ Apply deletion symbols last (safely);
if (isDeletion) { // if (isDeletion) {
applyDeletionSymbolsToFields(input, true); applyDeletionSymbolsToFields(input, isDeletion);
} // }
console.log('############################## END AMOUNT CALCULATION ############################################'); console.log('############################## END AMOUNT CALCULATION ############################################');
} }
// Apply Deletion (Negative) Values // Apply Deletion (Negative) Values
function applyDeletionSymbolsToFields(input, isDeletion) { // function applyDeletionSymbolsToFields(input, isDeletion) {
console.log('========== APPLYING DELETION SYMBOLS =========='); // console.log('========== APPLYING DELETION SYMBOLS ==========');
if (!isDeletion) return; // if (!isDeletion) return;
// const fieldIds = [
// 'base_premium',
// 'tp_premium',
// 'ter_premium',
// 'co_premium',
// 'co_tp_premium',
// 'co_ter_premium',
// 'gst_amount',
// 'agreed_amount',
// 'non_comm_per_amt',
// 'total_amt',
// 'exp_amt'
// ];
// fieldIds.forEach(field => {
// const $el = $('#' + field + '_' + input);
// console.log('$el', '#' + field + '_' + input);
// console.log('$el', $el);
// let val = $el.val()?.trim();
// console.log('$val', val);
// if (!val || val.startsWith('-')) return;
// let num = parseFloat(val);
// if (!isNaN(num) && num > 0) $el.val(-num);
// });
// console.log('========== COMPLETED DELETION SYMBOL APPLICATION ==========');
// }
function applyDeletionSymbolsToFields(input, isDeletion) {
console.log('========== APPLYING DELETION SYMBOLS ==========');
const fieldIds = [ const fieldIds = [
'base_premium', 'base_premium',
@ -1563,19 +1596,26 @@
fieldIds.forEach(field => { fieldIds.forEach(field => {
const $el = $('#' + field + '_' + input); const $el = $('#' + field + '_' + input);
console.log('$el', '#' + field + '_' + input);
console.log('$el', $el);
let val = $el.val()?.trim(); let val = $el.val()?.trim();
console.log('$val', val); if (!val) return;
if (!val || val.startsWith('-')) return;
let num = parseFloat(val); let num = parseFloat(val.replace(/^-/, '')); // remove any existing minus first
if (!isNaN(num) && num > 0) $el.val(-num); console.log('num', num);
if (isNaN(num)) return;
if (isDeletion) {
// Apply minus sign
if (num > 0) $el.val(-num);
} else {
// Remove minus sign
$el.val(num);
}
}); });
console.log('========== COMPLETED DELETION SYMBOL APPLICATION =========='); console.log('========== COMPLETED DELETION SYMBOL APPLICATION ==========');
} }
function setCoPremiums(input) { function setCoPremiums(input) {
// Get base, TP, and TEP premiums for the given input row // Get base, TP, and TEP premiums for the given input row
let bp = parseFloat($('#base_premium_' + input).val()) || 0; let bp = parseFloat($('#base_premium_' + input).val()) || 0;