• Hello Fabrik Community

    Fabrik is now in the hands of the development team that brought you Fabrik for Joomla 4. We have recently transitioned the Fabrik site over to a new server and are busy trying to clean it up. We have upgraded the site to Joomla 4 and are running the latest version of Fabrik 4. We have also upgraded the Xenforo forum software to the latest version. Many of the widgets you might have been used to on the forum are no longer operational, many abandoned by the developers. We hope to bring back some of the important ones as we have time.

    Exciting times to be sure.

    The Fabrik 4.0 Official release is now available. In addition, the Fabrik codebase is now available in a public repository. See the notices about these in the announcements section

    We wish to shout out a very big Thank You to all of you who have made donations. They have really helped. But we can always use more...wink..wink..

    Also a big Thank You to those of you who have been assisting others in the forum. This takes a very big burden off of us as we work on bugs, the website and the future of Fabrik.

Calculating Cost and Totals in forms

nbradshaw

Active Member
So - I have read dozens and dozens of forum posts on this subject - but it is just not clear to me how to properly calculate row totals then the Grand Total (in separate Group)

I can successfully use the calc element to get the individual row totals (ie, unit price * quantity) using the code below:

PHP:
$myCalc = (int)'{bid_system_5_repeat___quantity_raw}' * (int)'{bid_system_5_repeat___rate_raw}';
return $myCalc;

However, I am unclear if I am supposed to use a calc element (since it is not an input field and can cause issues with order firing, etc...when trying to get the grand total (in a different group)

Can someone please point me to a solid article on how to set all of this up properly? Also - Can I create a wiki that makes this super duper easily to understand after I get this setup properly?
 
There's a lot of ways to skin that cat.

First question, do you need to see the total update in real time on the page as you enter data in the repeat group?

-- hugh
 
Hi Hugh!

Yes, I do need it in real time....that's the issue I am having right now.

I did just figure out how to do it with this code with a calc element (with Ajax = Yes)...however, it is just not realtime (but it does work on save)

PHP:
$sum = 0;
$sum += array_sum($data['bid_system_5_repeat___total']);
return $sum;

And how about formatting to $0.00?
 
Last edited:
Thanks StarPoint. I am still needing guidance on how to do the realtime row calculations? Can someone please assist with this one?
 
Did you add the element name you are using to the "additional AJAX elements" (or whatever that field is called in the calc settings)?

If you use a placeholder in your calc, like {mytable___element}, then we will automatically set up the Javascript to watch that element, and fire off the AJAX calc when it changes. But if you need us to watch an element which isn't in the calc code as a placeholder (such as accessing it through $data[]), then you need to tell us, in that "additional elements" setting, which element name(s) to watch.

-- hugh
 
A big HUGE thanks to @startpoint !!! He was gracious enough work with me on this and wrote a custom jquery form_x.js file to make this work to fit my needs. Thanks again @startpoint !!! Not to take away from you also Hugh, you have helped me countless times also!!!
 
@nbradshaw @startpoint well, looks like I was a day or two late.

I just committed the first cut of a new 'total' plugin, that allows two types of total calculations:

"Repeat Totalling" - totalling one or more elements from a repeat group into a total on the main group (like, summing 'qty' on a repeat line item to a single 'total qty' in the main group).

"Multiple Totalling" - totalling multiple elements from the same group into a total, for example "cost * tax" to get a "cost with tax". This works in either repeat or non repeat groups.

The totalling allows you to specify the operand to use for each element.

To get the new plugin, do a full github update, then a J! "Discover" install for the new "Fabrik - total element" plugin, and then enable it in the J! plugin manager.

Tooltips probably need some work, but should give you enough to go on.

-- hugh
 
That is freaken awesome Hugh!!! That is a HUGE new feature, in my opinion!!! That is BLOG worthy!

I will check it out and give you some feedback.
 
Yes please, feedback needed.

The next thing I need to work out is subtotals and totals. So you can use a total element to total up other total elements. At the moment, there is no guarantee what order they get run in, so using totalling other total elements isn't really possible. It's not going to be trivial.

-- hugh
 
I haven't gotten to this quite yet to test...but just a thought of how to possibly get around those obstacles you are speaking of (from a non-hardcore programmers mind). Could you simply just do the math all over again on all of the row totals - then just add a user input field within the plugin saying "tax %". Then you would have one subtotal where the user leaves "tax %" empty - then on the Grand Total - they input say 8.25% into that user input field and the plugin simply gets the raw row totals and multiplies by 8.25%...

Not sure if all that made sense...but just a thought.
 
Hi Hugh,
thank you for this great plugin.

I've a calc to count the result of a repeated group element, which are 'not okay' (dropdown, value=2).
Does it make sense, to extend this total plugin with a condition?

Cheers,
Bianka
 
@bea - I can have a look at doing that. I think it might be possible, although complicated by the fact that we do the calculations in both Javascript on the browser side, and in PHP on the server side ... on the basis that we don't "trust" submitted totals from the form ... so (say) someone can't spoof a purchase order by manually setting the 'total' element to a lower value on the posted form data, we re-calculate totals on submission, and when re-displaying the record. So I'd have to come up with a way of allowing a condition to be specified which would work in both JS and PHP.

-- hugh
 
Hi Hugh,
there is a total element in the same site, where you got the login (total_single), if you need to test.
Cheers,
Bianka
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top