Added from date and to date in invoice chart dashboard
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Gemini PR Review / Gemini PR Review (pull_request) Has been cancelled
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Has been cancelled
Laravel Larastan / larastan (pull_request) Has been cancelled
Laravel Pint / pint (pull_request) Has been cancelled
Some checks failed
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (push) Has been cancelled
Gemini PR Review / Gemini PR Review (pull_request) Has been cancelled
Scan for leaked secrets using Kingfisher / kingfisher-secrets-scan (pull_request) Has been cancelled
Laravel Larastan / larastan (pull_request) Has been cancelled
Laravel Pint / pint (pull_request) Has been cancelled
This commit is contained in:
@@ -11,6 +11,7 @@ use Filament\Forms\Form;
|
|||||||
use Filament\Pages\Page;
|
use Filament\Pages\Page;
|
||||||
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
|
use Filament\Pages\Dashboard\Concerns\HasFiltersForm;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
use Filament\Forms\Components\DatePicker;
|
||||||
|
|
||||||
class InvoiceDashboard extends Page
|
class InvoiceDashboard extends Page
|
||||||
{
|
{
|
||||||
@@ -27,9 +28,13 @@ class InvoiceDashboard extends Page
|
|||||||
public function mount(): void
|
public function mount(): void
|
||||||
{
|
{
|
||||||
session()->forget(['selec_plant', 'select_invoice']);
|
session()->forget(['selec_plant', 'select_invoice']);
|
||||||
|
session()->forget(['from_date']);
|
||||||
|
session()->forget(['to_date']);
|
||||||
$this->filtersForm->fill([
|
$this->filtersForm->fill([
|
||||||
'plant' => null,
|
'plant' => null,
|
||||||
'invoice' => null,
|
'invoice' => null,
|
||||||
|
'from_date' => null,
|
||||||
|
'to_date' => null,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,9 +67,23 @@ class InvoiceDashboard extends Page
|
|||||||
->afterStateUpdated(function ($state) {
|
->afterStateUpdated(function ($state) {
|
||||||
session(['select_invoice' => $state]);
|
session(['select_invoice' => $state]);
|
||||||
$this->dispatch('invoiceChart');
|
$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
|
public static function getNavigationLabel(): string
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ class InvoiceChart extends ChartWidget
|
|||||||
{
|
{
|
||||||
$selectedPlant = session('selec_plant');
|
$selectedPlant = session('selec_plant');
|
||||||
$selectedInvoice = session('select_invoice');
|
$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'
|
$activeFilter = $this->filter; // Assuming filter is passed and activeFilter can be 'yesterday', 'this_week', 'this_month'
|
||||||
|
|
||||||
if (!$selectedPlant || !$selectedInvoice) {
|
if (!$selectedPlant || !$selectedInvoice) {
|
||||||
@@ -31,23 +35,33 @@ class InvoiceChart extends ChartWidget
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define the date range based on the active filter
|
$isCustomDate = !empty($fromDt) && !empty($toDt);
|
||||||
if ($activeFilter == 'yesterday') {
|
|
||||||
$startDate = now()->subDay()->setTime(8, 0, 0);
|
if (!empty($fromDt) && !empty($toDt)) {
|
||||||
$endDate = now()->setTime(8, 0, 0);
|
$startDate = \Carbon\Carbon::parse($fromDt)->setTime(8, 0, 0);
|
||||||
$groupBy = 'none'; // No grouping by hour
|
$endDate = \Carbon\Carbon::parse($toDt)->addDay()->setTime(8, 0, 0);
|
||||||
} elseif ($activeFilter == 'this_week') {
|
$groupBy = 'none';
|
||||||
$startDate = now()->startOfWeek()->setTime(8, 0, 0);
|
}
|
||||||
$endDate = now()->endOfWeek()->addDay()->setTime(8, 0, 0);
|
else{
|
||||||
$groupBy = 'day_of_week';
|
|
||||||
} elseif ($activeFilter == 'this_month') {
|
// Define the date range based on the active filter
|
||||||
$startDate = now()->startOfMonth()->setTime(8, 0, 0);
|
if ($activeFilter == 'yesterday') {
|
||||||
$endDate = now()->endOfMonth()->setTime(8, 0, 0);
|
$startDate = now()->subDay()->setTime(8, 0, 0);
|
||||||
$groupBy = 'week_of_month';
|
$endDate = now()->setTime(8, 0, 0);
|
||||||
} else {
|
$groupBy = 'none'; // No grouping by hour
|
||||||
$startDate = now()->setTime(8, 0, 0);
|
} elseif ($activeFilter == 'this_week') {
|
||||||
$endDate = now()->copy()->addDay()->setTime(8, 0, 0);
|
$startDate = now()->startOfWeek()->setTime(8, 0, 0);
|
||||||
$groupBy = 'none'; // No grouping by hour
|
$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
|
// 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
|
$labels = []; // Labels for each bar
|
||||||
$datasets = []; // Datasets for the chart
|
$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'];
|
$labels = ['Imported Invoice', 'Completed Invoice'];
|
||||||
$datasets = [[
|
$datasets = [[
|
||||||
'label' => 'Invoices',
|
'label' => 'Invoices',
|
||||||
@@ -120,8 +138,7 @@ class InvoiceChart extends ChartWidget
|
|||||||
'fill' => false,
|
'fill' => false,
|
||||||
]];
|
]];
|
||||||
}
|
}
|
||||||
|
elseif ($isCustomDate || $activeFilter == 'this_week')
|
||||||
elseif ($activeFilter == 'this_week')
|
|
||||||
{
|
{
|
||||||
$daysOfWeek = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
$daysOfWeek = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
|
||||||
$importedInvoicesPerDay = array_fill(0, 7, 0);
|
$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);
|
$startOfMonth = now()->startOfMonth()->setTime(8, 0, 0);
|
||||||
$endOfMonth = now()->endOfMonth()->addDay()->setTime(23, 59, 59); // include full last day
|
$endOfMonth = now()->endOfMonth()->addDay()->setTime(23, 59, 59); // include full last day
|
||||||
$monthName = $startOfMonth->format('M');
|
$monthName = $startOfMonth->format('M');
|
||||||
@@ -279,7 +296,7 @@ class InvoiceChart extends ChartWidget
|
|||||||
],
|
],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
else
|
elseif (!$isCustomDate)
|
||||||
{
|
{
|
||||||
$labels = ['Imported Invoice', 'Completed Invoice'];
|
$labels = ['Imported Invoice', 'Completed Invoice'];
|
||||||
$datasets = [[
|
$datasets = [[
|
||||||
@@ -354,7 +371,7 @@ class InvoiceChart extends ChartWidget
|
|||||||
|
|
||||||
public static function canView(): bool
|
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
|
// to avoid showing the widget in other pages
|
||||||
return request()->routeIs('filament.admin.pages.invoice-dashboard');
|
return request()->routeIs('filament.admin.pages.invoice-dashboard');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user