vernova/resources/views/inventory/form.blade.php
2026-07-26 19:58:27 +03:30

132 lines
6.1 KiB
PHP

@extends('layouts.app')
@section('title', isset($item) ? __('inventory.edit_item') : __('inventory.add_item'))
@section('content')
<div class="p-6">
<div class="flex items-center justify-between mb-6">
<div class="flex items-center gap-3">
<a href="{{ route('inventory.items') }}" class="p-2 text-gray-500 hover:text-gray-900 hover:bg-gray-100 rounded-lg transition-colors">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M10 19l-7-7m0 0l7-7m-7 7h18"/></svg>
</a>
<h1 class="text-2xl font-bold text-gray-800">
{{ isset($item) ? __('inventory.edit_item') : __('inventory.add_item') }}
</h1>
</div>
</div>
<form action="{{ isset($item) ? route('inventory.update', $item) : route('inventory.store') }}"
method="POST"
class="bg-white rounded-lg shadow p-6 space-y-6">
@csrf
@if(isset($item))
@method('PUT')
@endif
<!-- نام و کد -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label for="name" class="block text-sm font-medium text-gray-700 mb-1">
{{ __('inventory.name') }} *
</label>
<input type="text" name="name" id="name"
value="{{ old('name', isset($item) ? $item->name : '') }}"
class="w-full rounded-md border-gray-300 shadow-sm focus:border-teal-500 focus:ring-teal-500"
required>
@error('name')
<p class="mt-1 text-sm text-red-600">{{ $message }}</p>
@enderror
</div>
<div>
<label for="code" class="block text-sm font-medium text-gray-700 mb-1">
{{ __('inventory.code') }}
</label>
<input type="text" name="code" id="code"
value="{{ old('code', isset($item) ? $item->code : '') }}"
class="w-full rounded-md border-gray-300 shadow-sm focus:border-teal-500 focus:ring-teal-500">
@error('code')
<p class="mt-1 text-sm text-red-600">{{ $message }}</p>
@enderror
</div>
</div>
<!-- دسته‌بندی و واحد -->
<div class="grid grid-cols-1 md:grid-cols-2 gap-6">
<div>
<label for="category" class="block text-sm font-medium text-gray-700 mb-1">
{{ __('inventory.category') }}
</label>
<select name="category" id="category"
class="w-full rounded-md border-gray-300 shadow-sm focus:border-teal-500 focus:ring-teal-500">
<option value="">{{ __('common.select') }}</option>
@foreach($categories as $cat)
<option value="{{ $cat }}" {{ old('category', isset($item) ? $item->category : '') == $cat ? 'selected' : '' }}>
@php
$ck = 'inventory.category_' . $cat;
$cl = __($ck);
if ($cl === $ck) $cl = $cat;
@endphp
{{ $cl }}
</option>
@endforeach
</select>
@error('category')
<p class="mt-1 text-sm text-red-600">{{ $message }}</p>
@enderror
</div>
<div>
<label for="unit" class="block text-sm font-medium text-gray-700 mb-1">
{{ __('inventory.unit') }}
</label>
<select name="unit" id="unit"
class="w-full rounded-md border-gray-300 shadow-sm focus:border-teal-500 focus:ring-teal-500">
<option value="">{{ __('common.select') }}</option>
@foreach($units as $u)
<option value="{{ $u }}" {{ old('unit', isset($item) ? $item->unit : '') == $u ? 'selected' : '' }}>
{{ __('inventory.unit_' . $u) }}
</option>
@endforeach
</select>
@error('unit')
<p class="mt-1 text-sm text-red-600">{{ $message }}</p>
@enderror
</div>
</div>
<!-- توضیحات -->
<div>
<label for="description" class="block text-sm font-medium text-gray-700 mb-1">
{{ __('common.description') }}
</label>
<textarea name="description" id="description" rows="3"
class="w-full rounded-md border-gray-300 shadow-sm focus:border-teal-500 focus:ring-teal-500">{{ old('description', isset($item) ? $item->description : '') }}</textarea>
@error('description')
<p class="mt-1 text-sm text-red-600">{{ $message }}</p>
@enderror
</div>
<!-- فعال -->
<div class="flex items-center gap-2">
<input type="checkbox" name="is_active" id="is_active" value="1"
{{ old('is_active', isset($item) ? $item->is_active : true) ? 'checked' : '' }}
class="rounded border-gray-300 text-teal-600 focus:ring-teal-500">
<label for="is_active" class="text-sm font-medium text-gray-700">{{ __('common.active') }}</label>
</div>
<!-- دکمه‌ها -->
<div class="flex items-center justify-end gap-3 pt-4 border-t">
<a href="{{ route('inventory.items') }}"
class="px-4 py-2 text-gray-700 bg-gray-100 rounded-md hover:bg-gray-200 transition">
{{ __('common.cancel') }}
</a>
<button type="submit"
class="px-6 py-2 bg-teal-600 text-white rounded-md hover:bg-teal-700 transition">
{{ isset($item) ? __('common.save') : __('common.create') }}
</button>
</div>
</form>
</div>
@endsection