Changeset View
Changeset View
Standalone View
Standalone View
src/app/Console/Commands/PlanPackagesCommand.php
Show All 33 Lines | class PlanPackagesCommand extends Command | ||||
/** | /** | ||||
* Execute the console command. | * Execute the console command. | ||||
* | * | ||||
* @return mixed | * @return mixed | ||||
*/ | */ | ||||
public function handle() | public function handle() | ||||
{ | { | ||||
$plans = Plan::get(); | $plans = Plan::all(); | ||||
foreach ($plans as $plan) { | foreach ($plans as $plan) { | ||||
$this->info(sprintf("Plan: %s", $plan->title)); | $this->info(sprintf("Plan: %s", $plan->title)); | ||||
$plan_costs = 0; | $plan_costs = 0; | ||||
foreach ($plan->packages()->get() as $package) { | foreach ($plan->packages as $package) { | ||||
$qtyMin = $package->pivot->qty_min; | $qtyMin = $package->pivot->qty_min; | ||||
$qtyMax = $package->pivot->qty_max; | $qtyMax = $package->pivot->qty_max; | ||||
$discountQty = $package->pivot->discount_qty; | $discountQty = $package->pivot->discount_qty; | ||||
$discountRate = (100 - $package->pivot->discount_rate) / 100; | $discountRate = (100 - $package->pivot->discount_rate) / 100; | ||||
$this->info( | $this->info( | ||||
sprintf( | sprintf( | ||||
" Package: %s (min: %d, max: %d, discount %d%% after the first %d, base cost: %d)", | " Package: %s (min: %d, max: %d, discount %d%% after the first %d, base cost: %d)", | ||||
$package->title, | $package->title, | ||||
$package->pivot->qty_min, | $package->pivot->qty_min, | ||||
$package->pivot->qty_max, | $package->pivot->qty_max, | ||||
$package->pivot->discount_rate, | $package->pivot->discount_rate, | ||||
$package->pivot->discount_qty, | $package->pivot->discount_qty, | ||||
$package->cost() | $package->cost() | ||||
) | ) | ||||
); | ); | ||||
foreach ($package->skus()->get() as $sku) { | foreach ($package->skus as $sku) { | ||||
$this->info(sprintf(" SKU: %s (%d)", $sku->title, $sku->pivot->qty)); | $this->info(sprintf(" SKU: %s (%d)", $sku->title, $sku->pivot->qty)); | ||||
} | } | ||||
if ($qtyMin < $discountQty) { | if ($qtyMin < $discountQty) { | ||||
$plan_costs += $qtyMin * $package->cost(); | $plan_costs += $qtyMin * $package->cost(); | ||||
} elseif ($qtyMin == $discountQty) { | } elseif ($qtyMin == $discountQty) { | ||||
$plan_costs += $package->cost(); | $plan_costs += $package->cost(); | ||||
} else { | } else { | ||||
Show All 12 Lines |