Fix issue in budget limits

This commit is contained in:
James Cole
2022-10-01 16:35:29 +02:00
parent 5c471059f3
commit c4e46bf89b
2 changed files with 24 additions and 9 deletions

View File

@@ -151,10 +151,14 @@ class BudgetLimitController extends Controller
// sanity check on amount: // sanity check on amount:
if ((float) $amount === 0.0) { if ((float) $amount === 0.0) {
$amount = '1'; if (null !== $limit) {
$this->blRepository->destroyBudgetLimit($limit);
} }
if ((int) $amount > 65536) { // return empty=ish array:
$amount = '65536'; return response()->json([]);
}
if ((int) $amount > 16777216) {
$amount = '16777216';
} }
if (null !== $limit) { if (null !== $limit) {
@@ -208,10 +212,19 @@ class BudgetLimitController extends Controller
// sanity check on amount: // sanity check on amount:
if ((float) $amount === 0.0) { if ((float) $amount === 0.0) {
$amount = '1'; $budgetId = $budgetLimit->budget_id;
$currency = $budgetLimit->transactionCurrency;
$this->blRepository->destroyBudgetLimit($budgetLimit);
$array = [
'budget_id' => $budgetId,
'left_formatted' => app('amount')->formatAnything($currency, '0'),
'left_per_day_formatted' => app('amount')->formatAnything($currency, '0'),
'transaction_currency_id' => $currency->id,
];
return response()->json($array);
} }
if ((int) $amount > 65536) { if ((int) $amount > 16777216) { // 16 million
$amount = '65536'; $amount = '16777216';
} }
$limit = $this->blRepository->update($budgetLimit, ['amount' => $amount]); $limit = $this->blRepository->update($budgetLimit, ['amount' => $amount]);

View File

@@ -79,6 +79,7 @@ $(function () {
}); });
function updateBudgetedAmount(e) { function updateBudgetedAmount(e) {
console.log('updateBudgetedAmount');
var input = $(e.currentTarget); var input = $(e.currentTarget);
var budgetId = parseInt(input.data('id')); var budgetId = parseInt(input.data('id'));
var budgetLimitId = parseInt(input.data('limit')); var budgetLimitId = parseInt(input.data('limit'));
@@ -95,7 +96,7 @@ function updateBudgetedAmount(e) {
}).done(function (data) { }).done(function (data) {
input.prop('disabled', false); input.prop('disabled', false);
input.data('limit', data.id);
// update amount left. // update amount left.
$('.left_span[data-limit="0"][data-id="' + budgetId + '"]').html(data.left_formatted); $('.left_span[data-limit="0"][data-id="' + budgetId + '"]').html(data.left_formatted);
if (data.left_per_day > 0) { if (data.left_per_day > 0) {
@@ -113,6 +114,7 @@ function updateBudgetedAmount(e) {
amount: input.val(), amount: input.val(),
}).done(function (data) { }).done(function (data) {
input.prop('disabled', false); input.prop('disabled', false);
input.data('limit', data.id);
$('.left_span[data-limit="' + budgetLimitId + '"]').html(data.left_formatted); $('.left_span[data-limit="' + budgetLimitId + '"]').html(data.left_formatted);
if (data.left_per_day > 0) { if (data.left_per_day > 0) {
$('.left_span[data-limit="' + budgetLimitId + '"]').html(data.left_formatted + '(' + data.left_per_day_formatted + ')'); $('.left_span[data-limit="' + budgetLimitId + '"]').html(data.left_formatted + '(' + data.left_per_day_formatted + ')');