# Task 04 — Setup CRUD Screens

## Goal
Build CRUD for all setup tables: ItemCategory, UnitOfMeasure, SalesTaxRate, Supplier.

---

## Services to Create

### `ItemCategoryService` — `app/Services/Inventory/Setup/ItemCategoryService.php`
Methods: getAll(perPage=15), getActive(), create(data), update(category, data), delete(category)

### `UnitOfMeasureService` — `app/Services/Inventory/Setup/UnitOfMeasureService.php`
Methods: getAll(perPage=15), getActive(), create(data), update(uom, data), delete(uom)

### `SalesTaxRateService` — `app/Services/Sales/Setup/SalesTaxRateService.php`
Methods: getAll(perPage=15), getActive(), getDefault(), create(data), update(rate, data), delete(rate)

**Note for SalesTaxRateService.create():**
- If new rate has `is_default = true` → set all other rates to `is_default = false` first

### `SupplierService` — `app/Services/Inventory/Supplier/SupplierService.php`
Methods: getAll(perPage=15), getActive(), getBranches(), getAccounts(), create(data), update(supplier, data), delete(supplier)

---

## Controllers to Create

| Controller | Route Prefix | Permission Prefix |
|-----------|-------------|------------------|
| `Admin/Inventory/Setup/ItemCategoryController` | inventory/setup/item-categories | inventory.item_categories |
| `Admin/Inventory/Setup/UnitOfMeasureController` | inventory/setup/units-of-measure | inventory.units_of_measure |
| `Admin/Sales/Setup/SalesTaxRateController` | sales/setup/tax-rates | sales.tax_rates |
| `Admin/Inventory/Supplier/SupplierController` | inventory/suppliers | inventory.suppliers |

All controllers: index, create, store, edit, update, destroy.

---

## FormRequest Classes

### `StoreItemCategoryRequest`
```php
'code'                  => 'required|string|unique:item_categories',
'name.ar'               => 'required|string',
'name.en'               => 'nullable|string',
'inventory_account_id'  => 'nullable|exists:accounts,id',
'cogs_account_id'       => 'nullable|exists:accounts,id',
'revenue_account_id'    => 'nullable|exists:accounts,id',
'is_active'             => 'boolean',
```

### `StoreUnitOfMeasureRequest`
```php
'code'     => 'required|string|unique:units_of_measure',
'name.ar'  => 'required|string',
'name.en'  => 'nullable|string',
'is_active'=> 'boolean',
```

### `StoreSalesTaxRateRequest`
```php
'code'                     => 'required|string|unique:sales_tax_rates',
'name.ar'                  => 'required|string',
'name.en'                  => 'nullable|string',
'rate'                     => 'required|numeric|min:0|max:100',
'tax_payable_account_id'   => 'nullable|exists:accounts,id',
'is_active'                => 'boolean',
'is_default'               => 'boolean',
```

### `StoreSupplierRequest`
```php
'code'                => 'required|string|unique:suppliers',
'name.ar'             => 'required|string',
'name.en'             => 'nullable|string',
'phone'               => 'nullable|string',
'email'               => 'nullable|email',
'address.ar'          => 'nullable|string',
'address.en'          => 'nullable|string',
'tax_number'          => 'nullable|string',
'credit_limit'        => 'nullable|numeric|min:0',
'payment_terms_days'  => 'nullable|integer|min:0',
'ap_account_id'       => 'nullable|exists:accounts,id',
'branch_id'           => 'required|exists:branches,id',
'opening_balance'     => 'nullable|numeric',
'opening_balance_date'=> 'nullable|date',
'is_active'           => 'boolean',
```

---

## Views

Create standard index/create/edit views for each resource under:
- `resources/views/dashboard/admin/inventory/setup/item-categories/`
- `resources/views/dashboard/admin/inventory/setup/units-of-measure/`
- `resources/views/dashboard/admin/sales/setup/tax-rates/`
- `resources/views/dashboard/admin/inventory/suppliers/`

---

## Permissions to Seed

```php
// Item Categories
'inventory.item_categories.view'
'inventory.item_categories.create'
'inventory.item_categories.update'
'inventory.item_categories.delete'

// Units of Measure
'inventory.units_of_measure.view'
'inventory.units_of_measure.create'
'inventory.units_of_measure.update'
'inventory.units_of_measure.delete'

// Tax Rates
'sales.tax_rates.view'
'sales.tax_rates.create'
'sales.tax_rates.update'
'sales.tax_rates.delete'

// Suppliers
'inventory.suppliers.view'
'inventory.suppliers.create'
'inventory.suppliers.update'
'inventory.suppliers.delete'
```

---

## Routes to Add

Add to `routes/admin.php` inside the auth:admin middleware group:

```php
// Inventory Setup
Route::group(['prefix' => 'inventory/setup/item-categories', 'as' => 'inventory.item-categories.'], function () {
    Route::get('/', [ItemCategoryController::class, 'index'])->name('index');
    Route::get('/create', [ItemCategoryController::class, 'create'])->name('create');
    Route::post('/', [ItemCategoryController::class, 'store'])->name('store');
    Route::get('/{itemCategory}/edit', [ItemCategoryController::class, 'edit'])->name('edit');
    Route::put('/{itemCategory}', [ItemCategoryController::class, 'update'])->name('update');
    Route::delete('/{itemCategory}', [ItemCategoryController::class, 'destroy'])->name('destroy');
});

// Similar groups for units-of-measure, tax-rates, suppliers
```
