mirror of
https://github.com/opensourcepos/opensourcepos.git
synced 2026-04-13 19:40:06 -04:00
Render percentage discounts in configured locale (#3114)
This commit is contained in:
@@ -5,6 +5,7 @@ const DEFAULT_LANGUAGE_CODE = 'en-US';
|
||||
|
||||
define('NOW', time());
|
||||
define('MAX_PRECISION', 1e14);
|
||||
define('DEFAULT_PRECISION', 2);
|
||||
define('DEFAULT_DATE', mktime(0, 0, 0, 1, 1, 2010));
|
||||
define('DEFAULT_DATETIME', mktime(0, 0, 0, 1, 1, 2010));
|
||||
|
||||
@@ -386,7 +387,7 @@ function to_quantity_decimals($number)
|
||||
return to_decimals($number, 'quantity_decimals');
|
||||
}
|
||||
|
||||
function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
|
||||
function to_decimals($number, $decimals=NULL, $type=\NumberFormatter::DECIMAL)
|
||||
{
|
||||
// ignore empty strings and return
|
||||
// NOTE: do not change it to empty otherwise tables will show a 0 with no decimal nor currency symbol
|
||||
@@ -397,8 +398,9 @@ function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
|
||||
|
||||
$config = get_instance()->config;
|
||||
$fmt = new \NumberFormatter($config->item('number_locale'), $type);
|
||||
$fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $config->item($decimals));
|
||||
$fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $config->item($decimals));
|
||||
$fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, 0);
|
||||
$fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, empty($decimals) ? DEFAULT_PRECISION : $config->item($decimals));
|
||||
|
||||
if(empty($config->item('thousands_separator')))
|
||||
{
|
||||
$fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
|
||||
@@ -446,8 +448,6 @@ function parse_decimals($number, $decimals = NULL)
|
||||
|
||||
$fmt = new \NumberFormatter($config->item('number_locale'), \NumberFormatter::DECIMAL);
|
||||
|
||||
$fmt->setAttribute(\NumberFormatter::FRACTION_DIGITS, $decimals);
|
||||
|
||||
if(empty($config->item('thousands_separator')))
|
||||
{
|
||||
$fmt->setAttribute(\NumberFormatter::GROUPING_SEPARATOR_SYMBOL, '');
|
||||
|
||||
@@ -167,7 +167,7 @@ if (isset($success))
|
||||
?>
|
||||
<td>
|
||||
<div class="input-group">
|
||||
<?php echo form_input(array('name'=>'discount', 'class'=>'form-control input-sm', 'value'=>$item['discount_type'] ? to_currency_no_money($item['discount']) : to_decimals($item['discount'], 0), 'onClick'=>'this.select();')); ?>
|
||||
<?php echo form_input(array('name'=>'discount', 'class'=>'form-control input-sm', 'value'=>$item['discount_type'] ? to_currency_no_money($item['discount']) : to_decimals($item['discount']), 'onClick'=>'this.select();')); ?>
|
||||
<span class="input-group-btn">
|
||||
<?php echo form_checkbox(array('id'=>'discount_toggle', 'name'=>'discount_toggle', 'value'=>1, 'data-toggle'=>"toggle",'data-size'=>'small', 'data-onstyle'=>'success', 'data-on'=>'<b>'.$this->config->item('currency_symbol').'</b>', 'data-off'=>'<b>%</b>', 'data-line'=>$line, 'checked'=>$item['discount_type'])); ?>
|
||||
</span>
|
||||
|
||||
@@ -139,7 +139,7 @@ $(document).ready(function()
|
||||
<td class="item-name"><?php echo ($item['is_serialized'] || $item['allow_alt_description']) && !empty($item['description']) ? $item['description'] : $item['name'] . ' ' . $item['attribute_values']; ?></td>
|
||||
<td style='text-align:center;'><?php echo to_quantity_decimals($item['quantity']); ?></td>
|
||||
<td><?php echo to_currency($item['price']); ?></td>
|
||||
<td style='text-align:center;'><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):$item['discount'] . '%';?></td>
|
||||
<td style='text-align:center;'><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):to_decimals($item['discount']) . '%';?></td>
|
||||
<?php if($discount > 0): ?>
|
||||
<td style='text-align:center;'><?php echo to_currency($item['discounted_total'] / $item['quantity']); ?></td>
|
||||
<?php endif; ?>
|
||||
|
||||
@@ -92,7 +92,7 @@ if(isset($error_message))
|
||||
<td class="item-name"><?php echo $item['name']; ?></td>
|
||||
<td><?php echo to_quantity_decimals($item['quantity']); ?></td>
|
||||
<td><?php echo to_currency($item['price']); ?></td>
|
||||
<td><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):$item['discount'] . '%';?></td>
|
||||
<td><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):to_decimals($item['discount']) . '%';?></td>
|
||||
<?php if ($item['discount'] > 0): ?>
|
||||
<td><?php echo to_currency($item['discounted_total'] / $item['quantity']); ?></td>
|
||||
<?php endif; ?>
|
||||
|
||||
@@ -127,7 +127,7 @@ if (isset($error_message))
|
||||
<td class="item-name"><?php echo $item['name']; ?></td>
|
||||
<td style='text-align:center;'><?php echo to_quantity_decimals($item['quantity']); ?></td>
|
||||
<td><?php echo to_currency($item['price']); ?></td>
|
||||
<td style='text-align:center;'><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):$item['discount'] . '%';?></td>
|
||||
<td style='text-align:center;'><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):to_decimals($item['discount']) . '%';?></td>
|
||||
<?php if($discount > 0): ?>
|
||||
<td style='text-align:center;'><?php echo to_currency($item['discounted_total'] / $item['quantity']); ?></td>
|
||||
<?php endif; ?>
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
<td class="item-name"><?php echo $item['name']; ?></td>
|
||||
<td><?php echo to_quantity_decimals($item['quantity']); ?></td>
|
||||
<td><?php echo to_currency($item['price']); ?></td>
|
||||
<td><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):$item['discount'] . '%';?></td>
|
||||
<td><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):to_decimals($item['discount']) . '%';?></td>
|
||||
<?php if($discount > 0): ?>
|
||||
<td><?php echo to_currency($item['discounted_total'] / $item['quantity']); ?></td>
|
||||
<?php endif; ?>
|
||||
|
||||
@@ -118,7 +118,7 @@
|
||||
elseif($item['discount_type'] == PERCENT)
|
||||
{
|
||||
?>
|
||||
<td colspan="3" class="discount"><?php echo number_format($item['discount'], 0) . " " . $this->lang->line("sales_discount_included") ?></td>
|
||||
<td colspan="3" class="discount"><?php echo to_decimals($item['discount']) . " " . $this->lang->line("sales_discount_included") ?></td>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -96,7 +96,7 @@
|
||||
elseif($item['discount_type'] == PERCENT)
|
||||
{
|
||||
?>
|
||||
<td colspan="3" class="discount"><?php echo number_format($item['discount'], 0) . " " . $this->lang->line("sales_discount_included") ?></td>
|
||||
<td colspan="3" class="discount"><?php echo to_decimals($item['discount']) . " " . $this->lang->line("sales_discount_included") ?></td>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -98,7 +98,7 @@
|
||||
elseif($item['discount_type'] == PERCENT)
|
||||
{
|
||||
?>
|
||||
<td colspan="2" class="discount"><?php echo number_format($item['discount'], 0) . " " . $this->lang->line("sales_discount_included") ?></td>
|
||||
<td colspan="2" class="discount"><?php echo to_decimals($item['discount']) . " " . $this->lang->line("sales_discount_included") ?></td>
|
||||
<?php
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -195,7 +195,7 @@ if(isset($success))
|
||||
|
||||
<td>
|
||||
<div class="input-group">
|
||||
<?php echo form_input(array('name'=>'discount', 'class'=>'form-control input-sm', 'value'=>$item['discount_type'] ? to_currency_no_money($item['discount']) : to_decimals($item['discount'], 0), 'tabindex'=>++$tabindex, 'onClick'=>'this.select();')); ?>
|
||||
<?php echo form_input(array('name'=>'discount', 'class'=>'form-control input-sm', 'value'=>$item['discount_type'] ? to_currency_no_money($item['discount']) : to_decimals($item['discount']), 'tabindex'=>++$tabindex, 'onClick'=>'this.select();')); ?>
|
||||
<span class="input-group-btn">
|
||||
<?php echo form_checkbox(array('id'=>'discount_toggle', 'name'=>'discount_toggle', 'value'=>1, 'data-toggle'=>"toggle",'data-size'=>'small', 'data-onstyle'=>'success', 'data-on'=>'<b>'.$this->config->item('currency_symbol').'</b>', 'data-off'=>'<b>%</b>', 'data-line'=>$line, 'checked'=>$item['discount_type'])); ?>
|
||||
</span>
|
||||
|
||||
@@ -139,7 +139,7 @@ $(document).ready(function()
|
||||
<td class="item-name"><?php echo $item['name']; ?></td>
|
||||
<td style='text-align:center;'><?php echo to_quantity_decimals($item['quantity']); ?></td>
|
||||
<td><?php echo to_currency($item['price']); ?></td>
|
||||
<td style='text-align:center;'><?php echo $item['discount'] . '%'; ?></td>
|
||||
<td style='text-align:center;'><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):to_decimals($item['discount']) . '%';?></td>
|
||||
<?php if($discount > 0): ?>
|
||||
<td style='text-align:center;'><?php echo to_currency($item['discounted_total'] / $item['quantity']); ?></td>
|
||||
<?php endif; ?>
|
||||
|
||||
@@ -123,7 +123,7 @@ if(isset($error_message))
|
||||
<td class="item-name"><?php echo $item['name']; ?></td>
|
||||
<td style='text-align:center;'><?php echo to_quantity_decimals($item['quantity']); ?></td>
|
||||
<td><?php if($print_price_info) echo to_currency($item['price']); ?></td>
|
||||
<td style='text-align:center;'><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):$item['discount'] . '%';?></td>
|
||||
<td style='text-align:center;'><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):to_decimals($item['discount']) . '%';?></td>
|
||||
<td style='border-right: solid 1px; text-align:right;'><?php if($print_price_info) echo to_currency($item['discounted_total']); ?></td>
|
||||
</tr>
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@
|
||||
<td class="item-name"><?php echo $item['name']; ?></td>
|
||||
<td><?php echo to_quantity_decimals($item['quantity']); ?></td>
|
||||
<td><?php echo to_currency($item['price']); ?></td>
|
||||
<td><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):$item['discount'] . '%';?></td>
|
||||
<td><?php echo ($item['discount_type']==FIXED)?to_currency($item['discount']):to_decimals($item['discount']) . '%';?></td>
|
||||
<td class="total-line"><?php echo to_currency($item['discounted_total']); ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
|
||||
Reference in New Issue
Block a user