Sum total invoices to date
We are trying to sum the invoice totals of all records before today (some forward invoicing has been completed) of a custom module (client invoices) into the Accounts module. I have tried to use an if function so that if the invoice date is before today it will sum them. Below is the code, however it is not working, what am i doing wrong?
sold = zoho.crm.getRelatedRecords("Client_Invoices","Accounts",Id);
total = 0.0;
for each ele in sold
{
invmonth = ele.get("Invoice_Date").getDate();
calcdate = today;
if(invmonth >= calcdate)
{
invoices = ifnull(ele.get("TOTAL"),0.0).toDecimal();
total = total + invoices;
}
}
update = zoho.crm.updateRecord("Accounts",Id.toLong(),{"Invoiced_to_Date":total});