diff --git a/app/Models/Dividend.php b/app/Models/Dividend.php index ebf6d40..b53b7d9 100644 --- a/app/Models/Dividend.php +++ b/app/Models/Dividend.php @@ -27,7 +27,7 @@ class Dividend extends Model protected $casts = [ 'date' => 'datetime', - 'last_date' => 'datetime', + 'last_dividend_update' => 'datetime', ]; public function marketData() { @@ -55,22 +55,22 @@ public static function refreshDividendData(string $symbol): void { $dividends_meta = self::where(['symbol' => $symbol]) ->selectRaw('COUNT(symbol) as total_dividends') - ->selectRaw('MAX(date) as last_date') + ->selectRaw('MAX(created_at) as last_dividend_update') ->get() ->first(); // assume we need to populate ALL dividend data - $start_date = new \DateTime('@0'); + $start_date = new Carbon('@0'); $end_date = now(); // nope, refresh forward looking only if ( $dividends_meta->total_dividends ) { - - $start_date = $dividends_meta->last_date->addHours(24); + + $start_date = $dividends_meta->last_dividend_update->addHours(24); } - + // skip refresh if there's already recent data - if ($start_date >= $end_date) { + if ($start_date->greaterThan($end_date)) { return; } diff --git a/composer.lock b/composer.lock index 3c7af47..66f2b9b 100644 --- a/composer.lock +++ b/composer.lock @@ -62,16 +62,16 @@ }, { "name": "aws/aws-sdk-php", - "version": "3.325.3", + "version": "3.325.7", "source": { "type": "git", "url": "https://github.com/aws/aws-sdk-php.git", - "reference": "de0b289c7260fb19301ffa2eb724de2076daad74" + "reference": "55852104253172e66c3358bf4c35281bbd8622b2" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/de0b289c7260fb19301ffa2eb724de2076daad74", - "reference": "de0b289c7260fb19301ffa2eb724de2076daad74", + "url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/55852104253172e66c3358bf4c35281bbd8622b2", + "reference": "55852104253172e66c3358bf4c35281bbd8622b2", "shasum": "" }, "require": { @@ -154,9 +154,9 @@ "support": { "forum": "https://forums.aws.amazon.com/forum.jspa?forumID=80", "issues": "https://github.com/aws/aws-sdk-php/issues", - "source": "https://github.com/aws/aws-sdk-php/tree/3.325.3" + "source": "https://github.com/aws/aws-sdk-php/tree/3.325.7" }, - "time": "2024-11-06T19:05:22+00:00" + "time": "2024-11-12T19:27:31+00:00" }, { "name": "bacon/bacon-qr-code", @@ -1966,16 +1966,16 @@ }, { "name": "laravel/fortify", - "version": "v1.24.4", + "version": "v1.24.5", "source": { "type": "git", "url": "https://github.com/laravel/fortify.git", - "reference": "5bd3bdd535acf4054865c64eec6d8bb8c60cc127" + "reference": "bba8c2ecc3fcc78e8632e0d719ae10bef6343eef" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/fortify/zipball/5bd3bdd535acf4054865c64eec6d8bb8c60cc127", - "reference": "5bd3bdd535acf4054865c64eec6d8bb8c60cc127", + "url": "https://api.github.com/repos/laravel/fortify/zipball/bba8c2ecc3fcc78e8632e0d719ae10bef6343eef", + "reference": "bba8c2ecc3fcc78e8632e0d719ae10bef6343eef", "shasum": "" }, "require": { @@ -2027,7 +2027,7 @@ "issues": "https://github.com/laravel/fortify/issues", "source": "https://github.com/laravel/fortify" }, - "time": "2024-10-29T13:59:23+00:00" + "time": "2024-11-12T14:51:12+00:00" }, { "name": "laravel/framework", @@ -2240,16 +2240,16 @@ }, { "name": "laravel/jetstream", - "version": "v5.3.1", + "version": "v5.3.2", "source": { "type": "git", "url": "https://github.com/laravel/jetstream.git", - "reference": "d51ec6942f34e76ba4736452d5f4d6f54a186a6e" + "reference": "e5b9ef610bf13fb3b6053893f711227213833f35" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/jetstream/zipball/d51ec6942f34e76ba4736452d5f4d6f54a186a6e", - "reference": "d51ec6942f34e76ba4736452d5f4d6f54a186a6e", + "url": "https://api.github.com/repos/laravel/jetstream/zipball/e5b9ef610bf13fb3b6053893f711227213833f35", + "reference": "e5b9ef610bf13fb3b6053893f711227213833f35", "shasum": "" }, "require": { @@ -2303,7 +2303,7 @@ "issues": "https://github.com/laravel/jetstream/issues", "source": "https://github.com/laravel/jetstream" }, - "time": "2024-10-30T13:32:43+00:00" + "time": "2024-11-11T20:18:18+00:00" }, { "name": "laravel/prompts", @@ -3212,16 +3212,16 @@ }, { "name": "livewire/volt", - "version": "v1.6.5", + "version": "v1.6.6", "source": { "type": "git", "url": "https://github.com/livewire/volt.git", - "reference": "d09fdb4cb52c6ce821d255683195bb6d446fe141" + "reference": "9efa7bd50a71ad166ac44ed9322d2c004e0ece5f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/livewire/volt/zipball/d09fdb4cb52c6ce821d255683195bb6d446fe141", - "reference": "d09fdb4cb52c6ce821d255683195bb6d446fe141", + "url": "https://api.github.com/repos/livewire/volt/zipball/9efa7bd50a71ad166ac44ed9322d2c004e0ece5f", + "reference": "9efa7bd50a71ad166ac44ed9322d2c004e0ece5f", "shasum": "" }, "require": { @@ -3280,20 +3280,20 @@ "issues": "https://github.com/livewire/volt/issues", "source": "https://github.com/livewire/volt" }, - "time": "2024-05-31T19:07:20+00:00" + "time": "2024-11-12T14:51:01+00:00" }, { "name": "maatwebsite/excel", - "version": "3.1.58", + "version": "3.1.60", "source": { "type": "git", "url": "https://github.com/SpartnerNL/Laravel-Excel.git", - "reference": "18495a71b112f43af8ffab35111a58b4e4ba4a4d" + "reference": "4906dc57fbe6a41c405a77e1f7cac9078982c9c7" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/SpartnerNL/Laravel-Excel/zipball/18495a71b112f43af8ffab35111a58b4e4ba4a4d", - "reference": "18495a71b112f43af8ffab35111a58b4e4ba4a4d", + "url": "https://api.github.com/repos/SpartnerNL/Laravel-Excel/zipball/4906dc57fbe6a41c405a77e1f7cac9078982c9c7", + "reference": "4906dc57fbe6a41c405a77e1f7cac9078982c9c7", "shasum": "" }, "require": { @@ -3301,7 +3301,7 @@ "ext-json": "*", "illuminate/support": "5.8.*||^6.0||^7.0||^8.0||^9.0||^10.0||^11.0", "php": "^7.0||^8.0", - "phpoffice/phpspreadsheet": "^1.29.1", + "phpoffice/phpspreadsheet": "^1.29.4", "psr/simple-cache": "^1.0||^2.0||^3.0" }, "require-dev": { @@ -3349,7 +3349,7 @@ ], "support": { "issues": "https://github.com/SpartnerNL/Laravel-Excel/issues", - "source": "https://github.com/SpartnerNL/Laravel-Excel/tree/3.1.58" + "source": "https://github.com/SpartnerNL/Laravel-Excel/tree/3.1.60" }, "funding": [ { @@ -3361,7 +3361,7 @@ "type": "github" } ], - "time": "2024-09-07T13:53:36+00:00" + "time": "2024-11-11T12:27:45+00:00" }, { "name": "maennchen/zipstream-php", @@ -4181,16 +4181,16 @@ }, { "name": "openai-php/client", - "version": "v0.10.2", + "version": "v0.10.3", "source": { "type": "git", "url": "https://github.com/openai-php/client.git", - "reference": "efa92628ba9fb56f7877c0d616f5221c4a447856" + "reference": "4a565d145e0fb3ea1baba8fffe39d86c56b6dc2c" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/openai-php/client/zipball/efa92628ba9fb56f7877c0d616f5221c4a447856", - "reference": "efa92628ba9fb56f7877c0d616f5221c4a447856", + "url": "https://api.github.com/repos/openai-php/client/zipball/4a565d145e0fb3ea1baba8fffe39d86c56b6dc2c", + "reference": "4a565d145e0fb3ea1baba8fffe39d86c56b6dc2c", "shasum": "" }, "require": { @@ -4208,11 +4208,10 @@ "laravel/pint": "^1.18.1", "mockery/mockery": "^1.6.12", "nunomaduro/collision": "^7.11.0|^8.5.0", - "pestphp/pest": "^2.36.0|^3.4.1", + "pestphp/pest": "^2.36.0|^3.5.0", "pestphp/pest-plugin-arch": "^2.7|^3.0", "pestphp/pest-plugin-type-coverage": "^2.8.7|^3.1.0", - "phpstan/phpstan": "^1.12.6", - "rector/rector": "^1.2.7", + "phpstan/phpstan": "^1.12.7", "symfony/var-dumper": "^6.4.11|^7.1.5" }, "type": "library", @@ -4253,7 +4252,7 @@ ], "support": { "issues": "https://github.com/openai-php/client/issues", - "source": "https://github.com/openai-php/client/tree/v0.10.2" + "source": "https://github.com/openai-php/client/tree/v0.10.3" }, "funding": [ { @@ -4269,7 +4268,7 @@ "type": "github" } ], - "time": "2024-10-17T20:28:25+00:00" + "time": "2024-11-12T20:51:16+00:00" }, { "name": "openai-php/laravel", @@ -4614,16 +4613,16 @@ }, { "name": "phpoffice/phpspreadsheet", - "version": "1.29.2", + "version": "1.29.4", "source": { "type": "git", "url": "https://github.com/PHPOffice/PhpSpreadsheet.git", - "reference": "3a5a818d7d3e4b5bd2e56fb9de44dbded6eae07f" + "reference": "7ca7e325dca3adb6a598385aab81f527b8d6c75d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/3a5a818d7d3e4b5bd2e56fb9de44dbded6eae07f", - "reference": "3a5a818d7d3e4b5bd2e56fb9de44dbded6eae07f", + "url": "https://api.github.com/repos/PHPOffice/PhpSpreadsheet/zipball/7ca7e325dca3adb6a598385aab81f527b8d6c75d", + "reference": "7ca7e325dca3adb6a598385aab81f527b8d6c75d", "shasum": "" }, "require": { @@ -4713,9 +4712,9 @@ ], "support": { "issues": "https://github.com/PHPOffice/PhpSpreadsheet/issues", - "source": "https://github.com/PHPOffice/PhpSpreadsheet/tree/1.29.2" + "source": "https://github.com/PHPOffice/PhpSpreadsheet/tree/1.29.4" }, - "time": "2024-09-29T07:04:47+00:00" + "time": "2024-11-10T16:26:22+00:00" }, { "name": "phpoption/phpoption", @@ -5733,16 +5732,16 @@ }, { "name": "robsontenorio/mary", - "version": "1.41.2", + "version": "1.41.4", "source": { "type": "git", "url": "https://github.com/robsontenorio/mary.git", - "reference": "ec5661a7cb4911ffb48dbf64c4455bdb52d0f196" + "reference": "d88af3a6e52c39e84455927111449035f1ede92d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/robsontenorio/mary/zipball/ec5661a7cb4911ffb48dbf64c4455bdb52d0f196", - "reference": "ec5661a7cb4911ffb48dbf64c4455bdb52d0f196", + "url": "https://api.github.com/repos/robsontenorio/mary/zipball/d88af3a6e52c39e84455927111449035f1ede92d", + "reference": "d88af3a6e52c39e84455927111449035f1ede92d", "shasum": "" }, "require": { @@ -5808,7 +5807,7 @@ ], "support": { "issues": "https://github.com/robsontenorio/mary/issues", - "source": "https://github.com/robsontenorio/mary/tree/1.41.2" + "source": "https://github.com/robsontenorio/mary/tree/1.41.4" }, "funding": [ { @@ -5816,7 +5815,7 @@ "type": "github" } ], - "time": "2024-10-30T18:25:35+00:00" + "time": "2024-11-12T14:30:56+00:00" }, { "name": "scheb/yahoo-finance-api", @@ -8619,16 +8618,16 @@ "packages-dev": [ { "name": "fakerphp/faker", - "version": "v1.23.1", + "version": "v1.24.0", "source": { "type": "git", "url": "https://github.com/FakerPHP/Faker.git", - "reference": "bfb4fe148adbf78eff521199619b93a52ae3554b" + "reference": "a136842a532bac9ecd8a1c723852b09915d7db50" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/FakerPHP/Faker/zipball/bfb4fe148adbf78eff521199619b93a52ae3554b", - "reference": "bfb4fe148adbf78eff521199619b93a52ae3554b", + "url": "https://api.github.com/repos/FakerPHP/Faker/zipball/a136842a532bac9ecd8a1c723852b09915d7db50", + "reference": "a136842a532bac9ecd8a1c723852b09915d7db50", "shasum": "" }, "require": { @@ -8676,9 +8675,9 @@ ], "support": { "issues": "https://github.com/FakerPHP/Faker/issues", - "source": "https://github.com/FakerPHP/Faker/tree/v1.23.1" + "source": "https://github.com/FakerPHP/Faker/tree/v1.24.0" }, - "time": "2024-01-02T13:46:09+00:00" + "time": "2024-11-07T15:11:20+00:00" }, { "name": "filp/whoops", @@ -8870,16 +8869,16 @@ }, { "name": "laravel/sail", - "version": "v1.37.1", + "version": "v1.38.0", "source": { "type": "git", "url": "https://github.com/laravel/sail.git", - "reference": "7efa151ea0d16f48233d6a6cd69f81270acc6e93" + "reference": "d17abae06661dd6c46d13627b1683a2924259145" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/sail/zipball/7efa151ea0d16f48233d6a6cd69f81270acc6e93", - "reference": "7efa151ea0d16f48233d6a6cd69f81270acc6e93", + "url": "https://api.github.com/repos/laravel/sail/zipball/d17abae06661dd6c46d13627b1683a2924259145", + "reference": "d17abae06661dd6c46d13627b1683a2924259145", "shasum": "" }, "require": { @@ -8929,7 +8928,7 @@ "issues": "https://github.com/laravel/sail/issues", "source": "https://github.com/laravel/sail" }, - "time": "2024-10-29T20:18:14+00:00" + "time": "2024-11-11T20:16:51+00:00" }, { "name": "mockery/mockery", @@ -9016,16 +9015,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.12.0", + "version": "1.12.1", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c" + "reference": "123267b2c49fbf30d78a7b2d333f6be754b94845" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", - "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/123267b2c49fbf30d78a7b2d333f6be754b94845", + "reference": "123267b2c49fbf30d78a7b2d333f6be754b94845", "shasum": "" }, "require": { @@ -9064,7 +9063,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.12.0" + "source": "https://github.com/myclabs/DeepCopy/tree/1.12.1" }, "funding": [ { @@ -9072,7 +9071,7 @@ "type": "tidelift" } ], - "time": "2024-06-12T14:39:25+00:00" + "time": "2024-11-08T17:47:46+00:00" }, { "name": "nunomaduro/collision", @@ -10768,5 +10767,5 @@ "php": "^8.2" }, "platform-dev": [], - "plugin-api-version": "2.6.0" + "plugin-api-version": "2.3.0" } diff --git a/tests/DividendsTest.php b/tests/DividendsTest.php index d264e3e..7478869 100644 --- a/tests/DividendsTest.php +++ b/tests/DividendsTest.php @@ -61,4 +61,26 @@ public function test_new_dividends_are_reinvested(): void $this->assertCount(3, $transactions); $this->assertEqualsWithDelta(4.95, $dividendsReinvested * $market_data->market_value, 0.01); } + + /** + */ + public function test_do_not_duplicate_recent_dividends(): void + { + $this->actingAs($user = User::factory()->create()); + + $portfolio = Portfolio::factory()->create(); + Transaction::factory()->buy()->yearsAgo()->portfolio($portfolio->id)->symbol('ACME')->create(); + + $holding = Holding::query()->portfolio($portfolio->id)->symbol('ACME')->first(); + + Dividend::create([ + 'symbol' => 'ACME', + 'date' => now()->subDay(2), + 'dividend_amount' => .01 + ]); + + Dividend::refreshDividendData('ACME'); + + $this->assertCount(1, $holding->dividends); + } }