Prechádzať zdrojové kódy

updated schedule create and update

Alexander Musikhin 2 mesiacov pred
rodič
commit
0e3accd1aa

+ 63 - 33
app/Http/Controllers/ScheduleController.php

@@ -4,10 +4,14 @@ namespace App\Http\Controllers;
 
 use App\Helpers\DateHelper;
 use App\Http\Requests\CreateScheduleFromOrderRequest;
-use App\Http\Requests\CreateScheduleRequest;
 use App\Http\Requests\UpdateScheduleRequest;
+use App\Models\Dictionary\Area;
+use App\Models\Dictionary\District;
 use App\Models\Order;
+use App\Models\ProductSKU;
+use App\Models\Role;
 use App\Models\Schedule;
+use App\Models\User;
 use Illuminate\Http\Request;
 
 class ScheduleController extends Controller
@@ -20,6 +24,10 @@ class ScheduleController extends Controller
 
     public function index(Request $request)
     {
+        $this->data['districts'] = District::query()->get()->pluck('name', 'id');
+        $this->data['areas'] = Area::query()->get()->pluck('name', 'id');
+        $this->data['brigadiers'] = User::query()->where('role', Role::BRIGADIER)->get()->pluck('name', 'id');
+
         $this->data['weekNumber'] = $request->get('week' ,date('W'));
         $weekDates = [
             'mon' => DateHelper::getDateOfWeek(year(), $this->data['weekNumber']),
@@ -51,30 +59,56 @@ class ScheduleController extends Controller
     public function createFromOrder(CreateScheduleFromOrderRequest $request)
     {
         $validated = $request->validated();
+
         // delete all auto schedules for this order
-        Schedule::query()
-            ->where('order_id', $validated['order_id'])
-            ->where('manual', false)
-            ->delete();
+        if(isset($validated['delete_old_records'])) {
+            Schedule::query()
+                ->where('order_id', $validated['order_id'])
+                ->where('manual', false)
+                ->delete();
+        }
 
         // create all records in schedule
         $order = Order::query()
             ->where('id', $validated['order_id'])
             ->first();
 
+        if(empty($validated['skus'])) {
+            foreach ($order->products_sku as $psku)
+                $validated['skus'][] = $psku->id;
+        }
+
+        $mafs = [];
+        foreach ($validated['skus'] as $skuId) {
+            $sku = ProductSKU::query()->where('id', $skuId)->first();
+            if(!isset($mafs[$sku->product->article])) {
+                $mafs[$sku->product->article] = 1;
+            } else {
+                $mafs[$sku->product->article] += 1;
+            }
+        }
+        $mafsText = '';
+        $mafsCount = 0;
+        foreach ($mafs as $article => $count) {
+            $mafsText .= $article . ' - ' . $count . "\r\n";
+            $mafsCount += $count;
+        }
+
         for ($iDays = 1; $iDays < $order->install_days + 1; $iDays++) {
             $instDate = date('Y-m-d', strtotime('+' . $iDays - 1 . ' days', strtotime($order->installation_date)));
             Schedule::query()
                 ->create([
                     'order_id' => $validated['order_id'],
+                    'address_code' => $validated['order_id'],
+                    'source'    => 'Площадки',
                     'installation_date' => $instDate,
                     'manual' => false,
                     'district_id' => $order->district_id,
                     'area_id' => $order->area_id,
                     'object_address' => $order->object_address,
-                    'object_type_id' => $order->object_type_id,
-                    'mafs' => $order->productsWithCount,
-                    'mafs_count' => $order->products_sku()->count(),
+                    'object_type' => $order->objectType->name,
+                    'mafs' => $mafsText,
+                    'mafs_count' => $mafsCount,
                     'brigadier_id' => $order->brigadier_id,
                     'comment'   => $validated['comment'],
                 ]);
@@ -86,32 +120,28 @@ class ScheduleController extends Controller
     public function update(UpdateScheduleRequest $request)
     {
         $validated = $request->validated();
-        Schedule::query()
-            ->where('id', $validated['id'])
-            ->update($validated);
-        return redirect()->back();
-    }
 
-    public function create(CreateScheduleRequest $request)
-    {
-        $validated = $request->validated();
-        $order = Order::query()
-            ->where('id', $validated['order_id'])
-            ->first();
-        Schedule::query()
-            ->create([
-                'order_id' => $validated['order_id'],
-                'installation_date' => $validated['installation_date'],
-                'manual' => true,
-                'district_id' => $order->district_id,
-                'area_id' => $order->area_id,
-                'object_address' => $order->object_address,
-                'object_type_id' => $order->object_type_id,
-                'mafs' => $order->productsWithCount,
-                'mafs_count' => $order->products_sku()->count(),
-                'brigadier_id' => $order->brigadier_id,
-                'comment'   => $validated['comment'],
-            ]);
+        if(isset($validated['id'])) {
+            Schedule::query()
+                ->where('id', $validated['id'])
+                ->update($validated);
+        } else {
+            Schedule::query()
+                ->create([
+                    'address_code' => $validated['address_code'] ?? '-',
+                    'installation_date' => $validated['installation_date'],
+                    'manual' => true,
+                    'district_id' => $validated['district_id'],
+                    'area_id' => $validated['area_id'],
+                    'object_address' => $validated['object_address'],
+                    'object_type' => $validated['object_type'],
+                    'mafs' => $validated['mafs'],
+                    'mafs_count' => $validated['mafs_count'],
+                    'brigadier_id' => $validated['brigadier_id'],
+                    'comment'   => $validated['comment'],
+                ]);
+        }
+
         return redirect()->back();
     }
 

+ 4 - 2
app/Http/Requests/CreateScheduleFromOrderRequest.php

@@ -22,8 +22,10 @@ class CreateScheduleFromOrderRequest extends FormRequest
     public function rules(): array
     {
         return [
-            'order_id'  => 'required|exists:orders,id',
-            'comment'   => 'nullable|string',
+            'order_id'              => 'required|exists:orders,id',
+            'comment'               => 'nullable|string',
+            'skus'                  => 'nullable|array',
+            'delete_old_records'    => 'nullable|string',
         ];
     }
 }

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

@@ -1,30 +0,0 @@
-<?php
-
-namespace App\Http\Requests;
-
-use Illuminate\Foundation\Http\FormRequest;
-
-class CreateScheduleRequest 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<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
-     */
-    public function rules(): array
-    {
-        return [
-            'order_id'              => 'required|integer|exists:orders,id',
-            'installation_date'     => 'required|date',
-            'comment'               => 'nullable',
-        ];
-    }
-}

+ 9 - 1
app/Http/Requests/UpdateScheduleRequest.php

@@ -22,9 +22,17 @@ class UpdateScheduleRequest extends FormRequest
     public function rules(): array
     {
         return [
-            'id'                => 'required|exists:schedules,id',
+            'id'                => 'nullable|exists:schedules,id',
             'installation_date' => 'required|date',
             'comment'           => 'nullable|string',
+            'area_id'           => 'required|exists:areas,id',
+            'district_id'       => 'required|exists:districts,id',
+            'brigadier_id'      => 'required|exists:users,id',
+            'object_address'    =>  'required|string',
+            'object_type'       =>  'required|string',
+            'mafs'              => 'required|string',
+            'mafs_count'        => 'required|integer',
+            'address_code'      => 'nullable|string',
         ];
     }
 }

+ 0 - 1
app/Models/Order.php

@@ -259,7 +259,6 @@ class Order extends Model
         $closeTag = '</div>';
 
         foreach ($ret as $product) {
-
             $order_numbers = (isset($product['order_numbers'])) ? ' (' . implode(', ', array_unique($product['order_numbers'])) . ')' : '';
             $s .= $openTag . $product['name'] . ' - ' . $product['count'] . $order_numbers . $closeTag;
         }

+ 3 - 6
app/Models/Schedule.php

@@ -11,12 +11,14 @@ class Schedule extends Model
 {
     protected $fillable = [
         'installation_date',
+        'address_code',
         'manual',
+        'source',
         'order_id',
         'district_id',
         'area_id',
         'object_address',
-        'object_type_id',
+        'object_type',
         'mafs',
         'mafs_count',
         'brigadier_id',
@@ -33,11 +35,6 @@ class Schedule extends Model
         return $this->belongsTo(Area::class);
     }
 
-    public function objectType(): BelongsTo
-    {
-        return $this->belongsTo(ObjectType::class);
-    }
-
     public function brigadier(): BelongsTo
     {
         return $this->belongsTo(User::class, 'brigadier_id', 'id');

+ 4 - 2
database/migrations/2025_09_22_162208_create_schedules_table.php

@@ -15,11 +15,13 @@ return new class extends Migration
             $table->id();
             $table->date('installation_date');
             $table->boolean('manual')->default(false);
-            $table->foreignId('order_id')->constrained('orders')->cascadeOnDelete();
+            $table->foreignId('order_id')->nullable()->constrained('orders')->cascadeOnDelete();
             $table->foreignId('district_id')->constrained('districts')->cascadeOnDelete();
             $table->foreignId('area_id')->constrained('areas')->cascadeOnDelete();
             $table->text('object_address');
-            $table->foreignId('object_type_id')->constrained('object_types')->cascadeOnDelete();
+            $table->string('source')->default('Ручной');
+            $table->string('address_code')->nullable();
+            $table->string('object_type')->nullable();
             $table->text('mafs');
             $table->integer('mafs_count');
             $table->foreignId('brigadier_id')->constrained('users')->cascadeOnDelete();

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

@@ -116,8 +116,6 @@
 
         $('#district_id').on('change', function () {
             // load areas of selected district
-            console.log($(this).val());
-
             $.get('{{ route('area.ajax-get-areas-by-district') }}/' + $(this).val(),
                 function (data) {
                     $('#area_id').children().remove();

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

@@ -28,8 +28,8 @@
                 @if(in_array($order->order_status_id, [Order::STATUS_READY_TO_MOUNT, Order::STATUS_IN_MOUNT]) && $order->isAllMafConnected())
                     <a href="{{ route('order.generate-installation-pack', $order) }}"
                        class="btn btn-sm mb-1 btn-primary">Документы для монтажа</a>
-                        <button @disabled(is_null($order->brigadier_id)) class="btn btn-primary btn-sm mb-1" data-bs-toggle="modal"
-                                data-bs-target="#copySchedule">Перенести в график
+                        <button @disabled(is_null($order->brigadier_id)) class="btn btn-primary btn-sm mb-1"
+                                id="createScheduleButton">Перенести в график
                         </button>
                 @endif
                 @if($order->canCreateHandover())
@@ -299,12 +299,14 @@
                     <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
                 </div>
                 <div class="modal-body">
-                    <form action="{{ route('schedule.create-from-order') }}" method="post">
+                    <form action="{{ route('schedule.create-from-order') }}" method="post" id="scheduleCreateForm">
                         @csrf
                         <div>
                             <input type="hidden" name="order_id" value="{{ $order->id }}">
                             <textarea name="comment" placeholder="Комментарий для графика" class="form-control mb-3"></textarea>
-                            <button type="submit" class="btn btn-primary">Обновить график</button>
+                            <input type="checkbox" id="deleteOldRecords" name="delete_old_records" class="form-check-inline">
+                            <label for="deleteOldRecords" class="form-check-label mb-2">Удалить старые записи в графике для этой площадки?</label><br>
+                            <button type="submit" class="btn btn-primary btn-sm">Обновить график</button>
                         </div>
                     </form>
                 </div>
@@ -422,8 +424,22 @@
             }
         });
 
+        $('#createScheduleButton').on('click', function () {
+            let ids = Array();
+            $('.check-maf').each(function () {
+                if ($(this).prop('checked')) {
+                    ids.push($(this).attr('data-maf-id'));
+                    $('#scheduleCreateForm').append('<input type="hidden" name="skus[]" value="' + $(this).attr('data-maf-id') + '">');
+                }
+            });
+
+            let myModalSchedule = new bootstrap.Modal(document.getElementById("copySchedule"), {});
+            myModalSchedule.show();
+        });
+
         $('#ttnBtn').on('click', function () {
             if ($('input.check-maf:checkbox:checked').length > 0) {
+
                 let myModalTtn = new bootstrap.Modal(document.getElementById("createTtnModal"), {});
                 myModalTtn.show();
             } else {

+ 104 - 42
resources/views/schedule/index.blade.php

@@ -76,19 +76,24 @@
                         @foreach($schs as $schedule)
                             {!! (!$loop->first) ? '<tr>':'' !!}
                             <td style="background: {{ $schedule->brigadier->color }}"
-                                class="align-middle">{{ $schedule->order_id }}</td>
+                                class="align-middle code-{{ $schedule->id }}">{{ $schedule->address_code }}</td>
                             <td style="background: {{ $schedule->brigadier->color }}"
                                 class="align-middle">{{ $schedule->district->shortname }}</td>
                             <td style="background: {{ $schedule->brigadier->color }}"
                                 class="align-middle">{{ $schedule->area->name }}</td>
+                            <td style="background: {{ $schedule->brigadier->color }}" class="align-middle">
+                                @if($schedule->order_id)
+                                <a href="{{ route('order.show', $schedule->order_id) }}">{{ $schedule->object_address }}</a>
+                                @else
+                                    {{ $schedule->object_address }}
+                                @endif
+                            </td>
                             <td style="background: {{ $schedule->brigadier->color }}"
-                                class="align-middle">{{ $schedule->object_address }}</td>
-                            <td style="background: {{ $schedule->brigadier->color }}"
-                                class="align-middle">{{ $schedule->objectType->name }}</td>
+                                class="align-middle object-type-{{ $schedule->id }}">{{ $schedule->object_type }}</td>
                             <td style="background: {{ $schedule->brigadier->color }}"
-                                class="align-middle">{!! $schedule->mafs !!}</td>
+                                class="align-middle mafs-{{ $schedule->id }}">{!! nl2br($schedule->mafs) !!}</td>
                             <td style="background: {{ $schedule->brigadier->color }}"
-                                class="align-middle">{{ $schedule->mafs_count }}</td>
+                                class="align-middle  mafs-count-{{ $schedule->id }}">{{ $schedule->mafs_count }}</td>
                             <td style="background: {{ $schedule->brigadier->color }}"
                                 class="align-middle">{{ $schedule->brigadier->name }}</td>
                             <td style="background: {{ $schedule->brigadier->color }}"
@@ -96,6 +101,10 @@
                             <td style="background: {{ $schedule->brigadier->color }}" class="align-middle">
                                 <i class="bi bi-pencil p-1 m-1 cursor-pointer text-primary editSchedule"
                                    data-schedule-date="{{ $schedule->installation_date }}"
+                                   data-schedule-address="{{ $schedule->object_address }}"
+                                   data-schedule-district="{{ $schedule->district_id }}"
+                                   data-schedule-brigadier="{{ $schedule->brigadier_id }}"
+                                   data-schedule-area="{{ $schedule->area_id }}"
                                    data-schedule-id="{{ $schedule->id }}"></i>
                                 <i class="bi bi-trash text-danger p-1 m-1 deleteSchedule"
                                    data-schedule-id="{{ $schedule->id }}"></i>
@@ -123,7 +132,7 @@
             <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>
+                        <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">
@@ -131,11 +140,19 @@
                             @csrf
                             <input type="hidden" name="id" value="0">
                             <div>
-                                <input type="date" name="installation_date" value=""
-                                       class="form-control form-control-sm mb-3">
-                                <textarea name="comment" placeholder="Комментарий для графика"
-                                          class="form-control form-control-sm mb-3"></textarea>
-                                <button type="submit" class="btn btn-primary btn-sm">Обновить</button>
+                                @include('partials.input',  ['name' => 'installation_date', 'title' => 'Дата монтажа'])
+                                @include('partials.input',  ['name' => 'address_code', 'title' => 'Код адреса'])
+                                @include('partials.select', ['name' => 'district_id', 'title' => 'Округ', 'options' => $districts, 'first_empty' => true, 'required' => true])
+                                @include('partials.select', ['name' => 'area_id', 'title' => 'Район', 'options' => $areas, 'required' => true, 'first_empty' => true])
+                                @include('partials.input',  ['name' => 'object_address', 'title' => 'Адрес'])
+                                @include('partials.input',  ['name' => 'object_type', 'title' => 'Тип объекта'])
+                                @include('partials.textarea', ['name' => 'mafs', 'title' => 'МАФы'])
+                                @include('partials.input',  ['name' => 'mafs_count', 'title' => 'Кол-во МАФ'])
+                                @include('partials.select', ['name' => 'brigadier_id', 'title' => 'Бригадир', 'options' => $brigadiers, 'required' => true, 'first_empty' => true])
+                                @include('partials.textarea', ['name' => 'comment', 'title' => 'Комментарий'])
+                                <div class="text-center">
+                                    <button type="submit" class="btn btn-primary btn-sm">Сохранить</button>
+                                </div>
                             </div>
                         </form>
                     </div>
@@ -144,32 +161,35 @@
         </div>
 
         <!-- Модальное окно создания графика -->
-        <div class="modal fade" id="createSchedule" 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('schedule.create') }}" method="post" id="scheduleCreateForm">
-                            @csrf
-                            <input type="text" class="form-control mb-2" placeholder="Поиск площадки" id="search_order">
-                            <select id="select_order" name="order_id" class="form-select mb-3" size="7" multiple
-                                    required></select>
-                            <div>
-                                <input type="date" name="installation_date" value=""
-                                       class="form-control form-control-sm mb-3">
-                                <textarea name="comment" placeholder="Комментарий для графика"
-                                          class="form-control form-control-sm mb-3"></textarea>
-                                <button type="submit" class="btn btn-primary btn-sm">Создать</button>
-                            </div>
-                        </form>
-                    </div>
-                </div>
-            </div>
-        </div>
+{{--        <div class="modal fade" id="createSchedule" 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('schedule.create') }}" method="post" id="scheduleCreateForm">--}}
+{{--                            @csrf--}}
+{{--                            @include('partials.input',  ['name' => 'installation_date', 'title' => 'Дата монтажа'])--}}
+{{--                            @include('partials.input',  ['name' => 'address_code', 'title' => 'Код адреса'])--}}
+{{--                            @include('partials.select', ['name' => 'district_id', 'title' => 'Округ', 'options' => $districts, 'first_empty' => true, 'required' => true])--}}
+{{--                            @include('partials.select', ['name' => 'area_id', 'title' => 'Район', 'options' => $areas, 'required' => true, 'first_empty' => true])--}}
+{{--                            @include('partials.input',  ['name' => 'object_address', 'title' => 'Адрес'])--}}
+{{--                            @include('partials.input',  ['name' => 'object_type', 'title' => 'Тип объекта'])--}}
+{{--                            @include('partials.textarea', ['name' => 'mafs', 'title' => 'МАФы'])--}}
+{{--                            @include('partials.input',  ['name' => 'mafs_count', 'title' => 'Кол-во МАФ'])--}}
+{{--                            @include('partials.select', ['name' => 'brigadier_id', 'title' => 'Бригадир', 'options' => $brigadiers, 'required' => true, 'first_empty' => true])--}}
+{{--                            @include('partials.textarea', ['name' => 'comment', 'title' => 'Комментарий'])--}}
+{{--                            <div class="text-center">--}}
+{{--                                <button type="submit" class="btn btn-primary btn-sm">Сохранить</button>--}}
+{{--                            </div>--}}
+{{--                        </form>--}}
+{{--                    </div>--}}
+{{--                </div>--}}
+{{--            </div>--}}
+{{--        </div>--}}
 
 
         @if($errors->any())
@@ -183,10 +203,28 @@
         $('.editSchedule').on('click', function () {
             let scheduleId = $(this).attr('data-schedule-id');
             let scheduleDate = $(this).attr('data-schedule-date');
+            let scheduleDistrict = $(this).attr('data-schedule-district');
+            let scheduleArea = $(this).attr('data-schedule-area');
+            let scheduleBrigadier = $(this).attr('data-schedule-brigadier');
+            let scheduleAddress = $(this).attr('data-schedule-address');
             let scheduleComment = $('.comment-' + scheduleId).text();
+            let scheduleMafs = $('.mafs-' + scheduleId).text();
+            let scheduleObjectType = $('.object-type-' + scheduleId).text();
+            let scheduleMafsCount = $('.mafs-count-' + scheduleId).text();
+            let scheduleCode = $('.code-' + scheduleId).text();
+            console.log(scheduleId, scheduleDate, scheduleDistrict, $(this).attr('data-schedule-brigadier'));
             $('form#scheduleEditForm input[name=id]').val(scheduleId);
+            $('form#scheduleEditForm input[name=object_address]').val(scheduleAddress);
+            $('form#scheduleEditForm input[name=object_type]').val(scheduleObjectType);
             $('form#scheduleEditForm input[name=installation_date]').val(scheduleDate);
-            $('form#scheduleEditForm textarea').text(scheduleComment);
+            $('form#scheduleEditForm select[name=district_id]').val(scheduleDistrict);
+            $('form#scheduleEditForm select[name=area_id]').val(scheduleArea);
+            $('form#scheduleEditForm select[name=brigadier_id]').val(scheduleBrigadier);
+            $('form#scheduleEditForm textarea[name=comment]').text(scheduleComment);
+            $('form#scheduleEditForm textarea[name=mafs]').text(scheduleMafs);
+            $('form#scheduleEditForm input[name=mafs_count]').val(scheduleMafsCount);
+            $('form#scheduleEditForm input[name=address_code]').val(scheduleCode);
+
             let myModalEditSchedule = new bootstrap.Modal(document.getElementById("copySchedule"), {});
             myModalEditSchedule.show();
         });
@@ -202,10 +240,19 @@
         $('.createSchedule').on('click', function () {
             let scheduleDate = $(this).attr('data-schedule-date');
 
-            $('form#scheduleCreateForm input[name=installation_date]').val(scheduleDate);
-            $('form#scheduleCreateForm textarea').text('');
+            $('form#scheduleEditForm input[name=id]').val('');
+            $('form#scheduleEditForm input[name=object_address]').val('');
+            $('form#scheduleEditForm input[name=object_type]').val('');
+            $('form#scheduleEditForm input[name=installation_date]').val(scheduleDate);
+            $('form#scheduleEditForm select[name=district_id]').val('');
+            $('form#scheduleEditForm select[name=area_id]').val('');
+            $('form#scheduleEditForm select[name=brigadier_id]').val('');
+            $('form#scheduleEditForm textarea[name=comment]').text('');
+            $('form#scheduleEditForm textarea[name=mafs]').text('');
+            $('form#scheduleEditForm input[name=mafs_count]').val('');
+            $('form#scheduleEditForm input[name=address_code]').val('');
 
-            let myModalCreateSchedule = new bootstrap.Modal(document.getElementById("createSchedule"), {});
+            let myModalCreateSchedule = new bootstrap.Modal(document.getElementById("copySchedule"), {});
             myModalCreateSchedule.show();
         });
 
@@ -221,6 +268,21 @@
                 }
             );
         }).trigger('keyup');
+
+
+        $('#district_id').on('change', function () {
+            // load areas of selected district
+            $.get('{{ route('area.ajax-get-areas-by-district') }}/' + $(this).val(),
+                function (data) {
+                    $('#area_id').children().remove();
+                    $.each(data, function (id, name) {
+                        $('#area_id').append('<option value=\'' + id + '\'>' + name + '</option>');
+                    });
+                }
+            );
+        });
+
+
     </script>
     <script type="text/javascript">
         function getWeekNumber(d) {

+ 0 - 1
routes/web.php

@@ -148,7 +148,6 @@ Route::middleware('auth:web')->group(function () {
     Route::get('schedule', [ScheduleController::class, 'index'])->name('schedule.index');
     Route::post('schedule/create_from_order', [ScheduleController::class, 'createFromOrder'])->name('schedule.create-from-order');
     Route::post('schedule/update', [ScheduleController::class, 'update'])->name('schedule.update');
-    Route::post('schedule/create', [ScheduleController::class, 'create'])->name('schedule.create');
     Route::delete('schedule/delete/{schedule}', [ScheduleController::class, 'delete'])->name('schedule.delete');
 
     // ajax search products