Skip to content

Firefly III: a personal finances manager

Consistent dates for #3847

James Cole46ebf3c07c85
diff --git a/app/Repositories/Budget/AvailableBudgetRepository.php b/app/Repositories/Budget/AvailableBudgetRepository.php
index 66b82d5366..7917f2e755 100644
--- a/app/Repositories/Budget/AvailableBudgetRepository.php
+++ b/app/Repositories/Budget/AvailableBudgetRepository.php
@@ -108,7 +108,7 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
$availableBudget = $this->user->availableBudgets()
->where('transaction_currency_id', $currency->id)
->where('start_date', $start->format('Y-m-d 00:00:00'))
- ->where('end_date', $end->format('Y-m-d 00:00:00'))->first();
+ ->where('end_date', $end->format('Y-m-d 23:59:59'))->first();
if (null !== $availableBudget) {
$amount = (string)$availableBudget->amount;
}
@@ -126,8 +126,8 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
{
$return = [];
$availableBudgets = $this->user->availableBudgets()
- ->where('start_date', $start->format('Y-m-d'))
- ->where('end_date', $end->format('Y-m-d'))->get();
+ ->where('start_date', $start->format('Y-m-d 00:00:00'))
+ ->where('end_date', $end->format('Y-m-d 23:59:59'))->get();
/** @var AvailableBudget $availableBudget */
foreach ($availableBudgets as $availableBudget) {
$return[$availableBudget->transaction_currency_id] = $availableBudget->amount;
@@ -162,10 +162,10 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
$query = $this->user->availableBudgets();
if (null !== $start) {
- $query->where('start_date', '>=', $start->format('Y-m-d H:i:s'));
+ $query->where('start_date', '>=', $start->format('Y-m-d 00:00:00'));
}
if (null !== $end) {
- $query->where('end_date', '<=', $end->format('Y-m-d H:i:s'));
+ $query->where('end_date', '<=', $end->format('Y-m-d 23:59:59'));
}
return $query->get();
@@ -185,13 +185,13 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
$availableBudget = $this->user->availableBudgets()
->where('transaction_currency_id', $currency->id)
->where('start_date', $start->format('Y-m-d 00:00:00'))
- ->where('end_date', $end->format('Y-m-d 00:00:00'))->first();
+ ->where('end_date', $end->format('Y-m-d 23:59:59'))->first();
if (null === $availableBudget) {
$availableBudget = new AvailableBudget;
$availableBudget->user()->associate($this->user);
$availableBudget->transactionCurrency()->associate($currency);
$availableBudget->start_date = $start->format('Y-m-d 00:00:00');
- $availableBudget->end_date = $end->format('Y-m-d 00:00:00');
+ $availableBudget->end_date = $end->format('Y-m-d 23:59:59');
}
$availableBudget->amount = $amount;
$availableBudget->save();
@@ -214,13 +214,21 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
*/
public function store(array $data): ?AvailableBudget
{
+ $start = $data['start'];
+ if($start instanceof Carbon) {
+ $start = $data['start']->startOfDay();
+ }
+ $end = $data['end'];
+ if($end instanceof Carbon) {
+ $end = $data['end']->endOfDay();
+ }
return AvailableBudget::create(
[
'user_id' => $this->user->id,
'transaction_currency_id' => $data['currency']->id,
'amount' => $data['amount'],
- 'start_date' => $data['start'],
- 'end_date' => $data['end'],
+ 'start_date' => $start,
+ 'end_date' => $end,
]
);
@@ -254,16 +262,26 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
$existing = $this->user->availableBudgets()
->where('transaction_currency_id', $data['currency_id'])
->where('start_date', $data['start']->format('Y-m-d 00:00:00'))
- ->where('end_date', $data['end']->format('Y-m-d 00:00:00'))
+ ->where('end_date', $data['end']->format('Y-m-d 23:59:59'))
->where('id', '!=', $availableBudget->id)
->first();
if (null !== $existing) {
throw new FireflyException(sprintf('An entry already exists for these parameters: available budget object with ID #%d', $existing->id));
}
+
+ $start = $data['start'];
+ if($start instanceof Carbon) {
+ $start = $data['start']->startOfDay();
+ }
+ $end = $data['end'];
+ if($end instanceof Carbon) {
+ $end = $data['end']->endOfDay();
+ }
+
$availableBudget->transaction_currency_id = $data['currency_id'];
- $availableBudget->start_date = $data['start'];
- $availableBudget->end_date = $data['end'];
+ $availableBudget->start_date = $start;
+ $availableBudget->end_date = $end;
$availableBudget->amount = $data['amount'];
$availableBudget->save();
@@ -288,6 +306,6 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
->availableBudgets()
->where('transaction_currency_id', $currency->id)
->where('start_date', $start->format('Y-m-d 00:00:00'))
- ->where('end_date', $end->format('Y-m-d 00:00:00'))->first();
+ ->where('end_date', $end->format('Y-m-d 23:59:59'))->first();
}
}