Work on Payouts

This commit is contained in:
Rick Falkvinge
2019-02-12 10:23:14 +01:00
parent f9d26453a0
commit ba2b7f1fe5
12 changed files with 137 additions and 102 deletions
+3 -3
View File
@@ -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);
@@ -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;
@@ -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;
@@ -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; }
@@ -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;
@@ -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;
@@ -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;
@@ -69,11 +69,12 @@ namespace Swarmops.Frontend.Pages.Financial
"\"reference\":\"{5}\"," +
"\"amount\":\"{6}\"," +
"\"action\":\"" +
"<img id=\\\"IconApproval{7}\\\" class=\\\"IconApproval{7} LocalIconApproval LocalPrototype\\\" baseid=\\\"{0}\\\" height=\\\"18\\\" width=\\\"24\\\" />" +
"<img class=\\\"IconApproved{7} LocalIconApproved LocalPrototype\\\" baseid=\\\"{0}\\\" height=\\\"18\\\" width=\\\"24\\\" />" +
"<img class=\\\"IconDenial{7} LocalIconDenial LocalPrototype\\\" baseid=\\\"{0}\\\" height=\\\"18\\\" width=\\\"24\\\" />" +
"<img class=\\\"IconDenied{7} LocalIconDenied LocalPrototype\\\" baseid=\\\"{0}\\\" height=\\\"18\\\" width=\\\"24\\\" />" +
"<img class=\\\"IconUndo{7} LocalIconUndo LocalPrototype\\\" baseid=\\\"{0}\\\" height=\\\"18\\\" width=\\\"24\\\" />" +
"<img id='IconApproval{7}' class='IconApproval{7} LocalIconApproval LocalPrototype action-icon' baseid='{7}' protoid='{0}' />" +
"<img class='IconApproved{7} LocalIconApproved LocalPrototype status-icon' baseid='{7}' />" +
"<img class='IconWait{7} LocalIconWait LocalPrototype status-icon' baseid='{7}' />" +
"<img class='IconUndo{7} LocalIconUndo LocalPrototype action-icon' baseid='{7}' />" +
"<img class='IconDenial{7} LocalIconDenial LocalPrototype action-icon' baseid='{7}' />" +
"<img class='IconDenied{7} LocalIconDenied LocalPrototype status-icon' baseid='{7}' />" +
"\"",
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\":\"" +
"<img id=\\\"IconApproval{7}\\\" class=\\\"IconApproval{7} LocalIconApproval LocalPrevious\\\" databaseid=\\\"{8}\\\" baseid=\\\"{0}\\\" height=\\\"18\\\" width=\\\"24\\\" />" +
"<img class=\\\"IconApproved{7} LocalIconApproved LocalPrevious\\\" baseid=\\\"{0}\\\" height=\\\"18\\\" width=\\\"24\\\" />" +
"<img class=\\\"IconDenial{7} LocalIconDenial LocalPrevious\\\" baseid=\\\"{0}\\\" height=\\\"18\\\" width=\\\"24\\\" />" +
"<img class=\\\"IconDenied{7} LocalIconDenied LocalPrevious\\\" baseid=\\\"{0}\\\" height=\\\"18\\\" width=\\\"24\\\" />" +
"<img class=\\\"IconUndo{7} LocalIconUndo LocalPrevious\\\" baseid=\\\"{0}\\\" height=\\\"18\\\" width=\\\"24\\\" />" +
"<img id='IconApproval{7}' class='IconApproval{7} LocalIconApproval LocalPaid action-icon' baseid='{7}' protoid='{0}' databaseid='{8}' />" +
"<img class='IconApproved{7} LocalIconApproved LocalPaid status-icon' baseid='{0}' />" +
"<img class='IconWait{7} LocalIconWait LocalPaid status-icon' baseid='{0}' />" +
"<img class='IconUndo{7} LocalIconUndo LocalPaid action-icon' baseid='{0}' />" +
"<img class='IconDenial{7} LocalIconDenial LocalPaid action-icon' baseid='{0}' />" +
"<img class='IconDenied{7} LocalIconDenied LocalPaid status-icon' baseid='{0}' />" +
"\"",
payout.ProtoIdentity,
payout.ExpectedTransactionDate.ToShortDateString(),
@@ -81,11 +81,12 @@ namespace Swarmops.Frontend.Pages.Financial
"\"amount\":\"<span class='ocrFont'>{3}</span>\"," +
"\"account\":\"<span class='ocrFont'>{4}</span>\"," +
"\"action\":\"" +
"<img class=\\\"IconApproval{5} LocalIconApproval LocalPrototype\\\" baseid=\\\"{0}\\\" height=\\\"18\\\" width=\\\"24\\\" />" +
"<img class=\\\"IconApproved{5} LocalIconApproved LocalPrototype\\\" baseid=\\\"{0}\\\" height=\\\"18\\\" width=\\\"24\\\" />" +
"<img class=\\\"IconDenial{5} LocalIconDenial LocalPrototype\\\" baseid=\\\"{0}\\\" height=\\\"18\\\" width=\\\"24\\\" />" +
"<img class=\\\"IconDenied{5} LocalIconDenied LocalPrototype\\\" baseid=\\\"{0}\\\" height=\\\"18\\\" width=\\\"24\\\" />" +
"<img class=\\\"IconUndo{5} LocalIconUndo LocalPrototype\\\" baseid=\\\"{0}\\\" height=\\\"18\\\" width=\\\"24\\\" />" +
"<img class='IconApproval{5} LocalIconApproval LocalPrototype action-icon' baseid='{0}' />" +
"<img class='IconApproved{5} LocalIconApproved LocalPrototype status-icon' baseid='{0}' />" +
"<img class='IconWait{5} LocalIconWait status-icon' baseid='{0}' />" +
"<img class='IconUndo{5} LocalIconUndo LocalPrototype action-icon' baseid='{0}' />" +
"<img class='IconDenial{5} LocalIconDenial LocalPrototype action-icon' baseid='{0}' />" +
"<img class='IconDenied{5} LocalIconDenied LocalPrototype status-icon' baseid='{0}' />" +
"\"" ,
payout.ProtoIdentity,
(payout.ExpectedTransactionDate <= today
+73 -38
View File
@@ -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 @@
});
}
});
});*/
}
}
+26 -35
View File
@@ -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;
}
}
}
+1 -1
View File
@@ -1,4 +1,4 @@
NOV2018
FEB2019
=======
OVERALL: