Skip to content

Commit

Permalink
#19 fix balance calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
mnvx committed Nov 29, 2018
1 parent b22daaa commit 778c153
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
7 changes: 5 additions & 2 deletions app/Model/Repository/ContributorRepositoryEloquent.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Model\Repository;

use App\Model\Entity\Contributor;
use App\Model\Entity\PaymentStatus;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB;
Expand All @@ -24,11 +25,13 @@ public function getListQuery(array $parameters): Builder
{
$query = $this->model
->select($this->model->getTable() . '.*')
->addSelect(DB::raw('(
->addSelect(DB::raw("(
COALESCE((
SELECT sum(payment.hours)
FROM payment
JOIN payment_status ON payment_status.id = payment.status_id
WHERE payment.contributor_id = contributor.id
AND payment_status.alias = '" . PaymentStatus::PAYED . "'
), 0)
-
COALESCE((
Expand All @@ -38,7 +41,7 @@ public function getListQuery(array $parameters): Builder
WHERE note.author_id = contributor.id
), 0)
) as balance
'))
"))
;

if ($id = Arr::get($parameters, 'id'))
Expand Down
4 changes: 2 additions & 2 deletions resources/views/home.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

@include('partial/count_widget', [
'color' => $myBalance >= 0 ? 'green' : 'red',
'icon' => 'ion ion-person',
'icon' => 'fa fa-hourglass' . ($myBalance == 0 ? '-half' : ($myBalance < 0 ? '-end' : '')),
'title' => __('messages.My balance'),
'hint' => __('messages.Payed hours minus spent hours'),
'count' => $myBalance,
Expand All @@ -73,7 +73,7 @@
@if (Auth::user()->hasPermissionTo(User::PERMISSION_SHOW_PAYMENTS))
@include('partial/count_widget', [
'color' => $companyBalance >= 0 ? 'green' : 'red',
'icon' => 'ion ion-person',
'icon' => 'fa fa-hourglass' . ($companyBalance == 0 ? '-half' : ($companyBalance < 0 ? '-end' : '')),
'title' => __('messages.Company balance'),
'hint' => __('messages.Payed hours minus spent hours'),
'count' => $companyBalance,
Expand Down

0 comments on commit 778c153

Please sign in to comment.