Include graph.js and build some dashboard tiles.

This commit is contained in:
2025-02-03 16:58:31 +01:00
parent ade1bfb863
commit 92e9511550
9 changed files with 242 additions and 56 deletions

View File

@@ -0,0 +1,41 @@
<?php
namespace App\View\Composers;
use App\Models\Incoming;
use App\Models\Invoice;
use Illuminate\Support\Carbon;
use Illuminate\View\View;
class YearGraph
{
public function compose(View $view): void
{
$yearly_invoices = Invoice::all()
->groupBy(function ($invoice) {
return $invoice->created_at->format('Y');
})
->map(function ($year) {
return $year->sum('sum');
});
$yearly_incoming = Incoming::all()
->groupBy(function ($incoming) {
return Carbon::parse($incoming->pay_date)->format('Y');
})
->map(function ($year) {
return $year->sum('net');
});
$diff_invoices = $yearly_invoices->diffKeys($yearly_incoming);
foreach ($diff_invoices as $year => $invoices) {
$yearly_incoming[$year] = 0;
}
$diff_incoming = $yearly_incoming->diffKeys($yearly_invoices);
foreach ($diff_incoming as $year => $invoices) {
$yearly_invoices[$year] = 0;
}
$view->with(['yearly_invoices' => $yearly_invoices, 'yearly_incoming' => $yearly_incoming]);
}
}