# Task 03 — Setup Models

## Goal
Create Eloquent models for all setup tables from Task 02.

---

## Model 1: `app/Models/Inventory/Setup/ItemCategory.php`

```php
namespace App\Models\Inventory\Setup;

use Spatie\Translatable\HasTranslations;
use App\Models\Finance\Account;

class ItemCategory extends Model
{
    use HasTranslations;

    protected $table = 'item_categories';
    public $translatable = ['name'];

    protected $fillable = [
        'code', 'name', 'inventory_account_id', 'cogs_account_id',
        'revenue_account_id', 'is_active', 'created_by', 'updated_by',
    ];

    protected $casts = [
        'name' => 'array',
        'is_active' => 'boolean',
    ];

    // Relationships
    public function inventoryAccount(): BelongsTo { return $this->belongsTo(Account::class, 'inventory_account_id'); }
    public function cogsAccount(): BelongsTo { return $this->belongsTo(Account::class, 'cogs_account_id'); }
    public function revenueAccount(): BelongsTo { return $this->belongsTo(Account::class, 'revenue_account_id'); }

    // Scopes
    public function scopeActive($query) { return $query->where('is_active', true); }
}
```

---

## Model 2: `app/Models/Inventory/Setup/UnitOfMeasure.php`

```php
namespace App\Models\Inventory\Setup;

use Spatie\Translatable\HasTranslations;

class UnitOfMeasure extends Model
{
    use HasTranslations;

    protected $table = 'units_of_measure';
    public $translatable = ['name'];

    protected $fillable = ['code', 'name', 'is_active', 'created_by', 'updated_by'];
    protected $casts = ['name' => 'array', 'is_active' => 'boolean'];

    public function scopeActive($query) { return $query->where('is_active', true); }
}
```

---

## Model 3: `app/Models/Sales/Setup/SalesTaxRate.php`

```php
namespace App\Models\Sales\Setup;

use Spatie\Translatable\HasTranslations;
use App\Models\Finance\Account;

class SalesTaxRate extends Model
{
    use HasTranslations;

    protected $table = 'sales_tax_rates';
    public $translatable = ['name'];

    protected $fillable = [
        'code', 'name', 'rate', 'tax_payable_account_id',
        'is_active', 'is_default', 'created_by', 'updated_by',
    ];

    protected $casts = [
        'name' => 'array',
        'rate' => 'decimal:4',
        'is_active' => 'boolean',
        'is_default' => 'boolean',
    ];

    public function taxPayableAccount(): BelongsTo { return $this->belongsTo(Account::class, 'tax_payable_account_id'); }
    public function scopeActive($query) { return $query->where('is_active', true); }
    public function scopeDefault($query) { return $query->where('is_default', true); }
}
```

---

## Model 4: `app/Models/Inventory/Supplier/Supplier.php`

```php
namespace App\Models\Inventory\Supplier;

use Spatie\Translatable\HasTranslations;
use App\Models\Finance\Account;
use App\Models\Core\Branch;

class Supplier extends Model
{
    use HasTranslations;

    protected $table = 'suppliers';
    public $translatable = ['name', 'address'];

    protected $fillable = [
        'code', 'name', 'phone', 'email', 'address', 'tax_number',
        'credit_limit', 'payment_terms_days', 'ap_account_id',
        'branch_id', 'opening_balance', 'opening_balance_date', 'is_active',
        'created_by', 'updated_by',
    ];

    protected $casts = [
        'name' => 'array',
        'address' => 'array',
        'credit_limit' => 'decimal:2',
        'opening_balance' => 'decimal:2',
        'opening_balance_date' => 'date',
        'is_active' => 'boolean',
    ];

    public function apAccount(): BelongsTo { return $this->belongsTo(Account::class, 'ap_account_id'); }
    public function branch(): BelongsTo { return $this->belongsTo(Branch::class); }
    public function purchaseOrders(): HasMany { return $this->hasMany(PurchaseOrder::class); }

    public function scopeActive($query) { return $query->where('is_active', true); }
}
```

---

## Notes

- All models use `HasTranslations` for JSON name fields
- `$casts` must explicitly cast JSON fields as `'array'`
- Do NOT add any business logic to models
- After creating models, stop. Do not create services yet.
