Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117924584
D1150.1775443845.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
5 KB
Referenced Files
None
Subscribers
None
D1150.1775443845.diff
View Options
diff --git a/src/app/Console/Commands/WalletBalance.php b/src/app/Console/Commands/WalletBalance.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Commands/WalletBalance.php
@@ -0,0 +1,48 @@
+<?php
+
+namespace App\Console\Commands;
+
+use Illuminate\Console\Command;
+
+class WalletBalance extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'wallet:balance {wallet}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Display the balance of 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::find($this->argument('wallet'));
+
+ if (!$wallet) {
+ return 1;
+ }
+
+ $this->info($wallet->balance);
+ }
+}
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->discount ? $wallet->discount->discount : 0;
+
+ $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 = ((100 - $discount) / 100) * $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})");
+ }
+}
diff --git a/src/app/Console/Development/WalletSetBalance.php b/src/app/Console/Development/WalletSetBalance.php
new file mode 100644
--- /dev/null
+++ b/src/app/Console/Development/WalletSetBalance.php
@@ -0,0 +1,50 @@
+<?php
+
+namespace App\Console\Development;
+
+use Illuminate\Console\Command;
+
+class WalletSetBalance extends Command
+{
+ /**
+ * The name and signature of the console command.
+ *
+ * @var string
+ */
+ protected $signature = 'wallet:set-balance {wallet} {balance}';
+
+ /**
+ * The console command description.
+ *
+ * @var string
+ */
+ protected $description = 'Set the balance on 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::find($this->argument('wallet'));
+
+ if (!$wallet) {
+ return 1;
+ }
+
+ $wallet->balance = $this->argument('balance');
+
+ $wallet->save();
+ }
+}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Apr 6, 2:50 AM (9 h, 17 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18835363
Default Alt Text
D1150.1775443845.diff (5 KB)
Attached To
Mode
D1150: Wallet magic
Attached
Detach File
Event Timeline