2

I got table from array and many amounts $$$ for different dates.

Example:

-08/10/2015 | Amount: 2500$
-19/10/2015 | Amount: 1000$
-20/11/2015 | Amount: 500$
-27/11/2015 | Amount: 720$
-30/12/2015 | Amount: 100$
-31/12/2015 | Amount: 250$

My current code in the smarty template is:

                {foreach from=$referrals item=referral}
                    {if $referral.date eq "08/10/2015"}
                            {assign var="sum" value="`$sum+$referral.amount`"}
                    {/if}
                {/foreach}
                    <td>{$sum|number_format:2:",":"."} ден.</td>
                {assign var="sum" value=0}

And i only get total amount only for date: 08/10/2015

My question is how to get total amount for the whole month (10) October, or for the whole month (11) November and for whole year separated by months and only for amounts that are not 0 (zero), because i have that kind of amounts as well?

And this is my array (containing more than 136 arrays):

Smarty_Variable Object (3)
->value = Array (137)
  0 => Array (11)
    id => "1514"
    date => "05/01/2016"
    service => "Рамка со податоци"
    package => "Рамка со податоци"
    userid => "500"
    amount => "0.00"
    billingcycle => "One Time"
    amountdesc => "0,00 ден. One Time"
    commission => "0,00 ден."
    lastpaid => "Never"
    status => "Active"
  1 => Array (11)
    id => "1515"
    date => "05/01/2016"
    service => "Лого со податоци"
    package => "Лого со податоци"
    userid => "500"
    amount => "0.00"
    billingcycle => "One Time"
    amountdesc => "0,00 ден. One Time"
    commission => "0,00 ден."
    lastpaid => "Never"
    status => "Active"
  2 => Array (11)
    id => "1496"
    date => "29/12/2015"
    service => "Рамка со податоци"
    package => "Рамка со податоци"
    userid => "493"
    amount => "0.00"
    billingcycle => "One Time"
    amountdesc => "0,00 ден. One Time"
    commission => "0,00 ден."
    lastpaid => "Never"
    status => "Active"
  3 => Array (11)
    id => "1497"
    date => "29/12/2015"
    service => "Лого со податоци"
    package => "Лого со податоци"
    userid => "493"
    amount => "0.00"
    billingcycle => "One Time"
    amountdesc => "0,00 ден. One Time"
    commission => "0,00 ден."
    lastpaid => "Never"
    status => "Active"
  4 => Array (11)
    id => "1498"
    date => "29/12/2015"
    service => "Реклама во црно-бела техника на 1/6 -..."
    package => "Реклама во црно-бела техника на 1/6 -..."
    userid => "493"
    amount => "0.00"
    billingcycle => "One Time"
    amountdesc => "0,00 ден. One Time"
    commission => "0,00 ден."
    lastpaid => "Never"
    status => "Active"
  5 => Array (11)
    id => "1500"
    date => "29/12/2015"
    service => "Лого и мапа на www.abv.mk"
    package => "Лого и мапа на www.abv.mk"
    userid => "493"
    amount => "0.00"
    billingcycle => "One Time"
    amountdesc => "0,00 ден. One Time"
    commission => "0,00 ден."
    lastpaid => "Never"
    status => "Active"
Acidburns
  • 131
  • 3
  • 13
  • 2
    Just do it in regular php and send the results to Smarty with a variable. Smarty is a template system, it's not supposed to be used for such complex operations – Borgtex Jan 13 '16 at 08:42
  • I would agree with Borgtex - be sure to enable the Smarty PHP tags if you are using WHMCS v6 (WHMCS > Setup > General Settings > Security tab). Then you can use {php} {/php} within the template to do what you are wanting to do. Of course ideally you would add a hook in the hooks folder to do this, but I digress. – muely2k1 Jan 22 '16 at 00:14
  • I can try both things u mention, but the problem is im not really a php programmer, thats why i ask for help :) @muely2k1 – Acidburns Jan 24 '16 at 09:31

1 Answers1

1
*//sum for october month*

{assign var="sum" value=0}

{foreach from=$referrals item=referral}

  {if $referral.date|date_format:"%m" == 10 && $referral.amount != 0}

     {assign var="sum" value=$sum+$referral.amount}

  {/if}

{/foreach}

*//display sum*

{$sum|number_format:2:",":"."}
Nima
  • 3,309
  • 6
  • 27
  • 44
Nimya V
  • 336
  • 3
  • 5
  • It would be nice if you add some description to your code to point out how this solves OP's problem. – Nima Aug 24 '17 at 11:01