private static bool TryReadPostings(string line, out IPosting posting) { posting = null; line = line.Trim(); if (line.Length < 20) { return(false); } var dates = new List <DateTime>(); var datePositions = new List <int>(); for (var i = 0; i < line.Length - 10; i++) { var dateString = line.Substring(i, 10); if (!DateTime.TryParse(dateString, out var date)) { continue; } if (dateString != date.ToShortDateString()) { continue; } dates.Add(date); datePositions.Add(i); } if (dates.Count < 2) { return(false); } if (!double.TryParse(line[(datePositions[dates.Count - 1] + 10)..], out var amount))
private IPosting IncreasePostingAmount(IPosting posting) { return(new Posting { Date = posting.Date, Amount = posting.Amount * 24, Remark = posting.Remark }); }
private static bool DoesPostingMatchYearAndMonth(IPosting posting, IPostingClassification classification) { if (classification.Month == 0 && classification.Year == 0) { return(true); } return(classification.Month == posting.Date.Month && classification.Year == posting.Date.Year); }
public void RegisterContribution(string classification, double amount, IPosting posting) { if (!ContributionsPerClassification.ContainsKey(classification)) { ContributionsPerClassification[classification] = new List <ClassificationContribution>(); } ContributionsPerClassification[classification].Add(new ClassificationContribution { Amount = amount, Posting = posting }); }
private bool IsPostingRelevantHere(IPosting posting, IEnumerable <IPostingClassification> postingClassifications, DateTime minDate, double minAmount, out IPostingClassification classification) { classification = null; if (Math.Abs(posting.Amount) < minAmount) { return(false); } if (posting.Date < minDate) { return(false); } var classifications = postingClassifications.Where(c => PostingClassificationMatcher.DoesPostingMatchClassification(posting, c)).ToList(); if (classifications.Count != 1) { return(false); } classification = classifications[0]; return(true); }
public Posting(IPosting <T> postingPosition) { this._postingPosition = postingPosition; }
public bool DoesPostingMatchClassification(IPosting posting, IPostingClassification classification) { return(DoesPostingMatchDebitCredit(posting, classification) && DoesPostingMatchClue(posting, classification) && DoesPostingMatchYearAndMonth(posting, classification)); }
private static bool DoesPostingMatchClue(IPosting posting, IPostingClassification classification) { return(string.IsNullOrEmpty(classification.Clue) || posting.Remark.Contains(classification.Clue, StringComparison.OrdinalIgnoreCase)); }
private static bool DoesPostingMatchDebitCredit(IPosting posting, IPostingClassification classification) { return(classification.IsMonthClassification || classification.Credit == posting.Amount > 0 || !classification.Credit == posting.Amount < 0); }