HEX
Server: Microsoft-IIS/8.5
System: Windows NT YDAWBH120 6.3 build 9600 (Windows Server 2012 R2 Standard Edition) AMD64
User: tentjecom_web (0)
PHP: 7.4.14
Disabled: NONE
Upload Files
File: D:/HostingSpaces/SBogers10/netwerkbrabant.komma.pro/app/KommaApp/Orders/Models/Order.php
<?php


namespace App\KommaApp\Orders\Models;

use App\KommaApp\Countries\Models\Country;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;


class Order extends Model
{

    protected $table = 'orders';
    protected $class = Order::class;

    const OPEN = 0;
    const AWAITING_PAYMENT = 1;
    const PAID = 2;
    const CANCELED = 3;

    const PAYMENT_TERM_DAYS = 14;

    protected $guarded = [
        'id',
        'invoice_id',
        'invoice_id_prefixed',
        'status',
    ];

    /**
     * Get get products of this order
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function products() : HasMany
    {
        return $this->hasMany(OrderProduct::class);
    }

    /**
     * Get the payments created by this orders
     *
     * @return HasMany
     */
    public function payments() : hasMany
    {
        return $this->hasMany(OrderPayment::class);
    }

    /**
     * Get the formatted price for with or without vat
     *
     * @param bool $vat
     * @param string $decPoint
     * @param string $thousandsSept
     * @param int $decimals
     * @return string
     */
    public function getFormattedPrice($vat = true, $decPoint = '.', $thousandsSept = '', $decimals = 2){
        if($vat) return number_format($this->price_including_vat / 100, $decimals, $decPoint, $thousandsSept);
        return number_format($this->price / 100, $decimals, $decPoint, $thousandsSept);
    }

    /**
     * Get the vat amount of the order
     *
     * @param string $decPoint
     * @param string $thousandsSept
     * @param int $decimals
     * @return string
     */
    public function getFormattedVat($decPoint = '.', $thousandsSept = '', $decimals = 2)
    {
        $vat = $this->price_including_vat - $this->price;
        return number_format($vat / 100, $decimals, $decPoint, $thousandsSept);
    }

    /**
     * Get the date with the amount of payment term days added to it
     *
     * @return mixed
     */
    public function getPaymentExpireDate(){
        return $this->created_at->addDays($this::PAYMENT_TERM_DAYS);
    }
}