| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- declare(strict_types=1);
- namespace App\Models;
- use Illuminate\Database\Eloquent\Builder;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- class StockReservation extends Model
- {
- public const STATUS_ACTIVE = 'active';
- public const STATUS_ISSUED = 'issued';
- public const STATUS_CANCELLED = 'cancelled';
- public const STATUS_NAMES = [
- self::STATUS_ACTIVE => 'Забронировано',
- self::STATUS_ISSUED => 'Списано',
- self::STATUS_CANCELLED => 'Отменено',
- ];
- protected $fillable = [
- 'common_catalog_item_id',
- 'stock_order_id',
- 'manager_id',
- 'quantity',
- 'status',
- 'note',
- 'created_by',
- 'issued_at',
- 'cancelled_at',
- ];
- protected function casts(): array
- {
- return [
- 'common_catalog_item_id' => 'integer',
- 'stock_order_id' => 'integer',
- 'manager_id' => 'integer',
- 'quantity' => 'integer',
- 'created_by' => 'integer',
- 'issued_at' => 'datetime',
- 'cancelled_at' => 'datetime',
- ];
- }
- public function item(): BelongsTo
- {
- return $this->belongsTo(CommonCatalogItem::class, 'common_catalog_item_id');
- }
- public function order(): BelongsTo
- {
- return $this->belongsTo(StockOrder::class, 'stock_order_id');
- }
- public function manager(): BelongsTo
- {
- return $this->belongsTo(User::class, 'manager_id');
- }
- public function creator(): BelongsTo
- {
- return $this->belongsTo(User::class, 'created_by');
- }
- public function scopeActive(Builder $query): Builder
- {
- return $query->where('status', self::STATUS_ACTIVE);
- }
- public function isActive(): bool
- {
- return $this->status === self::STATUS_ACTIVE;
- }
- }
|