EOM work 4

This commit is contained in:
Rick Falkvinge
2018-12-31 21:07:18 +01:00
parent 167938d2a7
commit 177a9d5125
2 changed files with 36 additions and 1 deletions
+8 -1
View File
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Runtime.CompilerServices;
using Swarmops.Basic.Types.Financial;
using Swarmops.Common;
@@ -171,7 +172,13 @@ namespace Swarmops.Logic.Financial
public FinancialAccountDocument GetMostRecentDocument(FinancialAccountDocumentType documentType)
{
// TODO: Continue here
FinancialAccountDocuments documents = FinancialAccountDocuments.ForAccount(this, documentType);
if (documents.Count() > 0)
{
return documents.Last();
}
return null;
}
@@ -4,11 +4,39 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Swarmops.Basic.Types.Financial;
using Swarmops.Common.Enums;
using Swarmops.Database;
using Swarmops.Logic.Support;
namespace Swarmops.Logic.Financial
{
public class FinancialAccountDocuments: PluralBase<FinancialAccountDocuments,FinancialAccountDocument,BasicFinancialAccountDocument>
{
public static FinancialAccountDocuments ForAccount(FinancialAccount account, FinancialAccountDocumentType typeRequested = FinancialAccountDocumentType.Unknown)
{
FinancialAccountDocuments result = FromArray(SwarmDb.GetDatabaseForReading().GetFinancialAccountDocuments(account));
result.Sort(new FinancialAccountDocumentsSorterByTypeThenDate());
if (typeRequested != FinancialAccountDocumentType.Unknown)
{
return (FinancialAccountDocuments) result.Where(doc => doc.Type == typeRequested);
}
return result;
}
}
internal class FinancialAccountDocumentsSorterByTypeThenDate : IComparer<FinancialAccountDocument>
{
public int Compare(FinancialAccountDocument a, FinancialAccountDocument b)
{
if (a.Type != b.Type)
{
return a.Type.CompareTo(b.Type);
}
return (a.ConcernsPeriodStart.CompareTo(b.ConcernsPeriodStart));
}
}
}