| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- <?php
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\BelongsToMany;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- class Reclamation extends Model
- {
- const DEFAULT_SORT_BY = 'created_at';
- const STATUS_NEW = 1;
- const STATUS_WAIT = 2;
- const STATUS_IN_WORK = 3;
- const STATUS_SUBSCRIBE_ACT = 4;
- const STATUS_DONE = 5;
- const STATUS_SENT = 6;
- const STATUS_DO_DOCS = 7;
- const STATUS_HANDOVER_TO_CHECK = 8;
- const STATUS_PAID = 9;
- const STATUS_CLOSED_NO_PAY = 10;
- const STATUS_NAMES = [
- self::STATUS_NEW => 'Новая',
- self::STATUS_WAIT => 'В ожидании',
- self::STATUS_IN_WORK => 'В работе',
- self::STATUS_SUBSCRIBE_ACT => 'Подпись акта',
- self::STATUS_DONE => 'Исправлена',
- self::STATUS_SENT => 'Отправлена',
- self::STATUS_DO_DOCS => 'Подготовка документов',
- self::STATUS_HANDOVER_TO_CHECK => 'Передана на проверку',
- self::STATUS_PAID => 'Оплачена',
- self::STATUS_CLOSED_NO_PAY => 'Закрыта, не оплачивается',
- ];
- protected $fillable = [
- 'order_id',
- 'user_id',
- 'status_id',
- 'reason',
- 'guarantee',
- 'whats_done',
- 'create_date',
- 'finish_date',
- 'start_work_date',
- 'work_days',
- 'brigadier_id',
- 'comment',
- ];
- public function order(): BelongsTo
- {
- return $this->belongsTo(Order::class)->withoutGlobalScopes();
- }
- public function status(): BelongsTo
- {
- return $this->belongsTo(ReclamationStatus::class);
- }
- public function skus(): BelongsToMany
- {
- return $this->belongsToMany(
- ProductSKU::class,
- 'reclamation_product_sku',
- 'reclamation_id',
- 'product_sku_id')
- ->withoutGlobalScopes();
- }
- public function user(): BelongsTo
- {
- return $this->belongsTo(User::class);
- }
- public function brigadier(): BelongsTo
- {
- return $this->belongsTo(User::class, 'brigadier_id', 'id');
- }
- public function photos_before(): BelongsToMany
- {
- return $this->belongsToMany(File::class, 'reclamation_photo_before');
- }
- public function photos_after(): BelongsToMany
- {
- return $this->belongsToMany(File::class, 'reclamation_photo_after');
- }
- public function documents(): BelongsToMany
- {
- return $this->belongsToMany(File::class, 'reclamation_document');
- }
- public function acts(): BelongsToMany
- {
- return $this->belongsToMany(File::class, 'reclamation_act');
- }
- public function details(): HasMany
- {
- return $this->hasMany(ReclamationDetail::class);
- }
- public function spareParts(): BelongsToMany
- {
- return $this->belongsToMany(SparePart::class, 'reclamation_spare_part')
- ->withPivot('quantity', 'with_documents', 'status', 'reserved_qty', 'issued_qty')
- ->withTimestamps();
- }
- /**
- * Резервы запчастей для этой рекламации
- */
- public function sparePartReservations(): HasMany
- {
- return $this->hasMany(Reservation::class);
- }
- /**
- * Дефициты запчастей для этой рекламации
- */
- public function sparePartShortages(): HasMany
- {
- return $this->hasMany(Shortage::class);
- }
- /**
- * Активные резервы запчастей
- */
- public function activeReservations(): HasMany
- {
- return $this->hasMany(Reservation::class)->where('status', Reservation::STATUS_ACTIVE);
- }
- /**
- * Открытые дефициты запчастей
- */
- public function openShortages(): HasMany
- {
- return $this->hasMany(Shortage::class)->where('status', Shortage::STATUS_OPEN);
- }
- }
|