issue solved in invoice chart setted data label
This commit is contained in:
@@ -7,7 +7,7 @@ use App\Models\Line;
|
|||||||
use App\Models\Plant;
|
use App\Models\Plant;
|
||||||
use DB;
|
use DB;
|
||||||
use Filament\Widgets\ChartWidget;
|
use Filament\Widgets\ChartWidget;
|
||||||
use Illuminate\Support\Js;
|
use Filament\Support\RawJs;
|
||||||
|
|
||||||
class InvoiceChart extends ChartWidget
|
class InvoiceChart extends ChartWidget
|
||||||
{
|
{
|
||||||
@@ -59,7 +59,7 @@ class InvoiceChart extends ChartWidget
|
|||||||
->distinct('invoice_number') // Only distinct invoice numbers
|
->distinct('invoice_number') // Only distinct invoice numbers
|
||||||
->count('invoice_number');
|
->count('invoice_number');
|
||||||
|
|
||||||
$completedInvoicesCount = InvoiceValidation::select('invoice_number')
|
$completedInvoicesCount = InvoiceValidation::select('invoice_number')
|
||||||
->where('plant_id', $selectedPlant)
|
->where('plant_id', $selectedPlant)
|
||||||
->where('quantity', 1)
|
->where('quantity', 1)
|
||||||
->whereBetween('updated_at', [$startDate, $endDate])
|
->whereBetween('updated_at', [$startDate, $endDate])
|
||||||
@@ -269,69 +269,8 @@ class InvoiceChart extends ChartWidget
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
// 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 {
|
|
||||||
$labels = ['Imported Invoice', 'Completed Invoice'];
|
$labels = ['Imported Invoice', 'Completed Invoice'];
|
||||||
$datasets = [[
|
$datasets = [[
|
||||||
'label' => 'Invoices',
|
'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 [
|
return [
|
||||||
'datasets' => $datasets,
|
'datasets' => $datasets,
|
||||||
'labels' => $labels,
|
'labels' => $labels,
|
||||||
@@ -357,39 +303,22 @@ class InvoiceChart extends ChartWidget
|
|||||||
return 'invoice-chart';
|
return 'invoice-chart';
|
||||||
}
|
}
|
||||||
|
|
||||||
// protected function getOptions(): array
|
|
||||||
// {
|
|
||||||
// return [
|
|
||||||
// 'scales' => [
|
|
||||||
// 'y' => [
|
|
||||||
// 'beginAtZero' => true, //Start Y-axis from 0
|
|
||||||
// 'ticks' => [
|
|
||||||
// 'stepSize' => 1,
|
|
||||||
// ],
|
|
||||||
// ],
|
|
||||||
// ],
|
|
||||||
// ];
|
|
||||||
// }
|
|
||||||
protected function getOptions(): array
|
protected function getOptions(): array
|
||||||
{
|
{
|
||||||
return [
|
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' => [
|
'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' => [
|
'scales' => [
|
||||||
'y' => [
|
'y' => [
|
||||||
|
|||||||
Reference in New Issue
Block a user