Made expense currency conversion hidden by default

This commit is contained in:
Hillel Coren 2016-02-17 13:06:03 +02:00
parent ee516cb327
commit eac4c823d3
3 changed files with 43 additions and 36 deletions

View File

@ -76,19 +76,9 @@ class Expense extends EntityModel
return ENTITY_EXPENSE; return ENTITY_EXPENSE;
} }
public function apply($amount) public function isExchanged()
{ {
if ($amount > $this->balance) { return $this->invoice_currency_id != $this->expense_currency_id;
$applied = $this->balance;
$this->balance = 0;
} else {
$applied = $amount;
$this->balance = $this->balance - $amount;
}
$this->save();
return $applied;
} }
} }

View File

@ -1151,4 +1151,5 @@ return array(
'overdue' => 'Overdue', '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.', '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',
); );

View File

@ -63,9 +63,18 @@
{!! Former::checkbox('should_be_invoiced') {!! Former::checkbox('should_be_invoiced')
->text(trans('texts.should_be_invoiced')) ->text(trans('texts.should_be_invoiced'))
->data_bind('checked: should_be_invoiced() || client_id(), enable: !client_id()') ->data_bind('checked: should_be_invoiced() || client_id(), enable: !client_id()')
->label(' ') !!}<br/> ->label(' ') !!}
@endif @endif
@if (!$expense || ($expense && ! $expense->isExchanged()))
{!! Former::checkbox('convert_currency')
->text(trans('texts.convert_currency'))
->data_bind('checked: convert_currency')
->label(' ') !!}
@endif
<br/>
<div style="display:none" data-bind="visible: enableExchangeRate">
<span style="display:none" data-bind="visible: !client_id()"> <span style="display:none" data-bind="visible: !client_id()">
{!! Former::select('invoice_currency_id')->addOption('','') {!! Former::select('invoice_currency_id')->addOption('','')
->label(trans('texts.invoice_currency')) ->label(trans('texts.invoice_currency'))
@ -87,12 +96,13 @@
->addGroupClass('converted-amount') ->addGroupClass('converted-amount')
->data_bind("value: convertedAmount, enable: enableExchangeRate") ->data_bind("value: convertedAmount, enable: enableExchangeRate")
->append('<span data-bind="html: invoiceCurrencyCode"></span>') !!} ->append('<span data-bind="html: invoiceCurrencyCode"></span>') !!}
</div>
</div> </div>
<div class="col-md-6"> <div class="col-md-6">
{!! Former::textarea('public_notes')->style('height:255px') !!} {!! Former::textarea('public_notes')->rows(8) !!}
{!! Former::textarea('private_notes')->style('height:255px') !!} {!! Former::textarea('private_notes')->rows(8) !!}
</div> </div>
</div> </div>
</div> </div>
@ -194,6 +204,7 @@
self.amount = ko.observable(); self.amount = ko.observable();
self.exchange_rate = ko.observable(1); self.exchange_rate = ko.observable(1);
self.should_be_invoiced = ko.observable(); self.should_be_invoiced = ko.observable();
self.convert_currency = ko.observable(false);
if (data) { if (data) {
ko.mapping.fromJS(data, {}, this); ko.mapping.fromJS(data, {}, this);
@ -230,9 +241,14 @@
}); });
self.enableExchangeRate = ko.computed(function() { self.enableExchangeRate = ko.computed(function() {
if (self.convert_currency()) {
return true;
}
var expenseCurrencyId = self.expense_currency_id() || self.account_currency_id(); var expenseCurrencyId = self.expense_currency_id() || self.account_currency_id();
var invoiceCurrencyId = self.invoice_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();
}) })
}; };