Converting Estimates into Invoices using a report action - Calculating Subtotals

Converting Estimates into Invoices using a report action - Calculating Subtotals

I am trying to create a report action or button to convert my estimate into an invoice.  I have everything working up it will not calculate the subtotal and grand total after it is converted.  Any help or suggestions would be appreciated!

Here is what I have so far...

invoice_id = insert into Create_Invoice
[
Added_User=zoho.loginuser
Grand_Total=input.Grand_Total
Deal_Number=input.Deal_Number
Contact=input.Contact
Deal_Name=input.Deal_Name
Phone=input.Phone
Email=input.Email
Installation_Address=input.Installation_Address
Account=input.Account
];
for each  estimate_row in input.Items
{
insert into Invoice_Line_Items_Subform
[
Added_User=zoho.loginuser
Invoice_Number=invoice_id
Price=estimate_row.Price
Item_Name=estimate_row.Item_Name
Unit=estimate_row.Unit
Quantity=estimate_row.Quantity
Amount=estimate_row.Amount
]
}
openUrl("#Report:All_Invoice_Report","same window");

Everything works to this point but it will not complete the calculation,

totalAmount = 0.0;
for each  item in Invoice_Line_Items_Subform
{
totalAmount = totalAmount + ifnull(item.Amount,0.0);
}
input.Sub_Total = totalAmount;
taxAmount = input.Tax / 100 * input.Sub_Total;
input.Grand_Total = input.Sub_Total + input.Tax_Amount - input.Discount1;
input.Tax_Amount = taxAmount;