Zoho Invoices Custom Function - Automate the calculation of some fields

Zoho Invoices Custom Function - Automate the calculation of some fields

So I am using zoho invoices to manage our company's invoices. Recently we needed to add 4 custom fields which are :
1- Number of payments the customer needs to make [ field label is : No of Payments ]
2- Frequency of payments, that is, how frequently the customer needs to make the payment per month [ field label is : Freq of Payments ]
3- Next Payment Amount [ field lablel is : Next Payment amount ]. This one should be auto calculated as follows: 
Next Payment amount = Balance / No of Payments. 
4- Next Billing Date [ field label is Next Billing Date ]. Also auto calculated as follows :
Next Billing Date = invoice date + Frequency of payment. 

The four custom fields above are created and shown in the invoice module fields. 

I created the below code with a workflow but the function executes successfully without any value on next payment amount and next billing date.

<-----------Beginning of the code ------------->

invoiceNumber = invoice.get("Invoice#").toLong();
invoicedate = invoice.get("Date").toDate();
organizationID = organization.get("organization_id").toString();
Balance_N = invoice.get("Balance").toDecimal();
Date_Invoice = invoice.get("Date");
NextPaymentAmount = null;
NextBillingDate = null;
customFieldList = invoice.get("custom_fields").toList();
for each  customField in customFieldList
{
customFieldMap = customField.toMap();
if(customFieldMap.get("label") == "No Of Payments")
{
NoPayments = customFieldMap.get("value");
}
if(customFieldMap.get("label") == "Freq_of_Payments")
{
FreqOfPayments = customFieldMap.get("value");
}
if(customFieldMap.get("label") == "Next_Payment_amount")
{
NextPaymentAmount = customFieldMap.get(Balance_N / NoPayments);
}
if(customFieldMap.get("label") == "Next_Billing_Date")
{
NextBillingDate = customFieldMap.get(invoicedate.addMonth(FreqOfPayments)).toTime();
}
}
info NextPaymentAmount;
info NextBillingDate;
jsonMap = Map();
jsonMap.put("Next_Payment_amount",NextPaymentAmount);
jsonMap.put("Next_Billing_Date",NextBillingDate);
result = zoho.invoice.update("Invoices",organizationID,invoiceNumber,jsonMap);
info result.toMap().get("message");

<-----------End of the code ------------->