소스 검색

update orders status from main orders table

Alexander Musikhin 2 달 전
부모
커밋
c0a8eab32d

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

@@ -94,6 +94,8 @@ class OrderController extends Controller
             Order::where('id', $order->id)->first()?->recalculateReadyToMount();
         }
 
+        $this->data['statuses'] = OrderStatus::query()->get()->pluck('name', 'id');
+
         return view('orders.index', $this->data);
     }
 

+ 1 - 0
resources/views/orders/index.blade.php

@@ -15,6 +15,7 @@
         'id'        => $id,
         'header'    => $header,
         'strings'   => $orders,
+        'statuses'  => $statuses,
         'routeName' => 'order.show',
     ])
 

+ 0 - 1
resources/views/orders/show.blade.php

@@ -505,7 +505,6 @@
                     install_days: installDays
                 },
                 function () {
-                    console.log('Update success!');
                     $('.alerts').append(
                         '<div class="main-alert alert alert-success" role="alert">Обновлено количество дней на монтаж!</div>'
                     );

+ 32 - 1
resources/views/partials/table.blade.php

@@ -78,7 +78,7 @@
             <tr>
                 @foreach($header as $headerName => $headerTitle)
                     <td class="column_{{$headerName}}"
-                        @if(isset($routeName) && !str_contains($headerName, 'image')) onclick="location.href='{{ route($routeName, $string->id) }}'" @endif>
+                        @if(isset($routeName) && !str_contains($headerName, 'image') && !str_contains($headerName, 'order_status_name'))  onclick="location.href='{{ route($routeName, $string->id) }}'" @endif>
                         @if(str_contains($headerName, '-'))
                             @php
                                 list($rel, $field) = explode('-', $headerName);
@@ -125,6 +125,12 @@
                                data-size="fullscreen">
                                 <img src="{{ $string->$headerName }}" alt="" class="img-thumbnail maf-img">
                             </a>
+                        @elseif(str_contains($headerName, 'order_status_name'))
+                            <select name="order_status_name" data-order-id="{{ $string->id }}" @disabled(!hasRole('admin,manager')) class="change-order-status form-control form-control-sm" >
+                                @foreach($statuses as $statusId => $statusName)
+                                    <option value="{{ $statusId }}" @selected($statusName == $string->$headerName)>{{ $statusName }}</option>
+                                @endforeach
+                            </select>
                         @else
                             <p title="{!! $string->$headerName !!}">
                                 {!! \Illuminate\Support\Str::words($string->$headerName, config('app.words_in_table_cell_limit'), ' ...') !!}
@@ -384,5 +390,30 @@
             currentUrl.searchParams.delete('page');
             document.location.href = currentUrl.href;
         });
+
+        $('.change-order-status').on('change', function () {
+            let orderStatusId = $(this).val();
+            let orderId = $(this).attr('data-order-id');
+
+            $.post(
+                '{{ route('order.update') }}',
+                {
+                    '_token' : '{{ csrf_token() }}',
+                    id: orderId,
+                    order_status_id: orderStatusId
+                },
+                function () {
+                    $('.alerts').append(
+                        '<div class="main-alert alert alert-success" role="alert">Обновлён статус площадки!</div>'
+                    );
+                    setTimeout(function () {
+                        $('.main-alert').fadeTo(2000, 500).slideUp(500, function () {
+                            $(".main-alert").slideUp(500);
+                        })
+                    }, 3000);
+                }
+            );
+        });
+
     </script>
 @endpush

+ 1 - 1
routes/web.php

@@ -84,7 +84,7 @@ Route::middleware('auth:web')->group(function () {
     Route::get('order/{order}', [OrderController::class, 'show'])->name('order.show');
     Route::get('order/edit/{order}', [OrderController::class, 'edit'])->name('order.edit');
     Route::post('order/store', [OrderController::class, 'store'])->name('order.store');
-    Route::post('order/{order}/update', [OrderController::class, 'store'])->name('order.update');
+    Route::post('order/update', [OrderController::class, 'store'])->name('order.update');
     Route::delete('order/{order}', [OrderController::class, 'destroy'])->name('order.destroy')->middleware('role:' . Role::ADMIN);
 
     Route::get('order/{order}/get-maf', [OrderController::class, 'getMafToOrder'])->name('order.get-maf');