Exemplo n.º 1
0
        private List <Myorder> GetAllegroEntries(BankEntry entry, AllegroData model, out List <Offer> offersMatchingPrice)
        {
            offersMatchingPrice = null;
            List <Myorder> allegroOrders = FindOrdersWhichMatchEntryPriceFullyOrPartially(entry, model);

            if (allegroOrders.Count == 0)
            {
                return(null);
            }
            if (allegroOrders.Count == 1)
            {
                return(allegroOrders);
            }
            else
            {
                List <Myorder> dateFilteredEntries = allegroOrders.Where(x => x.payment.endDate.Date == entry.Date.Date).ToList();
                if (dateFilteredEntries.Count < 1)
                {
                    return(FindRefundEntries(entry, ref offersMatchingPrice, allegroOrders));
                }
                else
                {
                    return(FindProperEntriesBasedOnDateTime(entry, dateFilteredEntries));
                }
            }
        }
Exemplo n.º 2
0
        public static DateTime GetOldestDate(AllegroData model)
        {
            if (model.myorders == null)
            {
                return(DateTime.MinValue);
            }
            List <DateTime> allDates = GetAllDates(model);

            return(allDates.Last());
        }
Exemplo n.º 3
0
        public static AllegroDataContainer Consolidate(List <AllegroDataContainer> dataList)
        {
            dataList = dataList.Where(x => x?.Model.myorders != null).ToList();


            AllegroData           first     = dataList.First().Model;
            IEnumerable <Myorder> allOrders = dataList.SelectMany(x => x.Model.myorders.myorders);

            Myorder[] distinct = allOrders.GroupBy(x => x.id).Select(g => g.First()).OrderByDescending(x => x.orderDate).ToArray();

            first.myorders.myorders = distinct;
            return(new AllegroDataContainer(first, dataList.First().ServiceUserName));
        }
Exemplo n.º 4
0
        private List <Myorder> GetRelevantOrders(BankEntry entry, List <AllegroDataContainer> allegroDataContainers, out AllegroDataContainer associatedContainer, out List <Offer> potentiallyRelatedOfferIds)
        {
            associatedContainer = allegroDataContainers.FirstOrDefault(x => x.ServiceUserName == entry.Payer);
            AllegroData  model = associatedContainer?.Model;
            List <Offer> offersWhichMatchThePriceButNotTheDateBecauseTheyAreRefunds = null;

            List <Myorder> result = null;

            if (model != null)
            {
                result = this.GetAllegroEntries(entry, model, out _);
            }

            if (result != null)
            {
                potentiallyRelatedOfferIds = null;
                return(result);
            }
            else
            {
                //the payer can be empty or it can be somehow incorrect, but if we have an entry that matches the exact price and date... it's probably IT
                foreach (AllegroDataContainer container in allegroDataContainers)
                {
                    List <Myorder> entries = this.GetAllegroEntries(entry, container.Model, out List <Offer> offersMatchingPrice);
                    if (offersMatchingPrice != null && offersMatchingPrice.Any())
                    {
                        offersWhichMatchThePriceButNotTheDateBecauseTheyAreRefunds = new List <Offer>(offersMatchingPrice);
                    }
                    if (entries != null && entries.Any())
                    {
                        associatedContainer        = container;
                        potentiallyRelatedOfferIds = null;
                        return(entries);
                    }
                }
            }

            potentiallyRelatedOfferIds = offersWhichMatchThePriceButNotTheDateBecauseTheyAreRefunds?.ToList();
            return(null);
        }
Exemplo n.º 5
0
        private List <Myorder> GetAllegroOrders(BankEntry entry, AllegroData model)
        {
            //first try finding the orders which fully correspond to the price and more or less the date
            List <Myorder> dateFiltered = model.myorders.myorders
                                          .Where(x => x.orderDate.Date <= entry.Date.Date)
                                          .Where(x => (entry.Date.Date - x.orderDate.Date).TotalDays < 30).ToList();

            List <Myorder> allegroOrders = dateFiltered
                                           .Where(x =>
                                                  x.GetAmount(this.converter) == this.converter.ToDecimal(entry.Amount.ToString().Trim('-'))

                                                  ).ToList();


            if (allegroOrders.Count == 0)
            {
                return(null);
            }
            if (allegroOrders.Count == 1)
            {
                return(allegroOrders);
            }
            else
            {
                List <Myorder> dateFilteredOrders = allegroOrders.Where(
                    x => x.payment.endDate.Date == entry.Date.Date ||
                    (x.payment.endDate.Date.Year == 0001 &&
                     x.orderDate.Date == entry.Date.Date)
                    ).ToList();
                if (dateFilteredOrders.Count < 1)
                {
                    this.logger.Warning($"Unrecognized entry. {allegroOrders.Count} orders matched the price, but none matched the payment date. {entry}");
                    return(null);
                }
                else
                {
                    return(FindProperOrdersBasedOnDateTime(entry, dateFilteredOrders));
                }
            }
        }
Exemplo n.º 6
0
        private List <Myorder> GetRelevantOrders(BankEntry entry, List <AllegroDataContainer> allegroDataContainers, out AllegroDataContainer associatedContainer)
        {
            //get data model for the payer
            associatedContainer = allegroDataContainers.FirstOrDefault(x => x.ServiceUserName == entry.Payer);
            string      associatedUserName = associatedContainer?.ServiceUserName;
            AllegroData model = associatedContainer?.Model;

            List <Myorder> result = null;

            if (model != null)
            {
                result = this.GetAllegroOrders(entry, model);
            }
            //model might be not-null but the result might be null
            if (result != null)
            {
                return(result);
            }
            else
            {
                //the payer can be empty or it can be somehow incorrect, but if we have an order that matches the exact price and date... it's probably IT
                //so try finding order in any persons data
                List <AllegroDataContainer> alternativeContainers = FindAlternativeDataContainers(allegroDataContainers, associatedUserName);

                foreach (AllegroDataContainer container in alternativeContainers)
                {
                    List <Myorder> allegroOrders = this.GetAllegroOrders(entry, container.Model);
                    if (allegroOrders != null && allegroOrders.Any())
                    {
                        associatedContainer = container;
                        return(allegroOrders);
                    }
                }
            }
            return(null);
        }
Exemplo n.º 7
0
        private List <Myorder> FindOrdersWhichMatchEntryPriceFullyOrPartially(BankEntry entry, AllegroData model)
        {
            //first try finding the orders which fully correspond to the price
            List <Myorder> allegroOrders = model.myorders.myorders
                                           .Where(x => x.payment.startDate.Date <= entry.Date)
                                           .Where(x =>
                                                  x.GetAmount(converter) == this.converter.ToDecimal(entry.Amount.ToString().Trim('-')
                                                                                                     )).ToList();


            if (allegroOrders.Count == 0)
            {
                //and if that doesnt succeed, find orders where at least one offer matches the price
                allegroOrders = model.myorders.myorders
                                //  .Where(x=>x.payment.startDate < entry.Date)
                                .Where(x =>
                                       x.offers.Any(x =>
                                                    this.converter.ToDecimal(x.offerPrice.amount) == this.converter.ToDecimal(entry.Amount.ToString().Trim('-')))
                                       ).ToList();
            }

            return(allegroOrders);
        }
Exemplo n.º 8
0
 private static List <DateTime> GetAllDates(AllegroData model)
 {
     return(model.myorders.myorders.Select(x => Convert.ToDateTime(x.orderDate))
            .OrderByDescending(x => x).ToList());
 }
Exemplo n.º 9
0
 public AllegroDataContainer(AllegroData model, string serviceUserName)
 {
     this.Model           = model;
     this.ServiceUserName = serviceUserName;
     this.AssignTimeRange();
 }