Explorar el Código

Merge remote-tracking branch 'origin/master'

Alexander Musikhin hace 8 meses
padre
commit
0c28a651d4

+ 16 - 8
app/Http/Controllers/OrderController.php

@@ -11,6 +11,7 @@ use App\Models\Dictionary\District;
 use App\Models\ObjectType;
 use App\Models\Order;
 use App\Models\OrderStatus;
+use App\Models\Product;
 use App\Models\User;
 use Illuminate\Http\Request;
 use Illuminate\Support\Str;
@@ -39,6 +40,17 @@ class OrderController extends Controller
         ]
     ];
 
+    public function __construct()
+    {
+        $this->data['districts'] = District::query()->get()->pluck('name', 'id');
+        $this->data['areas'] = Area::query()->get()->pluck('name', 'id');
+        $this->data['objectTypes'] = ObjectType::query()->get()->pluck('name', 'id');
+        $this->data['orderStatuses'] =OrderStatus::query()->get()->pluck('name', 'id');
+        $this->data['brigadiers'] = Brigadier::query()->get()->pluck('name', 'id');
+        $this->data['users'] = User::query()->get()->pluck('name', 'id');
+    }
+
+
     /**
      * Display a listing of the resource.
      */
@@ -147,12 +159,6 @@ class OrderController extends Controller
      */
     public function create()
     {
-        $this->data['districts'] = District::query()->get()->pluck('name', 'id');
-        $this->data['areas'] = Area::query()->get()->pluck('name', 'id');
-        $this->data['objectTypes'] = ObjectType::query()->get()->pluck('name', 'id');
-        $this->data['orderStatuses'] =OrderStatus::query()->get()->pluck('name', 'id');
-        $this->data['brigadiers'] = Brigadier::query()->get()->pluck('name', 'id');
-        $this->data['users'] = User::query()->get()->pluck('name', 'id');
         return view('orders.edit', $this->data);
     }
 
@@ -173,9 +179,11 @@ class OrderController extends Controller
     /**
      * Display the specified resource.
      */
-    public function show(string $id)
+    public function show(Order $order)
     {
-        //
+        $this->data['order'] = $order;
+        $this->data['products'] = Product::get()->pluck('manufacturer_name', 'article')->toArray();
+        return view('orders.edit', $this->data);
     }
 
     /**

+ 34 - 9
app/Http/Controllers/ProductController.php

@@ -37,7 +37,14 @@ class ProductController extends Controller
             'total_price_txt'           => 'Итоговая цена',
             'note'                      => 'Примечания',
             'created_at'                => 'Дата создания',
-        ]
+        ],
+        'searchFields' =>  [
+            'nomenclature_number',
+            'article',
+            'name_tz',
+            'manufacturer_name',
+            'note',
+        ],
     ];
 
     public function index(Request $request)
@@ -84,14 +91,6 @@ class ProductController extends Controller
             ]
         ];
 
-        $this->data['searchFields'] = [
-            'nomenclature_number',
-            'article',
-            'name_tz',
-            'manufacturer_name',
-            'note',
-        ];
-
         // fill filters
         $this->data['filters'] = $filters;
         $this->data['dates'] = $dates;
@@ -202,4 +201,30 @@ class ProductController extends Controller
 
         return redirect()->route('catalog.index')->with(['success' => 'Задача экспорта успешно создана!']);
     }
+
+    /**
+     * @param Request $request
+     * @return array
+     */
+    public function search(Request $request): array
+    {
+        $s = $request->get('s');
+        $searchFields = $this->data['searchFields'];
+        $ret = [];
+        if($s && strlen($s > 1)) {
+            $result = Product::query()->where(function ($query) use ($searchFields, $s) {
+                foreach ($searchFields as $searchField) {
+                    $query->orWhere($searchField, 'LIKE', '%' . $s . '%');
+                }
+            });
+
+            foreach ($result->get() as $p) {
+                $string = '';
+                foreach ($searchFields as $searchField)
+                    $string .= $p->$searchField . ' / ';
+                $ret[$p->id] = $string;
+            }
+        }
+        return $ret;
+    }
 }

+ 35 - 6
resources/views/orders/edit.blade.php

@@ -1,16 +1,20 @@
 @extends('layouts.app')
 
 @section('content')
+
     <div class="px-3">
-        <div class="col-xxl-6 offset-xxl-2">
-            <form action="{{ route('order.store') }}" method="post">
+
+        <form class="row" action="{{ route('order.store') }}" method="post">
+            <div class="col-xxl-6">
+                <h4>Общая информация об объекте</h4>
+
                 @csrf
 
                 @if(isset($order))
                     <input type="hidden" name="id" value="{{ $order->id }}">
                 @endif
 
-                @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' => '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])
 
@@ -36,9 +40,19 @@
 
                 @include('partials.input', ['name' => 'tg_group_link', 'title' => 'Ссылка на группу в ТГ', 'value' => $order->tg_group_link ?? old('tg_group_link')])
 
+            </div>
+            <div class="col-xxl-6">
+                <h4>МАФ</h4>
+
+                @include('partials.input', ['name' => 'search_maf', 'title' => 'Поиск МАФ', 'value' => '', 'placeholder' => 'Артикул или номер номенклатуры', 'datalist' => []])
+
+
+            </div>
+            <div class="col-12 text-end">
                 @include('partials.submit')
-            </form>
-        </div>
+            </div>
+        </form>
+
     </div>
 
     @if($errors->any())
@@ -49,11 +63,26 @@
 
 @push('scripts')
     <script type="module">
+        $('#search_maf').on('keyup', function () {
+            // search products on backend
+            $.get('{{ route('product.search') }}?s=' + $(this).val(),
+                function (data) {
+                    $('#dl-search_maf').children().remove();
+                    $.each(data, function (id, name) {
+                        $('#dl-search_maf').append('<option value=\'' + name + '\'>' + id + '</option>');
+                    });
+                    console.log(data);
+                }
+            );
+        })
+
+
+
         $('#district_id').on('change', function () {
             // load areas of selected district
             console.log($(this).val());
 
-            $.get('{{ route('area.ajax-get-areas-by-district') }}/'+$(this).val(),
+            $.get('{{ route('area.ajax-get-areas-by-district') }}/' + $(this).val(),
                 function (data) {
                     $('#area_id').children().remove();
                     $.each(data, function (id, name) {

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

@@ -14,7 +14,8 @@
     @include('partials.table', [
         'id'        => $id,
         'header'    => $header,
-        'strings'   => $orders
+        'strings'   => $orders,
+        'routeName' => 'order.show',
     ])
 
     <div class="row pt-3 px-3">

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

@@ -46,7 +46,7 @@
         @foreach($strings as $string)
             <tr>
                 @foreach($header as $headerName => $headerTitle)
-                    <td class="column_{{$headerName}}">
+                    <td class="column_{{$headerName}}" @isset($routeName) onclick="location.href='{{ route($routeName, $string->id) }}'" @endisset>
                         @if(str_ends_with($headerName, '_id'))
                             @php
                                 $relation = str_replace('_id', '', $headerName);

+ 4 - 0
routes/web.php

@@ -48,6 +48,10 @@ 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');
 
+    // ajax search products
+    Route::get('product/search', [ProductController::class, 'search'])->name('product.search');
+
+
     // ajax get areas by district
     Route::get('areas/{district_id?}', [AreaController::class, 'ajaxGetAreasByDistrict'])->name('area.ajax-get-areas-by-district');
 

+ 3 - 2
todo.md

@@ -5,9 +5,10 @@
 - [x] каталог товаров: фильтры, поиск, сортировка
 - [x] каталог товаров: экспорт
 - [x] каталог товаров: импорт
-- [ ] складские остатки товаров
+- [x] складские остатки товаров - модель, таблица
 - [ ] Добавить ответственных и привязать к району: ФИО, телефон
-- [ ] заказы (площадки)
+- [x] заказы (площадки) - создание, отображение таблицы
+- [ ] просмотр заказа, добавление товаров в заказ
 - [ ] заказы поставщику
 - [ ] импорт площадок
 - [ ] рекламации (возможно создание рекламации на манагере, пока не скажу)