From 0d40fd92f00a16bbdd8edbbf2c184d45cbe7caa8 Mon Sep 17 00:00:00 2001 From: hackerESQ Date: Thu, 7 Nov 2024 18:06:27 -0600 Subject: [PATCH 1/3] fix: adds validation for transaction date (no post-dated transactions) --- resources/views/livewire/manage-transaction-form.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/livewire/manage-transaction-form.blade.php b/resources/views/livewire/manage-transaction-form.blade.php index 4e1fb82..8b89c4b 100644 --- a/resources/views/livewire/manage-transaction-form.blade.php +++ b/resources/views/livewire/manage-transaction-form.blade.php @@ -36,7 +36,7 @@ public function rules() 'symbol' => ['required', 'string', new SymbolValidationRule], 'transaction_type' => 'required|string|in:BUY,SELL', 'portfolio_id' => 'required|exists:portfolios,id', - 'date' => 'required|date_format:Y-m-d', + 'date' => ['required', 'date_format:Y-m-d', 'before_or_equal:' . now()->format('Y-m-d')], 'quantity' => [ 'required', 'numeric', From af3726cb91113dedd590e3d472978fcee6d7f9e2 Mon Sep 17 00:00:00 2001 From: hackerESQ Date: Thu, 7 Nov 2024 18:20:53 -0600 Subject: [PATCH 2/3] fix: sales quantity should use rounded float numbers --- app/Models/Transaction.php | 2 +- app/Rules/QuantityValidationRule.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index 8b58b82..a4793d0 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -125,7 +125,7 @@ public function scopeSell($query) public function scopeBeforeDate($query, $date) { - return $query->whereDate('date', '<', $date); + return $query->whereDate('date', '<=', $date); } public function scopeMyTransactions() diff --git a/app/Rules/QuantityValidationRule.php b/app/Rules/QuantityValidationRule.php index 91bebe2..0dea105 100644 --- a/app/Rules/QuantityValidationRule.php +++ b/app/Rules/QuantityValidationRule.php @@ -50,7 +50,7 @@ public function validate(string $attribute, mixed $value, \Closure $fail): void $maxQuantity = $purchase_qty - $sales_qty; - if ($value > $maxQuantity) { + if (round($value, 3) > round($maxQuantity, 3)) { $fail(__('The quantity must not be greater than the available quantity.')); } } From 0c29393f3b2e7610d57910abf775b0bc12cc2881 Mon Sep 17 00:00:00 2001 From: hackerESQ Date: Thu, 7 Nov 2024 20:40:55 -0600 Subject: [PATCH 3/3] fix: skip dividend sync if most recent dividend was less than 24 hours ago --- app/Models/Dividend.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/Models/Dividend.php b/app/Models/Dividend.php index b6fe241..ebf6d40 100644 --- a/app/Models/Dividend.php +++ b/app/Models/Dividend.php @@ -50,10 +50,8 @@ public function scopeSymbol($query, $symbol) /** * Grab new dividend data * - * @param string $symbol - * @return void */ - public static function refreshDividendData(string $symbol) + public static function refreshDividendData(string $symbol): void { $dividends_meta = self::where(['symbol' => $symbol]) ->selectRaw('COUNT(symbol) as total_dividends') @@ -68,7 +66,13 @@ public static function refreshDividendData(string $symbol) // nope, refresh forward looking only if ( $dividends_meta->total_dividends ) { - $start_date = $dividends_meta->last_date->addHours(48); + $start_date = $dividends_meta->last_date->addHours(24); + } + + // skip refresh if there's already recent data + if ($start_date >= $end_date) { + + return; } // get some data @@ -99,8 +103,6 @@ public static function refreshDividendData(string $symbol) $market_data->last_dividend_amount = $dividend_data->sortByDesc('date')->first()['dividend_amount']; $market_data->save(); } - - return $dividend_data; } public static function syncHoldings(string $symbol): void