mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -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()
|
$availableBudget = $this->user->availableBudgets()
|
||||||
->where('transaction_currency_id', $currency->id)
|
->where('transaction_currency_id', $currency->id)
|
||||||
->where('start_date', $start->format('Y-m-d 00:00:00'))
|
->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) {
|
if (null !== $availableBudget) {
|
||||||
$amount = (string)$availableBudget->amount;
|
$amount = (string)$availableBudget->amount;
|
||||||
}
|
}
|
||||||
@ -126,8 +126,8 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
|||||||
{
|
{
|
||||||
$return = [];
|
$return = [];
|
||||||
$availableBudgets = $this->user->availableBudgets()
|
$availableBudgets = $this->user->availableBudgets()
|
||||||
->where('start_date', $start->format('Y-m-d'))
|
->where('start_date', $start->format('Y-m-d 00:00:00'))
|
||||||
->where('end_date', $end->format('Y-m-d'))->get();
|
->where('end_date', $end->format('Y-m-d 23:59:59'))->get();
|
||||||
/** @var AvailableBudget $availableBudget */
|
/** @var AvailableBudget $availableBudget */
|
||||||
foreach ($availableBudgets as $availableBudget) {
|
foreach ($availableBudgets as $availableBudget) {
|
||||||
$return[$availableBudget->transaction_currency_id] = $availableBudget->amount;
|
$return[$availableBudget->transaction_currency_id] = $availableBudget->amount;
|
||||||
@ -162,10 +162,10 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
|||||||
$query = $this->user->availableBudgets();
|
$query = $this->user->availableBudgets();
|
||||||
|
|
||||||
if (null !== $start) {
|
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) {
|
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();
|
return $query->get();
|
||||||
@ -185,13 +185,13 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
|||||||
$availableBudget = $this->user->availableBudgets()
|
$availableBudget = $this->user->availableBudgets()
|
||||||
->where('transaction_currency_id', $currency->id)
|
->where('transaction_currency_id', $currency->id)
|
||||||
->where('start_date', $start->format('Y-m-d 00:00:00'))
|
->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) {
|
if (null === $availableBudget) {
|
||||||
$availableBudget = new AvailableBudget;
|
$availableBudget = new AvailableBudget;
|
||||||
$availableBudget->user()->associate($this->user);
|
$availableBudget->user()->associate($this->user);
|
||||||
$availableBudget->transactionCurrency()->associate($currency);
|
$availableBudget->transactionCurrency()->associate($currency);
|
||||||
$availableBudget->start_date = $start->format('Y-m-d 00:00:00');
|
$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->amount = $amount;
|
||||||
$availableBudget->save();
|
$availableBudget->save();
|
||||||
@ -214,13 +214,21 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
|||||||
*/
|
*/
|
||||||
public function store(array $data): ?AvailableBudget
|
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(
|
return AvailableBudget::create(
|
||||||
[
|
[
|
||||||
'user_id' => $this->user->id,
|
'user_id' => $this->user->id,
|
||||||
'transaction_currency_id' => $data['currency']->id,
|
'transaction_currency_id' => $data['currency']->id,
|
||||||
'amount' => $data['amount'],
|
'amount' => $data['amount'],
|
||||||
'start_date' => $data['start'],
|
'start_date' => $start,
|
||||||
'end_date' => $data['end'],
|
'end_date' => $end,
|
||||||
|
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
@ -254,16 +262,26 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
|||||||
$existing = $this->user->availableBudgets()
|
$existing = $this->user->availableBudgets()
|
||||||
->where('transaction_currency_id', $data['currency_id'])
|
->where('transaction_currency_id', $data['currency_id'])
|
||||||
->where('start_date', $data['start']->format('Y-m-d 00:00:00'))
|
->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)
|
->where('id', '!=', $availableBudget->id)
|
||||||
->first();
|
->first();
|
||||||
|
|
||||||
if (null !== $existing) {
|
if (null !== $existing) {
|
||||||
throw new FireflyException(sprintf('An entry already exists for these parameters: available budget object with ID #%d', $existing->id));
|
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->transaction_currency_id = $data['currency_id'];
|
||||||
$availableBudget->start_date = $data['start'];
|
$availableBudget->start_date = $start;
|
||||||
$availableBudget->end_date = $data['end'];
|
$availableBudget->end_date = $end;
|
||||||
$availableBudget->amount = $data['amount'];
|
$availableBudget->amount = $data['amount'];
|
||||||
$availableBudget->save();
|
$availableBudget->save();
|
||||||
|
|
||||||
@ -288,6 +306,6 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
|
|||||||
->availableBudgets()
|
->availableBudgets()
|
||||||
->where('transaction_currency_id', $currency->id)
|
->where('transaction_currency_id', $currency->id)
|
||||||
->where('start_date', $start->format('Y-m-d 00:00:00'))
|
->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