public void SetBooking(Booking booking) { if (booking == null) return; if (_booking == null) { _booking = booking; OnPropertyChanged(() => CanEditDropOffCountriesAndStates); OnPropertyChanged(() => CanViewDropOffAddressAndAirports); if (_booking.DropOffEndpoint.Type == BookingEndpointType.NotSet) _enterDropOffAddressByPhysicalAddress = true; else //select existing _enterDropOffAddressByPhysicalAddress = _booking.DropOffEndpoint.Type == BookingEndpointType.Suburb; OnPropertyChanged(() => EnterDropOffAddressByPhysicalAddress); var dropOffEndpoint = _booking.DropOffEndpoint.Clone(); dropOffEndpoint.IsPickup = false; DropOffPhysicalAddressViewModel.Address = dropOffEndpoint; DropOffAirportAddressViewModel.JourneyType = _booking.JourneyType; DropOffAirportAddressViewModel.City = _booking.City; DropOffAirportAddressViewModel.Address = dropOffEndpoint; GetDropOffCountries(); } }
public void SetBooking(Booking booking) { if (booking == null) return; _booking = booking; FareInfo = booking.FareInfo; OnPropertyChanged(() => FareInfo); if (booking.FareInfo != null) { FareInfoItems = new ObservableCollection<FareTypeInfoItemViewModel>(booking.FareInfo.Items.Select(i => new FareTypeInfoItemViewModel(i, false))); OnPropertyChanged(() => FareInfoItems); FareInfoItems.ForEach(i => i.IsSelected = i.FareInfoItem.FareType == booking.FareType); SelectedFareInfoItem = FareInfoItems.SingleOrDefault(i => i.IsSelected); AcceptedTnC = SelectedFareInfoItem != null; OnPropertyChanged(() => AcceptedTnC); } else { FareInfoItems = new ObservableCollection<FareTypeInfoItemViewModel>(); OnPropertyChanged(() => FareInfoItems); SelectedFareInfoItem = null; } }
public static double GetRate(LomsContext db, Booking booking, DebugWriter debugInfoWriter) { double extras; bool autoPending = false; double price = 0.0; try { price = GetBaseRateWithAdminFees(db, booking, debugInfoWriter, out autoPending, out extras); if (price == 0.0 || autoPending) return 0.0; } catch (Exception ex) { debugInfoWriter.WriteLine("Exception during GetBaseRateWithAdminFees!"); debugInfoWriter.WriteLine(ex.ToString()); return 0.0; } RateHelper.ApplyVehicleMargin(db, booking, debugInfoWriter, ref price); price += extras; RateHelper.ApplyHourZone(db, booking, debugInfoWriter, ref price); //RateHelper.ApplyEventMargin(db, booking, debugInfoWriter, ref price, ref autoPending, ref eventName); //if (autoPending) // return 0.0; return price; }
public BookingInfo(BookingDispatching dispatch, Association association, AirportMeetingPoint meetingPoint) { _dispatch = dispatch; _booking = dispatch.Booking; _association = association; _airportMeetingPoint = meetingPoint; }
public static bool AllocateVehicle(LomsContext db, Booking booking, bool isPhantom, StringBuilder debug) { int vehicleTypeId = booking.VehicleTypeId.Value; var pickUpTime = booking.PickUpTime.Value; int jorneyLength = 30; //min DateTime fromDate = pickUpTime.Date; DateTime toDate = pickUpTime.AddMinutes(jorneyLength).Date; int fromTime = (((int)pickUpTime.TimeOfDay.TotalMinutes) / 30) * 30; int toTime = (((int)pickUpTime.AddMinutes(jorneyLength).TimeOfDay.TotalMinutes) / 30) * 30; if (!CheckAvailability(db, booking.Id, booking.CityId, vehicleTypeId, fromDate, toDate, fromTime, toTime, isPhantom, debug)) return false; if (booking.AllocatedVehicle == null) booking.AllocatedVehicle = new BookingAllocatedVehicle() { BookingId = booking.Id }; booking.AllocatedVehicle.CityId = booking.CityId; booking.AllocatedVehicle.VehicleTypeId = vehicleTypeId; booking.AllocatedVehicle.From = fromDate.AddMinutes(fromTime); booking.AllocatedVehicle.To = toDate.AddMinutes(toTime); booking.AllocatedVehicle.IsPhantom = isPhantom; return true; }
public void SetBooking(Booking booking) { if (booking == null) return; if (_booking == null) { _booking = booking; OnPropertyChanged(() => CanEditPickupCountriesAndStates); OnPropertyChanged(() => CanViewPickUpAddressAndAirports); if (_booking.PickUpEndpoint.Type == BookingEndpointType.NotSet) _enterPickUpAddressByPhysicalAddress = true; else //select existing _enterPickUpAddressByPhysicalAddress = _booking.PickUpEndpoint.Type == BookingEndpointType.Suburb; OnPropertyChanged(() => EnterPickUpAddressByPhysicalAddress); var pickUpEndpoint = _booking.PickUpEndpoint.Clone(); pickUpEndpoint.IsPickup = true; PickUpPhysicalAddressViewModel.Address = pickUpEndpoint; PickUpAirportAddressViewModel.JourneyType = _booking.JourneyType; PickUpAirportAddressViewModel.City = _booking.City; PickUpAirportAddressViewModel.Address = pickUpEndpoint; GetPickupCountries(); } }
public void SetBooking(Booking booking) { if (booking == null) return; _booking = booking; BookingsService.BeginGetCityVehicleType(_booking.CityId, _booking.VehicleTypeId.Value, CreateAsyncCallback(ar => BookingsService.EndGetCityVehicleType(ar), result => { _cityVehicleType = result; OnPropertyChanged(() => NumberOfAdultsOptions); OnPropertyChanged(() => NumberOfChildOptions); OnPropertyChanged(() => NumberOfInfantOptions); OnPropertyChanged(() => NumberOfAdultPassengers); OnPropertyChanged(() => NumberOfChildPassengers); OnPropertyChanged(() => NumberOfInfantPassengers); OnPropertyChanged(() => TotalNumberOfPassengers); OnPropertyChanged(() => ShowAdditionalPassengers); }), null); UpdateManagedUsers(); }
private static double GetBaseRateWithAdminFees(LomsContext db, Booking booking, DebugWriter debug, out bool autoPending, out double extras) { autoPending = false; extras = 0; //pick-up debug.WriteLine("Pick-Up:"); double extrasForPickUp; SubDivision subFrom = GetSubDivision(db, booking, booking.PickUpEndpoint, debug, out autoPending, out extrasForPickUp); if (subFrom == null || autoPending) return 0.0; Zone zoneFrom; Region regionFrom; debug.WriteSubDivisionInfo(db, subFrom, out zoneFrom, out regionFrom); if (extrasForPickUp != 0.0) debug.WriteLine("Airport Extras: {0:0.00}", extrasForPickUp); //drop-off debug.WriteLine(); debug.WriteLine("Drop-Off:"); double extrasForDropOff; SubDivision subTo = GetSubDivision(db, booking, booking.DropOffEndpoint, debug, out autoPending, out extrasForDropOff); if (subTo == null) return 0.0; Zone zoneTo; Region regionTo; debug.WriteSubDivisionInfo(db, subTo, out zoneTo, out regionTo); if (extrasForDropOff != 0.0) debug.WriteLine("Airport Extras: {0:0.00}", extrasForDropOff); debug.WriteLine(); SubDivisionRate baseRate = db.SubDivisionRates.FirstOrDefault(r => r.SubDivisionFromId == subFrom.Id && r.SubDivisionToId == subTo.Id); debug.WriteBaseRate(baseRate); if (baseRate == null) return 0.0; double price = 0.0; if (baseRate != null) { price = baseRate.Rate; //admin fees List<AdminFee> adminFees = GetAdminFees(db, booking, zoneFrom, regionFrom, zoneTo, regionTo); if (adminFees != null) foreach (var value in adminFees) price += baseRate.Rate * value.Margin / 100.0 + value.Fee; } extras = extrasForPickUp + extrasForDropOff; return price; }
public static bool IsInnerJourney(LomsContext db, Booking booking) { if (!IsInner(db, booking.CityId, booking.PickUpEndpoint.Type, booking.PickUpEndpoint.SuburbId, booking.PickUpEndpoint.AirportId)) return false; if (!IsInner(db, booking.CityId, booking.DropOffEndpoint.Type, booking.DropOffEndpoint.SuburbId, booking.DropOffEndpoint.AirportId)) return false; foreach (BookingStop stop in booking.Stops) if (!IsInner(db, booking.CityId, stop.EndpointType, stop.SuburbId, stop.AirportId)) return false; return true; }
public void SetBooking(Booking booking, SubmitBookingResponse submitBookingResponse) { if (booking == null) return; _booking = booking; Email3 = Email4 = null; CreatorEmails = new ObservableCollection<string>(submitBookingResponse.CreatorEmails); if (!string.IsNullOrWhiteSpace(_booking.Creator.Email) && !CreatorEmails.Contains(_booking.Creator.Email)) CreatorEmails.Insert(0, _booking.Creator.Email); OnPropertyChanged(() => CreatorEmails); }
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 SetBooking(Booking booking) { if (booking == null) return; if (_booking == null || _booking.Id != booking.Id) { _booking = booking; RequestCityVehicleInfo(); } else if (_booking.CityId != booking.CityId) { _booking = booking; RequestCityVehicleInfo(); } else { _booking = booking; UpdateVehicleTypeSelection(); } }
public static Document Generate(Booking booking) { BookingInfo bookingInfo = new BookingInfo(booking); Document document = new Document(); document.Info.Title = "Confirmation Voucher"; document.Info.Subject = booking.ReferenceId; document.Info.Author = bookingInfo.AssociationName; DefineStyles(document); Section section = document.AddSection(); AddLogo(document, bookingInfo); AddTripSummary(document, bookingInfo); AddMeetingPoint(document, bookingInfo); AddPassengers(document, bookingInfo); section.AddParagraph(); AddPayment(document, bookingInfo); AddBookedByInfo(document, bookingInfo); return document; }
public void SetBooking(Booking booking) { if (booking == null) return; if (_booking == null || _booking.Id != booking.Id) { _booking = booking; _provisionInfo = _booking.ProvisionInfo; RequestCityVehicleInfo(); RequestSpecialOccasion(); //waiting time if (_provisionInfo.WaitingTime > ApprovedWaitingTimes.Last().Value) _provisionInfo.WaitingTime = 0; IsApprovedWaitingTimeYes = _provisionInfo.WaitingTime != 0; OnPropertyChanged(() => SelectedApprovedWaitingTime); OnPropertyChanged(() => CarryOnBaggage); OnPropertyChanged(() => EventName); } else if (_booking.CityId != booking.CityId || _booking.VehicleTypeId.Value != booking.VehicleTypeId.Value) { _booking = booking; _provisionInfo = _booking.ProvisionInfo; RequestCityVehicleInfo(); } else _provisionInfo = _booking.ProvisionInfo; if (Currency == null || Currency.Id != _booking.FareInfo.Currency.Id) { Currency = _booking.FareInfo.Currency; OnPropertyChanged(() => Currency); } }
public static double[] GetFareMargins(LomsContext db, Booking booking, DebugWriter debugInfoWriter) { var date = (from d in db.FareTypeDates where d.CityId == booking.CityId orderby d.StartDate descending select d) .Take(1).FirstOrDefault(); if (date != null) { var cityVehicleType = db.CityVehicleTypes.FirstOrDefault(cvt => cvt.CityId == booking.CityId && cvt.VehicleTypeId == booking.VehicleTypeId); FareTypeDateMargin margin = db.FareTypeDateMargins.FirstOrDefault(m => m.DateId == date.Id && m.CityVehicleId == cityVehicleType.Id); if (margin != null) { debugInfoWriter.WriteLine("City Fare Type Vehicle Margins:"); debugInfoWriter.WriteLine(" Margins: {0:0.00}%, {1:0.00}%, {2:0.00}%, {3:0.00}%, {4:0.00}%", margin.Margin1, margin.Margin2, margin.Margin3, margin.Margin4, margin.Margin5); debugInfoWriter.WriteLine(); return new double[] { margin.Margin1, margin.Margin2, margin.Margin3, margin.Margin4, margin.Margin5 }; } } debugInfoWriter.WriteLine("No Fare Margins"); debugInfoWriter.WriteLine(); return null; }
private static SubDivision GetSubDivision(LomsContext db, Booking booking, BookingEndpoint endpoint) { int? subId = null; switch (endpoint.Type) { case BookingEndpointType.Suburb: subId = endpoint.Suburb.SubDivisionId; break; case BookingEndpointType.AirportPrivate: case BookingEndpointType.AirportOther: subId = endpoint.Airport.SubDivisionId; break; } return db.SubDivisions.FirstOrDefault(sd => sd.Id == subId); }
//public static void ApplyEventMargin(LomsContext db, Booking booking, DebugWriter debug, ref double price, ref bool autoPending, ref string eventName) //{ // EventVehicleMargin eventMargin = RateHelper.GetEventVehicle(db, booking, ref autoPending, ref eventName, debug); // if (autoPending) // return; // if (eventMargin != null) // { // price = price * eventMargin.Margin / 100.0 + eventMargin.Fee; // if (price < eventMargin.MinimalRate) // price = eventMargin.MinimalRate; // } //} public static EventVehicleMargin GetEventVehicle(LomsContext db, Booking booking, out bool autoPending, out string eventName, DebugWriter debug) { autoPending = false; eventName = null; var cityVehicleType = db.CityVehicleTypes.FirstOrDefault(cvt => cvt.CityId == booking.CityId && cvt.VehicleTypeId == booking.VehicleTypeId); DateTime pickUpDate = booking.PickUpTime.Value.Date; int pickUpTimeOfDayMinutes = (int)booking.PickUpTime.Value.TimeOfDay.TotalMinutes; var events = from ev in db.Events where ev.CityId == booking.CityId && ev.StartDate <= pickUpDate && pickUpDate <= ev.EndDate && ev.StartTime <= pickUpTimeOfDayMinutes && pickUpTimeOfDayMinutes <= ev.EndTime select ev; debug.WriteLine(string.Format("Events: {0} found", events.Count())); //from SubDivision subDivisionFrom = GetSubDivision(db, booking, booking.PickUpEndpoint); Division divisionFrom = null; Zone zoneFrom = null; Region regionFrom = null; if (subDivisionFrom.DivisionId.HasValue) { divisionFrom = db.Divisions.FirstOrDefault(d => d.Id == subDivisionFrom.DivisionId.Value); if (divisionFrom.ZoneId.HasValue) { zoneFrom = db.Zones.FirstOrDefault(z => z.Id == divisionFrom.ZoneId.Value); if (zoneFrom.RegionId.HasValue) regionFrom = db.Regions.FirstOrDefault(r => r.Id == zoneFrom.RegionId.Value); } } //to SubDivision subDivisionTo = GetSubDivision(db, booking, booking.DropOffEndpoint); Division divisionTo = null; Zone zoneTo = null; Region regionTo = null; if (subDivisionTo.DivisionId.HasValue) { divisionTo = db.Divisions.FirstOrDefault(d => d.Id == subDivisionTo.DivisionId.Value); if (divisionTo.ZoneId.HasValue) { zoneTo = db.Zones.FirstOrDefault(z => z.Id == divisionTo.ZoneId.Value); if (zoneTo.RegionId.HasValue) regionTo = db.Regions.FirstOrDefault(r => r.Id == zoneTo.RegionId.Value); } } foreach (Event ev in events) { var areas = db.EventAreas.Where(m => m.EventId == ev.Id); bool contains = false; foreach (var area in areas) { if (area.Contains(regionFrom, zoneFrom, divisionFrom, subDivisionFrom) || area.Contains(regionTo, zoneTo, divisionTo, subDivisionTo)) { contains = true; break; } } if (contains) { eventName = ev.Name; if (ev.Autopend) { debug.WriteLine(string.Format("Mathched event: {0}, autopending"), ev.Name); autoPending = true; return null; } var vehicleMargin = db.EventVehicleMargins.FirstOrDefault(m => m.EventId == ev.Id && m.VehicleCityId == cityVehicleType.Id); if (vehicleMargin != null) { debug.WriteLine(string.Format("Mathched event: {0}, vehicle margin={1}, minimal rate={2}, fee={3}", ev.Name, vehicleMargin.Margin, vehicleMargin.MinimalRate, vehicleMargin.Fee)); return vehicleMargin; } } } return null; }
public static CountryFareType[] GetCountryFareTypes(LomsContext db, Booking booking, DebugWriter debugInfoWriter) { int countryId = booking.City.CountryId; CountryFareType typeEFR = db.CountryFareTypes.FirstOrDefault(t => t.CountryId == countryId && t.FareTypeId == (int)FareType.EFR); if (typeEFR == null) { debugInfoWriter.WriteLine("No country fare types!"); return null; } CountryFareType typeDSC = db.CountryFareTypes.FirstOrDefault(t => t.CountryId == countryId && t.FareTypeId == (int)FareType.DSC); CountryFareType typeNET = db.CountryFareTypes.FirstOrDefault(t => t.CountryId == countryId && t.FareTypeId == (int)FareType.NET); CountryFareType typePRM = db.CountryFareTypes.FirstOrDefault(t => t.CountryId == countryId && t.FareTypeId == (int)FareType.PRM); CountryFareType typeCOM = db.CountryFareTypes.FirstOrDefault(t => t.CountryId == countryId && t.FareTypeId == (int)FareType.COM); return new CountryFareType[] { typeEFR, typeDSC, typeNET, typePRM, typeCOM }; }
private static double GetAirportExtras(LomsContext db, Booking booking, int airportId, bool isPickUp, DebugWriter debug) { AirportExtrasDate date = (from d in db.AirportExtrasDates where d.AirportId == airportId && d.PickUpType == (isPickUp ? (int)AirportExtrasDirection.From : (int)AirportExtrasDirection.To) && d.StartDate <= booking.PickUpTime orderby d.StartDate descending select d) .Take(1).FirstOrDefault(); if (date != null) { var extras = db.AirportExtrasDateValues.FirstOrDefault(e => e.DateId == date.Id && e.VehicleId == booking.VehicleTypeId); if (extras != null) return extras.Extras1 + extras.Extras2 + extras.Extras3 + extras.Extras4 + extras.Extras5; } return 0; }
private static List<AdminFee> GetAdminFees(LomsContext db, Booking booking, Zone zoneFrom, Region regionFrom, Zone zoneTo, Region regionTo) { var date = (from d in db.AdminFeeDates where d.CountryId == booking.City.CountryId && d.StartDate <= booking.PickUpTime orderby d.StartDate descending select d) .Take(1).FirstOrDefault(); if (date == null) return null; var fees = new List<AdminFee>(); var regionFees = from f in db.RegionAdminFeeValues where f.DateId == date.Id && ( f.FromId == regionFrom.Id && f.ToId == regionTo.Id || f.FromId.HasValue && f.ToId == regionTo.Id || f.FromId == regionFrom.Id && !f.ToId.HasValue ) select f; regionFees.ForEach(rf => fees.Add(new AdminFee(rf.Margin, rf.Fee))); var zoneFees = from f in db.ZoneAdminFeeValues where f.DateId == date.Id && ( f.FromId == regionFrom.Id && f.ToId == regionTo.Id || f.FromId == null && f.ToId == regionTo.Id || f.FromId == regionFrom.Id && f.ToId == null ) select f; zoneFees.ForEach(zf => fees.Add(new AdminFee(zf.Margin, zf.Fee))); return fees; }
public static bool GetPickUpTime(LomsContext db, Booking booking, DateTime dropOffTime, DebugWriter debug, out DateTime pickUpTime) { pickUpTime = DateTime.MinValue; if (booking.JourneyType == JourneyType.ToAirport && (booking.DropOffEndpoint.Type == BookingEndpointType.AirportOther || booking.DropOffEndpoint.Type == BookingEndpointType.AirportPrivate)) { dropOffTime = dropOffTime.AddMinutes((-1.0) * booking.DropOffEndpoint.Airport.CheckInWaitingTime.Value); debug.WriteLine("Airport Check In Waiting Time - " + booking.DropOffEndpoint.Airport.CheckInWaitingTime.ToString() + "minutes"); } //pick-up debug.Write("Pick-Up "); Suburb subFrom = GetSuburb(db, booking.PickUpEndpoint, debug); if (subFrom == null) return false; //drop-off debug.Write("Drop-Off "); Suburb subTo = GetSuburb(db, booking.DropOffEndpoint, debug); if (subTo == null) return false; var info = db.TripInfoes.FirstOrDefault(i => i.FromId == subFrom.Id && i.ToId == subTo.Id); if (info == null) { debug.WriteLine("No Trip Info for this suburbs!"); return false; } debug.WriteLine(); debug.WriteLine("Trip Info:"); debug.WriteLine(" Distance - " + info.Distance.ToString() + "km"); debug.WriteLine(" Time - " + ToTimeString(info.Time)); debug.Write(" Buffer Time (7:00-19:00) - "); debug.WriteLine(info.Time1 != 0 ? ToTimeString(info.Time1) : "<not set>"); debug.Write(" Buffer Time (19:01 - 06:59) - "); debug.WriteLine(info.Time2 != 0 ? ToTimeString(info.Time2) : "<not set>"); int minutes = dropOffTime.Hour * 60 + dropOffTime.Minute; debug.WriteLine(); debug.WriteLine("Drop-off time is " + dropOffTime.ToString("dd/MM/yy HH:mm")); if (7 * 60 <= minutes && minutes <= 19 * 60 && info.Time1 != 0) { pickUpTime = dropOffTime.AddMinutes((info.Time + info.Time1) * (-1)); } else if (minutes < 7 * 60 && 19 * 60 < minutes && info.Time2 != 0) { pickUpTime = dropOffTime.AddMinutes((info.Time + info.Time2) * (-1)); } else { debug.WriteLine("Using City Buffer Times"); City city = booking.City; if (city == null) return false; int bufferTime = 0; if (7 * 60 <= minutes && minutes <= 19 * 60) { if (info.Distance <= 40) bufferTime = city.DayBufferTime40.Value; else if (info.Distance <= 80) bufferTime = city.DayBufferTime80.Value; else if (info.Distance <= 140) bufferTime = city.DayBufferTime140.Value; else if (info.Distance <= 200) bufferTime = city.DayBufferTime200.Value; else bufferTime = city.DayBufferTimeMore.Value; } else if (minutes < 7 * 60 && 19 * 60 < minutes) { if (info.Distance <= 40) bufferTime = city.NightBufferTime40.Value; else if (info.Distance <= 80) bufferTime = city.NightBufferTime80.Value; else if (info.Distance <= 140) bufferTime = city.NightBufferTime140.Value; else if (info.Distance <= 200) bufferTime = city.NightBufferTime200.Value; else bufferTime = city.NightBufferTimeMore.Value; } pickUpTime = dropOffTime.AddMinutes((info.Time + bufferTime) * (-1)); } debug.WriteLine("Pick-up time is " + pickUpTime.ToString("dd/MM/yy HH:mm")); return true; }
public void ResetSelectedData() { _booking = null; }
public static FareTypeName[] GetFarePromotions(LomsContext db, Booking booking, DebugWriter debugInfoWriter) { FareTypeName fareTypeNameEFR = RateHelper.GetFarePromotion(db, FareType.EFR, booking, debugInfoWriter); FareTypeName fareTypeNameDSC = RateHelper.GetFarePromotion(db, FareType.DSC, booking, debugInfoWriter); FareTypeName fareTypeNamePRM = RateHelper.GetFarePromotion(db, FareType.PRM, booking, debugInfoWriter); return new FareTypeName[] { fareTypeNameEFR, fareTypeNameDSC, null, fareTypeNamePRM, null }; }
private static void ApplyVehicleMargin(LomsContext db, Booking booking, DebugWriter debug, ref double price) { var cityVehicleType = db.CityVehicleTypes.FirstOrDefault(cvt => cvt.CityId == booking.CityId && cvt.VehicleTypeId == booking.VehicleTypeId); if (cityVehicleType == null) { debug.WriteLine("{0} city does not support {1} vehicle!", booking.City.Name, booking.VehicleType.Name); debug.WriteLine(); } else { debug.WriteLine("City Vehicle Rate ({0}):", booking.VehicleType.Name); debug.WriteLine(" Margin: {0:0.00}%", cityVehicleType.Margin); debug.WriteLine(" Fee: ${0:0.00}", cityVehicleType.Fee); debug.WriteLine(); price = price * cityVehicleType.Margin / 100.0 + cityVehicleType.Fee; } }
private static FareTypeName GetFarePromotion(LomsContext db, FareType fareType, Booking booking, DebugWriter debug) { var timeZone = db.CityCurrentTimeZones.FirstOrDefault(z => z.CityId == booking.CityId); if (timeZone == null) { debug.WriteLine("Cannot get city local time."); debug.WriteLine(); return null; } DateTime cityLocalTime = DateTime.UtcNow.AddMinutes(timeZone.UtcOffset); var cityVehicleType = db.CityVehicleTypes.FirstOrDefault(cvt => cvt.CityId == booking.CityId && cvt.VehicleTypeId == booking.VehicleTypeId); DateTime pickUpDate = booking.PickUpTime.Value.Date; int pickUpTimeOfDayMinutes = (int)booking.PickUpTime.Value.TimeOfDay.TotalMinutes; var name = (from n in db.FareTypeNames where n.CityId == booking.CityId && n.FareTypeId == (int)fareType && n.StartDate <= pickUpDate && pickUpDate <= n.EndDate && n.FromTime <= pickUpTimeOfDayMinutes && pickUpTimeOfDayMinutes <= n.EndTime select n).FirstOrDefault(); if (name != null) { var nameVehicle = db.FareTypeNameVehicles.FirstOrDefault(nv => nv.FareTypeNameId == name.Id && nv.CityVehicleId == cityVehicleType.Id); if (nameVehicle != null) { if (booking.JourneyType == JourneyType.ToAirport && nameVehicle.ToAirport || booking.JourneyType == JourneyType.FromAirport && nameVehicle.FromAirport || //booking.JourneyType == JourneyType.CityToSuburb && nameVehicle.FromCity || //booking.JourneyType == JourneyType.SuburbToCity && nameVehicle.ToCity || booking.JourneyType == JourneyType.SuburbToSuburb && nameVehicle.SuburbToSuburb || booking.JourneyType == JourneyType.AsDirected && nameVehicle.AsDirected) { if (cityLocalTime.AddDays(nameVehicle.Advance) <= booking.PickUpTime.Value) { var d1 = pickUpDate; var d2 = pickUpDate.AddDays(1.0); //not selected fares var query1 = from b in db.Bookings join bfi in db.BookingFareInfoes on b.Id equals bfi.BookingId join bfii in db.BookingFareInfoItems on bfi.BookingId equals bfii.BookingId where b.Id != booking.Id && b.FarePromotionId == 0 && (b.StatusId == (int)BookingStatus.Fare || b.StatusId == (int)BookingStatus.Pending || b.StatusId == (int)BookingStatus.PendingSubmitted) && b.VehicleTypeId == booking.VehicleTypeId && b.PickUpTime >= d1 && b.PickUpTime <= d2 && bfii.PromotionId == name.Id select b; int used1 = query1.Count(); //selected fares int used2 = db.Bookings.Count(b => b.Id != booking.Id && b.FarePromotionId == name.Id && (b.StatusId == (int)BookingStatus.Fare || b.StatusId == (int)BookingStatus.Submitted || b.StatusId == (int)BookingStatus.Confirmed) && b.VehicleTypeId == booking.VehicleTypeId && b.PickUpTime >= d1 && b.PickUpTime <= d2); if (used1 + used2 < nameVehicle.Limit) { debug.WriteLine("Fare Promotion - {0} ({1}):", name.Name, ((FareType)name.FareTypeId).ToString()); debug.Write(" {0}-{1}", name.StartDate.ToString("dd/MM/yy"), name.EndDate.ToString("dd/MM/yy")); debug.WriteLine(" {0}-{1}:", ToTimeString(name.FromTime), ToTimeString(name.EndTime)); debug.WriteLine(); return name; } } } } } debug.WriteLine("No Fare Promotions for {0}", fareType); debug.WriteLine(); return null; }
private static void ApplyHourZone(LomsContext db, Booking booking, DebugWriter debug, ref double price) { HourZoneMargin hourZoneMargin = RateHelper.GetHourZone(db, booking, debug); if (hourZoneMargin != null) { if (booking.JourneyType == JourneyType.ToAirport) price = price * hourZoneMargin.MarginToAirport / 100.0 + hourZoneMargin.FeeToAirport; else if (booking.JourneyType == JourneyType.FromAirport) price = price * hourZoneMargin.MarginFromAirport / 100.0 + hourZoneMargin.FeeFromAirport; //else if (booking.JourneyType == JourneyType.CityToSuburb) // price = price * hourZoneMargin.MarginFromCity / 100.0 + hourZoneMargin.FeeFromCity; //else if (booking.JourneyType == JourneyType.SuburbToCity) //price = price * hourZoneMargin.MarginToCity / 100.0 + hourZoneMargin.FeeToCity; else if (booking.JourneyType == JourneyType.SuburbToSuburb) price = price * hourZoneMargin.MarginSuburbToSuburb / 100.0 + hourZoneMargin.FeeSuburbToSuburb; else if (booking.JourneyType == JourneyType.AsDirected) price = price * hourZoneMargin.MarginAsDirected / 100.0 + hourZoneMargin.FeeAsDirected; } }
public static Promotion GetPromotionalCode(LomsContext db, Booking booking, DateTime pickUpTime, string promoCode, DebugWriter debug) { if (string.IsNullOrWhiteSpace(promoCode)) { debug.WriteLine("Promotional Code was not set in the booking!"); debug.WriteLine(); return null; } var promotions = db.Promotions.Where(p => p.Code == promoCode.Trim()); if (promotions.Count() == 0) { debug.WriteLine("No Promotional Codes with code {0}!", promoCode); debug.WriteLine(); return null; } DateTime pickUpDate = pickUpTime.Date; int pickUpTimeOfDayMinutes = (int)pickUpTime.TimeOfDay.TotalMinutes; var cityVehicleType = db.CityVehicleTypes.FirstOrDefault(cvt => cvt.CityId == booking.CityId && cvt.VehicleTypeId == booking.VehicleTypeId); foreach (Promotion promotion in promotions) { if (promotion.StartDate < pickUpDate && pickUpDate < promotion.EndDate && promotion.FromTime < pickUpTimeOfDayMinutes && pickUpTimeOfDayMinutes < promotion.EndTime) { var vehicles = db.PromotionVehicles.Where(pv => pv.PromotionId == promotion.Id); foreach (var promotionVehicle in vehicles) { if (promotionVehicle.CityVehicleId == cityVehicleType.Id) { if (booking.JourneyType == JourneyType.ToAirport && promotionVehicle.ToAirport || booking.JourneyType == JourneyType.FromAirport && promotionVehicle.FromAirport || //booking.JourneyType == JourneyType.CityToSuburb && promotionVehicle.FromCity || //booking.JourneyType == JourneyType.SuburbToCity && promotionVehicle.ToCity || booking.JourneyType == JourneyType.SuburbToSuburb && promotionVehicle.SuburbToSuburb || booking.JourneyType == JourneyType.AsDirected && promotionVehicle.AsDirected) { debug.WriteLine("Promotional Code - {0} ({1}):", promotion.Name, promotion.Code); debug.Write(" {0}-{1}", promotion.StartDate.ToString("dd/MM/yy"), promotion.EndDate.ToString("dd/MM/yy")); debug.WriteLine(" {0}-{1}:", ToTimeString(promotion.FromTime), ToTimeString(promotion.EndTime)); debug.WriteLine(" Margins: {0}, Bonus: {1}", promotion.Margin, promotion.Bonus); debug.WriteLine(); return promotion; } } } } } debug.WriteLine("Promotional Codes with name {0} do not match booking details!", promoCode); debug.WriteLine(); return null; }
private static HourZoneMargin GetHourZone(LomsContext db, Booking booking, DebugWriter debug) { int time = (int)booking.PickUpTime.Value.TimeOfDay.TotalMinutes; var zone = (from z in db.HourZones where (z.FromTime <= time && time <= z.EndTime) || (z.FromTime > z.EndTime && ((z.FromTime <= time && time <= 24 * 60) || (0 <= time && time <= z.EndTime))) select z).FirstOrDefault(); if (zone == null) { debug.WriteLine(" Hour zone cannot be found, city: {0}, pick-up time: {1}", booking.City.Name, booking.PickUpTime); debug.WriteLine(); return null; } var margin = (from m in db.HourZoneMargins where m.HourZoneId == zone.Id && m.StartDate <= booking.PickUpTime orderby m.StartDate descending select m).Take(1).FirstOrDefault(); if (margin != null) { debug.WriteLine("Hour Zone - {0}, {1}-{2}:", zone.Name, ToTimeString(zone.FromTime), ToTimeString(zone.EndTime)); debug.WriteLine("Start Date {0}:", margin.StartDate.ToString("dd/MM/yy")); debug.WriteLine(" From Airport: {0:0.00}% + {1:0.00}{2}", margin.MarginFromAirport, margin.FeeFromAirport, ""); debug.WriteLine(" To Airport: {0:0.00}% + {1:0.00}{2}", margin.MarginToAirport, margin.FeeToAirport, ""); debug.WriteLine(" From City: {0:0.00}% + {1:0.00}{2}", margin.MarginFromCity, margin.FeeFromCity, ""); debug.WriteLine(" To City: {0:0.00}% + {1:0.00}{2}", margin.MarginToCity, margin.FeeToCity, ""); debug.WriteLine(" Suburb To Suburb: {0:0.00}% + {1:0.00}{2}", margin.MarginSuburbToSuburb, margin.FeeSuburbToSuburb, ""); debug.WriteLine(" As Directed: {0:0.00}% + {1:0.00}{2}", margin.MarginAsDirected, margin.FeeAsDirected, ""); debug.WriteLine(" Wedding: {0:0.00}% + {1:0.00}{2}", margin.MarginWedding, margin.FeeWedding, ""); debug.WriteLine(" Funeral: {0:0.00}% + {1:0.00}{2}", margin.MarginFuneral, margin.FeeFuneral, ""); debug.WriteLine(" Secure Parcel: {0:0.00}% + {1:0.00}{2}", margin.MarginSecureParcel, margin.FeeSecureParcel, ""); debug.WriteLine(); return margin; } debug.WriteLine("No Hour Zones"); debug.WriteLine(); return null; }
private static SubDivision GetSubDivision(LomsContext db, Booking booking, BookingEndpoint endpoint, DebugWriter debug, out bool autoPending, out double extras) { autoPending = false; extras = 0; int? subId = null; switch (endpoint.Type) { case BookingEndpointType.Suburb: { if (endpoint.Suburb != null) { Landmark autoPendingLandmark = db.Landmarks.FirstOrDefault(l => l.Address1 == endpoint.Address1 && l.SuburbId == endpoint.SuburbId && l.Autopend); if (autoPendingLandmark != null) { autoPending = true; debug.WriteLine("Suburb {0} has autopending landmark {1}!", endpoint.Suburb.FullName, autoPendingLandmark.Name); return null; } subId = endpoint.Suburb.SubDivisionId; debug.Write("Suburb: {0}", endpoint.Suburb.FullName); } else { debug.WriteLine("Suburb has been removed from system!"); return null; } } break; case BookingEndpointType.AirportPrivate: case BookingEndpointType.AirportOther: { if (endpoint.Airport != null) { subId = endpoint.Airport.SubDivisionId; debug.Write("Airport: {0}", endpoint.Airport.Name); //airport extras extras = RateHelper.GetAirportExtras(db, booking, endpoint.Airport.Id, booking.PickUpEndpointId == endpoint.Id, debug); } else { debug.WriteLine("Airport has been removed from system!"); return null; } } break; } if (subId == null) { debug.WriteLine("Sub Division is not specified!"); return null; } var sub = db.SubDivisions.FirstOrDefault(sd => sd.Id == subId); if (sub == null) { debug.WriteLine("Sub Division is not specified!"); return null; } return sub; }
private void FixupBooking(Booking previousValue) { // This is the dependent end in an association that performs cascade deletes. // Update the principal's event listener to refer to the new dependent. // This is a unidirectional relationship from the dependent to the principal, so the dependent end is // responsible for managing the cascade delete event handler. In all other cases the principal end will manage it. if (previousValue != null) { previousValue.ChangeTracker.ObjectStateChanging -= HandleCascadeDelete; } if (Booking != null) { Booking.ChangeTracker.ObjectStateChanging += HandleCascadeDelete; } if (IsDeserializing) { return; } if (Booking != null) { BookingId = Booking.Id; } if (ChangeTracker.ChangeTrackingEnabled) { if (ChangeTracker.OriginalValues.ContainsKey("Booking") && (ChangeTracker.OriginalValues["Booking"] == Booking)) { ChangeTracker.OriginalValues.Remove("Booking"); } else { ChangeTracker.RecordOriginalValue("Booking", previousValue); // This is the dependent end of an identifying association, so it must be deleted when the relationship is // removed. If the current state is Added, the relationship can be changed without causing the dependent to be deleted. // This is a unidirectional relationship from the dependent to the principal, so the dependent end is // responsible for cascading the delete. In all other cases the principal end will manage it. if (previousValue != null && ChangeTracker.State != ObjectState.Added) { this.MarkAsDeleted(); } } if (Booking != null && !Booking.ChangeTracker.ChangeTrackingEnabled) { Booking.StartTracking(); } } }