mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-27 08:46:40 -06:00
Consistent dates for #3847
This commit is contained in:
parent
ed7977a105
commit
46ebf3c07c
@ -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();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user