Skip to content

Commit

Permalink
feat: Summaries
Browse files Browse the repository at this point in the history
add summaries by category
change UI to mobile compat
  • Loading branch information
sylfel committed Mar 14, 2024
1 parent 6657906 commit f648c11
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
18 changes: 15 additions & 3 deletions app/Livewire/Dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,29 @@ public function render()
$query->where('notes.year', $this->year)
->where('notes.month', $this->month);
}], 'price')
->orderBy('label')
->with(['notes' => function (HasMany $query) {
$query->where('notes.year', $this->year)
->where('notes.month', $this->month)
->orderBy('created_at', 'desc');
}, 'notes.poste'])
->get();

$total = $categories->sum(function (Category $category) {
return $category->notes_sum_price * ($category->credit ? 1 : -1);
$summaries = collect(['Extra' => 0]);
$total = 0;

$categories->each(function (Category $category) use (&$summaries, &$total) {
$montant = $category->notes_sum_price * ($category->credit ? 1 : -1);
if ($category->extra) {
$summaries->put('Extra', $summaries->get('Extra', 0) + $montant);
} else {
$summaries->put($category->label, $montant);
}
$total = $total + $montant;
});

return view('livewire.dashboard', compact('categories', 'total'));
$summaries = $summaries->sortKeys();

return view('livewire.dashboard', compact('categories', 'total', 'summaries'));
}
}
2 changes: 1 addition & 1 deletion resources/views/components/section.blade.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<section class="rounded-lg border border-black bg-white">
<section {{ $attributes->merge(['class' => 'rounded-lg border border-black bg-white ']) }}>
@if (isset($header))
<header class="p-4 flex border-b-2 gap-4">
{{ $header }}
Expand Down
35 changes: 27 additions & 8 deletions resources/views/livewire/dashboard.blade.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
<div>
<header class="m-4 flex justify-center gap-4" wire:loading.class="opacity-50">
<header class="m-4 gap-4 grid justify-stretch sm:flex sm:justify-center flex-wrap" wire:loading.class="opacity-50">
<x-section>
<x-slot:header>
<h2 class="text-center grow">Filtres</h2>
<span class="sm:hidden text-center font-bold {{ $total >= 0 ? 'text-green-600' : 'text-red-600' }}">
{{ Number::currency(($total ?? 0) / 100, 'EUR', 'fr') }}
</span>
</x-slot:header>


<form class="max-w-sm mx-auto flex gap-4">
<div class="flex items-center min-w-48">
<form class="gap-4">
<div class="flex items-center ">
<select id="month" wire:model.live="month"
class="bg-gray-50 border border-r-0 border-gray-300 text-gray-900 text-sm rounded-lg rounded-r-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5">
class="min-w-28 bg-gray-50 border border-r-0 border-gray-300 text-gray-900 text-sm rounded-lg rounded-r-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5">
@foreach ($months as $monthname)
<option value='{{ $loop->index }}'>{{ Str::ucfirst($monthname) }}</option>
@endforeach
</select>
<select id="years" wire:model.live="year"
class="bg-gray-50 border border-l-0 border-gray-300 text-gray-900 text-sm rounded-lg rounded-l-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5">
class="min-w-20 bg-gray-50 border border-l-0 border-gray-300 text-gray-900 text-sm rounded-lg rounded-l-none focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5">
@foreach ($years as $year)
<option value='{{ $year }}'>{{ $year }}</option>
@endforeach
Expand All @@ -24,13 +27,29 @@ class="bg-gray-50 border border-l-0 border-gray-300 text-gray-900 text-sm rounde
</form>
</x-section>

<x-section>
<x-section class="hidden sm:block">
<x-slot:header>
<h2 class="text-center grow">Total</h2>
</x-slot:header>

<span class="font-bold {{ $total >= 0 ? 'text-green-600' : 'text-red-600' }}">
{{ Number::currency(($total ?? 0) / 100, 'EUR', 'fr') }}</span>
<div class="text-center font-bold {{ $total >= 0 ? 'text-green-600' : 'text-red-600' }}">
{{ Number::currency(($total ?? 0) / 100, 'EUR', 'fr') }}
</div>

</x-section>

<x-section>


@foreach ($summaries as $label => $montant)
<div class="flex justify-between">
<span class="grow">{{ $label }}</span>
<span class="ml-8 {{ $montant >= 0 ? 'text-green-600' : 'text-red-600' }}">
{{ Number::currency((abs($montant) ?? 0) / 100, 'EUR', 'fr') }}
</span>
</div>
@endforeach


</x-section>
</header>
Expand Down

0 comments on commit f648c11

Please sign in to comment.