+
+
{{ 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');
+ }
+};