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/rentpix.corals.io/Corals/modules/RentPix/Models/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/rentpix.corals.io/Corals/modules/RentPix/Models/Inspection.php
<?php

namespace Corals\Modules\RentPix\Models;

use Corals\Foundation\Models\BaseModel;
use Corals\Foundation\Traits\ModelUniqueCode;
use Corals\Foundation\Transformers\PresentableTrait;
use Corals\Modules\RentPix\Constants\InspectionStatus;
use Corals\Modules\RentPix\Constants\InspectionTypeConstants;
use Corals\Modules\Utility\Traits\Comment\ModelHasComments;
use Corals\Modules\Utility\Traits\Gallery\ModelHasGallery;
use Corals\User\Models\User;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\MediaLibrary\HasMedia;
use Spatie\MediaLibrary\InteractsWithMedia;
use Spatie\MediaLibrary\MediaCollections\Models\Media;

class Inspection extends BaseModel implements HasMedia
{
    use PresentableTrait, LogsActivity, ModelUniqueCode, ModelHasGallery, InteractsWithMedia, SoftDeletes, ModelHasComments;

    public function registerMediaConversions(Media $media = null): void
    {
        $this->addMediaConversion('thumb')
            ->width(300)
            ->height(300)
            ->sharpen(10);
    }

    public $galleryMediaCollection = 'rentPix-inspection-gallery';

    public static $codePrefix = 'I';

    /**
     *  Model configuration.
     *
     * @var string
     */
    public $config = 'rentPix.models.inspection';

    protected $casts = [
        'properties' => 'json',
        'type' => InspectionTypeConstants::class,
        'status' => InspectionStatus::class,
    ];

    protected $table = 'pix_inspections';

    protected $guarded = ['id'];

    public function unit()
    {
        return $this->belongsTo(Unit::class);
    }

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

    public function reservation()
    {
        return $this->belongsTo(Reservation::class);
    }

    public static function getInspectionCode($reservation, $type)
    {
        $seq = Inspection::query()
            ->where('reservation_id', $reservation->id)
            ->where('type', $type)
            ->count();

        if ($seq) {
            if ($type == 'start' || 'end') {
                $type = 'update';
            }
            $seq = Inspection::query()
                ->where('reservation_id', $reservation->id)
                ->where('type', $type)
                ->count();

            $seq = ($type == 'update') ? $seq + 1 : $seq;
        }

        $code = strtoupper(trim(sprintf('%s-%s-%s', $reservation->code, ucfirst($type), $seq ?: ''), '-'));

        return [
            'code' => $code,
            'type' => $type,
        ];
    }

    /**
     * @param $fullPath
     * @return string
     */
    public function getPdfFileName()
    {
        $fileName = sprintf('%s_%s.pdf', $this->code, getCurrentTimeForFileName());

        return $fileName;
    }

    public function drivers()
    {
        return $this->belongsToMany(Driver::class, 'pix_driver_inspection')
            ->withTimestamps()
            ->withPivot(['properties', 'is_primary'])
            ->orderBy('is_primary', 'desc');
    }

    public function altDrivers()
    {
        return $this->belongsToMany(AltDriver::class, 'pix_alt_driver_inspection', 'inspection_id', 'driver_id')
            ->withTimestamps()
            ->withPivot(['properties', 'is_primary'])
            ->orderBy('is_primary', 'desc');
    }

    public function getIsDriverRequiredAttribute(): bool
    {
        return false;
//        return $this->type->value === InspectionTypeConstants::START->value;
    }

    public function failedInspection()
    {
        return $this->hasMany(FailedInspection::class);
    }
}

Spamworldpro Mini