Basheer Posted May 29, 2017 Share Posted May 29, 2017 Hi, I used both Euro and USD in my WHMCS , If customer choose any one currency , the invoice should have both currency valued prices . Is it possible ? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 29, 2017 Share Posted May 29, 2017 I used both Euro and USD in my WHMCS , If customer choose any one currency , the invoice should have both currency valued prices . Is it possible ? aahh, the Romanian question - i've seen similar posts from Romanians where they need to show their invoices in their local currency and EUR. the problem you have is that WHMCS doesn't store old currency rates - only today's... so while you can modify the invoice template to show an order today for €100.00, and query the database to get the current exchange rate and output a USD equivalent price) $111.80... tomorrow the EUR->USD rate will be different and if the client looks at the invoice again online (as it is written on the fly), the USD price will be different. when an invoice is paid, then the exchange rate for that day is stored in the database - so I guess for paid invoices, you might be able to do it accurately... and if your payment methods means the invoices are automatically paid when generated, then this might be an option. if so, then you're probably looking at an action hook to do this in the HTML invoice, and very similar PHP code within the invoicepdf.tpl template and output layout modifications to both. 0 Quote Link to comment Share on other sites More sharing options...
Basheer Posted May 30, 2017 Author Share Posted May 30, 2017 Thank You Brian. You are great 0 Quote Link to comment Share on other sites More sharing options...
Basheer Posted May 30, 2017 Author Share Posted May 30, 2017 One more thing , In which database table currency type related to a invoice is stored ? I checked 'tblinvoices' and 'tblaccounts'. In tblaccounts table there is field 'currency' but all values are 0 . 0 Quote Link to comment Share on other sites More sharing options...
Basheer Posted May 30, 2017 Author Share Posted May 30, 2017 And is there any option to pass variable to viewinvoice.tpl ? 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 30, 2017 Share Posted May 30, 2017 Thank You Brian. You are great don't get too excited - I think I was wrong... or at least oversimplifying the problem. let's say your default currency is EUR, and you have a secondary currency USD... if I make an order in EUR, let's say €100, it will be stored in tblinvoices as 100 with no currency attached (i'll explain why later)... if/when it's paid, a similar entry will be added to tblaccounts, but it will additionally store the exchange rate used. now, the problem you have (and didn't occur to me yesterday when I replied originally) would be that if I made the order in the default currency (and paid for it), tblaccounts would just store '1' for the exchange rate (as it's the default currency rate) - but it wouldn't store the USD exchange rate... therefore, there would be no way to calculate the USD price... I suppose if the invoice was creeated/paid on the same day, you could pull it from tblcurrencies and make the calculation - but then you'd run into issues if the client viewed that invoice online at a future date. if the order was in a non-default currency, then my original idea would work, because the order value would be in tblaccounts (100 USD), with an exchange rate of say 1.2846 and from that you could calculate the EUR equivalent and display it in the invoice - and you would know that it would be the same value today, tomorrow, next month - so the invoice would be accurate. what I suspect you're really going to need to do is create a new database table that stores the date and exchange rates of the currencies on a daily basis (from tblcurrencies) and then you those values for calculating the alternative price for a given date. One more thing , In which database table currency type related to a invoice is stored ? I checked 'tblinvoices' and 'tblaccounts'. it's very important to realise that the currency is assigned to the client and NOT an invoice - this is one of the reasons why a client cannot change their currencies after they've ordered... the database invoice tables just store amounts with no references to currency, e.g if a client had a $100 order today, but you changed their currency to EUR tomorrow, the invoice would then appear to be for €100 and mess up the transactions completely. but to answer your question, if you know the invoice number, you can get the client ID from tblinvoices (if you can't get it directly) and from that, get the currency from tblclients. And is there any option to pass variable to viewinvoice.tpl ? you could use ViewInvoiceDetailsPage to pass a variable to the template and then modify the template to show that value/array wherever you want to. 0 Quote Link to comment Share on other sites More sharing options...
Basheer Posted May 30, 2017 Author Share Posted May 30, 2017 I just created a new table and whenever a invoice created , corresponding converted euro value saved in that table. And i fetch that value and shows in invoice. 0 Quote Link to comment Share on other sites More sharing options...
Basheer Posted May 30, 2017 Author Share Posted May 30, 2017 you could use ViewInvoiceDetailsPage to pass a variable to the template and then modify the template to show that value/array wherever you want to. No response supported for this hook !! 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 30, 2017 Share Posted May 30, 2017 I just created a new table and whenever a invoice created , corresponding converted euro value saved in that table. And i fetch that value and shows in invoice. that's not a bad idea and simpler than my suggestion! No response supported for this hook !! my mistake - should be ClientAreaPageViewInvoice 0 Quote Link to comment Share on other sites More sharing options...
Basheer Posted May 30, 2017 Author Share Posted May 30, 2017 my mistake - should be ClientAreaPageViewInvoice But i think i doesnt get invoice details like invoiceid in that hook. 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 30, 2017 Share Posted May 30, 2017 But i think it doesn't get invoice details like invoiceid in that hook. but it has access to the Smarty variables available to that template, so if you want the invoiceid value.... $invoiceid = $vars['invoiceid']; but don't forget the client has to be logged in to view the invoice, so you'll have access to a lot of information - so you could do something like this... <?php function basheer_invoice_hook($vars) { $invoiceid = $vars['invoiceid']; $clientcurrency = $vars['clientsdetails']['currency']; return array("brian1" => $invoiceid, "brian2" => $clientcurrency); } add_hook("ClientAreaPageViewInvoice", 1, "basheer_invoice_hook"); ?> this is a little silly as it takes 2 variables from the template, and passes those values back (to the template) unchanged as $brian1 and $brian2 - but you get the idea of taking variables from the template and using them in the hook and then sending them back. for example, you could pull the invoice total from the Smarty variables without needing to touch any database tables and then multiply it by your exchange rate to get the alternate currency total. 0 Quote Link to comment Share on other sites More sharing options...
Basheer Posted May 31, 2017 Author Share Posted May 31, 2017 Thank you Brian , It works fine , is there any hook point for invoice pdf ? 0 Quote Link to comment Share on other sites More sharing options...
Basheer Posted May 31, 2017 Author Share Posted May 31, 2017 (edited) And is there any separate hook point while duplicate invoice ? Or same "InvoiceCreation" hook function is called ? I write some script in this hook function , but its not executed while duplicate invoice from admin side. I can see another hook point "InvoiceCreationAdminArea" . - - - Updated - - - "InvoiceCreationAdminArea" not help in duplicate invoice Edited May 31, 2017 by Basheer 0 Quote Link to comment Share on other sites More sharing options...
brian! Posted May 31, 2017 Share Posted May 31, 2017 Thank you Brian , It works fine , is there any hook point for invoice pdf ? unlike the Smarty templates, the invoicepdf.tpl template uses PHP - so you can just add your PHP direct into the template (it can't use hooks). 0 Quote Link to comment Share on other sites More sharing options...
Daniel Kamau Posted August 27, 2023 Share Posted August 27, 2023 Hi @brian! Thanks just a quick one i have a similar issue though slightly different. I have configured 4 currencies and I am adding the exchange rate manually, however when I geneate a customer invoice is there any way it can just show the currency of that specific country without the base price showing. I mean invoices get generated based on the country the user has selected when creating the account. Let me know if this is possible. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.