77 lines
2.4 KiB
PHP
77 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Modules\Sales\Infrastructure\Persistence\Eloquent;
|
|
|
|
use App\Modules\Sales\Domain\Enums\PaymentMethod;
|
|
use Database\Factories\QuickSaleFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
|
use Illuminate\Database\Eloquent\Attributes\Table;
|
|
use Illuminate\Database\Eloquent\Attributes\UseFactory;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
/**
|
|
* Persistence model, used only inside the Sales Infrastructure layer.
|
|
*
|
|
* @property int $id
|
|
* @property int $user_id
|
|
* @property int|null $customer_id
|
|
* @property PaymentMethod $payment_method
|
|
* @property Carbon $sold_at
|
|
* @property string $sold_on Y-m-d
|
|
* @property int $total_cents
|
|
* @property int|null $credits_quick_sale_id
|
|
* @property string|null $receipt_email
|
|
* @property int|null $quick_sale_order_id
|
|
* @property Carbon|null $receipt_sent_at
|
|
* @property Carbon|null $receipt_send_failed_at
|
|
*/
|
|
#[Table('quick_sales')]
|
|
#[Fillable(['user_id', 'customer_id', 'payment_method', 'sold_at', 'sold_on', 'total_cents', 'credits_quick_sale_id', 'receipt_email', 'quick_sale_order_id'])]
|
|
#[Hidden(['receipt_email'])]
|
|
#[UseFactory(QuickSaleFactory::class)]
|
|
class QuickSaleModel extends Model
|
|
{
|
|
/** @use HasFactory<QuickSaleFactory> */
|
|
use HasFactory;
|
|
|
|
/**
|
|
* @return HasMany<QuickSaleLineModel, $this>
|
|
*/
|
|
public function lines(): HasMany
|
|
{
|
|
return $this->hasMany(QuickSaleLineModel::class, 'quick_sale_id')->orderBy('sort_order');
|
|
}
|
|
|
|
/**
|
|
* @return HasOne<QuickSaleModel, $this>
|
|
*/
|
|
public function credit(): HasOne
|
|
{
|
|
return $this->hasOne(QuickSaleModel::class, 'credits_quick_sale_id');
|
|
}
|
|
|
|
/**
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'user_id' => 'integer',
|
|
'customer_id' => 'integer',
|
|
'payment_method' => PaymentMethod::class,
|
|
'sold_at' => 'datetime',
|
|
'total_cents' => 'integer',
|
|
'credits_quick_sale_id' => 'integer',
|
|
'receipt_email' => 'encrypted',
|
|
'quick_sale_order_id' => 'integer',
|
|
'receipt_sent_at' => 'datetime',
|
|
'receipt_send_failed_at' => 'datetime',
|
|
];
|
|
}
|
|
}
|