index.blade.php 18 KB

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