From 778c1535d59bdac70d3efc3facbe765332fb4625 Mon Sep 17 00:00:00 2001 From: mnv Date: Thu, 29 Nov 2018 11:16:06 +0300 Subject: [PATCH] #19 fix balance calculation --- app/Model/Repository/ContributorRepositoryEloquent.php | 7 +++++-- resources/views/home.blade.php | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Model/Repository/ContributorRepositoryEloquent.php b/app/Model/Repository/ContributorRepositoryEloquent.php index 1667484..a084807 100644 --- a/app/Model/Repository/ContributorRepositoryEloquent.php +++ b/app/Model/Repository/ContributorRepositoryEloquent.php @@ -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; @@ -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(( @@ -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')) diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index e4b5cc9..297d285 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -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, @@ -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,