diablo666 Posted February 2, 2018 Share Posted February 2, 2018 $tblhtml .= ' <tr height="30" bgcolor="#efefef" style="font-weight:bold;"> <td align="right">' . Lang::trans('invoicessubtotal') . '</td> <td align="center">' . $subtotal . '</td> </tr>'; if ($taxname) { $tblhtml .= ' <tr height="30" bgcolor="#efefef" style="font-weight:bold;"> <td align="right">' . $taxrate . '% ' . $taxname . '</td> <td align="center">' . $tax . '</td> </tr>'; } $tblhtml .= ' <tr height="30" bgcolor="#efefef" style="font-weight:bold;"> <td align="right">Totale Fattura</td> <td align="center">' . $myvariable . '</td> </tr>'; Hello i try to edit invoipdf.tpl, in this little pice of code, we have two already defined varible standard in whmcs $subtotal and $tax, what i want to achive is that the new variable $myvariable contains the sum of $subtotal+$tax how may i do this? There is a variable already with this value? The predefined variable $total is not good for me because he adds also the $tax2, and i don't want this. Hope in some help Link to comment Share on other sites More sharing options...
diablo666 Posted February 3, 2018 Author Share Posted February 3, 2018 $myvariableXXX = $item['amount'] + $tax; $tblhtml .= ' <tr height="30" bgcolor="#efefef" style="font-weight:bold;"> <td align="right">Totale Fattura</td> <td align="center">' . $myvariableXXX . '</td> </tr>'; This piece of code, will not work and i don't know why. $item['amount'] is 100.00 $tax is 22.00 but $myvariableXXX will get value 1.22 wich has no sense... Any one can help? Link to comment Share on other sites More sharing options...
brian! Posted February 4, 2018 Share Posted February 4, 2018 the problem you have is that those variables are strings, not numbers - so I assume $tax is really "$22.00 USD" (or your equivalent currency). if your site uses one currency, then you can easily do this in the template with existing variables; - e.g, you could do this to get the string as a number... $mysubtotal = $subtotal->toNumeric(); do the same for tax, add them together, format it and then you just need to get the currency - if there's only one, you can hardcode it in the output... otherwise, you'll need to get the currency details... either from exiting variables or by querying the database (you know the client and invoice IDs). Link to comment Share on other sites More sharing options...
diablo666 Posted February 9, 2018 Author Share Posted February 9, 2018 It works like a charm I've hardoced soemthing like this $mysubtotal = $subtotal->toNumeric(); $mytax = $tax->toNumeric(); $myvariableXXX = $mysubtotal+$mytax; Another thing if you can help me ... when i disaply the variable i need 2 decimal end the full stop in the number: for example 48.8, how may i change it to 48,80 ? Thank you! Link to comment Share on other sites More sharing options...
diablo666 Posted February 9, 2018 Author Share Posted February 9, 2018 I'll replay to myself $myvariableXXX = number_format($mysubtotal+$mytax,2, ',', ''); Works perfectly Link to comment Share on other sites More sharing options...
brian! Posted February 10, 2018 Share Posted February 10, 2018 On 2/9/2018 at 09:21, diablo666 said: Works perfectly the only thing to be wary of with this is if you're using multiple currencies with some using different currency formats - if not, then it won't matter. Link to comment Share on other sites More sharing options...
diablo666 Posted February 10, 2018 Author Share Posted February 10, 2018 Yeah i'm only using one currency, so for now not a problem. Surelly this part of script should be done better Link to comment Share on other sites More sharing options...
Recommended Posts