示例#1
0
        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
     });
 }
示例#3
0
        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);
        }
示例#4
0
        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
            });
        }
示例#5
0
        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);
        }
示例#6
0
文件: Posting.cs 项目: FrankMi101/LTO
 public Posting(IPosting <T> postingPosition)
 {
     this._postingPosition = postingPosition;
 }
示例#7
0
 public bool DoesPostingMatchClassification(IPosting posting, IPostingClassification classification)
 {
     return(DoesPostingMatchDebitCredit(posting, classification) && DoesPostingMatchClue(posting, classification) && DoesPostingMatchYearAndMonth(posting, classification));
 }
示例#8
0
 private static bool DoesPostingMatchClue(IPosting posting, IPostingClassification classification)
 {
     return(string.IsNullOrEmpty(classification.Clue) || posting.Remark.Contains(classification.Clue, StringComparison.OrdinalIgnoreCase));
 }
示例#9
0
 private static bool DoesPostingMatchDebitCredit(IPosting posting, IPostingClassification classification)
 {
     return(classification.IsMonthClassification || classification.Credit == posting.Amount > 0 || !classification.Credit == posting.Amount < 0);
 }