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, 'actionLinks' => $actionLinks,
'showBreadcrumbs' => false, 'showBreadcrumbs' => false,
'vendor' => $vendor, 'vendor' => $vendor,
'totalexpense' => $vendor->getTotalExpense(),
'title' => trans('texts.view_vendor'), 'title' => trans('texts.view_vendor'),
'hasRecurringInvoices' => false, 'hasRecurringInvoices' => false,
'hasQuotes' => false, 'hasQuotes' => false,

View File

@ -321,12 +321,14 @@ class Vendor extends EntityModel
/** /**
* @return float|int * @return float|int
*/ */
public function getTotalExpense() public function getTotalExpenses()
{ {
return DB::table('expenses') return DB::table('expenses')
->where('vendor_id', '=', $this->id) ->select('expense_currency_id', DB::raw('SUM(amount) as amount'))
->whereNull('deleted_at') ->whereVendorId($this->id)
->sum('amount'); ->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')) !!} {!! Button::normal(trans('texts.projects'))->asLinkTo(URL::to('/projects'))->appendIcon(Icon::create('list')) !!}
@endif @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')) !!} {!! Button::primary(mtrans($entityType, "new_{$entityType}"))->asLinkTo(url(Utils::pluralizeEntityType($entityType) . '/create/' . (isset($clientId) ? $clientId : '')))->appendIcon(Icon::create('plus-sign')) !!}
@endif @endif

View File

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