From 89c830a1eb0686115f7084a9de123f7189631c3b Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Tue, 29 Jan 2019 14:57:00 +0100 Subject: [PATCH] Work on Payment History --- Logic/Financial/Payout.cs | 14 ++++++- Logic/Financial/Salaries.cs | 6 +++ Logic/Financial/Salary.cs | 2 +- .../Pages.Ledgers.designer.cs | 4 +- Site/App_GlobalResources/Pages.Ledgers.resx | 4 +- ...son-MasterPersonEditPaymentHistory.aspx.cs | 38 +++++++++++++++++++ Site/Master-v5.master | 6 +-- 7 files changed, 64 insertions(+), 10 deletions(-) diff --git a/Logic/Financial/Payout.cs b/Logic/Financial/Payout.cs index 15a53ba0..d9271c20 100644 --- a/Logic/Financial/Payout.cs +++ b/Logic/Financial/Payout.cs @@ -44,9 +44,19 @@ namespace Swarmops.Logic.Financial // return payout; } - public static Payout FromDependency(IHasIdentity dependency) + public static Payout FromDependency(IHasIdentity dependency, FinancialDependencyType dependencyType = FinancialDependencyType.Unknown) { - int payoutId = SwarmDb.GetDatabaseForReading().GetPayoutIdFromDependency(dependency); + int payoutId = 0; + + if (dependencyType == FinancialDependencyType.Unknown) + { + payoutId = SwarmDb.GetDatabaseForReading().GetPayoutIdFromDependency(dependency); + } + else + { + payoutId = SwarmDb.GetDatabaseForReading().GetPayoutIdFromDependency(dependency, dependencyType); + } + if (payoutId == 0) { throw new ArgumentException("Supplied item does not have an associated payout"); diff --git a/Logic/Financial/Salaries.cs b/Logic/Financial/Salaries.cs index 7b7a7431..43d04b6c 100644 --- a/Logic/Financial/Salaries.cs +++ b/Logic/Financial/Salaries.cs @@ -70,6 +70,12 @@ namespace Swarmops.Logic.Financial includeClosed ? DatabaseCondition.None : DatabaseCondition.OpenTrue)); } + public static Salaries ForPersonAndOrganization(Person person, Organization organization, bool includeClosed) + { + return FromArray(SwarmDb.GetDatabaseForReading().GetSalaries(person, organization, + includeClosed ? DatabaseCondition.None : DatabaseCondition.OpenTrue)); + } + public static void CreateAnnualStatements (int year) { // This function is supposed to be running once a year, and summarize the past year of salaries. diff --git a/Logic/Financial/Salary.cs b/Logic/Financial/Salary.cs index 05d0a84c..a10433bf 100644 --- a/Logic/Financial/Salary.cs +++ b/Logic/Financial/Salary.cs @@ -303,7 +303,7 @@ namespace Swarmops.Logic.Financial // Add the financial transaction FinancialTransaction transaction = - FinancialTransaction.Create (payrollItem.OrganizationId, DateTime.Now, + FinancialTransaction.Create (payrollItem.OrganizationId, DateTime.UtcNow, "Salary #" + salary.Identity + ": " + payrollItem.PersonCanonical + " " + salary.PayoutDate.ToString ("yyyy-MMM", CultureInfo.InvariantCulture)); diff --git a/Site/App_GlobalResources/Pages.Ledgers.designer.cs b/Site/App_GlobalResources/Pages.Ledgers.designer.cs index 022d8b98..b04c1900 100644 --- a/Site/App_GlobalResources/Pages.Ledgers.designer.cs +++ b/Site/App_GlobalResources/Pages.Ledgers.designer.cs @@ -592,7 +592,7 @@ namespace Resources.Pages { } /// - /// Looks up a localized string similar to Dangling Payments (Must Balance, Match Or Fix). + /// Looks up a localized string similar to Dangling Payments (Must Balance, Match, or Fix). /// internal static string BalanceTransactions_HeaderUnbalancedTransactions { get { @@ -601,7 +601,7 @@ namespace Resources.Pages { } /// - /// Looks up a localized string similar to Some auto-imported financial transactions can't be automatically matched to the ongoing accounting. This is where you manually match such transactions to "balance" them (if a transaction only has one part completed, like the money sent to the organization with no record of what the money is for, the transaction is said to be "unbalanced").. + /// Looks up a localized string similar to Some auto-imported financial transactions can't be automatically matched to the ongoing accounting. This is where you manually match such transactions to "balance" them (if a transaction only has one part completed, like the money sent to the organization with no record of what the money is for, the transaction is said to be "unbalanced" and a "dangling payment", as in, missing its bookkeeping counterpart).. /// internal static string BalanceTransactions_Info { get { diff --git a/Site/App_GlobalResources/Pages.Ledgers.resx b/Site/App_GlobalResources/Pages.Ledgers.resx index 0bac1532..a660e67a 100644 --- a/Site/App_GlobalResources/Pages.Ledgers.resx +++ b/Site/App_GlobalResources/Pages.Ledgers.resx @@ -638,7 +638,7 @@ (detailed description withheld) - Dangling Payments (Must Balance, Match Or Fix) + Dangling Payments (Must Balance, Match, or Fix) A "dangling payment" is a transaction that's not yet completed to have equal parts debit and credit. Typically, it's a payment that hasn't been identified. @@ -656,7 +656,7 @@ Keep VERY short. - Some auto-imported financial transactions can't be automatically matched to the ongoing accounting. This is where you manually match such transactions to "balance" them (if a transaction only has one part completed, like the money sent to the organization with no record of what the money is for, the transaction is said to be "unbalanced"). + Some auto-imported financial transactions can't be automatically matched to the ongoing accounting. This is where you manually match such transactions to "balance" them (if a transaction only has one part completed, like the money sent to the organization with no record of what the money is for, the transaction is said to be "unbalanced" and a "dangling payment", as in, missing its bookkeeping counterpart). Balancing/Matching Transaction #<span id="spanModalTransactionId">67890</span> From <span id="spanModalTransactionDate">yyyy-mmm-dd</span> diff --git a/Site/Automation/Json-MasterPersonEditPaymentHistory.aspx.cs b/Site/Automation/Json-MasterPersonEditPaymentHistory.aspx.cs index 0a29af72..a7599619 100644 --- a/Site/Automation/Json-MasterPersonEditPaymentHistory.aspx.cs +++ b/Site/Automation/Json-MasterPersonEditPaymentHistory.aspx.cs @@ -7,6 +7,7 @@ using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using Swarmops.Common; +using Swarmops.Common.Enums; using Swarmops.Logic.Financial; using Swarmops.Logic.Swarm; @@ -28,6 +29,13 @@ namespace Swarmops.Frontend.Automation } this._person = Person.FromIdentity(personId); + if (this._person.Identity != _authenticationData.CurrentUser.Identity) + { + if (!_authenticationData.Authority.CanSeePerson(_person)) + { + throw new UnauthorizedAccessException(); + } + } List list = new List(); @@ -74,6 +82,36 @@ namespace Swarmops.Frontend.Automation } } + // Salaries + + Salaries salaries = Salaries.ForPersonAndOrganization(_person, _authenticationData.CurrentOrganization, true); + + foreach (Salary salary in salaries) + { + if (salary.Open || salary.NetPaid) // either of these must be open for the salary to be valid + { + PaymentHistoryLineItem newItem = new PaymentHistoryLineItem(); + newItem.Id = "S" + salary.Identity.ToString(CultureInfo.InvariantCulture); + newItem.Name = Resources.Global.Financial_Salary + " #" + salary.Identity.ToString("N0"); + newItem.Description = "Salary for something XYZ"; + newItem.OwedToPerson = salary.NetSalaryCents; + + FinancialTransaction openTx = FinancialTransaction.FromDependency(salary); + if (openTx != null) + { + newItem.OpenedDate = openTx.DateTime; + } + + Payout payout = Payout.FromDependency(salary, FinancialDependencyType.Salary); + if (payout != null && payout.Open == false) + { + newItem.ClosedDate = payout.FinancialTransaction.DateTime; + } + + items.Add(newItem); + } + } + return items; } diff --git a/Site/Master-v5.master b/Site/Master-v5.master index da723a64..1960a152 100644 --- a/Site/Master-v5.master +++ b/Site/Master-v5.master @@ -385,11 +385,11 @@ - - + + - +