Can someone help me fix code by me sharing my screen in Javascript? Spent 1 week debugging with no luck.

Joined
Oct 24, 2013
Messages
43
Reaction score
0
I have code written by someone and I have been told to fix dates and amounts issues which I have been debugging for a week with no luck. We can connect using a desktop-sharing app for further explanation and debugging. Txs.
 
Joined
Oct 24, 2013
Messages
43
Reaction score
0
I have code written by someone and I have been told to fix dates and amounts issues which I have been debugging for a week with no luck. We can connect using a desktop-sharing app for further explanation and debugging. Txs.
I have hardcoded all the variables here.
relevant code: in multiple posts because of the character limit:
const globalEventID = “23337888”;
const globalOwnerID = “88635481”;
const globalOpportunityID = “198737470”;
const globalOpportunityTypeID = “28701”;
const globalIsGlobalHealth = globalOpportunityTypeID == “28704” ? true : false;
const globalIsBudgetAmendment = “1” == “1” ? true : false;
const globalIsCTU = globalOpportunityTypeID == “28705” || globalOpportunityTypeID == “28710” ? true : false;
const globalPaymentPendingStatusID = “76222”;
const globalPaymentPaidStatusID = “76119”;
const globalPaymentDraftStatusID = “75938”;
const globalTentativePaymentTypeID = “76333”;
const globalTentativeDisbursementTypeID = “76334”;
const globalPaymentTypeID = “76089”;
const globalDisbursementTypeID = “76120”;
const globalContractOrganisationID = “” != “” ? “” : “1749016”;
const globalRefundTypeID = “76276”;
const globalTentativeOwnerID = “” != “” ? “” : “88635481”;
const globalFundingStream = “17”;
const globalContractOrganisation = “” != “” ? “” : “Imperial College London”;
const arrJointFunding = “”.split(“|;|”).filter(function (value) { return value != undefined && value != “”; });
const globalIsJointFunding = arrJointFunding.length == 5 ? true : false;//should only ever be one
const globalNumTotalCost = Number(“2673754.6”) + (“£128,000.00” == “” ? 0 : Number(“128000.00”));
const globalNumOriginalDuration = Number(“39”);
var numCurrentDuration = globalNumOriginalDuration + Number(“12”);
var globalAppStartDate = “” != “” ? new Date(" 00:00:00.000") : new Date(“2023-01-01 00:00:00.000”);
var globalPrevAppStartDate = “2023-01-01” != “” ? new Date(“2023-01-01 00:00:00.000”) : new Date(“2023-01-01 00:00:00.000”);
var globalAppOrgEndDate = new Date(“2026-03-31 00:00:00.000”);
var globalAppEndDate = new Date(globalAppStartDate);
var strAppStartDate = “” != “” ?
‘’ :
‘01 January 2023’;



const globalDateOptions = { day: '2-digit', month: '2-digit', year: 'numeric' };
var globalArrYearlyTotals = [

750674.55,
847703.81,
861544.96,
261831.28,
80000
];
var globalFlatYearlyTotals = ;
var globalPaymentsDisburesements = ;
var globalDisbursements = ;
var globalReprofiledDisbursements; // map
var globalPaymentsToDelete = ;
var globalArrRefundPayments = ;



var globalInitialWithheldPercent;
var globalExceptionOccurred = false;
var numAjaxRequests = 0;
var arrJSONVars = [];
var globalNumYears = 0;
var globalArrEventIDs = [];
var objPayments;
var globalRefundAmountTotal = 0;
var globalPaidAmountTotal = 0;
var globalDisbursementAdjustment;
var globalBoolRevisedDate = "" != "" ? true : false;
var globalDteRevisedDate = " 00:00:00.000";
var globalPaidArr = [];
let globalLastYearRowsCount = 0;
 
Joined
Oct 24, 2013
Messages
43
Reaction score
0
I have code written by someone and I have been told to fix dates and amounts issues which I have been debugging for a week with no luck. We can connect using a desktop-sharing app for further explanation and debugging. Txs.
function processStartDateChanged(strFrequency, dtNewStartDate = false, numfullDuration = false)
{
try
{ console.log("processStartDateChanged", "strFrequency", strFrequency, "dtNewStartDate", dtNewStartDate, "numfullDuration", numfullDuration);
let dtAppStartDate = dtNewStartDate ? dtNewStartDate : globalAppStartDate;
let dtAppEndDate = globalAppEndDate;

let duration = 0;
let newPayments = [];

let paymentFrequency = 0;
switch (strFrequency)
{
case "Quarterly":
paymentFrequency = 3;
break;
case "Monthly":
paymentFrequency = 1;
break;
case "Biannual":
paymentFrequency = 6;
break;
case "Yearly":
paymentFrequency = 12;
break;
case "Single":
default:
paymentFrequency = 0;
break;
}

// duration = globalNumOriginalDuration;
duration = numfullDuration ? globalNumOriginalDuration : 0;

let dtFirstPaymentDate;
if (dtNewStartDate)
{
dtFirstPaymentDate = new Date(dtAppStartDate); console.log("a - setDate", dtFirstPaymentDate);
dtFirstPaymentDate.setDate(dtFirstPaymentDate.getDate() - 3); console.log("b - setDate", dtFirstPaymentDate);
dtFirstPaymentDate.setMonth(dtFirstPaymentDate.getMonth() + paymentFrequency + 1); console.log("c - setDate", dtFirstPaymentDate);
dtFirstPaymentDate.setDate(1); console.log("e - setDate", dtFirstPaymentDate);
}
else
{
dtFirstPaymentDate = getPaymentDate(dtAppStartDate, strFrequency)
}
console.log("a - dtFirstPaymentDate", dtFirstPaymentDate, "a - dtAppStartDate", dtAppStartDate);
if (strFrequency == "Single")
{
newPayment = {};
newPayment["recordid"] = "new";
// numPaymentPeriod of the Single payments should be the same as the payment period of the Withheld
newPayment["cf_numPaymentPeriod"] = Math.ceil(numCurrentDuration / 12); // year 1 or year 2...
newPayment["cf_txtFrequency"] = strFrequency;
newPayment["cf_txtType"] = "Contract";
newPayment["cf_numRequestedAmount"] = 0;
newPayment["sf_Status Caption"] = "New";
newPayment["sf_Status ID"] = globalPaymentDraftStatusID;
newPayment["cf_dtePaymentDate"] = formatDate(dtFirstPaymentDate, "YYYY-MM-DD");
newPayment["cf_dteActualPaymentDate"] = formatDate(dtFirstPaymentDate, "YYYY-MM-DD");
newPayment["period"] = 0;
newPayment["newperiod"] = numCurrentDuration;
// new1
newPayment["cf_lkupContractingOrganisationL2"] = globalContractOrganisationID;
newPayment["cf_txtPayee"] = globalContractOrganisation;
newPayment["cf_cmbFundingStream"] = globalFundingStream;
//
newPayments.push(newPayment);
}
else
{
let dtCurrentPaymentDate = new Date(dtFirstPaymentDate);

let count = 0;
// we need to find the length of the first period
let periodLength = monthDiff(dtAppStartDate, dtFirstPaymentDate) + 1;
while (duration <= numCurrentDuration)
{
if(duration === numCurrentDuration) {
periodLength = paymentFrequency;
}
else {
if (numCurrentDuration - duration < paymentFrequency) {
periodLength = numCurrentDuration - duration;
}
}

newPayment = {};

newPayment["recordid"] = "new" + (count == 0 ? duration + 1 : duration);
if (count == 0)
{
duration += paymentFrequency + 1;
}
else {
duration += periodLength;
}

// we want to calculate the period number by the first month of the payment
newPayment["cf_numPaymentPeriod"] = Math.ceil((duration - periodLength + 1) / 12); // year 1 or year 2...
newPayment["cf_txtFrequency"] = strFrequency;
newPayment["cf_txtType"] = "Contract";
newPayment["cf_numRequestedAmount"] = 0;
newPayment["sf_Status Caption"] = "New";
newPayment["sf_Status ID"] = globalPaymentDraftStatusID;
newPayment["cf_dtePaymentDate"] = formatDate(dtCurrentPaymentDate, "YYYY-MM-DD");
newPayment["cf_dteActualPaymentDate"] = formatDate(dtCurrentPaymentDate, "YYYY-MM-DD");
// new1
newPayment["cf_lkupContractingOrganisationL2"] = globalContractOrganisationID;
newPayment["cf_txtPayee"] = globalContractOrganisation;
newPayment["cf_cmbFundingStream"] = globalFundingStream;
//
newPayment["period"] = 0;
newPayment["newperiod"] = periodLength;
newPayments.push(newPayment);

if (count == 0)
{
// change period length, might be different only at the first step, cause the project might start from the middle of the payment period
periodLength = paymentFrequency;
}
count++;

if (strFrequency == "Monthly" || strFrequency == "Yearly")
{
// calculate the date of the next payment - first day of the month
dtCurrentPaymentDate = new Date(dtCurrentPaymentDate.getFullYear(), dtCurrentPaymentDate.getMonth() + paymentFrequency, 1);
}
else
{
// calculate the date of the next payment - last day of the month
dtCurrentPaymentDate = new Date(dtCurrentPaymentDate.getFullYear(), dtCurrentPaymentDate.getMonth() + paymentFrequency + 1, 0);
}
console.log("dtCurrentPaymentDate", dtCurrentPaymentDate);
}
}

// add first withheld
newPayment = {};
newPayment["recordid"] = "new_withheld1";
newPayment["cf_txtType"] = "Withheld 1";
// numPaymentPeriod of Withheld payments should be the same as the payment period of the last payment
newPayment["cf_numPaymentPeriod"] = Math.ceil(numCurrentDuration / 12);
newPayment["cf_numRequestedAmount"] = 0;
newPayment["sf_Status Caption"] = "New";
newPayment["sf_Status ID"] = globalPaymentDraftStatusID;
let dtNewPaymentDate = new Date(dtAppEndDate.getFullYear(), dtAppEndDate.getUTCMonth() + 7, 1);
newPayment["cf_dtePaymentDate"] = formatDate(dtNewPaymentDate, "YYYY-MM-DD");
newPayment["cf_dteActualPaymentDate"] = formatDate(dtNewPaymentDate, "YYYY-MM-DD");
// new1
newPayment["cf_lkupContractingOrganisationL2"] = globalContractOrganisationID;
newPayment["cf_txtPayee"] = globalContractOrganisation;
newPayment["cf_cmbFundingStream"] = globalFundingStream;
//
newPayments.push(newPayment);

if (!globalIsGlobalHealth) // 2 withheld payments
{
// add second withheld
newPayment = {};
newPayment["recordid"] = "new_withheld2";
newPayment["cf_txtType"] = "Withheld 2";
newPayment["cf_numRequestedAmount"] = 0;
// numPaymentPeriod of Withheld payments should be the same as the payment period of the last payment
newPayment["cf_numPaymentPeriod"] = Math.ceil(numCurrentDuration / 12);
newPayment["sf_Status Caption"] = "New";
newPayment["sf_Status ID"] = globalPaymentDraftStatusID;
dtNewPaymentDate = new Date(dtAppEndDate.getFullYear(), dtAppEndDate.getUTCMonth() + 25, 1);
newPayment["cf_dtePaymentDate"] = formatDate(dtNewPaymentDate, "YYYY-MM-DD");
newPayment["cf_dteActualPaymentDate"] = formatDate(dtNewPaymentDate, "YYYY-MM-DD");
// new1
newPayment["cf_lkupContractingOrganisationL2"] = globalContractOrganisationID;
newPayment["cf_txtPayee"] = globalContractOrganisation;
newPayment["cf_cmbFundingStream"] = globalFundingStream;
//
newPayments.push(newPayment);
}

// console.log("newPayments", newPayments);
return newPayments;
}
catch (ex)
{
alert("Error in processStartDateChanged(): " + ex.toString());
disableAll();
return false;
}
}
 
Joined
Oct 24, 2013
Messages
43
Reaction score
0
I have code written by someone and I have been told to fix dates and amounts issues which I have been debugging for a week with no luck. We can connect using a desktop-sharing app for further explanation and debugging. Txs.
function processOriginalPayments(objResults, objTentativePayments)
{
try
{
console.log("processOriginalPayments", objResults, "globalPrevAppStartDate", globalPrevAppStartDate, "globalAppStartDate",globalAppStartDate, "globalAppEndDate", globalAppEndDate, "globalAppOrgEndDate",globalAppOrgEndDate);

let newPayments = [];
let records = [];
let isStartDateChanged = false;
let isTentative = objTentativePayments != null && objTentativePayments.records && objTentativePayments.records.length > 0;

if (objResults && objResults.records && objResults.records.length > 0)
{
let numLength = objResults.records.length;
for (let i = 0; i < numLength; i++)
{
let record = objResults.records;
records.push(record);
}
}

if (objTentativePayments && objTentativePayments.records && objTentativePayments.records.length > 0)
{
// we are merging "Paid" payments with Tentative payments
// objResults will have Paid Payments if any
let numLength = objTentativePayments.records.length;
for (let i = 0; i < numLength; i++)
{
let record = objTentativePayments.records;
records.push(record);
}
}

$tbPayments.empty();

if (globalPrevAppStartDate.getTime() !== globalAppStartDate.getTime())
{
isStartDateChanged = true;

if (objTentativePayments && objTentativePayments.records && objTentativePayments.records.length > 0)
{
let numLength = objTentativePayments.records.length;
for (let i = 0; i < numLength; i++)
{
let record = objTentativePayments.records;
globalPaymentsToDelete.push(record["sf_Level Two ID"]);
}
}

if (globalBoolRevisedDate)
{
let arrPaidPayments = objResults.records.filter(function (el)
{
if (el["sf_Status ID"] == "76119")
{
let numPaidAmount = el["cf_numRequestedAmount"]
globalPaidAmountTotal += Number(numPaidAmount);
return true;
}
return false;
});

globalPaidArr = arrPaidPayments;

let monthDif = monthDiff(new Date("@parent.dteCurrentStartDate@ 00:00:00.000"), new Date(globalDteRevisedDate));
numCurrentDuration -= monthDif;
}

newPayments = processStartDateChanged(records[0]["cf_txtFrequency"], false, false);
}
else
{
if (records && records.length > 0)
{
if (globalAppEndDate.getTime() !== globalAppOrgEndDate.getTime())
{
// remove last withheld
records.pop();
if (!globalIsGlobalHealth) // remove 2nd withheld
{
records.pop();
}

let dtLastPaymentEndDate = new Date(records[records.length - 1]["cf_dtePaymentDate"] + " 00:00:00.000"); console.log("dtLastPaymentEndDate", dtLastPaymentEndDate);

// Remove one more payment if date passed the current end date on application
if (globalAppOrgEndDate > globalAppEndDate)
{
while (dtLastPaymentEndDate > globalAppOrgEndDate)
{
records.pop();
dtLastPaymentEndDate = new Date(records[records.length - 1]["cf_dtePaymentDate"] + " 00:00:00.000");
}
}

let addedPayment = [];
addedPayment = processStartDateChanged(records[0]["cf_txtFrequency"], dtLastPaymentEndDate, true);
records = records.concat(addedPayment);
}

let numLength = records.length;

//if we already have tentative payments then we want to use here the duration that was current at the moment of tentative payments creation
let numInitialDuration = "@numTentativeDuration@" != "" ? Number("@numTentativeDuration@") : Number("@parent.txtResearchDuration@");

let dtAppStartDate = globalAppStartDate; // new Date("@parent.dteCurrentStartDate@ 00:00:00.000");
let dtAppEndDate = globalAppEndDate;

let dtPrevPaymentDate = new Date(dtAppStartDate.getFullYear(), dtAppStartDate.getMonth(), 0);
let duration = 0;
let withheldIndex = 1;

// prepare original payments according to current project duration
// add new empty payments if needed
// set "newperiod" for each payment to show how many month are covered by the pay period in updated contract
for (let i = 0; i < numLength; i++)
{
let newPayment = {};
let record = records;
let strType = record["cf_txtType"];
let strActualPaymentDate = record["cf_dteActualPaymentDate"];
let strFrequency = record["cf_txtFrequency"];
let dtActualPaymentDate = new Date(strActualPaymentDate + " 00:00:00.000");
let numPercentageWithheld = Number(record["cf_numPercentageWithheld"]);

let paymentFrequency = 0;
switch (strFrequency)
{
case "Quarterly":
paymentFrequency = 3;
break;
case "Monthly":
paymentFrequency = 1;
break;
case "Biannual":
paymentFrequency = 6;
break;
case "Yearly":
paymentFrequency = 12;
break;
case "Single":
default:
paymentFrequency = 0;
break;
}

if (i === 0 && numPercentageWithheld !== "")
{
if(numPercentageWithheld == 0) {
$optWithheld.val("0.00");
globalInitialWithheldPercent = "0.00";
}
else {
$optWithheld.val(numPercentageWithheld);
globalInitialWithheldPercent = numPercentageWithheld;
}
}
//UOSR-1727 - Minor reprofiling issues on contract variations
let numMonthDiff = monthDiff(dtPrevPaymentDate, dtActualPaymentDate);

duration += numMonthDiff;

if (strType.indexOf("Withheld") < 0)
{

if (strFrequency == "Single")
{
newPayment = record;
newPayment["period"] = numInitialDuration;
newPayment["newperiod"] = numCurrentDuration;
newPayment["cf_numPaymentPeriod"] = Math.ceil(numCurrentDuration / 12);
newPayments.push(newPayment);
}
else
{
newPayment = record;
newPayment["period"] = numMonthDiff;
// we want to calculate the period number by the first month of the payment
newPayment["cf_numPaymentPeriod"] = Math.ceil((duration - numMonthDiff + 1) / 12); // year 1 or year 2...

if (duration < numInitialDuration && duration < numCurrentDuration)
{
newPayment["newperiod"] = numMonthDiff;
newPayments.push(newPayment);
dtPrevPaymentDate = new Date(dtActualPaymentDate);
}
else
{
// period adjustment
if (duration > numInitialDuration)
{
// when the current duration > initial duration and the last payment used to cover only part of the period,
// for example last payment was in Mar 31, but the project ended on Jan 31, so the period should be 1 instead of 3 (in case of quarterly payments)
if (duration - numInitialDuration < paymentFrequency)
{
newPayment["period"] = numMonthDiff - (duration - numInitialDuration);
}
}

let newMonth = 0;

if (duration >= numCurrentDuration) // current duration is the same or smaller than the initial duration
{
if (duration - numCurrentDuration > paymentFrequency)
newMonth = 0;
else
newMonth = numMonthDiff - (duration - numCurrentDuration);
}
else // current duration is bigger than the initial duration
{
if (numMonthDiff < paymentFrequency)
{
newMonth = numCurrentDuration - duration >= paymentFrequency - numMonthDiff ? paymentFrequency : numMonthDiff + (numCurrentDuration - duration);

duration += newMonth - numMonthDiff;
}
else
{
newMonth = numMonthDiff;
}
}

newPayment["newperiod"] = newMonth;
newPayments.push(newPayment);
dtPrevPaymentDate = new Date(dtActualPaymentDate);

// we need to check if we need to create new payments when we are processing last Payment/Tentative Payment
if (i < numLength - 1 && records[i + 1]["cf_txtType"].indexOf("Withheld") >= 0)
{
// we need to create new payments only if we processed all the existing payments (the next payment is withheld)
// and the duration is still less than numCurrentDuration
while (duration < numCurrentDuration)
{
let periodLength = paymentFrequency;
if (numCurrentDuration - duration < paymentFrequency)
periodLength = numCurrentDuration - duration;

newPayment = {};
newPayment["recordid"] = "new" + duration;

duration = duration + periodLength;

// we want to calculate the period number by the first month of the payment
newPayment["cf_numPaymentPeriod"] = Math.ceil((duration - numMonthDiff + 1) / 12);
newPayment["cf_txtFrequency"] = strFrequency;
newPayment["cf_txtType"] = strType;
newPayment["cf_numRequestedAmount"] = 0;
newPayment["sf_Status Caption"] = "New";
newPayment["sf_Status ID"] = globalPaymentDraftStatusID; console.log("dtPrevPaymentDate", dtPrevPaymentDate, dtPrevPaymentDate.getFullYear(), dtPrevPaymentDate.getMonth() + paymentFrequency + 1)
let dtNewPaymentDate = new Date(dtPrevPaymentDate.getFullYear(), dtPrevPaymentDate.getMonth() + paymentFrequency + 1, 0);
dtNewPaymentDate.setDate(1);

newPayment["cf_dtePaymentDate"] = formatDate(dtNewPaymentDate, "YYYY-MM-DD");
newPayment["cf_dteActualPaymentDate"] = formatDate(dtNewPaymentDate, "YYYY-MM-DD");

newPayment["period"] = 0;
newPayment["newperiod"] = periodLength;
newPayments.push(newPayment);

dtPrevPaymentDate = new Date(dtNewPaymentDate);
}
}

}
}
}
else // withheld payments
{
newPayment = record;
// we will use this field of the Withheld payment during payment reprofiling
// it is not going to be saved to the SmartSimple
newPayment["cf_numPaymentPeriod"] = Math.ceil(numCurrentDuration / 12) + 1;

// The final report payment (first of the withheld payments) needs to be 6 months after end date plus 1 day. i.e.
// If project ends 31st July 21, final payment 1 is 1st February 22.
// Published report payment(second of withheld payments) is 24 months after end date plus 1 day.
if (withheldIndex == 1)
{
let dtNewPaymentDate = new Date(dtAppEndDate.getFullYear(), dtAppEndDate.getUTCMonth() + 7, 1);
newPayment["cf_dtePaymentDate"] = formatDate(dtNewPaymentDate, "YYYY-MM-DD");
newPayment["cf_dteActualPaymentDate"] = formatDate(dtNewPaymentDate, "YYYY-MM-DD");
}
else
{
let dtNewPaymentDate = new Date(dtAppEndDate.getFullYear(), dtAppEndDate.getUTCMonth() + 25, 1);
newPayment["cf_dtePaymentDate"] = formatDate(dtNewPaymentDate, "YYYY-MM-DD");
newPayment["cf_dteActualPaymentDate"] = formatDate(dtNewPaymentDate, "YYYY-MM-DD");
}
newPayment["newperiod"] = 1;
newPayment["period"] = 1;
newPayments.push(record);
withheldIndex++;
}

}

// calculate withheld and update budget totals
let numTotalBudget = globalArrYearlyTotals.reduce(function (acc, val) { return acc + val; }, 0);
let numWithheldAmount = numTotalBudget * $optWithheld.val() / 2;

if (globalIsGlobalHealth)
{
// this is only one payment for globalIsGlobalHealth
numWithheldAmount = numWithheldAmount * 2;
if (numWithheldAmount < 100000)
{
numWithheldAmount = 100000;
numHoldBackPercent = 100000 / numTotalBudget;
}
}
}
}

globalPayments = newPayments;

buildPaymentsTable(newPayments);

if (!isStartDateChanged)
{
// we would not care about the disbursements if the project start date has changed
getDisbursements();
}

hideSaving();
return true;
}
catch (ex)
{
alert("Error in processOriginalPayments(): " + ex.toString());
disableAll();
return false;
}
}

function buildPaymentsTable(newPayments)
{
try
{
// console.log("buildPaymentsTable", newPayments);
var arrYearlyTotals = [];

arrYearlyTotals = globalArrYearlyTotals;

let currentPaymentPeriod = 0;
let currentPaymentTotal = 0;

for (let i = 0; i < newPayments.length; i++)
{
let strHTML = "";
let record = newPayments;
let strEventID = record["recordid"];
let strPaymentPeriod = record["cf_numPaymentPeriod"];
let strFrequency = record["cf_txtFrequency"];
let strType = record["cf_txtType"];
let strPaymentDate = record["cf_dtePaymentDate"];
let numPaymentAmount = Number(record["cf_numRequestedAmount"]);

let dteTempPaymentDate = new Date(strPaymentDate + " 00:00:00.000");
let strFormattedPaymentDate;

// task 1616
// When generating the payment schedule for GH projects, the December payments need to be dated as 30th November.
// The calculations still need to work in the same way i.e. the payment still relates to the quarter for October to December,
// but we need to have the payments listed with a date of 30th November in order to be able to release the payments early and
// have the correct dates listed on the payment schedules.December payments are routinely released in November for GH.
// we are going to change the payment date only if the payment was initially scheduled on Dec 31
// if the payment's date was Dec 1 (for monthly or yearly payment, for example) then we are going to leave it - this was confirmed by Katelyn
if (globalIsGlobalHealth && dteTempPaymentDate.getMonth() === 11 && dteTempPaymentDate.getDate() === 31)
{ //GH and December

let strModTempPaymentDate = new Date(dteTempPaymentDate.getFullYear(), 11, 0); // November 30th
let strFormattedTempPaymentDate = formatDate(strModTempPaymentDate, "YYYY-MM-DD");
record["cf_dtePaymentDate"] = strFormattedTempPaymentDate;
strFormattedPaymentDate = ssConvertDate(strFormattedTempPaymentDate, "yyyy-mm-dd", "dd/mm/yyyy");
}
else
{
strFormattedPaymentDate = ssConvertDate(strPaymentDate, "yyyy-mm-dd", "dd/mm/yyyy");
}

let strStatusID = record["sf_Status ID"];
let strStatusCaption = record["sf_Status Caption"];

//if ($("#trPayment_" + strEventID).length <= 0)
{
//console.log("strType", strType);
//console.log("strPaymentPeriod", strPaymentPeriod);
//console.log("currentPaymentPeriod", currentPaymentPeriod);
if (strPaymentPeriod != currentPaymentPeriod || strType == "Withheld 1")
{
if (currentPaymentPeriod != 0)
{
//console.log("set summ", "#tdPeriodTotal_" + currentPaymentPeriod);
let $tdPrevPeriodTotal = $("#tdPeriodTotal_" + currentPaymentPeriod);
//console.log("$tdPrevPeriodTotal", $tdPrevPeriodTotal.prop("id"));
//console.log("currentPaymentTotal", currentPaymentTotal);
$tdPrevPeriodTotal.text(formatAsCurrency(currentPaymentTotal, 2, 2));
$tdPrevPeriodTotal.data("amount", currentPaymentTotal);
//console.log("$tdPrevPeriodTotal.text", $tdPrevPeriodTotal.data("amount"));
currentPaymentTotal = 0;
}
currentPaymentPeriod = strPaymentPeriod;
}
if (strType.indexOf("Withheld") < 0)//payment row
{
strHTML += "<tr>";
if (strFrequency == "Single")
{
currentPaymentPeriod = 1;
let totalBudget = arrYearlyTotals.reduce(function (acc, val) { return acc + val; }, 0);
//strHTML += "<th>All Years</th>"; // period
//strHTML += "<td></td>"; // status
//strHTML += "<td></td>"; // payment date
//strHTML += "<th class=\"text-right\" id=\"tdPeriodTotal_" + strPaymentPeriod + "\" style=\"display: none\"></th>";
//strHTML += "<th class=\"text-right\" id=\"tdNewPeriodTotal_" + strPaymentPeriod + "\" data-type=\"yearly-total\" data-amount=\"" + totalBudget + "\" style=\"display: none\">" + formatAsCurrency(totalBudget, 2, 2) + "</th>"; // updated amount
//strHTML += "</tr>";

strHTML += "<tr>";
strHTML += "<th></th>"; // period
strHTML += "<td>" + strStatusCaption + "</td>"; // status
strHTML += "<td class=\"text-center\">" + strFormattedPaymentDate + "</td>"; // payment date
strHTML += "<td class=\"text-right\" data-type=\"payment\" id=\"tdPayment_" + strEventID + "\" data-type=\"payment\" data-amount=\"" + numPaymentAmount + "\">" + (numPaymentAmount == 0 ? "N/A" : formatAsCurrency(numPaymentAmount, 2, 2)) + "</td>"; // original amount
strHTML += "<td class=\"text-right\" data-type=\"newpayment\" id=\"tdNewPayment_" + strEventID + "\" data-amount=\"\"></td>"; // updated amount
currentPaymentTotal += numPaymentAmount;
}
else
{
//if (arrYearsAdded.indexOf(strPaymentPeriod) < 0)
//{
/*
// add totals row
strHTML += "<th>Year " + strPaymentPeriod + "</th>"; // period
strHTML += "<td></td>"; // status
strHTML += "<td></td>"; // payment date
strHTML += "<th class=\"text-right\" id=\"tdPeriodTotal_" + strPaymentPeriod + "\" style=\"display: none\"></th>"; // original amount
strHTML += "<th class=\"text-right\" id=\"tdNewPeriodTotal_" + strPaymentPeriod + "\" data-type=\"yearly-total\" data-amount=\"" + arrYearlyTotals[strPaymentPeriod - 1] + "\" style=\"display: none\">" + formatAsCurrency(arrYearlyTotals.length > strPaymentPeriod - 1 ? arrYearlyTotals[strPaymentPeriod - 1] : 0, 2, 2) + "</th>"; // updated amount
strHTML += "<th></th><th></th>";
strHTML += "</tr>";
strHTML += "<tr>";
*/
//arrYearsAdded.push(strPaymentPeriod);
//}
currentPaymentTotal += Number(numPaymentAmount);

let changeClass = "";
let paidClass = "";

// request payments should be included in reprofiling
if (/strStatusID == globalPaymentPendingStatusID ||/ strStatusID == globalPaymentPaidStatusID)
{
changeClass = "nochange";
paidClass = "paid";
}

strHTML += "<th></th>"; // period
strHTML += "<td>" + strStatusCaption + "</td>"; // status
strHTML += "<td class=\"text-center\">" + strFormattedPaymentDate + "</td>"; // payment date
strHTML += "<td class=\"text-right " + changeClass + " " + paidClass + "\" id=\"tdPayment_" + strEventID + "\" data-type=\"payment\" data-amount=\"" + numPaymentAmount + "\">" + (numPaymentAmount == 0 ? "N/A" : formatAsCurrency(numPaymentAmount, 2, 2)) + "</td>"; // original amount
strHTML += "<td class=\"text-right " + changeClass + "\" data-period=\"" + strPaymentPeriod + "\" data-type=\"newpayment\" id=\"tdNewPayment_" + strEventID + "\" data-amount=\"\"></td>"; // updated amount
}
strHTML += "</tr>";
}
else//Withheld row
{
strHTML += "<tr>";
strHTML += "<th></th>"; // period
strHTML += "<td>" + strType + "</td>"; // status
strHTML += "<td class=\"text-center\">" + strFormattedPaymentDate + "</td>"; // payment date
strHTML += "<td class=\"text-right\" id=\"tdPayment_" + strEventID + "\" data-type=\"withheld\" data-amount=\"" + numPaymentAmount + "\">" + (numPaymentAmount == 0 ? "N/A" : formatAsCurrency(numPaymentAmount, 2, 2)) + "</td>"; // original amount
strHTML += "<td class=\"text-right\" id=\"tdNewPayment_" + strEventID + "\" data-type=\"newwithheld\" data-amount=\"\"></td>"; // updated amount
//strHTML += "<td class=\"text-right\" id=\"tdNewPayment_" + strEventID + "\" data-type=\"newwithheld\" data-amount=\"" + numWithheldAmount + "\">" + formatAsCurrency(numWithheldAmount, 2, 2) + "</td>"; // updated amount
strHTML += "</tr>";
}

}
$tbPayments.append(strHTML);
}

if (globalArrRefundPayments.length > 0)
{
for (let i = 0; i < globalArrRefundPayments.length; i++)
{
let record = globalArrRefundPayments;
let numRefundAmount = record["cf_numRequestedAmount"];
let dteRefundDateRaw = record["cf_dteActualPaymentDate"];
let strEventID = record["recordid"];
let strHTML = "";
let dteRefundDate = dteRefundDateRaw != "" ? new Date(dteRefundDateRaw + " 00:00:00.000") : null;
let strFormattedTempRefundDate = formatDate(dteRefundDate, "YYYY-MM-DD");
let strFormattedRefundDate = ssConvertDate(strFormattedTempRefundDate, "yyyy-mm-dd", "dd/mm/yyyy");

numRefundAmount != "" ? Math.abs(numRefundAmount) * -1 : 0;

strHTML += "<tr>";
strHTML += "<th></th>"; // period
strHTML += "<td>Refund</td>"; // status
strHTML += "<td class=\"text-center\">" + strFormattedRefundDate + "</td>"; // payment date
strHTML += "<td class=\"text-right nochange refund\" id=\"tdRefund_" + strEventID + "\" data-type=\"refund\" data-amount=\"" + numRefundAmount + "\">" + (numRefundAmount == 0 ? "N/A" : formatAsCurrency(numRefundAmount, 2, 2)) + "</td>";
strHTML += "<td class=\"text-right nochange refund\" id=\"tdRefund2_" + strEventID + "\" data-type=\"newrefund\" data-amount=\"" + numRefundAmount + "\">" + (numRefundAmount == 0 ? "N/A" : formatAsCurrency(numRefundAmount, 2, 2)) + "</td>";
strHTML += "</tr>";

$tbPayments.find("tr").each(function (index, tr)
{
let $tr = $(this);//tr;
let strDate = $tr.find("td:eq(1)").text();
let dtePaymentDate = strDate != "" ? new Date(ssConvertDate(strDate, "dd/mm/yyyy", "yyyy-mm-dd")) : null;

// console.log(index, dteRefundDate, dtePaymentDate);
if (dteRefundDate && dtePaymentDate && dteRefundDate < dtePaymentDate)
{
$tr.before(strHTML);
return false;
}
});
}
}

if (globalBoolRevisedDate)
{
if (globalPaidArr.length > 0)
{
for (let i = 0; i < globalPaidArr.length; i++)
{
let record = globalPaidArr;
let numPaidAmount = record["cf_numRequestedAmount"];
let dtePaidDateRaw = record["cf_dteActualPaymentDate"];
let strEventID = record["recordid"];
let strHTML = "";
let dtePaidDate = dtePaidDateRaw != "" ? new Date(dtePaidDateRaw + " 00:00:00.000") : null;
let strFormattedPaidDate = ssConvertDate(dtePaidDateRaw, "yyyy-mm-dd", "dd/mm/yyyy");

// globalPaidAmountTotal += Number(numPaidAmount);

strHTML += "<tr>";
strHTML += "<th></th>"; // period
strHTML += "<td>Paid</td>"; // status
strHTML += "<td class=\"text-center\">" + strFormattedPaidDate + "</td>"; // payment date
strHTML += "<td class=\"text-right\" id=\"tdPaid_" + strEventID + "\" data-type=\"paid\" data-amount=\"" + numPaidAmount + "\">" + (numPaidAmount == 0 ? "N/A" : formatAsCurrency(numPaidAmount, 2, 2)) + "</td>";
strHTML += "<td class=\"text-right\" id=\"tdPaid2_" + strEventID + "\" data-type=\"newpaid\" data-amount=\"" + numPaidAmount + "\">" + (numPaidAmount == 0 ? "N/A" : formatAsCurrency(numPaidAmount, 2, 2)) + "</td>";
strHTML += "</tr>";

$tbPayments.find("tr").each(function (index, tr)
{
let $tr = $(this);//tr;
let strDate = $tr.find("td:eq(1)").text();
let dtePaymentDate = strDate != "" ? new Date(ssConvertDate(strDate, "dd/mm/yyyy", "yyyy-mm-dd")) : null;

// console.log(index, dtePaidDate, dtePaymentDate);
if (dtePaidDate && dtePaymentDate && dtePaidDate < dtePaymentDate)
{
$tr.before(strHTML);
return false;
}
});
}
}
}

let grantTotal = sumTDAttr("td[data-type='payment'],td[data-type='withheld']", false, "amount", null);

$tdGrandTotal.html(grantTotal == 0 ? "N/A" : formatAsCurrency(grantTotal, 2, 2));
$tdFinalTotal.html(grantTotal == 0 ? "N/A" : formatAsCurrency(grantTotal - globalRefundAmountTotal, 2, 2));
//let newGrandTotal = sumTDAttr("th[data-type='yearly-total'],td[data-type='newwithheld']", false, "amount", null);
//let newGrandTotal = sumTDAttr("th[data-type='yearly-total']", false, "amount", null);

let newGrandTotal = globalArrYearlyTotals.reduce(function (acc, val) { return acc + val; }, 0);
// $tdNewGrandTotal.html(formatAsCurrency(newGrandTotal, 2, 2));
// $tdNewGrandTotal.data("amount", newGrandTotal);
if (!globalBoolRevisedDate) {
newGrandTotal -= globalRefundAmountTotal;
}

$tdNewGrandTotal.html(formatAsCurrency(newGrandTotal, 2, 2));
$tdNewGrandTotal.data("amount", newGrandTotal);

$tdNewFinalTotal.html(formatAsCurrency(newGrandTotal, 2, 2));
}
catch (ex)
{
alert("Error in buildPaymentsTable(): " + ex.toString());
//disableAll();
return false;
}
}
 
Joined
Oct 24, 2013
Messages
43
Reaction score
0
I have code written by someone and I have been told to fix dates and amounts issues which I have been debugging for a week with no luck. We can connect using a desktop-sharing app for further explanation and debugging. Txs.

function reprofileSchedule()
{
try
{
console.log("reprofileSchedule - begin");

// recalculate withheld payments
let grandTotal = Number($tdNewGrandTotal.data("amount"));
let newWithheldTotal = grandTotal * $optWithheld.val();
let finalWithhelpPercent = $optWithheld.val();
//let getRecordswithBadFrequency = [];

// empty the array
globalPaymentsDisburesements = [];

if (globalIsGlobalHealth)
{
// this is only one payment for globalIsGlobalHealth
if (newWithheldTotal < 100000)
{
newWithheldTotal = 100000;
}
finalWithhelpPercent = newWithheldTotal / grandTotal;

// console.log("finalWithhelpPercent 1", finalWithhelpPercent, newWithheldTotal, grandTotal);
}
else
{
// we have two withheld payment for other application types
// console.log("newWithheldTotal 1", newWithheldTotal, newWithheldTotal / 2);
newWithheldTotal = newWithheldTotal / 2;
}

if ($optProfile.val() == "Flat")
{
console.log("flat");
let remainedAmount = globalArrYearlyTotals.reduce(function (acc, val) { return acc + val; }, 0);

let reprofilingPeriod = 0;

for (let i = 0; i < globalPayments.length; i++)
{
let record = globalPayments;
let strEventID = record["recordid"];
let strType = record["cf_txtType"];
let numPaymentAmount = Number(record["cf_numRequestedAmount"]);
let strStatusID = record["sf_Status ID"];
let monthCount = record["newperiod"];

if (strType.indexOf("Withheld") >= 0 || /strStatusID == globalPaymentPendingStatusID ||/ strStatusID == globalPaymentPaidStatusID)
{
//console.log("strType", strType);
let $tdNew = $("#tdNewPayment_" + strEventID);
let $td = $("#tdPayment_" + strEventID);
if (strType.indexOf("Withheld") >= 0)
{
// we want to subtract the withheld amount according to the number if withheld payments (1 or 2)
remainedAmount -= newWithheldTotal;
$tdNew.text(formatAsCurrency((newWithheldTotal), 2, 2));
$tdNew.data("amount", newWithheldTotal);
}
else
{
// we copy the data for the paid payments
remainedAmount -= numPaymentAmount;
$tdNew.text($td.text());
$tdNew.data("amount", $td.data("amount"));
}
}
else
{
reprofilingPeriod += monthCount;
}
}

if (globalBoolRevisedDate)
{
remainedAmount -= globalPaidAmountTotal + globalRefundAmountTotal;
}

// new monthly payment
let flatPayment = (remainedAmount / reprofilingPeriod).toFixed(2);
let newTotal = flatPayment * reprofilingPeriod;
// adjustment will be applied to the first payment
let centsAdjustments = newTotal - remainedAmount;
let firstPayment = true;

for (let i = 0; i < globalPayments.length; i++)
{
let strEventID = globalPayments["recordid"];
let strType = globalPayments["cf_txtType"];
let strStatusID = globalPayments["sf_Status ID"];
let monthCount = globalPayments["newperiod"];
let disbursements = [];

if (strType.indexOf("Withheld") == -1 && /strStatusID != globalPaymentPendingStatusID &&/ strStatusID != globalPaymentPaidStatusID)
{
let $td = $("#tdNewPayment_" + strEventID);
let paymentMonthCount = globalPayments["newperiod"];//$td.data("month");
let numPaymentAmount = flatPayment * paymentMonthCount - (firstPayment ? centsAdjustments : 0);

$td.text(formatAsCurrency(numPaymentAmount, 2, 2));
$td.data("amount", numPaymentAmount);

console.log("flatPayment", numPaymentAmount, monthCount, paymentMonthCount);

globalPayments["cf_numRequestedAmount"] = numPaymentAmount;

for (j = 0; j < monthCount; j++)
{
disbursements.push(firstPayment && j == 0 ? (flatPayment - centsAdjustments) : flatPayment);
}
firstPayment = false;
}

if (strType.indexOf("Withheld") > -1)
{
let $td = $("#tdNewPayment_" + strEventID);
globalPayments["cf_numRequestedAmount"] = newWithheldTotal;
disbursements.push(newWithheldTotal);
}

globalPaymentsDisburesements.push(disbursements);
}
}
else // reprofile by yearly budget amount
{
console.log("yearly");
var arrYearlyTotals = [];
var arrYearlyMonths = [];

// prepare arrays with total amount and covered month per project year
globalArrYearlyTotals.forEach(function (value, index, array)
{
arrYearlyTotals.push(value);
});

// console.log("arrYearlyTotals", arrYearlyTotals); ///myc

for (let i = 0; i < globalArrYearlyTotals.length; i++)
{
if (numCurrentDuration > (i + 1) * 12)
{
arrYearlyMonths.push(12);
}
else
{
arrYearlyMonths.push(numCurrentDuration - i * 12)
}
}

// console.log("arrYearlyMonths", arrYearlyMonths); ///myc

// if all payments of one of the years were paid in full then we need to remove the withheld of this year from full withheld
// to calculate the final withheld percantage correctly
let withheldFromPaidPayments = 0;
/*
const highestFrequency = arr => (arr || []).sort((a,b) => arr.filter(v => v===a).length - arr.filter(v => v===b).length).pop();

const getHighestFrequency = highestFrequency(globalPayments.filter(x => x.cf_txtType === "Contract").map(x => x.newperiod));
getRecordswithBadFrequency = globalPayments.filter(x => x.cf_txtType === "Contract" && x.newperiod !== getHighestFrequency) || [];
globalPayments = globalPayments.map(x => x.cf_txtType === "Contract" && x.newperiod !== getHighestFrequency ? {...x, "newperiod": getHighestFrequency} : x);
*/

for (let i = 0; i < globalPayments.length; i++)
{
let record = globalPayments;
let strEventID = record["recordid"];
let strStatusID = record["sf_Status ID"];
let monthCount = record["newperiod"];
let numPaymentPeriod = record["cf_numPaymentPeriod"]
let numPaymentAmount = Number(record["cf_numRequestedAmount"]);

// if payment is already paid, then we need to adjust values in arrYearlyMonths and arrYearlyTotals arrays
if (strStatusID == globalPaymentPaidStatusID)
{
// console.log("here", monthCount, numPaymentPeriod, numPaymentAmount); ///myc
// reduce number of months that should be reduced
if (arrYearlyMonths[numPaymentPeriod - 1] < monthCount)
{
let over = monthCount - arrYearlyMonths[numPaymentPeriod - 1];
arrYearlyMonths[numPaymentPeriod - 1] = 0;
arrYearlyMonths[numPaymentPeriod] -= over;

// we need to look through the disbursements to identify the amount that should be reduce from the next period total
for (let j = 0; j < globalDisbursements.length; j++)
{
let objDisbursement = globalDisbursements[j];

// get only the disbursements of the current payment
if (objDisbursement["sf_Parent ID"] == strEventID)
{
// get the disbursement date
let dteStartDate = new Date(objDisbursement["sf_Start Date"]);
// identify how many months passed from the beginning of the project
let numDisbursementMonth = monthDiff(globalAppStartDate, dteStartDate);
// if the disbursement falls under "next" year, then remove disbursement's amount from the next year total
if (Math.floor((numDisbursementMonth + 1) / 12) == numPaymentPeriod)
{
arrYearlyTotals[numPaymentPeriod] -= Number(objDisbursement["sf_Amount"]);
}
else
{
arrYearlyTotals[numPaymentPeriod - 1] -= Number(objDisbursement["sf_Amount"]);
}
}
}

withheldFromPaidPayments += arrYearlyTotals[numPaymentPeriod - 1];
arrYearlyTotals[numPaymentPeriod - 1] = 0;
}
else
{
// console.log("here2", numPaymentPeriod, arrYearlyMonths[numPaymentPeriod - 1], monthCount, arrYearlyTotals[numPaymentPeriod - 1], numPaymentAmount); ///myc
arrYearlyMonths[numPaymentPeriod - 1] -= monthCount;
// arrYearlyTotals[numPaymentPeriod - 1] -= numPaymentAmount;
}
}
else
{
// we can have Paid payment only at the beginning of the list cause all the payments are ordered by payment date
// so one we reach unpaid payment we can break the cycle
break;
}
}


// recalculate total amount remained concidering paid payments
let remainedAmount = arrYearlyTotals.reduce(function (acc, val) { return acc + val; }, 0);
//console.log("finalWithhelpPercent", finalWithhelpPercent);
// console.log("remainedAmount", remainedAmount);

// recalculate final withheld percent concidering paid payments
if (globalIsGlobalHealth)
{
// final percent might change if newWithheldTotal = 100000 now
finalWithhelpPercent = (newWithheldTotal - withheldFromPaidPayments) / remainedAmount;
}
else
{
finalWithhelpPercent = ((newWithheldTotal * 2) - withheldFromPaidPayments) / remainedAmount;
}

// console.log("finalWithhelpPercent", newWithheldTotal, withheldFromPaidPayments, remainedAmount);

let yearMonths = 0;
let periodIndex = 0;
let arrYearlyMonthsClone = JSON.parse(JSON.stringify(arrYearlyMonths)); // clone array to add back paid months for calculations below
let numPaidPaymentTempAdjustment = 0; // Paid Payment Adjustment Amounts to the same period
let numPaidPaymentAdjustment = 0; // Paid Payment Adjustment Amounts to the same period
let numPaidPaymentPeriod = -1; // Check Period for Paid Payment Adjustments
let numPaidPaymentCounter = 0;

if (globalBoolRevisedDate) {
arrYearlyTotals[0] -= globalPaidAmountTotal + globalRefundAmountTotal;
}

for (let i = 0; i < globalPayments.length; i++)
{
//console.log("periodIndex", periodIndex);
let record = globalPayments;
console.log("record2", record, arrYearlyMonthsClone);
let strEventID = record["recordid"];
let strType = record["cf_txtType"];
let strStatusID = record["sf_Status ID"];
let monthCount = record["newperiod"];
let numPaymentPeriod = record["cf_numPaymentPeriod"]
let numPaymentAmount = Number(record["cf_numRequestedAmount"]);
let disbursements = [];

// console.log("yearMonths", yearMonths, monthCount, yearMonths + monthCount);
// we are still in the same period
if (i + 1 < globalPayments.length && (numPaymentPeriod <= globalPayments[i + 1]["cf_numPaymentPeriod"] || numPaymentPeriod >= globalPayments[i + 1]["cf_numPaymentPeriod"]))
{
//console.log("processPayment");
// find td where we are going to add an updated payment
let $tdNew = $("#tdNewPayment_" + strEventID);

// if payment is already paid, then just copy the old payment over
if (strStatusID == globalPaymentPaidStatusID)
{
let numPaidPaymentPeriodTotal = 0;
let $td = $("#tdPayment_" + strEventID);
$tdNew.text($td.text());
$tdNew.data("amount", $td.data("amount"));

// console.log("before1", arrYearlyTotals[periodIndex], arrYearlyMonthsClone[periodIndex], monthCount);
arrYearlyMonthsClone[periodIndex] += monthCount;
numPaidPaymentCounter++;

// console.log("before2", arrYearlyTotals[periodIndex], arrYearlyMonthsClone[periodIndex], monthCount);
numPaidPaymentPeriod = numPaymentPeriod;
numPaidPaymentPeriodTotal = arrYearlyTotals[periodIndex] * (1 - finalWithhelpPercent) / 12 * monthCount;
numPaidPaymentTempAdjustment += (numPaidPaymentPeriodTotal - numPaymentAmount);

// console.log("numPaidPaymentPeriodTotal", numPaidPaymentPeriodTotal, numPaymentAmount, numPaidPaymentTempAdjustment);
numPaidPaymentAdjustment = numPaidPaymentTempAdjustment / (4 - numPaidPaymentCounter);

// console.log("after", numPaidPaymentPeriod, numPaymentPeriod, arrYearlyTotals[periodIndex], arrYearlyMonthsClone[periodIndex], monthCount, numPaidPaymentAdjustment, numPaidPaymentPeriodTotal, numPaymentAmount);
}
else if (strType.indexOf("Withheld") < 0)
{
// calculate new payment
let paymentTotal = 0;

// if yearMonths < 0 it means that there are some months left from the previous pay period
if (yearMonths + monthCount > 12)
{
let prevYearMonth = 12 - yearMonths; // 2
let currentYearMonth = monthCount + yearMonths - 12; // 1
// get left months' amount from the previous pay period - we divide by 12
// having some months left from the previous period meens that that period was a full year
// let prevPeriod = arrYearlyTotals[periodIndex] * (1 - finalWithhelpPercent) * prevYearMonth / arrYearlyMonths[periodIndex];
// console.log("prevPeriod", prevYearMonth, arrYearlyTotals[periodIndex], arrYearlyMonthsClone[periodIndex]);
let prevPeriod = arrYearlyTotals[periodIndex] * (1 - finalWithhelpPercent) / arrYearlyMonthsClone[periodIndex] * prevYearMonth;
// add the amount from the current pay period
// let currentPeriod = arrYearlyTotals[periodIndex + 1] * (1 - finalWithhelpPercent) * currentYearMonth / arrYearlyMonths[periodIndex + 1];
// console.log("currentPeriod", currentYearMonth, arrYearlyTotals[periodIndex + 1], arrYearlyMonthsClone[periodIndex + 1]);
let currentPeriod = arrYearlyTotals[periodIndex + 1] * (1 - finalWithhelpPercent) / arrYearlyMonthsClone[periodIndex + 1] * currentYearMonth;

// console.log("monthCount1", prevYearMonth, prevPeriod, prevYearMonth, prevPeriod / prevYearMonth);
// console.log("monthCount2", prevYearMonth, currentPeriod, currentYearMonth, prevPeriod / prevYearMonth);
for (j = 0; j < monthCount; j++)
{
if (j < prevYearMonth)
{
disbursements.push(prevPeriod / prevYearMonth);
}
else
{
disbursements.push(currentPeriod / currentYearMonth);
}
}
paymentTotal = prevPeriod + currentPeriod;

console.log("paymentTotal1", paymentTotal, prevPeriod, currentPeriod);
}
else
{
// add the amount from the current pay period
// paymentTotal += arrYearlyTotals[periodIndex] * (1 - finalWithhelpPercent) * monthCount / arrYearlyMonths[periodIndex];
if (numPaymentPeriod === numPaidPaymentPeriod)
{
paymentTotal += arrYearlyTotals[periodIndex] * (1 - finalWithhelpPercent) / arrYearlyMonthsClone[periodIndex] * monthCount;
paymentTotal += numPaidPaymentAdjustment;
}
else
{
paymentTotal += arrYearlyTotals[periodIndex] * (1 - finalWithhelpPercent) / arrYearlyMonthsClone[periodIndex] * monthCount;
}

console.log("paymentTotal2", paymentTotal, arrYearlyTotals[periodIndex], arrYearlyMonthsClone[periodIndex], monthCount);

for (j = 0; j < monthCount; j++)
{
disbursements.push(paymentTotal / monthCount);
}
}
console.log("paymentTotal", paymentTotal, arrYearlyTotals[periodIndex], (1 - finalWithhelpPercent), 12, monthCount);
// set up new amount
$tdNew.text(formatAsCurrency(paymentTotal.toFixed(2), 2, 2));
$tdNew.data("amount", paymentTotal.toFixed(2));
}
yearMonths += monthCount;
}

// last payment of the period, next payment is next period
if (i + 1 == globalPayments.length || numPaymentPeriod < globalPayments[i + 1]["cf_numPaymentPeriod"])
{
// switch to the next period
periodIndex++;
// we need to reset the months count when we switch the period, so that we know if we still have some months left from the previous period
yearMonths -= 12;
}

if (strType.indexOf("Withheld") >= 0)
{
//console.log("newWithheldTotal", newWithheldTotal);
let $tdNew = $("#tdNewPayment_" + strEventID);
//let $td = $("#tdPayment_" + strEventID);
$tdNew.text(formatAsCurrency((newWithheldTotal), 2, 2));
$tdNew.data("amount", newWithheldTotal);
record["cf_numRequestedAmount"] = newWithheldTotal;
disbursements.push(newWithheldTotal);
}
globalPaymentsDisburesements.push(disbursements);
}
}

// // we do not need to update new grand total here, I am doing this just to make sure that the totals are matching after reprofiling
let newGrandTotal;

if (globalBoolRevisedDate)
{
newGrandTotal = sumTDAttr("td[data-type='newpayment'],td[data-type='newwithheld'],td[data-type='newpaid'],td[data-type='newrefund']", false, "amount", null);
}
else
{
newGrandTotal = sumTDAttr("td[data-type='newpayment'],td[data-type='newwithheld']", false, "amount", null);
}
// console.log("grand", grandTotal, newGrandTotal, grandTotal - newGrandTotal);

globalDisbursementAdjustment = null;
// grand adjustment
if (grandTotal != newGrandTotal)
{
let adjustment = grandTotal - newGrandTotal;
let $td = $("td:not(.nochange)[data-type='newpayment']:last");
let val = Number($td.data("amount"));
// console.log("adjustment", adjustment, val);
let numLastPaymentIndex = globalIsGlobalHealth ? globalPayments.length - 2 : globalPayments.length - 3;

// adjustments for last disbursement for reprofiling disbursement
globalDisbursementAdjustment = adjustment;
val = val + adjustment; // Math.ceil(adjustment*100)/100;

globalPayments[numLastPaymentIndex]["cf_numRequestedAmount"] = Number(val);

$td.html(formatAsCurrency(val, 2, 2));
$td.data("amount", val);

let numLastDisburesement = globalIsGlobalHealth ? globalPaymentsDisburesements.length - 2 : globalPaymentsDisburesements.length - 3;
let objDisburesements = globalPaymentsDisburesements[numLastDisburesement];
let numLastDisburesementsLength = objDisburesements ? objDisburesements.length : 0;

if (numLastDisburesementsLength && numLastDisburesementsLength > 0)
{
let numDisbAmount = val / numLastDisburesementsLength;

for (let x = 0; x < numLastDisburesementsLength; x++)
{
objDisburesements[x] = numDisbAmount
}
}
}

/*
globalPayments.forEach((list1) => {
getRecordswithBadFrequency.forEach((list2) => {
if (list2.recordid === list1.recordid) {
list1.newperiod = list2.newperiod;
}
})
})
*/

newGrandTotal = grandTotal;
$tdNewGrandTotal.html(formatAsCurrency(newGrandTotal, 2, 2));
$tdNewGrandTotal.data("amount", newGrandTotal);
// $tdNewFinalTotal.html(formatAsCurrency(newGrandTotal - globalRefundAmountTotal, 2, 2));
$tdNewFinalTotal.html(formatAsCurrency(newGrandTotal, 2, 2));

if (globalPrevAppStartDate.getTime() !== globalAppStartDate.getTime())
{
// project start date changed: we will create the full disbursements map only when we the start date changed and we need to recalculate everything
reprofileDisbursements(finalWithhelpPercent, newWithheldTotal);
}

// console.log("reprofileSchedule disb", globalPaymentsDisburesements);
$btnSave.prop("disabled", false);
}
catch (ex)
{
alert("Error in reprofileSchedule(): " + ex.toString());
//disableAll();
return false;
}
}

const objResults = {"records":[{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"56300.59","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2023","sf_Status Caption":"Draft","sf_Level Two ID":"23377769","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377769","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"1","cf_numRequestedAmountRounded":"56300.59","cf_txtType":"Contract","cf_dteActualPaymentDate":"2023-12-01","cf_dtePaymentDate":"2023-02-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"56300.59","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2023","sf_Status Caption":"Draft","sf_Level Two ID":"23377770","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377770","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"1","cf_numRequestedAmountRounded":"56300.59","cf_txtType":"Contract","cf_dteActualPaymentDate":"2024-01-01","cf_dtePaymentDate":"2023-03-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"56300.59","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2023","sf_Status Caption":"Draft","sf_Level Two ID":"23377801","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377801","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"1","cf_numRequestedAmountRounded":"56300.59","cf_txtType":"Contract","cf_dteActualPaymentDate":"2024-02-01","cf_dtePaymentDate":"2023-04-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"56300.59","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2023","sf_Status Caption":"Draft","sf_Level Two ID":"23377803","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377803","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"1","cf_numRequestedAmountRounded":"56300.59","cf_txtType":"Contract","cf_dteActualPaymentDate":"2024-03-01","cf_dtePaymentDate":"2023-05-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"56300.59","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2024","sf_Status Caption":"Draft","sf_Level Two ID":"23377805","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377805","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"1","cf_numRequestedAmountRounded":"56300.59","cf_txtType":"Contract","cf_dteActualPaymentDate":"2024-04-01","cf_dtePaymentDate":"2023-06-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"56300.59","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2024","sf_Status Caption":"Draft","sf_Level Two ID":"23377807","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377807","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"1","cf_numRequestedAmountRounded":"56300.59","cf_txtType":"Contract","cf_dteActualPaymentDate":"2024-05-01","cf_dtePaymentDate":"2023-07-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"56300.59","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2024","sf_Status Caption":"Draft","sf_Level Two ID":"23377776","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377776","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"1","cf_numRequestedAmountRounded":"56300.59","cf_txtType":"Contract","cf_dteActualPaymentDate":"2024-06-01","cf_dtePaymentDate":"2023-08-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"56300.59","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2024","sf_Status Caption":"Draft","sf_Level Two ID":"23377773","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377773","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"1","cf_numRequestedAmountRounded":"56300.59","cf_txtType":"Contract","cf_dteActualPaymentDate":"2024-07-01","cf_dtePaymentDate":"2023-09-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"56300.59","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2024","sf_Status Caption":"Draft","sf_Level Two ID":"23377777","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377777","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"1","cf_numRequestedAmountRounded":"56300.59","cf_txtType":"Contract","cf_dteActualPaymentDate":"2024-08-01","cf_dtePaymentDate":"2023-10-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"56300.59","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2024","sf_Status Caption":"Draft","sf_Level Two ID":"23377809","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377809","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"1","cf_numRequestedAmountRounded":"56300.59","cf_txtType":"Contract","cf_dteActualPaymentDate":"2024-09-01","cf_dtePaymentDate":"2023-11-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"56300.59","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2024","sf_Status Caption":"Draft","sf_Level Two ID":"23377808","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377808","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"1","cf_numRequestedAmountRounded":"56300.59","cf_txtType":"Contract","cf_dteActualPaymentDate":"2024-10-01","cf_dtePaymentDate":"2023-12-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"56300.59","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2024","sf_Status Caption":"Draft","sf_Level Two ID":"23377806","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377806","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"1","cf_numRequestedAmountRounded":"56300.59","cf_txtType":"Contract","cf_dteActualPaymentDate":"2024-11-01","cf_dtePaymentDate":"2024-01-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"63577.79","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2024","sf_Status Caption":"Draft","sf_Level Two ID":"23377804","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377804","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"2","cf_numRequestedAmountRounded":"63577.79","cf_txtType":"Contract","cf_dteActualPaymentDate":"2024-12-01","cf_dtePaymentDate":"2024-02-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"63577.79","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2024","sf_Status Caption":"Draft","sf_Level Two ID":"23377802","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377802","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"2","cf_numRequestedAmountRounded":"63577.79","cf_txtType":"Contract","cf_dteActualPaymentDate":"2025-01-01","cf_dtePaymentDate":"2024-03-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"63577.79","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2024","sf_Status Caption":"Draft","sf_Level Two ID":"23377800","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377800","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"2","cf_numRequestedAmountRounded":"63577.79","cf_txtType":"Contract","cf_dteActualPaymentDate":"2025-02-01","cf_dtePaymentDate":"2024-04-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"63577.79","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2024","sf_Status Caption":"Draft","sf_Level Two ID":"23377798","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377798","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"2","cf_numRequestedAmountRounded":"63577.79","cf_txtType":"Contract","cf_dteActualPaymentDate":"2025-03-01","cf_dtePaymentDate":"2024-05-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"63577.79","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2025","sf_Status Caption":"Draft","sf_Level Two ID":"23377796","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377796","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"2","cf_numRequestedAmountRounded":"63577.79","cf_txtType":"Contract","cf_dteActualPaymentDate":"2025-04-01","cf_dtePaymentDate":"2024-06-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"63577.79","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2025","sf_Status Caption":"Draft","sf_Level Two ID":"23377794","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377794","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"2","cf_numRequestedAmountRounded":"63577.79","cf_txtType":"Contract","cf_dteActualPaymentDate":"2025-05-01","cf_dtePaymentDate":"2024-07-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"63577.79","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2025","sf_Status Caption":"Draft","sf_Level Two ID":"23377793","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377793","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"2","cf_numRequestedAmountRounded":"63577.79","cf_txtType":"Contract","cf_dteActualPaymentDate":"2025-06-01","cf_dtePaymentDate":"2024-08-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"63577.79","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2025","sf_Status Caption":"Draft","sf_Level Two ID":"23377790","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377790","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"2","cf_numRequestedAmountRounded":"63577.79","cf_txtType":"Contract","cf_dteActualPaymentDate":"2025-07-01","cf_dtePaymentDate":"2024-09-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"63577.79","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2025","sf_Status Caption":"Draft","sf_Level Two ID":"23377788","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377788","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"2","cf_numRequestedAmountRounded":"63577.79","cf_txtType":"Contract","cf_dteActualPaymentDate":"2025-08-01","cf_dtePaymentDate":"2024-10-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"63577.79","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2025","sf_Status Caption":"Draft","sf_Level Two ID":"23377786","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377786","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"2","cf_numRequestedAmountRounded":"63577.79","cf_txtType":"Contract","cf_dteActualPaymentDate":"2025-09-01","cf_dtePaymentDate":"2024-11-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"63577.79","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2025","sf_Status Caption":"Draft","sf_Level Two ID":"23377780","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377780","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"2","cf_numRequestedAmountRounded":"63577.79","cf_txtType":"Contract","cf_dteActualPaymentDate":"2025-10-01","cf_dtePaymentDate":"2024-12-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"63577.79","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2025","sf_Status Caption":"Draft","sf_Level Two ID":"23377782","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377782","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"2","cf_numRequestedAmountRounded":"63577.79","cf_txtType":"Contract","cf_dteActualPaymentDate":"2025-11-01","cf_dtePaymentDate":"2025-01-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"64615.87","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2025","sf_Status Caption":"Draft","sf_Level Two ID":"23377771","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377771","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"3","cf_numRequestedAmountRounded":"64615.87","cf_txtType":"Contract","cf_dteActualPaymentDate":"2025-12-01","cf_dtePaymentDate":"2025-02-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"64615.87","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2025","sf_Status Caption":"Draft","sf_Level Two ID":"23377799","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377799","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"3","cf_numRequestedAmountRounded":"64615.87","cf_txtType":"Contract","cf_dteActualPaymentDate":"2026-01-01","cf_dtePaymentDate":"2025-03-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"64615.87","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2025","sf_Status Caption":"Draft","sf_Level Two ID":"23377797","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377797","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"3","cf_numRequestedAmountRounded":"64615.87","cf_txtType":"Contract","cf_dteActualPaymentDate":"2026-02-01","cf_dtePaymentDate":"2025-04-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"64615.87","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2025","sf_Status Caption":"Draft","sf_Level Two ID":"23377772","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377772","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"3","cf_numRequestedAmountRounded":"64615.87","cf_txtType":"Contract","cf_dteActualPaymentDate":"2026-03-01","cf_dtePaymentDate":"2025-05-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"64615.87","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2026","sf_Status Caption":"Draft","sf_Level Two ID":"23377774","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377774","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"3","cf_numRequestedAmountRounded":"64615.87","cf_txtType":"Contract","cf_dteActualPaymentDate":"2026-04-01","cf_dtePaymentDate":"2025-06-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"64615.87","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2026","sf_Status Caption":"Draft","sf_Level Two ID":"23377795","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377795","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"3","cf_numRequestedAmountRounded":"64615.87","cf_txtType":"Contract","cf_dteActualPaymentDate":"2026-05-01","cf_dtePaymentDate":"2025-07-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"64615.87","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2026","sf_Status Caption":"Draft","sf_Level Two ID":"23377792","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377792","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"3","cf_numRequestedAmountRounded":"64615.87","cf_txtType":"Contract","cf_dteActualPaymentDate":"2026-06-01","cf_dtePaymentDate":"2025-08-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"64615.87","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2026","sf_Status Caption":"Draft","sf_Level Two ID":"23377775","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377775","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"3","cf_numRequestedAmountRounded":"64615.87","cf_txtType":"Contract","cf_dteActualPaymentDate":"2026-07-01","cf_dtePaymentDate":"2025-09-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"64615.87","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2026","sf_Status Caption":"Draft","sf_Level Two ID":"23377783","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377783","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"3","cf_numRequestedAmountRounded":"64615.87","cf_txtType":"Contract","cf_dteActualPaymentDate":"2026-08-01","cf_dtePaymentDate":"2025-10-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"64615.87","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2026","sf_Status Caption":"Draft","sf_Level Two ID":"23377779","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377779","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"3","cf_numRequestedAmountRounded":"64615.87","cf_txtType":"Contract","cf_dteActualPaymentDate":"2026-09-01","cf_dtePaymentDate":"2025-11-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"64615.87","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2026","sf_Status Caption":"Draft","sf_Level Two ID":"23377791","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377791","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"3","cf_numRequestedAmountRounded":"64615.87","cf_txtType":"Contract","cf_dteActualPaymentDate":"2026-10-01","cf_dtePaymentDate":"2025-12-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"64615.87","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2026","sf_Status Caption":"Draft","sf_Level Two ID":"23377789","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377789","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"3","cf_numRequestedAmountRounded":"64615.87","cf_txtType":"Contract","cf_dteActualPaymentDate":"2026-11-01","cf_dtePaymentDate":"2026-01-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"64149.38","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2026","sf_Status Caption":"Draft","sf_Level Two ID":"23377787","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377787","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"4","cf_numRequestedAmountRounded":"64149.38","cf_txtType":"Contract","cf_dteActualPaymentDate":"2026-12-01","cf_dtePaymentDate":"2026-02-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"64149.38","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2026","sf_Status Caption":"Draft","sf_Level Two ID":"23377785","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377785","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"4","cf_numRequestedAmountRounded":"64149.38","cf_txtType":"Contract","cf_dteActualPaymentDate":"2027-01-01","cf_dtePaymentDate":"2026-03-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"64149.38","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2026","sf_Status Caption":"Draft","sf_Level Two ID":"23377781","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377781","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"4","cf_numRequestedAmountRounded":"64149.38","cf_txtType":"Contract","cf_dteActualPaymentDate":"2027-02-01","cf_dtePaymentDate":"2026-04-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"133687.73","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2026","sf_Status Caption":"Draft","sf_Level Two ID":"23377784","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377784","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"4","cf_numRequestedAmountRounded":"133687.73","cf_txtType":"Withheld 1","cf_dteActualPaymentDate":"2026-10-01","cf_dtePaymentDate":"2026-10-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"},{"sf_Parent ID":"198737470","cf_txtPayee":"Imperial College London","sf_Status ID":"75938","cf_numRequestedAmount":"133687.73","sf_Type ID":"76089","cf_numPaymentWithheld":"2","cf_txtPaymentFiscalYear":"2028","sf_Status Caption":"Draft","sf_Level Two ID":"23377778","cf_numPercentageWithheld":"0.1","cf_cmbManuallyUpdated":"","cf_lkupContractingOrganisationL2":"1749016","recordid":"23377778","cf_cmbFundingStream":"51","cf_numPaymentPeriod":"4","cf_numRequestedAmountRounded":"133687.73","cf_txtType":"Withheld 2","cf_dteActualPaymentDate":"2028-04-01","cf_dtePaymentDate":"2028-04-01","cf_txtFrequency":"Monthly","cf_txtProfileMethod":"Budget"}]}

processOriginalPayments(objResults, {});
There is a Reprofile Payments button on the page. When clicked, it calls reprofileSchedule() and it is supposed to divide yearly totals into months in every year and display amounts. Right now the Updated Amounts for the rows where "Payment Status" is New are wrong.
 
Joined
Nov 13, 2020
Messages
302
Reaction score
38
Have you never been on a help site before? PLEASE use the </> icon above to PASTE your code into it. It makes things smaller and easier for us to get the code to run it ourselves.
Thank You
 
Joined
Oct 24, 2013
Messages
43
Reaction score
0
Have you never been on a help site before? PLEASE use the </> icon above to PASTE your code into it. It makes things smaller and easier for us to get the code to run it ourselves.
Thank You
Sorry, will do it next time.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,064
Latest member
naturesElixirCBDReview

Latest Threads

Top