10, 'number' => 10, 'bank_name' => 10, 'bank_phone' => 5, 'bank_address' => 2, ]; public function currency() { return $this->belongsTo('App\Models\Setting\Currency', 'currency_code', 'code'); } public function invoice_payments() { return $this->hasMany('App\Models\Income\InvoicePayment'); } public function revenues() { return $this->hasMany('App\Models\Income\Revenue'); } public function bill_payments() { return $this->hasMany('App\Models\Expense\BillPayment'); } public function payments() { return $this->hasMany('App\Models\Expense\Payment'); } /** * Convert opening balance to double. * * @param string $value * @return void */ public function setOpeningBalanceAttribute($value) { $this->attributes['opening_balance'] = (double) $value; } /** * Get the current balance. * * @return string */ public function getBalanceAttribute() { // Opening Balance $total = $this->opening_balance; // Sum Incomes $total += $this->invoice_payments()->sum('amount') + $this->revenues()->sum('amount'); // Subtract Expenses $total -= $this->bill_payments()->sum('amount') + $this->payments()->sum('amount'); return $total; } }