Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/inventory.corals.io/Corals/modules/Inventory/Models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/inventory.corals.io/Corals/modules/Inventory/Models/Order.php
<?php

namespace Corals\Modules\Inventory\Models;

use Corals\Foundation\Models\BaseModel;
use Corals\Foundation\Traits\ModelPropertiesTrait;
use Corals\Foundation\Traits\ModelUniqueCode;
use Corals\Foundation\Transformers\PresentableTrait;
use Corals\Modules\Payment\Common\Models\Invoice;
use Corals\Modules\Payment\Common\Models\Transaction as PaymentTransaction;
use Corals\User\Models\User;
use Spatie\Activitylog\Traits\LogsActivity;


class Order extends BaseModel
{
    use PresentableTrait, LogsActivity, ModelUniqueCode, ModelPropertiesTrait;

    protected $table = 'inv_orders';

    /**
     *  Model configuration.
     * @var string
     */
    public $config = 'inventory.models.order';

    protected static $logAttributes = [
        'status',
        'number',
        'sub_total',
        'billing',
        'user_id',
        'discount_total',
        'currency',
        'adjustment_total'
    ];

    protected $casts = [
        'properties' => 'json',
        'billing' => 'array',
        'shipping' => 'array',
    ];

    protected $guarded = ['id'];

    public function inventory()
    {
        return $this->belongsTo(Inventory::class);
    }

    public function items()
    {
        return $this->hasMany(OrderItem::class);
    }

    public function invoice()
    {
        return $this->morphOne(Invoice::class, 'invoicable');
    }

    public function user()
    {
        return $this->belongsTo(User::class);
    }


    public function supplier()
    {
        return $this->belongsTo(Supplier::class);
    }


    public function transaction()
    {
        return $this->belongsTo(Transaction::class);
    }

    public function getInvoiceReference($target = "dashboard")
    {
        $number = $this->number;
        if ($target == "pdf") {
            return $number;
        } else {
            return "<a href='" . url('inv/orders/' . $this->hashed_id) . "'> $number </a>";
        }
    }

    public function getTaxAmount()
    {
        $discount_items = $this->items()->where('type', 'Tax')->get();
        return $discount_items ? $discount_items->sum('amount') : 0.0;
    }


    public function getRemainingAmountAttribute()
    {
        $paid_amount = $this->paymentTransactions()
            ->where('status', 'completed')
            ->sum('paid_amount');

        return $this->total - $paid_amount;
    }

    public function inventoryTransactions()
    {
        return $this->morphMany(Transaction::class, 'sourcable');
    }

    public function paymentTransactions()
    {
        return $this->morphMany(PaymentTransaction::class, 'sourcable');
    }

    public function getTransactionSource()
    {
        $number = $this->number;
        return "<a target='_blank' href='" . url('inv/orders/' . $this->hashed_id) . "'>  $number </a>";
    }

    public function scopeSalesOrder($query)
    {
        return $query->where('type', '=', 'sales_order');
    }

    public function scopeInventoryOrder($query)
    {
        return $query->where('type', '=', 'inventory_order');
    }
}

Spamworldpro Mini