'integer', 'branch_id' => 'integer', 'with_installation' => 'boolean', 'with_didox' => 'boolean', 'shipment_date' => 'datetime', 'accepted_at' => 'datetime', 'address_id' => 'integer', 'archived' => 'boolean', ]; protected static $logName = 'orders'; protected static $logOnlyDirty = true; protected static $logAttributes = [ 'full_name', 'phone', 'legal_id', 'address_id', 'with_installation', 'client_type', 'payment_type', 'with_didox', 'delivery_type', 'shipment_date', 'accepted_at', 'currency', 'status', 'payment_status', 'archived', ]; protected static $submitEmptyLogs = false; public static function statuses() { return [ 'processing', 'collected', 'waiting_buyer', 'in_way', 'closed', 'cancelled', 'replacement', 'completed' ]; } public static function paymentStatuses() { return [ 'waiting', 'cancelled', 'payed', 'cash', 'review' ]; } public static function paymentTypes() { return [ 'bank', 'cash', 'click', 'payme', ]; } public static function clientTypes() { return [ 'physical', 'legal', ]; } public static function deliveryTypes() { return [ 'delivery', 'pickup', ]; } public function getStatus() { return $this->belongsTo(Status::class, 'status', 'slug'); } public function contracts(): HasMany { return $this->hasMany(OrderContract::class, 'order_id', 'id'); } public function getCurrency(): BelongsTo { return $this->belongsTo(Currency::class, 'currency', 'id'); } public function getPaymentStatus() { return $this->belongsTo(Status::class, 'payment_status', 'slug'); } public function user(): BelongsTo { return $this->belongsTo(User::class); } public function address(): BelongsTo { return $this->belongsTo(Address::class, 'address_id', 'id'); } public function comments(): HasMany { return $this->hasMany(OrdersComment::class, 'order_id', 'id'); } public function legalInfo(): BelongsTo { return $this->belongsTo(UserLegalInfo::class, 'legal_id', 'id'); } public function products(): HasMany { return $this->hasMany(OrderProducts::class, 'order_id', 'id'); } public function branch(): BelongsTo { return $this->belongsTo(Branch::class); } public function getProductsPrice() { return $this->products->sum('total_price'); } public function billing() { return $this->hasOne(Billing::class); } }