Work on Payment Targets

This commit is contained in:
Rick Falkvinge
2019-02-24 11:53:33 +01:00
parent daaabfde08
commit 5a78b067ed
4 changed files with 122 additions and 3 deletions
+17 -2
View File
@@ -22,6 +22,7 @@ namespace Swarmops.Logic.Financial
/// The Country field is needed whenever a transfer is marked as "domestic"
/// </summary>
public Country Country { get; set; }
public string Recipient { get; set; }
public string CurrencyAmount { get; set; }
public PaymentTargetType TargetType { get; set; }
public string LocalizedPaymentMethodName { get; set; }
@@ -33,14 +34,28 @@ namespace Swarmops.Logic.Financial
{
ExpenseClaim claim = financialObject as ExpenseClaim;
return FromObject(claim.Claimer, new Money(claim.AmountCents, claim.Organization.Currency));
if (amountToPay == null)
{
return FromObject(claim.Claimer, new Money(claim.AmountCents, claim.Organization.Currency));
}
else
{
return FromObject(claim.Claimer, amountToPay);
}
}
if (financialObject is CashAdvance)
{
CashAdvance advance = financialObject as CashAdvance;
return FromObject(advance.Person, new Money(advance.AmountCents, advance.Organization.Currency));
if (amountToPay == null)
{
return FromObject(advance.Person, new Money(advance.AmountCents, advance.Organization.Currency));
}
else
{
return FromObject(advance.Person, amountToPay);
}
}
if (financialObject is Salary)
+2
View File
@@ -340,6 +340,7 @@
<input type="text" id="idModalTransferMethod" readonly="readonly" value="Transfer Method"/>&#8203;<br/>
<input type="text" id="idModalClearing" readonly="readonly" value="Clearing"/>&#8203;<br/>
<input type="text" id="idModalAccountNumber" readonly="readonly" value="Account Number"/>&#8203;<br/>
<Swarmops5:AjaxToggleSlider ID="MasterEditPerson2FAProvisioning" runat="server" Label="Show in machine-readable format XYZ" Cookie="2FAProvision" AjaxCallbackUrl="" OnChange="masterPersonEditor2FAProvisionToggle"/>
<input type="button" id="idModalButtonConfirm" value="Confirm XYZ" class="button-accent-color suppress-input-focus action-icon-button icon-yes" onclick="onConfirmModal();"/>
</div>
<div class="data-entry-labels">
@@ -349,6 +350,7 @@
<asp:Label ID="LabelModalTransferMethod" runat="server" Text="Transfer Method XYZ"/><br/>
Clearing<br/>
Account Number<br/>
Are you scanning this payment XYZ?
&nbsp;
</div>
Foobar high chaparral
+94 -1
View File
@@ -3,6 +3,7 @@ using System.Linq;
using System.Security;
using System.Web;
using System.Web.Services;
using System.Web.UI;
using Swarmops.Common.Enums;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Security;
@@ -114,12 +115,104 @@ namespace Swarmops.Frontend.Pages.Financial
};
}
[WebMethod]
public static PaymentTransferInfoResult GetPayoutTransferInfo(string prototypeId)
{
AuthenticationData authData = GetAuthenticationDataAndCulture();
// TODO: Authentication check
string[] payoutComponents = prototypeId.Split('|');
if (payoutComponents.Length < 1)
{
throw new InvalidOperationException("Prototype ID can't be empty");
}
PaymentTransferInfo info = new PaymentTransferInfo();
// Some payouts are composites of multiple objects, but all these will share the same
// payout data, so we can safely use just the first object to determine payment
// target information
//
// with one exception -- we need to determine the amount by adding all the objects
// together, if applicable
switch (Char.ToUpperInvariant(payoutComponents[0][0]))
{
case 'E': // expense claim
info =
PaymentTransferInfo.FromObject(
ExpenseClaim.FromIdentity(Int32.Parse(payoutComponents[0].Substring(1))),
new Money(GetSumCentsTotal(prototypeId), authData.CurrentOrganization.Currency));
break;
case 'A': // cash advance (payout or payback, same logic either way)
info =
PaymentTransferInfo.FromObject(
CashAdvance.FromIdentity(Int32.Parse(payoutComponents[0].Substring(1))),
new Money(GetSumCentsTotal(prototypeId), authData.CurrentOrganization.Currency));
break;
case 'S': // salary
info =
PaymentTransferInfo.FromObject(
Salary.FromIdentity(Int32.Parse(payoutComponents[0].Substring(1))));
break;
case 'I': // inbound invoice
info =
PaymentTransferInfo.FromObject(
InboundInvoice.FromIdentity(Int32.Parse(payoutComponents[0].Substring(1))));
break;
default:
throw new NotImplementedException("Unrecognized payment type");
}
PaymentTransferInfoResult result = new PaymentTransferInfoResult
{
Success = true,
CurrencyAmount = info.CurrencyAmount,
DisplayMessage = string.Empty,
Recipient = info.Recipient,
Reference = info.Reference,
TransferMethod = info.LocalizedPaymentMethodName,
};
// TODO: Continue with adding localized fields
}
static private Int64 GetSumCentsTotal(string prototypeId)
{
string[] payoutComponents = prototypeId.Split('|');
Int64 amountCentsTotal = 0;
foreach (string payoutComponent in payoutComponents)
{
switch (payoutComponent[0])
{
case 'E':
amountCentsTotal += ExpenseClaim.FromIdentity(Int32.Parse(payoutComponent.Substring(1))).AmountCents;
break;
case 'A': // Advance pay-OUT
amountCentsTotal += CashAdvance.FromIdentity(Int32.Parse(payoutComponent.Substring(1))).AmountCents;
break;
case 'a': // Advance pay-BACK
amountCentsTotal -= CashAdvance.FromIdentity(Int32.Parse(payoutComponent.Substring(1))).AmountCents;
break;
default:
throw new NotImplementedException();
}
}
return amountCentsTotal;
}
public class ConfirmPayoutResult: AjaxCallResult
{
public int AssignedId;
};
public class PayoutInformationResult : AjaxCallResult
public class PaymentTransferInfoResult : AjaxCallResult
{
public string Recipient { get; set; }
public string CurrencyAmount { get; set; }
+9
View File
@@ -138,6 +138,15 @@ namespace Swarmops.Frontend.Pages.Financial {
/// </remarks>
protected global::System.Web.UI.WebControls.Label LabelPayoutModalHeader;
/// <summary>
/// MasterEditPerson2FAProvisioning control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::Swarmops.Frontend.Controls.Base.AjaxToggleSlider MasterEditPerson2FAProvisioning;
/// <summary>
/// LabelModalRecipient control.
/// </summary>