• 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.

Column total on a custom module

Status
Not open for further replies.

SoilentRed

Caaan do!
I need to first total the amount of data from a column of entries on a list. Then, I need to display that total on a custom module. How can I do that?
 
hi
Nice video - thanks!
There are several steps you will need to go through to do this in fabrik.

First of all for the sake of simplicity I'm going to presume the list is called 'sales' and that you have two elements: 'sales__user_id' which stores the user to which the sale is made, and 'sales___sales' which stores the amount.

So the first thing to do is set up the calculations, edit the 'sales___sales' element

Under list view settings -> calculations tun on both "sum the column total" and "count records"
Under details -> formatting - set the format to be decimal, turn on number format and set 'format string' to '$%s'
Save the element.

Now if you view your list you should see a sum and total for all sales shown at the bottom of the page.

The next thing to do is to make a custom template, as all we are interested in doing is showing this calculation information.
Create a folder /components/com_fabrik/views/list/tmpl/calculations
and a file default.php inside this folder.
Edit the file and add some code similar to

Code:
Total sales:
<?php
echo str_replace('Sum', '', strip_tags($this->calculations['sales___sales']->sales___sales_calc_sum));
?>
<br />
Number of sales:
<?php
echo str_replace('Count', '', strip_tags($this->calculations['sales___sales']->sales___sales_calc_count));
?>

(Obviously prettify that to match your design)

Now lets add the list module.
Ensure that you have the fabrik list module installed.
Then go to "Extensions -> module manager" and press the "new" button
Select the fabrik list module from the list of modules
Assign the module to a position.

Under the advanced tab:

select the sales list
Select the 'calculations' template we have just made
Save the module (not save and close as you still want to edit the module)

This next bit i'm not sure if you need or if its going to be correct, but i'm presuming that you want the user to see their own sales...

Press the prefilter button, this will open up a modal window.
From that window press the [+] button to add a new prefilter
Select "element" = 'user_id'
"condition" = 'EQUALS'
Value = {$my->id}
Access = registered

Press the close button and re-save the module.

Check your site, where the module is displayed you should see the list rendered with the calculations template containing the logged in users sales.
 
Rob,
Thanks for that comprehensive response. Unfortunately, I'm getting the following error:

500 : Layout default_row not found.

An error has occurred while processing your request.

You may not be able to visit this page because of:

an out-of-date bookmark/favourite
a mistyped address
a search engine that has an out-of-date listing for this site
you have no access to this page

I titled the template folder "year-to-date-summary".

Here is the code I used for default.php:

Code:
<table style="width: 100%;" align="center">
<thead>
<tr align="center"><th colspan="2">
<div align="center">
<h2><strong>Year at a Glance</strong></h2>
</div>
</th></tr>
</thead>
<tbody>
<tr align="center">
<td align="center">
<div align="center">
<h4><strong>Estimated Potential Revenue</strong></h4>
<p style="color: #188f00;"><strong>
<?php
echo str_replace('Sum', '', strip_tags($this->calculations['lead_swap___opportunity_value']->lead_swap___opportunity_value_calc_sum));
?></strong></p>
<h4><strong>Actual Revenue Reported</strong></h4>
<p style="color: #188f00;"><strong>$24,825</strong></p>
</div>
</td>
<td align="center">
<div align="center">
<h4><strong>Referrals Passed</strong></h4>
<p style="color: #188f00;"><strong>
<?php
echo str_replace('Count', '', strip_tags($this->calculations['lead_swap___opportunity_value']->lead_swap___opportunity_value_calc_count));
?></strong></p>
<h4><strong>Deals Sealed</strong></h4>
<p style="color: #188f00;"><strong>16</strong></p>
</div>
</td>
</tr>
</tbody>
</table>

Any ideas?
 

Attachments

  • screencap-error500.jpg
    screencap-error500.jpg
    420.8 KB · Views: 217
I think just adding an empty default_row.php into the template folder will resolve the issue.
Id forgotten that Fabrik reads that in separately, normally its used to render the table rows, but as we aren't rendering them here you can simply leave the file blank
 
Hey! we're trying to create some new modules with the prefilter instructions you gave us here, but it doesn't seem to be taking the prefilter into consideration. We're trying to have it where Creator_groups = {$my->groups}. The result is the same as the original module without the prefilter. Think you can help with this?
 
I think I might have found a solution, I just created a new list from the original and prefiltered it with {$my->groups} and duplicated the module. If the problem with the module prefilter wasn't on my end, you may want to look into why the prefilter isn't taking on the module.
 
Status
Not open for further replies.
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top