Merge pull request #14 from investbrainapp/dev
fix: adds validation for transaction date
This commit is contained in:
@@ -50,10 +50,8 @@ class Dividend extends Model
|
||||
/**
|
||||
* 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 @@ class Dividend extends Model
|
||||
// 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 @@ class Dividend extends Model
|
||||
$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
|
||||
|
||||
@@ -125,7 +125,7 @@ class Transaction extends Model
|
||||
|
||||
public function scopeBeforeDate($query, $date)
|
||||
{
|
||||
return $query->whereDate('date', '<', $date);
|
||||
return $query->whereDate('date', '<=', $date);
|
||||
}
|
||||
|
||||
public function scopeMyTransactions()
|
||||
|
||||
@@ -50,7 +50,7 @@ class QuantityValidationRule implements ValidationRule
|
||||
|
||||
$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.'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ new class extends Component {
|
||||
'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',
|
||||
|
||||
Reference in New Issue
Block a user