Forráskód Böngészése

Update reclamation spare parts and warehouse visibility

Alexander Musikhin 3 hete
szülő
commit
b90aad9102

+ 9 - 0
app/Http/Controllers/ChatMessageController.php

@@ -258,6 +258,15 @@ class ChatMessageController extends Controller
                 abort(403);
             }
         }
+
+        if (hasRole(Role::WAREHOUSE_HEAD)) {
+            $canView = $reclamation->brigadier_id !== null
+                && in_array((int) $reclamation->status_id, Reclamation::visibleStatusIdsForBrigadier(), true);
+
+            if (!$canView) {
+                abort(403);
+            }
+        }
     }
 
     private function resolveTargetUserIds(

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

@@ -82,6 +82,9 @@ class ReclamationController extends Controller
         if (hasRole(Role::BRIGADIER)) {
             $q->where('brigadier_id', auth()->id())
                 ->whereIn('status_id', Reclamation::visibleStatusIdsForBrigadier());
+        } elseif (hasRole(Role::WAREHOUSE_HEAD)) {
+            $q->whereNotNull('brigadier_id')
+                ->whereIn('status_id', Reclamation::visibleStatusIdsForBrigadier());
         }
 
         $this->applyStableSorting($q);
@@ -591,6 +594,15 @@ class ReclamationController extends Controller
                 abort(403);
             }
         }
+
+        if (hasRole(Role::WAREHOUSE_HEAD)) {
+            $canView = $reclamation->brigadier_id !== null
+                && in_array((int)$reclamation->status_id, Reclamation::visibleStatusIdsForBrigadier(), true);
+
+            if (!$canView) {
+                abort(403);
+            }
+        }
     }
 
     private function ensureHasRole(array $roles): void

+ 35 - 1
app/Http/Controllers/ScheduleController.php

@@ -248,6 +248,7 @@ class ScheduleController extends Controller
             ->first();
 
         $order = $reclamation->order;
+        $scheduleComment = $this->buildScheduleCommentFromReclamation($reclamation);
 
         $mafs = [];
         if(empty($validated['skus'])) {
@@ -284,7 +285,7 @@ class ScheduleController extends Controller
                     'mafs' => $mafsText,
                     'mafs_count' => $mafsCount,
                     'brigadier_id' => $reclamation->brigadier_id,
-                    'comment'   => $reclamation->guarantee,
+                    'comment'   => $scheduleComment,
                 ]);
             if($first && isset($validated['send_notifications'])) {
                 $first = false;
@@ -295,6 +296,39 @@ class ScheduleController extends Controller
 
     }
 
+    private function buildScheduleCommentFromReclamation(Reclamation $reclamation): string
+    {
+        $guarantee = trim((string) $reclamation->guarantee);
+
+        $parts = $reclamation->sparePartReservations()
+            ->whereIn('status', ['active', 'issued'])
+            ->with(['sparePart:id,article', 'sparePartOrder:id,order_number'])
+            ->orderBy('created_at')
+            ->get()
+            ->map(static function ($reservation): ?string {
+                $article = trim((string) $reservation->sparePart?->article);
+
+                if ($article === '') {
+                    return null;
+                }
+
+                $orderNumber = $reservation->sparePartOrder?->display_order_number ?? '-';
+
+                return $article . ' - ' . $orderNumber;
+            })
+            ->filter()
+            ->values();
+
+        $lines = array_filter([
+            $guarantee !== '' ? $guarantee : null,
+            $parts->isNotEmpty()
+                ? 'Используемые детали: ' . $parts->implode(', ') . '.'
+                : null,
+        ]);
+
+        return implode(PHP_EOL, $lines);
+    }
+
 
     public function update(UpdateScheduleRequest $request, NotificationService $notificationService)
     {

+ 7 - 0
app/Models/SparePartOrder.php

@@ -156,6 +156,13 @@ class SparePartOrder extends Model
         return self::STATUS_NAMES[$this->status] ?? $this->status;
     }
 
+    public function getDisplayOrderNumberAttribute(): string
+    {
+        $orderNumber = trim((string) ($this->order_number ?? ''));
+
+        return $orderNumber !== '' ? $orderNumber : '#' . $this->id;
+    }
+
     /**
      * Сколько зарезервировано из этой партии
      */

+ 3 - 1
app/Services/Import/ImportSparePartOrdersService.php

@@ -39,13 +39,14 @@ class ImportSparePartOrdersService
                 $errors = 0;
 
                 // Начинаем со 2-й строки (пропускаем заголовок)
-                // Колонки: A=Артикул, B=кол-во, C=С документами?, D=Номер заказа, E=Статус
+                // Колонки: A=Артикул, B=кол-во, C=С документами?, D=Номер заказа, E=Статус, F=Примечание
                 for ($row = 2; $row <= $highestRow; $row++) {
                     $article = trim($sheet->getCell('A' . $row)->getValue());
                     $quantity = (int) $sheet->getCell('B' . $row)->getValue();
                     $withDocsRaw = trim($sheet->getCell('C' . $row)->getValue());
                     $orderNumber = trim($sheet->getCell('D' . $row)->getValue());
                     $statusRaw = trim($sheet->getCell('E' . $row)->getValue());
+                    $note = trim((string) $sheet->getCell('F' . $row)->getValue());
 
                     // Пропускаем пустые строки
                     if (empty($article)) {
@@ -82,6 +83,7 @@ class ImportSparePartOrdersService
                         'ordered_quantity' => $quantity,
                         'available_qty' => $quantity,
                         'with_documents' => $withDocuments,
+                        'note' => $note !== '' ? $note : null,
                         'user_id' => $this->userId,
                     ]);
 

+ 6 - 6
resources/views/reclamations/edit.blade.php

@@ -258,7 +258,7 @@
                                                 <th>Запчасть</th>
                                                 <th class="text-center">Кол-во</th>
                                                 <th class="text-center">С док.</th>
-                                                <th>Партия</th>
+                                                <th>Номер заказа</th>
                                                 @if(hasRole('admin,manager'))
                                                     <th></th>
                                                 @endif
@@ -292,10 +292,10 @@
                                                         @if($reservation->sparePartOrder)
                                                             @if(hasRole('admin,manager'))
                                                                 <a href="{{ route('spare_part_orders.show', $reservation->sparePartOrder->id) }}">
-                                                                    #{{ $reservation->sparePartOrder->id }}
+                                                                    {{ $reservation->sparePartOrder->display_order_number }}
                                                                 </a>
                                                             @else
-                                                                #{{ $reservation->sparePartOrder->id }}
+                                                                {{ $reservation->sparePartOrder->display_order_number }}
                                                             @endif
                                                         @else
                                                             -
@@ -346,7 +346,7 @@
                                                 <th>Запчасть</th>
                                                 <th class="text-center">Кол-во</th>
                                                 <th class="text-center">С док.</th>
-                                                <th>Партия</th>
+                                                <th>Номер заказа</th>
                                                 <th>Дата</th>
                                             </tr>
                                         </thead>
@@ -378,10 +378,10 @@
                                                         @if($reservation->sparePartOrder)
                                                             @if(hasRole('admin,manager'))
                                                                 <a href="{{ route('spare_part_orders.show', $reservation->sparePartOrder->id) }}">
-                                                                    #{{ $reservation->sparePartOrder->id }}
+                                                                    {{ $reservation->sparePartOrder->display_order_number }}
                                                                 </a>
                                                             @else
-                                                                #{{ $reservation->sparePartOrder->id }}
+                                                                {{ $reservation->sparePartOrder->display_order_number }}
                                                             @endif
                                                         @else
                                                             -

+ 4 - 4
resources/views/spare_parts/edit.blade.php

@@ -412,7 +412,7 @@
                                     <thead>
                                         <tr>
                                             <th>ID</th>
-                                            <th>Источник</th>
+                                            <th>Номер заказа</th>
                                             <th class="text-center">Остаток</th>
                                             <th class="text-center">С док.</th>
                                             <th>Дата поступления</th>
@@ -424,7 +424,7 @@
                                                 <td>
                                                     <a href="{{ route('spare_part_orders.show', $order->id) }}">#{{ $order->id }}</a>
                                                 </td>
-                                                <td>{{ $order->source_text ?: '-' }}</td>
+                                                <td>{{ $order->display_order_number }}</td>
                                                 <td class="text-center">{{ $order->available_qty }}</td>
                                                 <td class="text-center">
                                                     @if($order->with_documents)
@@ -461,7 +461,7 @@
                                         <tr>
                                             <th>Дата</th>
                                             <th>Тип</th>
-                                            <th>Партия</th>
+                                            <th>Номер заказа</th>
                                             <th class="text-center">Кол-во</th>
                                             <th class="text-center">С док.</th>
                                             <th>Примечание</th>
@@ -475,7 +475,7 @@
                                                 <td>{{ $movement->type_name }}</td>
                                                 <td>
                                                     @if($movement->sparePartOrder)
-                                                        <a href="{{ route('spare_part_orders.show', $movement->sparePartOrder->id) }}">#{{ $movement->sparePartOrder->id }}</a>
+                                                        <a href="{{ route('spare_part_orders.show', $movement->sparePartOrder->id) }}">{{ $movement->sparePartOrder->display_order_number }}</a>
                                                     @else
                                                         -
                                                     @endif