belongsTo(Member::class); } public function supplier() { return $this->belongsTo(Supplier::class); } public function payment_method() { return $this->belongsTo(PaymentMethod::class); } public function origin() { return $this->belongsTo(\App\Models\Bank::class, 'origin_id'); } public function destination() { return $this->belongsTo(\App\Models\Bank::class, 'destination_id'); } public function rows() { return $this->hasMany(RecordRow::class); } public function getTotal() { $vat = 0; foreach($this->rows as $r) { if ($r->vat_id > 0) { $v = \App\Models\Vat::where('id', $r->vat_id)->first(); if ($v && $v->value > 0) $vat += $r->amount / 100 * $v->value; } } return $this->rows->sum('amount') + $vat; } }