Browse Source

added comment field to reclamations, added check column exists on filters

Alexander Musikhin 4 weeks ago
parent
commit
ae3eeed59c

+ 10 - 5
app/Http/Controllers/FilterController.php

@@ -4,6 +4,7 @@ namespace App\Http\Controllers;
 
 use App\Http\Requests\FilterRequest;
 use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Schema;
 
 class FilterController extends Controller
 {
@@ -24,12 +25,16 @@ class FilterController extends Controller
 
         $dbTable = self::DB_TABLES[$table];
 
-        $q = DB::table($dbTable)->select($column)->distinct();
-        if($table !== 'reclamations') {
-            $q->where('year' , year());
+        if (Schema::hasColumn($dbTable, $column)) {
+            $q = DB::table($dbTable)->select($column)->distinct();
+            if($table !== 'reclamations') {
+                $q->where('year' , year());
+            }
+            $q->whereNull('deleted_at');
+            $result = $q->orderBy($column)->get()->pluck($column)->toArray();
+        } else {
+            $result = [];
         }
-        $q->whereNull('deleted_at');
-        $result = $q->orderBy($column)->get()->pluck($column)->toArray();
 
         return response()->json($result, 200, [], JSON_UNESCAPED_UNICODE|JSON_PRETTY_PRINT);
     }

+ 2 - 0
app/Http/Controllers/ReclamationController.php

@@ -40,11 +40,13 @@ class ReclamationController extends Controller
             'reason' => 'Причина',
             'guarantee' => 'Гарантии',
             'whats_done' => 'Что сделано',
+            'comment' => 'Комментарий',
         ],
         'searchFields' => [
             'reason',
             'guarantee',
             'whats_done',
+            'comment',
         ],
         'ranges' => [],
     ];

+ 1 - 0
app/Http/Requests/StoreReclamationRequest.php

@@ -32,6 +32,7 @@ class StoreReclamationRequest extends FormRequest
             'start_work_date' => 'nullable|date',
             'work_days'     => 'nullable|integer',
             'brigadier_id'  => 'nullable|exists:users,id',
+            'comment'       => 'nullable|string',
         ];
     }
 }

+ 1 - 0
app/Models/Reclamation.php

@@ -45,6 +45,7 @@ class Reclamation extends Model
         'start_work_date',
         'work_days',
         'brigadier_id',
+        'comment',
     ];
 
     public function order(): BelongsTo

+ 30 - 0
database/migrations/2025_11_06_135347_add_field_to_reclamations_table.php

@@ -0,0 +1,30 @@
+<?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('reclamations', function (Blueprint $table) {
+            $table->text('comment')->nullable();
+            $table->softDeletes();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::table('reclamations', function (Blueprint $table) {
+            $table->dropColumn('comment');
+            $table->dropSoftDeletes();
+        });
+    }
+};

+ 1 - 0
resources/views/reclamations/edit.blade.php

@@ -36,6 +36,7 @@
                     @include('partials.select', ['name' => 'reason', 'title' => 'Причина', 'size' => 6, 'value' => $reclamation->reason ?? '', 'options' => ['Вандализм', 'Гарантия', 'Сервисное обслуживание'], 'key_as_val' => true, 'disabled' => !hasRole('admin,manager')])
                     @include('partials.textarea', ['name' => 'guarantee', 'title' => 'Гарантии', 'size' => 6, 'value' => $reclamation->guarantee ?? '', 'disabled' => !hasRole('admin,manager')])
                     @include('partials.textarea', ['name' => 'whats_done', 'title' => 'Что сделано', 'size' => 6, 'value' => $reclamation->whats_done ?? '', 'disabled' => !hasRole('admin,manager')])
+                    @include('partials.textarea', ['name' => 'comment', 'title' => 'Комментарий', 'size' => 6, 'value' => $reclamation->comment ?? '', 'disabled' => !hasRole('admin,manager')])
                     @include('partials.submit', ['name' => 'Сохранить', 'offset' => 5, 'disabled' => !hasRole('admin,manager'), 'backurl' => route('reclamations.index', session('gp_reclamations'))])
                 </form>
             </div>