From 64233477bc297013eaa99f0db587a4e5cc1d4c0e Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sat, 21 Mar 2015 01:58:24 +0100 Subject: [PATCH] Significant improvements to payout maintenance --- Logic/Financial/Payout.cs | 6 - Site5/App_GlobalResources/Global.resx | 4 + .../App_GlobalResources/Pages.Financial.resx | 2 +- .../iconshock-balloon-no-16px-disabled.png | Bin 0 -> 931 bytes .../Icons/iconshock-balloon-undo-16px-hot.png | Bin 0 -> 931 bytes .../v5/Financial/Json-PayableCosts.aspx.cs | 59 ++++++-- Site5/Pages/v5/Financial/PayOutMoney.aspx | 133 +++++++++++++----- Site5/Pages/v5/Financial/PayOutMoney.aspx.cs | 25 +++- Site5/Pages/v5/Ledgers/AccountPlan.aspx.cs | 1 + 9 files changed, 175 insertions(+), 55 deletions(-) create mode 100644 Site5/Images/Icons/iconshock-balloon-no-16px-disabled.png create mode 100644 Site5/Images/Icons/iconshock-balloon-undo-16px-hot.png diff --git a/Logic/Financial/Payout.cs b/Logic/Financial/Payout.cs index f9ddb6ce..2c303edd 100644 --- a/Logic/Financial/Payout.cs +++ b/Logic/Financial/Payout.cs @@ -172,12 +172,6 @@ namespace Swarmops.Logic.Financial { get { - if (Identity != 0) - { - throw new InvalidOperationException ( - "Should never use ProtoIdentity after Identity has been established"); - } - string result = string.Empty; // ReSharper disable LoopCanBeConvertedToQuery diff --git a/Site5/App_GlobalResources/Global.resx b/Site5/App_GlobalResources/Global.resx index 6677d60d..0ab752b3 100644 --- a/Site5/App_GlobalResources/Global.resx +++ b/Site5/App_GlobalResources/Global.resx @@ -644,4 +644,8 @@ -- Several - select -- Displayed when multiple choice + + Options + For various page-specific checkboxes etc + \ No newline at end of file diff --git a/Site5/App_GlobalResources/Pages.Financial.resx b/Site5/App_GlobalResources/Pages.Financial.resx index b962e47b..353a574a 100644 --- a/Site5/App_GlobalResources/Pages.Financial.resx +++ b/Site5/App_GlobalResources/Pages.Financial.resx @@ -330,7 +330,7 @@ These are the various forms of costs to the organization that have passed all the hurdles for payout. They are ready to be paid out to the recipient. Here is where you check them off as being paid out (probably while having your bank open in another window). - Show open, unmatched payouts ({0:N0}) + Show open payouts ({0:N0}) These are payouts that have been ordered, but aren't yet mapped to actual transactions. Can be shown for the purpose of undoing them if they were wrong. diff --git a/Site5/Images/Icons/iconshock-balloon-no-16px-disabled.png b/Site5/Images/Icons/iconshock-balloon-no-16px-disabled.png new file mode 100644 index 0000000000000000000000000000000000000000..95ad50d1759a5cdd2852fae3c52a59a95ef60eb2 GIT binary patch literal 931 zcmV;U16=%xP)Y?-+D@CM7L`J0z(S$phz2thK?fK91G5p_xf28* zxKYsoL9LB1?84PxX%Smmv?4We##-9M(B@&rG|zjJn|m|&{#-b8F)loCHs`2wg@;EU914YyWf@gf=~@ zafA>^l0+a7z%UFlnGCU5jASy25CY4xC>Dz-?|k^t^33FgnE_oV5{VFvM%mrnMNt%N z+r}^qj*gC)oSbBFaSIRB-q&4!1Fv5MPYb& znDOy(Y}=+-EF#M?nx-MkGP2d}1Z>-8b#;~F<73+GHp|P))M_=x#>Oa>O62o-*4Ni* zG#d2#eNInL>GgV4Dix$xUw_lN^29|=Q50lZW@l#yMN#PWdgSwYqR}WmpAW}z@cDeq z&dw4H25B~%{BdxAeA+gD&*pL{s><#L&Bx68u90;Xw_PN#{*Vl)~J^7%Z$V32CH zO6D-CIJcQp`>SZ%|&{M3_|@jQ>Er6v4+Kb=koP169Fo}Q*qC@?xYO14hJm?+(ae&GNB002ovPDHLk FV1hbbxyt|m literal 0 HcmV?d00001 diff --git a/Site5/Images/Icons/iconshock-balloon-undo-16px-hot.png b/Site5/Images/Icons/iconshock-balloon-undo-16px-hot.png new file mode 100644 index 0000000000000000000000000000000000000000..d3a2833ec927d53494805a1b9810b9ca8e3e3428 GIT binary patch literal 931 zcmV;U16=%xP)NIHMXK4L|f7}=G4YCP0~c&=ICa#o6XK-cV-VWv-^9|v>*ujzmRy080XN6|iLsBcsY`2vBGkmUhQSos2`>!OB&c=;^e>dKM*yE@;! zr9So2Yq#~!&dqdPiO4ld@?Th$vb0o`@`p%NcJ&SYEC94%UFgiv+2L?iZOa22*GoX; zfa5=986024kH^z{>e<&`2|xl^Fl?E1oEs;c>K*87X}kOW`gH+W1;PjHJu*vA?+``L z10evx8_%@z{_{I90T;M7AIJCJr=PdgZEe1{qFj^eTJxDvhqJ$2qO+;Qxuf@S;`LVa zavvXkHOf>XgJC-)ZHJm_9mQW3dIX`WQ8P;^U9MClFm9@TZr?{q1z#6@aA({=$UYM`{UpEYazyCZGO^j z0jKCnW7XoqXe8@z*tyGRYvE_NZ`wdvC?Lv%8q4_{yW6X|8jGV50Lx@|dw|xRHDn47 z0Y&5Df?LO*f>QdBhyz`*CPOogP)@34{5ed^`E|J8ra#+qPRU0H(>5%t4sVbTn zydD#?13jM&fAQg~ek1RA;Zm_{$}B#S^!)2Pni}b7YM^Cv9h<9l8p2`9R1Jhr&X_qd zHZfUR8u|6D$mx@Z0eS0{AL{7bG~9Mz%8_cQK3pbiD*{46vXC@c%@sV{ycd|gI=s^N z{V~7*V!)ru%>~Of+xB`=2_pQMMoOg4pZm^ErlxW8d6uIF#mu60LsWqf&;%p}z&(2& z-x06eGGc4`N-(pOOr8Jw6UWXB02OP3Z!G{4@PK7t@^A4inXU?w;K%>~002ovPDHLk FV1oOUzwiJ6 literal 0 HcmV?d00001 diff --git a/Site5/Pages/v5/Financial/Json-PayableCosts.aspx.cs b/Site5/Pages/v5/Financial/Json-PayableCosts.aspx.cs index 850f932a..2257de4d 100644 --- a/Site5/Pages/v5/Financial/Json-PayableCosts.aspx.cs +++ b/Site5/Pages/v5/Financial/Json-PayableCosts.aspx.cs @@ -16,22 +16,21 @@ namespace Swarmops.Frontend.Pages.Financial // Get all payable items - Payouts payouts = Payouts.Construct (CurrentOrganization); + Payouts prototypePayouts = Payouts.Construct (CurrentOrganization); + Payouts previousPayouts = Payouts.ForOrganization (CurrentOrganization); // gets all currently open payouts - enabled for undoing // Format as JSON and return Response.ContentType = "application/json"; - string json = FormatAsJson (payouts); + string json = "{\"rows\":[" + FormatPrototypesAsJson (prototypePayouts) + "," + FormatPreviousAsJson (previousPayouts) + "]}"; Response.Output.WriteLine (json); Response.End(); } - private string FormatAsJson (Payouts payouts) + private string FormatPrototypesAsJson (Payouts payouts) { StringBuilder result = new StringBuilder (16384); - result.Append ("{\"rows\":["); - DateTime today = DateTime.Today; foreach (Payout payout in payouts) @@ -46,8 +45,12 @@ namespace Swarmops.Frontend.Pages.Financial "\"reference\":\"{5}\"," + "\"amount\":\"{6:N2}\"," + "\"action\":\"" + - "" + - "\"", + "" + + "" + + "" + + "" + + "" + + "\"", payout.ProtoIdentity, (payout.ExpectedTransactionDate <= today ? Global.Global_ASAP @@ -63,7 +66,47 @@ namespace Swarmops.Frontend.Pages.Financial result.Remove (result.Length - 1, 1); // remove last comma - result.Append ("]}"); + return result.ToString(); + } + + private string FormatPreviousAsJson(Payouts payouts) + { + StringBuilder result = new StringBuilder(16384); + + DateTime today = DateTime.Today; + + foreach (Payout payout in payouts) + { + result.Append("{"); + result.AppendFormat( + "\"itemId\":\"{0}\"," + + "\"databaseId\":\"{8}\"," + + "\"due\":\"{1}\"," + + "\"recipient\":\"{2}\"," + + "\"bank\":\"{3}\"," + + "\"account\":\"{4}\"," + + "\"reference\":\"{5}\"," + + "\"amount\":\"{6:N2}\"," + + "\"action\":\"" + + "" + + "" + + "" + + "" + + "" + + "\"", + payout.ProtoIdentity, + payout.ExpectedTransactionDate.ToShortDateString(), + JsonSanitize(TryLocalize(payout.Recipient)), + JsonSanitize(payout.Bank), + JsonSanitize(payout.Account), + JsonSanitize(TryLocalize(payout.Reference)), + payout.AmountCents / 100.0, + payout.ProtoIdentity.Replace("|", ""), + payout.Identity); + result.Append("},"); + } + + result.Remove(result.Length - 1, 1); // remove last comma return result.ToString(); } diff --git a/Site5/Pages/v5/Financial/PayOutMoney.aspx b/Site5/Pages/v5/Financial/PayOutMoney.aspx index 06623554..24c728ad 100644 --- a/Site5/Pages/v5/Financial/PayOutMoney.aspx +++ b/Site5/Pages/v5/Financial/PayOutMoney.aspx @@ -14,19 +14,46 @@ '/Images/Abstract/ajaxloader-medium.gif', '/Images/Icons/iconshock-balloon-yes-16px-hot.png', '/Images/Icons/iconshock-balloon-no-16px-hot.png', + '/Images/Icons/iconshock-balloon-undo-16px-hot.png', '/Images/Icons/iconshock-greentick-16px.png', '/Images/Icons/iconshock-redcross-16px.png', - '/Images/Icons/undo-16px.png' + '/Images/Icons/iconshock-balloon-undo-16px.png' ]); $(document).ready(function () { + + $('#CheckOptionsShowPrevious').change(function() { + var checked = $('#CheckOptionsShowPrevious').prop('checked'); + + if (checked) { + $('.rowPrevious').show(); + } else { + $('.rowPrevious').hide(); + } + }); + $('#TablePayableCosts').datagrid( { + rowStyler: function (index, rowData) { + if (rowData.databaseId != null) { + return { class: "rowPrevious row" + rowData.itemId.replace(/\|/g, '') }; + } + + if (rowData.itemId != null) { + return { class: "row" + rowData.itemId.replace(/\|/g, '') }; + } + + return ''; + }, + onLoadSuccess: function () { $(".LocalIconApproval").attr("src", "/Images/Icons/iconshock-balloon-yes-16px.png"); + $(".LocalIconDenial").attr("src", "/Images/Icons/iconshock-balloon-no-16px-disabled.png"); $(".LocalIconApproved").attr("src", "/Images/Icons/iconshock-greentick-16px.png"); - $(".LocalIconApproved").css("display", "none"); - $(".LocalIconApproval, .LocalIconApproved").css("cursor", "pointer"); + $(".LocalIconDenied").attr("src", "/Images/Icons/iconshock-cross-16px.png"); + $(".LocalIconUndo").attr("src", "/Images/Icons/iconshock-balloon-undo-16px.png"); + $(".LocalIconApproved.LocalPrototype, .LocalIconUndo.LocalPrototype, .LocalIconDenied.LocalPrototype, .LocalIconApproval.LocalPrevious, .LocalIconDenial.LocalPrevious, .LocalIconDenied.LocalPrevious").css("display", "none"); + $(".LocalIconApproval, .LocalIconUndo").css("cursor", "pointer"); $(".LocalIconApproval").mouseover(function () { if ($(this).attr("rel") != "loading") { @@ -40,68 +67,82 @@ } }); - $(".LocalIconApproved").mouseover(function () { + $(".LocalIconUndo").mouseover(function () { if ($(this).attr("rel") != "loading") { - $(this).attr("src", "/Images/Icons/undo-16px.png"); + $(this).attr("src", "/Images/Icons/iconshock-balloon-undo-16px-hot.png"); } }); - $(".LocalIconApproved").mouseout(function () { + $(".LocalIconUndo").mouseout(function () { if ($(this).attr("rel") != "loading") { - $(this).attr("src", "/Images/Icons/iconshock-greentick-16px.png"); + $(this).attr("src", "/Images/Icons/iconshock-balloon-undo-16px.png"); } }); $(".LocalIconApproval").click(function () { if ($(this).attr("rel") != "loading") { + + var jsonData = {}; + jsonData.protoIdentity = $(this).attr("baseid"); + $(this).attr("rel", "loading"); $(this).attr("src", "/Images/Abstract/ajaxloader-medium.gif"); - $("#IconDenial" + $(this).attr("baseid").replace(/\|/g,'')).fadeTo(1000, 0.01).css("cursor", "default"); - var thisIcon = this; + $("#IconDenial" + $(this).attr("baseid").replace(/\|/g,'')).fadeTo(1000, 0.01); + $.ajax({ type: "POST", url: "/Pages/v5/Financial/PayOutMoney.aspx/ConfirmPayout", - data: "{'protoIdentity': '" + escape($(this).attr("baseid")) + "'}", + data: $.toJSON(jsonData), contentType: "application/json; charset=utf-8", dataType: "json", - success: function (msg) { - $(thisIcon).attr("databaseid", msg.d.AssignedId); - $(thisIcon).css("display", "none"); - $(thisIcon).attr("src", "/Images/Icons/iconshock-balloon-yes-16px.png"); - $(thisIcon).attr("rel", "active"); - $("#IconApproved" + $(thisIcon).attr("baseid").replace(/\|/g, '')).fadeIn(100); - alertify.success(unescape(msg.d.DisplayMessage)); - } + success: $.proxy(function (msg) { + var baseid = $(this).attr("baseid").replace(/\|/g, ''); + $(this).attr("databaseid", msg.d.AssignedId); + $(this).attr("src", "/Images/Icons/iconshock-balloon-yes-16px.png"); + $(this).attr("rel", "active"); + $(this).hide(); + $("#IconApproved" + baseid).fadeIn(100); + $("#IconDenial" + baseid).css('opacity', 1.0).hide(); + $("#IconUndo" + baseid).fadeIn(100); + $('.row' + baseid).animate({ color: "#888" }, 400); + alertify.success(msg.d.DisplayMessage); + }, this) }); } }); - $(".LocalIconApproved").click(function () { + $(".LocalIconUndo").click(function () { if ($(this).attr("rel") != "loading") { - var thisIcon = this; - + var jsonData = {}; + jsonData.databaseId = $("#IconApproval" + $(this).attr("baseid").replace(/\|/g, '')).attr("databaseid"); + $(this).attr("rel", "loading"); $(this).attr("src", "/Images/Abstract/ajaxloader-medium.gif"); + $("#IconApproved" + $(this).attr("baseid").replace(/\|/g, '')).fadeTo(1000, 0.01); + $.ajax({ type: "POST", url: "/Pages/v5/Financial/PayOutMoney.aspx/UndoPayout", - data: "{'databaseId': '" + $("#IconApproval" + $(thisIcon).attr("baseid").replace(/\|/g, '')).attr("databaseid") + "'}", + data: $.toJSON(jsonData), contentType: "application/json; charset=utf-8", dataType: "json", - success: function (msg) { + success: $.proxy(function (msg) { if (msg.d.Success) { - $(thisIcon).css("display", "none"); - $(thisIcon).attr("src", "/Images/Icons/iconshock-greentick-16px.png"); - $(thisIcon).attr("rel", ""); - $("#IconApproval" + $(thisIcon).attr("baseid").replace(/\|/g, '')).fadeIn(100); - $("#" + $(thisIcon).attr("rel"), ""); - alertify.log(unescape(msg.d.DisplayMessage)); + var baseid = $(this).attr("baseid").replace(/\|/g, ''); + $(this).attr("src", "/Images/Icons/iconshock-balloon-undo-16px.png"); + $(this).attr("rel", ""); + $(this).hide(); + $("#IconApproved" + baseid).css('opacity', 1.0).hide(); + $("#IconApproval" + baseid).fadeIn(100); + $("#IconDenial" + baseid).fadeIn(100); + $('.row' + baseid).animate({ color: "#000" }, 100); + alertify.log(msg.d.DisplayMessage); } else { - $(thisIcon).attr("src", "/Images/Icons/iconshock-greentick-16px.png"); - alertify.error(unescape(msg.d.DisplayMessage)); + $(this).attr("src", "/Images/Icons/iconshock-greentick-16px.png"); + alertify.error(msg.d.DisplayMessage); // TODO: Add alert box? } - } + }, this) }); } @@ -118,12 +159,23 @@ .datagrid-row-selected,.datagrid-row-over{ background:transparent; } + .LocalIconApproval, .LocalIconApproved { + padding-right: 3px; + } + body.rtl .LocalIconApproval, body.rtl .LocalIconApproved { + padding-left: 3px; + padding-right: initial; + } + .rowPrevious { + color: #888; + display: none; + }

@@ -131,13 +183,24 @@ - + - +
+ +

+ +
+
+ +
+
+
diff --git a/Site5/Pages/v5/Financial/PayOutMoney.aspx.cs b/Site5/Pages/v5/Financial/PayOutMoney.aspx.cs index 20909f9d..2f7ace5d 100644 --- a/Site5/Pages/v5/Financial/PayOutMoney.aspx.cs +++ b/Site5/Pages/v5/Financial/PayOutMoney.aspx.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.ServiceModel.Security; using System.Web; using System.Web.Services; @@ -43,6 +44,16 @@ namespace Swarmops.Frontend.Pages.Financial this.LabelGridHeaderPaid.Text = Resources.Pages.Financial.PayOutMoney_GridHeader_PaidOut; this.LabelGridHeaderRecipient.Text = Resources.Pages.Financial.PayOutMoney_GridHeader_Recipient; this.LabelGridHeaderReference.Text = Resources.Pages.Financial.PayOutMoney_GridHeader_Reference; + + this.LabelSidebarOptions.Text = Resources.Global.Sidebar_Options; + + int previouslyOpenPayouts = GetOpenCount(); + this.LabelOptionsShowPrevious.Text = String.Format(Resources.Pages.Financial.PayOutMoney_OptionShowOpen, previouslyOpenPayouts); + } + + private int GetOpenCount() + { + return Payouts.ForOrganization (CurrentOrganization).Count; } [WebMethod] @@ -72,7 +83,7 @@ namespace Swarmops.Frontend.Pages.Financial result.DisplayMessage = String.Format (Resources.Pages.Financial.PayOutMoney_PayoutCreated, payout.Identity, payout.Recipient); - result.DisplayMessage = HttpUtility.UrlEncode (result.DisplayMessage).Replace ("+", "%20"); + result.DisplayMessage = result.DisplayMessage; return result; } @@ -81,8 +92,14 @@ namespace Swarmops.Frontend.Pages.Financial public static UndoPayoutResult UndoPayout (int databaseId) { AuthenticationData authData = GetAuthenticationDataAndCulture(); - UndoPayoutResult result = new UndoPayoutResult(); + if ( + !authData.CurrentUser.HasAccess(new Access(authData.CurrentOrganization, AccessAspect.Financials))) + { + throw new SecurityAccessDeniedException("Insufficient privileges for operation"); + } + + UndoPayoutResult result = new UndoPayoutResult(); Payout payout = Payout.FromIdentity (databaseId); if (!payout.Open) @@ -98,9 +115,7 @@ namespace Swarmops.Frontend.Pages.Financial payout.UndoPayout(); - result.DisplayMessage = - HttpUtility.UrlEncode (String.Format (Resources.Pages.Financial.PayOutMoney_PayoutUndone, databaseId)) - .Replace ("+", "%20"); + result.DisplayMessage = String.Format (Resources.Pages.Financial.PayOutMoney_PayoutUndone, databaseId); result.Success = true; return result; } diff --git a/Site5/Pages/v5/Ledgers/AccountPlan.aspx.cs b/Site5/Pages/v5/Ledgers/AccountPlan.aspx.cs index fea7fddf..f0035308 100644 --- a/Site5/Pages/v5/Ledgers/AccountPlan.aspx.cs +++ b/Site5/Pages/v5/Ledgers/AccountPlan.aspx.cs @@ -92,6 +92,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers FinancialAccounts organizationAccounts = FinancialAccounts.ForOrganization(this.CurrentOrganization); int inactiveCount = organizationAccounts.Count(account => !account.Active); + this.LabelSidebarOptions.Text = Resources.Global.Sidebar_Options; this.LabelOptionsShowInactive.Text = String.Format(Resources.Pages.Ledgers.AccountPlan_Options_ShowInactive, inactiveCount); } PageAccessRequired = new Access (CurrentOrganization, AccessAspect.Bookkeeping, AccessType.Write);