2024-08-29 23:36:44 -05:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
|
|
use App\Models\Holding;
|
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
|
2024-08-30 21:58:38 -05:00
|
|
|
class SyncHoldingData extends Command
|
2024-08-29 23:36:44 -05:00
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* The name and signature of the console command.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2024-10-23 16:57:55 -05:00
|
|
|
protected $signature = 'sync:holdings
|
|
|
|
|
{--user= : Limit refresh to user\'s holdings}';
|
2024-08-29 23:36:44 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The console command description.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2024-09-05 21:21:18 -05:00
|
|
|
protected $description = 'Syncs holdings with transactions and dividends';
|
2024-08-29 23:36:44 -05:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create a new command instance.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function __construct()
|
|
|
|
|
{
|
|
|
|
|
parent::__construct();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Execute the console command.
|
|
|
|
|
*
|
|
|
|
|
* @return int
|
|
|
|
|
*/
|
|
|
|
|
public function handle()
|
|
|
|
|
{
|
|
|
|
|
// get all holdings
|
2024-10-23 16:57:55 -05:00
|
|
|
$holdings = Holding::query();
|
2024-08-29 23:36:44 -05:00
|
|
|
|
2024-10-23 16:57:55 -05:00
|
|
|
if ($this->option('user')) {
|
|
|
|
|
$holdings->myHoldings($this->option('user'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($holdings->get() as $holding) {
|
2024-08-29 23:36:44 -05:00
|
|
|
$this->line('Refreshing ' . $holding->symbol);
|
|
|
|
|
|
2024-08-30 21:58:38 -05:00
|
|
|
$holding->syncTransactionsAndDividends();
|
2024-08-29 23:36:44 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|