belongsTo('App\Models\Sale\Invoice'); } public function scopeCode($query, $code) { return $query->where('code', '=', $code); } /** * 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->invoice->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') ? $percent. '%' : (($tax->type == 'fixed') ? $percent : $percent . '%'); } else { $title .= ($this->code == 'discount') ? '%' .$percent : (($tax->type == 'fixed') ? $percent : '%' . $percent); } $title .= ')'; } return $title; } }