belongsTo('App\Models\Expense\Bill'); } /** * Convert amount to double. * * @param string $value * @return void */ public function setAmountAttribute($value) { $this->attributes['amount'] = (double) $value; } /** * Get the formatted name. * * @return string */ public function getTitleAttribute() { $title = $this->name; $percent = 0; $tax = null; switch ($this->code) { case 'discount': $title = trans($title); $percent = $this->bill->discount; break; case 'tax': $tax = Tax::where('name', $title)->first(); if (!empty($tax->rate)) { $percent = $tax->rate; } break; } if (!empty($percent)) { $title .= ' ('; if (setting('localisation.percent_position', 'after') == 'after') { $title .= ($this->code == 'discount') ? false : (($tax->type == 'fixed') ? $percent : $percent . '%'); } else { $title .= ($this->code == 'discount') ? false : (($tax->type == 'fixed') ? $percent : '%' . $percent); } $title .= ')'; } return $title; } }