diff --git a/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaCreditsCmd.java b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaCreditsCmd.java index 92863d49bd4..bb952f71b33 100644 --- a/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaCreditsCmd.java +++ b/plugins/database/quota/src/org/apache/cloudstack/api/command/QuotaCreditsCmd.java @@ -95,6 +95,9 @@ public class QuotaCreditsCmd extends BaseCmd { if (accountId == null) { throw new ServerApiException(ApiErrorCode.INTERNAL_ERROR, "The account does not exists or has been removed/disabled"); } + if (value == null) { + throw new ServerApiException(ApiErrorCode.PARAM_ERROR, "Please send a valid non-empty quota value"); + } final QuotaCreditsResponse response = _quotaDBUtils.addQuotaCredits(accountId, domainId, value, CallContext.current().getCallingUserId()); response.setResponseName(getCommandName()); diff --git a/ui/plugins/quota/quota.js b/ui/plugins/quota/quota.js index 650476496fe..97be08ebe80 100644 --- a/ui/plugins/quota/quota.js +++ b/ui/plugins/quota/quota.js @@ -91,6 +91,7 @@ var g_quotaCurrency = ''; 'render': function ($node) { var statementView = $('
'); var generatedStatement = $('
'); + var generatedBalanceStatement = $('
'); var statementForm = $('
'); var domainDropdown = $('
'); @@ -189,6 +190,85 @@ var g_quotaCurrency = ''; } } }); + + $.ajax({ + url: createURL('quotaBalance'), + data: { + domainid: domainId, + account: account, + startdate: startDate, + enddate: endDate + }, + success: function(json) { + var statement = json.quotabalanceresponse.balance; + var credits = statement.credits; + var startBalance = ''; + var endBalance = ''; + + if (statement.hasOwnProperty('startquota')) { + startBalance = statement.startquota; + } + if (statement.hasOwnProperty('endquota')) { + endBalance = statement.endquota; + } + + generatedBalanceStatement.empty(); + $("
").appendTo(generatedBalanceStatement); + + $("

").html("
Quota Balance sheet:").appendTo(generatedBalanceStatement); + var statementTable = $(''); + statementTable.appendTo($('
').appendTo(generatedBalanceStatement)); + + var statementTableHead = $('
'); + $('').appendTo(statementTable)); + + var statementTableBody = $(''); + + if (startBalance) { + var statementTableBodyRow = $(''); + $(''); + if (i % 2 == 0) { + statementTableBodyRow.addClass('even'); + } else { + statementTableBodyRow.addClass('odd'); + } + $(''); + $('
').html('Description').appendTo(statementTableHead); + $('').html('Amount').appendTo(statementTableHead); + $('').html("Date").appendTo(statementTableHead); + statementTableHead.appendTo($('
').html("Start Balance").appendTo(statementTableBodyRow); + $('').html(g_quotaCurrency + startBalance).appendTo(statementTableBodyRow); + $('').html(startDate).appendTo(statementTableBodyRow); + statementTableBodyRow.appendTo(statementTableBody); + } + + for (var i = 0; i < credits.length; i++) { + var statementTableBodyRow = $('
').html("Credit").appendTo(statementTableBodyRow); + $('').html(g_quotaCurrency + credits[i].credits).appendTo(statementTableBodyRow); + $('').html(credits[i].updated_on).appendTo(statementTableBodyRow); + statementTableBodyRow.appendTo(statementTableBody); + } + + if (endBalance) { + var statementTableBodyRow = $('
').html("End Balance").appendTo(statementTableBodyRow); + $('').html(g_quotaCurrency + endBalance).appendTo(statementTableBodyRow); + $('').html(endDate).appendTo(statementTableBodyRow); + statementTableBodyRow.appendTo(statementTableBody); + } + + statementTableBody.appendTo(statementTable); + }, + error: function(json) { + generatedBalanceStatement.empty(); + var error = JSON.parse(json.responseText); + if (error.hasOwnProperty('quotabalanceresponse')) { + $("
").appendTo(generatedBalanceStatement); + $("

").html("Error: " + error.quotabalanceresponse.errortext).appendTo(generatedBalanceStatement); + } + } + }); + + }); domainDropdown.appendTo(statementForm); @@ -269,6 +349,7 @@ var g_quotaCurrency = ''; statementForm.appendTo(statementView); generatedStatement.appendTo(statementView); + generatedBalanceStatement.appendTo(statementView); statementView.appendTo($node); } }, @@ -385,6 +466,11 @@ var g_quotaCurrency = ''; var account = accountDropdown.find("select :selected").val(); var quotaValue = quotaValueInput.val(); + if (!quotaValue) { + creditStatement.empty(); + return; + } + $.ajax({ url: createURL('quotaCredits'), data: { @@ -394,8 +480,25 @@ var g_quotaCurrency = ''; }, success: function(json) { quotaValueInput.val(''); + creditStatement.empty(); $('


').appendTo(creditStatement); - $('

').html('Credit amount ' + g_quotaCurrency + json.quotacreditsresponse.quotacredits.credits + ' added to the account').appendTo(creditStatement); + $('

').html('Credit amount ' + g_quotaCurrency + json.quotacreditsresponse.quotacredits.credits + ' added to the account ' + account).appendTo(creditStatement); + $.ajax({ + url: createURL('quotaBalance'), + data: { + account: account, + domainid: domainId, + }, + success: function(json) { + if (json.hasOwnProperty('quotabalanceresponse') && json.quotabalanceresponse.hasOwnProperty('balance')) { + $('

').html('Current Quota Balance of "' + account + '": ' + g_quotaCurrency + json.quotabalanceresponse.balance.startquota).appendTo(creditStatement); + } + }, + error: function(json) { + } + }); + + }, error: function(json) { }