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

working on payment currency

This commit is contained in:
Hillel Coren 2017-11-19 11:55:01 +02:00
parent 5fb49dd1f5
commit 1d2134e59f
9 changed files with 45 additions and 7 deletions

View File

@ -100,6 +100,7 @@ class ReportController extends BaseController
'invoice_status' => request()->invoice_status,
'group_dates_by' => request()->group_dates_by,
'document_filter' => request()->document_filter,
'currency_type' => request()->currency_type,
'export_format' => $format,
];
$report = new $reportClass($startDate, $endDate, $isExport, $options);

View File

@ -91,7 +91,13 @@ class PaymentDatatable extends EntityDatatable
[
'amount',
function ($model) {
return Utils::formatMoney($model->amount, $model->currency_id, $model->country_id);
$amount = Utils::formatMoney($model->amount, $model->currency_id, $model->country_id);
if ($model->exchange_currency_id && $model->exchange_rate != 1) {
$amount .= ' | ' . Utils::formatMoney($model->amount * $model->exchange_rate, $model->exchange_currency_id, $model->country_id);
}
return $amount;
},
],
[

View File

@ -4,6 +4,7 @@ namespace App\Ninja\Reports;
use App\Models\Payment;
use Auth;
use Utils;
class PaymentReport extends AbstractReport
{
@ -20,6 +21,7 @@ class PaymentReport extends AbstractReport
public function run()
{
$account = Auth::user()->account;
$currencyType = $this->options['currency_type'];
$invoiceMap = [];
$payments = Payment::scope()
@ -39,22 +41,36 @@ class PaymentReport extends AbstractReport
foreach ($payments->get() as $payment) {
$invoice = $payment->invoice;
$client = $payment->client;
$amount = $payment->getCompletedAmount();
if ($currencyType == 'converted') {
$amount *= $payment->exchange_rate;
$this->addToTotals($payment->exchange_currency_id, 'paid', $amount);
$amount = Utils::formatMoney($amount, $payment->exchange_currency_id);
} else {
$this->addToTotals($client->currency_id, 'paid', $amount);
$amount = $account->formatMoney($amount, $client);
}
$this->data[] = [
$this->isExport ? $client->getDisplayName() : $client->present()->link,
$this->isExport ? $invoice->invoice_number : $invoice->present()->link,
$invoice->present()->invoice_date,
$account->formatMoney($invoice->amount, $client),
$payment->present()->payment_date,
$account->formatMoney($payment->getCompletedAmount(), $client),
$amount,
$payment->present()->method,
];
if (! isset($invoiceMap[$invoice->id])) {
$this->addToTotals($client->currency_id, 'amount', $invoice->amount);
$invoiceMap[$invoice->id] = true;
}
$this->addToTotals($client->currency_id, 'paid', $payment->getCompletedAmount());
if ($currencyType == 'converted') {
$this->addToTotals($payment->exchange_currency_id, 'amount', $invoice->amount * $payment->exchange_rate);
} else {
$this->addToTotals($client->currency_id, 'amount', $invoice->amount);
}
}
}
}
}

View File

@ -64,6 +64,8 @@ class PaymentRepository extends BaseRepository
'payments.routing_number',
'payments.bank_name',
'payments.private_notes',
'payments.exchange_rate',
'payments.exchange_currency_id',
'invoices.is_deleted as invoice_is_deleted',
'gateways.name as gateway_name',
'gateways.id as gateway_id',
@ -187,7 +189,7 @@ class PaymentRepository extends BaseRepository
$payment->payment_date = date('Y-m-d');
}
$payment->fill(request()->all());
$payment->fill($input);
if (! $publicId) {
$clientId = $input['client_id'];

View File

@ -60,6 +60,8 @@ class PaymentTransformer extends EntityTransformer
'invoice_id' => (int) ($this->invoice ? $this->invoice->public_id : $payment->invoice->public_id),
'invoice_number' => $this->invoice ? $this->invoice->invoice_number : $payment->invoice->invoice_number,
'private_notes' => $payment->private_notes,
'exchange_rate' => (float) $payment->exchange_rate,
'exchange_currency_id' => (int) $payment->exchange_currency_id,
]);
}
}

View File

@ -2524,6 +2524,8 @@ $LANG = array(
'your_password_reset_link' => 'Your Password Reset Link',
'subdomain_taken' => 'The subdomain is already in use',
'client_login' => 'Client Login',
'converted_amount' => 'Converted Amount',
'default' => 'Default',
);

View File

@ -9,6 +9,7 @@
<td>{{ trans('texts.method') }}</td>
<td>{{ trans('texts.transaction_reference') }}</td>
<td>{{ trans('texts.private_notes') }}</td>
<td>{{ trans('texts.converted_amount') }}</td>
</tr>
@foreach ($payments as $payment)
@ -24,6 +25,7 @@
<td>{{ $payment->present()->method }}</td>
<td>{{ $payment->transaction_reference }}</td>
<td>{{ $payment->private_notes }}</td>
<td>{{ Utils::formatMoney($payment->amount * $payment->exchange_rate, $payment->exchange_currency_id) }}</td>
</tr>
@endif
@endforeach

View File

@ -90,7 +90,7 @@
{!! Former::text('exchange_rate')
->data_bind("value: exchange_rate, enable: enableExchangeRate, valueUpdate: 'afterkeydown'") !!}
{!! Former::text('')
->label(trans('texts.amount'))
->label(trans('texts.converted_amount'))
->data_bind("value: convertedAmount, enable: enableExchangeRate")
->append('<span data-bind="html: exchangeCurrencyCode"></span>') !!}
</div>

View File

@ -141,6 +141,12 @@
->addOption(trans('texts.payment_date'), FILTER_PAYMENT_DATE) !!}
</div>
<div id="currencyType" style="display:none">
{!! Former::select('currency_type')->label(trans('texts.currency'))
->addOption(trans('texts.default'), 'default')
->addOption(trans('texts.converted'), 'converted') !!}
</div>
<div id="invoiceOrExpenseField" style="display:none">
{!! Former::select('document_filter')->label('filter')
->addOption(trans('texts.all'), '')
@ -283,6 +289,7 @@
$('#dateField').toggle(val == '{{ ENTITY_TAX_RATE }}');
$('#statusField').toggle(val == '{{ ENTITY_INVOICE }}' || val == '{{ ENTITY_PRODUCT }}');
$('#invoiceOrExpenseField').toggle(val == '{{ ENTITY_DOCUMENT }}');
$('#currencyType').toggle(val == '{{ ENTITY_PAYMENT }}');
}
function setDocumentZipShown() {