Esempio n. 1
0
        private static List <Invoice> DoSearchByOtherFields(InvoiceSearchFilter invoiceSearchFilter,
                                                            IEnumerable <Invoice> allInvoices)
        {
            //shan - mar 09, 2012 - match the values without case sensitive
            //Displays invoices related to a particular contact
            //Fix to Defect#39425
            if (!string.IsNullOrEmpty(invoiceSearchFilter.FirstName) &&
                !string.IsNullOrEmpty(invoiceSearchFilter.LastName))
            {
                allInvoices = allInvoices.Where(
                    i => i.FirstName.ToUpper().Equals(invoiceSearchFilter.FirstName.ToUpper()) &&
                    i.LastName.ToUpper().Equals(invoiceSearchFilter.LastName.ToUpper()))
                              .OrderByDescending(i => i.ID);
            }
            else if (!string.IsNullOrEmpty(invoiceSearchFilter.FirstName))
            {
                allInvoices =
                    allInvoices.Where(i => i.FirstName.ToLower().Contains(invoiceSearchFilter.FirstName.ToLower()));
            }
            else if (!string.IsNullOrEmpty(invoiceSearchFilter.LastName))
            {
                allInvoices =
                    allInvoices.Where(
                        i => i.LastName.ToLower().Contains(invoiceSearchFilter.LastName.ToLower()));
            }
            else if (!string.IsNullOrEmpty(invoiceSearchFilter.StreetAddress))
            {
                allInvoices =
                    allInvoices.Where(
                        i => i.Address1.ToLower().Contains(invoiceSearchFilter.StreetAddress.ToLower()));
            }
            else if (!string.IsNullOrEmpty(invoiceSearchFilter.City))
            {
                allInvoices =
                    allInvoices.Where(
                        i => i.City.ToLower().Contains(invoiceSearchFilter.City.ToLower()));
            }
            else if (!string.IsNullOrEmpty(invoiceSearchFilter.State))
            {
                allInvoices =
                    allInvoices.Where(
                        i => i.State.ToLower().Contains(invoiceSearchFilter.State.ToLower()));
            }
            else if (!string.IsNullOrEmpty(invoiceSearchFilter.ZipCode))
            {
                allInvoices =
                    allInvoices.Where(
                        i => i.PostalCode.ToLower().Contains(invoiceSearchFilter.ZipCode.ToLower()));
            }
            else if (invoiceSearchFilter.InvoiceTotal.HasValue)
            {
                allInvoices =
                    allInvoices.Where(
                        i => i.TotalDue == invoiceSearchFilter.InvoiceTotal);
            }
            else if (invoiceSearchFilter.TotalVolumePoints.HasValue)
            {
                allInvoices =
                    allInvoices.Where(
                        i => i.TotalVolumePoints == invoiceSearchFilter.TotalVolumePoints);
            }

            if (null != allInvoices && allInvoices.Count() > 0)
            {
                return(allInvoices.ToList());
            }
            return(null);
        }
Esempio n. 2
0
        private static List <Invoice> DoSearchByDateOrAmount(InvoiceSearchFilter invoiceSearchFilter,
                                                             IEnumerable <Invoice> allInvoices)
        {
            if (null == invoiceSearchFilter.FromDate &&
                null != invoiceSearchFilter.ToDate)
            {
                allInvoices =
                    allInvoices.Where(
                        i => i.InvoiceDate <= invoiceSearchFilter.ToDate);
            }

            if (null != invoiceSearchFilter.FromDate &&
                null == invoiceSearchFilter.ToDate)
            {
                allInvoices =
                    allInvoices.Where(i => i.InvoiceDate >= invoiceSearchFilter.FromDate &&
                                      i.InvoiceDate <= DateTime.Now);
            }

            if (null != invoiceSearchFilter.FromDate &&
                null != invoiceSearchFilter.ToDate)
            {
                allInvoices =
                    allInvoices.Where(i => i.InvoiceDate >= invoiceSearchFilter.FromDate &&
                                      i.InvoiceDate <= invoiceSearchFilter.ToDate);
            }

            //begin - shan - mar 14, 2012 - filter either by null or 0
            //field can be left empty or 0 can be entered..
            //if empty..dont consider as criteria..if 0..filter based on that..
            //if empty..null should have been set from UI
            //if (invoiceSearchFilter.StartAmount == null && invoiceSearchFilter.EndAmount > 0)
            //{
            //    invoiceSearchFilter.StartAmount = 0;
            //    allInvoices = allInvoices.
            //        Where(i => i.TotalDue >= invoiceSearchFilter.StartAmount &&
            //        i.TotalDue <= invoiceSearchFilter.EndAmount);
            //}

            //if (invoiceSearchFilter.StartAmount > 0 && invoiceSearchFilter.EndAmount == null)
            //{
            //    invoiceSearchFilter.EndAmount = 0;
            //    allInvoices = allInvoices.
            //        Where(i => i.TotalDue >= invoiceSearchFilter.StartAmount);
            //}

            //if ((invoiceSearchFilter.StartAmount > 0 && invoiceSearchFilter.EndAmount > 0) ||
            //    (invoiceSearchFilter.StartAmount.HasValue && invoiceSearchFilter.EndAmount.HasValue))
            //{
            //    allInvoices = allInvoices.
            //        Where(i => i.TotalDue >= invoiceSearchFilter.StartAmount &&
            //        i.TotalDue <= invoiceSearchFilter.EndAmount);
            //}
            if (null == invoiceSearchFilter.StartAmount &&
                0 < invoiceSearchFilter.EndAmount)
            {
                allInvoices = allInvoices.
                              Where(i => i.TotalDue <= invoiceSearchFilter.EndAmount);
            }

            if (0 < invoiceSearchFilter.StartAmount &&
                null == invoiceSearchFilter.EndAmount)
            {
                allInvoices = allInvoices.
                              Where(i => i.TotalDue >= invoiceSearchFilter.StartAmount);
            }

            if (invoiceSearchFilter.StartAmount.HasValue &&
                invoiceSearchFilter.EndAmount.HasValue)
            {
                allInvoices = allInvoices.
                              Where(i => i.TotalDue >= invoiceSearchFilter.StartAmount &&
                                    i.TotalDue <= invoiceSearchFilter.EndAmount);
            }
            //end

            if (null != allInvoices && allInvoices.Count() > 0)
            {
                return(allInvoices.ToList());
            }
            return(null);
        }
Esempio n. 3
0
        public static List <Invoice> SearchInvoice(InvoiceSearchFilter invoiceSearchFilter, string distributorID)
        {
            var proxy = ServiceClientProvider.GetOrderServiceProxy();

            try
            {
                var allInvoices = GetInvoices(distributorID);

                if (null == allInvoices)
                {
                    return(null);
                }

                if (invoiceSearchFilter != null)
                {
                    if (invoiceSearchFilter.SearchByDateOrAmount)
                    {
                        return(DoSearchByDateOrAmount(invoiceSearchFilter, allInvoices));
                    }
                    else
                    {
                        if (!string.IsNullOrEmpty(invoiceSearchFilter.SKU) ||
                            !string.IsNullOrEmpty(invoiceSearchFilter.Description))
                        {
                            var request = new SearchInvoiceRequest_V01
                            {
                                DistributorID = distributorID,
                                SKU           = invoiceSearchFilter.SKU,
                                Description   = invoiceSearchFilter.Description
                            };
                            var response = proxy.SearchInvoice(new SearchInvoiceRequest1(request)).SearchInvoiceResult as SearchInvoiceResponse_V01;

                            if (response != null && response.Status == ServiceResponseStatusType.Success &&
                                null != response.InvoiceIDs && response.InvoiceIDs.Count > 0)
                            {
                                var invoicesBySkuOrDesc = allInvoices.Where(i => response.InvoiceIDs.Any(a => a == i.ID));
                                if (null != invoicesBySkuOrDesc && invoicesBySkuOrDesc.Count() > 0)
                                {
                                    return(invoicesBySkuOrDesc.ToList());
                                }
                                return(null);
                            }
                        }
                        else
                        {
                            return(DoSearchByOtherFields(invoiceSearchFilter, allInvoices));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                WebUtilities.LogExceptionWithContext(ex);

                LoggerHelper.Exception("System.Exception", new Exception("OrderService: SearchInvoice\n", ex));
            }
            finally
            {
                if (proxy.State != CommunicationState.Closed)
                {
                    proxy.Close();
                }
                proxy = null;
            }
            return(null);
        }