discount
This commit is contained in:
@ -3,6 +3,7 @@
|
||||
namespace App\Models\Income;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Models\Setting\Tax;
|
||||
use App\Traits\DateTime;
|
||||
|
||||
class InvoiceTotal extends Model
|
||||
@ -33,4 +34,45 @@ class InvoiceTotal extends Model
|
||||
{
|
||||
$this->attributes['amount'] = (double) $value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the formatted name.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getNameAttribute($value)
|
||||
{
|
||||
$name = $value;
|
||||
|
||||
$percent = 0;
|
||||
|
||||
// Discount
|
||||
if ($this->code == 'discount') {
|
||||
$name = trans($name);
|
||||
$percent = $this->invoice->discount;
|
||||
}
|
||||
|
||||
// Tax
|
||||
if ($this->code == 'tax') {
|
||||
$rate = Tax::where('name', $name)->value('rate');
|
||||
|
||||
if (!empty($rate)) {
|
||||
$percent = $rate;
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($percent)) {
|
||||
$name .= ' (';
|
||||
|
||||
if (setting('general.percent_position', 'after') == 'after') {
|
||||
$name .= $percent . '%';
|
||||
} else {
|
||||
$name .= '%' . $percent;
|
||||
}
|
||||
|
||||
$name .= ')';
|
||||
}
|
||||
|
||||
return $name;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user