<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Supplier extends Model
{

    protected $table = 'supplier';
    
    protected $fillable = [
        'name','supplier_type_id','delivery_type_id','address','credit_period','credit_limit','status_id','payment_type_id','currency_type_id','shipping_terms','contact_no1','contact_p1','email1','contact_no2','contact_p2','email2','office_id','sup_code','country_id'
    ];

    public $timestamps = false;

    public function status()
    {
    	return $this->belongsTo('App\Common','status_id');
    }

    public function delivery()
    {
    	return $this->belongsTo('App\Common','delivery_type_id');
    }

    public function pay()
    {
    	return $this->belongsTo('App\Common','payment_type_id');
    }

    public function products()
    {
        return $this->hasMany('App\SupplierProduct','supplier_id');
    }

    public function supplierRate()
    {
        return $this->hasMany('App\SupplierRateEntry');
    }
    
    public function supplierCurrency()
    {
        return $this->belongsTo('App\Currency','currency_type_id');
    }

    public function office()
    {
        return $this->belongsTo('App\Office','office_id');
    }
}
