From eac4c823d374ecff4a2e017efc7b36f9063b8a65 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 17 Feb 2016 13:06:03 +0200 Subject: [PATCH] Made expense currency conversion hidden by default --- app/Models/Expense.php | 14 +----- resources/lang/en/texts.php | 3 +- resources/views/expenses/edit.blade.php | 62 ++++++++++++++++--------- 3 files changed, 43 insertions(+), 36 deletions(-) diff --git a/app/Models/Expense.php b/app/Models/Expense.php index 9fbd5a485c7d..2749607c87e2 100644 --- a/app/Models/Expense.php +++ b/app/Models/Expense.php @@ -76,19 +76,9 @@ class Expense extends EntityModel return ENTITY_EXPENSE; } - public function apply($amount) + public function isExchanged() { - if ($amount > $this->balance) { - $applied = $this->balance; - $this->balance = 0; - } else { - $applied = $amount; - $this->balance = $this->balance - $amount; - } - - $this->save(); - - return $applied; + return $this->invoice_currency_id != $this->expense_currency_id; } } diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 114022662c69..63ac704fe8e1 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -1150,5 +1150,6 @@ return array( 'trial_success' => 'Successfully enabled two week free pro plan trial', 'overdue' => 'Overdue', 'white_label_text' => 'Purchase a ONE YEAR white label license for $'.WHITE_LABEL_PRICE.' to remove the Invoice Ninja branding from the client portal and help support our project.', - + + 'convert_currency' => 'Convert currency', ); diff --git a/resources/views/expenses/edit.blade.php b/resources/views/expenses/edit.blade.php index 8d413e16b69c..13a718919ab6 100644 --- a/resources/views/expenses/edit.blade.php +++ b/resources/views/expenses/edit.blade.php @@ -63,36 +63,46 @@ {!! Former::checkbox('should_be_invoiced') ->text(trans('texts.should_be_invoiced')) ->data_bind('checked: should_be_invoiced() || client_id(), enable: !client_id()') - ->label(' ') !!}
+ ->label(' ') !!} @endif - - {!! Former::select('invoice_currency_id')->addOption('','') - ->label(trans('texts.invoice_currency')) - ->data_placeholder(Utils::getFromCache($account->getCurrencyId(), 'currencies')->name) - ->data_bind('combobox: invoice_currency_id, disable: true') - ->fromQuery($currencies, 'name', 'id') !!} - - - {!! Former::plaintext('test') - ->value('') - ->style('min-height:46px') - ->label(trans('texts.invoice_currency')) !!} - + @if (!$expense || ($expense && ! $expense->isExchanged())) + {!! Former::checkbox('convert_currency') + ->text(trans('texts.convert_currency')) + ->data_bind('checked: convert_currency') + ->label(' ') !!} + @endif +
- {!! Former::text('exchange_rate') - ->data_bind("value: exchange_rate, enable: enableExchangeRate, valueUpdate: 'afterkeydown'") !!} +
+ + {!! Former::select('invoice_currency_id')->addOption('','') + ->label(trans('texts.invoice_currency')) + ->data_placeholder(Utils::getFromCache($account->getCurrencyId(), 'currencies')->name) + ->data_bind('combobox: invoice_currency_id, disable: true') + ->fromQuery($currencies, 'name', 'id') !!} + + + {!! Former::plaintext('test') + ->value('') + ->style('min-height:46px') + ->label(trans('texts.invoice_currency')) !!} + - {!! Former::text('invoice_amount') - ->addGroupClass('converted-amount') - ->data_bind("value: convertedAmount, enable: enableExchangeRate") - ->append('') !!} + {!! Former::text('exchange_rate') + ->data_bind("value: exchange_rate, enable: enableExchangeRate, valueUpdate: 'afterkeydown'") !!} + {!! Former::text('invoice_amount') + ->addGroupClass('converted-amount') + ->data_bind("value: convertedAmount, enable: enableExchangeRate") + ->append('') !!} +
- {!! Former::textarea('public_notes')->style('height:255px') !!} - {!! Former::textarea('private_notes')->style('height:255px') !!} + {!! Former::textarea('public_notes')->rows(8) !!} + {!! Former::textarea('private_notes')->rows(8) !!} +
@@ -194,6 +204,7 @@ self.amount = ko.observable(); self.exchange_rate = ko.observable(1); self.should_be_invoiced = ko.observable(); + self.convert_currency = ko.observable(false); if (data) { ko.mapping.fromJS(data, {}, this); @@ -230,9 +241,14 @@ }); self.enableExchangeRate = ko.computed(function() { + if (self.convert_currency()) { + return true; + } var expenseCurrencyId = self.expense_currency_id() || self.account_currency_id(); var invoiceCurrencyId = self.invoice_currency_id() || self.account_currency_id(); - return expenseCurrencyId != invoiceCurrencyId; + return expenseCurrencyId != invoiceCurrencyId + || invoiceCurrencyId != self.account_currency_id() + || expenseCurrencyId != self.account_currency_id(); }) };