Skip to content

Commit

Permalink
Fixed #5 it better, but not perfect yet
Browse files Browse the repository at this point in the history
  • Loading branch information
Laumania committed Jun 21, 2016
1 parent 243d64a commit 6fe4779
Showing 1 changed file with 19 additions and 12 deletions.
Expand Up @@ -55,7 +55,7 @@ private IEnumerable<DifferenceEntryModel> GetDifferenceEntryModels(IEnumerable<E

foreach (var dineroEntry in dineroEntries)
{
var foundBankEntry = bankEntries.FirstOrDefault(x => x.Amount == dineroEntry.Amount && processedEntryModels.Contains(x) == false);
var foundBankEntry = FindBankEntryWithNearestDate(bankEntries.Except(processedEntryModels), dineroEntry);
var diffEntryModel = new DifferenceEntryModel()
{
DineroEntry = dineroEntry
Expand Down Expand Up @@ -92,18 +92,25 @@ private IEnumerable<DifferenceEntryModel> GetDifferenceEntryModels(IEnumerable<E
return result;
}

//private bool IsSelfCancelling(EntryModel dineroEntry, IEnumerable<EntryModel> dineroEntries)
//{
// var counterAmount = dineroEntry.Amount*-1;
// var foundEntryWithCounterAmount = dineroEntries.FirstOrDefault(x => x.State == EntryModelStates.Unprocessed && x.Amount == counterAmount);
private EntryModel FindBankEntryWithNearestDate(IEnumerable<EntryModel> bankEntries, EntryModel dineroEntryToMatch)
{
var foundEntries = bankEntries.Where(x => x.Amount == dineroEntryToMatch.Amount);
EntryModel nearestEntryFound = null;
double smallestTimeDifferenceInMinutes = double.MaxValue;

foreach (var foundEntry in foundEntries)
{
var differenceInMinutes = Math.Abs((dineroEntryToMatch.Date - foundEntry.Date).TotalMinutes);

if (differenceInMinutes < smallestTimeDifferenceInMinutes)
{
smallestTimeDifferenceInMinutes = differenceInMinutes;
nearestEntryFound = foundEntry;
}

// if (foundEntryWithCounterAmount != null)
// {
// //foundEntryWithCounterAmount.State = EntryModelStates.Processed;
// return true;
// }
}

// return false;
//}
return nearestEntryFound;
}
}
}

0 comments on commit 6fe4779

Please sign in to comment.