Example #1
0
        /// <summary>
        /// Adds the line.
        /// </summary>
        /// <param name="line">The line.</param>
        public void AddLine(IOrderLine <IProduct> line)
        {
            ErrorBase.CheckArgIsNull(line, nameof(line),
                                     nameof(line).GetArgumentNullErrorMessage(nameof(AddLine)));

            //Hp --> Note: Here interface IOrderLine is covariant of type IProduct.
            //Which means user is allowed to add any concreate class object which impelements IProduct.
            lines.Add(line);
        }
Example #2
0
        /// <summary>
        /// Removes the line.
        /// </summary>
        /// <param name="line">The line.</param>
        public void RemoveLine(IOrderLine <IProduct> line)
        {
            ErrorBase.CheckArgIsNull(line, nameof(line),
                                     nameof(line).GetArgumentNullErrorMessage(nameof(RemoveLine)));

            var comparer = Utility.GetEqualityComparer <IOrderLine <IProduct> >();

            if (lines.Contains(line, comparer))
            {
                lines.RemoveAll(L => L.Id == line.Id);
            }
        }
Example #3
0
        /// <summary>
        /// Sells the item.
        /// </summary>
        /// <param name="orderLine">Order line.</param>
        void SellItem(IOrderLine orderLine)
        {
            var count = orderLine.Count;

            // decrease items count
            orderLine.Item.Count -= count;

            // remove item from inventory if zero count
            if (DeleteIfEmpty && (orderLine.Item.Count == 0))
            {
                Inventory.Remove(orderLine.Item);
            }
        }
        public static void CalculateLog(StringBuilder log, IOrderLine srcLine, OrderLine destLine = null)
        {
            var prefix = "      ";
            var reason = "";

            if (destLine == null)
            {
                reason = "предложение отсутствует";
            }
            else if (srcLine.Cost != destLine.Cost && srcLine.Count != destLine.Count)
            {
                reason = "имеются различия с прайс-листом в цене и количестве заказанного препарата";
            }
            else if (srcLine.Count != destLine.Count && destLine.Count < srcLine.Count)
            {
                reason = "доступное количество препарата в прайс-листе меньше заказанного ранее";
            }
            else if (srcLine.Count != destLine.Count)
            {
                reason = "позиция была объединена";
            }
            else if (srcLine.Cost != destLine.Cost)
            {
                reason = "имеется различие в цене препарата";
            }

            if (String.IsNullOrEmpty(reason))
            {
                return;
            }

            log.Append(prefix);
            if (destLine == null)
            {
                log.AppendLine(
                    $"{srcLine.ProductSynonym} - {srcLine.ProducerSynonym} : {reason} (старая цена: {srcLine.Cost};" +
                    $" старый заказ: {srcLine.Count})");
            }
            else
            {
                log.AppendLine(
                    $"{srcLine.ProductSynonym} - {srcLine.ProducerSynonym} : {reason} (старая цена: {srcLine.Cost};" +
                    $" старый заказ: {srcLine.Count}; новая цена: {destLine.Cost}; новый заказ: {destLine.Count})");
            }
        }
Example #5
0
        /// <summary>
        /// Buy the item.
        /// </summary>
        /// <param name="orderLine">Order line.</param>
        void BuyItem(IOrderLine orderLine)
        {
            // find item in inventory
            var item = Inventory.Find(x => x.Name == orderLine.Item.Name);

            var count = orderLine.Count;

            // if not found add new item to inventory
            if (item == null)
            {
                Inventory.Add(new Item(orderLine.Item.Name, count));
            }
            // if found increase count
            else
            {
                item.Count += count;
            }
        }
 private bool ShouldCalculateStatus(IOrderLine orderline)
 {
     return(orderline is OrderLine && Restore);
 }
Example #7
0
 public static TimeSpan?FindBookingDuration(this IOrderLine orderLine)
 {
     return(orderLine.FindTimeSpanProperty(BookingOrderProperties.OrderLineBookingDuration));
 }
Example #8
0
		void BuyItem(IOrderLine orderLine)
		{
			// find item in inventory
			var item = Inventory.Find(x => x.Name==orderLine.Item.Name);

			var count = orderLine.Count;
			// if not found add new item to inventory
			if (item==null)
			{
				Inventory.Add(new Item(orderLine.Item.Name, count));
			}
			// if found increase count if items count not infinite
			else
			{
				item.Count += count;
			}
		}
Example #9
0
		void SellItem(IOrderLine orderLine)
		{
			var count = orderLine.Count;

			// decrease items count
			orderLine.Item.Count -= count;

			// remove item from inventory if zero count
			if (DeleteIfEmpty && (orderLine.Item.Count==0))
			{
				Inventory.Remove(orderLine.Item);
			}
		}
Example #10
0
 public void AddOrderLine(IOrderLine line)
 {
     OrderLines = line as IEnumerable<IOrderLine>;
 }
Example #11
0
 public static Guid GetBookingPeriodId(this IOrderLine orderLine)
 {
     return(Check.NotNull(FindBookingPeriodId(orderLine),
                          BookingOrderProperties.OrderLineBookingPeriodId) !.Value);
 }
        public void Merge(Order order, IOrder sourceOrder, IOrderLine sourceLine, Offer[] offers, StringBuilder log)
        {
            var action = GuesAction(sourceOrder);
            var rest   = sourceLine.Count;

            foreach (var offer in offers)
            {
                if (rest == 0)
                {
                    break;
                }

                uint ordered;
                var  oldDisplayId = sourceOrder.DisplayId;
                if (oldDisplayId == 0)
                {
                    oldDisplayId = sourceOrder.Id;
                }
                var line = order.TryOrder(offer, rest, out ordered);
                if (line != null)
                {
                    if (action == "восстановить")
                    {
                        line.Order.KeepId = oldDisplayId;
                    }
                    if (ShouldCalculateStatus(line))
                    {
                        if (sourceLine.Count == ordered)
                        {
                            line.ExportId          = ((OrderLine)sourceLine).ExportId;
                            line.ExportBatchLineId = ((OrderLine)sourceLine).ExportBatchLineId;
                        }
                        if (line.Cost != sourceLine.Cost)
                        {
                            line.SendResult |= LineResultStatus.CostChanged;
                            line.NewCost     = line.Cost;
                            line.OldCost     = sourceLine.Cost;
                            line.HumanizeSendError();
                        }
                    }
                    rest = rest - ordered;
                }
            }

            if (sourceOrder is Order)
            {
                var srcLine = (OrderLine)sourceLine;
                if (rest == 0)
                {
                    ((Order)sourceOrder).RemoveLine(srcLine);
                }
                else
                {
                    srcLine.Count = rest;
                }
            }

            if (rest > 0)
            {
                if (rest == sourceLine.Count)
                {
                    if (ShouldCalculateStatus(sourceLine))
                    {
                        ((OrderLine)sourceLine).SendResult = LineResultStatus.NoOffers;
                        ((OrderLine)sourceLine).HumanizeSendError();
                    }
                    log.AppendLine(
                        $"{order.Price.Name} : {sourceLine.ProductSynonym} - {sourceLine.ProducerSynonym} ; Предложений не найдено");
                }
                else
                {
                    if (ShouldCalculateStatus(sourceLine))
                    {
                        ((OrderLine)sourceLine).SendResult = LineResultStatus.CountReduced;
                        ((OrderLine)sourceLine).HumanizeSendError();
                    }
                    log.AppendLine(
                        $"{sourceOrder.Price.Name} : {sourceLine.ProductSynonym} - {sourceLine.ProducerSynonym}" +
                        $" ; Уменьшено заказное количество {sourceLine.Count - rest} вместо {sourceLine.Count}");
                }
            }
        }
Example #13
0
 public static TimeSpan GetBookingDuration(this IOrderLine orderLine)
 {
     return(Check.NotNull(FindBookingDuration(orderLine),
                          BookingOrderProperties.OrderLineBookingDuration) !.Value);
 }
Example #14
0
 public static int?FindBookingVolume(this IOrderLine orderLine)
 {
     return(orderLine.Quantity);
 }
Example #15
0
 public static TimeSpan?FindBookingStartingTime(this IOrderLine orderLine)
 {
     return(orderLine.FindTimeSpanProperty(BookingOrderProperties.OrderLineBookingStartingTime));
 }
Example #16
0
 public static DateTime GetBookingDate(this IOrderLine orderLine)
 {
     return(Check.NotNull(FindBookingDate(orderLine),
                          BookingOrderProperties.OrderLineBookingDate) !.Value);
 }
Example #17
0
 public static DateTime?FindBookingDate(this IOrderLine orderLine)
 {
     return(orderLine.FindDateTimeProperty(BookingOrderProperties.OrderLineBookingDate));
 }
Example #18
0
 public static int GetBookingVolume(this IOrderLine orderLine)
 {
     return(Check.NotNull(FindBookingVolume(orderLine),
                          BookingOrderProperties.OrderLineBookingVolume) !.Value);
 }
Example #19
0
 public static Guid?FindBookingAssetId(this IOrderLine orderLine)
 {
     return(orderLine.GetProperty <Guid?>(BookingOrderProperties.OrderLineBookingAssetId));
 }
Example #20
0
 public static bool HasVariantWithId(this IOrderLine orderLine, int id)
 {
     return(orderLine.Product.Variants.Any(usedVariant => id == usedVariant.OriginalId));
 }