issue solved in invoice chart setted data label

This commit is contained in:
dhanabalan
2025-06-29 16:26:20 +05:30
parent 61973a424e
commit 5fd8b7e6bf

View File

@@ -7,7 +7,7 @@ use App\Models\Line;
use App\Models\Plant;
use DB;
use Filament\Widgets\ChartWidget;
use Illuminate\Support\Js;
use Filament\Support\RawJs;
class InvoiceChart extends ChartWidget
{
@@ -59,7 +59,7 @@ class InvoiceChart extends ChartWidget
->distinct('invoice_number') // Only distinct invoice numbers
->count('invoice_number');
$completedInvoicesCount = InvoiceValidation::select('invoice_number')
$completedInvoicesCount = InvoiceValidation::select('invoice_number')
->where('plant_id', $selectedPlant)
->where('quantity', 1)
->whereBetween('updated_at', [$startDate, $endDate])
@@ -269,69 +269,8 @@ class InvoiceChart extends ChartWidget
],
];
}
// elseif ($activeFilter == 'this_month')
// {
// $startOfMonth = now()->startOfMonth();
// $endOfMonth = now()->endOfMonth();
// $monthName = $startOfMonth->format('M');
// // Prepare weeks for the month
// $labels = [];
// $startDay = 1;
// $totalDays = $endOfMonth->day;
// while ($startDay <= $totalDays) {
// $endDay = min($startDay + 6, $totalDays);
// $labels[] = "{$monthName}({$startDay}-{$endDay})";
// $startDay += 7;
// }
// $importedInvoicesPerWeek = array_fill(0, count($labels), 0);
// $completedInvoicesPerWeek = array_fill(0, count($labels), 0);
// foreach ($labels as $index => $label) {
// $weekStart = now()->startOfMonth()->addDays(($index * 7))->setTime(8, 0, 0);
// $weekEnd = $weekStart->copy()->addDays(6)->setTime(8, 0, 0);
// $queryImported = DB::table('invoice_validations')->where('plant_id', $selectedPlant)->whereBetween('created_at', [$weekStart, $weekEnd]);
// $queryCompleted = DB::table('invoice_validations')->where('plant_id', $selectedPlant)->whereBetween('updated_at', [$weekStart, $weekEnd]);
// if ($selectedInvoice == 'individual_material') {
// $queryImported->where('quantity', 1);
// $queryCompleted->where('quantity', 1)
// ->whereNotNull('serial_number')
// ->where('serial_number','!=', '');
// } elseif ($selectedInvoice == 'serial_invoice') {
// $queryImported->whereNull('quantity');
// $queryCompleted->whereNull('quantity')
// ->where('scanned_status', 'Scanned');
// } elseif ($selectedInvoice == 'bundle_material') {
// $queryImported->where('quantity', '>', 1);
// $queryCompleted->where('quantity', '>', 1)
// ->whereNotNull('serial_number')
// ->where('serial_number','!=', '');
// }
// $importedInvoicesPerWeek[$index] = $queryImported->distinct('invoice_number')->count('invoice_number');
// $completedInvoicesPerWeek[$index] = $queryCompleted->distinct('invoice_number')->count('invoice_number');
// }
// $datasets = [
// [
// 'label' => 'Imported Invoices',
// 'data' => $importedInvoicesPerWeek,
// 'backgroundColor' => 'rgba(75, 192, 192, 1)',
// ],
// [
// 'label' => 'Completed Invoices',
// 'data' => $completedInvoicesPerWeek,
// 'backgroundColor' => 'rgba(23, 211, 80, 1)',
// ],
// ];
// }
else {
else
{
$labels = ['Imported Invoice', 'Completed Invoice'];
$datasets = [[
'label' => 'Invoices',
@@ -341,6 +280,13 @@ class InvoiceChart extends ChartWidget
]];
}
foreach ($datasets as &$dataset)
{
$dataset['data'] = array_map(function ($value) {
return ($value == 0 || is_null($value)) ? null : $value;
}, $dataset['data']);
}
return [
'datasets' => $datasets,
'labels' => $labels,
@@ -357,39 +303,22 @@ class InvoiceChart extends ChartWidget
return 'invoice-chart';
}
// protected function getOptions(): array
// {
// return [
// 'scales' => [
// 'y' => [
// 'beginAtZero' => true, //Start Y-axis from 0
// 'ticks' => [
// 'stepSize' => 1,
// ],
// ],
// ],
// ];
// }
protected function getOptions(): array
{
return [
// 'plugins' => [
// 'datalabels' => [
// // 'anchor' => 'start',
// // 'align' => 'start',
// // 'offset' => 1,
// 'anchor' => 'start',
// 'align' => 'start',
// 'offset' => 8,
// 'color' => '#000',
// 'font' => [
// 'weight' => 'bold',
// ],
// 'formatter' => Js::from("function(value) { return Number(value); }"),
// ],
// ],
'plugins' => [
'datalabels' => false, // Disable datalabels plugin properly
'datalabels' => [
'anchor' => 'start',
'align' => 'start',
'offset' => -15,
'color' => '#000',
'font' => [
'weight' => 'bold',
],
'formatter' => RawJs::make('function(value) {
return value;
}'),
],
],
'scales' => [
'y' => [