Fix total balance for vendor with multiple expense currencies

This commit is contained in:
Hillel Coren 2016-12-20 17:48:58 +02:00
parent cd97904b75
commit 6e8f87a198
4 changed files with 13 additions and 8 deletions

View File

@ -82,7 +82,6 @@ class VendorController extends BaseController
'actionLinks' => $actionLinks,
'showBreadcrumbs' => false,
'vendor' => $vendor,
'totalexpense' => $vendor->getTotalExpense(),
'title' => trans('texts.view_vendor'),
'hasRecurringInvoices' => false,
'hasQuotes' => false,

View File

@ -321,12 +321,14 @@ class Vendor extends EntityModel
/**
* @return float|int
*/
public function getTotalExpense()
public function getTotalExpenses()
{
return DB::table('expenses')
->where('vendor_id', '=', $this->id)
->whereNull('deleted_at')
->sum('amount');
->select('expense_currency_id', DB::raw('SUM(amount) as amount'))
->whereVendorId($this->id)
->whereIsDeleted(false)
->groupBy('expense_currency_id')
->get();
}
}

View File

@ -55,7 +55,7 @@
{!! Button::normal(trans('texts.projects'))->asLinkTo(URL::to('/projects'))->appendIcon(Icon::create('list')) !!}
@endif
@if (Auth::user()->can('create', $entityType))
@if (Auth::user()->can('create', $entityType) && empty($vendorId))
{!! Button::primary(mtrans($entityType, "new_{$entityType}"))->asLinkTo(url(Utils::pluralizeEntityType($entityType) . '/create/' . (isset($clientId) ? $clientId : '')))->appendIcon(Icon::create('plus-sign')) !!}
@endif

View File

@ -153,8 +153,12 @@
<h3>{{ trans('texts.standing') }}
<table class="table" style="width:100%">
<tr>
<td><small>{{ trans('texts.balance') }}</small></td>
<td style="text-align: right">{{ Utils::formatMoney($totalexpense, $vendor->getCurrencyId()) }}</td>
<td style="vertical-align: top"><small>{{ trans('texts.balance') }}</small></td>
<td style="text-align: right">
@foreach ($vendor->getTotalExpenses() as $currency)
<p>{{ Utils::formatMoney($currency->amount, $currency->expense_currency_id) }}</p>
@endforeach
</td>
</tr>
</table>
</h3>