Example #1
0
function format_currency($amount, $currency = null, $culture = null)
{
    if (null === $amount) {
        return null;
    }
    $numberFormat = new sfNumberFormat(_current_language($culture));
    return $numberFormat->format($amount, 'c', $currency);
}
/**
 * Format a number
 *
 * @param float $number
 * @param string $culture
 * 
 * @return string
 */
function format_number($number, $culture = null)
{
    if (is_null($number)) {
        return null;
    }
    $numberFormat = new sfNumberFormat(_current_language($culture));
    return $numberFormat->format($number);
}
 public function getReductionValueFormatted()
 {
     if ($this->getReductionType() === self::REDUCTION_TYPE_DOLLAR) {
         $numberFormat = new sfNumberFormat(sfContext::getInstance()->getUser()->getCulture());
         return $numberFormat->format($this->getReductionValue(), 'c', sfConfig::get('app_rt_currency', 'USD'));
     }
     return $this->getReductionValue() . '%';
 }
 /**
  * @param  string $name        The element name
  * @param  string $value       The value displayed in this widget
  * @param  array  $attributes  An array of HTML attributes to be merged with the default HTML attributes
  * @param  array  $errors      An array of errors for the field
  *
  * @return string An HTML tag string
  *
  * @see sfWidgetForm
  */
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     if (!is_string($value) && !is_null($value)) {
         $numberFormat = new sfNumberFormat($this->getOption('culture'));
         $value = $numberFormat->format($value);
     }
     return parent::render($name, $value, $attributes, $errors);
     //return $this->renderTag('input', array_merge(array('type' => $this->getOption('type'), 'name' => $name, 'value' => $value), $attributes));
 }
Example #5
0
function format_currency($amount, $currency = null, $culture = null)
{
    if (null === $amount) {
        return null;
    }
    $numberFormat = new sfNumberFormat(_current_language($culture));
    //remove nbsp (sonst erkennt Excel keine Zahl)
    return substr($numberFormat->format($amount, 'c', $currency, 'ISO-8859-15'), 0, -1);
    //return rtrim($numberFormat->format($amount, 'c', $currency, 'ISO-8859-15'), '0\xa0');
}
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     $response = sfContext::getInstance()->getResponse();
     $response->addJavascript('/sfExtraWidgetsPlugin/js/money.js');
     $response->addStylesheet('/sfExtraWidgetsPlugin/css/money.css');
     if (is_null($value)) {
         $value = 0;
     }
     $numberFormat = new sfNumberFormat(sfContext::getInstance()->getUser()->getCulture());
     $value = $numberFormat->format($value, '#.00');
     return '<div id="container-' . $this->generateId($name) . '">' . parent::render($name, $value, $attributes, $errors) . '</div>' . javascript_tag("new Money(\$('" . $this->generateId($name) . "'),{ symbol: '" . $this->getOption('symbol') . "'})");
 }
 /**
  * Special method to handle the mixed handling beteen ajax and regular
  * 
  * @param sfWebRequest $request
  * @param string $message
  * @param rtShopProduct $rt_shop_product
  * @param string $status
  * @return void
  */
 protected function handleProductAdditionResponse(sfWebRequest $request, $rt_shop_product, $message, $status = 'error')
 {
     if ($request->getParameter('sf_format') === 'json') {
         $this->getResponse()->setContentType('application/json');
         $numberFormat = new sfNumberFormat(sfContext::getInstance()->getUser()->getCulture());
         $data = array('status' => $status, 'message' => $message, 'cartItems' => $this->getCartManager()->getItemsInCart(), 'cartTotal' => $this->getCartManager()->getTotalCharge(), 'cartTotalFormatted' => $numberFormat->format($this->getCartManager()->getTotalCharge(), 'c', sfConfig::get('app_rt_currency', 'USD')));
         echo json_encode($data);
         sfView::NONE;
         exit;
     }
     $this->getUser()->setFlash($status, $message, true);
     $this->redirect('rt_shop_product_show', $rt_shop_product);
 }
Example #8
0
function price_format($price, $sf_user = false)
{
    if (!$sf_user) {
        $sf_user = sfContext::getInstance()->getUser();
    }
    $cur = $sf_user->getCurrency();
    $culture = $sf_user->getCulture();
    $numberFormat = new sfNumberFormat($culture);
    $ar = sfNumberFormatInfo::getCurrencyInstance($culture)->getPattern();
    if ($cur->getAbbr() != 'EUR' && $cur->getAbbr() != 'USD') {
        $pattern = str_replace('¤', '', $ar['positive']);
        $pattern = trim(str_replace('¤', '', $ar['positive'])) . ' ' . $cur->getAbbr();
    } else {
        $pattern = $ar['positive'];
    }
    return $numberFormat->format($cur->getFactor() * $price, $pattern, $cur->getAbbr());
}
 public function render($name, $value = null, $attributes = array(), $errors = array())
 {
     if (is_numeric($value) && !is_null($value)) {
         $numberFormat = new sfNumberFormat($this->getOption('culture'));
         $value = $numberFormat->format($value);
     }
     $input = parent::render($name, $value, $attributes, $errors);
     $prepend = '';
     $append = '';
     if ($this->getOption('prepend')) {
         $prepend = '<span class="input-group-addon">' . $this->getOption('prepend') . '</span>';
     }
     if ($this->getOption('append')) {
         $append = '<span class="input-group-addon">' . $this->getOption('append') . '</span>';
     }
     $html = '<div class="input-group">';
     $html .= $prepend;
     $html .= $input;
     $html .= $append;
     $html .= '</div>';
     return $html;
 }
Example #10
0
 /**
  * Receives the Invoice form data and calculates each row total amount and
  * full invoice totals. Returns a json
  *
  * @param 'invoice' from Request
  * @return JSON through Response
  */
 public function executeCalculate(sfWebRequest $request)
 {
     $currency = PropertyTable::get('currency');
     $format = new sfNumberFormat($this->culture);
     $data = $request->getParameter('invoice');
     $this->getResponse()->setHttpHeader('Content-Type', 'application/json; charset=utf-8');
     $invoice = new Invoice();
     $items = array();
     $totals = array();
     if (isset($data['Items'])) {
         foreach ((array) $data['Items'] as $itemId => $itemData) {
             if ($itemData['remove']) {
                 continue;
             }
             $item = new Item();
             $item->setUnitaryCost($itemData['unitary_cost']);
             $item->setQuantity($itemData['quantity']);
             $item->setDiscount($itemData['discount']);
             if (isset($itemData['taxes_list'])) {
                 $taxes = Doctrine::getTable('Tax')->createQuery()->whereIn('id', $itemData['taxes_list'])->execute();
                 $item->Taxes = $taxes;
             }
             $items[$itemId] = $format->format($item->getGrossAmount(), 'c', $currency);
             $invoice->Items[] = $item;
         }
         $totals['base'] = $format->format($invoice->calculate('base_amount', true), 'c', $currency);
         $totals['discount'] = $format->format($invoice->calculate('discount_amount', true), 'c', $currency);
         $totals['net'] = $format->format($invoice->calculate('net_amount', true), 'c', $currency);
         $totals['taxes'] = $format->format($invoice->calculate('tax_amount', true), 'c', $currency);
         $totals['gross'] = $format->format($invoice->calculate('gross_amount', true), 'c', $currency);
     } else {
         $zero = $format->format(0, 'c', $currency);
         $totals['base'] = $zero;
         $totals['discount'] = $zero;
         $totals['net'] = $zero;
         $totals['taxes'] = $zero;
         $totals['gross'] = $zero;
     }
     return $this->renderText(json_encode(array('items' => $items, 'totals' => $totals)));
 }
 /**
  * Return data for check voucher request
  * 
  * @param  string $voucher_code Voucher code
  * @return array
  */
 public function getCheckVoucherArray($voucher_code)
 {
     $numberFormat = new sfNumberFormat(sfContext::getInstance()->getUser()->getCulture());
     $voucher_data = array('error' => false, 'id' => '');
     if ($voucher_code !== '') {
         $voucher = rtShopVoucherToolkit::getApplicable($voucher_code, $this->getItemsCharge());
         if ($voucher) {
             $this->getOrder()->setVoucherCode($voucher->getCode());
             $voucher_data = $voucher->getData();
         } else {
             $this->getOrder()->setVoucherCode(null);
             $voucher_data['error'] = true;
         }
     } else {
         $this->getOrder()->setVoucherCode(null);
     }
     $this->getOrder()->save();
     // Add data
     $voucher_data['shipping_charge'] = $this->getShippingCharge();
     $voucher_data['total_charge'] = $this->getTotalCharge();
     $voucher_data['reduction'] = $this->getVoucherReduction();
     $voucher_data['reduction_formatted'] = $numberFormat->format($this->getVoucherReduction(), 'c', sfConfig::get('app_rt_currency', 'USD'));
     $voucher_data['total_charge_formatted'] = $numberFormat->format($this->getTotalCharge(), 'c', sfConfig::get('app_rt_currency', 'USD'));
     return $voucher_data;
 }
 * advanced rtShopVoucher Testing
 *
 * @package    rtShopPlugin
 * @author     Piers Warmers <*****@*****.**>
 * @author     Konny Zurcher <*****@*****.**>
 */
include dirname(__FILE__) . '/../bootstrap/unit.php';
$t = new lime_test(16, new lime_output_color());
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'test', true);
$configuration->loadHelpers('Number');
sfContext::createInstance($configuration);
new sfDatabaseManager($configuration);
$t->comment('/////////////////////////////////////////////////////////////////////////////');
$t->comment('/// rtShopVoucher: Test range');
$t->comment('/////////////////////////////////////////////////////////////////////////////');
$numberFormat = new sfNumberFormat(sfContext::getInstance()->getUser()->getCulture());
// Tools
$tools = new rtShopVoucherRangeTestTools();
// Tax and shipping configurations
sfConfig::set('app_rt_shop_tax_rate', 10);
sfConfig::set('app_rt_shop_tax_mode', 'exclusive');
sfConfig::set('app_rt_shop_shipping_charges', array('default' => 20, 'AU' => 10, 'NZ' => 10));
// Add some data to play with...
$tools->clean();
// Products
try {
    $prod1 = new rtShopProduct();
    $prod1->setTitle('Product A');
    $prod1->save();
    $prod2 = new rtShopProduct();
    $prod2->setTitle('Product B');