index.blade.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339
  1. @extends('layouts.app')
  2. @section('content')
  3. <div class="container-fluid">
  4. <div class="row">
  5. <div class="col-12">
  6. <h3>{{ $title }}</h3>
  7. {{-- Вкладки --}}
  8. <ul class="nav nav-tabs mb-3">
  9. <li class="nav-item">
  10. <a class="nav-link {{ ($tab ?? 'catalog') === 'catalog' ? 'active' : '' }}"
  11. href="{{ route('spare_parts.index') }}">
  12. Каталог
  13. </a>
  14. </li>
  15. <li class="nav-item">
  16. <a class="nav-link {{ ($tab ?? '') === 'orders' ? 'active' : '' }}"
  17. href="{{ route('spare_part_orders.index') }}">
  18. Заказы деталей
  19. </a>
  20. </li>
  21. <li class="nav-item">
  22. <a class="nav-link {{ ($tab ?? '') === 'inventory' ? 'active' : '' }}"
  23. href="{{ route('spare_part_inventory.index') }}">
  24. Контроль наличия
  25. </a>
  26. </li>
  27. @if(hasRole('admin'))
  28. <li class="nav-item">
  29. <a class="nav-link" href="{{ route('pricing_codes.index') }}">
  30. Справочник расшифровок
  31. </a>
  32. </li>
  33. @endif
  34. <li class="nav-item">
  35. <a class="nav-link {{ ($tab ?? '') === 'help' ? 'active' : '' }}"
  36. href="{{ route('spare_parts.help') }}">
  37. <i class="bi bi-question-circle"></i> Справка
  38. </a>
  39. </li>
  40. </ul>
  41. @if(($tab ?? 'catalog') === 'catalog')
  42. {{-- Кнопки управления --}}
  43. <div class="mb-3">
  44. @if(hasRole('admin,manager'))
  45. <a href="{{ route('spare_parts.create') }}" class="btn btn-sm btn-primary">Добавить запчасть</a>
  46. @endif
  47. @if(hasRole('admin'))
  48. <form action="{{ route('spare_parts.export') }}" method="POST" class="d-inline">
  49. @csrf
  50. <button type="submit" class="btn btn-sm btn-success">Экспорт</button>
  51. </form>
  52. <button type="button" class="btn btn-sm btn-info" data-bs-toggle="modal" data-bs-target="#importModal">
  53. Импорт
  54. </button>
  55. @endif
  56. </div>
  57. {{-- Таблица каталога --}}
  58. @if(isset($spare_parts) && isset($strings))
  59. @include('partials.table', [
  60. 'id' => $id,
  61. 'header' => $header,
  62. 'strings' => $strings,
  63. 'filters' => $filters ?? [],
  64. 'ranges' => $ranges ?? [],
  65. 'dates' => $dates ?? [],
  66. 'searchFields' => $searchFields ?? [],
  67. 'sortBy' => $sortBy ?? 'article',
  68. 'orderBy' => $orderBy ?? 'asc',
  69. 'routeName' => $routeName ?? null,
  70. ])
  71. {{ $spare_parts->links() }}
  72. @endif
  73. @elseif($tab === 'orders')
  74. {{-- Таблица заказов --}}
  75. @if(isset($spare_part_orders))
  76. <div class="mb-3">
  77. @if(hasRole('admin,manager'))
  78. <a href="{{ route('spare_part_orders.create') }}" class="btn btn-sm btn-primary">Создать заказ</a>
  79. @endif
  80. </div>
  81. @include('partials.table', [
  82. 'id' => $id,
  83. 'header' => $header,
  84. 'strings' => $strings,
  85. 'filters' => $filters ?? [],
  86. 'ranges' => $ranges ?? [],
  87. 'dates' => $dates ?? [],
  88. 'searchFields' => $searchFields ?? [],
  89. 'sortBy' => $sortBy ?? 'id',
  90. 'orderBy' => $orderBy ?? 'desc',
  91. 'routeName' => $routeName ?? null,
  92. ])
  93. {{ $spare_part_orders->links() }}
  94. @endif
  95. @elseif($tab === 'inventory')
  96. {{-- Контроль наличия --}}
  97. {{-- Открытые дефициты --}}
  98. <h4 class="text-danger"><i class="bi bi-exclamation-triangle-fill"></i> Открытые дефициты
  99. @if(isset($open_shortages) && $open_shortages->count() > 0)
  100. <span class="badge bg-danger">{{ $open_shortages->count() }}</span>
  101. @endif
  102. </h4>
  103. @if(isset($open_shortages) && $open_shortages->count() > 0)
  104. <div class="table-responsive js-subtable-scroll">
  105. <table class="table table-danger table-striped">
  106. <thead>
  107. <tr>
  108. <th>Картинка</th>
  109. <th>Артикул</th>
  110. <th>Рекламация</th>
  111. <th class="text-center">Требуется</th>
  112. <th class="text-center">Зарезервировано</th>
  113. <th class="text-center">Не хватает</th>
  114. <th class="text-center">С док.</th>
  115. <th>Дата создания</th>
  116. </tr>
  117. </thead>
  118. <tbody>
  119. @foreach($open_shortages as $shortage)
  120. <tr>
  121. <td>
  122. @if($shortage->sparePart && $shortage->sparePart->image)
  123. <img src="{{ $shortage->sparePart->image }}" alt="{{ $shortage->sparePart->article }}" class="img-max-50">
  124. @endif
  125. </td>
  126. <td>
  127. @if($shortage->sparePart)
  128. <a href="{{ route('spare_parts.show', $shortage->sparePart->id) }}">{{ $shortage->sparePart->article }}</a>
  129. @if($shortage->sparePart->used_in_maf)
  130. <br><small class="text-muted">{{ $shortage->sparePart->used_in_maf }}</small>
  131. @endif
  132. @else
  133. -
  134. @endif
  135. </td>
  136. <td>
  137. @if($shortage->reclamation)
  138. <a href="{{ route('reclamations.show', $shortage->reclamation->id) }}">#{{ $shortage->reclamation->id }}</a>
  139. @else
  140. -
  141. @endif
  142. </td>
  143. <td class="text-center">{{ $shortage->required_qty }}</td>
  144. <td class="text-center">{{ $shortage->reserved_qty }}</td>
  145. <td class="text-center fw-bold">{{ $shortage->missing_qty }}</td>
  146. <td class="text-center">
  147. @if($shortage->with_documents)
  148. <i class="bi bi-check-circle text-success"></i> Да
  149. @else
  150. <i class="bi bi-x-circle text-muted"></i> Нет
  151. @endif
  152. </td>
  153. <td>{{ $shortage->created_at->format('d.m.Y H:i') }}</td>
  154. </tr>
  155. @endforeach
  156. </tbody>
  157. </table>
  158. </div>
  159. @else
  160. <p class="text-muted">Нет открытых дефицитов</p>
  161. @endif
  162. {{-- Запчасти с критическим недостатком --}}
  163. <h4 class="text-danger mt-4">Запчасти с дефицитами</h4>
  164. @if(isset($critical_shortages) && $critical_shortages->count() > 0)
  165. <div class="table-responsive js-subtable-scroll">
  166. <table class="table table-danger table-striped">
  167. <thead>
  168. <tr>
  169. <th>Картинка</th>
  170. <th>Артикул</th>
  171. <th class="text-center">Свободно без док</th>
  172. <th class="text-center">Свободно с док</th>
  173. <th>Дефициты</th>
  174. </tr>
  175. </thead>
  176. <tbody>
  177. @foreach($critical_shortages as $sp)
  178. <tr>
  179. <td>
  180. @if($sp->image)
  181. <img src="{{ $sp->image }}" alt="{{ $sp->article }}" class="img-max-50">
  182. @endif
  183. </td>
  184. <td>
  185. <a href="{{ route('spare_parts.show', $sp->id) }}">{{ $sp->article }}</a>
  186. @if($sp->used_in_maf)
  187. <br><small class="text-muted">{{ $sp->used_in_maf }}</small>
  188. @endif
  189. </td>
  190. <td class="text-center">{{ $sp->quantity_without_docs }}</td>
  191. <td class="text-center">{{ $sp->quantity_with_docs }}</td>
  192. <td>
  193. @if(isset($sp->shortage_details))
  194. @foreach($sp->shortage_details as $detail)
  195. <div class="small">
  196. <a href="{{ route('reclamations.show', $detail['reclamation_id']) }}">Рекл. #{{ $detail['reclamation_id'] }}</a>:
  197. не хватает <strong>{{ $detail['missing_qty'] }}</strong> шт.
  198. @if($detail['with_documents'])
  199. (с док.)
  200. @else
  201. (без док.)
  202. @endif
  203. </div>
  204. @endforeach
  205. @endif
  206. </td>
  207. </tr>
  208. @endforeach
  209. </tbody>
  210. </table>
  211. </div>
  212. @else
  213. <p class="text-muted">Нет запчастей с дефицитами</p>
  214. @endif
  215. <h4 class="text-warning mt-4"><i class="bi bi-exclamation-circle-fill"></i> Ниже минимального остатка</h4>
  216. @if(isset($below_min_stock) && $below_min_stock->count() > 0)
  217. <div class="table-responsive js-subtable-scroll">
  218. <table class="table table-warning table-striped">
  219. <thead>
  220. <tr>
  221. <th>Картинка</th>
  222. <th>Артикул</th>
  223. <th class="text-center">Текущий остаток</th>
  224. <th class="text-center">Минимальный остаток</th>
  225. <th class="text-center">Нужно заказать</th>
  226. </tr>
  227. </thead>
  228. <tbody>
  229. @foreach($below_min_stock as $sp)
  230. <tr>
  231. <td>
  232. @if($sp->image)
  233. <img src="{{ $sp->image }}" alt="{{ $sp->article }}" class="img-max-50">
  234. @endif
  235. </td>
  236. <td>
  237. <a href="{{ route('spare_parts.show', $sp->id) }}">{{ $sp->article }}</a>
  238. @if($sp->used_in_maf)
  239. <br><small class="text-muted">{{ $sp->used_in_maf }}</small>
  240. @endif
  241. </td>
  242. <td class="text-center">{{ $sp->total_quantity }}</td>
  243. <td class="text-center">{{ $sp->min_stock }}</td>
  244. <td class="text-center fw-bold">{{ max(0, $sp->min_stock - $sp->total_quantity) }}</td>
  245. </tr>
  246. @endforeach
  247. </tbody>
  248. </table>
  249. </div>
  250. @else
  251. <p class="text-muted">Нет запчастей ниже минимального остатка</p>
  252. @endif
  253. @elseif($tab === 'help')
  254. {{-- Справка --}}
  255. <div class="card">
  256. <div class="card-body markdown-content">
  257. {!! $helpContent !!}
  258. </div>
  259. </div>
  260. @endif
  261. </div>
  262. </div>
  263. </div>
  264. {{-- Модальное окно импорта --}}
  265. @if(hasRole('admin'))
  266. <div class="modal fade" id="importModal" tabindex="-1" aria-labelledby="importSparePartsModalLabel" aria-hidden="true">
  267. <div class="modal-dialog">
  268. <div class="modal-content">
  269. <div class="modal-header">
  270. <h1 class="modal-title fs-5" id="importSparePartsModalLabel">Импорт каталога запчастей и справочника расшифровок</h1>
  271. <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
  272. </div>
  273. <form action="{{ route('spare_parts.import') }}" method="POST" enctype="multipart/form-data">
  274. @csrf
  275. <div class="modal-body">
  276. <div class="mb-3">
  277. <label for="import_file" class="form-label">Выберите файл Excel</label>
  278. <input type="file" class="form-control" id="import_file" name="file" accept=".xlsx,.xls" required>
  279. <div class="form-text">
  280. Файл должен содержать две вкладки:<br>
  281. 1. Каталог запчастей (колонки: ID, Артикул, Где используется, Кол-во без док, Кол-во с док, Кол-во общее, Примечание, Цена закупки, Цена для заказчика, Цена экспертизы, № по ТСН, Шифр расценки, Минимальный остаток)<br>
  282. 2. Справочник расшифровок (колонки: ID, Тип, Код, Расшифровка)
  283. </div>
  284. </div>
  285. </div>
  286. <div class="modal-footer">
  287. <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Отмена</button>
  288. <button type="submit" class="btn btn-primary">Импортировать</button>
  289. </div>
  290. </form>
  291. </div>
  292. </div>
  293. </div>
  294. @endif
  295. @push('scripts')
  296. <script type="module">
  297. function waitForJQuery(callback) {
  298. if (typeof window.$ !== 'undefined') {
  299. callback();
  300. } else {
  301. setTimeout(() => waitForJQuery(callback), 50);
  302. }
  303. }
  304. waitForJQuery(function() {
  305. $(document).on('click', '.clickable-quantity', function(e) {
  306. e.preventDefault();
  307. const sparePartId = $(this).data('spare-part-id');
  308. const withDocs = $(this).data('with-docs');
  309. let url = "{{ route('spare_part_orders.index') }}" +
  310. "?spare_part_id=" + sparePartId +
  311. "&status=in_stock&available_qty_min=1";
  312. if (withDocs !== 'all') {
  313. url += "&with_documents=" + withDocs;
  314. }
  315. window.location.href = url;
  316. });
  317. });
  318. </script>
  319. @endpush
  320. @endsection