From 575fb27018f0212b3a6cf2569e02d4c41a8559d7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thomas=20G=C3=BCnther?=
Date: Tue, 26 May 2026 11:07:59 +0200
Subject: [PATCH] Displaying estimates
---
.../Budget/Controllers/ListController.php | 24 +++
.../Budget/Controllers/MainController.php | 19 ++
app/Domains/Budget/Routes/api.php | 17 ++
app/Domains/Budget/Routes/web.php | 20 ++
app/Domains/Budget/Views/List.vue | 93 +++++++++
app/Domains/Budget/Views/ListBudgetTypes.vue | 195 ++++++++++++++++++
app/Models/CostUnitEstimate.php | 55 +++++
app/Repositories/EstimatesRepository.php | 16 ++
app/Resources/CostUnitEstimateResource.php | 35 ++++
...5_25_140010_create_cost_unit_estimates.php | 32 +++
10 files changed, 506 insertions(+)
create mode 100644 app/Domains/Budget/Controllers/ListController.php
create mode 100644 app/Domains/Budget/Controllers/MainController.php
create mode 100644 app/Domains/Budget/Routes/api.php
create mode 100644 app/Domains/Budget/Routes/web.php
create mode 100644 app/Domains/Budget/Views/List.vue
create mode 100644 app/Domains/Budget/Views/ListBudgetTypes.vue
create mode 100644 app/Models/CostUnitEstimate.php
create mode 100644 app/Repositories/EstimatesRepository.php
create mode 100644 app/Resources/CostUnitEstimateResource.php
create mode 100644 database/migrations/2026_05_25_140010_create_cost_unit_estimates.php
diff --git a/app/Domains/Budget/Controllers/ListController.php b/app/Domains/Budget/Controllers/ListController.php
new file mode 100644
index 0000000..7d0741e
--- /dev/null
+++ b/app/Domains/Budget/Controllers/ListController.php
@@ -0,0 +1,24 @@
+costUnits->getById($costUnitId);
+ $estimates = $this->estimates->getEstimates($costUnit, $estimateType);
+
+ return response()->json([
+ 'status' => 'success',
+ 'costUnitId' => $costUnitId,
+ 'title' => InvoiceType::where('slug', $estimateType)->first()->name,
+ 'estimates' => $estimates,
+ ]);
+ }
+
+}
diff --git a/app/Domains/Budget/Controllers/MainController.php b/app/Domains/Budget/Controllers/MainController.php
new file mode 100644
index 0000000..0fb6ff9
--- /dev/null
+++ b/app/Domains/Budget/Controllers/MainController.php
@@ -0,0 +1,19 @@
+ $costUnitId
+ ]);
+ return $inertiaProvider->render();
+ }
+}
diff --git a/app/Domains/Budget/Routes/api.php b/app/Domains/Budget/Routes/api.php
new file mode 100644
index 0000000..2a7d345
--- /dev/null
+++ b/app/Domains/Budget/Routes/api.php
@@ -0,0 +1,17 @@
+group(function () {
+ Route::middleware(IdentifyTenant::class)->group(function () {
+ Route::prefix('budget')->group(function () {
+ Route::middleware(['auth'])->group(function () {
+ Route::prefix('/{costUnitId}')->group(function () {
+ Route::get('/list/{estimateType}', ListController::class);
+ });
+ });
+ });
+ });
+});
diff --git a/app/Domains/Budget/Routes/web.php b/app/Domains/Budget/Routes/web.php
new file mode 100644
index 0000000..e96b0ef
--- /dev/null
+++ b/app/Domains/Budget/Routes/web.php
@@ -0,0 +1,20 @@
+group(function () {
+ Route::prefix('budget')->group(function () {
+ Route::middleware(['auth'])->group(function () {
+ Route::prefix('/{costUnitId}')->group(function() {
+ Route::get('/', MainController::class);
+ });
+ });
+ });
+});
+
+
+
+
+
diff --git a/app/Domains/Budget/Views/List.vue b/app/Domains/Budget/Views/List.vue
new file mode 100644
index 0000000..facf885
--- /dev/null
+++ b/app/Domains/Budget/Views/List.vue
@@ -0,0 +1,93 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/app/Domains/Budget/Views/ListBudgetTypes.vue b/app/Domains/Budget/Views/ListBudgetTypes.vue
new file mode 100644
index 0000000..bf58ca6
--- /dev/null
+++ b/app/Domains/Budget/Views/ListBudgetTypes.vue
@@ -0,0 +1,195 @@
+
+
+
+
+
{{ props.data.title }}
+
+
+
+ |
+ {{ estimate.title }}
+ |
+ {{ estimate.totalAmountString }} |
+
+
+ |
+
+ Bearbeiten
+ Löschen
+ |
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Noch keine geschätzten Ausgaben vorhanden
+
+
+
+
+
+
+
diff --git a/app/Models/CostUnitEstimate.php b/app/Models/CostUnitEstimate.php
new file mode 100644
index 0000000..ac55c5d
--- /dev/null
+++ b/app/Models/CostUnitEstimate.php
@@ -0,0 +1,55 @@
+ AmountCast::class,
+ 'amount_by_user' => AmountCast::class,
+ ];
+
+ public function costUnit() : BelongsTo{
+ return $this->belongsTo(CostUnit::class);
+ }
+
+ public function invoiceType() : InvoiceType {
+ return $this->belongsTo(InvoiceType::class, 'type', 'slug')->first();
+ }
+
+ public function calculateAmount() : ?Amount {
+ switch (true) {
+ case $this->flat_amount !== null:
+ return $this->flat_amount;
+ default:
+ $event = $this->costUnit()->first()->event()?->first();
+ if (null !== $event) {
+
+ $participants = $event->participants()->count();
+ return $this->amount_by_user->multiply($participants);
+
+ } else {
+ dd('U');
+ return $this->amount_by_user;
+ }
+ }
+ }
+}
diff --git a/app/Repositories/EstimatesRepository.php b/app/Repositories/EstimatesRepository.php
new file mode 100644
index 0000000..253618d
--- /dev/null
+++ b/app/Repositories/EstimatesRepository.php
@@ -0,0 +1,16 @@
+estimates()->where('type', $estimateType)->get() as $estimate) {
+ $return[] = $estimate->toResource()->toArray(request());
+ }
+
+ return $return;
+ }
+}
diff --git a/app/Resources/CostUnitEstimateResource.php b/app/Resources/CostUnitEstimateResource.php
new file mode 100644
index 0000000..c8f7221
--- /dev/null
+++ b/app/Resources/CostUnitEstimateResource.php
@@ -0,0 +1,35 @@
+resource->flat_amount?->toString();
+ if ($amountString === null) {
+ $amountString = $this->resource->amount_by_user?->toString() . ' / Person';
+ } else {
+ $amountString .= ' Gesamt';
+ }
+
+ return [
+ 'id' => $this->resource->id,
+ 'title' => $this->resource->description,
+ 'totalAmountString' => $amountString,
+ ];
+ }
+}
diff --git a/database/migrations/2026_05_25_140010_create_cost_unit_estimates.php b/database/migrations/2026_05_25_140010_create_cost_unit_estimates.php
new file mode 100644
index 0000000..3c0aee3
--- /dev/null
+++ b/database/migrations/2026_05_25_140010_create_cost_unit_estimates.php
@@ -0,0 +1,32 @@
+id();
+ $table->string('tenant');
+ $table->foreignId('cost_unit_id')->constrained('cost_units', 'id')->restrictOnDelete()->cascadeOnUpdate();
+ $table->string('type');
+ $table->string('description');
+ $table->float('flat_amount', 2)->nullable();
+ $table->float('amount_by_user', 2)->nullable();
+
+ $table->foreign('tenant')->references('slug')->on('tenants')->restrictOnDelete()->cascadeOnUpdate();
+ $table->foreign('type')->references('slug')->on('invoice_types')->restrictOnDelete()->cascadeOnUpdate();
+
+ $table->timestamps();
+ });
+ }
+
+ public function down(): void
+ {
+ Schema::dropIfExists('cost_unit_estimates');
+ }
+};