diff --git a/app/Console/Commands/CalculatePayouts.php b/app/Console/Commands/CalculatePayouts.php new file mode 100644 index 000000000000..869783dc8ad3 --- /dev/null +++ b/app/Console/Commands/CalculatePayouts.php @@ -0,0 +1,90 @@ +info('Running CalculatePayouts...'); + + $servers = DbServer::orderBy('id')->get(['name']); + $userMap = []; + + foreach ($servers as $server) { + $this->info('Processing users: ' . $server->name); + config(['database.default' => $server->name]); + + $users = User::where('referral_code', '!=', '') + ->get(['email', 'referral_code']); + foreach ($users as $user) { + $userMap[$user->referral_code] = $user->email; + } + } + + foreach ($servers as $server) { + $this->info('Processing companies: ' . $server->name); + config(['database.default' => $server->name]); + + $companies = Company::where('referral_code', '!=', '') + ->with('payment.client.payments') + ->whereNotNull('payment_id') + ->get(); + + foreach ($companies as $company) { + $user = $userMap[$company->referral_code]; + $payment = $company->payment; + $client = $payment->client; + + $this->info("User: $user"); + + foreach ($client->payments as $payment) { + $this->info("Date: $payment->payment_date, Amount: $payment->amount, Reference: $payment->transaction_reference"); + } + } + } + } + + protected function getOptions() + { + return [ + + ]; + } + +} diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index c1cf74d0e6d0..46ab045be1c1 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -28,6 +28,7 @@ class Kernel extends ConsoleKernel 'App\Console\Commands\MakeModule', 'App\Console\Commands\MakeClass', 'App\Console\Commands\InitLookup', + 'App\Console\Commands\CalculatePayouts', ]; /**