Page MenuHomePhorge

PlanPackagesCommand.php
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

PlanPackagesCommand.php

<?php
namespace App\Console\Commands;
use App\Plan;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class PlanPackagesCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'plan:packages';
/**
* The console command description.
*
* @var string
*/
protected $description = "List packages for plans.";
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$plans = Plan::get();
foreach ($plans as $plan) {
$this->info(sprintf("Plan: %s", $plan->title));
$plan_costs = 0;
foreach ($plan->packages()->get() as $package) {
$qtyMin = $package->pivot->qty_min;
$qtyMax = $package->pivot->qty_max;
$discountQty = $package->pivot->discount_qty;
$discountRate = (100 - $package->pivot->discount_rate) / 100;
$this->info(
sprintf(
" Package: %s (min: %d, max: %d, discount %d%% after the first %d, base cost: %d)",
$package->title,
$package->pivot->qty_min,
$package->pivot->qty_max,
$package->pivot->discount_rate,
$package->pivot->discount_qty,
$package->cost()
)
);
foreach ($package->skus()->get() as $sku) {
$this->info(sprintf(" SKU: %s (%d)", $sku->title, $sku->pivot->qty));
}
if ($qtyMin < $discountQty) {
$plan_costs += $qtyMin * $package->cost();
} elseif ($qtyMin == $discountQty) {
$plan_costs += $package->cost();
} else {
// base rate
$plan_costs += $discountQty * $package->cost();
// discounted rate
$plan_costs += ($qtyMin - $discountQty) * $package->cost() * $discountRate;
}
}
$this->info(sprintf(" Plan costs per month: %d", $plan_costs));
}
}
}

File Metadata

Mime Type
text/x-php
Expires
Fri, Apr 24, 10:02 AM (6 d, 18 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18798348
Default Alt Text
PlanPackagesCommand.php (2 KB)

Event Timeline