Make dashboard configurable.

This commit is contained in:
2025-02-06 11:08:30 +01:00
parent a545e253d3
commit 4c43bf2193
19 changed files with 535 additions and 159 deletions

View File

@@ -2,6 +2,7 @@
namespace App\View\Composers;
use App\Models\Dashboard;
use App\Models\Incoming;
use App\Models\Invoice;
use Illuminate\Support\Carbon;
@@ -11,7 +12,10 @@ class MonthGraph
{
public function compose(View $view): void
{
$monthly_invoices = Invoice::whereYear('created_at', '=', Carbon::now()->year)->get()
$config = Dashboard::where('id', '=', 6)->first();
$config_year = (is_null($config->settings)) ? Carbon::now()->year : intval($config->settings);
$monthly_invoices = Invoice::whereYear('created_at', '=', $config_year)->get()
->groupBy(function ($invoice) {
return $invoice->created_at->format('n');
})
@@ -19,7 +23,7 @@ class MonthGraph
return $month->sum('sum');
});
$monthly_incoming = Incoming::whereYear('issue_date', '=', Carbon::now()->year)->get()
$monthly_incoming = Incoming::whereYear('issue_date', '=', $config_year)->get()
->groupBy(function ($incoming) {
return Carbon::parse($incoming->issue_date)->format('n');
})
@@ -36,6 +40,6 @@ class MonthGraph
$monthly_invoices[$year] = 0;
}
$view->with(['monthly_invoices' => $monthly_invoices, 'monthly_incoming' => $monthly_incoming]);
$view->with(['monthly_invoices' => $monthly_invoices, 'monthly_incoming' => $monthly_incoming, 'year' => $config_year]);
}
}