fix(overview): untuk barber itu datanya hanya milik dia

This commit is contained in:
Yoga Pangestu 2024-12-15 19:49:31 +07:00
parent e5a70da344
commit 86df663400
2 changed files with 65 additions and 26 deletions

View File

@ -54,6 +54,9 @@ public function index()
$todayNewCustomer = Transaction::with('customer')->whereDoesntHave('customer.transactions', function ($query) { $todayNewCustomer = Transaction::with('customer')->whereDoesntHave('customer.transactions', function ($query) {
$query->where('id', '<>', DB::raw('transactions.id')); $query->where('id', '<>', DB::raw('transactions.id'));
}) })
->when(auth()->user()->role_id === 5, function ($query) {
return $query->where('user_id', auth()->id());
})
->barbershop() ->barbershop()
->today() ->today()
->distinct('customer_id') ->distinct('customer_id')
@ -62,6 +65,9 @@ public function index()
$yesterdayNewCustomer = Transaction::with('customer')->whereDoesntHave('customer.transactions', function ($query) { $yesterdayNewCustomer = Transaction::with('customer')->whereDoesntHave('customer.transactions', function ($query) {
$query->where('id', '<>', DB::raw('transactions.id')); $query->where('id', '<>', DB::raw('transactions.id'));
}) })
->when(auth()->user()->role_id === 5, function ($query) {
return $query->where('user_id', auth()->id());
})
->barbershop() ->barbershop()
->yesterday() ->yesterday()
->distinct('customer_id') ->distinct('customer_id')
@ -84,8 +90,12 @@ public function index()
->barbershop() ->barbershop()
->barber() ->barber()
->withSum('transactions', 'total') ->withSum('transactions', 'total')
->withCount('transactions') ->withCount('transactions');
->get(); if (in_array(auth()->user()->role_id, [1, 2, 3])) {
$incomeByBarber = $incomeByBarber->get();
} elseif (auth()->user()->role_id === 5) {
$incomeByBarber = $incomeByBarber->find(auth()->id());
}
return view('pages.admin.dashboard.overview', [ return view('pages.admin.dashboard.overview', [
'pageTitle' => 'Ringkasan', 'pageTitle' => 'Ringkasan',

View File

@ -144,35 +144,64 @@
</div> </div>
</div> </div>
</div> </div>
<div class="card"> @if (in_array(auth()->user()->role_id, [1, 2, 3]))
<div class="card-header card-no-border"> <div class="card">
<div class="header-top"> <div class="card-header card-no-border">
<h5 class="m-0">Pendapatan Barber</h5> <div class="header-top">
<h5 class="m-0">Pendapatan Barber</h5>
</div>
</div> </div>
</div> <div class="card-body pt-0">
<div class="card-body pt-0"> <div class="table-responsive custom-scrollbar">
<div class="table-responsive custom-scrollbar"> <table class="table table-dashed">
<table class="table table-dashed"> <thead>
<thead>
<tr>
<th>Nama</th>
<th>Jumlah Transaksi</th>
<th>Total Transakski</th>
</tr>
</thead>
<tbody>
@foreach ($incomeByBarber as $item)
<tr> <tr>
<td>{{ $item->biography->full_name ?? '--deleted--' }}</td> <th>Nama</th>
<td>{{ $item->transactions_count }}</td> <th>Jumlah Transaksi</th>
<td>{{ formatToRupiah($item->transactions_sum_total) }}</td> <th>Total Transakski</th>
</tr> </tr>
@endforeach </thead>
</tbody> <tbody>
</table> @foreach ($incomeByBarber as $item)
<tr>
<td>{{ $item->biography->full_name ?? '--deleted--' }}</td>
<td>{{ $item->transactions_count }}</td>
<td>{{ formatToRupiah($item->transactions_sum_total) }}</td>
</tr>
@endforeach
</tbody>
</table>
</div>
</div> </div>
</div> </div>
</div> @elseif(auth()->user()->role_id == 5)
<div class="card">
<div class="card-header card-no-border">
<div class="header-top">
<h5 class="m-0">Pendapatan Barber</h5>
</div>
</div>
<div class="card-body pt-0">
<div class="table-responsive custom-scrollbar">
<table class="table table-dashed">
<thead>
<tr>
<th>Jumlah Transaksi</th>
<th>Total Transakski</th>
</tr>
</thead>
<tbody>
<tr>
<td>{{ $incomeByBarber->transactions_count }}</td>
<td>{{ formatToRupiah($incomeByBarber->transactions_sum_total) }}
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
@endif
</div> </div>
</div> </div>
</div> </div>