<?php

namespace App\Models\Orders;

use App\Models\ItemDb;
use App\Models\Orders\SalesOrder;
use Illuminate\Database\Eloquent\Model;

class SalesOrderDetail extends Model
{
    protected $table = 'sale_orders_detail';
    protected $fillable = [
        "order_item_id",
        "order_id",
        "item_id",
        "status_id",
        "item_price",
        "discount",
        "full_price",
        "shipping_amount",
        "tax_amount",
        "status_own",
        "log",
        'force_location'
    ];

    public function order()
    {
        return $this->belongsTo(SalesOrder::class);
    }
    public function item()
    {
        return $this->belongsTo(ItemDb::class, 'item_id', 'DefaultBarcode');
    }
    public function status()
    {
        return $this->belongsTo(Status::class);
    }
    public function billing()
    {
        return $this->belongsTo(SalesBilling::class, 'id', 'order_item_id',);
    }
    public function separate()
    {
        return $this->belongsTo(SalesSeparated::class, 'id', 'order_item_id')
            ->where('status', 1);
    }
    public function separateLog()
    {
        return $this->hasMany(SalesSeparatedLog::class, 'order_item_id', 'id');
    }
    public function logistic()
    {
        return $this->belongsTo(SalesLogistic::class, 'id' , 'order_item_id');
    }
    public function shipping()
    {
        return $this->belongsTo(SalesDelivery::class, 'id', 'order_item_id');
    }
    public function comments()
    {
        return $this->hasmany(SaleCommits::class, 'order_item_id', 'id');
    }
}
