Jump to content


  • Content count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About MikeS24

  • Rank
    Junior Member
  1. MikeS24

    Adding second currency in invoices

    Hey Brian, Thank you for one another helpful input! Yes, my posts are still getting through "purgatory" before they are released - it is a little annoying, but rules are the rules I guess. I absolutely didn't assume "->toNumeric()" would actually work in this case, as I thought "number_format" is the PHP version of that, and the first one is only available in Smarty templates. Of course... assumptions... Thanks for pointing this out. I think in a couple of days I will be trying to "save" the secondary currency value as a database entry, to solve the annoying problem with it changing every time the exchange rate gets updated. If I'm not mistaked, I have seen one of your posts where you explain how to do this with a hook. I'll try to figure it out, and hopefully I won't get stuck on my own stupidness again this time, haha... Have a good time! Best Regards, Michael
  2. MikeS24

    Adding second currency in invoices

    Unbelievable... I've managed to solved it on my own! It was necessary to get rid of the currency symbol before running the calculations. For some reason I thought the "number_format" thingy would do this, but it seems I was wrong. Here's how I've done this (just in case anyone else would get stuck with the same problem): Once again, thank you for your help and guidance Brian!
  3. MikeS24

    Adding second currency in invoices

    Of course, didn't I say I have a talent for overcomplicating things? I had this in mind, but it just seemed too simple of a solution to even consider this. For some reason, it seems that this field with secondary currency on pdf invoices shows just the currency to currency exchange rate output, and not the actual calculation for of the specific price in the field. From what I see, it's the same way in the image you showed me with your GBP>HRK price output. The result is just the 1 GBP exchange rate. I don't get why does it work this way, since the calculation formula seems to be formatted correctly and we actually see the correct exchange rate between two currencies being shown - it just doesn't seem to multiply the item price with this exchange rate. ('. number_format($item['amount'] * $exchangerate, 2, '.', '').' HRK) I'm sorry for troubling you with this Brian, I know this might be getting annoying for you already. Best Regards, Michael
  4. MikeS24

    Adding second currency in invoices

    Thank you Brian. I can't believe I have come this close to the solution, yet it would still take me eternity to figure this out on my own, haha... Sadly, it seems that capsule might be indeed disabled in my template, because I am getting an "Oops! Something went wrong" page when trying to download PDF file. I had no luck trying to google how to enable capsule for the template (or it's possible that I simply don't know what to search for...). Is this an easy thing to do or am I totally... out of luck in this scenario?
  5. MikeS24

    Adding second currency in invoices

    Hi again Brian! The implementation of the code and hook for the viewinvoice.tpl went successfully. I have customized it with the currencies from my page and it works. Thank you for your generous help with this problem of mine. Unfortunately, my lack of programming knowledge had hit me in the head once again and it really hurts me that I need to come here ask for help with yet another problem... I've spent many hours already and I'm still trying to figure out how to handle the exchange code implementation in the invoicepdf.tpl. The way you explained it to me (and from I've learned from some of your other posts), the "inside" part of the hook code should be implemented into the PDF template directly and the conversion calculation formula should be placed in fields where it's necessary. I've learned that there must be some slight tweaking done to the code when we transfer it to the PDF template, but after trying couple different methods already I still don't get the correct secondary currency output on PDF invoices. I feel that I've come really close to the correct format of the transferred code and calculation, but now I am kind of stuck with what I have and I'm not sure how to progress further. Below is the preview of the code the way I've implemented it inside invoicepdf.tpl. $pdf->Ln(10); ################################### ##### currency_exchange_rates ##### $clientcurrency = $vars['clientsdetails']['currency']; if ($clientcurrency == "1") { $exchangerate = Capsule::table('tblcurrencies')->where('code','HRK')->value('rate'); } elseif ($clientcurrency == "2") { $plnrate = Capsule::table('tblcurrencies')->where('code','PLN')->value('rate'); $hrkrate = Capsule::table('tblcurrencies')->where('code','HRK')->value('rate'); $exchangerate = number_format(((1/$plnrate) * $hrkrate), 5); } elseif ($clientcurrency == "3") { $eurrate = Capsule::table('tblcurrencies')->where('code','EUR')->value('rate'); $hrkrate = Capsule::table('tblcurrencies')->where('code','HRK')->value('rate'); $exchangerate = number_format(((1/$eurrate) * $hrkrate), 5); } elseif ($clientcurrency == "4") { $gbprate = Capsule::table('tblcurrencies')->where('code','GBP')->value('rate'); $hrkrate = Capsule::table('tblcurrencies')->where('code','HRK')->value('rate'); $exchangerate = number_format(((1/$gbprate) * $hrkrate), 5); } elseif ($clientcurrency == "5") { $jpyrate = Capsule::table('tblcurrencies')->where('code','JPY')->value('rate'); $hrkrate = Capsule::table('tblcurrencies')->where('code','HRK')->value('rate'); $exchangerate = number_format(((1/$jpyrate) * $hrkrate), 5); } elseif ($clientcurrency == "6") { } ##### currency_exchange_rates ##### ################################### foreach ($invoiceitems as $item) { $tblhtml .= ' <tr bgcolor="#fff"> <td align="left">' . nl2br($item['description']) . '<br /></td> <td align="center">' . $item['amount'] . ' ('. number_format($item['amount'] * $exchangerate, 2, '.', '').' HRK)</td> </tr>'; } And this is the result it gives me... I'm not sure what else I could do with this. I'll be grateful if you could take a look at it in your spare moment and let me know what am I missing or doing wrong. Best Regards, Michael
  6. MikeS24

    Adding second currency in invoices

    Hello Brian! Please forgive me for responding to you just now, but I was really busy with setting all other things up before we go live, and I actually remembered about this little currency thingy just today. First of all, you are a great guy, though I bet you hear this a lot. I am really thankful for all the time and energy you put into preparing the complete, ready to use code for my needs. Thanks for this wonderful gift! I still have some more things I need to take care of today, but I will definitely let you know about how it went with implementing the code as soon as I'm done with it. Once again, Big Thanks and Happy New Year! Michael
  7. MikeS24

    Adding second currency in invoices

    Thanks Brian! That's pretty much what I was thinking. Converting the non-default currency into default and then to HRK. I'll run some tests and hopefully I'll come up with something.
  8. MikeS24

    Adding second currency in invoices

    Hello Brian! Big thanks to you for helping me out with this. And thank you for your time. When it comes to my original idea with {if $clientsdetails.currency eq "2"} ({math equation="x * y" x=$item.amount|regex_replace:"/[^.,0-9]+/":"" y=1.82828 format="%.2f"} HRK){/if}, unfortuantely the result of this was as below: The currency ID definitely wasn't the issue, so I have no idea what the problem was. But... Thankfully, by using the first one of your suggested edits with $item.amount->toNumeric() instead of regex, it worked! Darn, I knew it must've been something as simple as that! Thank you! When it comes to snatching the actual exchange rate, of course this would be a much simpler solution overall, without the need for manual file updates, so I'll definitely try this out. However, I am going to make about 5 different currencies available to choose from for our clients, so I have a feeling that this may be a tidy bit more complicated, because if I understand it correctly, the hook example that you've given me above applies to a single currency, so I imagine that it would be necessary to create multiple hooks for different currencies... or this may be even more complicated than this, since the currency exchange rates between "non-default" currencies aren't actually stored anywhere within database. Or there's always a possibility that I am missing something very obvious, because my brain likes to trick me into overcomplicating simple things. Anyway, sticking to the "manual way" satisfies my needs for the time being, so I'm ok with this method. I am truly grateful for your assistance with this. Have a great time and Merry Chrismas/Happy Holidays to you, Brian! Best Regards, Michael
  9. Hi everyone! To be clear, I am not a programmer, so my knowledge about the programming logic, dependecies and all that is close to 0. I am just figuring out things that are necessary for me one at a time as they come. As some of you may already know, there are some countries in this world that require local currencies to be displayed on invoices. In my case it is Croatia. I am sweating my abs off trying to figure out some way to add the purchase value in another currency to our invoices. I feel that I've spent way too much time on this and it already becomes painful. This is what I was able to come up with: ------------------------------------------------------------ <td>{$item.description}{if $item.taxed eq "true"} *{/if}</td> <td class="text-center">{$item.amount} {if $clientsdetails.currency eq "2"} ({math equation="x * y" x=$item.amount|regex_replace:"/[^.,0-9]+/":"" y=1.82828 format="%.2f"} HRK){/if}</td> ------------------------------------------------------------ The way I see it, there is a problem with including math equations within {if} tags. Without "ifs" the equation works as intended and returns the correct value, but with them the value is empty. Unfortunately, it seems to me that those {if} tags are necessary in this scenario, with multiple currencies available for our clients. And here comes my question, or rather "cry for help"... Would anyone be willing and able to help me out with rewriting this code or at least point me in the right direction? Of course it would be best to include a "live" currency conversion rate in place of the fixed convestion value, but I wasn't able to find out how to handle this. I will be very very very grateful for any assistance with this. Best Regards, Michael
  10. Welcome to WHMCS.Community MikeS24! We're glad you're here please take some time to familiarise yourself with the Community Rules & Guidelines and take a moment to introduce yourself to other WHMCS.Community members in the Introduce Yourself Board.


Important Information

By using this site, you agree to our Terms of Use & Guidelines