Пример #1
0
        /// <summary>
        /// Method to check for a cart/changeorder being submitted
        /// </summary>
        public static bool CheckOrderBlock(UserProfile user, UserSelectedContext catalogInfo, Guid?cartId, string orderNumber,
                                           IPurchaseOrderRepository pORepository, IOrderHistoryHeaderRepsitory hHRepository, ICacheRepository cache)
        {
            if (cartId != null && orderNumber == null) // if we are given cartId but not orderNumber, check for cross-reference
            {
                string cachekey = string.Format("Cart2OrderId_{0}", cartId);
                orderNumber = cache.GetItem <string>(CACHE_GROUPNAME, CACHE_PREFIX, CACHE_NAME, cachekey);
            }

            if (orderNumber != null && cartId == null) // if we are given an orderNumber but not cartId, we could be in changeorder, check for cross-reference
            {
                string cachekey       = string.Format("ChangeOrder_Order2NewOrderId_{0}", orderNumber);
                string newOrderNumber = cache.GetItem <string>(CACHE_GROUPNAME, CACHE_PREFIX, CACHE_NAME, cachekey);
                if (newOrderNumber != null)
                {
                    orderNumber = newOrderNumber;
                }
            }

            EF.OrderHistoryHeader theEFOrder = null;

            Order theOrder = null;

            // to check, we need to build the order and look at its status.
            if (catalogInfo != null && orderNumber != null && hHRepository != null)
            {
                // We just get the header not the details for performance
                theEFOrder = hHRepository.Read(h => h.BranchId.Equals(catalogInfo.BranchId, StringComparison.InvariantCultureIgnoreCase) &&
                                               (h.ControlNumber.Equals(orderNumber))).FirstOrDefault();
            }

            if (theEFOrder == null && pORepository != null && orderNumber != null) // if we don't find a header, try and construct the order from the purchaseOrder
            {
                CS.PurchaseOrder po = pORepository.ReadPurchaseOrderByTrackingNumber(orderNumber);

                theOrder = po.ToOrder();
            }
            else
            {
                if (theEFOrder != null)
                {
                    theOrder = theEFOrder.ToOrder();
                }
            }

            // we provide for no block for sysadmin
            // block a pending or submitted order otherwise
            //if (user.RoleName.Equals("beksysadmin", StringComparison.CurrentCultureIgnoreCase) == false &&
            //    theOrder != null && ((theOrder.Status.Equals("Pending")) | (theOrder.Status.Equals("Submitted"))))
            if (theOrder != null)
            {
                if ((theOrder.Status.Equals("Pending")) | (theOrder.Status.Equals("Submitted")))
                {
                    return(true);
                }
            }

            return(false);
        }
        public static OrderHistoryFile ToOrderHistoryFile(this CS.PurchaseOrder value, UserSelectedContext customerInfo, string specialCatalogId = null)
        {
            OrderHistoryFile retVal = new OrderHistoryFile();

            retVal.Header = value.ToOrderHistoryHeader(customerInfo, specialCatalogId);
            if (value.Properties["LineItems"] != null)
            {
                retVal.Details = ((CommerceServer.Foundation.CommerceRelationshipList)value.Properties["LineItems"])
                                 .Select(l => ToOrderHistoryDetail((CS.LineItem)l.Target, customerInfo.BranchId, retVal.Header.InvoiceNumber)).ToList();
            }


            return(retVal);
        }
Пример #3
0
        public static Order ToOrderHeader(this CS.PurchaseOrder value)
        {
            Order retVal = new Order()
            {
                CreatedDate          = DateTime.Parse(value.Properties["DateCreated"].ToString()),
                OrderNumber          = value.Properties["OrderNumber"].ToString(),
                OrderTotal           = Double.Parse(value.Properties["Total"].ToString()),
                InvoiceNumber        = value.Properties["MasterNumber"] == null ? "Pending" : value.Properties["MasterNumber"].ToString(),
                IsChangeOrderAllowed = (value.Properties["MasterNumber"] != null && (value.Status.StartsWith("Confirmed"))),                 // if we have a master number (invoice #) and a confirmed status
                Status            = System.Text.RegularExpressions.Regex.Replace(value.Status, "([a-z])([A-Z])", "$1 $2"),
                RequestedShipDate = value.Properties["RequestedShipDate"].ToString(),
                InvoiceStatus     = "N/A",
                CommerceId        = Guid.Parse(value.Id)
            };

            retVal.ItemCount = retVal.Items == null ? 0 : retVal.Items.Count;

            return(retVal);
        }
Пример #4
0
        public static Order ToOrder(this CS.PurchaseOrder value)
        {
            Order retVal = new Order()
            {
                CreatedDate          = DateTime.Parse(value.Properties["DateCreated"].ToString()),
                OrderNumber          = value.Properties["OrderNumber"].ToString(),
                OrderTotal           = Double.Parse(value.Properties["Total"].ToString()),
                InvoiceNumber        = value.Properties["MasterNumber"] == null ? "Pending" : value.Properties["MasterNumber"].ToString(),
                IsChangeOrderAllowed = (value.Properties["MasterNumber"] != null && (value.Status.StartsWith("Confirmed"))), // if we have a master number (invoice #) and a confirmed status
                Status            = System.Text.RegularExpressions.Regex.Replace(value.Status, "([a-z])([A-Z])", "$1 $2"),
                RequestedShipDate = value.Properties["RequestedShipDate"].ToString(),
                InvoiceStatus     = "N/A",
                Items             = value.Properties["LineItems"] == null ? null : ((CommerceServer.Foundation.CommerceRelationshipList)value.Properties["LineItems"]).Select(l => ToOrderLine((CS.LineItem)l.Target)).ToList(),
                CommerceId        = Guid.Parse(value.Id),
                PONumber          = value.Properties["PONumber"] == null ? string.Empty : value.Properties["PONumber"].ToString(),
                OrderSystem       = new OrderSource().Parse("B").ToString()
            };

            retVal.ItemCount = retVal.Items == null ? 0 : retVal.Items.Count;

            return(retVal);
        }
Пример #5
0
        public static OrderHistoryHeader ToOrderHistoryHeader(this CS.PurchaseOrder value, UserSelectedContext customerInfo, string specialCatalogId = null)
        {
            OrderHistoryHeader header = new OrderHistoryHeader();

            header.OrderSystem = OrderSource.Entree;

            //if (specialCatalogId == null) // TODO: What to do about branch for unfi?
            header.BranchId = customerInfo.BranchId;
            //else
            //    header.BranchId = specialCatalogId;

            header.CustomerNumber        = customerInfo.CustomerId;
            header.InvoiceNumber         = value.Properties["MasterNumber"] == null ? "Processing" : value.Properties["MasterNumber"].ToString();
            header.DeliveryDate          = value.Properties["RequestedShipDate"].ToString().ToDateTime().Value.ToLongDateFormat();
            header.PONumber              = value.Properties["PONumber"] == null ? string.Empty : value.Properties["PONumber"].ToString();
            header.ControlNumber         = value.Properties["OrderNumber"].ToString();
            header.OriginalControlNumber = value.Properties["OrderNumber"].ToString();

            // OrderStatus for Order History is either a blank space (normal), I (invoiced), D (deleted), or P (processing)
            //header.OrderStatus = System.Text.RegularExpressions.Regex.Replace(header.Status, "([a-z])([A-Z])", "$1 $2");
            header.OrderStatus = string.Empty;

            return(header);
        }
Пример #6
0
        public void WriteFileToQueue(string orderingUserEmail, string orderNumber, CS.PurchaseOrder newPurchaseOrder, OrderType orderType, string catalogType, string dsrNumber,
                                     string addressStreet, string addressCity, string addressState, string addressZip)
        {
            var newOrderFile = new OrderFile()
            {
                SenderApplicationName = Configuration.ApplicationName,
                SenderProcessName     = "Send order to queue",

                Header = new OrderHeader()
                {
                    OrderingSystem      = OrderSource.Entree,
                    Branch              = newPurchaseOrder.Properties["BranchId"].ToString().ToUpper(),
                    CustomerNumber      = newPurchaseOrder.Properties["CustomerId"].ToString(),
                    DsrNumber           = dsrNumber,
                    AddressStreet       = addressStreet,
                    AddressCity         = addressCity,
                    AddressRegionCode   = addressState,
                    AddressPostalCode   = addressZip,
                    DeliveryDate        = newPurchaseOrder.Properties["RequestedShipDate"].ToString(),
                    PONumber            = newPurchaseOrder.Properties["PONumber"] == null ? string.Empty : newPurchaseOrder.Properties["PONumber"].ToString(),
                    Specialinstructions = string.Empty,
                    ControlNumber       = int.Parse(orderNumber),
                    OrderType           = orderType,
                    InvoiceNumber       = orderType == OrderType.NormalOrder ? string.Empty : (string)newPurchaseOrder.Properties["MasterNumber"],
                    OrderCreateDateTime = newPurchaseOrder.Properties["DateCreated"].ToString().ToDateTime().Value,
                    OrderSendDateTime   = DateTime.Now.ToLongDateFormatWithTime(),
                    UserId              = orderingUserEmail.ToUpper(),
                    OrderFilled         = false,
                    FutureOrder         = false,
                    CatalogType         = catalogType
                },
                Details = new List <OrderDetail>()
            };

            foreach (var lineItem in ((CommerceServer.Foundation.CommerceRelationshipList)newPurchaseOrder.Properties["LineItems"]))
            {
                var item = (CS.LineItem)lineItem.Target;
                if ((orderType == OrderType.ChangeOrder && String.IsNullOrEmpty(item.Status)) ||
                    orderType == OrderType.DeleteOrder)    // do not include line items a) during a change order with no change or b) during a delete order
                {
                    continue;
                }

                OrderDetail detail = new OrderDetail()
                {
                    ItemNumber                 = item.ProductId,
                    OrderedQuantity            = (short)item.Quantity,
                    UnitOfMeasure              = ((bool)item.Each ? UnitOfMeasure.Package : UnitOfMeasure.Case),
                    SellPrice                  = (double)item.PlacedPrice,
                    Catchweight                = (bool)item.CatchWeight,
                    LineNumber                 = Convert.ToInt16(lineItem.Target.Properties["LinePosition"]),
                    SubOriginalItemNumber      = string.Empty,
                    ReplacedOriginalItemNumber = string.Empty,
                    Description                = item.DisplayName,
                    ManufacturerName           = item.Notes,
                    UnitCost = (decimal)item.ListPrice
                };

                if (orderType == OrderType.ChangeOrder)
                {
                    switch (item.Status)
                    {
                    case "added":
                        detail.ItemChange = LineType.Add;
                        break;

                    case "changed":
                        detail.ItemChange = LineType.Change;
                        break;

                    case "deleted":
                        detail.ItemChange = LineType.Delete;
                        break;

                    default:
                        detail.ItemChange = LineType.NoChange;
                        break;
                    }
                }

                newOrderFile.Details.Add(detail);
            }

            _log.WriteInformationLog(string.Format("Writing order to queue: {0}", JsonConvert.SerializeObject(newOrderFile)));

            _orderQueue.PublishToQueue(JsonConvert.SerializeObject(newOrderFile), Configuration.RabbitMQOrderServer, Configuration.RabbitMQUserNamePublisher, Configuration.RabbitMQUserPasswordPublisher, Configuration.RabbitMQVHostOrder, GetSelectedExchange(OrderQueueLocation.Normal));

            //set order status ID to 5
        }