Changeset View
Changeset View
Standalone View
Standalone View
src/app/Package.php
Show First 20 Lines • Show All 61 Lines • ▼ Show 20 Lines | class Package extends Model | ||||
public function cost() | public function cost() | ||||
{ | { | ||||
$costs = 0; | $costs = 0; | ||||
foreach ($this->skus as $sku) { | foreach ($this->skus as $sku) { | ||||
$units = $sku->pivot->qty - $sku->units_free; | $units = $sku->pivot->qty - $sku->units_free; | ||||
if ($units < 0) { | if ($units < 0) { | ||||
\Log::debug("Package {$this->id} is misconfigured for more free units than qty."); | \Log::warning("Package {$this->id} is misconfigured for more free units than qty."); | ||||
$units = 0; | $units = 0; | ||||
} | } | ||||
$ppu = $sku->cost * ((100 - $this->discount_rate) / 100); | $ppu = $sku->cost * ((100 - $this->discount_rate) / 100); | ||||
$costs += $units * $ppu; | $costs += $units * $ppu; | ||||
} | } | ||||
Show All 29 Lines |