<?php

namespace App\Model\payment;

use App\Model\CurrencyModel;
use App\Model\people\CustomerModel;
use App\Model\people\SupplierModel;
use App\Model\people\TailorModel;
use App\Model\pos\SaleModel;
use App\Model\production\ProductionRequestModel;
use App\Model\stock_inventory\PurchaseModel;
use App\User;
use Illuminate\Database\Eloquent\Model;

class PaymentModel extends Model
{
    protected $table = 'nso007_payment';
    protected $fillable = [
        'invoice_id',
        'customer_id',
        'supplier_id',
        'packer_id',
        'user_id',
        'tailor_id',
        'payment_invoice',
        'payment_date',
        'payment_amount',
        'paid_amount',
        'paid_usd',
        'currency_id',
        'payment_status',
        'payment_method',
        'type',
        'description',
        'year',
        'status',
        'return_status',
        'note',
    ];

    public function customer()
    {
        return $this->hasOne(CustomerModel::class,'id','customer_id');
    }
    public function supplier()
    {
        return $this->hasOne(SupplierModel::class,'id','supplier_id');
    }
    public function user()
    {
        return $this->hasOne(User::class,'id','user_id');
    }

    public function sale()
    {
        if($this->type!=='purchase'){
            return $this->hasOne(SaleModel::class,'id','invoice_id');
        }else{
            return null;
        }
    }
    public function purchase()
    {
        if($this->type==='purchase') {
            return $this->hasOne(PurchaseModel::class,'id','invoice_id');
        }else{
            return null;
        }
    }

    public function production()
    {
        return $this->hasOne(ProductionRequestModel::class,'id','invoice_id');
    }

    public function tailor()
    {
        return $this->hasOne(TailorModel::class,'id','tailor_id');
    }
    public function currency()
    {
        return $this->hasOne(CurrencyModel::class,'id','currency_id');
    }

    public function detail()
    {
        return $this->hasMany(PaymentDetailModel::class,'payment_id');
    }
}
