<?php

namespace App\Models;

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

class AccBillsManager extends Model
{
    use HasFactory;

    protected $guarded = ['id'];

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

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

    /**A Bill Belongs to a Specific Vendor**/
    public function vendorDetails(){
        return $this->belongsTo(AccVendor::class, 'vendor_id');
    }

    /**A Bill has a Sum of Money paid to it**/
    public function billPaidAmount($id){
        return (new AccBillsManagerController)->billPaidAmount($id);
    }

    /**Create a Function to get the Bill Balance**/
    public function billBalance($id){
        return (new AccBillsManagerController)->billBalance($id);
    }

    /**A Bill has many Documents attached on it**/
    public function documents(){
        return $this->hasMany(DocsBill::class, 'bill_id');
    }
}
