| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- <?php
- declare(strict_types=1);
- namespace App\Models;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- class StockMovement extends Model
- {
- public const TYPE_RECEIPT = 'receipt';
- public const TYPE_RESERVE = 'reserve';
- public const TYPE_ISSUE = 'issue';
- public const TYPE_RESERVE_CANCEL = 'reserve_cancel';
- public const TYPE_NAMES = [
- self::TYPE_RECEIPT => 'Поступление',
- self::TYPE_RESERVE => 'Бронирование',
- self::TYPE_ISSUE => 'Списание',
- self::TYPE_RESERVE_CANCEL => 'Отмена брони',
- ];
- protected $fillable = [
- 'common_catalog_item_id',
- 'stock_order_id',
- 'stock_reservation_id',
- 'movement_type',
- 'quantity',
- 'user_id',
- 'note',
- ];
- protected function casts(): array
- {
- return [
- 'common_catalog_item_id' => 'integer',
- 'stock_order_id' => 'integer',
- 'stock_reservation_id' => 'integer',
- 'quantity' => 'integer',
- 'user_id' => 'integer',
- ];
- }
- 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 reservation(): BelongsTo
- {
- return $this->belongsTo(StockReservation::class, 'stock_reservation_id');
- }
- public function user(): BelongsTo
- {
- return $this->belongsTo(User::class);
- }
- public function getTypeNameAttribute(): string
- {
- return self::TYPE_NAMES[$this->movement_type] ?? $this->movement_type;
- }
- }
|