Пример #1
0
        public OrderChargeModel Calculate(int clientSubscriptionId, OrderSubscription orderSubscription)
        {
            _orderCharge = new OrderChargeModel
            {
                CookerId = _subscriptionHelper.GetCookerServingPriceModel(clientSubscriptionId).CookerId
            };
            var taxPercent = _subscriptionHelper.GetTaxPercent(_subscriptionHelper.GetCookerServingPriceModel(clientSubscriptionId).CookerId);
            _orderCharge.OrderTypeValue = Enum.GetName(typeof(OrderModelType.Values), orderSubscription.OrderTypeId);
            _orderCharge.PaymentMethodValue = Enum.GetName(typeof(PaymentMethodType.Values), orderSubscription.PaymentMethodId);

            #region PickUpOrderCharge

            //if (orderSubscription.OrderTypeId == (int)OrderType.Values.PickUp)
            //{
            //   _orderCharge = PickUpCharge(orderSubscription, taxPercent);
            //}

            #endregion

            #region DeliveryOrderCharge

            //var cookerDelieryZonesId = (from c in _cookerDeliveryZones where c.CookerId == cookerId select c.DeliveryId).ToList();

            //decimal deliveryFees = 0;
            //foreach (var deliveryZoneId in cookerDelieryZonesId)
            //{
            //    //Custom KML Function to see if the item is in the zone
            //    //Moq for now
            //    var deliveryzone = _deliveryZones.FirstOrDefault(c => c.DeliveryId == deliveryZoneId);

            //    //KML integration to see if deliveryaddress is Zone
            //    if (_deliveryAddress.AddressTypeId == (int) AddressToDeliveryZone.Values.AddressInZone)
            //    {
            //        if (deliveryzone != null)
            //        {
            //            deliveryFees = deliveryzone.DeliveryFees;
            //        }
            //    }
            //}

            //_orderCharge = DeliveryCharge(order, deliveryFees, taxPercent);

            #endregion

            #region Neutral
            _orderCharge = Netural(orderSubscription, taxPercent);
            #endregion

            return _orderCharge;
        }
        //Plan
        //PlanId = 1,
        //ExternalId = "1",
        //Description = "3 Meals per week",
        //Title="Mike Weekly Plan"
        // Cooker Subscription
        // CookerSubscriptionId = 1,
        // CookerId = 1,
        // PlanId = 1,
        // ServingPriceId = 1
        //SubscriptionServingPrice
        // ServingPrice
        // {
        //     ServicePriceId = 1,
        //     ServingMeasurementId = 1,
        //     PLanId = 1,
        //     Price = (decimal)19.99,
        //     Quantity = 1
        // }
        public OrderSubscription FirstSubscriptionOrder()
        {
            var cookerServingPriceModel = new SubscriptionHelper().GetCookerServingPriceModel(ClientSubscriptionId);

            var firstSubscriptionOrder = new OrderSubscription
            {
                OrderSubscriptionId = 1,
                ClientId = 1,
                OrderDate = DateTime.Today.Date,
                DeliveryDate = null,
                OrderTypeId = (int)OrderType.Values.PickUp,
                PaymentMethodId = (int)PaymentMethodType.Values.CardOnLine,
                CouponId = null,
                PromotionId = null,
                PlanId = cookerServingPriceModel.PLanId,
                SubTotal = cookerServingPriceModel.Price,
                CurrencyId = (int)CurrencyType.Values.Usd,
                OrderStatusId = (int)OrderStatus.Values.InProgress,
                ServingMeasurementId = cookerServingPriceModel.ServingMeasurementId,
                NumberofServingTotal = 4 * cookerServingPriceModel.Quantity,
                ClientSubscriptionId = ClientSubscriptionId,
            };

            #region Week1
            firstSubscriptionOrder.OrderSubscriptionItems.Add(GetFirstOrderSubscriptionItem((int)WeekType.Values.Week1));
            firstSubscriptionOrder.OrderSubscriptionItems.Add(GetSecondOrderSubscriptionItem((int)WeekType.Values.Week1));
            firstSubscriptionOrder.OrderSubscriptionItems.Add(GetThirdOrderSubscriptionItem((int)WeekType.Values.Week1));
            #endregion

            #region Week2
            firstSubscriptionOrder.OrderSubscriptionItems.Add(GetFirstOrderSubscriptionItem((int)WeekType.Values.Week2));
            firstSubscriptionOrder.OrderSubscriptionItems.Add(GetSecondOrderSubscriptionItem((int)WeekType.Values.Week2));
            firstSubscriptionOrder.OrderSubscriptionItems.Add(GetFourthOrderSubscriptionItem((int)WeekType.Values.Week2));
            #endregion

            #region Week3
            firstSubscriptionOrder.OrderSubscriptionItems.Add(GetFirstOrderSubscriptionItem((int)WeekType.Values.Week3));
            firstSubscriptionOrder.OrderSubscriptionItems.Add(GetSecondOrderSubscriptionItem((int)WeekType.Values.Week3));
            firstSubscriptionOrder.OrderSubscriptionItems.Add(GetThirdOrderSubscriptionItem((int)WeekType.Values.Week3));
            #endregion

            #region Week4
            firstSubscriptionOrder.OrderSubscriptionItems.Add(GetFirstOrderSubscriptionItem((int)WeekType.Values.Week4));
            firstSubscriptionOrder.OrderSubscriptionItems.Add(GetFourthOrderSubscriptionItem((int)WeekType.Values.Week4));
            firstSubscriptionOrder.OrderSubscriptionItems.Add(GetFirstOrderSubscriptionItem((int)WeekType.Values.Week4));
            #endregion

            return firstSubscriptionOrder;
        }
Пример #3
0
        private OrderSubscription CreateSubscriptionOrder(ClientSubscription newClientSubscription)
        {
            var cookerServingPriceModel = new SubscriptionHelper(_uow).GetCookerServingPriceModel(newClientSubscription.ClientSubscriptionId);
            var subscriptionOrder = new OrderSubscription
            {
                OrderSubscriptionId = _uow.OrderSubscriptionItemRepository.All.ToList().Max(x => x.OrderSubscriptionId) + 1,
                ClientId = newClientSubscription.ClientId,
                OrderDate = DateTime.Today.Date,
                DeliveryDate = null,
                OrderTypeId = (int)OrderType.Values.NotSet,
                PaymentMethodId = (int)PaymentMethodType.Values.NotSet,
                CouponId = null,
                PromotionId = null,
                PlanId = cookerServingPriceModel.PLanId,
                SubTotal = cookerServingPriceModel.Price,
                CurrencyId = (int)CurrencyType.Values.Usd,
                OrderStatusId = (int)OrderStatus.Values.InProgress,
                ServingMeasurementId = cookerServingPriceModel.ServingMeasurementId,
                NumberofServingTotal = 4 * cookerServingPriceModel.Quantity,
                ClientSubscriptionId = newClientSubscription.ClientSubscriptionId
            };

            #region WeeksSubscriptionItems

            #region Week1
            subscriptionOrder.OrderSubscriptionItems.Add(MostPopularDishFromCooker1MenuSubscriptionItem((int)WeekType.Values.Week1));
            #endregion

            #region Week2
            subscriptionOrder.OrderSubscriptionItems.Add(MostPopularDishFromCooker1MenuSubscriptionItem((int)WeekType.Values.Week2));
            #endregion

            #region Week3
            subscriptionOrder.OrderSubscriptionItems.Add(MostPopularDishFromCooker1MenuSubscriptionItem((int)WeekType.Values.Week3));

            #endregion

            #region Week4
            subscriptionOrder.OrderSubscriptionItems.Add(MostPopularDishFromCooker1MenuSubscriptionItem((int)WeekType.Values.Week4));
            #endregion

            #endregion

            _uow.OrderSubscriptionRepository.Add(subscriptionOrder);
            _uow.Save();
            return subscriptionOrder;
        }
Пример #4
0
        private Invoice CreateSubscriptionInvoice(OrderSubscription orderSubscription)
        {
            if (orderSubscription == null) return null;
            var subscriptionHelper = new SubscriptionHelper(_uow);
            var subscriptionOrderCharge = new SubscriptionCharge(uow: _uow).Calculate(orderSubscription.ClientId, orderSubscription);
            var subscriptionOrderInvoice = new Invoice
            {

                InvoiceId = _uow.InvoiceRepository.All.ToList().Max(x => x == null ? 0 : x.InvoiceId) + 1,

                #region Orders Fields
                //OrderId = null,
                OrderDate = null,
                DeliveryDate = null,
                #endregion

                #region Subscription Fields
                OrderId = orderSubscription.OrderSubscriptionId,
                SubscriptionStartDate = DateTime.Now.Date,
                SubscriptionEndDate = DateTime.Now.Date.AddMonths(1),
                SubscriptionInvoiceDate = DateTime.Now.Date,

                ClientSubscriptionId = orderSubscription.ClientSubscriptionId,
                CookerSubscriptionId = subscriptionHelper.GetCookerSubscription(orderSubscription.ClientSubscriptionId).CookerSubscriptionId,
                ServingPriceId = subscriptionHelper.GetCookerServingPriceModel(orderSubscription.ClientSubscriptionId).ServicePriceId,
                PlanId = orderSubscription.PlanId,
                PlanTitle = subscriptionHelper.GetPlanTitle(orderSubscription.PlanId),

                #endregion

                #region Common Fields

                ClientId = orderSubscription.ClientId,
                CookerId = subscriptionOrderCharge.CookerId,

                OrderModelTypeId = orderSubscription.OrderTypeId,
                OrderTypeValue = subscriptionOrderCharge.OrderTypeValue,

                PaymentMethodValue = subscriptionOrderCharge.PaymentMethodValue,
                CurrencyId = orderSubscription.CurrencyId,

                PromotionTitle = subscriptionOrderCharge.PromotionTitle,
                PromotionPrice = subscriptionOrderCharge.PromotionPrice,
                PromotionCurrencyId = subscriptionOrderCharge.PromotionCurrencyId,

                CouponTitle = subscriptionOrderCharge.CouponTitle,
                CouponPrice = subscriptionOrderCharge.CouponPrice,
                CouponCurrencyId = subscriptionOrderCharge.CouponCurrencyId,

                SalesTax = subscriptionOrderCharge.SalesTaxes,
                DeliveryFees = subscriptionOrderCharge.DeliveryFee,
                SubTotal = subscriptionOrderCharge.Subtotal,
                Total = subscriptionOrderCharge.TotalCharges

                #endregion

            };
            return subscriptionOrderInvoice;
        }
Пример #5
0
 private decimal CalculateCharges(OrderSubscription order, decimal charges)
 {
     return CalulateChargeAfterCoupon(CalulateChargeAfterPromotion(charges, order.PromotionId), order.CouponId);
 }
Пример #6
0
 private OrderChargeModel PickUpCharge(OrderSubscription order, decimal? taxPercent)
 {
     if (taxPercent == null)
     {
         taxPercent = 1;
     }
     return new OrderChargeModel
     {
         DeliveryFee = 0,
         SalesTaxes = new Money().RoundTo2Decimal((decimal)(order.SubTotal * taxPercent) / 100),
         Subtotal = order.SubTotal,
         TotalCharges = new Money().RoundTo2Decimal(CalculateCharges(order, (decimal)(order.SubTotal * taxPercent) / 100 + order.SubTotal))
     };
 }