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