parfum/app/Traits/Order/WithCalculateTotal.php

19 lines
442 B
PHP

<?php
namespace App\Traits\Order;
trait WithCalculateTotal
{
public function getSubTotal(): int
{
return $this->items->sum(fn ($item) => $item->unit_price * $item->quantity);
}
public function getTotal(): int
{
$subtotal = $this->items->sum(fn ($item) => $item->unit_price * $item->quantity);
return max(0, $subtotal - parseRupiahToInt($this->form->discount) - $this->voucherDiscount);
}
}