<?php

namespace App\Models;

use App\Http\Controllers\BillMasterVendorController;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class AccVendor extends Model
{
    use HasFactory;

    protected $guarded = ['id'];

    /**A Supplier is added to the System by a Specific User**/
    public function user(){
        return $this->belongsTo(User::class, 'created_by');
    }

    /**A Supplier belongs to a specific Branch**/
    public function branchDetails(){
        return $this->belongsTo(CompanyBranch::class, 'branch');
    }

    /**A Vendor has many Bill Master Entries**/
    public function billMasterVendor(){
        return $this->hasMany(BillMasterVendor::class, 'vendor_id');
    }
    /**Create a Function that will sum up all the Bill amount for a specific Vendor**/
    public function currentVendorBalance($id){
        return (new BillMasterVendorController)->currentVendorBalance($id);
    }

    /**A Vendor is affiliated to a certain Expense Ledger**/
    public function expenseAccount(){
        return $this->belongsTo(CompanyChartsOfAccount::class, 'ledger_id');
    }

}
