<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Quotation extends Model
{
    protected $table = "quotations";
    protected $fillable = [
        'company_id','client_id','outer_client_id','quotation_number','date','time','deleted','final_total','status'
    ];
    public function elements(){
        return $this->hasMany('\App\Models\QuotationElement','quotation_id','id');
    }
    public function extras(){
        return $this->hasMany('\App\Models\SaleBillExtra','sale_bill_id','id');
    }
    public function extra(){
        return $this->hasOne('\App\Models\QuotationExtra','quotation_id','id')->where('action','extra');
    }
    public function discount(){
        return $this->hasOne('\App\Models\QuotationExtra','quotation_id','id')->where('action','discount');
    }
    public function company(){
        return $this->belongsTo('\App\Models\Company','company_id','id');
    }
    public function outerClient(){
        return $this->belongsTo('\App\Models\OuterClient','outer_client_id','id');
    }
    public function client(){
        return $this->belongsTo('\App\Models\Client','client_id','id');
    }

    public function scopeActive($query){
        return $query->where('deleted',0);
    }
}
