/**
  * Returns substitution strings
  *
  * @see cbpaidSomething::substitutionStrings()
  *
  * @param  boolean  $html                              HTML or TEXT return
  * @param  boolean  $runContentPluginsIfAllowedByPlan  DEFAULT: TRUE
  * @return array
  */
 public function substitutionStrings($html, $runContentPluginsIfAllowedByPlan = true)
 {
     $strings = parent::substitutionStrings($html, $runContentPluginsIfAllowedByPlan);
     $plan = $this->getPlan();
     // For donations, [PLAN_PRICE] is the amount just donated, as it's user-selectable:
     $strings['PLAN_PRICE'] = cbpaidMoney::getInstance()->renderPrice($this->amount, $this->currency, $html, false);
     $strings['PLAN_RATE'] = sprintf('%.2f', cbpaidApp::getCurrenciesConverter()->convertCurrency($this->currency, $plan->currency(), $this->amount));
     $strings['PLAN_FIRST_RATE'] = $strings['PLAN_RATE'];
     return $strings;
 }
 /**
  * USED by XML interface ONLY !!! Renders amount
  *
  * @param  string           $price
  * @param  ParamsInterface  $params
  * @return string                    HTML to display
  */
 public function renderAmount($price, $params)
 {
     if ($price) {
         $cbpaidMoney = cbpaidMoney::getInstance();
         $priceRoundings = 100;
         // $params->get('price_roundings', 100 );
         $priceRounded = $cbpaidMoney->renderNumber(round($price * $priceRoundings) / $priceRoundings, 'money', false);
     } else {
         $priceRounded = '-';
     }
     return $priceRounded;
 }
コード例 #3
0
ファイル: cbpaidItem.php プロジェクト: kosmosby/medicine-prof
	/**
	 * preg_replace_callback replacer function
	 * @access protected
	 * (do not make private in this case, as it is invoked from an inherited class, it would hit PHP bug https://bugs.php.net/bug.php?id=62547 and protected triggers bug in PHP 5.2)
	 *
	 * @param  float|array  $input         Price to set  (or preg callback input array)
	 * @param  boolean      $htmlSet       $html to set
	 * @param  boolean      $roundingsSet  $roundings to set
	 * @return string
	 */
	public function _renderPriceInCurrency( $input, $htmlSet = null, $roundingsSet = null ) {
		static $price					=	null;
		static $html					=	null;
		static $roundings				=	null;
		if ( ! is_array( $input ) ) {
			$price						=	$input;
			$html						=	$htmlSet;
			$roundings					=	$roundingsSet;
			$secondaryPriceText			=	null;
		} else {
			$secondaryPriceText			=	null;
			$textCurrency				=	$this->currency();
			$textSecondaryCurrency		=	$input[1];

			if ( $textSecondaryCurrency ) {
				if ( $textSecondaryCurrency == $textCurrency ) {
					$priceInCurrency	=	$price;
				} else {
					$priceInCurrency	=	cbpaidMoney::getInstance()->convertPrice( $price, $textCurrency, $textSecondaryCurrency, $roundings, true );
				}
				$secondaryPriceText		=	$this->renderPrice( $priceInCurrency, $textSecondaryCurrency, $html, $roundings );
			}
		}
		return $secondaryPriceText;
	}
 /**
  * Renders a $variable for an $output
  *
  * @param  string       $variable  Variable to render
  * @param  string       $output    'html': HTML rendering, 'text': TEXT rendering
  * @param  boolean      $rounded   Round column values ?
  * @return string|null
  */
 public function renderColumn($variable, $output = 'html', $rounded = false)
 {
     $html = $output == 'html';
     switch ($variable) {
         case 'rate':
         case 'original_rate':
         case 'tax_amount':
             $ret = $this->renderItemRate($variable, $html, $rounded);
             break;
         case 'first_rate':
         case 'first_original_rate':
         case 'first_tax_amount':
             if (property_exists($this, $variable)) {
                 $ret = cbpaidMoney::getInstance()->renderPrice($this->{$variable}, $this->currency, $html, $rounded);
             } else {
                 $ret = null;
             }
             break;
         case 'validity_period':
             if ($this->start_date && $this->stop_date && $this->start_date != '0000-00-00 00:00:00' && $this->stop_date != '0000-00-00 00:00:00') {
                 $startDate = cbFormatDate($this->start_date, 0, false);
                 $stopDate = cbFormatDate($this->stop_date, 0, false);
                 $ret = htmlspecialchars($startDate);
                 if ($startDate != $stopDate) {
                     $ret .= ($html ? ' - ' : ' - ') . htmlspecialchars($stopDate);
                 }
             } else {
                 $ret = null;
             }
             break;
         case 'tax_rule_id':
             if ($this->tax_rule_id && is_callable(array('cbpaidTaxRule', 'getInstance'))) {
                 $ret = cbpaidTaxRule::getInstance((int) $this->tax_rule_id)->getShortCode();
             } else {
                 $ret = null;
             }
             break;
         case 'ordering':
             if ($this->payment_item_id) {
                 $paymItem = $this->_paymentBasket->getPaymentItem($this->payment_item_id);
                 if ($paymItem) {
                     $ret = htmlspecialchars($paymItem->ordering);
                 } else {
                     $ret = null;
                 }
             } else {
                 $ret = null;
             }
             break;
         case 'discount_amount':
         case 'first_discount_amount':
             $ret = null;
             break;
         case 'quantity':
         case 'artnum':
         case 'description':
         case 'discount_text':
         default:
             $ret = htmlspecialchars($this->get($variable));
             break;
     }
     return $ret;
 }
コード例 #5
0
 /**
  * converts each value to an option element of the array
  *
  * @param  array   $options
  * @param  array   $arr
  * @param  string  $currency
  */
 protected function _valuesToOptions(&$options, &$arr, $currency)
 {
     $cbpaidMoney = cbpaidMoney::getInstance();
     for ($i = 0, $n = count($arr); $i < $n; $i++) {
         $displayAmount = $cbpaidMoney->renderPrice($arr[$i], $currency, true);
         $options[] = moscomprofilerHTML::makeOption($arr[$i], $displayAmount);
     }
 }
コード例 #6
0
ファイル: cbsubs.tax.php プロジェクト: kosmosby/medicine-prof
	/**
	 * Computes the amount after percentage, only if it's combined
	 * 
	 * @param  float    $amount
	 * @param  float    $amountTaxExcl
	 * @param  float    $periodProrater
	 * @param  boolean  $isFirstPeriod
	 * @param  string   $currency_code
	 * @return float|null
	 */
	public function getAmountAfterPercents( $amount, $amountTaxExcl, $periodProrater, $isFirstPeriod, $currency_code ) {
		$return						=	null;
		if ( in_array( $this->tax_kind, array( 'fixed_percent' ) ) ) {
			$_CBPAY_CURRENCIES		=&	cbpaidApp::getCurrenciesConverter();
			$cbpaidMoney			=&	cbpaidMoney::getInstance();
			$return					=	$_CBPAY_CURRENCIES->convertCurrency( $cbpaidMoney->currency( $this->tax_currency ), $currency_code, $this->tax_amount );		// null if cannot convert
		}
		if ( $return !== null ) {
			$return					*=	$periodProrater;
		}
		return $return;
	}
コード例 #7
0
	/**
	 * returns price (rate) in the given currency.
	 *
	 * @param  string          $currency_code  ISO currency
	 * @param  float           $price          price to convert
	 * @return float|null                      returns $price in $currency_code or null if it can not convert.
	 */
	public function _priceConvert( $currency_code, $price ) {
		return cbpaidMoney::getInstance()->convertPrice( $price, $this->currency(), $currency_code, true, true );
	}