| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- declare(strict_types=1);
- namespace App\Models;
- use App\Enums\ProductionOrderExecutionType;
- use App\Enums\ProductionOrderSource;
- use App\Enums\ProductionOrderStatus;
- use Database\Factories\ProductionOrderFactory;
- use Illuminate\Database\Eloquent\Factories\HasFactory;
- use Illuminate\Database\Eloquent\Model;
- use Illuminate\Database\Eloquent\Relations\BelongsTo;
- use Illuminate\Database\Eloquent\Relations\HasMany;
- use Illuminate\Database\Eloquent\SoftDeletes;
- class ProductionOrder extends Model
- {
- /** @use HasFactory<ProductionOrderFactory> */
- use HasFactory;
- use SoftDeletes;
- public const DEFAULT_SORT_BY = 'created_at';
- public const DEFAULT_ORDER_BY = 'desc';
- protected $fillable = [
- 'external_id',
- 'source',
- 'order_number',
- 'order_year',
- 'customer_name',
- 'object_address',
- 'invoice_number',
- 'invoice_date',
- 'contract_number',
- 'contract_date',
- 'payment_date',
- 'supply_working_days',
- 'contract_shipment_date',
- 'application_shipment_date',
- 'status',
- 'execution_type',
- 'manager_id',
- 'note',
- 'created_by',
- 'updated_by',
- ];
- protected function casts(): array
- {
- return [
- 'source' => ProductionOrderSource::class,
- 'order_year' => 'integer',
- 'invoice_date' => 'immutable_date',
- 'contract_date' => 'immutable_date',
- 'payment_date' => 'immutable_date',
- 'supply_working_days' => 'integer',
- 'contract_shipment_date' => 'immutable_date',
- 'application_shipment_date' => 'immutable_date',
- 'status' => ProductionOrderStatus::class,
- 'execution_type' => ProductionOrderExecutionType::class,
- 'manager_id' => 'integer',
- 'created_by' => 'integer',
- 'updated_by' => 'integer',
- ];
- }
- public function manager(): BelongsTo
- {
- return $this->belongsTo(User::class, 'manager_id');
- }
- public function creator(): BelongsTo
- {
- return $this->belongsTo(User::class, 'created_by');
- }
- public function updater(): BelongsTo
- {
- return $this->belongsTo(User::class, 'updated_by');
- }
- public function items(): HasMany
- {
- return $this->hasMany(ProductionOrderItem::class)->orderBy('sort')->orderBy('id');
- }
- public function deliveries(): HasMany
- {
- return $this->hasMany(ProductionOrderDelivery::class)->orderBy('delivery_date')->orderBy('id');
- }
- public function installations(): HasMany
- {
- return $this->hasMany(ProductionOrderInstallation::class)->orderBy('installation_date')->orderBy('id');
- }
- public function activities(): HasMany
- {
- return $this->hasMany(ProductionOrderActivity::class)->latest('created_at')->latest('id');
- }
- public function statusLabel(): string
- {
- return $this->status->label();
- }
- public function executionTypeLabel(): string
- {
- return $this->execution_type->label();
- }
- public function getStatusNameAttribute(): string
- {
- return $this->statusLabel();
- }
- public function getExecutionTypeNameAttribute(): string
- {
- return $this->executionTypeLabel();
- }
- }
|