11th Feb2013
Author: Gyro

WHMCS: Round up product prices for secondary currencies

Today, I actually assisted my hosting provider in setting up secondary currencies in WHMCS, the billing and support system for/from cpanel! :)

They only wanted full numbers for the monthly breakdowns, so when they click "Update Prices" in the Currency Settings and a product would cost 1233.37 the price gets automatically rounded up to 1234.00.

Unfortunately, WHMCS doesn't offer this feature, so I suggested to setup a script on a secure location that they can trigger after they update the currency conversion rates and product prices. Below is the sql query that goes through all secondary currencies (1 = default currency) and rounds up the values, so that the setup fee and all monthly prices are full numbers.

The script itself would run a simple MySQL query:

UPDATE tblpricing SET
msetupfee = ceil(msetupfee),
qsetupfee = ceil(qsetupfee),
ssetupfee = ceil(ssetupfee),
asetupfee = ceil(asetupfee),
bsetupfee = ceil(bsetupfee),
tsetupfee = ceil(tsetupfee),
monthly = ceil(monthly),
quarterly = ceil(quarterly/3)*3,
semiannually = ceil(semiannually/6)*6,
annually = ceil(annually/12)*12,
biennially = ceil(biennially/24)*24,
triennially = ceil(triennially/36)*36
WHERE
currency != 1 AND
id = id

you could replace

currency != 1 AND

with
currency = 2 AND

or
currency IN(2,3,6) AND

etc

Enjoy :enjoy:

2275

Keep Me Going
Your Name / Website:
Did you like my post? Buy me a Bitcoffee! 14JX52Li7zTKbyQv2omw4tvu6Bi1KzfHNW



2 Responses to “WHMCS: Round up product prices for secondary currencies”

  • I might want to round the costs also.

    Particularly on the grounds that for instance in swiss francs, the littlest coin is 5 penny. So costs with something else than 0 or 5 toward the end look moronic and will really make perplexity among customers.

    For my situation I would want to round the costs down/up to xx.x0 for areas, and xx.00 for facilitating items. I figure I will simply impair the WHMCS include and compose my own cron script that redesigns costs accordignly…

    • Gyro

      Hi,

      To round up/down use this:

      echo round(3.63333333333, 1); // 3.6
      echo round(3.66666666666, 1); // 3.7

      If you need to have 2 decimal points, you can use number_format(VALUE, 2), for example:

      echo number_format(round(3.63333333333, 1), 2); // 3.60

      To always round up, use this php function:

      function round_up ( $value, $precision ) {
      $pow = pow ( 10, $precision );
      return ( ceil ( $pow * $value ) + ceil ( $pow * $value - ceil ( $pow * $value ) ) ) / $pow;
      }

      echo round_up(3.63333333333, 1); // 3.7
      echo number_format(round_up(3.63333333333, 1), 2); // 3.70

      source: http://stackoverflow.com/questions/8239600/rounding-up-to-the-second-decimal-place

Leave a Reply

Your email address will not be published. Required fields are marked *

What is 11 + 9 ?
Please leave these two fields as-is:
IMPORTANT! To be able to proceed, you need to solve the following simple math (so we know that you are a human) :-)