Set up of Calc element...

J3DI13

New Member
Hi there guys & girls.

I am running Joomla 2.5.11 & Fabrik 3.0.8

I am nearing the end of a project and in one of my clients forms a calculation needs to be made. Now i have absolutely no experience in coding in PHP or Javascript. I would assume that the calculation itself is simple enough. The form is setup that it is a repeating group that needs to be calculated first, It is your basic sum eg:

(Repeating Group)
bought 2 pencils at $2 and i spent a Total of $4 (All without VAT or Tax)

(Sum total with VAT)
Then i need to add up all the repeatable rows to get a sub total amount with a set VAT price to give a total figure at the end.

(The above does sound a tad confusing when reading so i have attached a screen grab of it.)

If any one can point me in the right direction on where to source such code would be greatly appreciated.

Thanks
 

Attachments

  • smt.jpg
    smt.jpg
    59.6 KB · Views: 517
There are a few pages in the wiki on using JS for this - they are in the Developers section in the main page. Here is one.
http://fabrikar.com/forums/index.php?wiki/adding-custom-javascript/

Here is a function I made a while back that might help you out as example code. My JS experience is very basic so I'm not sure how much help I can provide with your specifics. I remember using Firebug was very helpful for nailing down the JS element names and troubleshooting the code. The new wiki has some different sections than the old one so perhaps there is a better method for doing this now.

The following code is in a file 6.js located in /components/com_fabrik/js

Code:
// Updates the Event's net cash calc based on the bouts
function sumNetCash(){
  // Gets an array of all elements with "mps_bouts___cash" in the name
    var qtys = document.getElements('input[name *= mps_bouts___cash]');
 
    var sum = 0;
 
  // Sums all the values in the array
    qtys.each(function (val) {
        sum += parseInt(form_6.formElements.get(val.id).getValue());
    }); 
 
  // Updates the total element
  form_6.formElements.get('mps_events___net_cash').update(sum);  }

I added a JS action in my mps_bouts___cash element to call sumNetCash() on change.
 
Wow thank you very rackem, i really appreciate it.
Would i add that code to the calc element in the form?

Thanks again for the helping hand.
 
No, that is to perform the calculation using JS. I'm not sure how to do it in the calc element.
 
Help me!
what was your solution?

I must add the subtotal.
I have a repeating group
 

Attachments

  • Sin título.png
    Sin título.png
    18.2 KB · Views: 681
Put this code on calc element for sum total :

PHP:
$sum = array_sum($_POST['join'][1]['sample_2_repeat___total_price']);
return $sum;

Only Calc on Save = Yes
Ajax Calculation = Yes

Ajax observe field put

{sample_2_repeat___total_price}

Note : Remember to check your join value on form.
 
This is calc two field on repeat group.

PHP:
$quantity = array_sum($_POST['join'][1]['sample_2_repeat___quantity']);
$unit_price = array_sum($_POST['join'][1]['sample_2_repeat___unit_price']);
return $quantity * $unit_price;

Only Calc on Save = Yes
Ajax Calculation = Yes

Ajax observe field put

{sample_2_repeat___quantity}, {sample_2_repeat___unit_price}
 
my friend
Do not generate the total

Help me please
The total must also be seen in the list
 

Attachments

  • Sin título2.png
    Sin título2.png
    25.2 KB · Views: 497
Have you try the method i post?... I working for me... Can sum all total in repeat group. If you don't mind pm me the administrator and let me to look what wrong there.
 
If friend, I send the login details of administrator by mail?

I get the sum of the subtotals
 

Attachments

  • 3.jpg
    3.jpg
    84.9 KB · Views: 432
the number 4 is the id of the element?

CODE:
$sum = array_sum($_POST['join'][4]['gasto_encabezado_6_repeat___cantidad']);
return $sum;

I have not changed any data :)
 

Attachments

  • 4.jpg
    4.jpg
    16.1 KB · Views: 439
That are join id...

I recommended you to update your joomla to latest version and using Fabrikar version 3.0.9 with latest github update. You now using joomla version is 2.5.9. That very old.
 
I'm a bit confused, you shouldn't be migrating backwards.... if the code doesn't work in the latest version then we just need to modify it suit suit the new version.
 
For me better migrate to most stable version for Joomla 2.5.

As far i know the best source match with Joomla version is :

- Fabrik 3.o.9 for Joomla 2.5++
- Fabrik 3.1 for Joomla 3.1++
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top