Fix tax percentage parsing (#458, #727)

Add tabindexes to price, discount field in register
This commit is contained in:
jekkos
2016-07-08 08:38:05 +02:00
parent ef2cd9d001
commit 21f5e46488
7 changed files with 23 additions and 18 deletions

View File

@@ -58,9 +58,9 @@ class Config extends Secure_Controller
{
$batch_save_data = array(
'default_tax_1_rate' => parse_decimals($this->input->post('default_tax_1_rate')),
'default_tax_1_name' => parse_decimals($this->input->post('default_tax_1_name')),
'default_tax_1_name' => $this->input->post('default_tax_1_name'),
'default_tax_2_rate' => parse_decimals($this->input->post('default_tax_2_rate')),
'default_tax_2_name' => parse_decimals($this->input->post('default_tax_2_name')),
'default_tax_2_name' => $this->input->post('default_tax_2_name'),
'tax_included' => $this->input->post('tax_included') != NULL,
'receiving_calculate_average_price' => $this->input->post('receiving_calculate_average_price') != NULL,
'lines_per_page' => $this->input->post('lines_per_page'),

View File

@@ -370,9 +370,10 @@ class Items extends Secure_Controller
$count = count($tax_percents);
for ($k = 0; $k < $count; ++$k)
{
if(is_numeric($tax_percents[$k]))
$tax_percentage = parse_decimals($tax_percents[$k]);
if(is_numeric($tax_percentage))
{
$items_taxes_data[] = array('name' => $tax_names[$k], 'percent' => parse_decimals($tax_percents[$k]));
$items_taxes_data[] = array('name' => $tax_names[$k], 'percent' => $tax_percentage);
}
}
$success &= $this->Item_taxes->save($items_taxes_data, $item_id);

View File

@@ -101,7 +101,7 @@ class Receivings extends Secure_Controller
function numeric($str)
{
return (bool) preg_match('/^[\-+]?([0-9]*[\.,])*?[0-9]+$/', $str);
return parse_decimals($str, 2);
}
public function edit_item($item_id)

View File

@@ -282,7 +282,7 @@ class Sales extends Secure_Controller
function numeric($str)
{
return (bool) preg_match('/^[\-+]?([0-9]*[\.,])*?[0-9]+$/', $str);
return parse_decimals($str, 2);
}
public function edit_item($item_id)

View File

@@ -36,6 +36,10 @@ function to_currency_no_money($number)
function to_tax_decimals($number)
{
if (empty($number))
{
return $number;
}
return to_decimals($number, 'tax_decimals');
}
@@ -51,7 +55,7 @@ function to_decimals($number, $decimals, $type=\NumberFormatter::DECIMAL)
$fmt->setAttribute(\NumberFormatter::MIN_FRACTION_DIGITS, $CI->config->item($decimals));
$fmt->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, $CI->config->item($decimals));
$fmt->setSymbol(\NumberFormatter::CURRENCY_SYMBOL, $CI->config->item('currency_symbol'));
return $fmt->format(floatval($number));
return $fmt->format($number);
}
function parse_decimals($number)

View File

@@ -17,7 +17,7 @@
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('config_number_locale'), 'number_locale', array('class' => 'control-label col-xs-2')); ?>
<div class='form-group'>
<div class='row'>
<div class='col-xs-1'>
<?php echo form_input('number_locale', $this->config->item('number_locale'), array('class' => 'form-control input-sm', 'id' => 'number_locale')); ?>
</div>

View File

@@ -67,6 +67,8 @@ if (isset($success))
</div>
<?php echo form_close(); ?>
<?php $tabindex = 0; ?>
<?php echo form_open($controller_name."/add", array('id'=>'add_item_form', 'class'=>'form-horizontal panel panel-default')); ?>
<div class="panel-body form-group">
<ul>
@@ -74,7 +76,7 @@ if (isset($success))
<label for="item" class='control-label'><?php echo $this->lang->line('sales_find_or_scan_item_or_receipt'); ?></label>
</li>
<li class="pull-left">
<?php echo form_input(array('name'=>'item', 'id'=>'item', 'class'=>'form-control input-sm', 'size'=>'50', 'tabindex'=>'1')); ?>
<?php echo form_input(array('name'=>'item', 'id'=>'item', 'class'=>'form-control input-sm', 'size'=>'50', 'tabindex'=>++$tabindex)); ?>
<span class="ui-helper-hidden-accessible" role="status"></span>
</li>
<li class="pull-right">
@@ -118,7 +120,6 @@ if (isset($success))
}
else
{
$tabindex = 2;
foreach(array_reverse($cart, true) as $line=>$item)
{
?>
@@ -135,7 +136,7 @@ if (isset($success))
if ($items_module_allowed)
{
?>
<td><?php echo form_input(array('name'=>'price', 'class'=>'form-control input-sm', 'value'=>to_currency_no_money($item['price'])));?></td>
<td><?php echo form_input(array('name'=>'price', 'class'=>'form-control input-sm', 'value'=>to_currency_no_money($item['price']), 'tabindex'=>++$tabindex));?></td>
<?php
}
else
@@ -158,12 +159,12 @@ if (isset($success))
}
else
{
echo form_input(array('name'=>'quantity', 'class'=>'form-control input-sm', 'value'=>to_quantity_decimals($item['quantity']), 'tabindex'=>$tabindex));
echo form_input(array('name'=>'quantity', 'class'=>'form-control input-sm', 'value'=>to_quantity_decimals($item['quantity']), 'tabindex'=>++$tabindex));
}
?>
</td>
<td><?php echo form_input(array('name'=>'discount', 'class'=>'form-control input-sm', 'value'=>to_decimals($item['discount'], 0)));?></td>
<td><?php echo form_input(array('name'=>'discount', 'class'=>'form-control input-sm', 'value'=>to_decimals($item['discount'], 0), 'tabindex'=>++$tabindex));?></td>
<td><?php echo to_currency($item['price']*$item['quantity']-$item['price']*$item['quantity']*$item['discount']/100); ?></td>
<td><a href="javascript:document.getElementById('<?php echo 'cart_'.$line ?>').submit();" title=<?php echo $this->lang->line('sales_update')?> ><span class="glyphicon glyphicon-refresh"></span></a></td>
</tr>
@@ -222,7 +223,6 @@ if (isset($success))
</tr>
<?php echo form_close(); ?>
<?php
++$tabindex;
}
}
?>
@@ -366,13 +366,13 @@ if (isset($success))
<tr>
<td><span id="amount_tendered_label"><?php echo $this->lang->line('sales_amount_tendered'); ?></span></td>
<td>
<?php echo form_input(array('name'=>'amount_tendered', 'id'=>'amount_tendered', 'class'=>'form-control input-sm disabled', 'disabled'=>'disabled', 'value'=>'0', 'size'=>'5', 'tabindex'=>$tabindex)); ?>
<?php echo form_input(array('name'=>'amount_tendered', 'id'=>'amount_tendered', 'class'=>'form-control input-sm disabled', 'disabled'=>'disabled', 'value'=>'0', 'size'=>'5', 'tabindex'=>++$tabindex)); ?>
</td>
</tr>
</table>
<?php echo form_close(); ?>
<div class='btn btn-sm btn-success pull-right' id='finish_sale_button' tabindex='<?php echo $tabindex+1; ?>'><span class="glyphicon glyphicon-ok">&nbsp</span><?php echo $this->lang->line('sales_complete_sale'); ?></div>
<div class='btn btn-sm btn-success pull-right' id='finish_sale_button' tabindex='<?php echo ++$tabindex; ?>'><span class="glyphicon glyphicon-ok">&nbsp</span><?php echo $this->lang->line('sales_complete_sale'); ?></div>
<?php
}
else
@@ -389,13 +389,13 @@ if (isset($success))
<tr>
<td><span id="amount_tendered_label"><?php echo $this->lang->line('sales_amount_tendered'); ?></span></td>
<td>
<?php echo form_input(array('name'=>'amount_tendered', 'id'=>'amount_tendered', 'class'=>'form-control input-sm', 'value'=>to_currency_no_money($amount_due), 'size'=>'5', 'tabindex'=>5)); ?>
<?php echo form_input(array('name'=>'amount_tendered', 'id'=>'amount_tendered', 'class'=>'form-control input-sm', 'value'=>to_currency_no_money($amount_due), 'size'=>'5', 'tabindex'=>++$tabindex)); ?>
</td>
</tr>
</table>
<?php echo form_close(); ?>
<div class='btn btn-sm btn-success pull-right' id='add_payment_button' tabindex='<?php echo $tabindex+2; ?>'><span class="glyphicon glyphicon-credit-card">&nbsp</span><?php echo $this->lang->line('sales_add_payment'); ?></div>
<div class='btn btn-sm btn-success pull-right' id='add_payment_button' tabindex='<?php echo ++$tabindex; ?>'><span class="glyphicon glyphicon-credit-card">&nbsp</span><?php echo $this->lang->line('sales_add_payment'); ?></div>
<?php
}
?>