-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBadge.php
More file actions
93 lines (82 loc) · 2.63 KB
/
Copy pathBadge.php
File metadata and controls
93 lines (82 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php
namespace App\Models\Badge;
use App\Domain\Printing\Models\PrintJob;
use App\Models\Badge\State_Fulfillment\BadgeFulfillmentStatusState;
use App\Models\Badge\State_Payment\BadgePaymentStatusState;
use App\Models\Fursuit\Fursuit;
use Bavix\Wallet\Interfaces\Customer;
use Bavix\Wallet\Interfaces\ProductInterface;
use Bavix\Wallet\Traits\HasWalletFloat;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\ModelStates\HasStates;
class Badge extends Model implements ProductInterface
{
use HasStates, SoftDeletes, HasWalletFloat, LogsActivity, HasFactory;
protected $guarded = [];
protected $casts = [
'status_fulfillment' => BadgeFulfillmentStatusState::class,
'status_payment' => BadgePaymentStatusState::class,
'extra_copy' => 'boolean',
'dual_side_print' => 'boolean',
'apply_late_fee' => 'boolean',
'printed_at' => 'datetime',
'ready_for_pickup_at' => 'datetime',
'picked_up_at' => 'datetime',
'is_free_badge' => 'boolean',
];
public function fursuit(): BelongsTo
{
return $this->belongsTo(Fursuit::class);
}
public function printJobs()
{
return $this->morphMany(PrintJob::class, 'printable');
}
public function getAmountProduct(Customer $customer): int|string
{
return $this->total;
}
public function getMetaProduct(): ?array
{
// Title Generator
$features = [];
if ($this->dual_side_print) {
$features[] = 'Double Sided Print';
}
if ($this->extra_copy_of) {
$features[] = 'Extra Copy';
}
$append = '';
if (count($features) > 0) {
$append = ' with Extras (' . implode(', ', $features) . ')';
}
return [
'title' => 'Fursuit Badge',
'description' => 'Purchase of Fursuit Badge #' . $this->id . $append,
];
}
protected function casts()
{
return [
'picked_up_at' => 'datetime',
];
}
public function getActivitylogOptions(): LogOptions
{
return LogOptions::defaults()
->logOnly(['*']);
}
public function isCopyOfFreeBadge(): bool
{
if ($this->extra_copy_of !== null) {
$originalBadge = self::find($this->extra_copy_of);
return $originalBadge ? $originalBadge->is_free_badge : false;
}
return false;
}
}