From daaabfde08177de4bc0aff89de8ab25b0b00bbe9 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sat, 23 Feb 2019 18:30:51 +0100 Subject: [PATCH] More work on Payment Targets --- Logic/Financial/PaymentTransferInfo.cs | 98 +++++++++++++++++++ Logic/Financial/PaymentTransferMethodInfo.cs | 50 ---------- Logic/Logic.csproj | 10 +- ...Financial.PaymentTransferInfo.Designer.cs} | 6 +- ... Logic.Financial.PaymentTransferInfo.resx} | 0 Logic/Resources/SourceResourceFiles.txt | 2 +- 6 files changed, 107 insertions(+), 59 deletions(-) create mode 100644 Logic/Financial/PaymentTransferInfo.cs delete mode 100644 Logic/Financial/PaymentTransferMethodInfo.cs rename Logic/Resources/{Logic.Financial.PaymentTransferMethodInfo.Designer.cs => Logic.Financial.PaymentTransferInfo.Designer.cs} (97%) rename Logic/Resources/{Logic.Financial.PaymentTransferMethodInfo.resx => Logic.Financial.PaymentTransferInfo.resx} (100%) diff --git a/Logic/Financial/PaymentTransferInfo.cs b/Logic/Financial/PaymentTransferInfo.cs new file mode 100644 index 00000000..21256d28 --- /dev/null +++ b/Logic/Financial/PaymentTransferInfo.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Resources; +using System.Text; +using System.Threading.Tasks; +using Swarmops.Common.Enums; +using Swarmops.Common.Interfaces; +using Swarmops.Logic.Swarm; +using Swarmops.Logic.Structure; +using Swarmops.Logic.Resources; + +namespace Swarmops.Logic.Financial +{ + public class PaymentTransferInfo + { + /// + /// This is the currency to be used for the transfer. Note that the amount will be converted into this currency! + /// + public Currency Currency { get; set; } + /// + /// The Country field is needed whenever a transfer is marked as "domestic" + /// + public Country Country { get; set; } + public string CurrencyAmount { get; set; } + public PaymentTargetType TargetType { get; set; } + public string LocalizedPaymentMethodName { get; set; } + public Dictionary LocalizedPaymentInformation { get; set; } + + public static PaymentTransferInfo FromObject(IHasIdentity financialObject, Money amountToPay = null) + { + if (financialObject is ExpenseClaim) + { + ExpenseClaim claim = financialObject as ExpenseClaim; + + return FromObject(claim.Claimer, new Money(claim.AmountCents, claim.Organization.Currency)); + } + + if (financialObject is CashAdvance) + { + CashAdvance advance = financialObject as CashAdvance; + + return FromObject(advance.Person, new Money(advance.AmountCents, advance.Organization.Currency)); + } + + if (financialObject is Salary) + { + Salary salary = financialObject as Salary; + return FromObject(salary.PayrollItem.Person, new Money(salary.NetSalaryCents, salary.PayrollItem.Organization.Currency)); + } + + if (financialObject is Person) + { + Person person = financialObject as Person; + + // For now, assume the bank/clearing/account triplet + // TODO: Implement payment targets on teh Person object + + PaymentTransferInfo result = new PaymentTransferInfo(); + result.TargetType = PaymentTargetType.DomesticBankTransfer; + + // We must know the amount at this point + + if (amountToPay == null) + { + throw new ArgumentNullException("amountToPay", @"Cannot determine payment transfer information without knowing origin currency"); + } + + if (string.IsNullOrEmpty(person.BankName) || string.IsNullOrEmpty(person.BankClearing) || + string.IsNullOrEmpty(person.BankAccount)) + { + throw new NotImplementedException("Cannot provide payment transfer information for Person #" + person.Identity.ToString()); + } + + result.TargetType = PaymentTargetType.DomesticBankTransfer; + result.Country = person.Country; + result.Currency = amountToPay.Currency; // TODO: The currency will need to come from the payment method instead + + result.CurrencyAmount = result.Currency.Code + " " + (amountToPay.ToCurrency(result.Currency).Cents / 100.0).ToString("N2"); + + result.LocalizedPaymentMethodName = + Logic_Financial_PaymentTransferInfo.ResourceManager.GetString("PaymentTargetType_" + + result.TargetType.ToString()); + + result.LocalizedPaymentInformation = new Dictionary(); + result.LocalizedPaymentInformation[ + Logic_Financial_PaymentTransferInfo.PaymentTargetField_ClearingCode] = + person.BankName + " " + person.BankClearing; + result.LocalizedPaymentInformation[ + Logic_Financial_PaymentTransferInfo.PaymentTargetField_AccountNumber] = person.BankAccount; + + return result; + } + + throw new NotImplementedException("Unknown payment information"); + } + } +} diff --git a/Logic/Financial/PaymentTransferMethodInfo.cs b/Logic/Financial/PaymentTransferMethodInfo.cs deleted file mode 100644 index 3f81c5de..00000000 --- a/Logic/Financial/PaymentTransferMethodInfo.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Resources; -using System.Text; -using System.Threading.Tasks; -using Swarmops.Common.Enums; -using Swarmops.Common.Interfaces; -using Swarmops.Logic.Swarm; - -namespace Swarmops.Logic.Financial -{ - public class PaymentTransferMethodInfo - { - public Currency Currency { get; set; } - public PaymentTargetType TargetType { get; set; } - public string LocalizedPaymentMethodName { get; set; } - Dictionary LocalizedPaymentInformation { get; set; } - - public static PaymentTransferMethodInfo FromObject(IHasIdentity financialObject) - { - if (financialObject is ExpenseClaim) - { - return FromObject((financialObject as ExpenseClaim).Claimer); - } - - if (financialObject is CashAdvance) - { - return FromObject((financialObject as CashAdvance).Person); - } - - if (financialObject is Salary) - { - return FromObject((financialObject as Salary).PayrollItem.Person); - } - - if (financialObject is Person) - { - Person person = financialObject as Person; - - // For now, assume the bank - clearing - account triplet - // TODO: Implement payment targets on teh Person object - - PaymentTransferMethodInfo result = new PaymentTransferMethodInfo(); - result.TargetType = PaymentTargetType.DomesticBankTransfer; - } - } - - } -} diff --git a/Logic/Logic.csproj b/Logic/Logic.csproj index f6c8ac52..d639f790 100644 --- a/Logic/Logic.csproj +++ b/Logic/Logic.csproj @@ -143,7 +143,7 @@ - + @@ -163,10 +163,10 @@ True Logic.Financial.FinancialTransactionTagSetTypesStock.resx - + True True - Logic.Financial.PaymentTransferMethodInfo.resx + Logic.Financial.PaymentTransferInfo.resx True @@ -699,9 +699,9 @@ - + ResXFileCodeGenerator - Logic.Financial.PaymentTransferMethodInfo.Designer.cs + Logic.Financial.PaymentTransferInfo.Designer.cs diff --git a/Logic/Resources/Logic.Financial.PaymentTransferMethodInfo.Designer.cs b/Logic/Resources/Logic.Financial.PaymentTransferInfo.Designer.cs similarity index 97% rename from Logic/Resources/Logic.Financial.PaymentTransferMethodInfo.Designer.cs rename to Logic/Resources/Logic.Financial.PaymentTransferInfo.Designer.cs index 7cbeec51..2015dd01 100644 --- a/Logic/Resources/Logic.Financial.PaymentTransferMethodInfo.Designer.cs +++ b/Logic/Resources/Logic.Financial.PaymentTransferInfo.Designer.cs @@ -22,14 +22,14 @@ namespace Swarmops.Logic.Resources { [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - internal class Logic_Financial_PaymentTransferMethodInfo { + internal class Logic_Financial_PaymentTransferInfo { private static global::System.Resources.ResourceManager resourceMan; private static global::System.Globalization.CultureInfo resourceCulture; [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] - internal Logic_Financial_PaymentTransferMethodInfo() { + internal Logic_Financial_PaymentTransferInfo() { } /// @@ -39,7 +39,7 @@ namespace Swarmops.Logic.Resources { internal static global::System.Resources.ResourceManager ResourceManager { get { if (object.ReferenceEquals(resourceMan, null)) { - global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Swarmops.Logic.Resources.Logic.Financial.PaymentTransferMethodInfo", typeof(Logic_Financial_PaymentTransferMethodInfo).Assembly); + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Swarmops.Logic.Resources.Logic.Financial.PaymentTransferInfo", typeof(Logic_Financial_PaymentTransferInfo).Assembly); resourceMan = temp; } return resourceMan; diff --git a/Logic/Resources/Logic.Financial.PaymentTransferMethodInfo.resx b/Logic/Resources/Logic.Financial.PaymentTransferInfo.resx similarity index 100% rename from Logic/Resources/Logic.Financial.PaymentTransferMethodInfo.resx rename to Logic/Resources/Logic.Financial.PaymentTransferInfo.resx diff --git a/Logic/Resources/SourceResourceFiles.txt b/Logic/Resources/SourceResourceFiles.txt index 057b69bf..007d263e 100644 --- a/Logic/Resources/SourceResourceFiles.txt +++ b/Logic/Resources/SourceResourceFiles.txt @@ -4,7 +4,7 @@ Logic.Communications.Transmission.NotificationPayload.resx Logic.Financial.FinancialAccount.resx Logic.Financial.FinancialTransactionTagSetTypesStock.resx Logic.Financial.Payout.resx -Logic.Financial.PaymentTransferMethodInfo.resx +Logic.Financial.PaymentTransferInfo.resx Logic.Financial.VatReport.resx Logic.Structure.Country.resx Logic.Structure.Geography.resx