<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Supplier extends Model { protected $fillable=['name','company_name','phone','address','currency_id','opening_balance']; public function currency(){return $this->belongsTo(Currency::class);} public function purchases(){return $this->hasMany(Purchase::class);} public function payments(){return $this->hasMany(SupplierPayment::class);} public function balance(){ return $this->opening_balance + $this->purchases()->sum('due_amount') - $this->payments()->sum('amount'); } }
