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) {
$query->where('id', '<>', DB::raw('transactions.id'));
})
->when(auth()->user()->role_id === 5, function ($query) {
return $query->where('user_id', auth()->id());
})
->barbershop()
->today()
->distinct('customer_id')
@ -62,6 +65,9 @@ public function index()
$yesterdayNewCustomer = Transaction::with('customer')->whereDoesntHave('customer.transactions', function ($query) {
$query->where('id', '<>', DB::raw('transactions.id'));
})
->when(auth()->user()->role_id === 5, function ($query) {
return $query->where('user_id', auth()->id());
})
->barbershop()
->yesterday()
->distinct('customer_id')
@ -84,8 +90,12 @@ public function index()
->barbershop()
->barber()
->withSum('transactions', 'total')
->withCount('transactions')
->get();
->withCount('transactions');
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', [
'pageTitle' => 'Ringkasan',

View File

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