Exemplo n.º 1
0
 public ComplemarOrderHelper(Order order, MasterOrder masterOrder, ShipAddress shipAddress)
 {
     _order = order;
     _masterOrder = masterOrder;
     _orderItems = order.OrderLineItems.ToList();
     _shipAddress = shipAddress;
 }
Exemplo n.º 2
0
 public ItxOrderHelper(Order order, ShipAddress shipAddress)
 {
     _order = order;
     _orderItems = order.OrderLineItems.ToList();
     _shipAddress = shipAddress;
     _itxOrder = new ItxOrder();
     _itxFriendlyItems = GetComplemarFriendlyItems();
     UnsentItems = new List<OrderLineItem>();
 }
Exemplo n.º 3
0
 public ItxOrderHelper(Order order, ShipAddress shipAddress, int equipmentCatalog, string wtn = null)
 {
     _order = order;
     _orderItems = order.OrderLineItems.ToList();
     _shipAddress = shipAddress;
     _itxOrder = new ItxOrder();
     _itxFriendlyItems = GetComplemarFriendlyItems();
     _equipmentCatalog = equipmentCatalog;
     _wtn = wtn;
     UnsentItems = new List<OrderLineItem>();
 }
Exemplo n.º 4
0
        /* ******************************* Order Request *********************************
         * Required Fields:
         *
         * Items        -	List of items to order      -	ArrayOfOrderRequestItems   -    N/A
         * JobNumber    -	Customer contract number    -  	int
         * OrderedBy    -	Person placing order        -	OrderedByRequest
         * ShipTo	    -   Person receiving order      -	ShipToRequest
         *
         * *******************************************************************************/
        public OrderRequest EmitOrderRequest(Order order, MasterOrder masterOrder, List<OrderLineItem> orderItems, ShipAddress shipAddress, string uniqueId = null)
        {
            var orderRequest = new OrderRequest();
            var itemArray = new OrderRequestItem[orderItems.Count];
            // add item request for each item
            for (var i = 0; i < orderItems.Count; i++)
            {
                itemArray[i] = EmitOrderRequestItem(orderItems[i]);
            }
            orderRequest.Items = itemArray;

            orderRequest.OrderName = masterOrder.MasterOrderId.ToString(CultureInfo.InvariantCulture);
            orderRequest.JobNumber = 52000;
            orderRequest.OrderedBy = EmitOrderedByRequest(shipAddress);
            orderRequest.ShipTo = new[] { EmitShipToRequest(shipAddress) };
            orderRequest.Comment = "TEST ORDER: DO NOT SHIP";
            orderRequest.Transaction = 0; //*int.Parse(*/masterOrder.MasterOrderId;//.ToString() + masterOrder.CreateDateTime.Hour.ToString() + masterOrder.CreateDateTime.Minute.ToString()
            orderRequest.OrderPrefix = "FI";

            orderRequest.CreatedBy = uniqueId;

            orderRequest.TType = TransactionTypes.StandardOrder;

            #region Additional Fields

            orderRequest.REC_NUM = 0;
            //+ masterOrder.CreateDateTime.Second.ToString());
            orderRequest.Sequence = 0;
            //orderRequest.METHOD = 0;
            //orderRequest.WarehouseID = 0;
            orderRequest.OrderOrigination = OrderSources.Web;
            //orderRequest.Status = OrderStatuses.Open;
            //orderRequest.OrderApprovalStatus = ApprovalStatus.Approved;
            //orderRequest.CreatedDate = DateTime.Now;
            //orderRequest.CustReference = string.Empty;
            //orderRequest.CustomerNumber = string.Empty;
            // orderRequest.CustomerOrderType = string.Empty;
            //orderRequest.LastModDate = DateTime.Now;
            // orderRequest.LastUpdatedBy = string.Empty;
            //orderRequest.DiscountCode = 'a';
            // orderRequest.UsageCode = 'a';
            orderRequest.CustomerID = shipAddress.SubscriberId;
            #endregion

            System.Diagnostics.Debug.WriteLine(orderRequest.ToString());
            return orderRequest;
        }
Exemplo n.º 5
0
        /* ************************** Contact Request *********************************
         * Required fields:
         *
         * LastName OR CompanyName  - Name of the person           - string(18)
         * Addresses                - Addresses of the person      - AddressRequest
         * Phones                   - Phone numbers for person     - PhoneRequest
         *
         * ****************************************************************************/
        private ShipToRequest EmitShipToRequest(ShipAddress shipAddress)
        {
            var shipToRequest = new ShipToRequest
                {
                    JobNumber = 52000,
                    MidInitial = 'x',
                    Email = !string.IsNullOrEmpty(shipAddress.Email) ? "*****@*****.**" : shipAddress.Email,
                    EmailPreference = EmailTypes.HTML,
                    LastName = shipAddress.Name,
                    Identifier = shipAddress.SubscriberId,
                    Addresses = new[] { EmitAddressRequest(shipAddress) },
                    Phones = new[] { EmitPhoneNumberRequest(shipAddress) }
                };

            #region Additional Fields

            //shipToRequest.GuidID = new Guid();
            //shipToRequest.UserID = new Guid();
            //shipToRequest.LastModDate = DateTime.Now;
            //shipToRequest.Owner = new Guid();
            //shipToRequest.Creator = new Guid();

            #endregion

            System.Diagnostics.Debug.WriteLine(shipAddress.ToString());
            return shipToRequest;
        }
Exemplo n.º 6
0
 /* **************************** Phone Number Request *****************************
  * Required Fields:
  *
  * Number   -   Phone Number    -	string  -   16
  *
  * *******************************************************************************/
 private PhoneNumberRequest EmitPhoneNumberRequest(ShipAddress shipAddress)
 {
     PhoneNumberRequest phoneNumberRequest = new PhoneNumberRequest();
     phoneNumberRequest.Name = "Home";
     phoneNumberRequest.Number = !string.IsNullOrEmpty(shipAddress.Cbr) ? shipAddress.Cbr : "0000000000";
     System.Diagnostics.Debug.WriteLine(phoneNumberRequest.ToString());
     return phoneNumberRequest;
 }
Exemplo n.º 7
0
        /* ************************** Ship To Request *********************************
         * Required fields:
         *
         * LastName OR CompanyName  - Name of the receiving party   - string(18)
         * Addresses                - Addresses of the person       - AddressRequest
         * Phones                   - Phone numbers for person      - PhoneRequest
         *
         * ****************************************************************************/
        private OrderedByRequest EmitOrderedByRequest(ShipAddress shipAddress)
        {
            #region Additional Fields

            var orderedByRequest = new OrderedByRequest
                {
                    JobNumber = 52000,
                    MidInitial = 'x',
                    LastModDate = DateTime.Now,
                    Email = !string.IsNullOrEmpty(shipAddress.Email) ? "*****@*****.**" : shipAddress.Email,
                    EmailPreference = EmailTypes.HTML,
                    LastName = shipAddress.Name,
                    Addresses = new[] { EmitAddressRequest(shipAddress) },
                    Phones = new[] { EmitPhoneNumberRequest(shipAddress) }
                };

            //orderedByRequest.GuidID = new Guid();
            //orderedByRequest.UserID = new Guid();
            //orderedByRequest.Owner = new Guid();
            //orderedByRequest.Creator = new Guid();

            #endregion

            System.Diagnostics.Debug.WriteLine(orderedByRequest.ToString());
            return orderedByRequest;
        }
Exemplo n.º 8
0
 /* ******************************* Address Request *******************************
  * Required Fields:
  *
  * StreetAddress1	-	string	30
  * City	            -	string	14
  * State	        -	string	2
  * ZipCode	        - 	string	10
  * Country	        -	string	14
  *
  * *******************************************************************************/
 private AddressRequest EmitAddressRequest(ShipAddress shipAddress)
 {
     var addressRequest = new AddressRequest
         {
             StreetAddress1 = shipAddress.Address1,
             StreetAddress2 = shipAddress.Address2 != "" ? "" : shipAddress.Address2,
             City = shipAddress.City,
             State = shipAddress.State,
             ZipCode = shipAddress.Zip.ToString(CultureInfo.InvariantCulture),
             Country = "USA"
         };
     System.Diagnostics.Debug.WriteLine(addressRequest.ToString());
     return addressRequest;
 }
Exemplo n.º 9
0
        private Order GenerateOrder(OrderTypeEnum orderType, ShipAddress shipAddress, List<OrderLineItem> items, int fulfillmentLocation)
        {
            var order = new Order();
            OrderType foundType;

            // Add collateral to order (disconnect letter / exchange letter)
            switch (orderType)
            {
                case OrderTypeEnum.Dropship:
                    items.AddRange(AddCollateral(items));
                    order.FillLocId = Dropship.DropshipHelper.GetShippingVendorId();
                    order.ShipAddress1 = shipAddress;
                    foundType = DBCache.OrderTypes.FirstOrDefault(c => c.OrderTypeName.ToLower() == "fios_drop");
                    if (foundType != null)
                    {
                        order.OrderTypeId = foundType.OrderTypeId;
                    }
                    ReturnMailerConversion(items);
                    break;

                case OrderTypeEnum.Field:
                    order.FillLocId = fulfillmentLocation;
                    foundType = DBCache.OrderTypes.FirstOrDefault(c => c.OrderTypeName.ToLower() == "fios_field");
                    if (foundType != null)
                        order.OrderTypeId = foundType.OrderTypeId;
                    break;
            }

            foreach (var item in items)
            {
                order.OrderLineItems.Add(item);
            }

            var orderStatus = DBCache.OrderStatuses.FirstOrDefault(c => c.OrderStatusName.ToLower() == "ordered");
            if (orderStatus != null)
                order.Status = orderStatus.OrderStatusId;
            return order;
        }
Exemplo n.º 10
0
        public string PlaceFieldOrder(
            OrderTypeEnum orderType,
            List<OrderLineItem> orderLineItems,
            int fulfillmentLocation,
            int entityId,
            ShipAddress shipAddress,
            string commentText,
            string userId,
            int receivingId = 0)
        {
            var failureString = string.Empty;
            var masterOrder = GenerateMasterOrder(orderType, commentText, entityId, receivingId);
            int owningLocId;
            string userEmail;
            // establish entity objects
            var primaryOrder = GenerateOrder(orderType, shipAddress, orderLineItems, fulfillmentLocation);
            masterOrder.Orders.Add(primaryOrder);
            ApplyBusinessRulesToOrder(masterOrder, fulfillmentLocation);

            // Add required objects to the database
            using (var db = DBContextFactory.CreateContext())
            {
                var userEntity = db.Entities.First(e => e.EntityId == entityId);
                owningLocId = db.Locations.First(l => l.LocId == userEntity.LocId).OwningLocId;
                userEmail = userEntity.Email;

                db.MasterOrders.AddObject(masterOrder);

                try
                {
                    db.SaveChanges(); // save order to the db
                }
                catch (SqlException)
                {
                    throw new Exception("Error creating new order: database");
                }
                catch (Exception ex)
                {
                    throw new Exception("Error creating new order.", ex);
                }

            } // close context
            if (primaryOrder.ShipAddress == null) // order is not a dropship order
            {
                var mail = new JP.Util.MailHelper(); // create and send email to designated recipients at location
                //get the orderobject based on the orderid
                using (var db = DBContextFactory.CreateContext())
                {
                    primaryOrder = (from c in db.Orders
                             .Include("Location")
                                    where c.OrderId == primaryOrder.OrderId
                                    select c).First();
                }

                var okToSend = mail.CreateOrderNotification(primaryOrder, owningLocId, userEmail); // get recipients list order number, order items, etc, and format into email.
                if (okToSend)
                    mail.Send();
            }

            return String.IsNullOrEmpty(failureString) ? masterOrder.MasterOrderId.ToString(CultureInfo.InvariantCulture) : failureString;
        }
Exemplo n.º 11
0
        public string PlaceDropshipOrder(
            OrderTypeEnum orderType,
            List<OrderLineItem> orderLineItems,
            int fulfillmentLocation,
            int entityId,
            ShipAddress shipAddress,
            string commentText,
            string userId,
            int equipmentCatalog,
            int receivingId = 0,
            string wtn = null)
        {
            var failureString = string.Empty;
            var masterOrder = GenerateMasterOrder(orderType, commentText, entityId, receivingId);

            // establish entity objects
            var primaryOrder = GenerateOrder(orderType, shipAddress, orderLineItems, fulfillmentLocation);
            masterOrder.Orders.Add(primaryOrder);
            ApplyBusinessRulesToOrder(masterOrder, fulfillmentLocation);

            // Add required objects to the database
            using (var db = DBContextFactory.CreateContext())
            {
                db.MasterOrders.AddObject(masterOrder);

                try
                {
                    db.SaveChanges(); // save order to the db
                }
                catch (SqlException)
                {
                    throw new Exception("Error creating new order: database");
                }
                catch (Exception ex)
                {
                    throw new Exception("Error creating new order.", ex);
                }

                var exceptionMessage = "Error when trying to save the DropShip order, please see inner exception for more details";
                try
                {
                    foreach (var order in masterOrder.Orders)
                    {
                        // if order is a dropship get this data to our shipping vendor du jour
                        if (orderType == OrderTypeEnum.Dropship)
                        {

                            // if we are using live Complemar interface, uncomment the code block you wish to use for submitting code to Complemar:

                            // Asynchronous code ******************************************
                            /**/
                            var uniqueId = userId;

                            //BackgroundWorker worker = new BackgroundWorker();
                            //worker.DoWork += new DoWorkEventHandler((sender, e) =>
                            //{
                            //    SIMPL.BLL.Dropship.ComplemarOrderHelper complemarHelper = new BLL.Dropship.ComplemarOrderHelper(primaryOrder, masterOrder, orderLineItems, shipAddress);
                            //    complemarHelper.SubmitOrder(uniqueId);
                            //});
                            //worker.RunWorkerAsync();

                            // Synchronous code *******************************************
                            var complemarHelper = new Dropship.ComplemarOrderHelper(order, masterOrder, shipAddress);
                            complemarHelper.SubmitOrder(uniqueId);

                            /**/

                            // save itx-formatted order to db

                            var itxHelper = new Dropship.ItxOrderHelper(order, shipAddress, equipmentCatalog, wtn);
                            itxHelper.SubmitOrder();

                            // verify all items were submitted to complemar
                            if (itxHelper.UnsentItems.Count > 1)
                            {
                                var unsentItemString = itxHelper.UnsentItems.Aggregate(string.Empty, (current, item) =>
                                                       current + string.Format("{0} was not sent.<br />",
                                                       DBCache.EquipmentTypes.First(e => e.EquipmentTypeId == item.EquipTypeId).EquipName));
                                failureString += "<br />" + unsentItemString;
                            }
                        }
                    }
                }
                catch (SqlException inner)
                {
                    if (_errorLoggingService != null)
                    {
                        var myException = new Exception(exceptionMessage, inner);
                        if (_errorLoggingService != null)
                        {
                            _errorLoggingService.LogErrorNoContext(myException);
                        }
                    }
                    failureString += "The order was placed but fell out during importing. Please check Order History page to verify order was placed.<br />";
                }
                catch (Exception inner)
                {
                    if (_errorLoggingService != null)
                    {
                        var myException = new Exception(exceptionMessage, inner);
                        if (_errorLoggingService != null)
                        {
                            _errorLoggingService.LogErrorNoContext(myException);
                        }
                    }
                    failureString += "The order was placed but fell out during importing. Please check Order History page to verify order was placed.<br />";
                }

            } // close context

            return String.IsNullOrEmpty(failureString) ? masterOrder.MasterOrderId.ToString(CultureInfo.InvariantCulture) : failureString;
        }
Exemplo n.º 12
0
 /// <summary>
 /// Deprecated Method for adding a new object to the ShipAddresses EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToShipAddresses(ShipAddress shipAddress)
 {
     base.AddObject("ShipAddresses", shipAddress);
 }
Exemplo n.º 13
0
 /// <summary>
 /// Create a new ShipAddress object.
 /// </summary>
 /// <param name="shipAddressId">Initial value of the ShipAddressId property.</param>
 /// <param name="name">Initial value of the Name property.</param>
 /// <param name="address1">Initial value of the Address1 property.</param>
 /// <param name="city">Initial value of the City property.</param>
 /// <param name="state">Initial value of the State property.</param>
 /// <param name="zip">Initial value of the Zip property.</param>
 public static ShipAddress CreateShipAddress(global::System.Int32 shipAddressId, global::System.String name, global::System.String address1, global::System.String city, global::System.String state, global::System.String zip)
 {
     ShipAddress shipAddress = new ShipAddress();
     shipAddress.ShipAddressId = shipAddressId;
     shipAddress.Name = name;
     shipAddress.Address1 = address1;
     shipAddress.City = city;
     shipAddress.State = state;
     shipAddress.Zip = zip;
     return shipAddress;
 }