<?php

namespace App\Model\stock_inventory;

use App\Model\product\ColorModel;
use App\Model\product\ProductModel;
use Illuminate\Database\Eloquent\Model;
use App\Model\product\SizeModel;

class TransferStockDetailModel extends Model
{
    protected $table = "nso007_transfer_stock_detail";
    protected $fillable = [ 'size_code', 'color_code', 'barcode'];
    public function getItem()
    {
        $barcode = $this->barcode;
        $product_unit = findProductUnitByCode($barcode,'product');
        return getProductById($product_unit->product_id);
    }
    public function product()
    {
        return $this->hasOne(ProductModel::class,'id','product_id');
    }
    public function getSize()
    {
        return $this->hasOne(SizeModel::class,'code','size_code');
    }
    public function getColor()
    {
        return $this->hasOne(ColorModel::class,'code','color_code');
    }
    public function getUnitName()
    {
        $barcode = $this->barcode;
        $product_unit = findProductUnitByCode($barcode,'product');
        return findUnit($product_unit->unit_id);
    }
}
