<?php

namespace App\Models;

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

class Cash extends Model
{
    protected $table = "cash";
    protected $fillable = [
        'cash_number','company_id','client_id','safe_id','outer_client_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 outerClient(){
        return $this->belongsTo('\App\Models\OuterClient','outer_client_id','id');
    }
    public function safe(){
        return $this->belongsTo('\App\Models\Safe','safe_id','id');
    }
    public function salebill(){
        return $this->hasOne('\App\Models\SaleBill','sale_bill_number','bill_id')->where('company_id',Auth::user()->company_id);
    }
    public function salebillelements(){
        return $this->hasMany('\App\Models\SaleBillElement','sale_bill_id','id');
    }
    public function getCreatedAtAttribute($value){
        return date('Y-m-d', strtotime($value));
    }

}
