Преглед изворни кода

feat: adiciona novos campos para cadastro/edit de unidade

ebagabee пре 2 недеља
родитељ
комит
1b393aea71

+ 16 - 0
app/Http/Controllers/UnitFinancialController.php

@@ -47,4 +47,20 @@ public function upsert(UnitFinancialRequest $request): JsonResponse
 
         return $this->successResponse(payload: new UnitFinancialResource($item), message: __('messages.updated'));
     }
+
+    public function upsertMe(UnitFinancialRequest $request): JsonResponse
+    {
+        $unitId = Auth::user()?->load('units')->units->first()?->id;
+
+        if (!$unitId) {
+            return $this->errorResponse(message: 'Unidade não encontrada', code: 404);
+        }
+
+        $validated = $request->validated();
+        unset($validated['unit_id']);
+
+        $item = $this->service->upsert($unitId, $validated);
+
+        return $this->successResponse(payload: new UnitFinancialResource($item), message: __('messages.updated'));
+    }
 }

+ 7 - 1
app/Http/Requests/UnitFinancialRequest.php

@@ -9,7 +9,7 @@ class UnitFinancialRequest extends FormRequest
     public function rules(): array
     {
         return [
-            'unit_id'               => 'required|integer|exists:units,id',
+            'unit_id'               => 'sometimes|nullable|integer|exists:units,id',
             'tax_regime'            => 'nullable|string|max:50',
             'bank'                  => 'nullable|string|max:100',
             'agency'                => 'nullable|string|max:20',
@@ -24,6 +24,12 @@ public function rules(): array
             'maintenance_fee'       => 'nullable|numeric|min:0',
             'marketing_fund'        => 'nullable|numeric|min:0',
             'tbr'                   => 'nullable|numeric|min:0',
+            'max_freeze_count'      => 'nullable|integer|min:0',
+            'charge_roi'            => 'nullable|boolean',
+            'charge_fnm'            => 'nullable|boolean',
+            'default_discount'      => 'nullable|numeric|min:0|max:100',
+            'default_interest'      => 'nullable|numeric|min:0',
+            'default_fine'          => 'nullable|numeric|min:0|max:100',
         ];
     }
 }

+ 6 - 0
app/Http/Resources/UnitFinancialResource.php

@@ -28,6 +28,12 @@ public function toArray(Request $request): array
             'maintenance_fee'  => $this->maintenance_fee,
             'marketing_fund'   => $this->marketing_fund,
             'tbr'              => $this->tbr,
+            'max_freeze_count' => $this->max_freeze_count,
+            'charge_roi'       => (bool) $this->charge_roi,
+            'charge_fnm'       => (bool) $this->charge_fnm,
+            'default_discount' => $this->default_discount,
+            'default_interest' => $this->default_interest,
+            'default_fine'     => $this->default_fine,
             'created_at'       => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
             'updated_at'       => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
         ];

+ 12 - 6
app/Models/UnitFinancial.php

@@ -64,12 +64,18 @@ class UnitFinancial extends Model
     protected $guarded = ['id'];
 
     protected $casts = [
-        'maintenance_fee' => 'decimal:2',
-        'marketing_fund'  => 'decimal:2',
-        'tbr'             => 'decimal:2',
-        'created_at'      => 'datetime',
-        'updated_at'      => 'datetime',
-        'deleted_at'      => 'datetime',
+        'maintenance_fee'   => 'decimal:2',
+        'marketing_fund'    => 'decimal:2',
+        'tbr'               => 'decimal:2',
+        'max_freeze_count'  => 'integer',
+        'charge_roi'        => 'boolean',
+        'charge_fnm'        => 'boolean',
+        'default_discount'  => 'decimal:2',
+        'default_interest'  => 'decimal:2',
+        'default_fine'      => 'decimal:2',
+        'created_at'        => 'datetime',
+        'updated_at'        => 'datetime',
+        'deleted_at'        => 'datetime',
     ];
 
     public function unit(): BelongsTo

+ 37 - 0
database/migrations/2026_05_26_140542_add_contract_defaults_to_unit_financials_table.php

@@ -0,0 +1,37 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::table('unit_financials', function (Blueprint $table) {
+            $table->unsignedSmallInteger('max_freeze_count')->nullable();
+            $table->boolean('charge_roi')->default(false);
+            $table->boolean('charge_fnm')->default(false);
+            $table->decimal('default_discount', 5, 2)->nullable();
+            $table->decimal('default_interest', 5, 2)->nullable();
+            $table->decimal('default_fine', 5, 2)->nullable();
+        });
+    }
+
+    public function down(): void
+    {
+        Schema::table('unit_financials', function (Blueprint $table) {
+            $table->dropColumn([
+                'max_freeze_count',
+                'charge_roi',
+                'charge_fnm',
+                'default_discount',
+                'default_interest',
+                'default_fine',
+            ]);
+        });
+    }
+};

+ 1 - 0
routes/authRoutes/unit_financial.php

@@ -5,6 +5,7 @@
 
 Route::controller(UnitFinancialController::class)->prefix('unit-financial')->group(function () {
     Route::get('/me', 'showMe');
+    Route::post('/me', 'upsertMe');
 
     Route::get('/', 'show')
         ->middleware('permission:unit,view');