public bool IsAccept(OrderToTrackDTO orderToTrackInfo,
                             string status,
                             DateTime?statusDate,
                             IList <TrackingRecord> records)
        {
            var today = _time.GetAppNowTime().Date;

            //var now = _time.GetAppNowTime();

            //почта после 60 дней за них не отвечает
            //старше 55 дней
            if (statusDate.HasValue &&
                statusDate.Value.AddDays(55) < today)
            {
                return(false);
            }

            //5.	Don’t show “Label Never Shipped” for 36 hours after it was generated.
            //NOTE: round to 2 days
            //TASK: давай сделаем 10
            if (statusDate.HasValue &&
                _time.GetBizDaysCount(statusDate.Value.Date, today) > 10)
            {
                return(false);
            }

            if (orderToTrackInfo.LabelCanceled)
            {
                return(false);
            }

            if (orderToTrackInfo.ActualDeliveryDate.HasValue)
            {
                return(false);
            }

            if (status.ToLower().Contains("delivered"))
            {
                return(false);
            }

            if ((status.Contains(USPSPreShipmentInfoStatus) ||
                 status == USPSShipmentPickedUp ||
                 status == USPSNoRecordStatus ||
                 status == USPSShipmentProcessing) &&
                statusDate.HasValue)
            {
                var dayCount = _time.GetBizDaysCount(statusDate.Value.Date, today);
                if (dayCount > 1)
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 2
0
        public void Process(Core.IUnitOfWork db,
                            OrderToTrackDTO shipping,
                            string status,
                            DateTime?statusDate,
                            IList <TrackingRecord> records,
                            DateTime when)
        {
            if (IsAccept(shipping, status, statusDate, records))
            {
                var recordId = shipping.ShipmentInfoId.HasValue
                    ? shipping.ShipmentInfoId.Value
                    : (shipping.MailInfoId ?? 0);

                var additionalParams = new LabelGetStuckParams()
                {
                    Status          = status,
                    StatusDate      = statusDate,
                    ShippingName    = shipping.ShippingName,
                    Carrier         = shipping.Carrier,
                    OrderNumber     = shipping.OrderNumber,
                    LabelFromTypeId =
                        shipping.ShipmentInfoId.HasValue ? (int)LabelFromType.Batch : (int)LabelFromType.Mail,
                    ShippingInfoId = recordId,
                    ReasonId       = shipping.ReasonId
                };

                var result = _notificationService.Add(shipping.TrackingNumber,
                                                      EntityType.Tracking,
                                                      String.Empty,
                                                      additionalParams,
                                                      shipping.OrderNumber,
                                                      Type);

                if (result.HasValue)
                {
                    _log.Info("Added notification, type=" + Type + ", id=" + shipping.TrackingNumber);
                }
            }
            else
            {
                _notificationService.RemoveExist(shipping.TrackingNumber, Type);
            }
        }
Ejemplo n.º 3
0
 public void CheckRules(IUnitOfWork db,
                        OrderToTrackDTO shipping,
                        string status,
                        DateTime?statusDate,
                        IList <TrackingRecord> records,
                        IList <ITrackingRule> ruleList)
 {
     foreach (var rule in ruleList)
     {
         try
         {
             rule.Process(db,
                          shipping,
                          status,
                          statusDate,
                          records,
                          _time.GetAppNowTime());
         }
         catch (Exception ex)
         {
             _log.Error("Can't process tracking rule, for order #: " + shipping.OrderNumber, ex);
         }
     }
 }
Ejemplo n.º 4
0
        public bool IsAccept(OrderToTrackDTO orderToTrackInfo,
                             string status,
                             DateTime?statusDate,
                             IList <TrackingRecord> records)
        {
            var now   = _time.GetAppNowTime();
            var today = _time.GetAppNowTime().Date;

            var lastRecord    = records.FirstOrDefault();
            var packageGoBack = (lastRecord != null ? _addressService.IsMine(lastRecord.AsAddressDto()) : false) ||
                                orderToTrackInfo.DeliveredStatus == (int)DeliveredStatusEnum.DeliveredToSender;

            //почта после 60 дней за них не отвечает
            //старше 55 дней
            if (statusDate.HasValue &&
                statusDate.Value.AddDays(55) < today)
            {
                return(false);
            }

            if (packageGoBack)
            {
                return(false); //No actions if package go back
            }
            if (orderToTrackInfo.Carrier == ShippingServiceUtils.USPSCarrier)
            {
                if (statusDate.HasValue &&
                    !_time.IsBusinessDay(statusDate.Value) &&
                    _time.GetBizDaysCount(statusDate.Value, today) < 2)
                {
                    //TASK: Let’s not send Exception messages for First Class packages if they were not delivered on Weekends/holidays.
                    if (orderToTrackInfo.ShippingMethodId.HasValue
                        &&
                        ShippingUtils.GetShippingType(orderToTrackInfo.ShippingMethodId.Value) ==
                        ShippingTypeCode.Standard)
                    {
                        //Don’t send notice to first class orders which USPS tried to deliver on Saturday.
                        //They will automatically will redeliver it on the next business day.
                        return(false);
                    }


                    //TASK: if any package couldn’t be delivered to FF on weekends/holidays
                    if (AddressHelper.IsFFAddress(orderToTrackInfo.ShippingAddress))
                    {
                        return(false);
                    }
                }

                //TASK: If First Class order wasn’t delivered like 102-1600419-5915438 check again in 24 hours, and only then send notifications.
                if (orderToTrackInfo.ShippingMethodId.HasValue
                    &&
                    ShippingUtils.GetShippingType(orderToTrackInfo.ShippingMethodId.Value) == ShippingTypeCode.Standard)
                {
                    var statusNextBusiessDay = _time.AddBusinessDays(statusDate, 1);
                    if (statusNextBusiessDay > now)
                    {
                        return(false);
                    }
                }

                if (!String.IsNullOrEmpty(status) &&
                    (status.IndexOf("Notice Left", StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                     status.IndexOf("Receptacle Blocked", StringComparison.CurrentCultureIgnoreCase) >= 0 ||
                     status.IndexOf("Available for Pickup", StringComparison.InvariantCultureIgnoreCase) >= 0 ||
                     status.IndexOf("Business Closed", StringComparison.OrdinalIgnoreCase) >= 0 ||
                     status.IndexOf("Undeliverable as Addressed", StringComparison.OrdinalIgnoreCase) >= 0 ||
                     status.IndexOf("Addressee not available", StringComparison.OrdinalIgnoreCase) >= 0) &&
                    statusDate.HasValue)
                {
                    return(true);
                }
            }

            if (orderToTrackInfo.Carrier == ShippingServiceUtils.DHLCarrier ||
                orderToTrackInfo.Carrier == ShippingServiceUtils.DHLMXCarrier)
            {
                if (!String.IsNullOrEmpty(status) &&
                    status.IndexOf("Delivery attempted; recipient not home", StringComparison.InvariantCultureIgnoreCase) >= 0 &&
                    statusDate.HasValue)
                {
                    return(true);
                }
            }

            return(false);
        }
Ejemplo n.º 5
0
        public bool IsAccept(OrderToTrackDTO orderToTrackInfo,
                             string status,
                             DateTime?statusDate,
                             IList <TrackingRecord> records)
        {
            /*TASK: When tracking history contains “Undeliverable as Addressed” like order 114-8804539-8077829
             * When it’s being scanned back in Hallandale (after that),and if there is no Notes in account after the day it was scanned as undeliverable, send client an email:
             * “Dear %Name%,
             * Your order of %List Of pajamas% being returned to us by USPS because the address you have provided for this order is undeliverable.
             * Please review full tracking history of this order at %link to USPS with tracking number%.
             * Please let us know how would you like us to proceed with your order once we get it back.
             *
             * Best Regards,
             * Customer Service”
             *
             * Please also add a note to the account: Order being returned, emailed customer.
             */

            var today = _time.GetAppNowTime().Date;

            //NOTE: processing only fresh records
            if (statusDate.HasValue &&
                statusDate.Value < today.AddDays(-10))
            {
                _log.Info("Skip old status, pass more than 10 days");
                return(false);
            }

            if (orderToTrackInfo.Carrier == ShippingServiceUtils.USPSCarrier)
            {
                //TASK: When tracking history contains “Undeliverable as Addressed”
                var undeliverableAsAddressStatus = records.FirstOrDefault(s =>
                                                                          String.Compare(s.Message, "Undeliverable as Addressed", StringComparison.OrdinalIgnoreCase) == 0 ||
                                                                          (s.Message ?? "").IndexOf("Addressee not available", StringComparison.OrdinalIgnoreCase) >= 0);
                if (undeliverableAsAddressStatus != null)
                {
                    //TASK: sent only to US and CA, for other country we always do refund
                    if (ShippingUtils.IsInternational(orderToTrackInfo.ShippingAddress.FinalCountry) &&
                        orderToTrackInfo.ShippingAddress.FinalCountry != "CA")
                    {
                        return(false);
                    }

                    _log.Info("Found \"Undeliverable As Addressed\"");
                    var scanInHallandale = records.FirstOrDefault(r => r.Date > undeliverableAsAddressStatus.Date &&
                                                                  _addressService.IsMine(r.AsAddressDto()));
                    if (scanInHallandale != null)
                    {
                        _log.Info("Being scanned back");
                        //When it’s being scanned back in Hallandale (after that),and if there is no Notes in account after the day it was scanned as undeliverable, send client an email

                        //NOTE: disable check and send message at same day when scanned back
                        //if (scanInHallandale.Date.HasValue && _time.GetBizDaysCount(scanInHallandale.Date.Value, today) > 1)
                        //{
                        //    if (!records.Any(r => r.Date >= scanInHallandale.Date.Value
                        //                          && !_addressService.IsMine(r.AsAddressDto())))
                        //    {
                        //        _log.Info("no Notes in account after the day it was scanned. Send email.");

                        //        return true;
                        //    }
                        //    else
                        //    {
                        //        _log.Info("Found extra notes after package was scanned back");
                        //    }
                        //}

                        return(true);
                    }
                }
            }

            return(false);
        }
Ejemplo n.º 6
0
        public bool IsAccept(OrderToTrackDTO orderToTrackInfo,
                             string status,
                             DateTime?statusDate,
                             IList <TrackingRecord> records)
        {
            var today = _time.GetAppNowTime().Date;

            if (orderToTrackInfo.LabelCanceled == true ||
                orderToTrackInfo.CancelLabelRequested == true)
            {
                return(false);
            }

            //почта после 60 дней за них не отвечает
            //старше 55 дней
            if (statusDate.HasValue &&
                statusDate.Value.AddDays(55) < today)
            {
                return(false);
            }

            if (orderToTrackInfo.LabelCanceled)
            {
                return(false);
            }

            if (orderToTrackInfo.ActualDeliveryDate.HasValue)
            {
                return(false);
            }

            if (status.IndexOf("Pre-Shipment Info Sent to USPS", StringComparison.InvariantCultureIgnoreCase) > 0)
            {
                return(false);
            }

            if (statusDate.HasValue && orderToTrackInfo.ShippingMethodId.HasValue)
            {
                var isInternational = ShippingUtils.IsInternationalShippingType(orderToTrackInfo.ShippingMethodId.Value);
                if (!isInternational)
                {
                    var shippingType = ShippingUtils.GetShippingType(orderToTrackInfo.ShippingMethodId.Value);

                    var periodDays = 4;
                    switch (shippingType)
                    {
                    case ShippingTypeCode.Standard:
                        periodDays = 4;
                        break;

                    case ShippingTypeCode.Priority:
                        periodDays = 2;
                        break;

                    case ShippingTypeCode.PriorityExpress:
                        periodDays = 1;
                        break;

                    case ShippingTypeCode.SameDay:
                        periodDays = 1;     //TODO: 0.5
                        break;
                    }

                    var dayCount = _time.GetBizDaysCount(statusDate.Value, today);
                    if (dayCount > periodDays)
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }