Page MenuHomePhorge

D1150.1775460550.diff
No OneTemporary

Authored By
Unknown
Size
2 KB
Referenced Files
None
Subscribers
None

D1150.1775460550.diff

diff --git a/src/app/Console/Commands/WalletCharge.php b/src/app/Console/Commands/WalletCharge.php
--- a/src/app/Console/Commands/WalletCharge.php
+++ b/src/app/Console/Commands/WalletCharge.php
@@ -52,11 +52,6 @@
);
$wallet->chargeEntitlements();
-
- if ($wallet->balance < 0) {
- // Disabled for now
- // \App\Jobs\WalletPayment::dispatch($wallet);
- }
}
}
}
diff --git a/src/app/Console/Commands/WalletUntil.php b/src/app/Console/Commands/WalletUntil.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/WalletUntil.php
@@ -0,0 +1,91 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+
+class WalletUntil extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'wallet:until {wallet}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Show until when the balance on a wallet lasts.';
+
+ /**
+ * Create a new command instance.
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ parent::__construct();
+ }
+
+ /**
+ * Execute the console command.
+ *
+ * @return mixed
+ */
+ public function handle()
+ {
+ $wallet = \App\Wallet::find($this->argument('wallet'));
+
+ if (!$wallet) {
+ return 1;
+ }
+
+ $balance = $wallet->balance;
+
+ $discount = $wallet->getDiscountRate();
+
+ $costs = 0;
+
+ $fromDate = \Carbon\Carbon::now()->subMonthsWithoutOverflow(6);
+ $toDate = \Carbon\Carbon::now()->subMonthsWithoutOverflow(6);
+
+ foreach ($wallet->entitlements as $entitlement) {
+ if ($entitlement->cost == 0) {
+ continue;
+ }
+
+ if ($entitlement->created_at > $fromDate) {
+ $fromDate = $entitlement->created_at->copy();
+ }
+
+ if ($entitlement->updated_at > $toDate) {
+ $toDate = $entitlement->updated_at->copy();
+ }
+ }
+
+ $entitlements = \App\Entitlement::where('wallet_id', $wallet->id)->orderBy('updated_at');
+
+ foreach ($entitlements->get() as $entitlement) {
+ if ($entitlement->cost == 0) {
+ continue;
+ }
+
+ $newToDate = $entitlement->updated_at->copy()->addMonthsWithoutOverflow(1);
+
+ $cost = $discount * $entitlement->cost;
+ $costs += $cost;
+
+ if ($balance >= $cost) {
+ $balance -= $cost;
+ if ($newToDate > $toDate) {
+ $toDate = $newToDate;
+ }
+ }
+ }
+
+ $this->info("{$wallet->balance} lasts until {$toDate} (a month costs {$costs})");
+ }
+}

File Metadata

Mime Type
text/plain
Expires
Mon, Apr 6, 7:29 AM (14 h, 54 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18832502
Default Alt Text
D1150.1775460550.diff (2 KB)

Event Timeline