Added awareness of Uninitialized Budgets to Attestations

This commit is contained in:
Rick Falkvinge
2016-03-31 19:45:36 +02:00
parent 49c5b75897
commit c0b2d4b0c9
3 changed files with 55 additions and 4 deletions
@@ -279,6 +279,9 @@
<value>Salary #{0:N0} for {1} was DE-attested. It will not be paid out unless attested again.</value>
<comment>When somebody undoes a previous attestation.</comment>
</data>
<data name="AttestCosts_Warn_UninitializedBudget" xml:space="preserve">
<value>&lt;strong&gt;WARNING: UNINITIALIZED BUDGET&lt;/strong&gt;&lt;br/&gt;&lt;br/&gt;The cost you're approving belongs to an uninitialized budget -- an account in the ledger that lacks owner and doesn't have a set budget allowance for the year. Consider visiting the Account Plan and allocating budgets for the expected revenue and expenses.&lt;br/&gt;&lt;br/&gt;This message will only display once per visit to Attestations.&lt;br/&gt;</value>
</data>
<data name="CreateInboundInvoice_Amount" xml:space="preserve">
<value>Invoice amount (in {0})</value>
<comment>{0} is the organization's main currency.</comment>
+21 -1
View File
@@ -32,6 +32,8 @@
'/Images/Icons/iconshock-balloon-undo-128x96px-hot.png'
]);
loadUninitializedBudgets(); // no need to wait for doc.ready
$(document).ready(function () {
$('#TableAttestableCosts').datagrid(
{
@@ -278,6 +280,12 @@
budgetRemainingLookup[accountId] += funds;
setAttestability();
if (budgetUninitializedLookup[accountId] == true && uninitializedPopupDisplayed == false) {
alertify.alert(decodeURIComponent('<asp:Literal id="LiteralWarnUnintializedBudget" runat="server" />'));
uninitializedPopupDisplayed = true;
}
$.ajax({
type: "POST",
url: "/Pages/v5/Financial/AttestCosts.aspx/Attest",
@@ -327,6 +335,16 @@
});
}
function loadUninitializedBudgets() {
SwarmopsJS.ajaxCall("/Pages/v5/Financial/AttestCosts.aspx/GetUninitializedBudgets", {}, function(data) {
console.log(data);
data.forEach(function(accountData, dummy1, dummy2) {
budgetUninitializedLookup[accountData] = true;
// console.log("Rechecking budget " + accountData.AccountId + ": remaining is " + accountData.Remaining);
});
});
}
function setAttestability() {
@@ -337,7 +355,7 @@
// console.log("attestability checking accountid " + accountId + ", amount requested is " + amountRequested + ", funds in budget is " + fundsInBudget);
if (fundsInBudget >= amountRequested) {
if (fundsInBudget >= amountRequested || budgetUninitializedLookup[accountId] == true) {
// console.log("- removing insufficience marker");
$(this).removeClass("LocalFundsInsufficient");
if ($(this).attr("rel") != "loading") {
@@ -445,6 +463,8 @@
var recordId = '';
var accountId = 0;
var budgetRemainingLookup = {};
var budgetUninitializedLookup = {};
var uninitializedPopupDisplayed = false;
// The variable below is advisory for the UI - actual access control is done server-side
var canOverdraftBudgets = <asp:Literal ID="LiteralCanOverdraftBudgets" runat="server" />;
+31 -3
View File
@@ -68,12 +68,12 @@ namespace Swarmops.Frontend.Pages.v5.Financial
// checks the owner.
Dictionary<int, bool> result = new Dictionary<int, bool>();
FinancialAccounts accounts = FinancialAccounts.ForOrganization (authData.CurrentOrganization);
FinancialAccounts accounts = FinancialAccounts.ForOrganization(authData.CurrentOrganization);
foreach (FinancialAccount account in accounts)
{
if (account.OwnerPersonId == authData.CurrentUser.Identity ||
(account.OwnerPersonId == 0 && authData.Authority.HasAccess (new Access (authData.CurrentOrganization, AccessAspect.Administration))))
if (account.OwnerPersonId == authData.CurrentUser.Identity ||
(account.OwnerPersonId == 0 && authData.Authority.HasAccess(new Access(authData.CurrentOrganization, AccessAspect.Administration))))
{
if (account.AccountType == FinancialAccountType.Cost)
{
@@ -85,6 +85,32 @@ namespace Swarmops.Frontend.Pages.v5.Financial
return result;
}
[WebMethod]
public static int[] GetUninitializedBudgets()
{
AuthenticationData authData = GetAuthenticationDataAndCulture();
// This function finds the exceptional accounts that aren't initialized, to let a sysadmin approve expenses to them.
List<int> result = new List<int>();
FinancialAccounts accounts = FinancialAccounts.ForOrganization(authData.CurrentOrganization);
foreach (FinancialAccount account in accounts)
{
if (account.AccountType == FinancialAccountType.Cost)
{
if (account.OwnerPersonId == 0 &&
authData.Authority.HasAccess (new Access (authData.CurrentOrganization,
AccessAspect.Administration)))
{
result.Add (account.Identity);
}
}
}
return result.ToArray();
}
private void Localize()
{
PageTitle = Resources.Pages.Financial.AttestCosts_PageTitle;
@@ -99,6 +125,8 @@ namespace Swarmops.Frontend.Pages.v5.Financial
this.LabelGridHeaderRequested.Text = Resources.Pages.Financial.AttestCosts_GridHeader_Requested;
this.LiteralErrorInsufficientBudget.Text = JavascriptEscape (Resources.Pages.Financial.AttestCosts_OutOfBudget);
this.LiteralWarnUnintializedBudget.Text =
JavascriptEscape (Resources.Pages.Financial.AttestCosts_Warn_UninitializedBudget);
this.LabelDescribeDeny.Text = Resources.Pages.Financial.AttestCosts_Modal_DescribeOptionDeny;
this.LabelDescribeCorrect.Text = String.Format (Resources.Pages.Financial.AttestCosts_Modal_DescribeOptionAmount, CurrentOrganization.Currency.DisplayCode);