Complex Multi Step Form with very slow calculations - guidance needed

Current set-up : SPA Pages, Windows 10, phpMyAdmin, PHP

I have a complex multi-step form with calculations and a button to create a PDF.

These are the 11 parts of the multi-step form. Pressing on each step WILL save, as well as a separate Save button at the end.

This all works very well except that the calculations are very slow, so slow that if you open the page and click the step “11. Create PDF” button, the calculation will not have completed and the PDF creation will error.

Instead, if you open the page, count to twenty, and then press the “11. Create PDF” button, then all will be OK.

Open the page and click section “7. Costs” you will see the calculation happening before your eyes. Here is a quick video to show you.

I don’t know what I should do to speed things up.

Should I move all the calculations into a separate page or maybe just a modal?

My basic calculations are explained below, hopefully they make sense.

In this first screenshot I do A x B and it totals in C, then the result C is added to D + E + F to give result G. That then is added to H to give the Grand total. So I can see here that several calculations are dependent upon the result of other calculations before processing.

Therefore should I do three separate, unconnected calculations? ie
Result C to be A x B =
Result G to be (A x B) + (D + E + F) =
Result Grand total to be (A x B) + (D + E + F + H) =

The Specialist total figure comes from an expanded Specialist Section (dmx-show) which has more calculations. I wonder if this should be in a modal, or even a totally separate page?

To add to the problem, the page starts out blank, the user inputs data and calculations are made, they save the data to DB. This page can be recalled and the saved data is used to populate the fields, then data is changed and so the form recalculates.

When the page is recalled, all the calculations happen on opening the page even if nothing is changed and only data populates the input fields from the DB.

How can I best configure the INPUT fields to only use DB populated data UNLESS the user then changes a figure, at which point the calculation needs to process?

I don’t want a “Calculate now” button :slight_smile:

Anyone got any ideas on this?

If the values are saved to DB, could you create a View in the DB that does the calculations and is called to fill the form?

From what I am seeing the data is updated without a refresh, what steps are you taking to have it calculate then update without a browser refresh? Could that be the slow down?