// // GET: /Admin/Rate/ public ActionResult Index(long?id) { try{ Models.RateModel data = new Models.RateModel(); if (!id.HasValue) { id = 0; } else { data.Rates = BLayer.Rate.GetAll(id.Value); data.PropertyId = BLayer.Accommodation.GetPropertyId(id.Value); CLayer.RateCommission rc = BLayer.Property.GetCommission(data.PropertyId); data.Commission.ComPropertyId = data.PropertyId; data.Commission.B2CLongTerm = rc.B2CLongTerm; data.Commission.B2CShortTerm = rc.B2CShortTerm; data.Commission.B2BLongTerm = rc.B2BLongTerm; data.Commission.B2BShortTerm = rc.B2BShortTerm; } data.RateAccommodationId = id.Value; return(View(data)); }catch (Exception ex) { Common.LogHandler.HandleError(ex); return(RedirectToAction("Index", "ErrorPage")); } }
//[Required(ErrorMessage = "Required")] //[Range(0, 100.00, ErrorMessage = "Invalid")] //public decimal CommissionBA {get;set;} public void TakeCopy(CLayer.RateCommission data) { B2BShortTerm = data.B2BShortTerm; B2BLongTerm = data.B2BLongTerm; B2CLongTerm = data.B2CLongTerm; B2CShortTerm = data.B2CShortTerm; ComPropertyId = data.PropertyId; CancellationType = (int)CLayer.ObjectStatus.CancellationType.FixedNight; }
public static void SetCommission(CLayer.RateCommission commission) { DataLayer.Property prperty = new DataLayer.Property(); if (commission.B2CShortTerm <= 0) { commission.B2CShortTerm = commission.B2CShortTerm; } if (commission.B2CLongTerm <= 0) { commission.B2CLongTerm = commission.B2CLongTerm; } if (commission.B2BShortTerm <= 0) { commission.B2BShortTerm = commission.B2BShortTerm; } if (commission.B2BLongTerm <= 0) { commission.B2BLongTerm = commission.B2BLongTerm; } prperty.SetCommission(commission); }
public string SaveAccRate(Models.RateValueModel data) { CLayer.Rates rat = new CLayer.Rates(); rat.RateId = data.RRateId; rat.AccommodationId = data.AccommodationId; long uid = 0; long.TryParse(User.Identity.GetUserId(), out uid); //Get commission CLayer.RateCommission rc = BLayer.Property.GetCommission(BLayer.Accommodation.GetPropertyId(data.AccommodationId)); if (rc == null) { return("false"); } rat.UpdatedBy = uid; //find dates int days = DateTime.DaysInMonth(2014, data.StartMonth); if (days < data.StartDay) { data.StartDay = days; } rat.StartDate = new DateTime(DateTime.Today.Year, data.StartMonth, data.StartDay); days = DateTime.DaysInMonth(2014, data.EndMonth); if (days < data.EndDay) { data.EndDay = days; } rat.EndDate = new DateTime(DateTime.Today.Year, data.EndMonth, data.EndDay); //Save Regular rate rat.RateFor = (int)CLayer.Role.Roles.Customer; rat.RateId = data.RRateId; rat.DailyRate = data.RCDaily; rat.WeeklyRate = data.RCWeekly; rat.MonthlyRate = data.RCMonthly; rat.LongTermRate = data.RCLong; rat.GuestRate = data.RCGuest; BLayer.Rate.Save(rat); // Corporate rat.RateFor = (int)CLayer.Role.Roles.Corporate; rat.RateId = data.CRateId; rat.DailyRate = data.CCDaily; rat.WeeklyRate = data.CCWeekly; rat.MonthlyRate = data.CCMonthly; rat.LongTermRate = data.CCLong; rat.GuestRate = data.CCGuest; BLayer.Rate.Save(rat); ////Supplier //rat.RateFor = (int)CLayer.Role.Roles.Supplier; //rat.RateId = data.SRateId; //rat.DailyRate = data.SCDaily; //rat.WeeklyRate = data.SCWeekly; //rat.MonthlyRate = data.SCMonthly; //rat.GuestRate = data.SCGuest; //BLayer.Rate.Save(rat, rc.Supplier); ////Travel Agent //rat.RateFor = (int)CLayer.Role.Roles.Agent; //rat.RateId = data.TRateId; //rat.DailyRate = data.TCDaily; //rat.WeeklyRate = data.TCWeekly; //rat.MonthlyRate = data.TCMonthly; //rat.GuestRate = data.TCGuest; //BLayer.Rate.Save(rat, rc.TravelA); return("true"); }
public static List <CLayer.Rates> GetTotalRates(List <long> accIds, DateTime checkIn, DateTime checkOut, CLayer.Role.Roles rateType, long loggedInUserId, long InventoryAPIID) { List <CLayer.Rates> arates; StringBuilder ids = new StringBuilder(); bool isCorporate = false; long TAMInventoryAPIID = InventoryAPIID; long corpId = 0; if (rateType == CLayer.Role.Roles.Corporate) { CLayer.Role.Roles rle = BLayer.User.GetRole(loggedInUserId); if (rle == CLayer.Role.Roles.CorporateUser) { corpId = BLayer.B2B.GetCorporateIdOfUser(loggedInUserId); } else { corpId = loggedInUserId; } isCorporate = true; } foreach (long id in accIds) { ids.Append(","); ids.Append(id); } ids.Remove(0, 1); List <CLayer.Rates> result = new List <CLayer.Rates>(); if (TAMInventoryAPIID == 4 || TAMInventoryAPIID == 5) { arates = GetAccommodationRatesForAPI(ids.ToString(), checkIn, checkOut, rateType); } else { arates = GetAccommodationRates(ids.ToString(), checkIn, checkOut, rateType); } DateTime currentDate; decimal total, currate, curguest_rate, guest, PurchaseRateaAfterTaxs, totalPurchaseRateAfterTaxs, PurchaseRateBeforeTax, SellRateAfterTax, SellRateBeforeTax, Prch_Rate_AT, Prch_Rate_ATX, PurchaseRateAfterTax; int cnt, idx; int days = (checkOut - checkIn).Days; long propertyId = BLayer.Accommodation.GetPropertyId(accIds[0]); int inventory = 0; CLayer.Discount dicnt = null; if (isCorporate) { dicnt = BLayer.Discount.GetDiscount(corpId, propertyId); } CLayer.RateCommission rc = BLayer.Property.GetCommission(propertyId); List <CLayer.Offers> propertyOffers = BLayer.Offers.GetForPropertyCalc(propertyId, checkIn, checkOut); bool hasPrOffers = (propertyOffers.Count > 0); List <CLayer.Offers> accOffers; CLayer.Offers propOffer = null; if (hasPrOffers) { propOffer = propertyOffers[0]; } CLayer.Offers curOffer = null; DateTime offEndDate, offStartDate; offStartDate = offEndDate = DateTime.Today; List <CLayer.BookingItemOffer> appliedOffers; List <CLayer.Rates.RateValues> bookingRates; int noOfDays = (checkOut - checkIn).Days; int reduceDateBy = 0; int calcDays = 0; long curOfferId = 0; decimal curOldRate = 0; List <DateTime> freeDays = new List <DateTime>(); bool freeDaysExist = false; foreach (long id in accIds) { List <CLayer.Rates> accrates = arates.Where(m => m.AccommodationId == id).OrderBy(x => x.StartDate).ToList(); cnt = accrates.Count(); if (cnt > 0) { inventory = accrates[0].NoofAcc; } else { inventory = 0; result.Add(new CLayer.Rates() { Amount = 0, GuestRate = 0, AccommodationId = id, NoofAcc = 0, RateChanges = new List <CLayer.Rates.RateValues>(), //FirstDayCharge = fctotal, SBMarkup = 0, CorpDiscount = 0, AppliedOffers = new List <CLayer.BookingItemOffer>() }); continue; } accOffers = BLayer.Offers.GetForAccommodationCalc(id, checkIn, checkOut); appliedOffers = new List <CLayer.BookingItemOffer>(); curOffer = null; bookingRates = new List <CLayer.Rates.RateValues>(); if (accOffers.Count > 0) { curOffer = accOffers[0]; } else { curOffer = null; if (hasPrOffers) { curOffer = propOffer; } } curOfferId = 0; currentDate = checkIn; total = 0; guest = 0; PurchaseRateaAfterTaxs = 0; totalPurchaseRateAfterTaxs = 0; currate = 0; curOldRate = 0; curguest_rate = 0; SellRateBeforeTax = 0; PurchaseRateBeforeTax = 0; Prch_Rate_AT = 0; Prch_Rate_ATX = 0; PurchaseRateAfterTax = 0; SellRateAfterTax = 0; freeDays.Clear(); //calculate if free nights offer is available.. reduceDateBy = 0; if (curOffer != null && (!isCorporate)) //offer is not available for corporate { //find offer applicable date if (checkIn > curOffer.StartDate) { offStartDate = checkIn; } else { offStartDate = curOffer.StartDate; } if (checkOut < curOffer.EndDate) { offEndDate = checkOut; } else { offEndDate = curOffer.EndDate; } if (curOffer.RateType == (int)CLayer.ObjectStatus.OfferRateType.OfferFreeRate) { int tot = curOffer.FreeDays + curOffer.NoOfDays; //total days -Example: for 4 days booking 2 days free.. So total - minimum- 6days booking should be there int hwmany = 0; calcDays = (offEndDate - offStartDate).Days; if (calcDays >= tot) { hwmany = calcDays / tot; reduceDateBy = hwmany * curOffer.FreeDays; // currentDate = currentDate.AddDays(reduceDateBy); //reduce freedays from calculation if (reduceDateBy == 1) { if (offEndDate == checkOut) { offEndDate = offEndDate.AddDays(-1); } if (offEndDate >= checkIn) { freeDays.Add(offEndDate); } } else if (reduceDateBy > 1) { if (offEndDate == checkOut) { offEndDate = offEndDate.AddDays(-1); } while (reduceDateBy > 0) { if (offEndDate >= checkIn) { freeDays.Add(offEndDate); } offEndDate.AddDays(-1 * reduceDateBy); reduceDateBy--; } } //to do offer applied markit curOfferId = curOffer.OfferId; appliedOffers.Add(new CLayer.BookingItemOffer() { OfferId = curOffer.OfferId, OfferTitle = curOffer.Title, AccommodationId = id }); } curOffer = null; //avoid checking other offer types } } freeDaysExist = (freeDays.Count > 0); // find tax here decimal tax = BLayer.PropertyTax.GetTotalTax(propertyId); while (currentDate < checkOut) { //never reset currate or curguest_rate here, if a rate is not found for the date then old rate is used for (idx = 0; idx < cnt; idx++) { if (currentDate >= accrates[idx].StartDate && currentDate <= accrates[idx].EndDate) { currate = accrates[idx].Amount; curguest_rate = accrates[idx].GuestRate; PurchaseRateaAfterTaxs = accrates[idx].PurchaseRateAfterTax; Prch_Rate_AT = accrates[idx].PurchaseRateAfterTax; break; } } if (curOldRate != currate) { bookingRates.Add(new CLayer.Rates.RateValues() { StartDate = currentDate.ToShortDateString(), DayCharge = (double)currate, DayGuestCharge = (double)curguest_rate, DayTotalCharge = 0, DayTotalGuestCharge = 0 }); curOldRate = currate; } if (curOffer != null && (!isCorporate)) { if (currentDate >= offStartDate && currentDate <= offEndDate) { if (curOfferId != curOffer.OfferId && curOfferId != 0) { curOfferId = curOffer.OfferId; appliedOffers.Add(new CLayer.BookingItemOffer() { OfferId = curOffer.OfferId, OfferTitle = curOffer.Title, AccommodationId = id }); } switch ((CLayer.ObjectStatus.OfferRateType)curOffer.RateType) { case CLayer.ObjectStatus.OfferRateType.OfferFlatRate: total = total + curOffer.Amount; guest = guest + curguest_rate; break; case CLayer.ObjectStatus.OfferRateType.OfferPercentageRate: total = Math.Round(total + (currate - (currate * curOffer.Amount / 100))); guest = Math.Round(guest + (curguest_rate - (curguest_rate * curOffer.Amount / 100))); break; } } else { total = total + currate; totalPurchaseRateAfterTaxs = totalPurchaseRateAfterTaxs + PurchaseRateaAfterTaxs; guest = guest + curguest_rate; Prch_Rate_ATX = Prch_Rate_ATX + Prch_Rate_AT; } } else { //perform calculations here if (freeDaysExist) { if (!freeDays.Contains(currentDate)) { total = total + currate; totalPurchaseRateAfterTaxs = totalPurchaseRateAfterTaxs + PurchaseRateaAfterTaxs; guest = guest + curguest_rate; Prch_Rate_ATX = Prch_Rate_ATX + Prch_Rate_AT; } } else { total = total + currate; totalPurchaseRateAfterTaxs = totalPurchaseRateAfterTaxs + PurchaseRateaAfterTaxs; guest = guest + curguest_rate; Prch_Rate_ATX = Prch_Rate_ATX + Prch_Rate_AT; } } currentDate = currentDate.AddDays(1); } decimal CalcTotalTax = Math.Round((total * tax) / 100); decimal CalcGuestTax = Math.Round((guest * tax) / 100); //reduce tax from supplier rate SellRateAfterTax = total; total = Math.Round(total / (1 + (tax / 100))); guest = Math.Round(guest / (1 + (tax / 100))); totalPurchaseRateAfterTaxs = Math.Round(totalPurchaseRateAfterTaxs / (1 + (tax / 100))); SellRateBeforeTax = totalPurchaseRateAfterTaxs; PurchaseRateBeforeTax = total; PurchaseRateAfterTax = Prch_Rate_ATX; //calculate corp discount and SB Markup here.. //SB Markup decimal SBMarkup_rate = 0; decimal SBMarkup_guest = 0; if (days < CLayer.Rates.LONG_TERM_DAYS) { if (isCorporate) { SBMarkup_rate = Math.Round(total * ((decimal)rc.B2BShortTerm) / 100); SBMarkup_guest = Math.Round(guest * ((decimal)rc.B2BShortTerm) / 100); //first day charge //diff rates calculation for (int ai = 0; ai < bookingRates.Count; ai++) { bookingRates[ai].DayTotalCharge = bookingRates[ai].DayCharge + Math.Round(bookingRates[ai].DayCharge * rc.B2BShortTerm / 100); bookingRates[ai].DayTotalGuestCharge = bookingRates[ai].DayGuestCharge + Math.Round(bookingRates[ai].DayGuestCharge * rc.B2BShortTerm / 100); } } else { if (TAMInventoryAPIID == 4 || TAMInventoryAPIID == 5) { SBMarkup_rate = Math.Round(total - totalPurchaseRateAfterTaxs); SBMarkup_guest = Math.Round(guest * ((decimal)rc.B2CShortTerm) / 100); } else { SBMarkup_rate = Math.Round(total * ((decimal)rc.B2CShortTerm) / 100); SBMarkup_guest = Math.Round(guest * ((decimal)rc.B2CShortTerm) / 100); } ////first day charge for (int ai = 0; ai < bookingRates.Count; ai++) { bookingRates[ai].DayTotalCharge = bookingRates[ai].DayCharge + Math.Round(bookingRates[ai].DayCharge * rc.B2CShortTerm / 100); bookingRates[ai].DayTotalGuestCharge = bookingRates[ai].DayGuestCharge + Math.Round(bookingRates[ai].DayGuestCharge * rc.B2CShortTerm / 100); } } } else { if (isCorporate) { SBMarkup_rate = Math.Round(total * ((decimal)rc.B2BLongTerm) / 100); SBMarkup_guest = Math.Round(guest * ((decimal)rc.B2BLongTerm) / 100); //first day charge //diff rates calc for (int ai = 0; ai < bookingRates.Count; ai++) { bookingRates[ai].DayTotalCharge = bookingRates[ai].DayTotalCharge + Math.Round(bookingRates[ai].DayCharge * rc.B2BLongTerm / 100); bookingRates[ai].DayTotalGuestCharge = bookingRates[ai].DayTotalGuestCharge + Math.Round(bookingRates[ai].DayGuestCharge * rc.B2BLongTerm / 100); } } else { if (TAMInventoryAPIID == 4 || TAMInventoryAPIID == 5) { SBMarkup_rate = Math.Round(total - totalPurchaseRateAfterTaxs); SBMarkup_guest = Math.Round(guest * ((decimal)rc.B2CLongTerm) / 100); } else { SBMarkup_rate = Math.Round(total * ((decimal)rc.B2CLongTerm) / 100); SBMarkup_guest = Math.Round(guest * ((decimal)rc.B2CLongTerm) / 100); } //diff rates calc for (int ai = 0; ai < bookingRates.Count; ai++) { bookingRates[ai].DayTotalCharge = bookingRates[ai].DayTotalCharge + Math.Round(bookingRates[ai].DayCharge * rc.B2CLongTerm / 100); bookingRates[ai].DayTotalGuestCharge = bookingRates[ai].DayTotalGuestCharge + Math.Round(bookingRates[ai].DayGuestCharge * rc.B2CLongTerm / 100); } } } //Corporate Discount decimal add_discount = 0; decimal base_discount = 0; decimal guest_add_discount = 0; decimal guest_base_discount = 0; if (isCorporate) { if (days < CLayer.Rates.LONG_TERM_DAYS) { if (dicnt.ShortTermRate > 0) { add_discount = Math.Round(total * (decimal)dicnt.ShortTermRate / 100); guest_add_discount = Math.Round(guest * (decimal)dicnt.ShortTermRate / 100); //first day charge //individual rates for (int ai = 0; ai < bookingRates.Count; ai++) { bookingRates[ai].DayTotalCharge = bookingRates[ai].DayTotalCharge - Math.Round(bookingRates[ai].DayCharge * dicnt.ShortTermRate / 100); bookingRates[ai].DayTotalGuestCharge = bookingRates[ai].DayTotalGuestCharge - Math.Round(bookingRates[ai].DayGuestCharge * dicnt.ShortTermRate / 100); } } if (dicnt.BaseShortTerm > 0) { base_discount = Math.Round(total * (decimal)dicnt.BaseShortTerm / 100); guest_base_discount = Math.Round(guest * (decimal)dicnt.BaseShortTerm / 100); //first day charge for (int ai = 0; ai < bookingRates.Count; ai++) { bookingRates[ai].DayTotalCharge = bookingRates[ai].DayTotalCharge - Math.Round(bookingRates[ai].DayCharge * dicnt.BaseShortTerm / 100, 2); bookingRates[ai].DayTotalGuestCharge = bookingRates[ai].DayTotalGuestCharge - Math.Round(bookingRates[ai].DayGuestCharge * dicnt.BaseShortTerm / 100, 2); } } } else { if (dicnt.LongTermRate > 0) { add_discount = Math.Round(total * (decimal)dicnt.LongTermRate / 100); guest_add_discount = Math.Round(guest * (decimal)dicnt.LongTermRate / 100); //first day charge //diff rates calc for (int ai = 0; ai < bookingRates.Count; ai++) { bookingRates[ai].DayTotalCharge = bookingRates[ai].DayTotalCharge - Math.Round(bookingRates[ai].DayCharge * dicnt.LongTermRate / 100); bookingRates[ai].DayTotalGuestCharge = bookingRates[ai].DayTotalGuestCharge - Math.Round(bookingRates[ai].DayGuestCharge * dicnt.LongTermRate / 100); } } if (dicnt.BaseLongTerm > 0) { base_discount = Math.Round(total * (decimal)dicnt.BaseLongTerm / 100); guest_add_discount = Math.Round(guest * (decimal)dicnt.BaseLongTerm / 100); //first day charge //diff rates calc for (int ai = 0; ai < bookingRates.Count; ai++) { bookingRates[ai].DayTotalCharge = bookingRates[ai].DayTotalCharge - Math.Round(bookingRates[ai].DayCharge * dicnt.BaseLongTerm / 100); bookingRates[ai].DayTotalGuestCharge = bookingRates[ai].DayTotalGuestCharge - Math.Round(bookingRates[ai].DayGuestCharge * dicnt.BaseLongTerm / 100); } } } } decimal suppRate = total; decimal suppGuestRate = guest; if (TAMInventoryAPIID == 4 || TAMInventoryAPIID == 5) { total = Math.Round(total); guest = Math.Round(guest + SBMarkup_guest - guest_add_discount - guest_base_discount); } else { total = Math.Round(total + SBMarkup_rate - add_discount - base_discount); guest = Math.Round(guest + SBMarkup_guest - guest_add_discount - guest_base_discount); } //find tax on total amount and guest rate decimal totaltax = (total * tax) / 100; decimal guesttax = (guest * tax) / 100; result.Add(new CLayer.Rates() { SupplierRate = suppRate + CalcTotalTax, SupplierGuestRate = guest + CalcGuestTax, Amount = total, GuestRate = guest, AccommodationId = id, NoofAcc = inventory, RateChanges = bookingRates, //FirstDayCharge = fctotal, SBMarkup = SBMarkup_rate, //(SBMarkup_rate + SBMarkup_guest), SBGuestMarkup = SBMarkup_guest, CorpDiscount = (add_discount + base_discount), CorpGuestDiscount = (guest_add_discount + guest_base_discount), AppliedOffers = appliedOffers, TotalRateTax = totaltax, TotalGuestTax = guesttax, PurchaseRateAfterTax = PurchaseRateAfterTax, SellRateBeforeTax = PurchaseRateBeforeTax, PurchaseRateBeforeTax = SellRateBeforeTax, SellRateAfterTax = SellRateAfterTax }); } return(result); }