PurchaseService.php 476B

1234567891011121314151617181920212223
  1. <?php
  2. namespace App\Services;
  3. use App\Models\Ppn;
  4. use Illuminate\Database\Eloquent\Collection;
  5. class PurchaseService
  6. {
  7. public static function totalPrice(Collection $purchaseDetail)
  8. {
  9. return $purchaseDetail->sum(function ($purchase) {
  10. return self::priceWithPpn($purchase->price);
  11. });
  12. }
  13. public static function priceWithPpn(int $price)
  14. {
  15. $ppn = Ppn::first()->ppn;
  16. return $price + $price * ($ppn / 100);
  17. }
  18. }