fix(dashboard): hitung penjualan hanya dari transaksi yang sudah dikonfirmasi, bukan pending atau rejected
This commit is contained in:
parent
e4918c4b7c
commit
27ed24dba6
|
|
@ -14,22 +14,23 @@ class DashboardController extends Controller
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
$activeStatuses = ['pending', 'confirmed'];
|
$activeStatuses = ['pending', 'confirmed'];
|
||||||
|
$confirmedStatus = ['confirmed'];
|
||||||
|
|
||||||
$totalTicketsSold = TicketOrderItem::whereHas('order', function (Builder $query) use ($activeStatuses) {
|
$totalTicketsSold = TicketOrderItem::whereHas('order', function (Builder $query) use ($confirmedStatus) {
|
||||||
$query->whereIn('status', $activeStatuses);
|
$query->whereIn('status', $confirmedStatus);
|
||||||
})->count();
|
})->count();
|
||||||
|
|
||||||
$monthlyTicketSales = TicketOrder::whereIn('status', $activeStatuses)
|
$monthlyTicketSales = TicketOrder::whereIn('status', $confirmedStatus)
|
||||||
->whereYear('created_at', now()->year)
|
->whereYear('created_at', now()->year)
|
||||||
->whereMonth('created_at', now()->month)
|
->whereMonth('created_at', now()->month)
|
||||||
->sum('total_price');
|
->sum('total_price');
|
||||||
|
|
||||||
$monthlyBookings = Booking::whereIn('status', $activeStatuses)
|
$monthlyBookings = Booking::whereIn('status', $confirmedStatus)
|
||||||
->whereYear('created_at', now()->year)
|
->whereYear('created_at', now()->year)
|
||||||
->whereMonth('created_at', now()->month)
|
->whereMonth('created_at', now()->month)
|
||||||
->count();
|
->count();
|
||||||
|
|
||||||
$monthlyRevenue = $monthlyTicketSales + Booking::whereIn('status', $activeStatuses)
|
$monthlyRevenue = $monthlyTicketSales + Booking::whereIn('status', $confirmedStatus)
|
||||||
->whereYear('created_at', now()->year)
|
->whereYear('created_at', now()->year)
|
||||||
->whereMonth('created_at', now()->month)
|
->whereMonth('created_at', now()->month)
|
||||||
->sum('total_price');
|
->sum('total_price');
|
||||||
|
|
@ -42,15 +43,15 @@ public function index()
|
||||||
$date = Carbon::now()->subMonths($i);
|
$date = Carbon::now()->subMonths($i);
|
||||||
$months[] = $date->translatedFormat('M Y');
|
$months[] = $date->translatedFormat('M Y');
|
||||||
|
|
||||||
$ticketData[] = TicketOrderItem::whereHas('order', function (Builder $query) use ($date, $activeStatuses) {
|
$ticketData[] = TicketOrderItem::whereHas('order', function (Builder $query) use ($date, $confirmedStatus) {
|
||||||
$query->whereYear('visit_date', $date->year)
|
$query->whereYear('visit_date', $date->year)
|
||||||
->whereMonth('visit_date', $date->month)
|
->whereMonth('visit_date', $date->month)
|
||||||
->whereIn('status', $activeStatuses);
|
->whereIn('status', $confirmedStatus);
|
||||||
})->count();
|
})->count();
|
||||||
|
|
||||||
$bookingData[] = Booking::whereYear('booking_date', $date->year)
|
$bookingData[] = Booking::whereYear('booking_date', $date->year)
|
||||||
->whereMonth('booking_date', $date->month)
|
->whereMonth('booking_date', $date->month)
|
||||||
->whereIn('status', $activeStatuses)
|
->whereIn('status', $confirmedStatus)
|
||||||
->count();
|
->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -74,5 +75,6 @@ public function index()
|
||||||
'hasTransactionData'
|
'hasTransactionData'
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue