diff --git a/Logic/Financial/Payout.cs b/Logic/Financial/Payout.cs index d9271c20..affc1455 100644 --- a/Logic/Financial/Payout.cs +++ b/Logic/Financial/Payout.cs @@ -389,7 +389,7 @@ namespace Swarmops.Logic.Financial SwarmopsLogEntry.Create (null, new PayoutCreatedLogEntry (null, advance.Person, organization, - organization.Currency, advance.AmountCents/100.0, + organization.Currency, advance.AmountCents, "Cash Advance Paid Out"), advance.Person, advance); @@ -518,7 +518,7 @@ namespace Swarmops.Logic.Financial SwarmopsLogEntry.Create (creator, new PayoutCreatedLogEntry (creator, advance.Person, organization, - organization.Currency, amountCents/100.0, + organization.Currency, amountCents, "Cash Advance Paid Out"), advance.Person, advance); @@ -614,7 +614,7 @@ namespace Swarmops.Logic.Financial SwarmopsLogEntry.Create (creator, new PayoutCreatedLogEntry (creator, beneficiaryPerson, organization, - organization.Currency, amountCents/100.0, + organization.Currency, amountCents, referenceString), beneficiaryPerson); diff --git a/Logic/Support/LogEntries/CashAdvanceRequestedLogEntry.cs b/Logic/Support/LogEntries/CashAdvanceRequestedLogEntry.cs index 05af4f1c..c6251ab1 100644 --- a/Logic/Support/LogEntries/CashAdvanceRequestedLogEntry.cs +++ b/Logic/Support/LogEntries/CashAdvanceRequestedLogEntry.cs @@ -16,7 +16,7 @@ namespace Swarmops.Logic.Support.LogEntries FinancialAccount budget, string reason) { Amount = amount; - Currency = budget.Organization.Currency.Code; + CurrencyCode = budget.Organization.Currency.Code; DateTime = DateTime.UtcNow; Description = reason; OrganizationId = budget.OrganizationId; diff --git a/Logic/Support/LogEntries/ExpenseClaimFiledLogEntry.cs b/Logic/Support/LogEntries/ExpenseClaimFiledLogEntry.cs index 7042db26..6be073f9 100644 --- a/Logic/Support/LogEntries/ExpenseClaimFiledLogEntry.cs +++ b/Logic/Support/LogEntries/ExpenseClaimFiledLogEntry.cs @@ -17,7 +17,7 @@ namespace Swarmops.Logic.Support.LogEntries { Amount = amount; Vat = vat; - Currency = budget.Organization.Currency.Code; + CurrencyCode = budget.Organization.Currency.Code; DateTime = DateTime.UtcNow; Description = reason; OrganizationId = budget.OrganizationId; diff --git a/Logic/Support/LogEntries/FinancialActionBase.cs b/Logic/Support/LogEntries/FinancialActionBase.cs index 08e89a22..cf5902bc 100644 --- a/Logic/Support/LogEntries/FinancialActionBase.cs +++ b/Logic/Support/LogEntries/FinancialActionBase.cs @@ -10,9 +10,16 @@ namespace Swarmops.Logic.Support.LogEntries public int ActingPersonId { get; set; } public int BeneficiaryPersonId { get; set; } public int OrganizationId { get; set; } + + [Obsolete("Find and eliminate all uses of double-precision in financial")] public double Amount { get; set; } + public Int64 AmountCents { get; set; } + + [Obsolete("Find and eliminate all uses of double-precision in financial")] public double Vat { get; set; } - public string Currency { get; set; } + public Int64 VatCents { get; set; } + + public string CurrencyCode { get; set; } public string Description { get; set; } public int OwnerPersonId { get; set; } public string OwnerPersonName { get; set; } diff --git a/Logic/Support/LogEntries/InboundInvoiceCreatedLogEntry.cs b/Logic/Support/LogEntries/InboundInvoiceCreatedLogEntry.cs index bd5c93d1..08b5375c 100644 --- a/Logic/Support/LogEntries/InboundInvoiceCreatedLogEntry.cs +++ b/Logic/Support/LogEntries/InboundInvoiceCreatedLogEntry.cs @@ -16,7 +16,7 @@ namespace Swarmops.Logic.Support.LogEntries FinancialAccount budget) { Amount = amount; - Currency = budget.Organization.Currency.Code; + CurrencyCode = budget.Organization.Currency.Code; DateTime = DateTime.UtcNow; Description = description; OrganizationId = budget.OrganizationId; diff --git a/Logic/Support/LogEntries/PayoutCreatedLogEntry.cs b/Logic/Support/LogEntries/PayoutCreatedLogEntry.cs index a86fc959..13bd9263 100644 --- a/Logic/Support/LogEntries/PayoutCreatedLogEntry.cs +++ b/Logic/Support/LogEntries/PayoutCreatedLogEntry.cs @@ -14,10 +14,10 @@ namespace Swarmops.Logic.Support.LogEntries } public PayoutCreatedLogEntry (Person payingPerson, Person beneficiaryPerson, Organization organization, - Currency currency, double amount, string reason) + Currency currency, Int64 amountCents, string reason) { - Amount = amount; - Currency = currency.Code; + AmountCents = amountCents; + CurrencyCode = currency.Code; OrganizationId = organization.Identity; DateTime = DateTime.UtcNow; Description = reason; diff --git a/Logic/Support/LogEntries/SalaryCreatedLogEntry.cs b/Logic/Support/LogEntries/SalaryCreatedLogEntry.cs index 8ea5c694..bdb3512c 100644 --- a/Logic/Support/LogEntries/SalaryCreatedLogEntry.cs +++ b/Logic/Support/LogEntries/SalaryCreatedLogEntry.cs @@ -17,7 +17,7 @@ namespace Swarmops.Logic.Support.LogEntries ActingPersonId = 0; BeneficiaryPersonId = salary.PayrollItem.PersonId; Amount = salary.NetSalaryCents/100.0; - Currency = salary.Budget.Organization.Currency.Code; + CurrencyCode = salary.Budget.Organization.Currency.Code; DateTime = DateTime.UtcNow; FinancialAccountId = salary.Budget.Identity; FinancialAccountName = salary.Budget.Name; diff --git a/Site/Pages/v5/Financial/Json-PayableCosts.aspx.cs b/Site/Pages/v5/Financial/Json-PayableCosts.aspx.cs index e5ba1311..1f57bc74 100644 --- a/Site/Pages/v5/Financial/Json-PayableCosts.aspx.cs +++ b/Site/Pages/v5/Financial/Json-PayableCosts.aspx.cs @@ -69,11 +69,12 @@ namespace Swarmops.Frontend.Pages.Financial "\"reference\":\"{5}\"," + "\"amount\":\"{6}\"," + "\"action\":\"" + - "" + - "" + - "" + - "" + - "" + + "" + + "" + + "" + + "" + + "" + + "" + "\"", payout.ProtoIdentity, (payout.ExpectedTransactionDate <= today @@ -100,13 +101,12 @@ namespace Swarmops.Frontend.Pages.Financial { StringBuilder result = new StringBuilder(16384); - DateTime today = DateTime.Today; - foreach (Payout payout in payouts) { result.Append("{"); result.AppendFormat( "\"itemId\":\"{0}\"," + + "\"paid\":\"yes\"," + "\"databaseId\":\"{8}\"," + "\"due\":\"{1}\"," + "\"recipient\":\"{2}\"," + @@ -115,11 +115,12 @@ namespace Swarmops.Frontend.Pages.Financial "\"reference\":\"{5}\"," + "\"amount\":\"{6:N2}\"," + "\"action\":\"" + - "" + - "" + - "" + - "" + - "" + + "" + + "" + + "" + + "" + + "" + + "" + "\"", payout.ProtoIdentity, payout.ExpectedTransactionDate.ToShortDateString(), diff --git a/Site/Pages/v5/Financial/Json-PayableCostsOcr.aspx.cs b/Site/Pages/v5/Financial/Json-PayableCostsOcr.aspx.cs index db2c22ad..4c659f81 100644 --- a/Site/Pages/v5/Financial/Json-PayableCostsOcr.aspx.cs +++ b/Site/Pages/v5/Financial/Json-PayableCostsOcr.aspx.cs @@ -81,11 +81,12 @@ namespace Swarmops.Frontend.Pages.Financial "\"amount\":\"{3}\"," + "\"account\":\"{4}\"," + "\"action\":\"" + - "" + - "" + - "" + - "" + - "" + + "" + + "" + + "" + + "" + + "" + + "" + "\"" , payout.ProtoIdentity, (payout.ExpectedTransactionDate <= today diff --git a/Site/Pages/v5/Financial/PayOutMoney.aspx b/Site/Pages/v5/Financial/PayOutMoney.aspx index 47e478d3..d4f08730 100644 --- a/Site/Pages/v5/Financial/PayOutMoney.aspx +++ b/Site/Pages/v5/Financial/PayOutMoney.aspx @@ -39,9 +39,9 @@ var checked = $('#CheckOptionsShowPrevious').prop('checked'); if (checked) { - $('.rowPrevious').show(); + $('.LocalPaid').show(); } else { - $('.rowPrevious').hide(); + $('.LocalPaid').hide(); } }); @@ -61,14 +61,14 @@ { rowStyler: function (index, rowData) { if (rowData.databaseId != null) { - return { class: "rowPrevious row" + rowData.itemId.replace(/\|/g, '') }; + return { class: "action-list-item-approved row" + rowData.itemId.replace(/\|/g, "") }; } if (rowData.itemId != null) { - return { class: "row" + rowData.itemId.replace(/\|/g, '') }; + return { class: "row" + rowData.itemId.replace(/\|/g, "") }; } - return ''; + return ""; }, onLoadSuccess: function () { @@ -82,47 +82,79 @@ $(".LocalIconApproval").attr("src", "/Images/Icons/iconshock-balloon-yes-128x96px.png"); $(".LocalIconApproved").attr("src", "/Images/Icons/iconshock-green-tick-128x96px.png").css("opacity", 0.5); $(".LocalIconDenied").attr("src", "/Images/Icons/iconshock-red-cross-circled-128x96px.png"); - $(".LocalIconUndo").attr("src", "/Images/Icons/iconshock-balloon-undo-128x96px.png"); - $(".LocalIconApproved.LocalPrototype, .LocalIconUndo.LocalPrototype, .LocalIconDenied.LocalPrototype, .LocalIconApproval.LocalPrevious, .LocalIconDenial.LocalPrevious, .LocalIconDenied.LocalPrevious").css("display", "none"); + $(".LocalIconUndo").attr("src", "/Images/Icons/iconshock-balloon-undo-128x96px.png").hide(); + $(".LocalIconApproved.LocalPrototype, .LocalIconUndo.LocalPrototype, .LocalIconDenied.LocalPrototype, .LocalIconApproval.LocalPaid, .LocalIconDenial.LocalPaid, .LocalIconDenied.LocalPaid").hide(); $(".LocalIconDenial").attr("src", "/Images/Icons/iconshock-balloon-no-128x96px-disabled.png"); $(".LocalIconApproval, .LocalIconUndo, .LocalIconDenial").css("cursor", "pointer"); - $(".LocalIconApproval").mouseover(function() { - if ($(this).attr("rel") != "loading") { - $(this).attr("src", "/Images/Icons/iconshock-balloon-yes-128x96px-hot.png"); - } + $(".LocalIconApproval").click(function () { + var itemId = $(this).attr("baseid"); + var prototypeId = $(this).attr("protoid"); + $(this).hide(); + $("#IconWait" + itemId).show(); + $("#IconDenial" + itemId).fadeTo(1000, 0.01); + + SwarmopsJS.proxiedAjaxCall( + "/Pages/v5/Financial/PayOutMoney.aspx/ConfirmPayout", + { protoIdentity: prototypeId }, + this, + function (result) { + if (result.Success) { + var itemId = $(this).attr("baseid"); + $('.row' + itemId).addClass("action-list-item-approved"); + $("#IconApproval" + itemId).attr("databaseid", msg.d.AssignedId); + $(".IconWait" + itemId).hide(); + $(".IconDenial" + itemId).hide(); + $(".IconApproved" + itemId).fadeTo(200, 0.5); // half opacity is intentional + $(".IconUndo" + itemId).fadeTo(1000, 1); // the longer delay is intentional + alertify.success(result.DisplayMessage); + } else { + // There's probably a concurrency error. + // The socket handler will take care of updating the UI on + // receiving the cause of the concurrency error. + + alertify.log(result.DisplayMessage); + + } + } + ); }); - $(".LocalIconApproval").mouseout(function() { - if ($(this).attr("rel") != "loading") { - $(this).attr("src", "/Images/Icons/iconshock-balloon-yes-128x96px.png"); - } + + $(".LocalIconUndo").click(function() { + $(this).hide(); + var itemId = $(this).attr("baseid"); + $(".IconApproved" + itemId).fadeTo(1000, 0.01); + $(".IconWait" + itemId).show(); + + SwarmopsJS.proxiedAjaxCall( + "/Pages/v5/Financial/PayOutMoney.aspx/UndoPayout", + { databaseId: $(this).attr("databaseid") }, + this, + function(result) { + if (result.Success) { + var itemId = $(this).attr("baseid"); + $('.row' + itemId).removeClass("action-list-item-approved"); + $(".IconWait" + itemId).hide(); + $(".IconApproved" + itemId).hide(); + $(".IconApproval" + itemId).fadeTo(200, 1); + $(".IconDenial" + itemId).fadeTo(200, 1); + alertify.log(result.DisplayMessage); + + } else { + // There's probably a concurrency error. + // The socket handler will take care of updating the UI on + // receiving the cause of the concurrency error. + + alertify.log(result.DisplayMessage); + } + } + ); }); - $(".LocalIconUndo").mouseover(function() { - if ($(this).attr("rel") != "loading") { - $(this).attr("src", "/Images/Icons/iconshock-balloon-undo-128x96px-hot.png"); - } - }); - $(".LocalIconUndo").mouseout(function() { - if ($(this).attr("rel") != "loading") { - $(this).attr("src", "/Images/Icons/iconshock-balloon-undo-128x96px.png"); - } - }); - - $(".LocalIconDenial").mouseover(function() { - if ($(this).attr("rel") != "loading") { - $(this).attr("src", "/Images/Icons/iconshock-balloon-no-128x96px-hot-disabled.png"); - } - }); - - $(".LocalIconDenial").mouseout(function() { - if ($(this).attr("rel") != "loading") { - $(this).attr("src", "/Images/Icons/iconshock-balloon-no-128x96px-disabled.png"); - } - }); + /* $(".LocalIconApproval").click(function() { if ($(this).attr("rel") != "loading") { @@ -155,6 +187,9 @@ } }); + + + $(".LocalIconUndo").click(function() { if ($(this).attr("rel") != "loading") { var jsonData = {}; @@ -190,7 +225,7 @@ }); } - }); + });*/ } } diff --git a/Site/Pages/v5/Financial/PayOutMoney.aspx.cs b/Site/Pages/v5/Financial/PayOutMoney.aspx.cs index 1dc70449..2fe9a814 100644 --- a/Site/Pages/v5/Financial/PayOutMoney.aspx.cs +++ b/Site/Pages/v5/Financial/PayOutMoney.aspx.cs @@ -7,6 +7,7 @@ using Swarmops.Common.Enums; using Swarmops.Logic.Financial; using Swarmops.Logic.Security; using Swarmops.Logic.Support; +using Swarmops.Logic.Support.LogEntries; namespace Swarmops.Frontend.Pages.Financial { @@ -67,74 +68,64 @@ namespace Swarmops.Frontend.Pages.Financial [WebMethod] public static ConfirmPayoutResult ConfirmPayout (string protoIdentity) { - protoIdentity = HttpUtility.UrlDecode (protoIdentity); - AuthenticationData authData = GetAuthenticationDataAndCulture(); if ( !authData.Authority.HasAccess (new Access (authData.CurrentOrganization, AccessAspect.Financials, AccessType.Write))) { - throw new SecurityException ("Insufficient privileges for operation"); + throw new UnauthorizedAccessException("Insufficient privileges for operation"); } - ConfirmPayoutResult result = new ConfirmPayoutResult(); - - Payout payout = Payout.CreateFromProtoIdentity (authData.CurrentUser, protoIdentity); - PWEvents.CreateEvent (EventSource.PirateWeb, EventType.PayoutCreated, - authData.CurrentUser.Identity, 1, 1, 0, payout.Identity, - protoIdentity); + Payout payout = Payout.CreateFromProtoIdentity (authData.CurrentUser, protoIdentity); // TODO: Catch ConcurrencyException // Create result and return it - result.AssignedId = payout.Identity; - result.DisplayMessage = String.Format (Resources.Pages.Financial.PayOutMoney_PayoutCreated, payout.Identity, - payout.Recipient); - - return result; + return new ConfirmPayoutResult + { + AssignedId = payout.Identity, + DisplayMessage = String.Format(Resources.Pages.Financial.PayOutMoney_PayoutCreated, payout.Identity, + payout.Recipient), + Success = true + }; } [WebMethod] - public static UndoPayoutResult UndoPayout (int databaseId) + public static AjaxCallResult UndoPayout (int databaseId) { AuthenticationData authData = GetAuthenticationDataAndCulture(); if ( !authData.Authority.HasAccess(new Access(authData.CurrentOrganization, AccessAspect.Financials))) { - throw new SecurityException("Insufficient privileges for operation"); + throw new UnauthorizedAccessException("Insufficient privileges for operation"); } - UndoPayoutResult result = new UndoPayoutResult(); Payout payout = Payout.FromIdentity (databaseId); if (!payout.Open) { - // this payout has already been settled, or picked up for settling + // this payout has already been settled, or picked up for settling. This is a concurrency error, only detected earlier than the database layer. - result.Success = false; - result.DisplayMessage = String.Format (Resources.Pages.Financial.PayOutMoney_PayoutCannotUndo, - databaseId); - - return result; + return new AjaxCallResult + { + Success = false, + DisplayMessage = String.Format(Resources.Pages.Financial.PayOutMoney_PayoutCannotUndo, + databaseId) + }; } - payout.UndoPayout(); + payout.UndoPayout(); // TODO: catch ConcurrencyException - result.DisplayMessage = String.Format (Resources.Pages.Financial.PayOutMoney_PayoutUndone, databaseId); - result.Success = true; - return result; + return new AjaxCallResult + { + DisplayMessage = String.Format(Resources.Pages.Financial.PayOutMoney_PayoutUndone, databaseId), + Success = true + }; } - public struct ConfirmPayoutResult + public class ConfirmPayoutResult: AjaxCallResult { public int AssignedId; - public string DisplayMessage; }; - - public struct UndoPayoutResult - { - public string DisplayMessage; - public bool Success; - } } } \ No newline at end of file diff --git a/todo.txt b/todo.txt index a420b1ce..ca0747ea 100644 --- a/todo.txt +++ b/todo.txt @@ -1,4 +1,4 @@ -NOV2018 +FEB2019 ======= OVERALL: