1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 12:12:48 +01:00

Enable selecting currency symbol or code

This commit is contained in:
Hillel Coren 2016-10-20 17:17:47 +03:00
parent 4ed8246681
commit a0f8475a35
16 changed files with 80 additions and 24 deletions

View File

@ -551,6 +551,7 @@ if (!defined('CONTACT_EMAIL')) {
define('SESSION_TIMEZONE', 'timezone');
define('SESSION_CURRENCY', 'currency');
define('SESSION_CURRENCY_DECORATOR', 'currency_decorator');
define('SESSION_DATE_FORMAT', 'dateFormat');
define('SESSION_DATE_PICKER_FORMAT', 'datePickerFormat');
define('SESSION_DATETIME_FORMAT', 'datetimeFormat');
@ -751,6 +752,10 @@ if (!defined('CONTACT_EMAIL')) {
define('BANK_LIBRARY_OFX', 1);
define('CURRENCY_DECORATOR_CODE', 'code');
define('CURRENCY_DECORATOR_SYMBOL', 'symbol');
define('CURRENCY_DECORATOR_NONE', 'none');
define('RESELLER_REVENUE_SHARE', 'A');
define('RESELLER_LIMITED_USERS', 'B');

View File

@ -354,7 +354,7 @@ class Utils
return $data->first();
}
public static function formatMoney($value, $currencyId = false, $countryId = false, $showCode = false)
public static function formatMoney($value, $currencyId = false, $countryId = false, $decorator = CURRENCY_DECORATOR_SYMBOL)
{
$value = floatval($value);
@ -387,7 +387,9 @@ class Utils
$value = number_format($value, $precision, $decimal, $thousand);
$symbol = $currency->symbol;
if ($showCode || !$symbol) {
if ($decorator == CURRENCY_DECORATOR_NONE) {
return $value;
} elseif ($decorator == CURRENCY_DECORATOR_SYMBOL || ! $symbol) {
return "{$value} {$code}";
} elseif ($swapSymbol) {
return "{$value} " . trim($symbol);

View File

@ -438,7 +438,7 @@ class Account extends Eloquent
* @param bool $hideSymbol
* @return string
*/
public function formatMoney($amount, $client = null, $hideSymbol = false)
public function formatMoney($amount, $client = null, $decorator = CURRENCY_DECORATOR_SYMBOL)
{
if ($client && $client->currency_id) {
$currencyId = $client->currency_id;
@ -458,7 +458,7 @@ class Account extends Eloquent
$hideSymbol = $this->show_currency_code || $hideSymbol;
return Utils::formatMoney($amount, $currencyId, $countryId, $hideSymbol);
return Utils::formatMoney($amount, $currencyId, $countryId, $decorator);
}
/**
@ -1040,6 +1040,7 @@ class Account extends Eloquent
$locale = ($client && $client->language_id) ? $client->language->locale : ($this->language_id ? $this->Language->locale : DEFAULT_LOCALE);
Session::put(SESSION_CURRENCY, $currencyId);
Session::put(SESSION_CURRENCY_DECORATOR, $this->show_currency_code ? CURRENCY_DECORATOR_CODE : CURRENCY_DECORATOR_SYMBOL);
Session::put(SESSION_LOCALE, $locale);
App::setLocale($locale);

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -370,7 +370,7 @@ NINJA.invoiceLines = function(invoice) {
var row = [];
var item = invoice.invoice_items[i];
var cost = formatMoneyInvoice(item.cost, invoice, true);
var cost = formatMoneyInvoice(item.cost, invoice, 'none');
var qty = NINJA.parseFloat(item.qty) ? roundToTwo(NINJA.parseFloat(item.qty)) + '' : '';
var notes = item.notes;
var productKey = item.product_key;

View File

@ -2160,6 +2160,9 @@ $LANG = array(
'enterprise_upgrade_feature2' => 'Attach 3rd party files to invoices & expenses',
'much_more' => 'Much More!',
'currency_symbol' => 'Symbol',
'currency_code' => 'Code',
);
return $LANG;

View File

@ -1,5 +1,11 @@
@extends('header')
@section('head')
@parent
@include('money_script')
@stop
@section('content')
@parent
@ -20,11 +26,24 @@
</div>
<div class="panel-body form-padding-right">
{!! Former::select('currency_id')->addOption('','')
->fromQuery($currencies, 'name', 'id') !!}
{!! Former::select('currency_id')
->addOption('','')
->fromQuery($currencies, 'name', 'id')
->onchange('updateCurrencyCodeRadio()') !!}
{!! Former::radios('show_currency_code')->radios([
trans('texts.currency_symbol') . ': <span id="currency_symbol_example"/>' => array('name' => 'show_currency_code', 'value' => 0),
trans('texts.currency_code') . ': <span id="currency_code_example"/>' => array('name' => 'show_currency_code', 'value' => 1),
])->inline()
->check('timer')
->label('&nbsp;')
->addGroupClass('currrency_radio') !!}
<br/>
{!! Former::select('language_id')->addOption('','')
->fromQuery($languages, 'name', 'id')
->help(trans('texts.translate_app', ['link' => link_to(TRANSIFEX_URL, 'Transifex.com', ['target' => '_blank'])])) !!}
<br/>
{!! Former::select('timezone_id')->addOption('','')
->fromQuery($timezones, 'location', 'id') !!}
{!! Former::select('date_format_id')->addOption('','')
@ -34,7 +53,6 @@
{!! Former::select('start_of_week')->addOption('','')
->fromQuery($weekdays) !!}
{!! Former::checkbox('military_time')->text(trans('texts.enable')) !!}
{{-- Former::checkbox('show_currency_code')->text(trans('texts.enable')) --}}
</div>
</div>
@ -47,8 +65,31 @@
{!! Former::close() !!}
<script type="text/javascript">
function updateCurrencyCodeRadio() {
var currencyId = $('#currency_id').val();
var currency = currencyMap[currencyId];
var symbolExample = '';
var codeExample = '';
if ( ! currency || ! currency.symbol) {
$('.currrency_radio').hide();
} else {
symbolExample = formatMoney(100, currencyId, {{ Auth::user()->account->country_id }}, '{{ CURRENCY_DECORATOR_SYMBOL }}');
codeExample = formatMoney(100, currencyId, {{ Auth::user()->account->country_id }}, '{{ CURRENCY_DECORATOR_CODE }}');
$('.currrency_radio').show();
}
$('#currency_symbol_example').text(symbolExample);
$('#currency_code_example').text(codeExample);
}
</script>
@stop
@section('onReady')
$('#currency_id').focus();
updateCurrencyCodeRadio();
@stop

View File

@ -33,14 +33,14 @@
return window.parseFloat(str);
}
function formatMoneyInvoice(value, invoice, hideSymbol) {
function formatMoneyInvoice(value, invoice, decorator) {
var account = invoice.account;
var client = invoice.client;
return formatMoneyAccount(value, account, client, hideSymbol);
return formatMoneyAccount(value, account, client, decorator);
}
function formatMoneyAccount(value, account, client, hideSymbol) {
function formatMoneyAccount(value, account, client, decorator) {
var currencyId = false;
var countryId = false;
@ -56,10 +56,14 @@
countryId = account.country_id;
}
return formatMoney(value, currencyId, countryId, hideSymbol)
if ( ! decorator) {
decorator = account.show_currency_code ? 'code' : 'symbol';
}
function formatMoney(value, currencyId, countryId, hideSymbol) {
return formatMoney(value, currencyId, countryId, decorator)
}
function formatMoney(value, currencyId, countryId, decorator) {
value = NINJA.parseFloat(value);
if (!currencyId) {
@ -87,9 +91,9 @@
value = accounting.formatMoney(value, '', precision, thousand, decimal);
var symbol = currency.symbol;
if (hideSymbol) {
if (decorator == 'none') {
return value;
} else if (!symbol) {
} else if (decorator == 'code' || !symbol) {
return value + ' ' + code;
} else if (swapSymbol) {
return value + ' ' + symbol.trim();

View File

@ -29,7 +29,7 @@
<center>
@if(isset($amount))
{!! Button::success(strtoupper(trans('texts.pay_now') . ' - ' . $account->formatMoney($amount, $client, true) ))
{!! Button::success(strtoupper(trans('texts.pay_now') . ' - ' . $account->formatMoney($amount, $client, CURRENCY_DECORATOR_CODE) ))
->submit()
->large() !!}
@else

View File

@ -261,7 +261,7 @@
<p>&nbsp;</p>
<center>
@if(isset($amount))
{!! Button::success(strtoupper(trans('texts.pay_now') . ' - ' . $account->formatMoney($amount, $client, true) ))
{!! Button::success(strtoupper(trans('texts.pay_now') . ' - ' . $account->formatMoney($amount, $client, CURRENCY_DECORATOR_CODE) ))
->submit()
->large() !!}
@else

View File

@ -15,7 +15,7 @@
<header>
@if ($client && isset($invoiceNumber))
<h2>{{ $client->getDisplayName() }}</h2>
<h3>{{ trans('texts.invoice') . ' ' . $invoiceNumber }}<span>|&nbsp; {{ trans('texts.amount_due') }}: <em>{{ $account->formatMoney($amount, $client, true) }}</em></span></h3>
<h3>{{ trans('texts.invoice') . ' ' . $invoiceNumber }}<span>|&nbsp; {{ trans('texts.amount_due') }}: <em>{{ $account->formatMoney($amount, $client, CURRENCY_DECORATOR_CODE) }}</em></span></h3>
@elseif ($paymentTitle)
<h2>{{ $paymentTitle }}
@if(isset($paymentSubtitle))

View File

@ -237,7 +237,7 @@
->large() !!}
@if ($accountGateway->getPlaidEnabled() && !empty($amount))
{!! Button::success(strtoupper(trans('texts.pay_now') . ' - ' . $account->formatMoney($amount, $client, true) ))
{!! Button::success(strtoupper(trans('texts.pay_now') . ' - ' . $account->formatMoney($amount, $client, CURRENCY_DECORATOR_CODE) ))
->submit()
->withAttributes(['style'=>'display:none', 'id'=>'pay_now_button'])
->large() !!}

View File

@ -29,7 +29,7 @@
<center>
@if(isset($amount) && empty($paymentMethodPending))
{!! Button::success(strtoupper(trans('texts.pay_now') . ' - ' . $account->formatMoney($amount, $client, true) ))
{!! Button::success(strtoupper(trans('texts.pay_now') . ' - ' . $account->formatMoney($amount, $client, CURRENCY_DECORATOR_CODE) ))
->submit()
->large() !!}
@else