private IList <Transaction> GetAccountTransactions(CreditAccountDescriptor accountDescriptor, IList <CardListInfo> cards, DateTime period)
        {
            var index        = GetCardIndex(accountDescriptor, cards);
            var transactions = _api.GetTransactions(index, period.Month, period.Year);

            var result = new List <Transaction>();

            foreach (var transaction in transactions)
            {
                if (transaction.DealsInbound != null && transaction.DealsInbound.Equals("yes", StringComparison.OrdinalIgnoreCase))
                {
                    var      pd   = transaction.FullPurchaseDate;
                    string[] date = string.IsNullOrEmpty(pd) ? new[] { "1", "1", "2000" } : pd.Split('/');
                    var      voucherNumberRatz = Convert.ToInt64(transaction.VoucherNumberRatz);
                    var      supplierName      = transaction.SupplierName;
                    var      paymentSum        = Convert.ToDecimal(transaction.PaymentSum);
                    var      supplierId        = transaction.SupplierId;
                    var      creditInfo        = transaction.MoreInfo;

                    if (voucherNumberRatz != 0)
                    {
                        var purchaseDate = new DateTime(Convert.ToInt32(date[2]), Convert.ToInt32(date[1]), Convert.ToInt32(date[0]));
                        var paymentDate  = 12 * (period.Year - purchaseDate.Year) + period.Month - purchaseDate.Month;
                        result.Add(new Transaction
                        {
                            SupplierId     = supplierId,
                            Id             = voucherNumberRatz,
                            PurchaseDate   = purchaseDate,
                            PaymentDate    = purchaseDate.AddMonths(paymentDate),
                            Description    = string.IsNullOrEmpty(creditInfo) ? supplierName : $"{supplierName} - {creditInfo}",
                            ProviderName   = _providerName,
                            CurrentBalance = Decimal.Zero,
                            Amount         = paymentSum > 0 ? paymentSum : -1 * paymentSum,
                            Type           = paymentSum > 0 ? TransactionType.Expense : TransactionType.Income
                        });
                    }
                }
                else
                {
                    var      pd   = transaction.FullPurchaseDateOutbound as string;
                    string[] date = string.IsNullOrEmpty(pd) ? new[] { "1", "1", "2000" } : pd.Split('/');
                    var      voucherNumberRatz = Convert.ToInt64(transaction.VoucherNumberRatzOutbound);
                    var      supplierName      = string.IsNullOrEmpty(transaction.SupplierNameOutbound) ? "" : transaction.SupplierNameOutbound;
                    var      paymentSum        = Convert.ToDecimal(transaction.PaymentSumOutbound);
                    var      supplierId        = transaction.SupplierId;

                    if (voucherNumberRatz != 0)
                    {
                        var purchaseDate = new DateTime(Convert.ToInt32(date[2]), Convert.ToInt32(date[1]),
                                                        Convert.ToInt32(date[0]));
                        var paymentDate = 12 * (period.Year - purchaseDate.Year) + period.Month - purchaseDate.Month;
                        result.Add(new Transaction
                        {
                            SupplierId     = supplierId,
                            Id             = voucherNumberRatz,
                            PurchaseDate   = purchaseDate,
                            PaymentDate    = purchaseDate.AddMonths(paymentDate),
                            Description    = supplierName,
                            ProviderName   = _providerName,
                            CurrentBalance = Decimal.Zero,
                            Amount         = paymentSum,
                            Type           = TransactionType.Expense
                        });
                    }
                    else if (!string.IsNullOrEmpty(transaction.SupplierName))
                    {
                        if (transaction.SupplierName.Contains("לידיעה"))
                        {
                            result.RemoveAt(result.Count - 1);
                        }
                    }
                }
            }

            FilterPullTransactions(result);

            return(result);
        }
Beispiel #2
0
        public IEnumerable <ITransaction> GetTransactions(long accountId, DateTime startTime, DateTime endTime)
        {
            var index        = GetCardIndex(accountId);
            var transactions = _amexApi.GetTransactions(index, startTime.Month, startTime.Year);

            var result = new List <ITransaction>();

            foreach (var transaction in transactions)
            {
                if (transaction.DealsInbound.Equals("yes", StringComparison.InvariantCultureIgnoreCase))
                {
                    var      purchaseDate      = transaction.FullPurchaseDate as string;
                    string[] date              = string.IsNullOrEmpty(purchaseDate) ? new[] { "1", "1", "2000" } : purchaseDate.Split('/');
                    var      voucherNumberRatz = Convert.ToInt64(transaction.VoucherNumberRatz);
                    var      supplierName      = transaction.SupplierName;
                    var      paymentSum        = Convert.ToDouble(transaction.PaymentSum);
                    var      supplierId        = transaction.SupplierId;
                    var      creditInfo        = transaction.MoreInfo;

                    if (voucherNumberRatz != 0)
                    {
                        result.Add(new CreditTransaction
                        {
                            AccountId        = accountId,
                            SupplierId       = supplierId,
                            EventId          = voucherNumberRatz,
                            EventDate        = new DateTime(Convert.ToInt32(date[2]), Convert.ToInt32(date[1]), Convert.ToInt32(date[0])),
                            EventDescription = string.IsNullOrEmpty(creditInfo) ? supplierName : string.Format("{0} - {1}", supplierName, creditInfo),
                            CurrentBalance   = Double.NaN,
                            EventAmount      = paymentSum > 0 ? paymentSum : -1 * paymentSum,
                            Type             = paymentSum > 0 ? TransactionType.Expense : TransactionType.Income
                        });
                    }
                }
                else
                {
                    var      purchaseDate      = transaction.FullPurchaseDateOutbound as string;
                    string[] date              = string.IsNullOrEmpty(purchaseDate) ? new[] { "1", "1", "2000" } : purchaseDate.Split('/');
                    var      voucherNumberRatz = Convert.ToInt64(transaction.VoucherNumberRatzOutbound);
                    var      supplierName      = string.IsNullOrEmpty(transaction.SupplierNameOutbound) ? "" : transaction.SupplierNameOutbound;
                    var      paymentSum        = Convert.ToDouble(transaction.PaymentSumOutbound);
                    var      supplierId        = transaction.SupplierId as String;

                    if (voucherNumberRatz != 0)
                    {
                        result.Add(new CreditTransaction
                        {
                            AccountId        = accountId,
                            SupplierId       = supplierId,
                            EventId          = voucherNumberRatz,
                            EventDate        = new DateTime(Convert.ToInt32(date[2]), Convert.ToInt32(date[1]), Convert.ToInt32(date[0])),
                            EventDescription = supplierName,
                            CurrentBalance   = Double.NaN,
                            EventAmount      = paymentSum,
                            Type             = TransactionType.Expense
                        });
                    }
                }
            }

            return(result);
        }