public override UnifiedAccountOperation Map(SodexoOperation operation, CultureInfo culture)
        {
            var rawAmount = operation.Amount.Replace(" ", string.Empty);

            var amount = decimal.Parse(
                rawAmount,
                NumberStyles.AllowLeadingSign | NumberStyles.AllowThousands | NumberStyles.AllowDecimalPoint | NumberStyles.AllowCurrencySymbol,
                culture);

            decimal income = 0, outcome = 0;

            if (amount < 0)
            {
                outcome = -amount;
            }
            else
            {
                income = amount;
            }

            var trx = new UnifiedAccountOperation
            {
                ValueDate     = operation.Date,
                ExecutionDate = operation.Date,
                Income        = income,
                Outcome       = outcome,
                Currency      = "EUR",
                Note          = operation.Detail,
                SourceKind    = operation.SourceKind
            };

            return(trx);
        }
Example #2
0
        public void Add(UnifiedAccountOperation operation)
        {
            Operations.Add(operation);
            Income  += operation.Income;
            Outcome += operation.Outcome;
            Balance  = Balance + operation.Income - operation.Outcome;

            if (!MinExecutionDate.HasValue || operation.ExecutionDate < MinExecutionDate)
            {
                MinExecutionDate = operation.ExecutionDate;
            }

            if (!MaxExecutionDate.HasValue || operation.ExecutionDate > MaxExecutionDate)
            {
                MaxExecutionDate = operation.ExecutionDate;
            }
        }
Example #3
0
        public static string BuildLabel(UnifiedAccountOperation operation)
        {
            var label = operation.Note;

            if (!string.IsNullOrEmpty(operation.PatternName))
            {
                var prioritizedParts =
                    new List <string>
                {
                    operation.ThirdParty,
                    operation.Address,
                    operation.City,
                    operation.Communication,
                    operation.IBAN,
                    operation.BIC?.Insert(0, "BIC ")
                }.Where(s => !string.IsNullOrWhiteSpace(s))
                .Select(s => _whiteSpaceRegex.Replace(s, " ").Trim())
                .Where(s => !string.IsNullOrEmpty(s)).ToArray();

                var patternNameLength = operation.PatternName.Length;
                var maxLength         = 128 - patternNameLength;

                var sb = new StringBuilder();

                foreach (var part in prioritizedParts)
                {
                    var toAdd = $"{part} - ";
                    if (sb.Length + toAdd.Length <= maxLength)
                    {
                        sb.Append(toAdd);
                    }
                }

                sb.Append(operation.PatternName);

                label = sb.ToString();
                label = label.ToLowerInvariant();
                label = SetAcronymsToUpperCase(label);
                label = CultureInfo.InvariantCulture.TextInfo.ToTitleCase(label);
                label = SetAcronymsToUpperCase(label);
            }

            return(label);
        }
Example #4
0
        public override UnifiedAccountOperation Map(FortisOperation fortisOperation, CultureInfo culture)
        {
            decimal income = 0, outcome = 0;

            if (!string.IsNullOrEmpty(fortisOperation.Amount))
            {
                var amount = decimal.Parse(
                    fortisOperation.Amount,
                    NumberStyles.AllowLeadingSign | NumberStyles.AllowThousands | NumberStyles.AllowDecimalPoint,
                    culture);

                if (amount < 0)
                {
                    outcome = -amount;
                }
                else
                {
                    income = amount;
                }
            }

            var trx = new UnifiedAccountOperation
            {
                Account       = fortisOperation.Account,
                OperationId   = fortisOperation.Reference,
                ValueDate     = fortisOperation.ValueDate,
                ExecutionDate = fortisOperation.ExecutionDate,
                Income        = income,
                Outcome       = outcome,
                Currency      = fortisOperation.Currency,
                Note          = fortisOperation.Detail,
                ThirdParty    = fortisOperation.CounterpartyOfTheTransaction,
                SourceKind    = fortisOperation.SourceKind
            };

            return(trx);
        }