Browse Source

refactored to softDeletes, added maf orders

Alexander Musikhin 8 tháng trước cách đây
mục cha
commit
d8c104431c

+ 5 - 1
app/Http/Controllers/Controller.php

@@ -16,7 +16,11 @@ class Controller extends BaseController
 {
     use AuthorizesRequests, ValidatesRequests;
 
-    protected array $data;
+    protected array $data = [
+        'filters'   => [],
+        'ranges'    => [],
+        'dates'     => [],
+    ];
 
     /**
      * @param Model $model

+ 79 - 0
app/Http/Controllers/MafOrderController.php

@@ -0,0 +1,79 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\Http\Requests\StoreMafOrderRequest;
+use App\Models\MafOrder;
+use Illuminate\Http\Request;
+
+class MafOrderController extends Controller
+{
+    protected array $data = [
+        'active'    => 'maf_order',
+        'title'     => 'Заказы МАФ',
+        'id'        => 'maf_order',
+        'header'    => [
+            'id'                                => 'ID',
+            'order_number'                      => '№ заказа',
+            'user-name'                         => 'Менеджер',
+            'product-article'                   => 'Артикул',
+            'product-nomenclature_number'       => 'Номер номенклатуры',
+            'product-common_name'               => 'МАФ',
+            'quantity'                          => 'Количество',
+            'created_at'                        => 'Дата создания',
+//
+//            'product-name_tz'                   => 'Наименование ТЗ',
+//            'product-type_tz'                   => 'Тип по ТЗ',
+//            'product-type'                      => 'Тип',
+//            'product-manufacturer_name'         => 'Наименование производителя',
+
+        ],
+        'searchFields' =>  [
+            'order_number',
+            'product-nomenclature_number',
+            'product-article',
+        ],
+    ];
+
+    public function index(Request $request)
+    {
+        $model = new MafOrder;
+
+        $this->createDateFilters($model, 'created_at');
+
+        $q = $model::query();
+
+        $this->acceptFilters($q, $request);
+        $this->acceptSearch($q, $request);
+        $this->setSortAndOrderBy($model, $request);
+
+        $q->orderBy($this->data['sortBy'], $this->data['orderBy']);
+
+        $this->data['maf_orders'] = $q->paginate()->withQueryString();
+        return view('maf_orders.index', $this->data);
+    }
+
+    public function store(StoreMafOrderRequest $request)
+    {
+        MafOrder::query()->create($request->validated() + ['user_id' => $request->user()->id]);
+        return redirect()->route('maf_order.index');
+    }
+
+    public function show(MafOrder $maf_order)
+    {
+        $this->data['maf_order'] = $maf_order;
+        return view('maf_orders.edit', $this->data);
+    }
+
+    public function update(StoreMafOrderRequest $request, MafOrder $maf_order)
+    {
+        $maf_order->update($request->validated());
+        return redirect()->route('maf_order.index');
+    }
+
+    public function destroy(MafOrder $maf_order)
+    {
+        $maf_order->delete();
+        return redirect()->route('maf_order.index');
+    }
+}

+ 30 - 0
app/Http/Requests/StoreMafOrderRequest.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace App\Http\Requests;
+
+use Illuminate\Foundation\Http\FormRequest;
+
+class StoreMafOrderRequest extends FormRequest
+{
+    /**
+     * Determine if the user is authorized to make this request.
+     */
+    public function authorize(): bool
+    {
+        return auth()->check();
+    }
+
+    /**
+     * Get the validation rules that apply to the request.
+     *
+     * @return array
+     */
+    public function rules(): array
+    {
+        return [
+            'order_number'  => 'nullable|string',
+            'product_id'    => 'required|exists:products,id',
+            'quantity'      => 'required|integer|min:1',
+        ];
+    }
+}

+ 30 - 0
app/Models/MafOrder.php

@@ -0,0 +1,30 @@
+<?php
+
+namespace App\Models;
+
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Relations\BelongsTo;
+use Illuminate\Database\Eloquent\SoftDeletes;
+
+class MafOrder extends Model
+{
+    use SoftDeletes;
+    protected $fillable = [
+        'order_number',
+        'user_id',
+        'product_id',
+        'quantity',
+    ];
+
+    const DEFAULT_SORT_BY = 'created_at';
+
+    public function user(): BelongsTo
+    {
+        return $this->belongsTo(User::class);
+    }
+
+    public function product(): BelongsTo
+    {
+        return $this->belongsTo(Product::class);
+    }
+}

+ 2 - 0
app/Models/ObjectType.php

@@ -3,8 +3,10 @@
 namespace App\Models;
 
 use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
 
 class ObjectType extends Model
 {
+    use SoftDeletes;
     protected $fillable = ['name'];
 }

+ 2 - 0
app/Models/Order.php

@@ -7,10 +7,12 @@ use App\Models\Dictionary\District;
 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Database\Eloquent\Relations\BelongsTo;
 use Illuminate\Database\Eloquent\Relations\BelongsToMany;
+use Illuminate\Database\Eloquent\SoftDeletes;
 use Illuminate\Support\Facades\DB;
 
 class Order extends Model
 {
+    use SoftDeletes;
     const DEFAULT_SORT_BY = 'created_at';
 
     protected $fillable = [

+ 2 - 0
app/Models/OrderStatus.php

@@ -3,8 +3,10 @@
 namespace App\Models;
 
 use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\SoftDeletes;
 
 class OrderStatus extends Model
 {
+    use SoftDeletes;
     protected $fillable = ['name'];
 }

+ 2 - 0
app/Models/Responsible.php

@@ -5,9 +5,11 @@ namespace App\Models;
 use App\Models\Dictionary\Area;
 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Database\Eloquent\Relations\HasOne;
+use Illuminate\Database\Eloquent\SoftDeletes;
 
 class Responsible extends Model
 {
+    use SoftDeletes;
     const DEFAULT_SORT_BY = 'updated_at';
     protected $fillable = [
         'name',

+ 1 - 0
database/migrations/2025_03_04_153350_create_object_types_table.php

@@ -15,6 +15,7 @@ return new class extends Migration
             $table->id();
             $table->string('name');
             $table->timestamps();
+            $table->softDeletes();
         });
     }
 

+ 1 - 0
database/migrations/2025_03_04_153402_create_order_statuses_table.php

@@ -15,6 +15,7 @@ return new class extends Migration
             $table->id();
             $table->string('name');
             $table->timestamps();
+            $table->softDeletes();
         });
     }
 

+ 1 - 0
database/migrations/2025_03_24_153700_create_orders_table.php

@@ -27,6 +27,7 @@ return new class extends Migration
             $table->string('tg_group_name')->nullable();
             $table->string('tg_group_link')->nullable();
             $table->timestamps();
+            $table->softDeletes();
         });
     }
 

+ 1 - 2
database/migrations/2025_03_31_145335_create_products_sku_table.php

@@ -30,9 +30,8 @@ return new class extends Migration
             $table->date('certificate_date')->nullable();               // дата выдачи сертификата
             $table->string('certificate_issuer')->nullable();           // орган сертификации
             $table->string('certificate_type')->nullable();             // декларация, сертификат, отказное письмо
-
-            $table->softDeletes();
             $table->timestamps();
+            $table->softDeletes();
         });
     }
 

+ 1 - 0
database/migrations/2025_04_03_192940_create_responsibles_table.php

@@ -16,6 +16,7 @@ return new class extends Migration
             $table->string('name');
             $table->string('phone');
             $table->timestamps();
+            $table->softDeletes();
         });
         Schema::table('areas', function (Blueprint $table) {
             $table->foreignId('responsible_id')

+ 32 - 0
database/migrations/2025_04_05_231749_create_maf_orders_table.php

@@ -0,0 +1,32 @@
+<?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::create('maf_orders', function (Blueprint $table) {
+            $table->id();
+            $table->string('order_number')->nullable();
+            $table->foreignId('user_id')->constrained('users');
+            $table->foreignId('product_id')->constrained('products');
+            $table->unsignedInteger('quantity');
+            $table->timestamps();
+            $table->softDeletes();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        Schema::dropIfExists('maf_orders');
+    }
+};

+ 11 - 3
resources/views/layouts/menu.blade.php

@@ -1,9 +1,17 @@
 <li class="nav-item"><a class="nav-link" href="{{ route('order.index') }}">Площадки</a></li>
-<li class="nav-item"><a class="nav-link" href="{{ route('product_sku.index') }}">Заказы МАФ</a></li>
+<li class="nav-item"><a class="nav-link" href="{{ route('maf_order.index') }}">Заказы МАФ</a></li>
 
 <li class="nav-item"><a class="nav-link" href="{{ route('catalog.index') }}">Каталог</a></li>
 
 @if(hasrole('admin'))
-    <li class="nav-item"><a class="nav-link" href="{{ route('user.index') }}">Пользователи</a></li>
-    <li class="nav-item"><a class="nav-link" href="{{ route('responsible.index') }}">Ответственные</a></li>
+    <li class="nav-item dropdown">
+        <a id="navbarDropdown" class="nav-link dropdown-toggle" href="#" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
+            Администрирование
+        </a>
+        <ul class="dropdown-menu dropdown-menu-end">
+            <li class="dropdown-item"><a class="nav-link" href="{{ route('user.index') }}">Пользователи</a></li>
+            <li class="dropdown-item"><a class="nav-link" href="{{ route('responsible.index') }}">Ответственные</a></li>
+        </ul>
+    </li>
+
 @endif

+ 28 - 0
resources/views/maf_orders/edit.blade.php

@@ -0,0 +1,28 @@
+@extends('layouts.app')
+
+@section('content')
+
+    <div class="px-3">
+
+        <form class="row" action="{{ route('maf_order.update', $maf_order) }}" method="post">
+            <div class="col-xxl-6">
+                <h4>Заказ МАФ</h4>
+                @csrf
+
+                <input type="hidden" id="product_id" name="product_id" value="{{ $maf_order->product_id }}">
+                @include('partials.input', ['name' => 'product_name', 'title' => 'МАФ', 'disabled' => true, 'value' => $maf_order->product->common_name])
+                @include('partials.input', ['name' => 'order_number', 'title' => 'Номер заказа', 'required' => false, 'value' => $maf_order->order_number])
+                @include('partials.input', ['name' => 'quantity', 'title' => 'Количество', 'required' => true, 'value' => $maf_order->quantity, 'required' => true])
+
+                @include('partials.submit', ['name' => 'Сохранить', 'delete' => ['form_id' => 'destroy', 'title' => 'Удалить']])
+            </div>
+        </form>
+    </div>
+    <div class="visually-hidden d-none">
+        <form action="{{ route('maf_order.delete', $maf_order) }}" id="destroy" method="post">
+            @csrf
+            @method('DELETE')
+        </form>
+    </div>
+@endsection
+

+ 75 - 0
resources/views/maf_orders/index.blade.php

@@ -0,0 +1,75 @@
+@extends('layouts.app')
+
+@section('content')
+
+    <div class="row mb-3">
+        <div class="col-6">
+            <h3>Заказы МАФ</h3>
+        </div>
+        <div class="col-6 text-end">
+            <button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#addModal">
+                Добавить
+            </button>
+
+        </div>
+    </div>
+
+
+    @include('partials.table', [
+        'id'        => $id,
+        'header'    => $header,
+        'strings'   => $maf_orders,
+        'routeName' => 'maf_order.show',
+    ])
+
+    <div class="row pt-3 px-3">
+        <div class="col-12 pagination">
+            {{ $maf_orders->links() }}
+        </div>
+    </div>
+
+    <!-- Модальное окно добавления-->
+    <div class="modal fade" id="addModal" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
+        <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
+            <div class="modal-content">
+                <div class="modal-header">
+                    <h1 class="modal-title fs-5" id="addModalLabel">Добавить заказ МАФ</h1>
+                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
+                </div>
+                <div class="modal-body">
+                    <form action="{{ route('maf_order.store') }}" method="post">
+                        @csrf
+                        <div id="select_maf_form">
+                            <input type="text" class="form-control mb-2" placeholder="Поиск номенклатуры" id="search_maf">
+                            <select id="select_maf" class="form-select mb-3" multiple></select>
+                        </div>
+                        <div style="display:none;" id="sku_form">
+                            <a href="#" onclick="$('#sku_form').slideUp(); $('#select_maf_form').slideDown()">назад</a>
+                            <input type="hidden" id="product_id" name="product_id" value="">
+                            @include('partials.input', ['name' => 'product_name', 'title' => 'МАФ', 'disabled' => true])
+                            @include('partials.input', ['name' => 'order_number', 'title' => 'Номер заказа', 'required' => false])
+                            @include('partials.input', ['name' => 'quantity', 'title' => 'Количество', 'required' => true, 'min' => 1])
+                            @include('partials.submit', ['name' => 'Добавить'])
+                        </div>
+                    </form>
+                </div>
+            </div>
+        </div>
+    </div>
+
+    @if($errors->count())
+        @dump($errors)
+    @endif
+@endsection
+
+
+@push('scripts')
+    <script type="module">
+        $('#select_maf').on('change', function () {
+            $('#product_id').val($(this).val());
+            $('#product_name').val($('#select_maf option:selected').text()).slideDown();
+            $('#select_maf_form').slideUp();
+            $('#sku_form').slideDown();
+        });
+    </script>
+@endpush

+ 106 - 83
resources/views/partials/table.blade.php

@@ -1,25 +1,27 @@
-
 <div class="table-responsive">
 
 
     <div class="table-buttons py-2 bg-primary rounded-start d-flex flex-column ">
-        <button type="button" class="btn btn-sm text-white" data-bs-toggle="modal" data-bs-target="#table_{{ $id }}_modal_search">
+        <button type="button" class="btn btn-sm text-white" data-bs-toggle="modal"
+                data-bs-target="#table_{{ $id }}_modal_search">
             <i class="bi bi-search"></i>
         </button>
 
-        <button type="button" class="btn btn-sm text-white " data-bs-toggle="modal" data-bs-target="#table_{{ $id }}_modal_filters">
+        <button type="button" class="btn btn-sm text-white " data-bs-toggle="modal"
+                data-bs-target="#table_{{ $id }}_modal_filters">
             <i class="bi bi-funnel-fill"></i>
         </button>
 
-        <button type="button" class="btn btn-sm text-white " data-bs-toggle="modal" data-bs-target="#table_{{ $id }}_modal_settings">
+        <button type="button" class="btn btn-sm text-white " data-bs-toggle="modal"
+                data-bs-target="#table_{{ $id }}_modal_settings">
             <i class="bi bi-gear-fill"></i>
         </button>
     </div>
     <table class="table" id="tbl" data-table-name="{{ $id }}" style="display: none;">
         <thead>
-            <tr>
-                @foreach($header as $headerName => $headerTitle)
-                    <th scope="col" class="bg-primary-subtle column_{{ $headerName }}">
+        <tr>
+            @foreach($header as $headerName => $headerTitle)
+                <th scope="col" class="bg-primary-subtle column_{{ $headerName }}">
                         <span class="cursor-pointer sort-by-column" data-name="{{ $headerName }}">
                             {{ $headerTitle }}
                             @if(str_starts_with($headerName, $sortBy))
@@ -37,16 +39,17 @@
                                 <i class="bi bi-funnel"></i>
                             @endif
                         </span>
-                    </th>
-                @endforeach
+                </th>
+            @endforeach
 
-            </tr>
+        </tr>
         </thead>
         <tbody>
         @foreach($strings as $string)
             <tr>
                 @foreach($header as $headerName => $headerTitle)
-                    <td class="column_{{$headerName}}" @isset($routeName) onclick="location.href='{{ route($routeName, $string->id) }}'" @endisset>
+                    <td class="column_{{$headerName}}"
+                        @isset($routeName) onclick="location.href='{{ route($routeName, $string->id) }}'" @endisset>
                         @if(str_contains($headerName, '-'))
                             @php
                                 list($rel, $field) = explode('-', $headerName);
@@ -80,7 +83,8 @@
 </div>
 
 <!-- Модальное окно настроек таблицы -->
-<div class="modal fade" id="table_{{ $id }}_modal_settings" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
+<div class="modal fade" id="table_{{ $id }}_modal_settings" tabindex="-1" aria-labelledby="exampleModalLabel"
+     aria-hidden="true">
     <div class="modal-dialog modal-fullscreen-sm-down">
         <div class="modal-content">
             <div class="modal-header">
@@ -89,9 +93,11 @@
             </div>
             <div class="modal-body">
                 @foreach($header as $headerName => $headerTitle)
-                <div>
-                    <label class="me-3"><input type="checkbox" checked="checked" data-name="{{ $headerName }}" class="toggle-column checkbox-{{ $headerName }}"> {{ $headerTitle }}</label>
-                </div>
+                    <div>
+                        <label class="me-3"><input type="checkbox" checked="checked" data-name="{{ $headerName }}"
+                                                   class="toggle-column checkbox-{{ $headerName }}"> {{ $headerTitle }}
+                        </label>
+                    </div>
                 @endforeach
             </div>
             <div class="modal-footer">
@@ -102,7 +108,8 @@
 </div>
 
 <!-- Модальное окно фильтров -->
-<div class="modal fade" id="table_{{ $id }}_modal_filters" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
+<div class="modal fade" id="table_{{ $id }}_modal_filters" tabindex="-1" aria-labelledby="exampleModalLabel"
+     aria-hidden="true">
     <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
         <div class="modal-content">
             <div class="modal-header">
@@ -111,64 +118,75 @@
             </div>
             <div class="modal-body">
                 <form class="filters">
-                    @foreach($filters as $filterName => $filter)
-                        @php $filter['values'] = ['' => ''] + $filter['values'] @endphp
-                        @include('partials.select', [
-                                'name' => 'filters[' . $filterName . ']',
-                                'title' => $filter['title'],
-                                'options' => $filter['values'],
-                                'value' => request()->filters[$filterName] ?? '',
-                            ])
-                    @endforeach
-                    @foreach($ranges as $rangeName => $range)
+                    @if(isset($filters) && is_array($filters))
+                        @foreach($filters as $filterName => $filter)
+                            @php $filter['values'] = ['' => ''] + $filter['values'] @endphp
+                            @include('partials.select', [
+                                    'name' => 'filters[' . $filterName . ']',
+                                    'title' => $filter['title'],
+                                    'options' => $filter['values'],
+                                    'value' => request()->filters[$filterName] ?? '',
+                                ])
+                        @endforeach
+                    @endif
+
+                    @if(isset($ranges) && is_array($ranges))
+
+                        @foreach($ranges as $rangeName => $range)
 
-                        @include('partials.input', [
-                                'name' => 'filters[' . $rangeName . '_from]',
-                                'type' => 'number',
-                                'title' => $range['title'] . ' с:',
-                                'min' => $range['min'],
-                                'max' => $range['max'],
-                                'value' => request()->filters[$rangeName . '_from'] ?? '', // $range['min']
-                            ])
-                        @include('partials.input', [
-                                'name' => 'filters[' . $rangeName . '_to]',
-                                'type' => 'number',
-                                'title' => ' по:',
-                                'min' => $range['min'],
-                                'max' => $range['max'],
-                                'value' => request()->filters[$rangeName . '_to'] ?? '', // $range['max']
-                            ])
-                    @endforeach
-                    @foreach($dates as $rangeName => $range)
-                        @include('partials.input', [
-                                'name' => 'filters[' . $rangeName . '_from]',
-                                'type' => 'date',
-                                'title' => $range['title'] . ' с:',
-                                'min' => $range['min'],
-                                'max' => $range['max'],
-                                'value' => request()->filters[$rangeName . '_from'] ?? '',
-                            ])
-                        @include('partials.input', [
-                                'name' => 'filters[' . $rangeName . '_to]',
-                                'type' => 'date',
-                                'title' => $range['title'] . ' по:',
-                                'min' => $range['min'],
-                                'max' => $range['max'],
-                                'value' => request()->filters[$rangeName . '_to'] ?? '',
-                            ])
-                    @endforeach
+                            @include('partials.input', [
+                                    'name' => 'filters[' . $rangeName . '_from]',
+                                    'type' => 'number',
+                                    'title' => $range['title'] . ' с:',
+                                    'min' => $range['min'],
+                                    'max' => $range['max'],
+                                    'value' => request()->filters[$rangeName . '_from'] ?? '', // $range['min']
+                                ])
+                            @include('partials.input', [
+                                    'name' => 'filters[' . $rangeName . '_to]',
+                                    'type' => 'number',
+                                    'title' => ' по:',
+                                    'min' => $range['min'],
+                                    'max' => $range['max'],
+                                    'value' => request()->filters[$rangeName . '_to'] ?? '', // $range['max']
+                                ])
+                        @endforeach
+                    @endif
+                    @if(isset($dates) && is_array($dates))
+
+                        @foreach($dates as $rangeName => $range)
+                            @include('partials.input', [
+                                    'name' => 'filters[' . $rangeName . '_from]',
+                                    'type' => 'date',
+                                    'title' => $range['title'] . ' с:',
+                                    'min' => $range['min'],
+                                    'max' => $range['max'],
+                                    'value' => request()->filters[$rangeName . '_from'] ?? '',
+                                ])
+                            @include('partials.input', [
+                                    'name' => 'filters[' . $rangeName . '_to]',
+                                    'type' => 'date',
+                                    'title' => $range['title'] . ' по:',
+                                    'min' => $range['min'],
+                                    'max' => $range['max'],
+                                    'value' => request()->filters[$rangeName . '_to'] ?? '',
+                                ])
+                        @endforeach
+                    @endif
                 </form>
             </div>
             <div class="modal-footer">
                 <button type="button" class="btn btn-primary accept-filters" data-bs-dismiss="modal">Применить</button>
-                <button type="button" class="btn btn-outline-secondary reset-filters" data-bs-dismiss="modal">Сбросить</button>
+                <button type="button" class="btn btn-outline-secondary reset-filters" data-bs-dismiss="modal">Сбросить
+                </button>
             </div>
         </div>
     </div>
 </div>
 
 <!-- Модальное окно поиска -->
-<div class="modal fade" id="table_{{ $id }}_modal_search" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
+<div class="modal fade" id="table_{{ $id }}_modal_search" tabindex="-1" aria-labelledby="exampleModalLabel"
+     aria-hidden="true">
     <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
         <div class="modal-content">
             <div class="modal-header">
@@ -181,7 +199,9 @@
                     <span class="fst-italic">
                         @foreach($searchFields as $searchField)
                             {{ $header[$searchField] }}
-                            @if(!$loop->last),@endif
+                            @if(!$loop->last)
+                                ,
+                            @endif
                         @endforeach
                     </span>
                 </div>
@@ -197,7 +217,8 @@
             </div>
             <div class="modal-footer">
                 <button type="button" class="btn btn-primary accept-search" data-bs-dismiss="modal">Найти</button>
-                <button type="button" class="btn btn-outline-secondary reset-search" data-bs-dismiss="modal">Сбросить</button>
+                <button type="button" class="btn btn-outline-secondary reset-search" data-bs-dismiss="modal">Сбросить
+                </button>
             </div>
         </div>
     </div>
@@ -208,26 +229,28 @@
         // on page load set column visible
         let tbl = $('#tbl');
         let tableName = tbl.attr('data-table-name');
-        let tables = JSON.parse(localStorage.getItem('table_'+tableName));
+        let tables = JSON.parse(localStorage.getItem('table_' + tableName));
 
         // on first load create tables object
-        if(!tables) { tables = {}; }
+        if (!tables) {
+            tables = {};
+        }
 
         // hide disabled columns
         $.each(tables, function (colName, colStatus) {
-            if(!colStatus) {
-                $('.checkbox-'+colName).attr('checked', false);
-                $('.column_'+colName).hide();
+            if (!colStatus) {
+                $('.checkbox-' + colName).attr('checked', false);
+                $('.column_' + colName).hide();
             }
         });
 
         // highlight search text
         let searchText = $('.search-form input').val();
-        if(searchText !== '') {
+        if (searchText !== '') {
             let innerHTML = tbl.html();
             let index = innerHTML.indexOf(searchText);
             if (index >= 0) {
-                innerHTML = innerHTML.substring(0,index) + "<span class='highlight'>" + innerHTML.substring(index,index+searchText.length) + "</span>" + innerHTML.substring(index + searchText.length);
+                innerHTML = innerHTML.substring(0, index) + "<span class='highlight'>" + innerHTML.substring(index, index + searchText.length) + "</span>" + innerHTML.substring(index + searchText.length);
                 tbl.html(innerHTML);
             }
         }
@@ -240,13 +263,13 @@
 
             // save column status
             tables[columnName] = columnStatus;
-            localStorage.setItem('table_'+tableName, JSON.stringify(tables));
+            localStorage.setItem('table_' + tableName, JSON.stringify(tables));
 
             // show or hide column
-            if(columnStatus) {
-                $('.column_'+columnName).show('fast');
+            if (columnStatus) {
+                $('.column_' + columnName).show('fast');
             } else {
-                $('.column_'+columnName).hide('fast');
+                $('.column_' + columnName).hide('fast');
             }
         });
 
@@ -255,7 +278,7 @@
             let currentUrl = new URL(document.location.href);
             let currentColumnName = currentUrl.searchParams.get('sortBy');
             currentUrl.searchParams.set('sortBy', columnName);
-            if((currentColumnName !== columnName) || (currentUrl.searchParams.has('order'))) {
+            if ((currentColumnName !== columnName) || (currentUrl.searchParams.has('order'))) {
                 currentUrl.searchParams.delete('order');
             } else {
                 currentUrl.searchParams.set('order', 'desc');
@@ -267,7 +290,7 @@
             let filters = $('.filters').serializeArray();
             let currentUrl = new URL(document.location.href);
             $.each(filters, function (id, filter) {
-                if(filter.value !== '') {
+                if (filter.value !== '') {
                     currentUrl.searchParams.set(filter.name, filter.value);
                 } else {
                     currentUrl.searchParams.delete(filter.name);
@@ -290,11 +313,11 @@
         $('.accept-search').on('click', function () {
             let s = $('.search-form input').val();
             let currentUrl = new URL(document.location.href);
-            if(s !== '') {
-                    currentUrl.searchParams.set('s', s);
-                } else {
-                    currentUrl.searchParams.delete('s');
-                }
+            if (s !== '') {
+                currentUrl.searchParams.set('s', s);
+            } else {
+                currentUrl.searchParams.delete('s');
+            }
             currentUrl.searchParams.delete('page');
             document.location.href = currentUrl.href;
         });

+ 9 - 1
routes/web.php

@@ -1,6 +1,7 @@
 <?php
 
 use App\Http\Controllers\AreaController;
+use App\Http\Controllers\MafOrderController;
 use App\Http\Controllers\OrderController;
 use App\Http\Controllers\ProductController;
 use App\Http\Controllers\ProductSKUController;
@@ -57,12 +58,19 @@ Route::middleware('auth:web')->group(function () {
     Route::post('order/{order}/store', [OrderController::class, 'store'])->name('order.update');
     Route::get('order/destroy', [OrderController::class, 'destroy'])->name('order.destroy');
 
-    // Склад - Заказы МАФ
+    // Склад
     Route::get('product_sku', [ProductSKUController::class, 'index'])->name('product_sku.index');
     Route::get('product_sku/{product_sku}', [ProductSKUController::class, 'show'])->name('product_sku.show');
     Route::post('product_sku/store', [ProductSKUController::class, 'store'])->name('product_sku.store');
     Route::post('product_sku/update/{product_sku}', [ProductSKUController::class, 'update'])->name('product_sku.update');
 
+   // Склад заказы МАФ
+    Route::get('maf_orders', [MafOrderController::class, 'index'])->name('maf_order.index');
+    Route::get('maf_orders/{maf_order}', [MafOrderController::class, 'show'])->name('maf_order.show');
+    Route::post('maf_orders/store', [MafOrderController::class, 'store'])->name('maf_order.store');
+    Route::post('maf_orders/update/{maf_order}', [MafOrderController::class, 'update'])->name('maf_order.update');
+    Route::delete('maf_orders/delete/{maf_order}', [MafOrderController::class, 'destroy'])->name('maf_order.delete');
+
     // ajax search products
     Route::get('product/search', [ProductController::class, 'search'])->name('product.search');