Skip to content

Commit 8437b0a

Browse files
author
Itamar Junior
committed
feat: add budget forecast page with company contract summary view
1 parent a6e7dae commit 8437b0a

File tree

4 files changed

+103
-0
lines changed

4 files changed

+103
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
namespace App\Livewire\Company;
4+
5+
use App\Models\Company;
6+
use Livewire\Component;
7+
use Illuminate\Support\Facades\Auth;
8+
use App\Models\CompanyServiceContract;
9+
10+
class BudgetForecast extends Component
11+
{
12+
public $companies;
13+
public $selectedCompanyId;
14+
public $contracts = [];
15+
16+
public function mount()
17+
{
18+
$this->companies = Company::where('business_id', Auth::user()->current_business_id)
19+
->orderBy('name')
20+
->get();
21+
22+
$this->selectedCompanyId = null;
23+
}
24+
25+
public function updatedSelectedCompanyId($value)
26+
{
27+
$this->loadContracts();
28+
}
29+
30+
public function loadContracts()
31+
{
32+
if ($this->selectedCompanyId) {
33+
$this->contracts = CompanyServiceContract::with(['category', 'provider'])
34+
->where('company_id', $this->selectedCompanyId)
35+
->get();
36+
} else {
37+
$this->contracts = [];
38+
}
39+
}
40+
public function render()
41+
{
42+
return view('livewire.company.budget-forecast');
43+
}
44+
}

resources/views/components/layouts/app/sidebar.blade.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
</flux:navlist.group>
1818
@if(auth()->user()?->hasCompaniesInCurrentBusiness())
1919
<flux:navlist.item icon="briefcase" :href="route('company.index')" :current="request()->routeIs('company.index')" wire:navigate>{{ __('Companies') }}</flux:navlist.item>
20+
<flux:navlist.item icon="table-cells" :href="route('company.budget.forecast')" :current="request()->routeIs('company.budget.forecast')" wire:navigate>
21+
{{ __('Budget Forecast') }}
22+
</flux:navlist.item>
2023
@endif
2124
</flux:navlist>
2225

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<div class="h-full flex flex-col bg-white dark:bg-gray-800 relative overflow-hidden">
2+
<div class="flex flex-col md:flex-row items-center justify-between space-y-3 md:space-y-0 md:space-x-4 p-4">
3+
<div class="w-full md:w-1/2">
4+
<label for="company" class="block text-sm font-medium text-gray-700 dark:text-gray-300">Select
5+
Company</label>
6+
<select wire:model.live="selectedCompanyId" id="company"
7+
class="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-indigo-500 focus:ring focus:ring-indigo-200 focus:ring-opacity-50 sm:text-sm dark:bg-gray-700 dark:border-gray-600 dark:text-white">
8+
<option value="">-- Choose a company --</option>
9+
@foreach ($companies as $company)
10+
<option value="{{ $company->id }}">{{ $company->name }}</option>
11+
@endforeach
12+
</select>
13+
</div>
14+
</div>
15+
16+
<table class="w-full h-fit text-sm text-left text-gray-500 dark:text-gray-400 mt-4" wire:loading.class="opacity-50">
17+
<thead class="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
18+
<tr>
19+
<th class="px-4 py-3">Service</th>
20+
<th class="px-4 py-3">Provider</th>
21+
<th class="px-4 py-3">Budget (€)</th>
22+
<th class="px-4 py-3">Next Due</th>
23+
<th class="px-4 py-3">Status</th>
24+
</tr>
25+
</thead>
26+
<tbody>
27+
@forelse ($contracts as $contract)
28+
<tr class="border-b dark:border-gray-700">
29+
<td class="px-4 py-2">{{ $contract->category->name }}</td>
30+
<td class="px-4 py-2">{{ $contract->provider->name }}</td>
31+
<td class="px-4 py-2 font-medium text-green-600">€{{ number_format($contract->budget, 2) }}</td>
32+
<td class="px-4 py-2">{{ $contract->next_due_date ?? '' }}</td>
33+
<td class="px-4 py-2 capitalize">{{ $contract->status }}</td>
34+
</tr>
35+
@empty
36+
<tr>
37+
<td colspan="5" class="px-4 py-4 text-center text-sm text-gray-500 dark:text-gray-300">
38+
No contracts available.
39+
</td>
40+
</tr>
41+
@endforelse
42+
</tbody>
43+
<tfoot>
44+
<tr class="border-t dark:border-gray-700">
45+
<td colspan="2" class="px-4 py-2 text-right font-semibold text-gray-700 dark:text-gray-300">Total
46+
</td>
47+
<td class="px-4 py-2 font-bold text-green-700 dark:text-green-400">
48+
{{ number_format(collect($contracts)->sum('budget'), 2) }}
49+
</td>
50+
<td colspan="2"></td>
51+
</tr>
52+
</tfoot>
53+
</table>
54+
</div>

routes/company.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@
1717
Route::get('/company/service/category/manager/', \App\Livewire\Company\Service\CategoryManager::class)->name('company.service.category.manager');
1818
Route::get('/company/service/provider/manager/', \App\Livewire\Company\Service\Provider\ProviderManager::class)->name('company.service.provider.manager');
1919
Route::get('/company/service/contract/manager/', \App\Livewire\Company\Service\ContractManager::class)->name('company.service.contract.manager');
20+
21+
Route::get('/company/budget/forecast', \App\Livewire\Company\BudgetForecast::class)->name('company.budget.forecast');
2022
});

0 commit comments

Comments
 (0)