Ejemplo n.º 1
0
        public Order GetOrder(string orderId, OpenBizContext ctx = null)
        {
            if (ctx == null)
            {
                ctx = new OpenBizContext();
            }

            Order order = ctx.Order.Include("OrderLines.OrderLineOptions.ProductOption")
                          .Include("OrderLines.OrderLineOptions.ProductOptionValueObject")
                          .Include("OrderLines.ResourcePlannings")
                          .Include("OrderLines.Product")
                          .Include("OrderTaxes").FirstOrDefault(o => o.Id == orderId);

            // .Include("OrderLines.ResourcePlannings")

            if (order != null)
            {
                ctx.Entry(order).Collection(o => o.Payments).Load();
                ctx.Entry(order).Collection(o => o.Appointments).Load();
                ctx.Entry(order).Reference("Party").Load();

                if (order.Appointments != null)
                {
                    foreach (var app in order.Appointments)
                    {
                        ctx.Entry(app).Collection(a => a.ResourcePlannings).Load();
                    }
                }
            }
            return(order);
        }
Ejemplo n.º 2
0
        public OrderParser(string organisationName, string accountLoginName = null, string partyName = null)
        {
            _Ctx = new OpenBizContext();

            Organisation = _Ctx.Organisation.FirstOrDefault(o => o.UniqueName == organisationName);

            Catalogs = _Ctx.Catalog.Where(c => c.OrganisationId == this.Organisation.Id).ToList();

            if (!string.IsNullOrWhiteSpace(accountLoginName))
            {
                Account = _Ctx.Account.FirstOrDefault(a => a.LoginName == accountLoginName);
            }

            if (Account == null)
            {
                Account = _Ctx.Account.FirstOrDefault();
            }

            if (!string.IsNullOrWhiteSpace(partyName))
            {
                Party = _Ctx.Party.FirstOrDefault(a => a.Name == partyName);
            }

            if (Party == null)
            {
                Party = _Ctx.Party.FirstOrDefault();
            }

            /*
             * _Account = ctx.Account.FirstOrDefault();
             * else
             * _Account = ctx.Account.FirstOrDefault(a => a.LoginName == _AccountLoginName);
             */
        }
Ejemplo n.º 3
0
        public OrderPricingContext(Order order, OpenBizContext ctx = null)
        {
            if (ctx == null)
            {
                ctx = new OpenBizContext();
            }

            _Ctx = ctx;

            Init(order);
        }
Ejemplo n.º 4
0
        /*
         * var regExpString = '\\b' + word + '\\b(?!\')';
         * formula = formula.replace(new RegExp(regExpString, 'g'), 'values.' + word);
         */
        public string PrepareFormula(string formula, string orgId, string productId, OpenBizContext ctx)
        {
            formula = formula.Replace("\r\n", " ");

            SysLinkTypeSvc _linkTypeSvc            = new SysLinkTypeSvc();
            string         productOptionLinkTypeId = _linkTypeSvc.ProductOptionLinkTypeId;

            SysLinkSvc <Product, ProductOption> productOptionLinks = new SysLinkSvc <Product, ProductOption>(orgId, productOptionLinkTypeId, productId);

            List <ProductOption> productOptions = productOptionLinks.Type2Objects;

            foreach (var prodOption in productOptions)
            {
                var regExp = new Regex("\\b" + prodOption.Code + "\\b");

                formula = regExp.Replace(formula, GuidToVar(prodOption.Id));
                // formula = formula.Replace(prodOption.Code, GuidToVar(prodOption.Id));
            }

            IEnumerable <string> prodOptionIdsWithValues = productOptions.Where(po => po.HasValueObjects).Select(po => po.Id);

            if (prodOptionIdsWithValues != null && prodOptionIdsWithValues.Count() > 0)
            {
                IEnumerable <ProductOptionValue> values = ctx.ProductOptionValue.Where(pov => prodOptionIdsWithValues.Contains(pov.ProductOptionId));

                if (values != null)
                {
                    foreach (ProductOptionValue value in values)
                    {
                        var regExp = new Regex("\\b" + value.Code + "\\b");

                        formula = regExp.Replace(formula, GuidToVar(value.Id));
                    }
                }


                //foreach (var )
            }
            return(formula);
        }
Ejemplo n.º 5
0
        public LogItems GetLogItems(Order order, string title = "")
        {
            LogItems items = new LogItems();

            items.Info("Log order: " + title);

            OpenBizContext ctx = new OpenBizContext();

            if (order == null)
            {
                items.Warn("Order is null!");
                return(items);
            }

            if (order.OrderLines == null || order.OrderLines.Count() == 0)
            {
                items.Warn("Order has no orderlines!");
                return(items);
            }

            int nrOfOrderLines = 0;

            if (order.OrderLines != null)
            {
                nrOfOrderLines = order.OrderLines.Count();
            }

            string orderDate = "";

            if (order.Date.HasValue)
            {
                orderDate = string.Format("date: {0} (ToUt={1} TimeZoneInfoUtc={2})", order.Date, order.Date.Value.ToUniversalTime(), TimeZoneInfo.ConvertTimeToUtc(order.Date.Value));
            }

            items.Info("Log order (order lines: {0}, isAppointment:{1}, A={2},D={3}) {4}", nrOfOrderLines, order.IsAppointment, order.IsActive, order.IsDeleted, orderDate);

            List <string> allProductIds;

            //  List<string> allOrderLineIds;

            //  allOrderLineIds = order.OrderLines.Select(ol => ol.Id).Distinct().ToList();
            allProductIds = order.OrderLines.Select(ol => ol.ProductId).Distinct().ToList();

            var allSubscriptions = ctx.Subscription.Where(s => s.PurchaseOrderId == order.Id);

            var allProducts = ctx.Product.Where(p => allProductIds.Contains(p.Id));

            List <string> allProductOptionIds = new List <string>();

            foreach (OrderLine orderLine in order.OrderLines)
            {
                if (orderLine.OrderLineOptions != null)
                {
                    allProductOptionIds.AddRange(orderLine.OrderLineOptions.Select(olo => olo.ProductOptionId));
                }
            }

            if (order.Appointments != null && order.Appointments.Count() > 0)
            {
                foreach (var app in order.Appointments)
                {
                    items.Info(" -> App: {0} {1}", app.Start, app.End);
                }
            }

            List <ProductOption>      allProductOptions      = new List <ProductOption>();
            List <ProductOptionValue> allProductOptionValues = new List <ProductOptionValue>();

            if (allProductOptionIds.Count > 0)
            {
                allProductOptions      = ctx.ProductOption.Where(po => allProductOptionIds.Contains(po.Id)).ToList();
                allProductOptionValues = ctx.ProductOptionValue.Where(pov => allProductOptionIds.Contains(pov.ProductOptionId)).ToList();
            }

            foreach (OrderLine orderLine in order.OrderLines)
            {
                Product product = null;

                string productName = "?";

                if (orderLine.Product != null)
                {
                    product     = orderLine.Product;
                    productName = product.Name;
                }
                else
                {
                    product = allProducts.FirstOrDefault(p => p.Id == orderLine.ProductId);

                    if (product != null)
                    {
                        productName = product.Name;
                    }
                }

                string optionString = "";

                if (orderLine.OrderLineOptions != null && orderLine.OrderLineOptions.Count() > 0)
                {
                    List <string> optionStrings = new List <string>();

                    foreach (OrderLineOption option in orderLine.OrderLineOptions)
                    {
                        ProductOption prodOpt = allProductOptions.FirstOrDefault(po => po.Id == option.ProductOptionId);

                        var optionName  = "unknown";
                        var optionValue = "";

                        if (prodOpt != null)
                        {
                            optionName = prodOpt.Name;

                            if (prodOpt.HasValueObjects)
                            {
                                var prodOptValue = allProductOptionValues.FirstOrDefault(v => v.Id == option.ProductOptionValueId);

                                if (prodOptValue != null)
                                {
                                    optionValue = prodOptValue.Name;
                                }
                            }
                            else
                            {
                                optionValue = option.ProductOptionValue.ToString();
                            }
                        }

                        string opt = string.Format("{0}={1}", optionName, optionValue);
                        optionStrings.Add(opt);

                        //_Logger.Info("Option id: {0}, value:{1} {2}", option.Id, option.ProductOptionValueId, option.ProductOptionValue);
                    }


                    string sep = "";

                    foreach (string str in optionStrings)
                    {
                        optionString += sep + str;
                        sep           = "&";
                    }
                }
                string orderLineLog = string.Format("    {0} x {1}?{2}", orderLine.Quantity, productName, optionString);
                items.Info(orderLineLog);


                if (orderLine.ResourcePlannings != null && orderLine.ResourcePlannings.Count > 0)
                {
                    foreach (var resourcePlanning in orderLine.ResourcePlannings)
                    {
                        items.Info("    -> resourcePlanning {0:dd/MM HH:mm} (UTC={3:HH:mm}) - {1:dd/MM HH:mm}  ({2})", resourcePlanning.Start, resourcePlanning.End, resourcePlanning.ResourceId, resourcePlanning.Start.ToUniversalTime());
                    }
                }
                else
                {
                    items.Info("    -> no resourcePlanning records!");
                }
            }

            if (allSubscriptions != null && allSubscriptions.Count() > 0)
            {
                items.Info("Subscriptions");
                items.Info("=============");
                foreach (Subscription sub in allSubscriptions)
                {
                    items.Info("  Subscription '{0}': {1}/{2}  (€ {3}/{4})  (A:{5},D:{6})", sub.Name, sub.UsedQuantity, sub.TotalQuantity, sub.TotalPayed, sub.TotalPrice, sub.IsActive, sub.IsDeleted);
                }
            }


            return(items);
        }
Ejemplo n.º 6
0
 public OrderSearchSvc(OpenBizContext ctx) : base(ctx)
 {
 }