Added from date and to date in invoice chart dashboard #581

Merged
jothi merged 1 commits from ranjith-dev into master 2026-05-11 05:23:56 +00:00
2 changed files with 61 additions and 25 deletions
Showing only changes of commit 25cfaa6479 - Show all commits

View File

@@ -11,6 +11,7 @@ use Filament\Forms\Form;
use Filament\Pages\Page;
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
use Illuminate\Support\Facades\Auth;
use Filament\Forms\Components\DatePicker;
class InvoiceDashboard extends Page
{
@@ -27,9 +28,13 @@ class InvoiceDashboard extends Page
public function mount(): void
{
session()->forget(['selec_plant', 'select_invoice']);
session()->forget(['from_date']);
session()->forget(['to_date']);
$this->filtersForm->fill([
'plant' => null,
'invoice' => null,
'from_date' => null,
'to_date' => null,
]);
}
@@ -62,9 +67,23 @@ class InvoiceDashboard extends Page
->afterStateUpdated(function ($state) {
session(['select_invoice' => $state]);
$this->dispatch('invoiceChart');
})
}),
DatePicker::make('created_from')
->label('Created From')
->reactive()
->afterStateUpdated(function ($state,callable $set) {
session(['from_date' => $state]);
$this->dispatch('invoiceChart');
}),
DatePicker::make('created_to')
->label('Created To')
->reactive()
->afterStateUpdated(function ($state,callable $set) {
session(['to_date' => $state]);
$this->dispatch('invoiceChart');
}),
])
->columns(2);
->columns(4);
}
public static function getNavigationLabel(): string

View File

@@ -22,6 +22,10 @@ class InvoiceChart extends ChartWidget
{
$selectedPlant = session('selec_plant');
$selectedInvoice = session('select_invoice');
$fromDt = session('from_date');
$toDt = session('to_date');
$activeFilter = $this->filter; // Assuming filter is passed and activeFilter can be 'yesterday', 'this_week', 'this_month'
if (!$selectedPlant || !$selectedInvoice) {
@@ -31,23 +35,33 @@ class InvoiceChart extends ChartWidget
];
}
// Define the date range based on the active filter
if ($activeFilter == 'yesterday') {
$startDate = now()->subDay()->setTime(8, 0, 0);
$endDate = now()->setTime(8, 0, 0);
$groupBy = 'none'; // No grouping by hour
} elseif ($activeFilter == 'this_week') {
$startDate = now()->startOfWeek()->setTime(8, 0, 0);
$endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
$groupBy = 'day_of_week';
} elseif ($activeFilter == 'this_month') {
$startDate = now()->startOfMonth()->setTime(8, 0, 0);
$endDate = now()->endOfMonth()->setTime(8, 0, 0);
$groupBy = 'week_of_month';
} else {
$startDate = now()->setTime(8, 0, 0);
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
$groupBy = 'none'; // No grouping by hour
$isCustomDate = !empty($fromDt) && !empty($toDt);
if (!empty($fromDt) && !empty($toDt)) {
$startDate = \Carbon\Carbon::parse($fromDt)->setTime(8, 0, 0);
$endDate = \Carbon\Carbon::parse($toDt)->addDay()->setTime(8, 0, 0);
$groupBy = 'none';
}
else{
// Define the date range based on the active filter
if ($activeFilter == 'yesterday') {
$startDate = now()->subDay()->setTime(8, 0, 0);
$endDate = now()->setTime(8, 0, 0);
$groupBy = 'none'; // No grouping by hour
} elseif ($activeFilter == 'this_week') {
$startDate = now()->startOfWeek()->setTime(8, 0, 0);
$endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
$groupBy = 'day_of_week';
} elseif ($activeFilter == 'this_month') {
$startDate = now()->startOfMonth()->setTime(8, 0, 0);
$endDate = now()->endOfMonth()->setTime(8, 0, 0);
$groupBy = 'week_of_month';
} else {
$startDate = now()->setTime(8, 0, 0);
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
$groupBy = 'none'; // No grouping by hour
}
}
// Get the counts for Imported Invoices (unique invoice numbers) and Completed Invoices
@@ -111,7 +125,11 @@ class InvoiceChart extends ChartWidget
$labels = []; // Labels for each bar
$datasets = []; // Datasets for the chart
if (in_array($activeFilter, ['yesterday'])) {
if (!empty($fromDt) && !empty($toDt)) {
$activeFilter = null;
}
if ($isCustomDate || in_array($activeFilter, ['yesterday'])) {
$labels = ['Imported Invoice', 'Completed Invoice'];
$datasets = [[
'label' => 'Invoices',
@@ -120,8 +138,7 @@ class InvoiceChart extends ChartWidget
'fill' => false,
]];
}
elseif ($activeFilter == 'this_week')
elseif ($isCustomDate || $activeFilter == 'this_week')
{
$daysOfWeek = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
$importedInvoicesPerDay = array_fill(0, 7, 0);
@@ -191,7 +208,7 @@ class InvoiceChart extends ChartWidget
],
];
}
elseif ($activeFilter == 'this_month') {
elseif ($isCustomDate || $activeFilter == 'this_month') {
$startOfMonth = now()->startOfMonth()->setTime(8, 0, 0);
$endOfMonth = now()->endOfMonth()->addDay()->setTime(23, 59, 59); // include full last day
$monthName = $startOfMonth->format('M');
@@ -279,7 +296,7 @@ class InvoiceChart extends ChartWidget
],
];
}
else
elseif (!$isCustomDate)
{
$labels = ['Imported Invoice', 'Completed Invoice'];
$datasets = [[
@@ -354,7 +371,7 @@ class InvoiceChart extends ChartWidget
public static function canView(): bool
{
// dd('Checking route:', request()->route()->getName());
// dd('Checking route:', request()->route()->getName());
// to avoid showing the widget in other pages
return request()->routeIs('filament.admin.pages.invoice-dashboard');
}