public void Clear() { FareType = FareType.None; Name = ""; Margin = 0; Price = 0; Rule = ""; PromotionId = 0; }
internal static string GetMessage(this FareType type, string licensePlate) { if (licensePlate.IsNullOrEmpty()) { return(string.Empty); } return(FareToCodeMap.ContainsKey(type) ? $"{FareToCodeMap[type]} {licensePlate}" : string.Empty); }
private void SendSms(FareType type) { if (!_smsTask.CanSendSms) { return; } if (_settingsService.LicensePlate.IsNullOrEmpty()) { return; } if (_settingsService.PhoneNumber.IsNullOrEmpty()) { return; } var message = type.GetMessage(_settingsService.LicensePlate); _smsTask.SendSms(_settingsService.PhoneNumber, message); }
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; }
public CancellationInfoResponse GetBookingCancellationInfo(int bookingId, FareType fareType) { try { using (var db = new LomsContext()) { var booking = db.Bookings.IncludeAll("PickUpEndpoint", "DropOffEndpoint", "Stops").FirstOrDefault(b => b.Id == bookingId); var cityId = booking.CityId; var vehicleTypeId = booking.VehicleTypeId.Value; var pickUpTime = booking.PickUpTime.Value; var cancellation = db.Cancellations.First(c => c.CityId == cityId); var date = s_compiledCancellatioDatesQuery.Invoke(db, cancellation.Id, (byte)fareType, pickUpTime.Date).Take(1).FirstOrDefault(); var cityVehicleType = db.CityVehicleTypes.Include("VehicleType").First(cvt => cvt.CityId == cityId && cvt.VehicleTypeId == vehicleTypeId); double pickUpTimeInMinutes = pickUpTime.TimeOfDay.TotalMinutes; int timeRangeIndex = cancellation.GetTimeRangeIndex(pickUpTimeInMinutes); if (RegionHelper.IsInnerJourney(db, booking)) { var cancellatioDateVehicleInner = db.CancellationDateVehicleInners.FirstOrDefault(v => v.CancellationDateId == date.Id && v.CityVehicleId == cityVehicleType.Id && v.TimeRangeIndex == timeRangeIndex); if (cancellatioDateVehicleInner == null) throw new ApplicationException(string.Format("No cancellation information for {0} {1} Inner", date.FareType.ToString(), cityVehicleType.VehicleType.Name)); int outside = cancellatioDateVehicleInner.GetOutside(booking.JourneyType); double fee = cancellatioDateVehicleInner.GetFee(booking.JourneyType); return new CancellationInfoResponse() { Outside = outside, Fee = fee }; } else { var cancellatioDateVehicleOuter = db.CancellationDateVehicleOuters.FirstOrDefault(v => v.CancellationDateId == date.Id && v.CityVehicleId == cityVehicleType.Id && v.TimeRangeIndex == timeRangeIndex); if (cancellatioDateVehicleOuter == null) throw new ApplicationException(string.Format("No cancellation information for {0} {1} Outer", date.FareType.ToString(), cityVehicleType.VehicleType.Name)); int outside = cancellatioDateVehicleOuter.GetOutside(booking.JourneyType); double fee = cancellatioDateVehicleOuter.GetFee(booking.JourneyType); return new CancellationInfoResponse() { Outside = outside, Fee = fee }; } } } catch (Exception ex) { var response = new CancellationInfoResponse(); response.AddError("Outside", "Cannot get cancellation info."); response.AddError("Outside", ex.Message); return response; } }
public void GivenNullPlate_GetMessage_ReturnsEmptyString([Values] FareType type) { Assert.That(type.GetMessage(null), Is.Empty); }
public string GivenTypeAndPlate_GetMessage_ReturnsExpectedMessage(FareType type, string plate) { return(type.GetMessage(plate)); }
public BookingResponse SaveBookingFareType(int bookingId, FareType fareType) { try { using (var db = new LomsContext()) { var booking = GetBooking(db, bookingId); booking.FareType = fareType; var promotionId = booking.FareInfo.Items.First(i => i.FareTypeId == (byte)fareType).PromotionId; booking.FarePromotionId = promotionId.HasValue ? promotionId.Value : 0; db.BookingPaymentItems.Where(p => p.BookingId == bookingId).ForEach(item => db.BookingPaymentItems.DeleteObject(item)); //remove charge info and incompleted credit card transactions var chargeInfo = db.BookingChargeInfoes.SingleOrDefault(ci => ci.BookingId == bookingId); if (chargeInfo != null) db.BookingChargeInfoes.DeleteObject(chargeInfo); db.BookingTransactionCreditCards.Where(p => p.BookingId == bookingId && p.OrderDateTime == null).ForEach(item => db.BookingTransactionCreditCards.DeleteObject(item)); db.Bookings.ApplyChanges(booking); db.SaveChanges(); booking = GetBooking2(db, bookingId); return new BookingResponse { Booking = booking }; } } catch (Exception ex) { var response = new BookingResponse(); response.AddError("Response", ex.ToString()); return response; } }
public static ObservableCollection<FareTypeRule> GetFareTypeRules(FareType fareType, double fee, string currencySymbol) { var rules = new ObservableCollection<FareTypeRule>(); switch (fareType) { //E-Fare case FareType.EFR: rules.Add(new FareTypeRule(RuleKey.PickupAddress, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.Date, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.FareType, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.Vehicle, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.TypeOfJourney, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.RefundableFare, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.LossofFare, ActionType.Yes, ActionType.Yes)); rules.Add(new FareTypeRule(RuleKey.CoS, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.PromoCode, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.PrimaryPassenger, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.Passengers, ActionType.Phone, ActionType.Phone)); rules.Add(new FareTypeRule(RuleKey.CancelFee, ActionType.TotalCharges, ActionType.TotalCharges)); break; //Saver case FareType.DSC: rules.Add(new FareTypeRule(RuleKey.PickupAddress, ActionType.Yes, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.Date, ActionType.Yes, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.FareType, ActionType.Yes, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.Vehicle, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.TypeOfJourney, ActionType.Phone, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.RefundableFare, ActionType.Yes, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.LossofFare, ActionType.No, ActionType.Yes)); rules.Add(new FareTypeRule(RuleKey.CoS, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.PromoCode, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.PrimaryPassenger, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.Passengers, ActionType.Yes, ActionType.Phone)); if (fee == 0) rules.Add(new FareTypeRule(RuleKey.CancelFee, ActionType.NA, ActionType.TotalCharges)); else rules.Add(new FareTypeRule(RuleKey.CancelFee, ActionType.Fee, ActionType.TotalCharges, string.Format("{0} {1:0.00}", currencySymbol, fee))); break; //FLEXI case FareType.NET: rules.Add(new FareTypeRule(RuleKey.PickupAddress, ActionType.Yes, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.Date, ActionType.Yes, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.FareType, ActionType.Yes, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.Vehicle, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.TypeOfJourney, ActionType.Phone, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.RefundableFare, ActionType.Yes, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.LossofFare, ActionType.No, ActionType.Yes)); rules.Add(new FareTypeRule(RuleKey.CoS, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.PromoCode, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.PrimaryPassenger, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.Passengers, ActionType.Yes, ActionType.Phone)); if (fee == 0) rules.Add(new FareTypeRule(RuleKey.CancelFee, ActionType.NA, ActionType.TotalCharges)); else rules.Add(new FareTypeRule(RuleKey.CancelFee, ActionType.Fee, ActionType.TotalCharges, string.Format("{0} {1:0.00}", currencySymbol, fee))); break; //PLUS case FareType.PRM: rules.Add(new FareTypeRule(RuleKey.PickupAddress, ActionType.Yes, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.Date, ActionType.Yes, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.FareType, ActionType.Yes, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.Vehicle, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.TypeOfJourney, ActionType.Phone, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.RefundableFare, ActionType.Yes, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.LossofFare, ActionType.No, ActionType.Yes)); rules.Add(new FareTypeRule(RuleKey.CoS, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.PromoCode, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.PrimaryPassenger, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.Passengers, ActionType.Yes, ActionType.Phone)); if (fee == 0) rules.Add(new FareTypeRule(RuleKey.CancelFee, ActionType.NA, ActionType.TotalCharges)); else rules.Add(new FareTypeRule(RuleKey.CancelFee, ActionType.Fee, ActionType.TotalCharges, string.Format("{0} {1:0.00}", currencySymbol, fee))); break; //FLEXI-A case FareType.COM: rules.Add(new FareTypeRule(RuleKey.PickupAddress, ActionType.Yes, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.Date, ActionType.Yes, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.FareType, ActionType.Yes, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.Vehicle, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.TypeOfJourney, ActionType.Phone, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.RefundableFare, ActionType.Yes, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.LossofFare, ActionType.No, ActionType.Yes)); rules.Add(new FareTypeRule(RuleKey.CoS, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.PromoCode, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.PrimaryPassenger, ActionType.No, ActionType.No)); rules.Add(new FareTypeRule(RuleKey.Passengers, ActionType.Yes, ActionType.Phone)); if (fee == 0) rules.Add(new FareTypeRule(RuleKey.CancelFee, ActionType.NA, ActionType.TotalCharges)); else rules.Add(new FareTypeRule(RuleKey.CancelFee, ActionType.Fee, ActionType.TotalCharges, string.Format("{0} {1:0.00}", currencySymbol, fee))); break; } return rules; }
public static string GetFareTypeName(FareType fareType) { string fareTypeName = String.Empty; switch (fareType) { //E-Fare case FareType.EFR: fareTypeName = "E-FARE"; break; //Saver case FareType.DSC: fareTypeName = "SAVER FARE"; break; //FLEXI case FareType.NET: fareTypeName = "FLEXI FARE"; break; //PLUS case FareType.PRM: fareTypeName = "PLUS FARE"; break; //FLEXI-A case FareType.COM: fareTypeName = "FLEXI-A FARE"; break; } return fareTypeName; }
public PTCFareBreakdownTypeFareInfo() { this._passengerFare = new FareType(); }