refactor: consolidate order creator and marketing name retrieval into model attributes

This commit is contained in:
Yoga Pangestu 2026-06-23 11:10:46 +07:00
parent 18650f1cbf
commit 4414f2c050
3 changed files with 20 additions and 10 deletions

View File

@ -29,6 +29,8 @@
'payment_type_label',
'price_type_label',
'status_label',
'creator_name',
'marketing_name',
])]
class Order extends Model
{
@ -131,6 +133,20 @@ public function statusLabel(): Attribute
);
}
public function creatorName(): Attribute
{
return Attribute::make(
get: fn () => $this->createdBy?->profile?->full_name ?? $this->createdBy?->username ?? '-',
);
}
public function marketingName(): Attribute
{
return Attribute::make(
get: fn () => $this->marketing?->profile?->full_name ?? $this->marketing?->username ?? '-',
);
}
public function subtotalFormatted(): Attribute
{
return Attribute::make(

View File

@ -58,14 +58,6 @@ const { open: deleteConfirmOpen, processing: deleteProcessing, destroy: destroyO
errorMessage: 'Gagal menghapus pesanan.',
});
const creatorName = computed(() => {
return props.order.created_by?.profile?.full_name ?? props.order.created_by?.username ?? '-';
});
const marketingName = computed(() => {
return props.order.marketing?.profile?.full_name ?? props.order.marketing?.username ?? '-';
});
function statusVariant(status: string): 'default' | 'secondary' | 'destructive' | 'outline' {
if (status === OrderStatus.COMPLETED) return 'default';
if (status === OrderStatus.CANCELLED) return 'destructive';
@ -305,11 +297,11 @@ const feeEntries = computed(() => {
</div>
<div>
<p class="text-muted-foreground text-sm">Dibuat Oleh</p>
<p class="font-medium">{{ creatorName }}</p>
<p class="font-medium">{{ order.creator_name }}</p>
</div>
<div v-if="order.marketing">
<p class="text-muted-foreground text-sm">Marketing</p>
<p class="font-medium">{{ marketingName }}</p>
<p class="font-medium">{{ order.marketing_name }}</p>
</div>
</div>
</div>

View File

@ -157,6 +157,8 @@ export type OrderDetail = {
total_amount_formatted: string;
notes: string | null;
created_at_formatted: string;
creator_name: string;
marketing_name: string | null;
customer?: {
id: number;
name: string;