MOON
Server: Apache
System: Linux 101-53-147-124.cprapid.com 4.18.0-553.121.1.el8_10.x86_64 #1 SMP Thu Apr 30 09:06:34 EDT 2026 x86_64
User: clientsoftwares (1005)
PHP: 8.2.30
Disabled: show_source, system, shell_exec, passthru, exec, popen, proc_open
Upload Files
File: /home/clientsoftwares/public_html/stocky.clientsoftwares.com/app/Models/Order.php
<?php

namespace App\Models;

use App\Casts\Hash;
use App\Classes\Common;
use App\Models\BaseModel;
use App\Scopes\CompanyScope;

class Order extends BaseModel
{
    protected $table = 'orders';

    protected $default = ['xid'];

    protected $guarded = ['id', 'warehouse_id', 'staff_user_id', 'order_type', 'created_at', 'updated_at'];

    protected $hidden = ['id', 'warehouse_id', 'from_warehouse_id', 'user_id', 'tax_id', 'staff_user_id', 'cancelled_by'];

    protected $appends = ['xid', 'x_warehouse_id', 'x_from_warehouse_id', 'x_user_id', 'x_tax_id', 'x_staff_user_id', 'x_cancelled_by', 'document_url'];

    protected $dates = ['order_date'];

    protected $filterable = ['id', 'invoice_number', 'payment_status', 'order_status', 'cancelled', 'order_date', 'user_id', 'warehouse_id', 'staff_user_id'];

    protected $hashableGetterFunctions = [
        'getXWarehouseIdAttribute' => 'warehouse_id',
        'getXFromWarehouseIdAttribute' => 'from_warehouse_id',
        'getXUserIdAttribute' => 'user_id',
        'getXTaxIdAttribute' => 'tax_id',
        'getXStaffUserIdAttribute' => 'staff_user_id',
        'getXCancelledByAttribute' => 'cancelled_by',
    ];

    protected $casts = [
        'order_date' => 'datetime',
        'warehouse_id' => Hash::class . ':hash',
        'user_id' => Hash::class . ':hash',
        'tax_id' => Hash::class . ':hash',
        'cancelled_by' => Hash::class . ':hash',
        'cancelled' => 'integer',
        'is_deletable' => 'integer',
        'tax_rate' => 'double',
        'tax_amount' => 'double',
        'discount' => 'double',
        'shipping' => 'double',
        'subtotal' => 'double',
        'total' => 'double',
        'paid_amount' => 'double',
        'due_amount' => 'double',
        'total_items' => 'double',
        'total_quantity' => 'double',
    ];

    protected static function boot()
    {
        parent::boot();

        static::addGlobalScope(new CompanyScope);
    }

    public function getDocumentUrlAttribute()
    {
        $orderDocumentPath = Common::getFolderPath('orderDocumentPath');

        return $this->image == null ? asset('images/order.png') : Common::getFileUrl($orderDocumentPath, $this->image);
    }

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

    public function orderPayments()
    {
        return $this->hasMany(OrderPayment::class, 'order_id', 'id');
    }

    public function user()
    {
        return $this->belongsTo(StaffMember::class, 'user_id', 'id')->withoutGlobalScope('type');
    }

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

    public function staffMember()
    {
        return $this->belongsTo(StaffMember::class, 'staff_user_id', 'id');
    }

    public function warehouse()
    {
        return $this->belongsTo(Warehouse::class, 'warehouse_id', 'id');
    }

    public function fromWarehouse()
    {
        return $this->belongsTo(Warehouse::class, 'from_warehouse_id', 'id');
    }

    public function tax()
    {
        return $this->belongsTo(Tax::class, 'tax_id', 'id');
    }

    public function shippingAddress()
    {
        return $this->belongsTo(OrderShippingAddress::class, 'id', 'order_id');
    }
}