filters['startDate'] ?? Carbon::now()->startOfYear(); $endDate = $this->filters['endDate'] ?? Carbon::now()->endOfYear(); $startDate = Carbon::parse($startDate)->startOfDay(); $endDate = Carbon::parse($endDate)->endOfDay(); $data = CooperationPayment::query() ->select( DB::raw("DATE_FORMAT(payment_date, '%Y-%m') as month"), DB::raw('SUM(amount) as total') ) ->whereBetween('payment_date', [$startDate, $endDate]) ->groupBy('month') ->orderBy('month') ->get(); $labels = []; $values = []; $current = clone $startDate; while ($current <= $endDate) { $monthStr = $current->format('Y-m'); $labels[] = $current->translatedFormat('M Y'); $monthData = $data->where('month', $monthStr)->first(); $values[] = $monthData ? (int) $monthData->total : 0; $current->addMonth(); } return [ 'datasets' => [ [ 'label' => 'Total Pembayaran (Rp)', 'data' => $values, 'fill' => 'start', 'backgroundColor' => 'rgba(59, 130, 246, 0.1)', 'borderColor' => '#3B82F6', 'tension' => 0.3, ], ], 'labels' => $labels, ]; } protected function getType(): string { return 'line'; } }