Beispiel #1
0
        public override void Apply(OrderLineVendor orderLineVendor, IUnitOfWork unit, int?score)
        {
            var avgPrice = (from m in orderLineVendor.OrderLine.Product.VendorAssortments
                            where orderLineVendor.VendorValues.Select(c => c.VendorID).Contains(m.VendorID)
                            select m).SelectMany(c => c.VendorPrices).Average(c => c.Price);

            foreach (var vendor in orderLineVendor.VendorValues)
            {
                decimal?vendorPrice = 0;
                int?    productID   = orderLineVendor.OrderLine.ProductID;

                if (productID.HasValue)
                {
                    var va = VendorUtility.GetMatchedVendorAssortment(unit.Scope.Repository <VendorAssortment>(), vendor.VendorID, productID.Value);

                    if (va != null)
                    {
                        vendorPrice = va.VendorPrices.FirstOrDefault().Try <VendorPrice, decimal?>(c => c.Price.Value, null);
                    }
                }

                if (vendorPrice != null)
                {
                    if (vendorPrice <= avgPrice)
                    {
                        vendor.Value += GetValue(unit, orderLineVendor.OrderLine.Order.ConnectorID, vendor.VendorID);
                        vendor.Score += score.HasValue ? score.Value : 0;
                    }
                }
            }
        }
Beispiel #2
0
        private void ParseBrandVendor()
        {
            BrandVendor bv = VendorUtility.MergeBrand(_unit.Scope.Repository <BrandVendor>(), _vendor, _record.Field <string>("Brand").Trim(), _brandVendorList);

            //submit changes
            this._brandID = bv.BrandID;
        }
Beispiel #3
0
        public string GetVendorItemNumber(Product product, string customItemNumber, int vendorID)
        {
            var assortmentRepository = _scope.Repository <VendorAssortment>();

            if (product != null)
            {
                var va = assortmentRepository.GetSingle(x => (x.VendorID == vendorID || (x.Vendor.ParentVendorID.HasValue && x.Vendor.ParentVendorID.Value == vendorID)) && x.ProductID == product.ProductID); //&& x.IsActive);

                if (va != null)
                {
                    return(va.CustomItemNumber);
                }

                va = VendorUtility.GetMatchedVendorAssortment(assortmentRepository, vendorID, product.ProductID);

                if (va != null)
                {
                    return(va.CustomItemNumber);
                }
            }

            return(customItemNumber);
        }
Beispiel #4
0
        public int DispatchOrders(Dictionary <Concentrator.Objects.Models.Orders.Order, List <OrderLine> > orderLines, Vendor vendor, IAuditLogAdapter log, IUnitOfWork unit)
        {
            try
            {
                var orderDoc = new XDocument(new XDeclaration("1.0", "UTF-8", "yes"),
                                             new XElement("SalesOrders",
                                                          from o in orderLines
                                                          select new XElement("SalesOrder",
                                                                              new XElement("CustomerCode", vendor.VendorSettings.GetValueByKey("VSNUser", string.Empty)),
                                                                              new XElement("Reference", o.Key.OrderID),
                                                                              new XElement("DeliveryDate", DateTime.Now.ToString("dd-MM-yyyy")),
                                                                              new XElement("DeliveryAddress",
                                                                                           new XElement("AddressName", o.Key.ShippedToCustomer.CustomerName),
                                                                                           new XElement("Street", o.Key.ShippedToCustomer.CustomerAddressLine1),
                                                                                           new XElement("HouseNumber", o.Key.ShippedToCustomer.HouseNumber),
                                                                                           new XElement("ZipCode", o.Key.ShippedToCustomer.PostCode.Length < 7 ? o.Key.ShippedToCustomer.PostCode.Substring(0, 4) + " " + o.Key.ShippedToCustomer.PostCode.Substring(4, 2).ToUpper() : o.Key.ShippedToCustomer.PostCode.ToUpper()),
                                                                                           new XElement("City", o.Key.ShippedToCustomer.City),
                                                                                           new XElement("CountryCode", o.Key.ShippedToCustomer.Country)),
                                                                              from ol in o.Value
                                                                              let vendorAss = VendorUtility.GetMatchedVendorAssortment(unit.Scope.Repository <VendorAssortment>(), vendor.VendorID, ol.ProductID.Value)
                                                                                              let purchaseLine = ol.OrderResponseLines.Where(x => x.OrderLineID == ol.OrderLineID && x.OrderResponse.ResponseType == OrderResponseTypes.PurchaseAcknowledgement.ToString()).FirstOrDefault()
                                                                                                                 select new XElement("SalesOrderLine",
                                                                                                                                     new XElement("ProductCode", vendorAss.CustomItemNumber),
                                                                                                                                     new XElement("Quantity", ol.GetDispatchQuantity()),
                                                                                                                                     new XElement("Reference", ol.OrderLineID + "/" + ol.Order.WebSiteOrderNumber)//(purchaseLine != null ? purchaseLine.VendorItemNumber : vendorAss.ProductID.ToString()))
                                                                                                                                     )
                                                                              )
                                                          )
                                             );

                var ftp = new FtpManager(vendor.VendorSettings.GetValueByKey("VSNFtpUrl", string.Empty), "orders/",
                                         vendor.VendorSettings.GetValueByKey("VSNUser", string.Empty),
                                         vendor.VendorSettings.GetValueByKey("VSNPassword", string.Empty), false, false, log);
                var fileName = String.Format("{0}.xml", DateTime.Now.ToString("yyyyMMddhhmmss"));

                using (var inStream = new MemoryStream())
                {
                    using (XmlWriter writer = XmlWriter.Create(inStream))
                    {
                        orderDoc.WriteTo(writer);
                        writer.Flush();
                    }
                    ftp.Upload(inStream, fileName);
                }

                LogOrder(orderDoc, vendor.VendorID, fileName, log);

                return(-1);
            }
            catch (Exception e)
            {
                throw new Exception("VSN dispatching failed", e);
            }
        }
        private void LoadVendorOrderRules()
        {
            var rules = unit.Scope.Repository <OrderRule>().GetAll().ToList();

            foreach (var line in orderLines)
            {
                try
                {
                    if (line.DispatchedToVendorID.HasValue)
                    {
                        if (!VendorOrderLines.ContainsKey(line.DispatchedToVendorID.Value))
                        {
                            VendorOrderLines.Add(line.DispatchedToVendorID.Value, new List <OrderLine>());
                        }

                        VendorOrderLines[line.DispatchedToVendorID.Value].Add(line);
                        continue;
                    }

                    if (line.Product == null || (line.Product.IsNonAssortmentItem.HasValue && line.Product.IsNonAssortmentItem.Value))
                    {
                        continue;
                    }

                    OrderLineVendor olv = new OrderLineVendor()
                    {
                        OrderLine    = line,
                        VendorValues = (from v in vendorIDs
                                        let va = VendorUtility.GetMatchedVendorAssortment(unit.Scope.Repository <VendorAssortment>(), v, line.ProductID.Value)
                                                 where va != null && va.VendorPrices.Any(y => y.Price.HasValue)
                                                 select new VendorRuleValue
                        {
                            Value = 0,
                            VendorID = v,
                            VendorassortmentID = va.VendorAssortmentID
                        }).ToList()
                    };

                    if (olv.VendorValues.Count < 1)
                    {
                        if (line.Order.Connector.AdministrativeVendorID.HasValue)
                        {
                            int administrativeVendorID = line.Order.Connector.AdministrativeVendorID.Value;


                            var administrativeVendors = (from v in unit.Scope.Repository <Vendor>().GetAllAsQueryable()
                                                         where (v.VendorID == administrativeVendorID || (v.ParentVendorID.HasValue && v.ParentVendorID.Value == administrativeVendorID)) &&
                                                         v.IsActive //&& v.OrderDispatcherType != null
                                                         select v).ToList();

                            administrativeVendors = administrativeVendors.Where(x => ((VendorType)x.VendorType).Has(VendorType.Assortment)).ToList();

                            olv = new OrderLineVendor()
                            {
                                OrderLine    = line,
                                VendorValues = (from v in administrativeVendors
                                                let va = VendorUtility.GetMatchedVendorAssortment(unit.Scope.Repository <VendorAssortment>(), v.VendorID, line.ProductID.Value, false)
                                                         where va != null &&
                                                         va.VendorPrices.Any(y => y.Price.HasValue)
                                                         select new VendorRuleValue
                                {
                                    Value = 0,
                                    VendorID = v.VendorID,
                                    VendorassortmentID = va.VendorAssortmentID
                                }).ToList()
                            };
                        }

                        if (olv.VendorValues.Count < 1)
                        {
                            line.Remarks = "No Vendor to process product, Line will be cancelled";

                            try
                            {
                                CancelLine(line, unit);
                                line.isDispatched = true;
                            }
                            catch (Exception)
                            {
                            }

                            log.DebugFormat("No Vendor to process product line {0}, line cancelled", line.OrderLineID);
                            continue;
                        }
                    }

                    foreach (var rule in OrderRules)
                    {
                        var dbRule = rules.Where(x => x.Name == rule.Name).FirstOrDefault();

                        if (dbRule != null)
                        {
                            rule.Apply(olv, unit, dbRule.Score);
                        }
                    }

                    var vendorValuesList = olv.VendorValues.Where(c => c.Value == olv.VendorValues.Max(v => v.Value));
                    var vendorID         = vendorValuesList.OrderByDescending(x => x.Score).FirstOrDefault().VendorID;



                    var connector = line.Order.Connector;

                    var preferredVendorOverride = connector.PreferredConnectorVendors.FirstOrDefault(c => c.isPreferred);
                    if (preferredVendorOverride != null)
                    {
                        vendorID = preferredVendorOverride.VendorID;
                    }

                    var preferredVendor = connector.PreferredConnectorVendors.Where(x => x.VendorID == vendorID).FirstOrDefault();

                    if (preferredVendor != null && preferredVendor.CentralDelivery)
                    {
                        line.isDispatched         = false;
                        line.DispatchedToVendorID = vendorID;
                        line.CentralDelivery      = true;
                        continue;
                    }

                    var parentVendor = vendors.FirstOrDefault(x => x.VendorID == vendorID && x.ParentVendorID.HasValue);

                    //TODO: check impact
                    //if (parentVendor != null)
                    //  vendorID = parentVendor.ParentVendorID.Value;

                    if (!VendorOrderLines.ContainsKey(vendorID))
                    {
                        VendorOrderLines.Add(vendorID, new List <OrderLine>());
                    }

                    VendorOrderLines[vendorID].Add(olv.OrderLine);
                }
                catch (Exception e)
                {
                    log.Debug("Error process orderlineID " + line.OrderLineID, e);
                }
            }
        }