Exemplo n.º 1
0
 public static function convertBaseCurrencyToUSD($amount, $base_currency = "", $exchange_rate_allow = false)
 {
     if ($amount == "") {
         $amount = "0";
     }
     if (doubleval($amount) > 0) {
         $amt = $amount;
         if ($base_currency != "USD") {
             $currency_details = CUtil::chkIsValidCurrency($base_currency);
             if (count($currency_details) > 0) {
                 $exchange_rate = doubleval($currency_details['exchange_rate']);
                 if ($exchange_rate_allow) {
                     $exchange_price = $exchange_rate * (doubleval(\Config::get("webshoppack::site_exchange_rate")) * 0.01);
                     $exchange_rate = $exchange_rate - $exchange_price;
                 }
                 $amt = $amt / $exchange_rate;
             }
         }
         return $amt;
     }
     return $amount;
 }
Exemplo n.º 2
0
 public static function getCurrencyBasedAmount($base_amount, $usd_amount, $base_currency, $return_as_arr = false)
 {
     if ($usd_amount != "") {
         $amt = $usd_amount;
         $currency_symbol = "USD";
         $currency_symbol_font = "\$";
         $fetched_api_currency = "";
         $return_arr = compact('amt', 'currency_symbol', 'currency_symbol_font');
         $currency_code = \Config::get("webshoppack::site_cookie_prefix") . "_selected_currency";
         if (CUtil::getCookie($currency_code) == "") {
             $fetched_api_currency = CUtil::getLocatorApiCurrencyCode();
         }
         if (\Config::get("webshoppack::currency_is_multi_currency_support") == "true") {
             if (CUtil::getCookie($currency_code) != "" || $fetched_api_currency != "") {
                 $currency_details = array();
                 //Check whether the currency in coookie is Active status
                 if ($fetched_api_currency != "") {
                     $currency_details = CUtil::chkIsValidCurrency($fetched_api_currency);
                 } else {
                     $currency_details = CUtil::chkIsValidCurrency(CUtil::getCookie($currency_code));
                 }
                 if (count($currency_details) > 0) {
                     if ($fetched_api_currency != "") {
                         if ($base_currency == $fetched_api_currency) {
                             $amt = $base_amount;
                             $currency_symbol = $currency_details["currency_code"];
                             $currency_symbol_font = $currency_details["currency_symbol"];
                             $return_arr = compact('amt', 'currency_symbol', 'currency_symbol_font');
                             if ($currency_symbol == "INR") {
                                 $currency_symbol_font = "<em class=\"clsWebRupe\">" . $currency_details["currency_symbol"] . "</em>";
                             }
                         } else {
                             if ($currency_details["currency_code"] != "USD") {
                                 //Currency 2 = currency1 x exchange rate.
                                 $amt = $amt * $currency_details["exchange_rate"];
                                 $currency_symbol = $currency_details["currency_code"];
                                 $currency_symbol_font = $currency_details["currency_symbol"];
                                 $return_arr = compact('amt', 'currency_symbol', 'currency_symbol_font');
                                 if ($currency_symbol == "INR") {
                                     $currency_symbol_font = "<em class=\"clsWebRupe\">" . $currency_details["currency_symbol"] . "</em>";
                                 }
                             }
                         }
                     } else {
                         if ($base_currency == CUtil::getCookie($currency_code)) {
                             //$amt = $base_amount.toDouble;
                             $amt = $base_amount;
                             $currency_symbol = $currency_details["currency_code"];
                             $currency_symbol_font = $currency_details["currency_symbol"];
                             $return_arr = compact('amt', 'currency_symbol', 'currency_symbol_font');
                             if ($currency_symbol == "INR") {
                                 $currency_symbol_font = "<em class=\"clsWebRupe\">" . $currency_details["currency_symbol"] . "</em>";
                             }
                         } else {
                             if ($currency_details["currency_code"] != "USD") {
                                 //Currency 2 = currency1 x exchange rate.
                                 $amt = $amt * $currency_details["exchange_rate"];
                                 $currency_symbol = $currency_details["currency_code"];
                                 $currency_symbol_font = $currency_details["currency_symbol"];
                                 $return_arr = compact('amt', 'currency_symbol', 'currency_symbol_font');
                                 if ($currency_symbol == "INR") {
                                     $currency_symbol_font = "<em class=\"clsWebRupe\">" . $currency_details["currency_symbol"] . "</em>";
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $formatted_amt = "";
         $formatted_amt = number_format($amt, 2, '.', '');
         $formatted_amt = str_replace(".00", "", $formatted_amt);
         $formatted_amt = str_replace("Rs.", "", $formatted_amt);
         //	$currencyFormatter = NumberFormat.getCurrencyInstance(new Locale("en", "IN"));
         //	formatted_amt = currencyFormatter.format(amt);
         //	formatted_amt = formatted_amt.replace(".00","");
         //	formatted_amt = formatted_amt.replace("Rs.","");
         //	return "<span class=\"clsPriSym\">"+currency_symbol+"</span>" + " " + currency_symbol_font + formatted_amt;
         if ($return_as_arr) {
             return $return_arr;
         } else {
             //return "<small class=\"clsPriSym\">".$currency_symbol. '</small> <strong>' . $currency_symbol_font . $formatted_amt.'</strong>';
             return '<strong>' . $currency_symbol_font . ' ' . $formatted_amt . '</strong>';
         }
     }
     return "";
 }