<?php

namespace App\Model\pos;

use App\Model\people\CustomerModel;
use App\User;
use Illuminate\Database\Eloquent\Model;

class SaleModel extends Model
{
    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $table = "nso007_sales";

    protected $fillable = [
        'driver_id',
        'customer_id',
        'user_id',
        'request_by',
        'warehouse_id',
        'rate',
        'rate_baht',
        'invoice_number',
        'year',
        'sale_date',
        'paid_amount_kh',
        'paid_amount_usd',
        'paid_amount_baht',
        'refund_amount',
        'refund_currency',
        'refund_reason',
        'refund_status',
        'discount',
        'payment_status',
        'status',
        'note',
        'return_status',
        'is_role',
        'sale_type',
        'request_type',
        'seen_at',
        'delivery_fee',
        'delivery_note',
        'delivery_phone',
        'delivery_status',
        'done_date',
        'daily_order_number',
        'edited_by',
    ];
    public function customer()
    {
       return $this->hasOne(CustomerModel::class,'id','customer_id');
    }

    public function user()
    {
       return $this->hasOne(User::class,'id','user_id');
    }
    public function user_edit()
    {
       return $this->hasOne(User::class,'id','edited_by');
    }

    public function detail()
    {
        return $this->hasMany(SaleDetailsModel::class,'sale_id','id');
    }

}
