File: /var/www/ipsremont-demo/app/Models/WorkCompleteCertificate.php
<?php
namespace App\Models;
use App\Models\Repair\Repair;
use App\Traits\My;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
/**
* @property int $id
* @property int $repair_id
* @property string $work_description
* @property string $serial_number
* @property string $device_name
* @property string $client
* @property string $executor
* @property int $result
* @property bool $is_updated
* @property string $created_at
* @property string $updated_at
* @property ?string $deleted_at
*
* @property Repair $repair
* @property Collection|WorkCompleteCertificateItem[] $workCompleteCertificateItems
* @property Collection|WorkCompleteCertificateChangeLog[] $workCompleteCertificateChangeLogs
*/
class WorkCompleteCertificate extends BaseModel
{
use SoftDeletes, My;
public const RESULT_SUCCESS = 1;
public const RESULT_REJECT = 2;
protected $table = 'work_complete_certificates';
protected $fillable = [
'serial_number',
'device_name',
'client',
'executor',
'result',
'repair_id',
'work_description',
'is_updated',
];
protected static $labels = [
'repair_id' => 'wcc.repair_id',
'work_description' => 'wcc.work_description',
'is_updated' => 'wcc.is_updated',
'executor' => 'wcc.executor',
'client' => 'wcc.client',
'serial_number' => 'wcc.serial_number',
'device_name' => 'wcc.device_name',
'result' => 'wcc.result',
];
public static array $resultText = [
self::RESULT_SUCCESS => 'Устройство отремонтировано и технически исправно. Вышеперечисленные услуги выполнены полностью и в срок. Заказчик по объёму, качеству и срокам оказания услуг претензий не имеет.',
self::RESULT_REJECT => 'По результатам диагностики в гарантийном ремонте отказано. Гарантия не распространяется на неисправности устройства, вызванные несоблюдением инструкции по эксплуатации. Заказчик от ремонта отказался. Устройство выдано без ремонта, в собранном виде, в комплектации на момент приёмки в ремонт.',
];
public function getResultText(): string
{
return self::$resultText[$this->result] ?? 'Не выбрано';
}
// MARK: - Relations
public function repair(): BelongsTo
{
return $this->belongsTo(Repair::class);
}
public function getClient(): string
{
return htmlspecialchars_decode($this->client);
}
public function getExecutor(): string
{
return htmlspecialchars_decode($this->executor);
}
public function workCompleteCertificateItems(): HasMany
{
return $this->hasMany(WorkCompleteCertificateItem::class);
}
public function workCompleteCertificateChangeLogs(): HasMany
{
return $this->hasMany(WorkCompleteCertificateChangeLog::class)->orderBy('work_complete_certificate_change_logs.id', 'desc');
}
public function isAllowPdf(): bool
{
return in_array($this->repair->status, [Repair::STATUS_COMPLETED, Repair::STATUS_REPORT], true);
}
/**
* @return OrderItems[]
*/
public function parts(): array
{
$parts = [];
foreach ($this->repair->orders as $order) {
$parts = array_merge($parts, $order->order_items()->get()->all());
}
return $parts;
}
}