diff --git a/app/Filament/Widgets/InvoiceDataChart.php b/app/Filament/Widgets/InvoiceDataChart.php index e07d8c8..f41e0b7 100644 --- a/app/Filament/Widgets/InvoiceDataChart.php +++ b/app/Filament/Widgets/InvoiceDataChart.php @@ -176,6 +176,50 @@ class InvoiceDataChart extends ChartWidget ], ]; } + elseif ($selectedDistribution == 'WOS') + { + $totalInvoices = InvoiceDataValidation::where('plant_id', $selectedPlant) + ->where('distribution_channel_desc', $selectedDistribution) + ->whereBetween('document_date', [$startDate, $endDate]) + ->distinct('document_number') + ->pluck('document_number') + ->toArray(); + + if (empty($totalInvoices)) { + return [ + 'labels' => ['Total', 'Went Out', 'Pending'], + 'datasets' => [ + [ + 'label' => 'Invoice Count', + 'data' => [0, 0, 0], + 'backgroundColor' => ['#60A5FA', '#34D399', '#F87171'], + ], + ], + ]; + } + + $wentOutInvoices = InvoiceOutValidation::where('plant_id', $selectedPlant) + ->whereIn('qr_code', $totalInvoices) + ->whereBetween('scanned_at', [$startDate, $endDate]) + ->distinct('qr_code') + ->pluck('qr_code') + ->toArray(); + + $totalCount = count($totalInvoices); + $wentOutCount = count($wentOutInvoices); + $pendingCount = $totalCount - $wentOutCount; + + return [ + 'labels' => ['Total Invoices', 'Went Out', 'Pending'], + 'datasets' => [ + [ + 'label' => ucfirst(str_replace('_', ' ', $activeFilter)), + 'data' => [$totalCount, $wentOutCount, $pendingCount], + 'backgroundColor' => ['#60A5FA', '#34D399', '#F87171'], // blue, green, red + ], + ], + ]; + } elseif ($selectedDistribution == 'Challan') { $totalInvoices = InvoiceDataValidation::where('plant_id', $selectedPlant)