This topic is locked
[SOLVED]

 Dynamically calculating invoice line totals and subtotals on the fly

5/24/2015 8:55:03 AM
PHPRunner General questions
M
Maxbots author

I have a feeling that I am missing something simple and obvious here, but I have been looking for two days now and I don't see an explicit answer anywhere. I see lots of hints and partial answers, but nothing quite seems to work as I expect it.
I have an invoice table, with a related invoice_items table. I want to be able to create an invoice with an arbitrary number of line items, and have both the line total and the subtotal dynamically calculated with Javascript as you enter the information. I do not need to save the totals, just display them.
My simplified tables are:
Invoices:

InvoiceID

...

InvoiceTax

InvoiceShipping
Invoice_Items:

ItemID

InvoiceID

...

ItemPrice

ItemQty
I want a div for GrandTotal that is the subtotal, shipping and tax.
The Javascript examples I have found here and in the manual seem to work fine on a normal form, but they don't seem to work on the inline form-- either that or I was just screwing up somehow and don't know enough to know what I am doing wrong.
Can anyone give me any pointers as to what I need?

Thanks!

HJB 5/24/2015
M
Maxbots author 5/24/2015



http://xlinesoft.com/phprunner/docs/how_to_calculate_values_on_the_fly.htm

http://xlinesoft.com/articles/how_to_use_calculated_fields.htm
... URL content above provides ALL you need to get your project up and running ...


I found both those links and others already-- they qualify as the "partial answers" I referenced earlier (unless I am missing something). With those I can calculate the the LineTotal and GrandTotal. It still doesn't work quite as well as I would like-- I just want it displayed as text, not as a text field, but that is just a matter of figuring out the variable names probably. That part is easy enough to deal with I suspect, admittedly I have spent almost no time looking at that part of the issue yet, I've been focused on the Javascript.
The main thing I have not figured out is how do I calculate the value of the subtotal? It is conceivable that an invoice could have 50 items on it, so I don't really like the idea of having a equation with 50 variables just in case... Nevermind when someone ends up buying 51 items. I'm guessing I need a javascript loop, and I'm sure I can learn enough Javascript to figure it out, but since this seems like something that others have already solved, I was hoping to not need to learn any more js than necessary, but of course I can if I have no other choice.
Anyway, it seems to me that this should be fairly commonly required functionality, it would be nice if there was a simple explanation of how to achieve it. This is not something that is just used on invoices, but a significant percentage of PHPRunner users must need the basic functionality, it would be nice to have a simple explanation.

M
Maxbots author 5/24/2015



http://xlinesoft.com/phprunner/docs/how_to_calculate_values_on_the_fly.htm

http://xlinesoft.com/articles/how_to_use_calculated_fields.htm
... URL content above provides ALL you need to get your project up and running ...


I think part of my confusion is the control names and contexts. I have mostly been focused on the detail view of Invoice_Items, and when I tested that Javascript I was only using 'ItemQty' and 'Item_Price', and not getting it to update. Those are the variables used in the List page view, which seemed right, but I am guessing that is not correct. The Edit page view uses 'ItemQty_editcontrol' (for example) instead, which may be why I never got the sample code to work right. Regardless, it doesn't address the subtotal question, so I would appreciate any help you can offer.

HJB 5/25/2015

http://xlinesoft.com/invoice was tested by me on 51 items, say, wrapping to a new page is not implemented, however that very Xlinesoft invoice template was not designed and intended to be a 100% solution at all, but meant to pave the way and to allow full customization to own needs, yet think, you should give the invoice online demo a look in regard to the ON THE FLY CALCULATION via JS (and only saved into the fields once SAVE button is clicked) rather to try to invent the wheel again on your own or you can look at 15 other invoice options to go under http://codegeekz.com/free-invoice-generators.

M
Maxbots author 5/25/2015

<deleted>

Admin 5/25/2015

If for any reason you haven't received the download link you need to contact support directly sending your order number. Someone will be glad to assist you.