edit.blade.php 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. @extends('layouts.app')
  2. @section('content')
  3. <div class="px-3">
  4. <div class="row">
  5. <div class="col-xl-6">
  6. <h4>Рекламация</h4>
  7. </div>
  8. <div class="col-xl-6 text-end mb-2">
  9. @if(hasRole('admin') && !is_null($reclamation->brigadier_id) && !is_null($reclamation->start_work_date))
  10. <button class="btn btn-sm btn-primary" id="createScheduleButton">Перенести в график</button>
  11. @endif
  12. @if(hasRole('admin,manager'))
  13. <a href="{{ route('order.generate-reclamation-pack', $reclamation) }}"
  14. class="btn btn-primary btn-sm">Пакет документов рекламации</a>
  15. <a href="{{ route('reclamation.generate-reclamation-payment-pack', $reclamation) }}"
  16. class="btn btn-primary btn-sm">Пакет документов на оплату</a>
  17. @endif
  18. @if(hasRole('admin'))
  19. <a href="#" onclick="if(confirm('Удалить рекламацию?')) $('form#destroy').submit();"
  20. class="btn btn-sm btn-danger">Удалить</a>
  21. <form action="{{ route('reclamations.delete', $reclamation) }}" method="post" class="d-none" id="destroy">
  22. @csrf
  23. @method('DELETE')
  24. </form>
  25. @endif
  26. </div>
  27. </div>
  28. <div class="row">
  29. <div class="col-xl-5 border-end mb-3 mb-xl-0">
  30. <form action="{{ route('reclamations.update', $reclamation) }}" method="post">
  31. @csrf
  32. <input type="hidden" id="order_id" name="order_id" value="{{ $reclamation->order_id}}">
  33. <input type="hidden" name="previous_url" value="{{ $previous_url ?? '' }}">
  34. @include('partials.link', ['title' => 'Площадка', 'href' => route('order.show', $reclamation->order_id), 'text' => $reclamation->order->common_name ?? ''])
  35. @include('partials.select', ['name' => 'status_id', 'title' => 'Статус', 'options' => $statuses, 'value' => $reclamation->status_id ?? old('status_id'), 'disabled' => !hasRole('admin,manager')])
  36. @include('partials.select', ['name' => 'user_id', 'title' => 'Менеджер', 'options' => $users, 'value' => $reclamation->user_id ?? old('user_id') ?? auth()->user()->id, 'disabled' => !hasRole('admin,manager')])
  37. @include('partials.input', ['name' => 'maf_installation_year', 'title' => 'Год установки МАФ', 'type' => 'text', 'value' => $reclamation->order->year, 'disabled' => true])
  38. @include('partials.input', ['name' => 'create_date', 'title' => 'Дата создания', 'type' => 'date', 'required' => true, 'value' => $reclamation->create_date ?? date('Y-m-d'), 'disabled' => !hasRole('admin,manager')])
  39. @include('partials.input', ['name' => 'finish_date', 'title' => 'Дата завершения', 'type' => 'date', 'required' => true, 'value' => $reclamation->finish_date ?? date('Y-m-d', strtotime('+30 days')), 'disabled' => !hasRole('admin,manager')])
  40. @include('partials.select', ['name' => 'brigadier_id', 'title' => 'Бригадир', 'options' => $brigadiers, 'value' => $reclamation->brigadier_id ?? old('brigadier_id'), 'disabled' => !hasRole('admin,manager'), 'first_empty' => true])
  41. @include('partials.input', ['name' => 'start_work_date', 'title' => 'Дата начала работ', 'type' => 'date', 'value' => $reclamation->start_work_date, 'disabled' => !hasRole('admin,manager')])
  42. @include('partials.input', ['name' => 'work_days', 'title' => 'Срок работ, дней', 'type' => 'number', 'min' => 1, 'value' => $reclamation->work_days, 'disabled' => !hasRole('admin,manager')])
  43. @include('partials.select', ['name' => 'reason', 'title' => 'Причина', 'size' => 6, 'value' => $reclamation->reason ?? '', 'options' => ['Вандализм', 'Гарантия', 'Сервисное обслуживание'], 'key_as_val' => true, 'disabled' => !hasRole('admin,manager')])
  44. @include('partials.input', ['name' => 'factory_reclamation_number', 'title' => '№ рекламации на фабрике', 'type' => 'text', 'value' => $reclamation->factory_reclamation_number ?? '', 'disabled' => !hasRole('admin,manager')])
  45. @include('partials.textarea', ['name' => 'guarantee', 'title' => 'Гарантии', 'size' => 6, 'value' => $reclamation->guarantee ?? '', 'disabled' => !hasRole('admin,manager')])
  46. @include('partials.textarea', ['name' => 'whats_done', 'title' => 'Что сделано', 'size' => 6, 'value' => $reclamation->whats_done ?? '', 'disabled' => !hasRole('admin,manager')])
  47. @include('partials.textarea', ['name' => 'comment', 'title' => 'Комментарий', 'size' => 6, 'value' => $reclamation->comment ?? '', 'disabled' => !hasRole('admin,manager')])
  48. @include('partials.submit', ['name' => 'Сохранить', 'offset' => 5, 'disabled' => !hasRole('admin,manager'), 'backurl' => route('reclamations.index', session('gp_reclamations'))])
  49. </form>
  50. </div>
  51. <div class="col-xl-7 ">
  52. <div class="col-12 overflow-x-scroll">
  53. <table class="table">
  54. <thead>
  55. <tr>
  56. <th>Картинка</th>
  57. <th>МАФ</th>
  58. <th>Тип</th>
  59. <th>Номер заказа МАФ</th>
  60. <th>RFID</th>
  61. <th>Заводской номер</th>
  62. <th>Дата производства</th>
  63. </tr>
  64. </thead>
  65. <tbody>
  66. @foreach($reclamation->skus as $p)
  67. <tr>
  68. <td>
  69. @if($p->product->image)
  70. <a href="{{ $p->product->image }}" data-toggle="lightbox" data-gallery="maf"
  71. data-size="fullscreen">
  72. <img src="{{ $p->product->image }}" alt="" class="img-thumbnail maf-img">
  73. </a>
  74. @endif
  75. </td>
  76. <td>
  77. @if(hasRole('admin,manager'))
  78. <a href="{{ route('product_sku.show', $p) }}">
  79. {!! $p->product->article !!}
  80. </a>
  81. <br>
  82. <a class="small" href="{{ route('catalog.show', $p->product) }}">каталог</a>
  83. @endif
  84. </td>
  85. <td>{!! $p->product->nomenclature_number !!}</td>
  86. <td>
  87. @if($p->maf_order_id && hasRole('admin,manager'))
  88. <a href="{{ route('maf_order.show', $p->maf_order) }}">{{ $p->maf_order->order_number }}</a>
  89. @endif
  90. </td>
  91. <td>{{ $p->rfid }}</td>
  92. <td>{{ $p->factory_number }}</td>
  93. <td>{{ $p->manufacture_date }}</td>
  94. </tr>
  95. @endforeach
  96. </tbody>
  97. </table>
  98. </div>
  99. <div class="spare-parts">
  100. @php
  101. $activeReservationsCount = $reclamation->activeReservations()->count();
  102. $openShortagesCount = $reclamation->openShortages()->count();
  103. @endphp
  104. <a href="#spare_parts" data-bs-toggle="collapse">
  105. Запчасти ({{ $reclamation->spareParts->count() }})
  106. @if($activeReservationsCount > 0)
  107. <span class="badge bg-warning" title="Активных резервов">{{ $activeReservationsCount }} резерв</span>
  108. @endif
  109. @if($openShortagesCount > 0)
  110. <span class="badge bg-danger" title="Открытых дефицитов">{{ $openShortagesCount }} дефицит</span>
  111. @endif
  112. </a>
  113. <form method="post" action="{{ route('reclamations.update-spare-parts', $reclamation) }}"
  114. class="my-2 collapse" id="spare_parts">
  115. @csrf
  116. <div class="spare-parts-rows">
  117. @forelse($reclamation->spareParts as $idx => $sp)
  118. <div class="row mb-1 spare-part-row" data-index="{{ $idx }}">
  119. <div class="col-6 position-relative">
  120. <input type="hidden" name="rows[{{ $idx }}][spare_part_id]" value="{{ $sp->id }}" class="spare-part-id">
  121. <input type="text" class="form-control form-control-sm spare-part-search"
  122. value="{{ $sp->article }}@if($sp->used_in_maf) ({{ $sp->used_in_maf }})@endif"
  123. placeholder="Введите артикул или название"
  124. autocomplete="off"
  125. @disabled(!hasRole('admin,manager'))>
  126. <div class="spare-part-dropdown"></div>
  127. </div>
  128. <div class="col-2">
  129. <input type="number" name="rows[{{ $idx }}][quantity]" value="{{ $sp->pivot->quantity }}"
  130. min="0" class="form-control form-control-sm text-end"
  131. @disabled(!hasRole('admin,manager'))
  132. placeholder="кол-во">
  133. </div>
  134. <div class="col-3">
  135. <div class="form-check form-check-inline mt-1">
  136. <input type="hidden" name="rows[{{ $idx }}][with_documents]" value="0">
  137. <input type="checkbox" name="rows[{{ $idx }}][with_documents]" value="1"
  138. class="form-check-input" id="with_docs_{{ $idx }}"
  139. @checked($sp->pivot->with_documents)
  140. @disabled(!hasRole('admin,manager'))>
  141. <label class="form-check-label small" for="with_docs_{{ $idx }}">с док.</label>
  142. </div>
  143. </div>
  144. <div class="col-1">
  145. <span class="btn btn-sm text-danger remove-spare-part-row" title="Удалить строку">
  146. <i class="bi bi-x-circle"></i>
  147. </span>
  148. </div>
  149. </div>
  150. @empty
  151. <div class="row mb-1 spare-part-row" data-index="0">
  152. <div class="col-6 position-relative">
  153. <input type="hidden" name="rows[0][spare_part_id]" value="" class="spare-part-id">
  154. <input type="text" class="form-control form-control-sm spare-part-search"
  155. value=""
  156. placeholder="Введите артикул или название"
  157. autocomplete="off"
  158. @disabled(!hasRole('admin,manager'))>
  159. <div class="spare-part-dropdown"></div>
  160. </div>
  161. <div class="col-2">
  162. <input type="number" name="rows[0][quantity]" value=""
  163. min="0" class="form-control form-control-sm text-end"
  164. @disabled(!hasRole('admin,manager'))
  165. placeholder="кол-во">
  166. </div>
  167. <div class="col-3">
  168. <div class="form-check form-check-inline mt-1">
  169. <input type="hidden" name="rows[0][with_documents]" value="0">
  170. <input type="checkbox" name="rows[0][with_documents]" value="1"
  171. class="form-check-input" id="with_docs_0"
  172. @disabled(!hasRole('admin,manager'))>
  173. <label class="form-check-label small" for="with_docs_0">с док.</label>
  174. </div>
  175. </div>
  176. <div class="col-1">
  177. <span class="btn btn-sm text-danger remove-spare-part-row" title="Удалить строку">
  178. <i class="bi bi-x-circle"></i>
  179. </span>
  180. </div>
  181. </div>
  182. @endforelse
  183. </div>
  184. <div class="row mb-1 spare-part-row spare-part-template d-none" data-index="__INDEX__">
  185. <div class="col-6 position-relative">
  186. <input type="hidden" name="rows[__INDEX__][spare_part_id]" value="" class="spare-part-id">
  187. <input type="text" class="form-control form-control-sm spare-part-search"
  188. value=""
  189. placeholder="Введите артикул или название"
  190. autocomplete="off"
  191. disabled>
  192. <div class="spare-part-dropdown"></div>
  193. </div>
  194. <div class="col-2">
  195. <input type="number" name="rows[__INDEX__][quantity]" value=""
  196. min="0" class="form-control form-control-sm text-end" disabled
  197. placeholder="кол-во">
  198. </div>
  199. <div class="col-3">
  200. <div class="form-check form-check-inline mt-1">
  201. <input type="hidden" name="rows[__INDEX__][with_documents]" value="0">
  202. <input type="checkbox" name="rows[__INDEX__][with_documents]" value="1"
  203. class="form-check-input" disabled>
  204. <label class="form-check-label small">с док.</label>
  205. </div>
  206. </div>
  207. <div class="col-1">
  208. <span class="btn btn-sm text-danger remove-spare-part-row" title="Удалить строку">
  209. <i class="bi bi-x-circle"></i>
  210. </span>
  211. </div>
  212. </div>
  213. <div class="row">
  214. <div class="col-12 text-end">
  215. <span class="btn btn-light btn-sm cursor-pointer" id="add-spare-part-row"
  216. @disabled(!hasRole('admin,manager'))>Добавить строку</span>
  217. <button class="btn btn-primary btn-sm" type="submit" @disabled(!hasRole('admin,manager'))>Сохранить запчасти</button>
  218. </div>
  219. </div>
  220. @if($errors->any())
  221. @dump($errors->all())
  222. @endif
  223. </form>
  224. {{-- Резервы и дефициты --}}
  225. @php
  226. $reservations = $reclamation->sparePartReservations()
  227. ->with('sparePart', 'sparePartOrder')
  228. ->orderByDesc('created_at')
  229. ->get();
  230. $shortages = $reclamation->sparePartShortages()
  231. ->with('sparePart')
  232. ->orderByDesc('created_at')
  233. ->get();
  234. @endphp
  235. @if($reservations->count() > 0 || $shortages->count() > 0)
  236. <div class="mt-3 p-2 border rounded bg-light">
  237. {{-- Активные резервы --}}
  238. @if($reservations->where('status', 'active')->count() > 0)
  239. <div class="mb-3">
  240. <strong class="text-warning"><i class="bi bi-bookmark-fill"></i> Активные резервы</strong>
  241. <table class="table table-sm table-striped mt-1 mb-0">
  242. <thead>
  243. <tr>
  244. <th>Запчасть</th>
  245. <th class="text-center">Кол-во</th>
  246. <th class="text-center">С док.</th>
  247. <th>Партия</th>
  248. @if(hasRole('admin,manager'))
  249. <th></th>
  250. @endif
  251. </tr>
  252. </thead>
  253. <tbody>
  254. @foreach($reservations->where('status', 'active') as $reservation)
  255. <tr>
  256. <td>
  257. @if($reservation->sparePart)
  258. <a href="{{ route('spare_parts.show', $reservation->sparePart->id) }}">
  259. {{ $reservation->sparePart->article }}
  260. </a>
  261. @else
  262. -
  263. @endif
  264. </td>
  265. <td class="text-center">{{ $reservation->reserved_qty }}</td>
  266. <td class="text-center">
  267. @if($reservation->with_documents)
  268. <i class="bi bi-check-circle text-success"></i>
  269. @else
  270. <i class="bi bi-x-circle text-muted"></i>
  271. @endif
  272. </td>
  273. <td>
  274. @if($reservation->sparePartOrder)
  275. <a href="{{ route('spare_part_orders.show', $reservation->sparePartOrder->id) }}">
  276. #{{ $reservation->sparePartOrder->id }}
  277. </a>
  278. @else
  279. -
  280. @endif
  281. </td>
  282. @if(hasRole('admin,manager'))
  283. <td class="text-end">
  284. <form action="{{ route('spare_part_reservations.issue', $reservation) }}" method="POST" class="d-inline">
  285. @csrf
  286. <button type="submit" class="btn btn-sm btn-success" title="Списать">
  287. <i class="bi bi-check-lg"></i>
  288. </button>
  289. </form>
  290. <form action="{{ route('spare_part_reservations.cancel', $reservation) }}" method="POST" class="d-inline">
  291. @csrf
  292. <button type="submit" class="btn btn-sm btn-outline-warning" title="Отменить резерв">
  293. <i class="bi bi-x-lg"></i>
  294. </button>
  295. </form>
  296. </td>
  297. @endif
  298. </tr>
  299. @endforeach
  300. </tbody>
  301. </table>
  302. @if(hasRole('admin,manager') && $reservations->where('status', 'active')->count() > 1)
  303. <div class="text-end mt-1">
  304. <form action="{{ route('spare_part_reservations.issue_all', $reclamation->id) }}" method="POST" class="d-inline">
  305. @csrf
  306. <button type="submit" class="btn btn-sm btn-success">Списать все</button>
  307. </form>
  308. <form action="{{ route('spare_part_reservations.cancel_all', $reclamation->id) }}" method="POST" class="d-inline">
  309. @csrf
  310. <button type="submit" class="btn btn-sm btn-outline-warning">Отменить все резервы</button>
  311. </form>
  312. </div>
  313. @endif
  314. </div>
  315. @endif
  316. {{-- Списанные --}}
  317. @if($reservations->where('status', 'issued')->count() > 0)
  318. <div class="mb-3">
  319. <strong class="text-success"><i class="bi bi-check-circle-fill"></i> Списано</strong>
  320. <table class="table table-sm table-success mt-1 mb-0">
  321. <thead>
  322. <tr>
  323. <th>Запчасть</th>
  324. <th class="text-center">Кол-во</th>
  325. <th class="text-center">С док.</th>
  326. <th>Партия</th>
  327. <th>Дата</th>
  328. </tr>
  329. </thead>
  330. <tbody>
  331. @foreach($reservations->where('status', 'issued') as $reservation)
  332. <tr>
  333. <td>
  334. @if($reservation->sparePart)
  335. <a href="{{ route('spare_parts.show', $reservation->sparePart->id) }}">
  336. {{ $reservation->sparePart->article }}
  337. </a>
  338. @else
  339. -
  340. @endif
  341. </td>
  342. <td class="text-center">{{ $reservation->reserved_qty }}</td>
  343. <td class="text-center">
  344. @if($reservation->with_documents)
  345. <i class="bi bi-check-circle text-success"></i>
  346. @else
  347. <i class="bi bi-x-circle text-muted"></i>
  348. @endif
  349. </td>
  350. <td>
  351. @if($reservation->sparePartOrder)
  352. <a href="{{ route('spare_part_orders.show', $reservation->sparePartOrder->id) }}">
  353. #{{ $reservation->sparePartOrder->id }}
  354. </a>
  355. @else
  356. -
  357. @endif
  358. </td>
  359. <td>{{ $reservation->updated_at->format('d.m.Y H:i') }}</td>
  360. </tr>
  361. @endforeach
  362. </tbody>
  363. </table>
  364. </div>
  365. @endif
  366. {{-- Открытые дефициты --}}
  367. @if($shortages->where('status', 'open')->count() > 0)
  368. <div class="mb-3">
  369. <strong class="text-danger"><i class="bi bi-exclamation-triangle-fill"></i> Дефициты (нехватка)</strong>
  370. <table class="table table-sm table-danger mt-1 mb-0">
  371. <thead>
  372. <tr>
  373. <th>Запчасть</th>
  374. <th class="text-center">Требуется</th>
  375. <th class="text-center">Зарезервировано</th>
  376. <th class="text-center">Не хватает</th>
  377. <th class="text-center">С док.</th>
  378. </tr>
  379. </thead>
  380. <tbody>
  381. @foreach($shortages->where('status', 'open') as $shortage)
  382. <tr>
  383. <td>
  384. @if($shortage->sparePart)
  385. <a href="{{ route('spare_parts.show', $shortage->sparePart->id) }}">
  386. {{ $shortage->sparePart->article }}
  387. </a>
  388. @else
  389. -
  390. @endif
  391. </td>
  392. <td class="text-center">{{ $shortage->required_qty }}</td>
  393. <td class="text-center">{{ $shortage->reserved_qty }}</td>
  394. <td class="text-center fw-bold">{{ $shortage->missing_qty }}</td>
  395. <td class="text-center">
  396. @if($shortage->with_documents)
  397. <i class="bi bi-check-circle text-success"></i>
  398. @else
  399. <i class="bi bi-x-circle text-muted"></i>
  400. @endif
  401. </td>
  402. </tr>
  403. @endforeach
  404. </tbody>
  405. </table>
  406. </div>
  407. @endif
  408. </div>
  409. @endif
  410. </div>
  411. <hr>
  412. <div class="documents">
  413. Документы
  414. @if(hasRole('admin,manager'))
  415. <button class="btn btn-sm text-success" onclick="$('#upl-documents').trigger('click');"><i
  416. class="bi bi-plus-circle-fill"></i> Загрузить
  417. </button>
  418. <form action="{{ route('reclamations.upload-document', $reclamation) }}"
  419. enctype="multipart/form-data" method="post" class="visually-hidden">
  420. @csrf
  421. <input required type="file" id="upl-documents" onchange="$(this).parent().submit()" multiple
  422. name="document[]" class="form-control form-control-sm">
  423. </form>
  424. @endif
  425. <div class="row my-2 g-1">
  426. @foreach($reclamation->documents as $document)
  427. <div class="col-12">
  428. <a href="{{ $document->link }}" target="_blank">
  429. {{ $document->original_name }}
  430. </a>
  431. @if(hasRole('admin'))
  432. <i class="bi bi-x-circle-fill fs-6 text-danger cursor-pointer ms-2"
  433. onclick="if(confirm('Удалить?')) $('#document-{{ $document->id }}').submit()"
  434. title="Удалить"></i>
  435. @endif
  436. <form action="{{ route('reclamations.delete-document', [$reclamation, $document]) }}"
  437. method="POST" id="document-{{ $document->id }}" class="visually-hidden">
  438. @csrf
  439. @method('DELETE')
  440. </form>
  441. </div>
  442. @endforeach
  443. </div>
  444. </div>
  445. <hr>
  446. <div class="acts">
  447. Акты
  448. @if(hasRole('admin,manager'))
  449. <button class="btn btn-sm text-success" onclick="$('#upl-acts').trigger('click');"><i
  450. class="bi bi-plus-circle-fill"></i> Загрузить
  451. </button>
  452. <form action="{{ route('reclamations.upload-act', $reclamation) }}" enctype="multipart/form-data"
  453. method="post" class="visually-hidden">
  454. @csrf
  455. <input required type="file" id="upl-acts" onchange="$(this).parent().submit()" multiple
  456. name="acts[]" class="form-control form-control-sm">
  457. </form>
  458. @endif
  459. <div class="row my-2 g-1">
  460. @foreach($reclamation->acts as $act)
  461. <div class="col-12">
  462. <a href="{{ $act->link }}" target="_blank">
  463. {{ $act->original_name }}
  464. </a>
  465. @if(hasRole('admin'))
  466. <i class="bi bi-x-circle-fill fs-6 text-danger cursor-pointer ms-2"
  467. onclick="if(confirm('Удалить?')) $('#act-{{ $act->id }}').submit()"
  468. title="Удалить"></i>
  469. <form action="{{ route('reclamations.delete-act', [$reclamation, $act]) }}"
  470. method="POST"
  471. id="act-{{ $act->id }}" class="visually-hidden">
  472. @csrf
  473. @method('DELETE')
  474. </form>
  475. @endif
  476. </div>
  477. @endforeach
  478. </div>
  479. </div>
  480. <hr>
  481. <div class="photo_before">
  482. <a href="#photos_before" data-bs-toggle="collapse">Фотографии проблемы
  483. ({{ $reclamation->photos_before->count() }})</a>
  484. <button class="btn btn-sm text-success" onclick="$('#upl-photo-before').trigger('click');"><i
  485. class="bi bi-plus-circle-fill"></i> Загрузить
  486. </button>
  487. @if($reclamation->photos_before->count())
  488. <a href="{{ route('reclamation.generate-photos-before-pack', $reclamation) }}"
  489. class="btn btn-sm text-primary"><i
  490. class="bi bi-download"></i> Скачать все
  491. </a>
  492. @endif
  493. <form action="{{ route('reclamations.upload-photo-before', $reclamation) }}"
  494. enctype="multipart/form-data" method="post" class="visually-hidden">
  495. @csrf
  496. <input required type="file" id="upl-photo-before" onchange="$(this).parent().submit()" multiple
  497. name="photo[]" class="form-control form-control-sm" accept=".jpg,.jpeg,.png">
  498. </form>
  499. <div class="row my-2 g-1 collapse" id="photos_before">
  500. @foreach($reclamation->photos_before as $photo)
  501. <div class="col-4">
  502. <a href="{{ $photo->link }}"
  503. data-toggle="lightbox" data-gallery="photos-before" data-size="fullscreen">
  504. <img class="img-thumbnail" src="{{ $photo->link }}" alt="">
  505. </a>
  506. @if(hasRole('admin'))
  507. <i class="bi bi-x-circle-fill fs-6 text-danger cursor-pointer rm-but"
  508. onclick="if(confirm('Удалить фото?')) $('#photo-{{ $photo->id }}').submit()"
  509. title="Удалить"></i>
  510. @endif
  511. <form action="{{ route('reclamations.delete-photo-before', [$reclamation, $photo]) }}"
  512. method="POST" id="photo-{{ $photo->id }}" class="visually-hidden">
  513. @csrf
  514. @method('DELETE')
  515. </form>
  516. </div>
  517. @endforeach
  518. </div>
  519. </div>
  520. <hr>
  521. <div class="photo_after">
  522. <a href="#photos_after" data-bs-toggle="collapse">Фотографии после устранения
  523. ({{ $reclamation->photos_after->count() }})</a>
  524. <button class="btn btn-sm text-success" onclick="$('#upl-photo-after').trigger('click');"><i
  525. class="bi bi-plus-circle-fill"></i> Загрузить
  526. </button>
  527. @if($reclamation->photos_after->count())
  528. <a href="{{ route('reclamation.generate-photos-after-pack', $reclamation) }}"
  529. class="btn btn-sm text-primary"><i
  530. class="bi bi-download"></i> Скачать все
  531. </a>
  532. @endif
  533. <form action="{{ route('reclamations.upload-photo-after', $reclamation) }}"
  534. enctype="multipart/form-data" method="post" class="visually-hidden">
  535. @csrf
  536. <input required type="file" id="upl-photo-after" onchange="$(this).parent().submit()" multiple
  537. name="photo[]" class="form-control form-control-sm" accept=".jpg,.jpeg,.png">
  538. </form>
  539. <div class="row my-2 g-1 collapse" id="photos_after">
  540. @foreach($reclamation->photos_after as $photo)
  541. <div class="col-4">
  542. <a href="{{ $photo->link }}"
  543. data-toggle="lightbox" data-gallery="photos-after" data-size="fullscreen">
  544. <img class="img-thumbnail" src="{{ $photo->link }}" alt="">
  545. </a>
  546. @if(hasRole('admin'))
  547. <i class="bi bi-x-circle-fill fs-6 text-danger cursor-pointer rm-but"
  548. onclick="if(confirm('Удалить фото?')) $('#photo-{{ $photo->id }}').submit()"
  549. title="Удалить"></i>
  550. @endif
  551. <form action="{{ route('reclamations.delete-photo-after', [$reclamation, $photo]) }}"
  552. method="POST" id="photo-{{ $photo->id }}" class="visually-hidden">
  553. @csrf
  554. @method('DELETE')
  555. </form>
  556. </div>
  557. @endforeach
  558. </div>
  559. </div>
  560. </div>
  561. </div>
  562. </div>
  563. <!-- Модальное окно графика -->
  564. <div class="modal fade" id="copySchedule" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
  565. <div class="modal-dialog modal-fullscreen-sm-down modal-lg">
  566. <div class="modal-content">
  567. <div class="modal-header">
  568. <h1 class="modal-title fs-5" id="addModalLabel">Перенести в график монтажей</h1>
  569. <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Закрыть"></button>
  570. </div>
  571. <div class="modal-body">
  572. <form action="{{ route('schedule.create-from-reclamation') }}" method="post" id="scheduleCreateForm">
  573. @csrf
  574. <div>
  575. <input type="hidden" name="reclamation_id" value="{{ $reclamation->id }}">
  576. {{-- <textarea name="comment" placeholder="Комментарий для графика" class="form-control mb-3"></textarea>--}}
  577. <input type="checkbox" checked="checked" id="sendNotifications" name="send_notifications" value="1" class="form-check-inline">
  578. <label for="sendNotifications" class="form-check-label mb-2">Уведомить менеджера и бригадира</label><br>
  579. <input type="checkbox" id="deleteOldRecords" name="delete_old_records" class="form-check-inline">
  580. <label for="deleteOldRecords" class="form-check-label mb-2">Удалить старые записи в графике для этой рекламации?</label><br>
  581. <button type="submit" class="btn btn-primary btn-sm">Обновить график</button>
  582. </div>
  583. </form>
  584. </div>
  585. </div>
  586. </div>
  587. </div>
  588. @endsection
  589. @push('scripts')
  590. <script type="module">
  591. $('#createScheduleButton').on('click', function () {
  592. let myModalSchedule = new bootstrap.Modal(document.getElementById("copySchedule"), {});
  593. myModalSchedule.show();
  594. });
  595. let sparePartIndex = {{ max($reclamation->spareParts->count(), 1) }};
  596. const searchUrl = '{{ route('spare_parts.search') }}';
  597. // Инициализация автокомплита для поля
  598. function initSparePartAutocomplete($row) {
  599. const $input = $row.find('.spare-part-search');
  600. const $dropdown = $row.find('.spare-part-dropdown');
  601. const $hiddenId = $row.find('.spare-part-id');
  602. let currentFocus = -1;
  603. let searchTimeout;
  604. $input.on('input', function() {
  605. const query = $(this).val().trim();
  606. clearTimeout(searchTimeout);
  607. // Сбрасываем ID при изменении текста
  608. $hiddenId.val('');
  609. if (query.length >= 1) {
  610. searchTimeout = setTimeout(function() {
  611. $.get(searchUrl, { query: query }).done(function(data) {
  612. showDropdown(data, query);
  613. });
  614. }, 200);
  615. } else {
  616. $dropdown.hide();
  617. }
  618. });
  619. function showDropdown(items, query) {
  620. $dropdown.empty();
  621. currentFocus = -1;
  622. if (items.length === 0) {
  623. $dropdown.hide();
  624. return;
  625. }
  626. items.forEach(function(item) {
  627. const $item = $('<div class="sp-item"></div>');
  628. const highlightedArticle = highlightMatch(item.article, query);
  629. const highlightedUsed = item.used_in_maf ? highlightMatch(item.used_in_maf, query) : '';
  630. $item.html('<span class="sp-article">' + highlightedArticle + '</span>' +
  631. (item.used_in_maf ? ' <span class="sp-used">(' + highlightedUsed + ')</span>' : ''));
  632. $item.data('id', item.id);
  633. $item.data('article', item.article);
  634. $item.data('used', item.used_in_maf || '');
  635. $item.on('click', function() {
  636. selectItem($(this));
  637. });
  638. $dropdown.append($item);
  639. });
  640. $dropdown.show();
  641. }
  642. function highlightMatch(text, query) {
  643. if (!text || !query) return text || '';
  644. const regex = new RegExp('(' + escapeRegex(query) + ')', 'gi');
  645. return text.replace(regex, '<strong>$1</strong>');
  646. }
  647. function escapeRegex(str) {
  648. return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
  649. }
  650. function selectItem($item) {
  651. const article = $item.data('article');
  652. const used = $item.data('used');
  653. const displayText = article + (used ? ' (' + used + ')' : '');
  654. $input.val(displayText);
  655. $hiddenId.val($item.data('id'));
  656. $dropdown.hide();
  657. }
  658. // Навигация клавиатурой
  659. $input.on('keydown', function(e) {
  660. const $items = $dropdown.find('.sp-item');
  661. if (e.keyCode === 40) { // Стрелка вниз
  662. e.preventDefault();
  663. currentFocus++;
  664. if (currentFocus >= $items.length) currentFocus = 0;
  665. setActive($items);
  666. } else if (e.keyCode === 38) { // Стрелка вверх
  667. e.preventDefault();
  668. currentFocus--;
  669. if (currentFocus < 0) currentFocus = $items.length - 1;
  670. setActive($items);
  671. } else if (e.keyCode === 13) { // Enter
  672. e.preventDefault();
  673. if (currentFocus > -1 && $items.length > 0) {
  674. selectItem($items.eq(currentFocus));
  675. }
  676. } else if (e.keyCode === 27) { // Escape
  677. $dropdown.hide();
  678. }
  679. });
  680. function setActive($items) {
  681. $items.removeClass('active');
  682. if (currentFocus >= 0 && currentFocus < $items.length) {
  683. $items.eq(currentFocus).addClass('active');
  684. }
  685. }
  686. // Закрытие при клике вне
  687. $(document).on('click', function(e) {
  688. if (!$(e.target).closest($row).length) {
  689. $dropdown.hide();
  690. }
  691. });
  692. }
  693. // Инициализация для существующих строк
  694. $('.spare-part-row').not('.spare-part-template').each(function() {
  695. initSparePartAutocomplete($(this));
  696. });
  697. // Добавление новой строки запчасти
  698. $('#add-spare-part-row').on('click', function() {
  699. let template = $('.spare-part-template').first();
  700. let newRow = template.clone();
  701. newRow.removeClass('spare-part-template d-none');
  702. newRow.attr('data-index', sparePartIndex);
  703. // Заменяем __INDEX__ на реальный индекс во всех name атрибутах
  704. newRow.find('[name]').each(function() {
  705. let name = $(this).attr('name');
  706. $(this).attr('name', name.replace('__INDEX__', sparePartIndex));
  707. $(this).prop('disabled', false);
  708. });
  709. // Сбрасываем значения и разблокируем поле поиска
  710. newRow.find('.spare-part-search').val('').prop('disabled', false);
  711. newRow.find('.spare-part-id').val('');
  712. newRow.find('input[type="number"]').val('');
  713. newRow.find('input[type="checkbox"]').prop('checked', false);
  714. $('.spare-parts-rows').append(newRow);
  715. // Инициализируем автокомплит для новой строки
  716. initSparePartAutocomplete(newRow);
  717. sparePartIndex++;
  718. });
  719. // Удаление строки
  720. $(document).on('click', '.remove-spare-part-row', function() {
  721. $(this).closest('.spare-part-row').remove();
  722. });
  723. </script>
  724. @endpush