<?php

namespace App\Models;

use App\Models\Concerns\BranchScoped;

use Illuminate\Database\Eloquent\Model;

class VanSession extends Model
{
    use BranchScoped;
    protected $fillable = ['session_no', 'warehouse_id', 'branch_id', 'salesman_id', 'driver_name', 'route', 'session_date', 'opening_odometer', 'closing_odometer', 'starting_cash', 'expected_cash', 'actual_cash', 'cash_difference', 'status', 'started_at', 'closed_at', 'closed_by'];
    protected $casts = ['session_date' => 'date', 'started_at' => 'datetime', 'closed_at' => 'datetime', 'opening_odometer' => 'decimal:2', 'closing_odometer' => 'decimal:2', 'starting_cash' => 'decimal:2', 'expected_cash' => 'decimal:2', 'actual_cash' => 'decimal:2', 'cash_difference' => 'decimal:2'];
    public function warehouse() { return $this->belongsTo(Warehouse::class); }
    public function branch() { return $this->belongsTo(Branch::class); }
    public function salesman() { return $this->belongsTo(User::class, 'salesman_id'); }
    public function sales() { return $this->hasMany(Sale::class); }
    public function loadings() { return $this->hasMany(VanLoading::class); }
    public function closing() { return $this->hasOne(VanClosing::class); }
}
