HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: /home/xedaptot/be.naniguide.com/app/Model/InvoiceItem.php
<?php

namespace Acelle\Model;

use Illuminate\Database\Eloquent\Model;
use Acelle\Library\Traits\HasUid;

class InvoiceItem extends Model
{
    use HasUid;
    protected $connection = 'mysql';

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $fillable = [
        'item_id', 'item_type', 'amount', 'title', 'description'
    ];

    /**
     * Invoice.
     */
    public function invoice()
    {
        return $this->belongsTo('Acelle\Model\Invoice');
    }

    /**
     * Tax percent.
     *
     * @return void
     */
    public function getTaxPercent()
    {
        if ($this->invoice->billing_country_id) {
            $country = \Acelle\Model\Country::find($this->invoice->billing_country_id);
            $tax = \Acelle\Model\Setting::getTaxByCountry($country);
        } else {
            $tax = \Acelle\Model\Setting::getTaxByCountry(null);
        }

        return $tax;
    }

    /**
     * Tax amount.
     *
     * @return void
     */
    public function getTax()
    {
        $tax = $this->getTaxPercent();

        return ($this->subTotal() * ($tax / 100));
    }

    public function subTotal()
    {
        return $this->amount - $this->discount;
    }

    /**
     * Total amount.
     *
     * @return void
     */
    public function total()
    {
        return $this->subTotal() + $this->getTax();
    }
}