discount
This commit is contained in:
@ -15,6 +15,13 @@ class Bill extends Model
|
||||
|
||||
protected $table = 'bills';
|
||||
|
||||
/**
|
||||
* The accessors to append to the model's array form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $appends = ['attachment', 'discount'];
|
||||
|
||||
protected $dates = ['deleted_at', 'billed_at', 'due_at'];
|
||||
|
||||
/**
|
||||
@ -155,4 +162,26 @@ class Bill extends Model
|
||||
|
||||
return $this->getMedia('attachment')->last();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the discount percentage.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getDiscountAttribute()
|
||||
{
|
||||
$discount = 0;
|
||||
|
||||
foreach ($this->totals as $total) {
|
||||
if ($total->code != 'discount') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$discount = number_format((($total->amount * 100) / $this->amount), 0);
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
return $discount;
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Models\Expense;
|
||||
|
||||
use App\Models\Model;
|
||||
use App\Models\Setting\Tax;
|
||||
use App\Traits\DateTime;
|
||||
|
||||
class BillTotal extends Model
|
||||
@ -33,4 +34,45 @@ class BillTotal 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->bill->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