Page MenuHomePhorge

D1063.1775422858.diff
No OneTemporary

Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None

D1063.1775422858.diff

diff --git a/src/app/Console/Commands/UserDiscount.php b/src/app/Console/Commands/UserDiscount.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/UserDiscount.php
@@ -0,0 +1,55 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+
+class UserDiscount extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'user:discount {user} {discount}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = "Apply a discount to all of the user's entitlements";
+
+ /**
+ * Create a new command instance.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $user = \App\User::where('email', $this->argument('user'))->first();
+
+ if (!$user) {
+ return 1;
+ }
+
+ $this->info("Found user {$user->id}");
+
+ $discount = (int)$this->argument('discount');
+
+ foreach ($user->wallets as $wallet) {
+ $wallet->discount = $discount;
+ $wallet->save();
+ }
+ }
+}
diff --git a/src/app/Console/Commands/UserWallets.php b/src/app/Console/Commands/UserWallets.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/UserWallets.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+
+class UserWallets extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'user:wallets {user}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'List wallets for a user';
+
+ /**
+ * Create a new command instance.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $user = \App\User::where('email', $this->argument('user'))->first();
+
+ if (!$user) {
+ return 1;
+ }
+
+ foreach ($user->wallets as $wallet) {
+ $this->info("{$wallet->id} {$wallet->description}");
+ }
+ }
+}
diff --git a/src/app/Console/Commands/WalletDiscount.php b/src/app/Console/Commands/WalletDiscount.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/WalletDiscount.php
@@ -0,0 +1,49 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+
+class WalletDiscount extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'wallet:discount {wallet} {discount}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Apply a discount to a wallet';
+
+ /**
+ * Create a new command instance.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $wallet = \App\Wallet::where('id', $this->argument('wallet'))->first();
+
+ if (!$wallet) {
+ return 1;
+ }
+
+ $wallet->discount = $this->argument('discount');
+ $wallet->save();
+ }
+}
diff --git a/src/app/Wallet.php b/src/app/Wallet.php
--- a/src/app/Wallet.php
+++ b/src/app/Wallet.php
@@ -33,7 +33,8 @@
];
protected $nullable = [
- 'description'
+ 'description',
+ 'discount'
];
protected $casts = [
@@ -76,7 +77,11 @@
if ($entitlement->updated_at <= Carbon::now()->subMonths(1)) {
$diff = $entitlement->updated_at->diffInMonths(Carbon::now());
- $charges += $entitlement->cost * $diff;
+ \Log::info("discount: {$this->discount}");
+
+ $cost = (int)($entitlement->cost * ((100 - $this->discount) / 100) * $diff);
+
+ $charges += $cost;
// if we're in dry-run, you know...
if (!$apply) {
@@ -86,7 +91,7 @@
$entitlement->updated_at = $entitlement->updated_at->copy()->addMonths($diff);
$entitlement->save();
- $this->debit($entitlement->cost * $diff);
+ $this->debit($cost * $diff);
}
}
diff --git a/src/database/migrations/2020_03_26_074731_add_wallet_discount_column.php b/src/database/migrations/2020_03_26_074731_add_wallet_discount_column.php
new file mode 100644
--- /dev/null
+++ b/src/database/migrations/2020_03_26_074731_add_wallet_discount_column.php
@@ -0,0 +1,39 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+// phpcs:ignore
+class AddWalletDiscountColumn extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::table(
+ 'wallets',
+ function (Blueprint $table) {
+ $table->integer('discount')->default(0)->nullable();
+ }
+ );
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table(
+ 'wallets',
+ function (Blueprint $table) {
+ $table->dropColumn(['discount']);
+ }
+ );
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Sun, Apr 5, 9:00 PM (1 d, 7 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18834448
Default Alt Text
D1063.1775422858.diff (5 KB)

Event Timeline