public static double CalculateTotalBalance(Guid reservationId) { double dblTotalBalance = 0; ReservationRepository reservationRepository = new ReservationRepository(); var reservation = reservationRepository.GetReservationById(reservationId, LogInManager.LoggedInUserId).FirstOrDefault(); ReservationChargeRepository reservationChargeRepository = new ReservationChargeRepository(); if (reservation != null) { if (reservation.IsCheckIn == true) { //Reservation Charges var reservationCharges = reservationChargeRepository.GetReservationCharges(reservationId, null, LogInManager.LoggedInUserId); if (reservationCharges != null && reservationCharges.Count > 0) { var totalReservationCharges = reservationCharges.Where(m => m.Amount.HasValue) .Sum(m => (m.Amount.Value * (m.Qty.HasValue ? m.Qty.Value : 1))); dblTotalBalance += totalReservationCharges; dblTotalBalance = CurrencyManager.ConvertAmountToBaseCurrency(dblTotalBalance, LogInManager.CurrencyCode); } } else { double totalRoomRentCharge = 0; //totalRoomRentCharge = CalculateRoomRentCharges(reservation.NoOfNight, (reservation.Rate.HasValue ? reservation.Rate.Value : 0), reservation.NoOfChildren, reservation.DiscountAmount, reservation.DiscountPercentage, (reservation.DiscountPercentage.HasValue ? true : false)); totalRoomRentCharge = CalculateReservationTotalPrice(reservation.Id); dblTotalBalance = totalRoomRentCharge; ////Package Price //var packageDetails = reservationRepository.GetReservationPackageMapping(reservation.Id, null); //if (packageDetails != null && packageDetails.Count > 0) //{ // var totalPackagePrice = packageDetails.Where(m => m.PackagePrice.HasValue).Sum(m => m.PackagePrice); // dblTotalBalance += (totalPackagePrice.HasValue) ? totalPackagePrice.Value : 0; //} } } return(Math.Round(dblTotalBalance, 2)); }
public ActionResult ReverseCheckIn(Guid reservationId, string source = "") { try { var reservation = reservationRepository.GetReservationById(reservationId, LogInManager.LoggedInUserId).FirstOrDefault(); if (reservation != null) { #region Remove Rent Charges var roomRentCharge = additionalChargeRepository.GetAdditionalChargesByCode(AdditionalChargeCode.ROOM_RENT).FirstOrDefault(); var reservationCharge = reservationChargeRepository.GetReservationCharges(reservation.Id, roomRentCharge.Id, LogInManager.LoggedInUserId).FirstOrDefault(); if (reservationCharge != null) { reservationChargeRepository.DeleteReservationCharges(reservationCharge.Id, LogInManager.LoggedInUserId, LogInManager.LoggedInUserId); } #endregion #region Remove Reservation Charges reservationChargeRepository.DeleteReservationChargesByReservation(reservation.Id, LogInManager.LoggedInUserId, LogInManager.LoggedInUserId); #endregion #region Remove Reservation Log (Room Occupied) reservationLogRepository.DeleteReservationLogByReservation(reservation.Id, LogInManager.LoggedInUserId, LogInManager.LoggedInUserId); #endregion #region Update Reservation Check In Flag (FALSE) reservationRepository.UpdateReservationCheckInFlag(reservation.Id, false, LogInManager.LoggedInUserId); #endregion #region Remove Check In Details checkInCheckOutRepository.DeleteCheckInCheckOutDetailByReservation(reservation.Id, LogInManager.LoggedInUserId, LogInManager.LoggedInUserId); #endregion #region Update Reservation Status (NULL) reservationRepository.UpdateReservationStatus(reservation.Id, null, LogInManager.LoggedInUserId); #endregion #region Update Reservation Total Price double totalPrice = Utility.Utility.CalculateReservationTotalPrice(reservation.Id); //Update Total Price. reservationRepository.UpdateReservationTotalPrice(reservation.Id, totalPrice, LogInManager.LoggedInUserId); #endregion #region Update Reservation Total Balance. double totalGuestBalance = 0; //totalGuestBalance = Utility.Utility.CalculateTotalBalance(reservation.Id); //Update Total Balance. reservationRepository.UpdateReservationTotalBalance(reservation.Id, totalGuestBalance, LogInManager.LoggedInUserId); #endregion #region Update TrackReservationLog Status = False reservationRepository.UpdateTrackReservationLogStatusByReservationId(reservation.Id, false); #endregion #region Record Activity Log RecordActivityLog.RecordActivity(Pages.CHECKIN, string.Format("Reverse Checked in profile successfully. Name: {0} {1}, Comfirmation #: {2} ", reservation.LastName, reservation.FirstName, reservation.ConfirmationNumber)); #endregion return(Json(new { IsSuccess = true, data = new { ReservationId = reservationId } }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { IsSuccess = false, errorMessage = "Reverse check in not done successfully." }, JsonRequestBehavior.AllowGet)); } } catch (Exception e) { Utility.Utility.LogError(e, "ReverseCheckIn"); return(Json(new { IsSuccess = false, errorMessage = e.Message })); } }