<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Product_unit extends Model
{
    use HasFactory;


    public $table = 'product_unit';

    protected $fillable = [
        'company_id',
        'product_id',
        'product_primary_unit_id',
        'secondary_unit_id',
        'quantity',
        'price',
        'barcode',
        'user_id',
    ];

    public $timestamps = false;

    public function product()
    {
        return $this->belongsTo(Product::class,'product_id','id');
    }

    public function primary_unit()
    {
        return $this->belongsTo(Unit::class,'product_primary_unit_id','id');
    }

    public function secondary_unit()
    {
        return $this->belongsTo(Unit::class,'secondary_unit_id','id');
        
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }

    public function company()
    {
        return $this->belongsTo(Company::class,'company_id','id');
    }

    public function buy_bill_elements_unit()
    {
        return $this->belongsTo(BuyBillElement::class,'secondary_unit_id','unit_id');
    }

    public function sale_bill_elements_unit()
    {
        return $this->hasMany(SaleBillElement::class,'secondary_unit_id','unit_id');
    }




}
