public string UpdateReservationCharges(ReservationChargeVM reservationCharge)
        {
            string chargeId = string.Empty;

            SqlParameter[] parameters =
            {
                new SqlParameter {
                    ParameterName = "@Id", Value = reservationCharge.Id
                },
                new SqlParameter {
                    ParameterName = "@ReservationId", Value = reservationCharge.ReservationId
                },
                new SqlParameter {
                    ParameterName = "@AdditionalChargeId", Value = reservationCharge.AdditionalChargeId
                },
                new SqlParameter {
                    ParameterName = "@Code", Value = reservationCharge.Code
                },
                new SqlParameter {
                    ParameterName = "@Description", Value = reservationCharge.Description
                },
                new SqlParameter {
                    ParameterName = "@TransactionDate", Value = reservationCharge.TransactionDate
                },
                new SqlParameter {
                    ParameterName = "@Amount", Value = reservationCharge.Amount
                },
                new SqlParameter {
                    ParameterName = "@Qty", Value = reservationCharge.Qty
                },
                new SqlParameter {
                    ParameterName = "@Supplement", Value = reservationCharge.Supplement
                },
                new SqlParameter {
                    ParameterName = "@Reference", Value = reservationCharge.Reference
                },
                new SqlParameter {
                    ParameterName = "@AdditionalChargeSource", Value = reservationCharge.AdditionalChargeSource
                },
                new SqlParameter {
                    ParameterName = "@IsActive", Value = reservationCharge.IsActive
                },
                new SqlParameter {
                    ParameterName = "@UpdatedBy", Value = reservationCharge.UpdatedBy
                }
            };

            chargeId = Convert.ToString(DALHelper.ExecuteScalar("UpdateReservationCharges", parameters));

            return(chargeId);
        }
        public string AddReservationCharges(ReservationChargeVM reservationCharge)
        {
            string chargeId = string.Empty;

            SqlParameter[] parameters =
            {
                new SqlParameter {
                    ParameterName = "@ReservationId", Value = reservationCharge.ReservationId
                },
                new SqlParameter {
                    ParameterName = "@AdditionalChargeId", Value = reservationCharge.AdditionalChargeId
                },
                new SqlParameter {
                    ParameterName = "@PaymentMethodId", Value = reservationCharge.PaymentMethodId
                },
                new SqlParameter {
                    ParameterName = "@Code", Value = reservationCharge.Code
                },
                new SqlParameter {
                    ParameterName = "@Description", Value = reservationCharge.Description
                },
                new SqlParameter {
                    ParameterName = "@TransactionDate", Value = reservationCharge.TransactionDate
                },
                new SqlParameter {
                    ParameterName = "@Amount", Value = reservationCharge.Amount
                },
                new SqlParameter {
                    ParameterName = "@Qty", Value = reservationCharge.Qty
                },
                new SqlParameter {
                    ParameterName = "@Supplement", Value = reservationCharge.Supplement
                },
                new SqlParameter {
                    ParameterName = "@Reference", Value = reservationCharge.Reference
                },
                new SqlParameter {
                    ParameterName = "@AdditionalChargeSource", Value = reservationCharge.AdditionalChargeSource
                },
                new SqlParameter {
                    ParameterName = "@IsActive", Value = reservationCharge.IsActive
                },
                new SqlParameter {
                    ParameterName = "@CreatedBy", Value = reservationCharge.CreatedBy
                },
                new SqlParameter {
                    ParameterName = "@CreditCardNo", Value = reservationCharge.CreditCardNo
                },
                new SqlParameter {
                    ParameterName = "@CardExpiryDate", Value = reservationCharge.CardExpiryDate
                },
                new SqlParameter {
                    ParameterName = "@CVVNo", Value = reservationCharge.CVVNo
                },
                new SqlParameter {
                    ParameterName = "IsDummyReservationPayment", Value = reservationCharge.IsDummyReservationPayment
                }
            };

            chargeId = Convert.ToString(DALHelper.ExecuteScalar("AddReservationCharges", parameters));

            return(chargeId);
        }
        public ActionResult CheckIn(CheckInPaymentMethodVM model)
        {
            try
            {
                if (!string.IsNullOrWhiteSpace(model.RoomIds))
                {
                    string strETAText = "10:00";
                    if (!string.IsNullOrWhiteSpace(model.CheckInTimeText))
                    {
                        strETAText = model.CheckInTimeText;
                    }

                    var checkReservationOrNot = reservationRepository.GetPreviousReservationOrNot(Guid.Parse(model.RoomIds), model.CheckInDate, TimeSpan.Parse(strETAText), null, LogInManager.LoggedInUserId);
                    if (checkReservationOrNot != null && checkReservationOrNot.Count > 0)
                    {
                        return(Json(new
                        {
                            IsSuccess = false,
                            IsReservation = true,
                            errorMessage = "Selected room already checked in by another user. please select check in (ETA) time after " + checkReservationOrNot.Select(m => m.DepartureDate != null ? m.DepartureDate.Value.ToString("dd MMM yyyy") : null).FirstOrDefault() + " " + checkReservationOrNot.Select(m => m.CheckOutTime != null ? m.CheckOutTime : null).FirstOrDefault() + ""
                        }, JsonRequestBehavior.AllowGet));
                    }
                }
                CheckInCheckOutVM   checkIn           = new CheckInCheckOutVM();
                ReservationChargeVM reservationCharge = new ReservationChargeVM();

                //Get Reservation detail.
                var reservation = reservationRepository.GetReservationById(model.ReservationId, LogInManager.LoggedInUserId).FirstOrDefault();

                if (reservation != null)
                {
                    reservation.PaymentMethodId = model.PaymentMethodId;

                    //Encrypt Credit Card#
                    reservation.CreditCardNo = Utility.Utility.Encrypt(model.CreditCardNo, Utility.Utility.EncryptionKey);

                    reservation.CardExpiryDate = model.CardExpiryDate;
                    reservation.ArrivalDate    = model.CheckInDate;
                    if (model.RoomTypeId.HasValue)
                    {
                        reservation.RoomTypeId = model.RoomTypeId.Value;
                    }


                    DateTime dtDepartureDate;
                    dtDepartureDate           = model.CheckInDate.Value.AddDays(reservation.NoOfNight);
                    reservation.DepartureDate = dtDepartureDate;

                    string   CheckInTimeText = model.CheckInTimeText;
                    TimeSpan checkInTime     = new TimeSpan();
                    if (!string.IsNullOrWhiteSpace(CheckInTimeText))
                    {
                        string   todayDate = DateTime.Now.ToString("dd/MM/yyyy");
                        string   date      = (todayDate + " " + CheckInTimeText);
                        DateTime time      = Convert.ToDateTime(date);
                        checkInTime = time.TimeOfDay;

                        reservation.ETA = checkInTime;
                    }

                    if (reservation.ETA.HasValue)
                    {
                        checkInTime = reservation.ETA.Value;
                    }

                    reservation.UpdatedBy = LogInManager.LoggedInUserId;
                    reservationRepository.UpdateReservation(reservation);

                    #region Save Room Rent Charges

                    double totalPrice = Utility.Utility.CalculateReservationTotalPrice(reservation.Id);

                    var roomRentCharge = additionalChargeRepository.GetAdditionalChargesByCode(AdditionalChargeCode.ROOM_RENT).FirstOrDefault();

                    reservationCharge = new ReservationChargeVM();
                    reservationCharge.ReservationId          = reservation.Id;
                    reservationCharge.AdditionalChargeId     = roomRentCharge.Id;
                    reservationCharge.AdditionalChargeSource = AdditionalChargeSource.ADDITIONAL_CHARGE;
                    reservationCharge.Code            = roomRentCharge.Code;
                    reservationCharge.Description     = roomRentCharge.Description;
                    reservationCharge.TransactionDate = reservation.ArrivalDate;
                    reservationCharge.Amount          = totalPrice;
                    reservationCharge.Qty             = 1;
                    reservationCharge.IsActive        = true;
                    reservationCharge.CreatedBy       = LogInManager.LoggedInUserId;

                    reservationChargeRepository.AddReservationCharges(reservationCharge);

                    #endregion

                    #region Save Reservation Room Mapping & Update Room Occupied Flag

                    var roomIds = model.RoomIds;

                    string[] roomIdsArr = null;
                    if (!string.IsNullOrWhiteSpace(roomIds))
                    {
                        roomIdsArr = roomIds.Split(',');
                        if (roomIdsArr != null)
                        {
                            //Remove Duplication.
                            roomIdsArr = roomIdsArr.Distinct().ToArray();
                        }
                    }

                    //Delete Existing Reservation Room Mapping.
                    //roomRepository.DeleteReservationRoomMappingByReservation(reservation.Id, LogInManager.LoggedInUserId);

                    #region Delete Room Mapping

                    var roomMappings = roomRepository.GetReservationRoomMapping(reservation.Id, null, LogInManager.LoggedInUserId);

                    if (roomMappings != null && roomMappings.Count > 0)
                    {
                        List <Guid> roomMappingIds = new List <Guid>();

                        foreach (var roomMapping in roomMappings)
                        {
                            if (roomMapping.RoomId.HasValue)
                            {
                                if (roomIdsArr == null || !roomIdsArr.Contains(roomMapping.RoomId.Value.ToString()))
                                {
                                    roomMappingIds.Add(roomMapping.Id);
                                }
                            }
                        }

                        //Delete Room Mapping
                        if (roomMappingIds != null && roomMappingIds.Count > 0)
                        {
                            foreach (var mappingId in roomMappingIds)
                            {
                                roomRepository.DeleteReservationRoomMapping(mappingId, LogInManager.LoggedInUserId, LogInManager.LoggedInUserId);
                            }
                        }
                    }

                    #endregion


                    if (roomIdsArr != null)
                    {
                        foreach (var item in roomIdsArr)
                        {
                            //Save Reservation Room Mapping.
                            ReservationRoomMappingVM reservationRoomMapping = new ReservationRoomMappingVM();
                            reservationRoomMapping.RoomId        = Guid.Parse(item.Trim());
                            reservationRoomMapping.ReservationId = reservation.Id;
                            reservationRoomMapping.CreatedBy     = LogInManager.LoggedInUserId;
                            reservationRoomMapping.UpdatedBy     = LogInManager.LoggedInUserId;

                            roomRepository.AddUpdateReservationRoomMapping(reservationRoomMapping);

                            ////Update Room Occupied Flag.
                            //roomRepository.UpdateRoomOccupiedFlag(Guid.Parse(item.Trim()), true, LogInManager.LoggedInUserId);

                            ////Update Room Status CLEAN to DIRTY.
                            //roomRepository.UpdateRoomCheckInStatus(Guid.Parse(item.Trim()), Guid.Parse(RoomStatusType.DIRTY), true, LogInManager.LoggedInUserId);

                            //Commented by Raju: 22-JUNE-2018 (Due to functionality change)
                            //#region Remove Existing Reservation & Room Mapping (Who selected this Room# but not checked in yet.)
                            //reservationRepository.DeleteReservationAndRoomMappingByRoom(Guid.Parse(item.Trim()), reservation.Id, LogInManager.LoggedInUserId, LogInManager.LoggedInUserId);
                            //#endregion
                            //Commented by Raju: 22-JUNE-2018 (Due to functionality change)

                            //#region Remove Existing Reservation who did just booking but not checked-in yet.

                            //var reservationRoomMappingDetails = roomRepository.GetReservationRoomMappingByRoom(Guid.Parse(item.Trim()), reservation.Id, reservation.ArrivalDate, reservation.DepartureDate, LogInManager.LoggedInUserId);

                            //if (reservationRoomMappingDetails != null && reservationRoomMappingDetails.Count > 0)
                            //{
                            //    foreach(var reservationRoomMappingDetail in reservationRoomMappingDetails)
                            //    {
                            //        //Delete Reservation.
                            //        reservationRepository.DeleteReservation(reservationRoomMappingDetail.ReservationId.Value, LogInManager.LoggedInUserId, LogInManager.LoggedInUserId);

                            //        //Delete Reservation Room Mapping.
                            //        roomRepository.DeleteReservationRoomMappingByReservation(reservationRoomMappingDetail.ReservationId.Value, LogInManager.LoggedInUserId, LogInManager.LoggedInUserId);

                            //        //Delete Reservation Log.
                            //        reservationLogRepository.DeleteReservationLog(reservationRoomMappingDetail.Id, LogInManager.LoggedInUserId, LogInManager.LoggedInUserId);
                            //    }
                            //}

                            //#endregion

                            #region Add Reservation Log

                            var lstReservationLog = reservationLogRepository.GetReservationLogDetails(model.ReservationId, Guid.Parse(item.Trim()), null, LogInManager.LoggedInUserId).FirstOrDefault();

                            if (lstReservationLog != null)
                            {
                                lstReservationLog.ReservationId = model.ReservationId;
                                lstReservationLog.ProfileId     = model.ProfileId;
                                lstReservationLog.RoomId        = Guid.Parse(item.Trim());
                                lstReservationLog.CheckInDate   = model.CheckInDate.Value;
                                lstReservationLog.CheckInTime   = checkInTime;
                                lstReservationLog.CheckOutDate  = reservation.DepartureDate;
                                lstReservationLog.RoomStatusId  = Guid.Parse(RoomStatusType.DIRTY);
                                lstReservationLog.IsActive      = true;
                                lstReservationLog.UpdatedBy     = LogInManager.LoggedInUserId;

                                reservationLogRepository.UpdateReservationLog(lstReservationLog);
                            }
                            else
                            {
                                ReservationLogVM reservationLog = new ReservationLogVM();
                                reservationLog.ReservationId = model.ReservationId;
                                reservationLog.ProfileId     = model.ProfileId;
                                reservationLog.RoomId        = Guid.Parse(item.Trim());
                                reservationLog.CheckInDate   = model.CheckInDate.Value;
                                reservationLog.CheckInTime   = checkInTime;
                                reservationLog.CheckOutDate  = reservation.DepartureDate;
                                reservationLog.RoomStatusId  = Guid.Parse(RoomStatusType.DIRTY);
                                reservationLog.IsActive      = true;
                                reservationLog.CreatedBy     = LogInManager.LoggedInUserId;

                                reservationLogRepository.AddReservationLog(reservationLog);
                            }

                            #endregion
                        }
                    }

                    #endregion

                    #region Save CheckIn Details

                    checkIn.ReservationId = model.ReservationId;
                    checkIn.ProfileId     = model.ProfileId;
                    checkIn.CheckInDate   = model.CheckInDate.Value;
                    checkIn.CheckInTime   = checkInTime;
                    checkIn.IsActive      = true;
                    checkIn.CreatedBy     = LogInManager.LoggedInUserId;

                    var checkInId = checkInCheckOutRepository.AddCheckInDetail(checkIn);

                    #endregion

                    #region Update Reservation Check In Flag

                    reservationRepository.UpdateReservationCheckInFlag(model.ReservationId, true, LogInManager.LoggedInUserId);

                    #endregion

                    #region Update Reservation Status

                    reservationRepository.UpdateReservationStatus(model.ReservationId, Guid.Parse(ReservationStatusName.CHECKEDIN), LogInManager.LoggedInUserId);

                    #endregion

                    #region Update Reservation Total Balance.

                    double totalGuestBalance = Utility.Utility.CalculateTotalBalance(reservation.Id);

                    //Update Total Balance.
                    reservationRepository.UpdateReservationTotalBalance(reservation.Id, totalGuestBalance, LogInManager.LoggedInUserId);

                    #endregion

                    #region Update TrackReservationLog Status

                    reservationRepository.UpdateTrackReservationLogStatusByReservationId(reservation.Id, true);

                    #endregion

                    #region Record Activity Log
                    RecordActivityLog.RecordActivity(Pages.CHECKIN, string.Format("Checked in profile successfully. Name: {0} {1}, Comfirmation #: {2} ", reservation.LastName, reservation.FirstName, reservation.ConfirmationNumber));
                    #endregion

                    return(Json(new
                    {
                        IsSuccess = true,
                        data = new
                        {
                            CheckInId = checkInId,
                            Name = model.Name
                        }
                    }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new
                    {
                        IsSuccess = false,
                        errorMessage = "Check In details not saved successfully."
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception e)
            {
                Utility.Utility.LogError(e, "CheckIn");
                return(Json(new { IsSuccess = false, errorMessage = e.Message }));
            }
        }
Пример #4
0
        public ActionResult Create(ReservationChargeVM model)
        {
            try
            {
                string chargeId = string.Empty;

                model.CreatedBy = LogInManager.LoggedInUserId;
                model.AdditionalChargeSource = AdditionalChargeSource.ADDITIONAL_CHARGE;
                chargeId = reservationChargeRepository.AddReservationCharges(model);

                if (!string.IsNullOrWhiteSpace(chargeId))
                {
                    model.Id = Guid.Parse(chargeId);

                    #region Update Reservation Total Balance.
                    var reservation = new ReservationVM();

                    if (model.ReservationId.HasValue)
                    {
                        reservation = reservationRepository.GetReservationById(model.ReservationId.Value, LogInManager.LoggedInUserId).FirstOrDefault();
                    }

                    double totalBalance = 0;
                    if (reservation != null)
                    {
                        totalBalance = reservation.GuestBalance.HasValue ? reservation.GuestBalance.Value : 0;

                        //Calculate total Amount.
                        int qty = 1;

                        if (model.Qty.HasValue)
                        {
                            qty = model.Qty.Value;
                        }

                        totalBalance = totalBalance + (model.Amount.HasValue ? (model.Amount.Value * qty) : 0);

                        //totalBalance += model.Amount.HasValue ? model.Amount.Value : 0;

                        //Update Total Balance.
                        reservationRepository.UpdateReservationTotalBalance(reservation.Id, totalBalance, LogInManager.LoggedInUserId);
                    }
                    #endregion


                    var transaction = new List <ReservationChargeVM>();
                    transaction.Add(model);

                    #region Record Activity Log
                    RecordActivityLog.RecordActivity(Pages.BILLING_TRANSACTION, "Added new biling transaction.");
                    #endregion

                    return(Json(new
                    {
                        IsSuccess = true,
                        data = new
                        {
                            ChargeId = chargeId,
                            Transaction = transaction,
                            TotalBalance = totalBalance
                        }
                    }, JsonRequestBehavior.AllowGet));
                }
                else
                {
                    return(Json(new
                    {
                        IsSuccess = false,
                        errorMessage = "Charge not saved successfully."
                    }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception e)
            {
                Utility.Utility.LogError(e, "Create");
                return(Json(new { IsSuccess = false, errorMessage = e.Message }));
            }
        }