add currency decimals configuration, fix quantity decimals in forms, merged helpers in locale one (#307 #429)

This commit is contained in:
FrancescoUK
2016-04-01 21:07:29 +01:00
parent 12f4209055
commit c5037c5725
27 changed files with 123 additions and 78 deletions

View File

@@ -83,7 +83,7 @@ $autoload['drivers'] = array();
|
| $autoload['helper'] = array('url', 'file');
*/
$autoload['helper'] = array('form', 'url', 'table', 'text', 'currency', 'html', 'download', 'directory', 'dateformat', 'quantity');
$autoload['helper'] = array('form', 'url', 'table', 'text', 'locale', 'html', 'download', 'directory');
/*
| -------------------------------------------------------------------

View File

@@ -63,12 +63,12 @@ class Config extends Secure_area
$message = $this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully');
$message = $upload_success ? $message : $this->upload->display_errors();
echo json_encode(array('success'=>$success,'message'=>$message));
echo json_encode(array('success'=>$success, 'message'=>$message));
}
function save_locale()
{
$batch_save_data=array(
$batch_save_data = array(
'currency_symbol'=>$this->input->post('currency_symbol'),
'currency_side'=>$this->input->post('currency_side') != null,
'language'=>$this->input->post('language'),
@@ -77,10 +77,11 @@ class Config extends Secure_area
'timeformat'=>$this->input->post('timeformat'),
'thousands_separator'=>$this->input->post('thousands_separator'),
'decimal_point'=>$this->input->post('decimal_point'),
'currency_decimals'=>$this->input->post('currency_decimals'),
'quantity_decimals'=>$this->input->post('quantity_decimals')
);
$result = $this->Appconfig->batch_save( $batch_save_data );
$result = $this->Appconfig->batch_save($batch_save_data);
$success = $result ? true : false;
echo json_encode(array('success'=>$success, 'message'=>$this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully')));
@@ -131,7 +132,7 @@ class Config extends Secure_area
$success = $this->db->trans_complete();
echo json_encode(array('success'=>$success,'message'=>$this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully')));
echo json_encode(array('success'=>$success, 'message'=>$this->lang->line('config_saved_' . ($success ? '' : 'un') . 'successfully')));
}
function save_barcode()
@@ -185,7 +186,7 @@ class Config extends Secure_area
{
$result = $this->Appconfig->batch_save(array('company_logo' => ''));
echo json_encode(array('success' => $result));
echo json_encode(array('success'=>$result));
}
private function _handle_logo_upload()
@@ -221,7 +222,8 @@ class Config extends Secure_area
$file_name = 'ospos-' . date("Y-m-d-H-i-s") .'.zip';
$save = 'uploads/'.$file_name;
$this->load->helper('download');
while (ob_get_level()) {
while (ob_get_level())
{
ob_end_clean();
}
force_download($file_name, $backup);

View File

@@ -1,40 +0,0 @@
<?php
function to_currency($number, $escape=FALSE)
{
$CI =& get_instance();
$currency_symbol = $CI->config->item('currency_symbol') ? $CI->config->item('currency_symbol') : '$';
$currency_symbol = $currency_symbol == '$' && $escape ? '\$' : $currency_symbol;
$thousands_separator = $CI->config->item('thousands_separator') ? $CI->config->item('thousands_separator') : '';
$decimal_point = $CI->config->item('decimal_point') ? $CI->config->item('decimal_point') : '.';
$decimals = $CI->config->item('currency_decimals') ? $CI->config->item('currency_decimals') : 2;
if($number >= 0)
{
if($CI->config->item('currency_side') !== 'currency_side')
return $currency_symbol.number_format($number, $decimals, $decimal_point, $thousands_separator);
else
return number_format($number, $decimals, $decimal_point, $thousands_separator).$currency_symbol;
}
else
{
if($CI->config->item('currency_side') !== 'currency_side')
return '-'.$currency_symbol.number_format(abs($number), $decimals, $decimal_point, $thousands_separator);
else
return '-'.number_format(abs($number), $decimals, $decimal_point, $thousands_separator).$currency_symbol;
}
}
function to_currency_no_money($number)
{
$CI =& get_instance();
$thousands_separator = $CI->config->item('thousands_separator') ? $CI->config->item('thousands_separator') : '';
$decimal_point = $CI->config->item('decimal_point') ? $CI->config->item('decimal_point') : '.';
$decimals = $CI->config->item('currency_decimals') ? $CI->config->item('currency_decimals') : 2;
return number_format($number, $decimals, $decimal_point, $thousands_separator);
}
?>

View File

@@ -1,9 +1,72 @@
<?php
class DateFormatter {
/*
* Currency locale
*/
function to_currency($number, $escape=FALSE)
{
$CI =& get_instance();
$currency_symbol = $CI->config->item('currency_symbol') ? $CI->config->item('currency_symbol') : '$';
$currency_symbol = $currency_symbol == '$' && $escape ? '\$' : $currency_symbol;
$thousands_separator = $CI->config->item('thousands_separator') ? $CI->config->item('thousands_separator') : '';
$decimal_point = $CI->config->item('decimal_point') ? $CI->config->item('decimal_point') : '.';
$decimals = $CI->config->item('currency_decimals') ? $CI->config->item('currency_decimals') : 0;
if($number >= 0)
{
if($CI->config->item('currency_side') !== 'currency_side')
return $currency_symbol.number_format($number, $decimals, $decimal_point, $thousands_separator);
else
return number_format($number, $decimals, $decimal_point, $thousands_separator).$currency_symbol;
}
else
{
if($CI->config->item('currency_side') !== 'currency_side')
return '-'.$currency_symbol.number_format(abs($number), $decimals, $decimal_point, $thousands_separator);
else
return '-'.number_format(abs($number), $decimals, $decimal_point, $thousands_separator).$currency_symbol;
}
}
function to_currency_no_money($number)
{
// ignore empty strings as they are just for empty input
if( empty($number) )
{
return $number;
}
$CI =& get_instance();
$decimals = $CI->config->item('currency_decimals') ? $CI->config->item('currency_decimals') : 0;
return number_format($number, $decimals, '.', '');
}
/*
* Quantity decimals
*/
function to_quantity($number)
{
$CI =& get_instance();
$decimal_point = $CI->config->item('decimal_point') ? $CI->config->item('decimal_point') : '.';
$decimals = $CI->config->item('quantity_decimals') ? $CI->config->item('quantity_decimals') : 0;
return number_format($number, $decimals, $decimal_point, '');
}
function quantity_decimals()
{
$CI =& get_instance();
return $CI->config->item('quantity_decimals') ? $CI->config->item('quantity_decimals') : 0;
}
/*
* Matches each symbol of PHP date format standard
* with jQuery equivalent codeword
@@ -112,6 +175,7 @@ function dateformat_momentjs($php_format)
'r' => '', // no equivalent
'U' => 'X'
);
return strtr($php_format, $SYMBOLS_MATCHING);
}
@@ -178,4 +242,4 @@ function dateformat_bootstrap($php_format)
return $bootstrap_format;
}
?>
?>

View File

@@ -1,13 +0,0 @@
<?php
function to_quantity($number)
{
$CI =& get_instance();
$decimals = $CI->config->item('quantity_decimals') ? $CI->config->item('quantity_decimals') : 0;
$decimal_point = $CI->config->item('decimal_point') ? $CI->config->item('decimal_point') : '.';
return number_format($number, $decimals, $decimal_point, '');
}
?>

View File

@@ -34,6 +34,7 @@ $lang["config_company_required"] = "Firmenname ist erforderlich";
$lang["config_company_website_url"] = "Webseite ist nicht in korrektem Format";
$lang["config_currency_side"] = "Pos. rechts";
$lang["config_currency_symbol"] = "Währungssymbol";
$lang["config_currency_decimals"] = "Currency Decimals";
$lang["config_custom1"] = "Zusatzfeld 1";
$lang["config_custom10"] = "Zusatzfeld 10";
$lang["config_custom2"] = "Zusatzfeld 2";

View File

@@ -34,6 +34,7 @@ $lang["config_company_required"] = "Company name is a required field";
$lang["config_company_website_url"] = "Company website is not a valid URL (http://...)";
$lang["config_currency_side"] = "Right side";
$lang["config_currency_symbol"] = "Currency Symbol";
$lang["config_currency_decimals"] = "Currency Decimals";
$lang["config_custom1"] = "Custom Field 1";
$lang["config_custom10"] = "Custom Field 10";
$lang["config_custom2"] = "Custom Field 2";

View File

@@ -34,6 +34,7 @@ $lang["config_company_required"] = "Nombre del Comercio es requerido";
$lang["config_company_website_url"] = "Sitio Web no es una URL estándar (http://...)";
$lang["config_currency_side"] = "Lado derecho";
$lang["config_currency_symbol"] = "Símbolo de moneda";
$lang["config_currency_decimals"] = "Currency Decimals";
$lang["config_custom1"] = "Campo Libre 1";
$lang["config_custom10"] = "Campo Libre 10";
$lang["config_custom2"] = "Campo Libre 2";

View File

@@ -34,6 +34,7 @@ $lang["config_company_required"] = "Le nom d'entreprise est requis";
$lang["config_company_website_url"] = "Le site web de l'entreprise n'est pas une URL valide (http://...)";
$lang["config_currency_side"] = "Symbole à droite";
$lang["config_currency_symbol"] = "Symbole Monétaire";
$lang["config_currency_decimals"] = "Currency Decimals";
$lang["config_custom1"] = "Champ Personnalisé 1";
$lang["config_custom10"] = "Champ Personnalisé 10";
$lang["config_custom2"] = "Champ Personnalisé 2";

View File

@@ -34,6 +34,7 @@ $lang["config_company_required"] = "Cégnév kötelező mező";
$lang["config_company_website_url"] = "A cég webcime nem érvényes URL (http://...)";
$lang["config_currency_side"] = "Jobb oldal";
$lang["config_currency_symbol"] = "Pénznem";
$lang["config_currency_decimals"] = "Currency Decimals";
$lang["config_custom1"] = "Egyedi mező 1";
$lang["config_custom10"] = "Egyedi mező 10";
$lang["config_custom2"] = "Egyedi mező 2";

View File

@@ -34,6 +34,7 @@ $lang["config_company_required"] = "Nama Perusahaan wajib diisi";
$lang["config_company_website_url"] = "Situs Perusahaan bukan URL yang benar(http://...)";
$lang["config_currency_side"] = "Sisi Kanan";
$lang["config_currency_symbol"] = "Simbol Mata Uang";
$lang["config_currency_decimals"] = "Currency Decimals";
$lang["config_custom1"] = "Custom Field 1";
$lang["config_custom10"] = "Custom Field 10";
$lang["config_custom2"] = "Custom Field 2";

View File

@@ -34,6 +34,7 @@ $lang["config_company_required"] = "De bedrijfsnaam moet ingevuld worden";
$lang["config_company_website_url"] = "De website van het bedrijf is geen geldige URL (http://...)";
$lang["config_currency_side"] = "Rechterkant";
$lang["config_currency_symbol"] = "Valuta";
$lang["config_currency_decimals"] = "Currency Decimals";
$lang["config_custom1"] = "Custom Veld 1";
$lang["config_custom10"] = "Custom Veld 10";
$lang["config_custom2"] = "Custom Veld 2";

View File

@@ -34,6 +34,7 @@ $lang["config_company_required"] = "Имя Компании обязательн
$lang["config_company_website_url"] = "Веб-сайт Компании не является допустимым URL (http://...)";
$lang["config_currency_side"] = "Правая сторона";
$lang["config_currency_symbol"] = "Символ валюты";
$lang["config_currency_decimals"] = "Currency Decimals";
$lang["config_custom1"] = "Изготовленный пробел 1";
$lang["config_custom10"] = "Изготовленный пробел 10";
$lang["config_custom2"] = "Изготовленный пробел 2";

View File

@@ -34,6 +34,7 @@ $lang["config_company_required"] = "ชื่อร้านค้าต้อ
$lang["config_company_website_url"] = "เว็บไซต์ร้านค้าไม่ถูกต้อง";
$lang["config_currency_side"] = "ด้านขวา";
$lang["config_currency_symbol"] = "สัญลักษณ์ค่าเงิน";
$lang["config_currency_decimals"] = "Currency Decimals";
$lang["config_custom1"] = "พื้นที่เพิ่มเติม 1";
$lang["config_custom10"] = "พื้นที่เพิ่มเติม 10";
$lang["config_custom2"] = "พื้นที่เพิ่มเติม 2";

View File

@@ -34,6 +34,7 @@ $lang["config_company_required"] = "Şirket Adı zorunlu alandır";
$lang["config_company_website_url"] = "website adresi yanlış (http://...)";
$lang["config_currency_side"] = "Sağda";
$lang["config_currency_symbol"] = "Para Birimi";
$lang["config_currency_decimals"] = "Currency Decimals";
$lang["config_custom1"] = "Özel Alan 1";
$lang["config_custom10"] = "Özel Alan 10";
$lang["config_custom2"] = "Özel Alan 2";

View File

@@ -34,6 +34,7 @@ $lang["config_company_required"] = "公司名稱為必填";
$lang["config_company_website_url"] = "公司網址格式錯誤 (http://...)";
$lang["config_currency_side"] = "Right side";
$lang["config_currency_symbol"] = "貨幣符號";
$lang["config_currency_decimals"] = "Currency Decimals";
$lang["config_custom1"] = "Custom Field 1";
$lang["config_custom10"] = "Custom Field 10";
$lang["config_custom2"] = "Custom Field 2";

View File

@@ -25,6 +25,19 @@
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('config_currency_decimals'), 'language', array('class'=>'control-label col-xs-2')); ?>
<div class='col-xs-2'>
<?php echo form_dropdown('currency_decimals', array(
'0' => '0',
'1' => '1',
'2' => '2'
),
$this->config->item('currency_decimals'), array('class'=>'form-control input-sm'));
?>
</div>
</div>
<div class="form-group form-group-sm">
<?php echo form_label($this->lang->line('config_decimal_point'), 'language', array('class'=>'control-label col-xs-2')); ?>
<div class='col-xs-2'>

View File

@@ -38,7 +38,7 @@
'name'=>'value',
'id'=>'value',
'class'=>'form-control input-sm',
'value'=>$giftcard_info->value)
'value'=>to_currency_no_money($giftcard_info->value))
);?>
</div>
</div>

View File

@@ -106,7 +106,7 @@ $(document).ready(function()
function display_stock(location_id)
{
var item_quantities = <?php echo json_encode($item_quantities); ?>;
document.getElementById("quantity").value = item_quantities[location_id];
document.getElementById("quantity").value = parseFloat(item_quantities[location_id]).toFixed(<?php echo quantity_decimals(); ?>);
var inventory_data = <?php echo json_encode($inventory_array); ?>;
var employee_data = <?php echo json_encode($employee_name); ?>;
@@ -137,7 +137,7 @@ function display_stock(location_id)
tr.appendChild(td);
td = document.createElement('td');
td.appendChild(document.createTextNode(data['trans_inventory']));
td.appendChild(document.createTextNode(parseFloat(data['trans_inventory']).toFixed(<?php echo quantity_decimals(); ?>)));
td.setAttribute("style", "text-align:center");
tr.appendChild(td);
@@ -149,5 +149,4 @@ function display_stock(location_id)
}
}
}
</script>

View File

@@ -62,7 +62,7 @@
'name'=>'cost_price',
'id'=>'cost_price',
'class'=>'form-control input-sm',
'value'=>$item_info->cost_price)
'value'=>to_currency_no_money($item_info->cost_price))
);?>
</div>
</div>
@@ -77,7 +77,7 @@
'name'=>'unit_price',
'id'=>'unit_price',
'class'=>'form-control input-sm',
'value'=>$item_info->unit_price)
'value'=>to_currency_no_money($item_info->unit_price))
);?>
</div>
</div>

View File

@@ -132,10 +132,9 @@ $(document).ready(function()
});
});
function fill_quantity(val)
{
var item_quantities = <?php echo json_encode($item_quantities); ?>;
document.getElementById("quantity").value = item_quantities[val];
document.getElementById("quantity").value = parseFloat(item_quantities[val]).toFixed(<?php echo quantity_decimals(); ?>);
}
</script>

View File

@@ -119,7 +119,7 @@ if (isset($error))
<tr>
<td><?php echo anchor("receivings/delete_item/$line", '<span class="glyphicon glyphicon-trash"></span>');?></td>
<td style="align:center;">
<?php echo $item['name']; ?><br /> [<?php echo $item['in_stock']; ?> in <?php echo $item['stock_name']; ?>]
<?php echo $item['name']; ?><br /> <?php echo '[' . to_quantity($item['in_stock']) . 'in' . $item['stock_name'] . ']'; ?>
<?php echo form_hidden('location', $item['item_location']); ?>
</td>
@@ -127,7 +127,7 @@ if (isset($error))
if ($items_module_allowed && $mode !='requisition')
{
?>
<td><?php echo form_input(array('name'=>'price', 'class'=>'form-control input-sm', 'value'=>$item['price']));?></td>
<td><?php echo form_input(array('name'=>'price', 'class'=>'form-control input-sm', 'value'=>to_currency_no_money($item['price'])));?></td>
<?php
}
else

View File

@@ -126,7 +126,7 @@ if (isset($success))
<td><?php echo anchor("sales/delete_item/$line", '<span class="glyphicon glyphicon-trash"></span>');?></td>
<td><?php echo $item['item_number']; ?></td>
<td style="align: center;">
<?php echo $item['name']; ?><br /> [<?php echo $item['in_stock'] ?> in <?php echo $item['stock_name']; ?>]
<?php echo $item['name']; ?><br /> <?php echo '[' . to_quantity($item['in_stock']) . 'in' . $item['stock_name'] . ']'; ?>
<?php echo form_hidden('location', $item['item_location']); ?>
</td>
@@ -134,7 +134,7 @@ if (isset($success))
if ($items_module_allowed)
{
?>
<td><?php echo form_input(array('name'=>'price', 'class'=>'form-control input-sm', 'value'=>$item['price']));?></td>
<td><?php echo form_input(array('name'=>'price', 'class'=>'form-control input-sm', 'value'=>to_currency_no_money($item['price'])));?></td>
<?php
}
else
@@ -668,7 +668,7 @@ function check_payment_type_giftcard()
else
{
$("#amount_tendered_label").html("<?php echo $this->lang->line('sales_amount_tendered'); ?>");
$("#amount_tendered").val('<?php echo $amount_due; ?>');
$("#amount_tendered").val('<?php echo to_currency_no_money($amount_due); ?>');
}
}

View File

@@ -57,7 +57,10 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES
('show_total_discount', '1'),
('dateformat', 'm/d/Y'),
('timeformat', 'H:i:s'),
('currency_symbol', '$');
('currency_symbol', '$'),
('decimal_point', '.'),
('currency_decimals', '2'),
('quantity_decimals', '0');
-- --------------------------------------------------------

View File

@@ -57,7 +57,10 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES
('show_total_discount', '1'),
('dateformat', 'm/d/Y'),
('timeformat', 'H:i:s'),
('currency_symbol', '$');
('currency_symbol', '$'),
('decimal_point', '.'),
('currency_decimals', '2'),
('quantity_decimals', '0');
-- --------------------------------------------------------

View File

@@ -57,7 +57,10 @@ INSERT INTO `ospos_app_config` (`key`, `value`) VALUES
('show_total_discount', '1'),
('dateformat', 'm/d/Y'),
('timeformat', 'H:i:s'),
('currency_symbol', '$');
('currency_symbol', '$'),
('decimal_point', '.'),
('currency_decimals', '2'),
('quantity_decimals', '0');
-- --------------------------------------------------------

View File

@@ -33,6 +33,7 @@ config_company_required,Cégnév kötelező mező,Firmenname ist erforderlich,De
config_company_website_url,A cég webcime nem érvényes URL (http://...),Webseite ist nicht in korrektem Format,De website van het bedrijf is geen geldige URL (http://...),Sitio Web no es una URL estándar (http://...),Company website is not a valid URL (http://...),Le site web de l'entreprise n'est pas une URL valide (http://...),公司網址格式錯誤 (http://...),Веб-сайт Компании не является допустимым URL (http://...),เว็บไซต์ร้านค้าไม่ถูกต้อง,website adresi yanlış (http://...),Situs Perusahaan bukan URL yang benar(http://...)
config_currency_side,Jobb oldal,Pos. rechts,Rechterkant,Lado derecho,Right side,Symbole à droite,Right side,Правая сторона,ด้านขวา,Sağda,Sisi Kanan
config_currency_symbol,Pénznem,Währungssymbol,Valuta,Símbolo de moneda,Currency Symbol,Symbole Monétaire,貨幣符號,Символ валюты,สัญลักษณ์ค่าเงิน,Para Birimi,Simbol Mata Uang
config_currency_decimals,Currency Decimals,Currency Decimals,Currency Decimals,Currency Decimals,Currency Decimals,Currency Decimals,Currency Decimals,Currency Decimals,Currency Decimals,Currency Decimals,Currency Decimals
config_custom1,Egyedi mező 1,Zusatzfeld 1,Custom Veld 1,Campo Libre 1,Custom Field 1,Champ Personnalisé 1,Custom Field 1,Изготовленный пробел 1,พื้นที่เพิ่มเติม 1,Özel Alan 1,Custom Field 1
config_custom10,Egyedi mező 10,Zusatzfeld 10,Custom Veld 10,Campo Libre 10,Custom Field 10,Champ Personnalisé 10,Custom Field 10,Изготовленный пробел 10,พื้นที่เพิ่มเติม 10,Özel Alan 10,Custom Field 10
config_custom2,Egyedi mező 2,Zusatzfeld 2,Custom Veld 2,Campo Libre 2,Custom Field 2,Champ Personnalisé 2,Custom Field 2,Изготовленный пробел 2,พื้นที่เพิ่มเติม 2,Özel Alan 2,Custom Field 2
1 label hu-HU de-CH nl-BE es en fr zh ru th tr id
33 config_company_website_url A cég webcime nem érvényes URL (http://...) Webseite ist nicht in korrektem Format De website van het bedrijf is geen geldige URL (http://...) Sitio Web no es una URL estándar (http://...) Company website is not a valid URL (http://...) Le site web de l'entreprise n'est pas une URL valide (http://...) 公司網址格式錯誤 (http://...) Веб-сайт Компании не является допустимым URL (http://...) เว็บไซต์ร้านค้าไม่ถูกต้อง website adresi yanlış (http://...) Situs Perusahaan bukan URL yang benar(http://...)
34 config_currency_side Jobb oldal Pos. rechts Rechterkant Lado derecho Right side Symbole à droite Right side Правая сторона ด้านขวา Sağda Sisi Kanan
35 config_currency_symbol Pénznem Währungssymbol Valuta Símbolo de moneda Currency Symbol Symbole Monétaire 貨幣符號 Символ валюты สัญลักษณ์ค่าเงิน Para Birimi Simbol Mata Uang
36 config_currency_decimals Currency Decimals Currency Decimals Currency Decimals Currency Decimals Currency Decimals Currency Decimals Currency Decimals Currency Decimals Currency Decimals Currency Decimals Currency Decimals
37 config_custom1 Egyedi mező 1 Zusatzfeld 1 Custom Veld 1 Campo Libre 1 Custom Field 1 Champ Personnalisé 1 Custom Field 1 Изготовленный пробел 1 พื้นที่เพิ่มเติม 1 Özel Alan 1 Custom Field 1
38 config_custom10 Egyedi mező 10 Zusatzfeld 10 Custom Veld 10 Campo Libre 10 Custom Field 10 Champ Personnalisé 10 Custom Field 10 Изготовленный пробел 10 พื้นที่เพิ่มเติม 10 Özel Alan 10 Custom Field 10
39 config_custom2 Egyedi mező 2 Zusatzfeld 2 Custom Veld 2 Campo Libre 2 Custom Field 2 Champ Personnalisé 2 Custom Field 2 Изготовленный пробел 2 พื้นที่เพิ่มเติม 2 Özel Alan 2 Custom Field 2