first&last

This commit is contained in:
sbb45
2026-03-20 15:47:17 +05:00
commit d6441abdd2
230 changed files with 20367 additions and 0 deletions
@@ -0,0 +1,65 @@
<?php
namespace App\Livewire\Directories;
use App\Models\Department;
use Illuminate\Validation\Rule;
use Livewire\Attributes\Layout;
use Livewire\Component;
#[Layout('layouts.app')]
class DepartmentsPage extends Component
{
public string $name = '';
public string $description = '';
public ?int $editingId = null;
public function mount(): void
{
abort_unless(auth()->user()->isAdmin(), 403);
}
public function edit(int $id): void
{
$model = Department::query()->findOrFail($id);
$this->editingId = $model->id;
$this->name = $model->name;
$this->description = (string) $model->description;
}
public function save(): void
{
$nameRule = Rule::unique('departments', 'name');
if ($this->editingId) {
$nameRule = $nameRule->ignore($this->editingId);
}
$this->validate([
'name' => ['required', 'string', 'max:255', $nameRule],
'description' => ['nullable', 'string'],
]);
Department::query()->updateOrCreate(
['id' => $this->editingId],
['name' => $this->name, 'description' => $this->description]
);
$this->reset(['name', 'description', 'editingId']);
session()->flash('success', 'Отдел сохранен.');
}
public function delete(int $id): void
{
Department::query()->findOrFail($id)->delete();
session()->flash('success', 'Отдел удален.');
}
public function render()
{
return view('livewire.directories.departments-page', [
'items' => Department::query()->orderBy('name')->get(),
])->title('Справочник: Отделы');
}
}
@@ -0,0 +1,85 @@
<?php
namespace App\Livewire\Directories;
use App\Models\EquipmentCategory;
use Illuminate\Support\Str;
use Livewire\Attributes\Layout;
use Livewire\Component;
#[Layout('layouts.app')]
class EquipmentCategoriesPage extends Component
{
public string $name = '';
public string $description = '';
public ?int $editingId = null;
public function mount(): void
{
abort_unless(auth()->user()->isAdmin(), 403);
}
public function edit(int $id): void
{
$model = EquipmentCategory::query()->findOrFail($id);
$this->editingId = $model->id;
$this->name = $model->name;
$this->description = (string) $model->description;
}
public function save(): void
{
$this->validate([
'name' => ['required', 'string', 'max:255'],
'description' => ['nullable', 'string'],
]);
$slug = $this->generateUniqueSlug($this->name);
EquipmentCategory::query()->updateOrCreate(
['id' => $this->editingId],
['name' => $this->name, 'slug' => $slug, 'description' => $this->description]
);
$this->reset(['name', 'description', 'editingId']);
session()->flash('success', 'Категория сохранена.');
}
public function delete(int $id): void
{
EquipmentCategory::query()->findOrFail($id)->delete();
session()->flash('success', 'Категория удалена.');
}
private function generateUniqueSlug(string $name): string
{
$baseSlug = Str::slug($name);
if ($baseSlug === '') {
$baseSlug = 'category';
}
$slug = $baseSlug;
$suffix = 2;
while (
EquipmentCategory::query()
->where('slug', $slug)
->when($this->editingId, fn ($query) => $query->where('id', '!=', $this->editingId))
->exists()
) {
$slug = $baseSlug.'-'.$suffix;
$suffix++;
}
return $slug;
}
public function render()
{
return view('livewire.directories.equipment-categories-page', [
'items' => EquipmentCategory::query()->orderBy('name')->get(),
])->title('Справочник: Категории оборудования');
}
}
+114
View File
@@ -0,0 +1,114 @@
<?php
namespace App\Livewire\Directories;
use App\Models\Equipment;
use App\Models\EquipmentCategory;
use App\Models\User;
use Livewire\Attributes\Layout;
use Livewire\Component;
use Livewire\WithPagination;
use Illuminate\Validation\Rule;
#[Layout('layouts.app')]
class EquipmentPage extends Component
{
use WithPagination;
public string $name = '';
public string $serialNumber = '';
public string $inventoryNumber = '';
public string $categoryId = '';
public string $clientId = '';
public string $purchaseDate = '';
public string $warrantyUntil = '';
public string $condition = 'good';
public string $notes = '';
public ?int $editingId = null;
public function mount(): void
{
abort_unless(auth()->user()->isAdmin(), 403);
}
public function edit(int $id): void
{
$model = Equipment::query()->findOrFail($id);
$this->editingId = $model->id;
$this->name = $model->name;
$this->serialNumber = $model->serial_number;
$this->inventoryNumber = $model->inventory_number;
$this->categoryId = (string) $model->category_id;
$this->clientId = (string) $model->client_id;
$this->purchaseDate = (string) $model->purchase_date;
$this->warrantyUntil = (string) $model->warranty_until;
$this->condition = $model->condition->value;
$this->notes = (string) $model->notes;
}
public function save(): void
{
$serialRule = Rule::unique('equipment', 'serial_number');
$inventoryRule = Rule::unique('equipment', 'inventory_number');
if ($this->editingId) {
$serialRule = $serialRule->ignore($this->editingId);
$inventoryRule = $inventoryRule->ignore($this->editingId);
}
$this->validate([
'name' => ['required', 'string', 'max:255'],
'serialNumber' => ['required', 'string', $serialRule],
'inventoryNumber' => ['required', 'string', $inventoryRule],
'categoryId' => ['required', 'exists:equipment_categories,id'],
'clientId' => ['nullable', 'exists:users,id'],
'purchaseDate' => ['nullable', 'date'],
'warrantyUntil' => ['nullable', 'date'],
'condition' => ['required', Rule::in(['good', 'fair', 'poor'])],
'notes' => ['nullable', 'string'],
]);
Equipment::query()->updateOrCreate(
['id' => $this->editingId],
[
'name' => $this->name,
'serial_number' => $this->serialNumber,
'inventory_number' => $this->inventoryNumber,
'category_id' => $this->categoryId,
'client_id' => $this->clientId ?: null,
'purchase_date' => $this->purchaseDate ?: null,
'warranty_until' => $this->warrantyUntil ?: null,
'condition' => $this->condition,
'notes' => $this->notes,
]
);
$this->reset(['name', 'serialNumber', 'inventoryNumber', 'categoryId', 'clientId', 'purchaseDate', 'warrantyUntil', 'notes', 'editingId']);
$this->condition = 'good';
session()->flash('success', 'Оборудование сохранено.');
}
public function delete(int $id): void
{
Equipment::query()->findOrFail($id)->delete();
session()->flash('success', 'Оборудование удалено.');
}
public function render()
{
return view('livewire.directories.equipment-page', [
'items' => Equipment::query()->with(['category', 'client'])->latest()->paginate(15),
'categories' => EquipmentCategory::query()->orderBy('name')->get(),
'clients' => User::query()->where('role', 'client')->orderBy('name')->get(),
])->title('Справочник: Оборудование');
}
}
@@ -0,0 +1,71 @@
<?php
namespace App\Livewire\Directories;
use App\Models\Priority;
use Illuminate\Validation\Rule;
use Livewire\Attributes\Layout;
use Livewire\Component;
#[Layout('layouts.app')]
class PrioritiesPage extends Component
{
public string $name = '';
public string $colorHex = '#3B82F6';
public int $level = 1;
public ?int $editingId = null;
public function mount(): void
{
abort_unless(auth()->user()->isAdmin(), 403);
}
public function edit(int $id): void
{
$model = Priority::query()->findOrFail($id);
$this->editingId = $model->id;
$this->name = $model->name;
$this->colorHex = $model->color_hex;
$this->level = $model->level;
}
public function save(): void
{
$levelRule = Rule::unique('priorities', 'level');
if ($this->editingId) {
$levelRule = $levelRule->ignore($this->editingId);
}
$this->validate([
'name' => ['required', 'string', 'max:255'],
'colorHex' => ['required', 'regex:/^#[0-9A-Fa-f]{6}$/'],
'level' => ['required', 'integer', 'between:1,4', $levelRule],
]);
Priority::query()->updateOrCreate(
['id' => $this->editingId],
['name' => $this->name, 'color_hex' => $this->colorHex, 'level' => $this->level]
);
$this->reset(['name', 'editingId']);
$this->colorHex = '#3B82F6';
$this->level = 1;
session()->flash('success', 'Приоритет сохранен.');
}
public function delete(int $id): void
{
Priority::query()->findOrFail($id)->delete();
session()->flash('success', 'Приоритет удален.');
}
public function render()
{
return view('livewire.directories.priorities-page', [
'items' => Priority::query()->orderBy('level')->get(),
])->title('Справочник: Приоритеты');
}
}
@@ -0,0 +1,70 @@
<?php
namespace App\Livewire\Directories;
use App\Models\RequestType;
use Illuminate\Validation\Rule;
use Livewire\Attributes\Layout;
use Livewire\Component;
#[Layout('layouts.app')]
class RequestTypesPage extends Component
{
public string $name = '';
public string $description = '';
public int $slaHours = 24;
public ?int $editingId = null;
public function mount(): void
{
abort_unless(auth()->user()->isAdmin(), 403);
}
public function edit(int $id): void
{
$model = RequestType::query()->findOrFail($id);
$this->editingId = $model->id;
$this->name = $model->name;
$this->description = (string) $model->description;
$this->slaHours = $model->sla_hours;
}
public function save(): void
{
$nameRule = Rule::unique('request_types', 'name');
if ($this->editingId) {
$nameRule = $nameRule->ignore($this->editingId);
}
$this->validate([
'name' => ['required', 'string', 'max:255', $nameRule],
'description' => ['nullable', 'string'],
'slaHours' => ['required', 'integer', 'min:1', 'max:720'],
]);
RequestType::query()->updateOrCreate(
['id' => $this->editingId],
['name' => $this->name, 'description' => $this->description, 'sla_hours' => $this->slaHours]
);
$this->reset(['name', 'description', 'editingId']);
$this->slaHours = 24;
session()->flash('success', 'Тип заявки сохранен.');
}
public function delete(int $id): void
{
RequestType::query()->findOrFail($id)->delete();
session()->flash('success', 'Тип заявки удален.');
}
public function render()
{
return view('livewire.directories.request-types-page', [
'items' => RequestType::query()->orderBy('name')->get(),
])->title('Справочник: Типы заявок');
}
}
+94
View File
@@ -0,0 +1,94 @@
<?php
namespace App\Livewire\Directories;
use App\Models\Status;
use Illuminate\Validation\Rule;
use Livewire\Attributes\Layout;
use Livewire\Component;
#[Layout('layouts.app')]
class StatusesPage extends Component
{
public string $name = '';
public string $colorHex = '#3B82F6';
public string $slug = '';
public bool $isFinal = false;
public int $sortOrder = 1;
public ?int $editingId = null;
public function mount(): void
{
abort_unless(auth()->user()->isAdmin(), 403);
}
public function edit(int $id): void
{
$model = Status::query()->findOrFail($id);
$this->editingId = $model->id;
$this->name = $model->name;
$this->colorHex = $model->color_hex;
$this->slug = $model->slug;
$this->isFinal = $model->is_final;
$this->sortOrder = $model->sort_order;
}
public function save(): void
{
$slugRule = Rule::unique('statuses', 'slug');
if ($this->editingId) {
$slugRule = $slugRule->ignore($this->editingId);
}
$this->validate([
'name' => ['required', 'string', 'max:255'],
'colorHex' => ['required', 'regex:/^#[0-9A-Fa-f]{6}$/'],
'slug' => ['required', 'string', $slugRule],
'isFinal' => ['boolean'],
'sortOrder' => ['required', 'integer', 'min:1', 'max:100'],
]);
Status::query()->updateOrCreate(
['id' => $this->editingId],
[
'name' => $this->name,
'color_hex' => $this->colorHex,
'slug' => $this->slug,
'is_final' => $this->isFinal,
'sort_order' => $this->sortOrder,
]
);
$this->reset(['name', 'slug', 'editingId']);
$this->colorHex = '#3B82F6';
$this->isFinal = false;
$this->sortOrder = 1;
session()->flash('success', 'Статус сохранен.');
}
public function delete(int $id): void
{
$status = Status::query()->findOrFail($id);
if ($status->requests()->exists()) {
session()->flash('error', 'Нельзя удалить статус, который используется в заявках.');
return;
}
$status->delete();
session()->flash('success', 'Статус удален.');
}
public function render()
{
return view('livewire.directories.statuses-page', [
'items' => Status::query()->orderBy('sort_order')->get(),
])->title('Справочник: Статусы');
}
}