This support ticket is created 6 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
I have built a rudimentary budget system in toolset which allows users to create budget items and allocate payments to each item. I run some simple calculations to show remaining balance on a budget item using this shortcode:
What I would like to do next is to calculate the total of all budget items and present that to the user at the bottom of the view.
Then, if I were to create a view where each budget item had a Debit and Credit amount, how would I be able to create a final column with a running total?
What I need assistance with here is the methodology around this. I am starting to think like a programmer, but I still struggle in places to get my mind to bend around certain problems.
If I could ask the coders out there to help me with methodology, I would be indebted.
Thanks in advance.
Next, here is a shortcode I use for reporting the iterations of a View:
/**
* Add loop-iteration shortcode
*
* Attributes
* 'n' (optional) : test for nth iteration
*/
add_shortcode( 'loop-iteration', function( $atts ){
global $loop_n;
if ( !isset( $loop_n ) ) {
$loop_n = 0;
return $loop_n;
}
$loop_n++;
if ( !isset( $atts['n'] ) ) {
// no nth parameter, just return the current index
return $loop_n;
}
else {
$remainder = ( $loop_n + 1 ) % $atts['n'];
return ( $remainder == 0 );
}
});
Without 'n' parameter, the shortcode will simply output the current iteration.
With 'n' parameter it can be used with a conditional shortcode to only show some content for every nth iteration of the loop, like so:
[php]
[wpv-conditional if="( '[loop-iteration n='3']' eq '1' )"]
<p>3rd item in loop</p>
[/wpv-conditional]
Now, with this second shortcode you can see how you can create global variables which are remembered until the page is reloaded.
So it is an example of how you can create a global variable for the running total of credits, another for the running total of debits, and you can perform a calculation using both to output the net value.
That should give you some ideas, let me know if you get stuck.
Sure thing Pamela, let me mark this is as requiring feedback from you, which I think gives you about a week before you have to make a reply of some kind.
Turns out I'm going to need more than methodology here.
I've implemented the above, but not sure how I would define or create a variable within a view, given the 'index' or iteration provided by the shortcode. I'm sure you meant I should use that shortcode as an example on how to extract certain information from fields as the view renders, but I probably should have mentioned that, while I've proven in the past to do some very complex things with Toolset, I'm not fluent in PHP (as much as I'm trying to be).
I have taken on two huge projects now based solely on my confidence in Toolset. I hope I can pick your brain a bit in the coming weeks.