Various code reshuffelling.

This commit is contained in:
James Cole
2021-03-12 06:20:01 +01:00
parent 97561ab9c9
commit 748d61fb8f
51 changed files with 1874 additions and 1873 deletions

View File

@@ -41,6 +41,14 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
{
private User $user;
/**
* Delete all available budgets.
*/
public function destroyAll(): void
{
$this->user->availableBudgets()->delete();
}
/**
* @param AvailableBudget $availableBudget
*/
@@ -171,6 +179,18 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
return $query->get();
}
/**
* @inheritDoc
*/
public function getByCurrencyDate(Carbon $start, Carbon $end, TransactionCurrency $currency): ?AvailableBudget
{
return $this->user
->availableBudgets()
->where('transaction_currency_id', $currency->id)
->where('start_date', $start->format('Y-m-d'))
->where('end_date', $end->format('Y-m-d'))->first();
}
/**
* @param TransactionCurrency $currency
* @param Carbon $start
@@ -215,13 +235,14 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
public function store(array $data): ?AvailableBudget
{
$start = $data['start'];
if($start instanceof Carbon) {
if ($start instanceof Carbon) {
$start = $data['start']->startOfDay();
}
$end = $data['end'];
if($end instanceof Carbon) {
if ($end instanceof Carbon) {
$end = $data['end']->endOfDay();
}
return AvailableBudget::create(
[
'user_id' => $this->user->id,
@@ -271,11 +292,11 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
}
$start = $data['start'];
if($start instanceof Carbon) {
if ($start instanceof Carbon) {
$start = $data['start']->startOfDay();
}
$end = $data['end'];
if($end instanceof Carbon) {
if ($end instanceof Carbon) {
$end = $data['end']->endOfDay();
}
@@ -288,24 +309,4 @@ class AvailableBudgetRepository implements AvailableBudgetRepositoryInterface
return $availableBudget;
}
/**
* Delete all available budgets.
*/
public function destroyAll(): void
{
$this->user->availableBudgets()->delete();
}
/**
* @inheritDoc
*/
public function getByCurrencyDate(Carbon $start, Carbon $end, TransactionCurrency $currency): ?AvailableBudget
{
return $this->user
->availableBudgets()
->where('transaction_currency_id', $currency->id)
->where('start_date', $start->format('Y-m-d'))
->where('end_date', $end->format('Y-m-d'))->first();
}
}