예제 #1
0
        public static void CreateOrUpdateBookingFareInfoItems(BookingFareInfo bookingFareInfo, decimal price, CountryFareType[] countryFareTypes, FareTypeName[] farePromotions, double[] fareMargins)
        {
            for (int i = 0; i < 5; i++)
            {
                BookingFareInfoItem item;
                if (bookingFareInfo.Items.Count > i)
                    item = bookingFareInfo.Items[i];
                else
                {
                    item = new BookingFareInfoItem();
                    bookingFareInfo.Items.Add(item);
                }

                item.FareType = (FareType)(i + 1);
                item.Margin = fareMargins[i];

                if (farePromotions[i] == null)
                    item.Name = countryFareTypes[i].Name;
                else
                {
                    item.Name = farePromotions[i].Name;
                    if (item.Margin != 0.0)
                        item.PromotionId = farePromotions[i].Id;
                }

                item.Price = (decimal)Math.Round((double)price * fareMargins[i] / 100.0, 4);
                item.Rule = countryFareTypes[i].Rule;
            }
        }
예제 #2
0
        public static void FillBookingFareInfoAndItems(LomsContext db, Booking booking, BookingFareInfo bookingFareInfo, decimal price, byte associationCurrencyId, DebugWriter debugInfoWriter)
        {
            try
            {
                CountryFareType[] countryFareTypes = RateHelper.GetCountryFareTypes(db, booking, debugInfoWriter);
                if (countryFareTypes == null)
                {
                    bookingFareInfo.DebugInfo = debugInfoWriter.ToString();
                    return;
                }

                var farePromotions = RateHelper.GetFarePromotions(db, booking, debugInfoWriter);

                double[] fareMargins = RateHelper.GetFareMargins(db, booking, debugInfoWriter);
                if (fareMargins == null)
                {
                    bookingFareInfo.DebugInfo = debugInfoWriter.ToString();
                    return;
                }

                if (farePromotions[0] == null) fareMargins[0] = 0.0;
                if (farePromotions[1] == null) fareMargins[1] = 0.0;
                if (farePromotions[3] == null) fareMargins[3] = 0.0;

                //if (fareMargins[0] + fareMargins[1] + fareMargins[2] + fareMargins[3] + fareMargins[4] == 0.0)
                //{
                //    bookingFareInfo.DebugInfo = debugInfoWriter.ToString();
                //    return;
                //}

                bookingFareInfo.Price = price;
                CreateOrUpdateBookingFareInfoItems(bookingFareInfo, price, countryFareTypes, farePromotions, fareMargins);

                ApplyCurrencyBookingFareInfoAndItems(db, booking, bookingFareInfo, associationCurrencyId, debugInfoWriter);

                ApplyPromoCodeToBookingFareInfoAndItems(db, booking, bookingFareInfo, debugInfoWriter);

                //rounding
                bookingFareInfo.Price = booking.City.Round(bookingFareInfo.Price);
                bookingFareInfo.Items.ForEach(i => i.Price = booking.City.Round(i.Price));
            }
            catch (Exception ex)
            {
                debugInfoWriter.WriteLine(ex.ToString());
            }

            bookingFareInfo.DebugInfo = debugInfoWriter.ToString();
        }
        public void SendQuoteToUser(int bookingId, TimeSpan timeToExpire, BookingFareInfo bookingFareInfo)
        {
            using (var db = new LomsContext())
            {
                db.Connection.Open();
                using (var transaction = db.Connection.BeginTransaction())
                {
                    var bookingQuote = db.BookingQuotations.Single(q => q.BookingId == bookingId);
                    bookingQuote.Status = QuotationStatus.Sent;
                    db.BookingQuotations.ApplyChanges(bookingQuote);

                    var booking = db.Bookings.IncludeAll("FareInfo", "FareInfo.Currency", "FareInfo.Items").Single(b => b.Id == bookingId);
                    booking.Status = BookingStatus.Fare;
                    booking.ExpiryTime = DateTime.UtcNow + timeToExpire;
                    //update fare info prices
                    booking.FareInfo.Price = bookingFareInfo.Price;
                    for (int i = 0; i < 5; i++)
                    {
                        var item = booking.FareInfo.Items[i];
                        item.Price = (decimal)Math.Round((double)bookingFareInfo.Items[i].Price * item.Margin / 100.0, 4);
                    }
                    db.Bookings.ApplyChanges(booking);

                    db.SaveChanges();
                    transaction.Commit();
                }
            }
        }
예제 #4
0
 private void GetQuote(BookingFareInfo bookingFareInfo)
 {
     if (bookingFareInfo == null) return;
     foreach (BookingFareInfoItem fareItem in bookingFareInfo.Items)
     {
         switch (fareItem.FareType)
         {
             case FareType.EFR:
                 EFare = fareItem.CurrencySymbol + fareItem.Price.ToString();
                 break;
             case FareType.DSC:
                 Saver = fareItem.CurrencySymbol + fareItem.Price.ToString();
                 break;
             case FareType.NET:
                 Flexi = fareItem.CurrencySymbol + fareItem.Price.ToString();
                 break;
             case FareType.PRM:
                 Plus101 = fareItem.CurrencySymbol + fareItem.Price.ToString();
                 break;
             case FareType.COM:
                 FlexiA = fareItem.CurrencySymbol + fareItem.Price.ToString();
                 break;
         }
     }
 }
예제 #5
0
     public bool Equals(BookingFareInfo other)
     {
         if (ReferenceEquals(null, other)) return false;
         if (ReferenceEquals(this, other)) return true;
 		if (other.BookingId == 0 && BookingId == 0)
 			return false;
 		else
 			return other.BookingId == BookingId;
     }
예제 #6
0
파일: Booking.cs 프로젝트: felixthehat/Limo
     private void FixupFareInfo(BookingFareInfo previousValue)
     {
         // This is the principal end in an association that performs cascade deletes.
         // Update the event listener to refer to the new dependent.
         if (previousValue != null)
         {
             ChangeTracker.ObjectStateChanging -= previousValue.HandleCascadeDelete;
         }
 
         if (FareInfo != null)
         {
             ChangeTracker.ObjectStateChanging += FareInfo.HandleCascadeDelete;
         }
 
         if (IsDeserializing)
         {
             return;
         }
 
         if (FareInfo != null)
         {
             FareInfo.BookingId = Id;
         }
 
         if (ChangeTracker.ChangeTrackingEnabled)
         {
             if (ChangeTracker.OriginalValues.ContainsKey("FareInfo")
                 && (ChangeTracker.OriginalValues["FareInfo"] == FareInfo))
             {
                 ChangeTracker.OriginalValues.Remove("FareInfo");
             }
             else
             {
                 ChangeTracker.RecordOriginalValue("FareInfo", previousValue);
                 // This is the principal end of an identifying association, so the dependent must be deleted when the relationship is removed.
                 // If the current state of the dependent is Added, the relationship can be changed without causing the dependent to be deleted.
                 if (previousValue != null && previousValue.ChangeTracker.State != ObjectState.Added)
                 {
                     previousValue.MarkAsDeleted();
                 }
             }
             if (FareInfo != null && !FareInfo.ChangeTracker.ChangeTrackingEnabled)
             {
                 FareInfo.StartTracking();
             }
         }
     }
예제 #7
0
        public static void ApplyCurrencyBookingFareInfoAndItems(LomsContext db, Booking booking, BookingFareInfo bookingFareInfo, byte associationCurrencyId, DebugWriter debugInfoWriter)
        {
            try
            {
                ////gateway
                //var gateway = db.Gateways.FirstOrDefault(g => g.CountryId == creatorCountryId);
                //var gatewayCountry = db.GatewayCountries.Include("DisplayedCurrency").FirstOrDefault(gc => gc.GatewayId == gateway.Id && gc.CountryId == booking.City.CountryId);
                //if (gatewayCountry == null)
                //    bookingFareInfo.Currency = db.CurrencyInfoes.Single(c => c.Name == "USD");
                //else
                //    bookingFareInfo.Currency = gatewayCountry.DisplayedCurrency;

                bookingFareInfo.Currency = db.CurrencyInfoes.Single(c => c.Id == associationCurrencyId); ;

                //currency conversion
                if (bookingFareInfo.CurrencyId != booking.City.Country.CurrencyId)
                {
                    var currencyFrom = db.CurrencyInfoes.Single(c => c.Id == booking.City.Country.CurrencyId);
                    var conversionRate = GeoPluginHelper.GetCurrencyConversionRate(currencyFrom.Name, bookingFareInfo.Currency.Name);

                    debugInfoWriter.WriteLine(string.Format("Conversion rate from {0} to {1} is {2}", currencyFrom.Name, bookingFareInfo.Currency.Name, conversionRate));

                    //fee
                    var conversionFee = (decimal)(db.ConversionFees.Single(f => f.FromId == currencyFrom.Id && f.ToId == bookingFareInfo.Currency.Id).Fee);
                    debugInfoWriter.WriteLine(string.Format("Conversion fee is {0}%", conversionFee));

                    bookingFareInfo.Price = (bookingFareInfo.Price * conversionRate) * (100 + conversionFee) / 100;
                    bookingFareInfo.Items.ForEach(i =>
                    {
                        if (i.Price > 0)
                            i.Price = (i.Price * conversionRate) * (100 + conversionFee) / 100;
                    });

                    bookingFareInfo.ConversionRate = conversionRate;
                    bookingFareInfo.ConversionFee = conversionFee;
                }
                else
                {
                    bookingFareInfo.ConversionRate = 1;
                    bookingFareInfo.ConversionFee = 0;
                }

                bookingFareInfo.Items.ForEach(i => i.CurrencySymbol = bookingFareInfo.Currency.Symbol);

            }
            catch (Exception ex)
            {
                debugInfoWriter.WriteLine(ex.ToString());
            }
        }
예제 #8
0
        public static void ApplyPriceToBookingFareInfoAndItems(LomsContext db, Booking booking, BookingFareInfo bookingFareInfo, decimal price, byte associationCurrencyId, DebugWriter debugInfoWriter)
        {
            bookingFareInfo.Price = price;
            for (int i = 0; i < 5; i++)
            {
                var item = bookingFareInfo.Items[i];
                item.Price = (decimal)Math.Round((double)price * item.Margin / 100.0, 4);
            }

            ApplyCurrencyBookingFareInfoAndItems(db, booking, bookingFareInfo, associationCurrencyId, debugInfoWriter);

            ApplyPromoCodeToBookingFareInfoAndItems(db, booking, bookingFareInfo, debugInfoWriter);

            //rounding
            bookingFareInfo.Price = booking.City.Round(bookingFareInfo.Price);
            bookingFareInfo.Items.ForEach(i => i.Price = booking.City.Round(i.Price));
        }
예제 #9
0
        public static void ApplyPromoCodeToBookingFareInfoAndItems(LomsContext db, Booking booking, BookingFareInfo bookingFareInfo, DebugWriter debugInfoWriter)
        {
            //promo code
            if (!string.IsNullOrWhiteSpace(booking.PromoCode))
            {
                Promotion promotionalCode = RateHelper.GetPromotionalCode(db, booking, booking.PickUpTime.Value, booking.PromoCode, debugInfoWriter);
                if (promotionalCode != null)
                {
                    booking.PromoMargin = promotionalCode.Margin;
                    booking.PromoBonus = promotionalCode.Bonus;
                }
                else
                {
                    booking.PromoMargin = 0;
                    booking.PromoBonus = 0;
                }

                bookingFareInfo.Price = bookingFareInfo.Price * (100 - (decimal)booking.PromoMargin) / 100;
                bookingFareInfo.Items.ForEach(i => i.Price = i.Price * (100 - (decimal)booking.PromoMargin) / 100);
            }
        }