<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Auth;

class BuyCash extends Model
{
    protected $table = "buy_cash";
    protected $fillable = [
        'cash_number','company_id','client_id','safe_id','supplier_id','balance_before','balance_after','amount',
        'bill_id','date','time','notes','reviewed'
    ];
    public function company(){
        return $this->belongsTo('\App\Models\Company','company_id','id');
    }
    public function client(){
        return $this->belongsTo('\App\Models\Client','client_id','id');
    }
    public function supplier(){
        return $this->belongsTo('\App\Models\Supplier','supplier_id','id');
    }
    public function safe(){
        return $this->belongsTo('\App\Models\Safe','safe_id','id');
    }
    public function buybill(){
        return $this->hasOne('\App\Models\BuyBill','buy_bill_number','bill_id')->where('company_id',Auth::user()->company_id);
    }
    public function getCreatedAtAttribute($value){
        return date('Y-m-d', strtotime($value));
    }
}
