Consistent end dates for budget limits.

This commit is contained in:
James Cole
2020-09-03 06:49:22 +02:00
parent f0fe8bf5c7
commit b0f18a0419
2 changed files with 9 additions and 13 deletions

View File

@@ -52,14 +52,10 @@ class BudgetLimitController extends Controller
{ {
use DateCalculation; use DateCalculation;
/** @var BudgetLimitRepositoryInterface */ private BudgetLimitRepositoryInterface $blRepository;
private $blRepository; private CurrencyRepositoryInterface $currencyRepos;
/** @var CurrencyRepositoryInterface */ private OperationsRepositoryInterface $opsRepository;
private $currencyRepos; private BudgetRepositoryInterface $repository;
/** @var OperationsRepositoryInterface */
private $opsRepository;
/** @var BudgetRepositoryInterface The budget repository */
private $repository;
/** /**
* AmountController constructor. * AmountController constructor.

View File

@@ -115,8 +115,8 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
{ {
return $budget->budgetlimits() return $budget->budgetlimits()
->where('transaction_currency_id', $currency->id) ->where('transaction_currency_id', $currency->id)
->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'))->first(); ->where('end_date', $end->format('Y-m-d 23:59:59'))->first();
} }
/** /**
@@ -307,7 +307,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
// find limit with same date range and currency. // find limit with same date range and currency.
$limit = $budget->budgetlimits() $limit = $budget->budgetlimits()
->where('budget_limits.start_date', $data['start_date']->format('Y-m-d 00:00:00')) ->where('budget_limits.start_date', $data['start_date']->format('Y-m-d 00:00:00'))
->where('budget_limits.end_date', $data['end_date']->format('Y-m-d 00:00:00')) ->where('budget_limits.end_date', $data['end_date']->format('Y-m-d 23:59:59'))
->where('budget_limits.transaction_currency_id', $currency->id) ->where('budget_limits.transaction_currency_id', $currency->id)
->get(['budget_limits.*'])->first(); ->get(['budget_limits.*'])->first();
if (null !== $limit) { if (null !== $limit) {
@@ -319,7 +319,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
$limit = new BudgetLimit; $limit = new BudgetLimit;
$limit->budget()->associate($budget); $limit->budget()->associate($budget);
$limit->start_date = $data['start_date']->format('Y-m-d 00:00:00'); $limit->start_date = $data['start_date']->format('Y-m-d 00:00:00');
$limit->end_date = $data['end_date']->format('Y-m-d 00:00:00'); $limit->end_date = $data['end_date']->format('Y-m-d 23:59:59');
$limit->amount = $data['amount']; $limit->amount = $data['amount'];
$limit->transaction_currency_id = $currency->id; $limit->transaction_currency_id = $currency->id;
$limit->save(); $limit->save();
@@ -339,7 +339,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
$budgetLimit->amount = array_key_exists('amount',$data) ? $data['amount'] : $budgetLimit->amount; $budgetLimit->amount = array_key_exists('amount',$data) ? $data['amount'] : $budgetLimit->amount;
$budgetLimit->budget_id = array_key_exists('budget_id', $data) ? $data['budget_id'] : $budgetLimit->budget_id; $budgetLimit->budget_id = array_key_exists('budget_id', $data) ? $data['budget_id'] : $budgetLimit->budget_id;
$budgetLimit->start_date = array_key_exists('start_date', $data) ? $data['start_date']->format('Y-m-d 00:00:00') : $budgetLimit->start_date; $budgetLimit->start_date = array_key_exists('start_date', $data) ? $data['start_date']->format('Y-m-d 00:00:00') : $budgetLimit->start_date;
$budgetLimit->end_date = array_key_exists('end_date', $data) ? $data['end_date']->format('Y-m-d 00:00:00') : $budgetLimit->end_date; $budgetLimit->end_date = array_key_exists('end_date', $data) ? $data['end_date']->format('Y-m-d 23:59:59') : $budgetLimit->end_date;
// if no currency has been provided, use the user's default currency: // if no currency has been provided, use the user's default currency:
$currency = null; $currency = null;