Allow user to set multi-currency available budget. WIP

This commit is contained in:
James Cole
2019-08-31 21:47:55 +02:00
parent ca777857c2
commit 509276e20b
10 changed files with 434 additions and 164 deletions

View File

@@ -227,14 +227,14 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
$q1->where(
static function (Builder $q2) use ($start, $end) {
$q2->where('budget_limits.end_date', '>=', $start->format('Y-m-d 00:00:00'));
$q2->where('budget_limits.end_date', '<=', $end->format('Y-m-d 00:00:00'));
$q2->where('budget_limits.end_date', '<=', $end->format('Y-m-d 23:59:59'));
}
)
// budget limit start within period
->orWhere(
static function (Builder $q3) use ($start, $end) {
$q3->where('budget_limits.start_date', '>=', $start->format('Y-m-d 00:00:00'));
$q3->where('budget_limits.start_date', '<=', $end->format('Y-m-d 00:00:00'));
$q3->where('budget_limits.start_date', '<=', $end->format('Y-m-d 23:59:59'));
}
);
}
@@ -242,7 +242,7 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
->orWhere(
static function (Builder $q4) use ($start, $end) {
// or start is before start AND end is after end.
$q4->where('budget_limits.start_date', '<=', $start->format('Y-m-d 00:00:00'));
$q4->where('budget_limits.start_date', '<=', $start->format('Y-m-d 23:59:59'));
$q4->where('budget_limits.end_date', '>=', $end->format('Y-m-d 00:00:00'));
}
);
@@ -265,6 +265,17 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
*
* @return BudgetLimit
*/
public function store(array $data): BudgetLimit
{
return BudgetLimit::create($data);
}
/**
* @param array $data
*
* @return BudgetLimit
* @deprecated
*/
public function storeBudgetLimit(array $data): BudgetLimit
{
/** @var Budget $budget */
@@ -303,12 +314,27 @@ class BudgetLimitRepository implements BudgetLimitRepositoryInterface
return $limit;
}
/**
* @param BudgetLimit $budgetLimit
* @param array $data
*
* @return BudgetLimit
*/
public function update(BudgetLimit $budgetLimit, array $data): BudgetLimit
{
$budgetLimit->amount = $data['amount'] ?? $budgetLimit->amount;
$budgetLimit->save();
return $budgetLimit;
}
/**
* @param BudgetLimit $budgetLimit
* @param array $data
*
* @return BudgetLimit
* @throws Exception
* @deprecated
*/
public function updateBudgetLimit(BudgetLimit $budgetLimit, array $data): BudgetLimit
{

View File

@@ -35,6 +35,19 @@ use Illuminate\Support\Collection;
*/
interface BudgetLimitRepositoryInterface
{
/**
* Tells you which amount has been budgeted (for the given budgets)
* in the selected query. Returns a positive amount as a string.
*
* @param Carbon $start
* @param Carbon $end
* @param TransactionCurrency $currency
* @param Collection|null $budgets
*
* @return string
*/
public function budgeted(Carbon $start, Carbon $end, TransactionCurrency $currency, ?Collection $budgets = null): string;
/**
* Destroy a budget limit.
*
@@ -80,20 +93,15 @@ interface BudgetLimitRepositoryInterface
*
* @return BudgetLimit
*/
public function storeBudgetLimit(array $data): BudgetLimit;
public function store(array $data): BudgetLimit;
/**
* Tells you which amount has been budgeted (for the given budgets)
* in the selected query. Returns a positive amount as a string.
* @param array $data
*
* @param Carbon $start
* @param Carbon $end
* @param TransactionCurrency $currency
* @param Collection|null $budgets
*
* @return string
* @return BudgetLimit
* @deprecated
*/
public function budgeted(Carbon $start, Carbon $end, TransactionCurrency $currency, ?Collection $budgets = null): string;
public function storeBudgetLimit(array $data): BudgetLimit;
/**
* @param BudgetLimit $budgetLimit
@@ -101,6 +109,15 @@ interface BudgetLimitRepositoryInterface
*
* @return BudgetLimit
*/
public function update(BudgetLimit $budgetLimit, array $data): BudgetLimit;
/**
* @param BudgetLimit $budgetLimit
* @param array $data
*
* @return BudgetLimit
* @deprecated
*/
public function updateBudgetLimit(BudgetLimit $budgetLimit, array $data): BudgetLimit;
/**