Przeglądaj źródła

return select order status
revert maf to stock
select mafs in order

Alexander Musikhin 7 miesięcy temu
rodzic
commit
a5828ab086

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

@@ -184,4 +184,48 @@ class OrderController extends Controller
         ProductSKU::query()->where('order_id', $order->id)->delete();
         return redirect()->route('order.index');
     }
+
+    public function revertMaf(Request $request, Order $order)
+    {
+        $ids = $request->validate([
+            'ids' => 'required|json',
+        ]);
+        $ids = json_decode($ids['ids'], true);
+        $updated = [];
+        foreach ($ids as $mafId) {
+            $maf = ProductSKU::query()
+                ->where('order_id', $order->id)
+                ->where('id', $mafId)
+                ->first();
+            if($maf) {
+                MafOrder::query()->where('id', $maf->maf_order_id)->increment('in_stock');
+                $maf->update(['maf_order_id' => null, 'status' => 'требуется']);
+                $updated[] = $maf;
+            }
+        }
+
+        return response()->json($updated);
+    }
+
+    public function moveMaf(Request $request)
+    {
+        $data = $request->validate([
+            'new_order_id' => 'required',
+            'ids' => 'required|json',
+        ]);
+        $ids = json_decode($data['ids'], true);
+        $updated = [];
+        foreach ($ids as $mafId) {
+            $maf = ProductSKU::query()
+                ->where('id', $mafId)
+                ->first();
+            if($maf) {
+                $maf->update(['order_id' => $data['new_order_id']]);
+                // todo update comment: add previous address
+                $updated[] = $maf;
+            }
+        }
+
+        return response()->json($updated);
+    }
 }

+ 1 - 0
app/Http/Requests/Order/StoreOrderRequest.php

@@ -39,6 +39,7 @@ class StoreOrderRequest extends FormRequest
             'products'          => 'nullable|array',
             'quantity'          => 'nullable|array',
             'products_sku'      => 'nullable|array',
+            'order_status_id'   => 'nullable|exists:order_statuses,id',
         ];
     }
 }

+ 2 - 0
resources/views/orders/edit.blade.php

@@ -14,6 +14,8 @@
                     <input type="hidden" name="id" value="{{ $order->id }}">
                 @endif
 
+                @include('partials.select', ['name' => 'order_status_id', 'title' => 'Статус', 'options' => $orderStatuses, 'value' => $order->order_status_id ?? old('order_status_id'), 'required' => true])
+
                 @include('partials.select', ['name' => 'district_id', 'title' => 'Округ', 'options' => $districts, 'value' => $order?->district_id ?? old('district_id'), 'first_empty' => true, 'required' => true])
 
                 @include('partials.select', ['name' => 'area_id', 'title' => 'Район', 'options' => $areas, 'value' => $order?->area_id ?? old('area_id'), 'required' => true, 'first_empty' => true])

+ 40 - 4
resources/views/orders/show.blade.php

@@ -22,7 +22,7 @@
             </div>
         </div>
         <div class="row">
-            <div class="col-xl-4">
+            <div class="col-xl-3">
                 <h4>Общая информация об объекте</h4>
                 <div>ID площадки: {{ $order->id }}</div>
                 <div>
@@ -44,7 +44,7 @@
                 <div>Ссылка на группу в ТГ: {{ $order->tg_group_link }}</div>
 
             </div>
-            <div class="col-xl-8">
+            <div class="col-xl-9">
                 <h4>МАФы заказа</h4>
 
                 <div id="selected_maf">
@@ -52,7 +52,7 @@
                         <table class="table">
                             <thead>
                             <tr>
-                                <th></th>
+                                <th><input type="checkbox" class="form-check" id="check-all-maf"></th>
                                 <th>МАФ</th>
                                 <th>Тип</th>
                                 <th>Статус</th>
@@ -70,7 +70,9 @@
                             @endphp
                             @foreach($order->products_sku as $p)
                                 <tr>
-                                    <td>{{ $loop->iteration }}</td>
+                                    <td>
+                                        <input type="checkbox" class="form-check check-maf" data-maf-id="{{ $p->id }}">
+                                    </td>
                                     <td>{!! $p->product->article !!}</td>
                                     <td>{!! $p->product->nomenclature_number !!}</td>
                                     <td>{{ $p->status }}</td>
@@ -94,6 +96,9 @@
                             @endforeach
                             </tbody>
                         </table>
+                        <div>
+                            <button class="btn btn-primary btn-sm revert-maf">Вернуть на склад</button>
+                        </div>
                     @endif
                 </div>
 
@@ -103,3 +108,34 @@
     </div>
 
 @endsection
+
+@push('scripts')
+    <script type="module">
+
+        $('#check-all-maf').on('change', function () {
+            $('input:checkbox.check-maf').not(this).prop('checked', this.checked);
+        });
+
+        $('.revert-maf').on('click', function () {
+            let ids = Array();
+            $('.check-maf').each(function (){
+                if($(this).prop('checked')) {
+                    ids.push($(this).attr('data-maf-id'));
+                }
+            });
+
+            $.post('{{ route('order.revert-maf', $order) }}',
+                {
+                    '_token': $('meta[name=csrf-token]').attr('content'),
+                    ids: JSON.stringify(ids),
+                },
+                function (){
+                        // console.log(data);
+                        location.reload();
+                    }
+            );
+        });
+
+
+    </script>
+@endpush

+ 5 - 0
routes/web.php

@@ -69,6 +69,11 @@ Route::middleware('auth:web')->group(function () {
     Route::get('order/{order}/get-maf', [OrderController::class, 'getMafToOrder'])->name('order.get-maf');
     Route::delete('order/{order}', [OrderController::class, 'destroy'])->name('order.destroy')->middleware('role:' . Role::ADMIN);
 
+    Route::post('order/revert-maf/{order}', [OrderController::class, 'revertMaf'])->name('order.revert-maf');
+    Route::post('order/move-maf', [OrderController::class, 'moveMaf'])->name('order.move-maf');
+
+
+
     // Склад (МАФ)
     Route::get('product_sku', [ProductSKUController::class, 'index'])->name('product_sku.index');
     Route::get('product_sku/{product_sku}', [ProductSKUController::class, 'show'])->name('product_sku.show');