//=======================================================
        //Author: LinhTing
        //Function : Tính hiệu suất phòng
        //=======================================================
        public List<EfficiencyEN> GetEfficiencyRoom(DateTime From, DateTime To, List<string> ListCodeRoom)
        {
            try
            {
                List<sp_RoomsExt_CalculationEfficiency_Result> aListSP = new List<sp_RoomsExt_CalculationEfficiency_Result>();
                double UsedDate = new double();
                List<EfficiencyEN> aListEfficiencyEN = new List<EfficiencyEN>();
                TimeSpan dis = To.Subtract(From);
                double TotalDate = dis.TotalDays;
                RoomsBO aRoomBO = new RoomsBO();
                for (int i = 0; i < ListCodeRoom.Count; i++)
                {
                    EfficiencyEN aEfficiencyEN = new EfficiencyEN();
                    aListSP = aDatabaseDA.sp_RoomsExt_CalculationEfficiency(ListCodeRoom[i], From, To).ToList();
                    UsedDate = new double();
                    UsedDate = double.Parse(aListSP.Select(p => p.RankTime).Sum().ToString());
                    //ret.Add((UsedDate / TotalDate) * 100);
                    aEfficiencyEN.CodeRoom = ListCodeRoom[i];
                    Rooms aRooms = aRoomBO.Select_ByCodeRoom(aEfficiencyEN.CodeRoom, 1);
                    aEfficiencyEN.Sku = aRooms.Sku;
                    aEfficiencyEN.Efficiency = Math.Round((UsedDate / TotalDate) * 100, 2);
                    aListEfficiencyEN.Add(aEfficiencyEN);

                }

                return aListEfficiencyEN;
            }
            catch (Exception ex)
            {
                throw new Exception("ReceptionTaskBO.GetEfficiencyRoom \n" + ex.ToString());
            }
        }
        public void LoadDataBookingRoom()
        {
            try
            {
                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                List<BookingRooms> aListTemp = aBookingRoomsBO.Select_ByDateAndCodeRoomAndStaus(DateTime.Now,this.codeRoom,3); //3 = status = da check In
                BookingRooms aBookingRooms;
                List<BookingRooms> aListBookingRoom = new List<BookingRooms>();
                RoomsBO aRoomsBO = new RoomsBO();

                foreach (BookingRooms item in aListTemp)
                {
                    aBookingRooms = new BookingRooms();
                    aBookingRooms.ID = item.ID;
                    aBookingRooms.IDBookingR = item.IDBookingR;
                    aBookingRooms.CodeRoom = item.CodeRoom;
                    aBookingRooms.Cost = item.Cost;
                    aBookingRooms.PercentTax = item.PercentTax;
                    aBookingRooms.CostRef_Rooms = item.CostRef_Rooms;
                    aBookingRooms.Note = item.Note;
                    aBookingRooms.CheckInPlan = item.CheckInPlan;
                    aBookingRooms.CheckInActual = item.CheckInActual;
                    aBookingRooms.CheckOutPlan = item.CheckOutPlan;
                    aBookingRooms.CheckOutActual = item.CheckOutActual;
                    aBookingRooms.BookingStatus = item.BookingStatus;
                    aBookingRooms.Status = item.Status;
                    aBookingRooms.StartTime = item.StartTime;
                    aBookingRooms.EndTime = item.EndTime;
                    aBookingRooms.IsAllDayEvent = item.IsAllDayEvent;
                    aBookingRooms.Color = item.Color;
                    aBookingRooms.IsEditable = item.IsEditable;
                    aBookingRooms.IsRecurring = item.IsRecurring;
                    Rooms aRooms = aRoomsBO.Select_ByCodeRoom(item.CodeRoom, 1);//1= IDLang

                    //dung tam de hien thi sku
                    aBookingRooms.AdditionalColumn1 = aRooms.Sku;
                    aListBookingRoom.Add(aBookingRooms);

                }

                if (String.IsNullOrEmpty(txtSku.Text) == false)
                {
                    dgvBookingRooms.DataSource = aListBookingRoom.Where(b => b.AdditionalColumn1.Contains(txtSku.Text)).ToList();
                }
                else
                {
                    dgvBookingRooms.DataSource = aListBookingRoom;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_PendingRoom_Step1.LoadDataBookingRoom\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        //Author: Tqtrung
        public List<BookingRoomsEN> GetListRoomsCheckOutPlanInDayAndH(DateTime Checktime, int Status)
        {
            try
            {

                DateTime Checktime2 = Checktime.AddDays(1);

                RoomsBO aRoomsBO = new RoomsBO();
                List<BookingRooms> aListTemp = aDatabaseDA.BookingRooms.Where(b => b.Status == Status).Where(b => b.CheckOutPlan > Checktime && b.CheckOutPlan < Checktime2).ToList();
                List<BookingRooms> alistTemp2 = aDatabaseDA.BookingRooms.Where(c => c.Status == Status).Where(b => b.CheckOutPlan < Checktime).ToList();
                List<BookingRoomsEN> aListBookingRoomEN = new List<BookingRoomsEN>();
                BookingRoomsEN aBookingRoomEN, aBookingRoomEN2;
                for (int i = 0; i < aListTemp.Count; i++)
                {
                    aBookingRoomEN = new BookingRoomsEN();
                    aBookingRoomEN.SetValue(aListTemp[i]);
                    if (aRoomsBO.Select_ByCodeRoom(aListTemp[i].CodeRoom, 1) != null)
                    {
                        aBookingRoomEN.RoomSku = aRoomsBO.Select_ByCodeRoom(aListTemp[i].CodeRoom, 1).Sku;
                    }
                    aListBookingRoomEN.Add(aBookingRoomEN);
                }

                for (int y = 0; y < alistTemp2.Count; y++)
                {
                    aBookingRoomEN2 = new BookingRoomsEN();
                    aBookingRoomEN2.SetValue(alistTemp2[y]);
                    if (aRoomsBO.Select_ByCodeRoom(alistTemp2[y].CodeRoom, 1) != null)
                    {
                        aBookingRoomEN2.RoomSku = aRoomsBO.Select_ByCodeRoom(alistTemp2[y].CodeRoom, 1).Sku;
                    }
                    aListBookingRoomEN.Add(aBookingRoomEN2);
                }

                return aListBookingRoomEN;
            }
            catch (Exception ex)
            {
                throw new Exception("BookingRoomsBO.GetListRoomsCheckOutPlanInDayAndH:" + ex.ToString());
            }
        }
        public void LoadData()
        {
            try
            {
                CustomersBO aCustomersBO = new CustomersBO();
                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                BookingRooms aBookingRooms = new BookingRooms();
                RoomsBO aRoomsBO = new RoomsBO();

                // Load các thông tin chung về phòng
                aBookingRooms = aBookingRoomsBO.Select_ByID(this.IDBookingRooms);
                if (aBookingRooms != null)
                {
                    lblCheckIn.Text = aBookingRooms.CheckInActual.ToString("dd/MM/yyyy HH:mm");
                    lblCheckOut.Text = aBookingRooms.CheckOutPlan.ToString("dd/MM/yyyy HH:mm");
                    lblRoomSku.Text = aRoomsBO.Select_ByCodeRoom(aBookingRooms.CodeRoom, 1).Sku;
                }
                BookingRsBO aBookingRsBO = new BookingRsBO();
                BookingRs aBookingRs = new BookingRs();
                aBookingRs = aBookingRsBO.Select_ByID(this.IDBookingRs);
                if (aBookingRs != null)
                {
                    lblCustomerType.Text = CORE.CONSTANTS.SelectedCustomerType(Convert.ToInt32(aBookingRs.CustomerType)).Name;

                    CompaniesBO aCompaniesBO = new CompaniesBO();
                    lblCompany.Text = aCompaniesBO.Select_ByIDBookingRoom(this.IDBookingRooms).Name;

                    lblCustomer.Text = aCustomersBO.Select_ByID(aBookingRs.IDCustomer).Name;

                    CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                    lblGroup.Text = aCustomerGroupsBO.Select_ByID(aBookingRs.IDCustomerGroup).Name;

                    lblTel.Text = aCustomersBO.Select_ByID(aBookingRs.IDCustomer).Tel;

                    this.IDCustomerGroup = aBookingRs.IDCustomerGroup;
                }
                //Load danh sách phòng còn trống
                lueRooms.Properties.DataSource = this.LoadListAvailableRooms(aBookingRooms.CheckInActual, aBookingRooms.CheckOutPlan);
                lueRooms.Properties.ValueMember = "RoomCode";
                lueRooms.EditValue = this.IDBookingRooms;
                //Load danh sách khách trong phòng
                this.aListCustomersInRoom = aCustomersBO.SelectListCustomer_ByIDBookingRoom(this.IDBookingRooms);
                dgvAvailableCustomers.DataSource = this.aListCustomersInRoom;
                dgvAvailableCustomers.RefreshDataSource();

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_EditBooking.ReloadData\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void LoadDataBookingRoom(int Status)
        {
            try
            {
                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                List<BookingRooms> aListTemp = aBookingRoomsBO.Select_ByStatus_ByTime(DateTime.Now,Status);
                BookingRooms aBookingRooms;
                List<BookingRooms> aListBookingRoom = new List<BookingRooms>();
                RoomsBO aRoomsBO = new RoomsBO();

                foreach (BookingRooms item in aListTemp)
                {
                    aBookingRooms = new BookingRooms();
                    aBookingRooms.ID = item.ID;
                    aBookingRooms.IDBookingR = item.IDBookingR;
                    aBookingRooms.CodeRoom = item.CodeRoom;
                    aBookingRooms.Cost = item.Cost;
                    aBookingRooms.PercentTax = item.PercentTax;
                    aBookingRooms.CostRef_Rooms = item.CostRef_Rooms;

                    //dung tam truong Note de hien thi trang thai phong
                    aBookingRooms.Note = CORE.CONSTANTS.SelectedBookingRoomStatus(item.Status.GetValueOrDefault()).Name;

                    aBookingRooms.CheckInPlan = item.CheckInPlan;
                    aBookingRooms.CheckInActual = item.CheckInActual;
                    aBookingRooms.CheckOutPlan = item.CheckOutPlan;
                    aBookingRooms.CheckOutActual = item.CheckOutActual;
                    aBookingRooms.BookingStatus = item.BookingStatus;
                    aBookingRooms.Status = item.Status;
                    aBookingRooms.StartTime = item.StartTime;
                    aBookingRooms.EndTime = item.EndTime;
                    aBookingRooms.IsAllDayEvent = item.IsAllDayEvent;
                    aBookingRooms.Color = item.Color;
                    aBookingRooms.IsEditable = item.IsEditable;
                    aBookingRooms.IsRecurring = item.IsRecurring;
                    Rooms aRooms = aRoomsBO.Select_ByCodeRoom(item.CodeRoom, 1);//1= IDLang

                    //dung tam de hien thi sku
                    aBookingRooms.AdditionalColumn1 = aRooms.Sku;
                    aListBookingRoom.Add(aBookingRooms);

                }
                dgvBookingRooms.DataSource = aListBookingRoom;
                dgvBookingRooms.RefreshDataSource();

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_PendingCheckIn_Step1.LoadDataBookingRoom\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void LoadData()
        {
            try
            {
                CustomersBO aCustomersBO = new CustomersBO();
                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                BookingRooms aBookingRooms = new BookingRooms();
                RoomsBO aRoomsBO = new RoomsBO();

                aBookingRooms = aBookingRoomsBO.Select_ByID(this.IDBookingRooms);
                if (aBookingRooms != null)
                {
                    lblCheckIn.Text = aBookingRooms.CheckInActual.ToString("dd/MM/yyyy HH:mm");
                    lblCheckOut.Text = aBookingRooms.CheckOutPlan.ToString("dd/MM/yyyy HH:mm");
                    lblRoomSku.Text = aRoomsBO.Select_ByCodeRoom(aBookingRooms.CodeRoom,1).Sku;
                }
                BookingRsBO aBookingRsBO = new BookingRsBO();
                BookingRs aBookingRs = new BookingRs();
                aBookingRs = aBookingRsBO.Select_ByID(this.IDBookingRs);
                if (aBookingRs != null)
                {
                    lblCustomerType.Text = CORE.CONSTANTS.SelectedCustomerType(Convert.ToInt32(aBookingRs.CustomerType)).Name;

                    CompaniesBO aCompaniesBO = new CompaniesBO();
                    lblCompany.Text = aCompaniesBO.Select_ByIDBookingRoom(this.IDBookingRooms).Name;

                    lblCustomer.Text = aCustomersBO.Select_ByID(aBookingRs.IDCustomer).Name;

                    CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                    lblGroup.Text = aCustomerGroupsBO.Select_ByID(aBookingRs.IDCustomerGroup).Name;

                    lblTel.Text = aCustomersBO.Select_ByID(aBookingRs.IDCustomer).Tel;

                    this.IDCustomerGroup = aBookingRs.IDCustomerGroup;
                }
                dgvAvaiableRooms.DataSource = this.LoadListAvailableRooms(aBookingRooms.CheckInActual, aBookingRooms.CheckOutPlan);
                dgvAvaiableRooms.RefreshDataSource();

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_EditBooking.ReloadData\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public void Reload()
        {
            BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
            RoomsBO aRoomsBO = new RoomsBO();

            BookingRoomsEN aBookingRoomsEN = new BookingRoomsEN();
            BookingRooms aBookingRooms = aBookingRoomsBO.Select_ByID(IDBookingRoom);
            aBookingRoomsEN.SetValue(aBookingRooms);
            aBookingRoomsEN.ID = aBookingRooms.ID;
            aBookingRoomsEN.RoomSku = aRoomsBO.Select_ByCodeRoom(aBookingRooms.CodeRoom, 1).Sku;
            this.lbCurrentRoom.Text = "Phòng số : " + aBookingRoomsEN.RoomSku;

            aListBookingRoom.Add(aBookingRoomsEN);
            dgvRooms.DataSource = aListBookingRoom;
            dgvRooms.RefreshDataSource();

            ServicesBO aServicesBO = new ServicesBO();
            aListService = aServicesBO.Select_ByType(2);
            dgvServices.DataSource = aListService;
            dgvServices.RefreshDataSource();
        }
        // ===============================================================================
        // Khoi tao doi tuong Payment
        private void InitData(int IDBookingR, int IDBookingH)
        {
            CompaniesBO aCompaniesBO = new CompaniesBO();
            CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
            SystemUsersBO aSystemUsersBO = new SystemUsersBO();
            BookingHsBO aBookingHsBO = new BookingHsBO();
            BookingRsBO aBookingRsBO = new BookingRsBO();
            BookingRoomsBO aBookingRoomBO = new BookingRoomsBO();
            CustomersBO aCustomersBO = new CustomersBO();
            ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();
            RoomsBO aRoomsBO = new RoomsBO();
            HallsBO aHallsBO = new HallsBO();
            BookingHallsBO aBookingHallsBO = new BookingHallsBO();
            FoodsBO aFoodsBO = new FoodsBO();
            ExtraCostBO aExtraCostBO = new ExtraCostBO();
            List<int> aListIndexTemp = new List<int>();
            BookingHs aBookingHs = new BookingHs();
            BookingRs aBookingRs = aBookingRsBO.Select_ByID(IDBookingR);
            if (this.IDBookingH > 0)
            {
                aBookingHs = aBookingHsBO.Select_ByID(this.IDBookingH);
            }
            else
            {
                BookingRs_BookingHs aItem = (new BookingRs_BookingHsBO()).Select_ByIDBookingR(this.IDBookingR);
                if (aItem != null)
                {
                    this.IDBookingH = aItem.IDBookingH.GetValueOrDefault(0);
                    aBookingHs = aBookingHsBO.Select_ByID(this.IDBookingH);
                }

            }

            // Truyen du lieu chung cua NewPayment
            if (aBookingRs != null)
            {
                aNewPaymentEN.IDBookingR = aBookingRs.ID;
                aNewPaymentEN.IDCustomer = aBookingRs.IDCustomer;
                Customers aCustomers = aCustomersBO.Select_ByID(aBookingRs.IDCustomer);
                if (aCustomers != null)
                {
                    aNewPaymentEN.NameCustomer = aCustomers.Name;
                }
                aNewPaymentEN.IDSystemUser = aBookingRs.IDSystemUser;
                SystemUsers aSystemUsers = aSystemUsersBO.Select_ByID(aBookingRs.IDSystemUser);
                if (aSystemUsers != null)
                {
                    aNewPaymentEN.NameSystemUser = aSystemUsers.Name;
                }
                aNewPaymentEN.IDCustomerGroup = aBookingRs.IDCustomerGroup;
                CustomerGroups aCustomerGroups = aCustomerGroupsBO.Select_ByID(aBookingRs.IDCustomerGroup);
                if (aCustomerGroups != null)
                {
                    aNewPaymentEN.NameCustomerGroup = aCustomerGroups.Name;
                    aNewPaymentEN.IDCompany = aCustomerGroups.IDCompany;
                    Companies aCompanies = aCompaniesBO.Select_ByID(aCustomerGroups.IDCompany);
                    if (aCompanies != null)
                    {
                        aNewPaymentEN.NameCompany = aCompanies.Name;
                        aNewPaymentEN.TaxNumberCodeCompany = aCompanies.TaxNumberCode;
                        aNewPaymentEN.AddressCompany = aCompanies.Address;
                    }
                }
                aNewPaymentEN.PayMenthodR = aBookingRs.PayMenthod;
                aNewPaymentEN.CreatedDate_BookingR = aBookingRs.CreatedDate;
                aNewPaymentEN.CustomerType = aBookingRs.CustomerType;
                aNewPaymentEN.Status_BookingR = aBookingRs.Status;
                aNewPaymentEN.StatusPay = aBookingRs.StatusPay;
                aNewPaymentEN.BookingRMoney = aBookingRs.BookingMoney;
                aNewPaymentEN.Status_BookingR = aBookingRs.Status;
                aNewPaymentEN.AcceptDate = aBookingRs.AcceptDate;
                aNewPaymentEN.InvoiceDate = aBookingRs.InvoiceDate;
                aNewPaymentEN.InvoiceNumber = aBookingRs.InvoiceNumber;

                // Truyen du lieu cho List BookingRoom cua NewPayment
                List<BookingRooms> aListBookingRooms = aBookingRoomBO.Select_ByIDBookingRs(this.IDBookingR);
                if (aListBookingRooms.Count > 0)
                {
                    BookingRoomUsedEN aBookingRoomUsedEN;

                    foreach (BookingRooms item in aListBookingRooms)
                    {
                        aBookingRoomUsedEN = new BookingRoomUsedEN();
                        aBookingRoomUsedEN.SetValue(item);
                        aBookingRoomUsedEN.ListCustomer = aCustomersBO.SelectListCustomer_ByIDBookingRoom(item.ID);
                        Rooms aRooms = aRoomsBO.Select_ByCodeRoom(item.CodeRoom, 1);
                        if (aRooms != null)
                        {
                            aBookingRoomUsedEN.RoomSku = aRooms.Sku;
                        }
                        else
                        {
                            aBookingRoomUsedEN.RoomSku = string.Empty;
                        }
                        if (item.Status == 8 || item.Status == 7)
                        {
                            aBookingRoomUsedEN.AddTimeStart = Convert.ToDouble(aReceptionTaskBO.GetAddTimeStart(Convert.ToInt32(item.Type), item.CheckInActual));
                            aBookingRoomUsedEN.AddTimeEnd = Convert.ToDouble(aReceptionTaskBO.GetAddTimeEnd(Convert.ToInt32(item.Type), item.CheckOutActual));
                            aBookingRoomUsedEN.TimeInUse = Convert.ToDecimal(aReceptionTaskBO.GetTimeInUsed(item.CheckInActual, item.CheckOutActual) * 24 * 60);
                        }
                        else
                        {
                            aBookingRoomUsedEN.AddTimeStart = Convert.ToDouble(aReceptionTaskBO.GetAddTimeStart(Convert.ToInt32(item.Type), item.CheckInActual));
                            aBookingRoomUsedEN.AddTimeEnd = Convert.ToDouble(aReceptionTaskBO.GetAddTimeEnd(Convert.ToInt32(item.Type), item.CheckOutPlan));
                            aBookingRoomUsedEN.TimeInUse = Convert.ToDecimal(aReceptionTaskBO.GetTimeInUsed(item.CheckInActual, item.CheckOutPlan) * 24 * 60);

                        }
                        decimal? cost = 0;
                        if (item.Cost == null)
                        {
                            cost = item.CostRef_Rooms;
                            aBookingRoomUsedEN.Cost = cost + Convert.ToDecimal(aExtraCostBO.Select_BySku_ByPriceType_ByNumberPeople(aRooms.Sku, aBookingRoomUsedEN.PriceType, aBookingRoomUsedEN.ListCustomer.Count).ExtraValue);
                        }
                        else
                        {
                            cost = item.Cost;
                            aBookingRoomUsedEN.Cost = cost;
                        }
                        List<ServiceUsedEN> aListServiceRTemp = aReceptionTaskBO.GetListServiceUsedInRoom_ByIDBookingRoom(item.ID);
                        foreach (ServiceUsedEN aTemp in aListServiceRTemp)
                        {
                            aBookingRoomUsedEN.ListServiceUsed.Add(aTemp);
                            aListIndexTemp.Add(Convert.ToInt32(aTemp.IndexSubPayment));
                        }
                        aListIndexTemp.Add(Convert.ToInt32(aBookingRoomUsedEN.IndexSubPayment));
                        aNewPaymentEN.aListBookingRoomUsed.Add(aBookingRoomUsedEN);
                    }
                }

                //====================================================================================================
                //====================================================================================================
                //====================================================================================================
                // Brucelee Thanh sửa ngày 04/06/2015
                //
                //---------------
                // Lỗi sai điều kiện câu lệnh if khiến aBookingHs truyền dữ liệu CustomerType sai cho NewPaymentEN
                //---------------
                // Ban đầu : if (aBookingHs != null)
                //-------------------------------------
                if (aBookingHs.ID > 0)
                {
                    aNewPaymentEN.IDBookingH = aBookingHs.ID;
                    aNewPaymentEN.PayMenthodH = aBookingHs.PayMenthod;
                    aNewPaymentEN.CreatedDate_BookingH = aBookingHs.CreatedDate;
                    aNewPaymentEN.CustomerType = aBookingHs.CustomerType;
                    aNewPaymentEN.Status_BookingH = aBookingHs.Status;
                    aNewPaymentEN.BookingHMoney = aBookingHs.BookingMoney;
                    // Truyen du lieu cho List BookingHall cua NewPayment
                    List<BookingHalls> aListBookingHalls = aBookingHallsBO.Select_ByIDBookigH(this.IDBookingH);
                    if (aListBookingHalls != null)
                    {
                        BookingHallUsedEN aBookingHallUsedEN;
                        foreach (BookingHalls item in aListBookingHalls)
                        {
                            aBookingHallUsedEN = new BookingHallUsedEN();
                            aBookingHallUsedEN.SetValue(item);
                            Halls aHalls = aHallsBO.Select_ByCodeHall(item.CodeHall, 1);
                            if (aHalls != null)
                            {
                                aBookingHallUsedEN.HallSku = aHalls.Sku;
                            }
                            else
                            {
                                aBookingHallUsedEN.HallSku = string.Empty;
                            }
                            aBookingHallUsedEN.CustomerType = aBookingHs.CustomerType;
                            aBookingHallUsedEN.BookingTypeBookingH = aBookingHs.BookingType;
                            aBookingHallUsedEN.StatusPayBookingH = aBookingHs.StatusPay;
                            aBookingHallUsedEN.LevelBookingH = aBookingHs.Level;
                            aBookingHallUsedEN.aListMenuEN = aReceptionTaskBO.GetListMenus_ByIDBookingHall(item.ID);

                            aListIndexTemp.Add(Convert.ToInt32(aBookingHallUsedEN.IndexSubPayment));
                            List<ServiceUsedEN> aListServiceTemp = aReceptionTaskBO.GetListServiceUsedInHall_ByIDBookingHall(item.ID);
                            foreach (ServiceUsedEN aTemp in aListServiceTemp)
                            {
                                aBookingHallUsedEN.aListServiceUsed.Add(aTemp);
                                aListIndexTemp.Add(Convert.ToInt32(aTemp.IndexSubPayment));
                            }
                            aNewPaymentEN.aListBookingHallUsed.Add(aBookingHallUsedEN);
                        }
                    }
                }
                aNewPaymentEN.ListIndex = aListIndexTemp.Distinct().ToList();
            }
        }
        private void btnCheckIn_Click(object sender, EventArgs e)
        {
            try
            {
                if (dtpFrom.DateTime < dtpTo.DateTime)
                {
                    if (this.Status == 2)
                    {
                        BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                        //cap nhat bookingroom
                        BookingRooms aBookingRooms = aBookingRoomsBO.Select_ByID(this.IDBookingRoom);

                        //aBookingRooms.CheckInPlan = DateTime.Now;
                        //aBookingRooms.CheckInActual = DateTime.Now;

                        aBookingRooms.CheckInPlan = dtpFrom.DateTime;
                        aBookingRooms.CheckInActual = dtpFrom.DateTime;

                        aBookingRooms.CheckOutPlan = dtpTo.DateTime;
                        aBookingRooms.CheckOutActual = dtpTo.DateTime;
                        //aBookingRooms.PriceType = "G1";
                        aBookingRooms.Status = 3;// 3= Da check in

                        aBookingRoomsBO.Update(aBookingRooms);

                        if (this.afrmTsk_PendingCheckIn_Step1 != null)
                        {
                            this.afrmTsk_PendingCheckIn_Step1.LoadDataBookingRoom(this.Status);
                            if (this.afrmTsk_PendingCheckIn_Step1.afrmMain != null)
                            {
                                this.afrmTsk_PendingCheckIn_Step1.afrmMain.ReloadData();
                            }
                        }

                        MessageBox.Show("Thực hiện thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);

                        this.Close();

                    }
                    else if (this.Status == 5)
                    {
                        BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                        RoomsBO aRoomsBO = new RoomsBO();
                        AccountancyBO aAccountancyBO = new AccountancyBO();
                        //Check out giai doan pending
                        aAccountancyBO.CheckOut(this.IDBookingRoom, dtpFrom.DateTime);

                        //them moi mot bookingroom
                        BookingRooms aBookingRooms = aBookingRoomsBO.Select_ByID(this.IDBookingRoom);
                        BookingRooms aBookingRoomsAddNew = new BookingRooms();
                        aBookingRoomsAddNew.IDBookingR = IDBookingR;
                        aBookingRoomsAddNew.CodeRoom = CodeRoom;

                        aBookingRoomsAddNew.PercentTax = aBookingRooms.PercentTax;
                        aBookingRoomsAddNew.CostRef_Rooms = aRoomsBO.Select_ByCodeRoom(aBookingRooms.CodeRoom, 1).CostRef;
                        aBookingRoomsAddNew.Note = aBookingRooms.Note;

                        aBookingRoomsAddNew.CheckInPlan = dtpFrom.DateTime;
                        aBookingRoomsAddNew.CheckInActual = dtpFrom.DateTime;
                        aBookingRoomsAddNew.CheckOutPlan = dtpTo.DateTime;
                        aBookingRoomsAddNew.CheckOutActual = dtpTo.DateTime;
                        aBookingRoomsAddNew.PriceType = aBookingRooms.PriceType;
                        aBookingRoomsAddNew.Type = 1;

                        aBookingRoomsAddNew.BookingStatus = aBookingRooms.BookingStatus;

                        aBookingRoomsAddNew.Status = 3;// 3 = Da CheckIn

                        aBookingRoomsAddNew.StartTime = aBookingRooms.StartTime;
                        aBookingRoomsAddNew.EndTime = aBookingRooms.EndTime;
                        aBookingRoomsAddNew.IsAllDayEvent = aBookingRooms.IsAllDayEvent;
                        aBookingRoomsAddNew.Color = aBookingRooms.Color;
                        aBookingRoomsAddNew.IsRecurring = aBookingRooms.IsRecurring;
                        aBookingRoomsAddNew.IsEditable = aBookingRooms.IsEditable;
                        aBookingRoomsAddNew.AdditionalColumn1 = aBookingRooms.AdditionalColumn1;
                        int ID = aBookingRoomsBO.Insert(aBookingRoomsAddNew);

                        if (ID > 0)
                        {
                            BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();
                            List<BookingRoomsMembers> aListBookingRoomsMembers = aBookingRoomsMembersBO.Select_ByIDBookingRoom(this.IDBookingRoom);
                            BookingRoomsMembers aBookingRoomsMembers;
                            foreach (BookingRoomsMembers item1 in aListBookingRoomsMembers)
                            {
                                aBookingRoomsMembers = new BookingRoomsMembers();
                                aBookingRoomsMembers.IDBookingRoom = ID;
                                aBookingRoomsMembers.IDCustomer = item1.IDCustomer;
                                aBookingRoomsMembers.PurposeComeVietnam = item1.PurposeComeVietnam;
                                aBookingRoomsMembers.DateEnterCountry = item1.DateEnterCountry;
                                aBookingRoomsMembers.EnterGate = item1.EnterGate;
                                aBookingRoomsMembers.TemporaryResidenceDate = item1.TemporaryResidenceDate;
                                aBookingRoomsMembers.LimitDateEnterCountry = item1.LimitDateEnterCountry;
                                aBookingRoomsMembers.Organization = item1.Organization;
                                aBookingRoomsMembers.LeaveDate = item1.LeaveDate;

                                aBookingRoomsMembersBO.Insert(aBookingRoomsMembers);

                            }
                        }

                        if (this.afrmTsk_PendingCheckIn_Step1 != null)
                        {
                            this.afrmTsk_PendingCheckIn_Step1.LoadDataBookingRoom(Status);
                            if (this.afrmTsk_PendingCheckIn_Step1.afrmMain != null)
                            {
                                this.afrmTsk_PendingCheckIn_Step1.afrmMain.ReloadData();
                            }
                        }

                        MessageBox.Show("Thực hiện thành công.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.Close();

                    }
                }
                else
                {
                    MessageBox.Show("Ngày giờ không hợp lệ");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_PendingCheckIn_Step2.btnCheckIn_Click\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void frmTsk_PendingCheckIn_Step2_Load(object sender, EventArgs e)
        {
            try
            {
                BookingRsBO aBookingRsBO = new BookingRsBO();
                BookingRs aBookingRs = aBookingRsBO.Select_ByID(IDBookingR);
                lblIDBookingR.Text = aBookingRs.ID.ToString();

                CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
                CustomerGroups aCustomerGroups = aCustomerGroupsBO.Select_ByID(aBookingRs.IDCustomerGroup);
                lblNameCustomerGroup.Text = aCustomerGroups.Name;

                CompaniesBO aCompaniesBO = new CompaniesBO();
                Companies aCompanies = aCompaniesBO.Select_ByID(aCustomerGroups.IDCompany);
                lblNameCompany.Text = aCompanies.Name;

                CustomersBO aCustomersBO = new CustomersBO();
                Customers aCustomers = aCustomersBO.Select_ByID(aBookingRs.IDCustomer);
                lblNameCustomer.Text = aCustomers.Name;

                RoomsBO aRoomsBO = new RoomsBO();
                Rooms aRooms = aRoomsBO.Select_ByCodeRoom(CodeRoom, 1);//1=IDLang
                lblSku.Text = aRooms.Sku;

                dtpTo.DateTime = CheckOutPlan;
                dtpFrom.DateTime = DateTime.Now;
                dtpFrom.Enabled = false;
                dtpFrom.Properties.ReadOnly = true;

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_PendingCheckIn_Step2.frmTsk_PendingCheckIn_Step2_Load\n" + ex.ToString(), "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        public frmRpt_PersonalPayment(List<RptPaymentStyle1_ForPrint> aListData, string CompanyName, string Address, string NameCustomerGroup, string InvoiceNumber
            , DateTime FirstDate, DateTime LastDate, decimal? BookingHMoney, decimal? BookingRMoney,int IDBookingR)
        {
            InitializeComponent();
            //Load dữ liệu
             BookingRoomsBO aBookingRoomBO = new BookingRoomsBO();
                        CustomersBO aCustomersBO = new CustomersBO();
            RoomsBO aRoomsBO = new RoomsBO();

            string RoomSku = "";
            string CustomerNames = "";
              List<BookingRooms> aListBookingRooms = aBookingRoomBO.Select_ByIDBookingRs(IDBookingR);
              if (aListBookingRooms.Count > 0)
              {
                  BookingRoomUsedEN aBookingRoomUsedEN;

                  foreach (BookingRooms item in aListBookingRooms)
                  {
                      aBookingRoomUsedEN = new BookingRoomUsedEN();
                      aBookingRoomUsedEN.SetValue(item);
                      aBookingRoomUsedEN.ListCustomer = aCustomersBO.SelectListCustomer_ByIDBookingRoom(item.ID);
                      Rooms aRooms = aRoomsBO.Select_ByCodeRoom(item.CodeRoom, 1);
                      if (aRooms != null)
                      {
                          aBookingRoomUsedEN.RoomSku = aRooms.Sku;
                      }
                      else
                      {
                          aBookingRoomUsedEN.RoomSku = string.Empty;
                      }
                      if (RoomSku == "")
                      {
                          RoomSku = aBookingRoomUsedEN.RoomSku;
                      }
                      else
                      {
                          RoomSku = RoomSku + " + " + aBookingRoomUsedEN.RoomSku;
                      }
                      foreach (Customers aItem in aBookingRoomUsedEN.ListCustomer)
                      {
                          if (CustomerNames == "")
                          {
                              CustomerNames = aItem.Name;
                          }
                          else
                          {
                              CustomerNames = CustomerNames + " + " + aItem.Name;
                          }
                      }
                  }

              }
              decimal MealCharge = 0;
              decimal DrinkCharge = 0;
              decimal    RoomCharge= 0;
               decimal   RoomServiceCharge= 0;
               decimal   Tel= 0;
              decimal Laundry = 0;
              decimal    OtherServiceCharge = 0;
              decimal TotalServiceMoney = 0;
              decimal TotalMoneyBeforeTax = 0;
              foreach (RptPaymentStyle1_ForPrint aItem in aListData)
              {
                  MealCharge = MealCharge + aItem.ServiceGroup8_Fee;
                  DrinkCharge = DrinkCharge + aItem.ServiceGroup7_Fee;
                  RoomCharge = RoomCharge + aItem.Room_Fee;
                  RoomServiceCharge = RoomServiceCharge + aItem.ServiceGroup5_Fee;
                  Tel = Tel + aItem.ServiceGroup2_Fee;
                  Laundry = Laundry + aItem.ServiceGroup3_Fee;
                  OtherServiceCharge = OtherServiceCharge + aItem.ServiceGroup4_Fee + aItem.ServiceGroup5_Fee + aItem.ServiceGroup9_Fee;
                  TotalServiceMoney = TotalServiceMoney + aItem.TotalServiceMoney;
                  TotalMoneyBeforeTax = TotalMoneyBeforeTax + aItem.TotalMoney;
              }

            //Hiển thị dữ liệu
              BookingRs aBookingRs = new BookingRs();
              aBookingRs = (new BookingRsBO()).Select_ByID(IDBookingR);

              lblIDBookingR.Text = IDBookingR.ToString();
              lblInvoiceNumber.Text = aBookingRs.InvoiceNumber;
              lblInvoiceDate.Text = aBookingRs.InvoiceDate.GetValueOrDefault().Date.ToShortDateString();
              lbAcceptDate.Text = aBookingRs.AcceptDate.GetValueOrDefault().Date.ToShortDateString();

              lblCheckIn.Text = FirstDate.ToString("dd/MM/yyyy");
              lblCheckOut.Text = LastDate.ToString("dd/MM/yyyy");
              lblCustomerName.Text = CustomerNames;
              lblRoomSku.Text = RoomSku;

              lblMealChargeVN.Text = MealCharge.ToString("0,0");
              lblDrinkChargeVN.Text = DrinkCharge.ToString("0,0");
              lblRoomChargeVN.Text = RoomCharge.ToString("0,0");
              lblRoomServiceVN.Text = RoomServiceCharge.ToString("0,0");
              lblTelVN.Text = Tel.ToString("0,0");
              lblLaundryVN.Text = Laundry.ToString("0,0");
              lblOtherServiceVN.Text = OtherServiceCharge.ToString("0,0");

              lblServiceChargeVN.Text = TotalServiceMoney.ToString("0,0");
              lblTotalBTVN.Text = TotalMoneyBeforeTax.ToString("0,0");
              lblTaxVN.Text = (TotalMoneyBeforeTax * 10 / 100).ToString("0,0");
              lblMoneyAfterTaxVN.Text = (TotalMoneyBeforeTax * 110 / 100).ToString("0,0");
              lblBookingMoneyVN.Text = Convert.ToDecimal(BookingHMoney + BookingHMoney).ToString("0,0");
              lblTotalMoneyVN.Text = ((TotalMoneyBeforeTax * 110 / 100) - Convert.ToDecimal(BookingHMoney + BookingHMoney)).ToString("0,0");
              string TotalMoney_String = UppercaseFirst(StringUtility.ConvertDecimalToString((TotalMoneyBeforeTax * 110 / 100) - Convert.ToDecimal(BookingHMoney + BookingHMoney)));
              lblConvertToString.Text = TotalMoney_String;

              int day = DateTime.Now.Day;
              int month = DateTime.Now.Month;
              int year = DateTime.Now.Year;
              lblDayMonthYear.Text = "Hà nội , ngày " + day.ToString() + " tháng " + month.ToString() + " năm " + year.ToString();
        }
        //Hiennv     Tạo mới    18/11/2014
        private void viewSelectedRooms_RowCellClick(object sender, DevExpress.XtraGrid.Views.Grid.RowCellClickEventArgs e)
        {
            try
            {
                RoomsBO aRoomsBO = new RoomsBO();
                this.aCurrent_CodeRoom = Convert.ToString(viewSelectedRooms.GetFocusedRowCellValue("RoomCode"));
                lblRoomSku.Text = "Phòng số :" + aRoomsBO.Select_ByCodeRoom(this.aCurrent_CodeRoom, 1).Sku;

                dgvSelectedCustomer.DataSource = null;
                dgvSelectedCustomer.DataSource = this.aCheckInEN.GetListCustomerByRoomCode(this.aCurrent_CodeRoom);
                dgvSelectedCustomer.RefreshDataSource();

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_CheckIn.viewSelectedRooms_RowCellClick\n" + ex.ToString(), "Error ", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        //Hiennv  tạo mới   18/11/2014
        private void frmTsk_CheckIn_Load(object sender, EventArgs e)
        {
            try
            {

                if (this.customerType == 1)
                {
                    chkCustomerType.Visible = true;
                    txtNameCompany.Visible = true;
                }
                else if (this.customerType == 2)
                {
                    chkCustomerType.Visible = false;
                    txtNameCompany.Visible = true;
                }
                else
                {
                    chkCustomerType.Visible = false;
                    txtNameCompany.Visible = false;
                }

                ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();

                dtpFrom.DateTime = DateTime.Now;
                dtpTo.DateTime = aReceptionTaskBO.SetDateValueDefault(DateTime.Now.AddDays(1));

                dgvAvailableRooms.DataSource = this.LoadListAvailableRooms(dtpFrom.DateTime, dtpTo.DateTime);
                dgvAvailableRooms.RefreshDataSource();

                dgvSelectedRooms.DataSource = this.LoadListSelectRooms(dtpFrom.DateTime, dtpTo.DateTime);
                dgvSelectedRooms.RefreshDataSource();

                this.LoadAllListCustomers();

                lueIDCompanies.Properties.DataSource = this.LoadListCompaniesByType(this.customerType);
                lueIDCompanies.Properties.ValueMember = "ID";
                lueIDCompanies.Properties.DisplayMember = "Name";
                if (this.customerType == 3) // khach le
                {
                    if (this.LoadListCompaniesByType(this.customerType).Count > 0)
                    {
                        lueIDCompanies.EditValue = this.LoadListCompaniesByType(this.customerType)[0].ID;
                    }
                }

                lueGender.Properties.DataSource = CORE.CONSTANTS.ListGenders;//Load Gioi tinh
                lueGender.Properties.DisplayMember = "Name";
                lueGender.Properties.ValueMember = "ID";
                lueGender.EditValue = CORE.CONSTANTS.SelectedGender(1).ID;

                lueNationality.Properties.DataSource = CORE.CONSTANTS.ListCountries;//Load Country
                lueNationality.Properties.DisplayMember = "Name";
                lueNationality.Properties.ValueMember = "Code";
                lueNationality.EditValue = CORE.CONSTANTS.SelectedCountry(704).Code;

                lueCitizen.Properties.DataSource = CORE.CONSTANTS.ListCitizens;//Load Citizen
                lueCitizen.Properties.DisplayMember = "Name";
                lueCitizen.Properties.ValueMember = "ID";
                lueCitizen.EditValue = CORE.CONSTANTS.SelectedCitizen(2).ID;

                if (!String.IsNullOrEmpty(this.aCurrent_CodeRoom))
                {
                    RoomsBO aRoomsBO = new RoomsBO();
                    lblRoomSku.Text = "Phòng số :" + aRoomsBO.Select_ByCodeRoom(this.aCurrent_CodeRoom, 1).Sku;
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_CheckIn.frmTsk_CheckIn_Group_Step1_Load\n" + ex.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        private void InitForm()
        {
            // Kiem tra xem phong dang o che do checkIn hay book phong
            if (this.aBookingRoom.Status < 3)
            {
                dtpCheckIn.Text = aBookingRoom.CheckInPlan.ToString();

                dtpCheckOut.Text = aBookingRoom.CheckOutPlan.ToString();
            }
            else if (this.aBookingRoom.Status == 3)  // Phong da checkIn
            {
                dtpCheckIn.Text = DateTime.Now.ToString();
                dtpCheckOut.Text = aBookingRoom.CheckOutPlan.ToString();
            }

            if (aBookingRs.CustomerType == 1)
            {
                lblCustomerType.Text = "Khách nhà nước";
            }
            else if (aBookingRs.CustomerType == 2)
            {
                lblCustomerType.Text = "Cty ngoài";
            }
            else if (aBookingRs.CustomerType == 3)
            {
                lblCustomerType.Text = "Khách lẻ";
            }
            else if (aBookingRs.CustomerType == 4)
            {
                lblCustomerType.Text = "Khách vãng lai";
            }

            CustomersBO aCustomersBO = new CustomersBO();
            CustomerInfoEN aCustomers = new CustomerInfoEN();
            aCustomers = new CustomerInfoEN (aCustomersBO.Select_ByID(aBookingRs.IDCustomer));

            lblCustomer.Text = aCustomers.Name;
            lblTel.Text = aCustomers.Tel;

            CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
            CustomerGroups aCustomerGroups = aCustomerGroupsBO.Select_ByID(aBookingRs.IDCustomerGroup);
            lblGroup.Text = aCustomerGroups.Name;

            CompaniesBO aCompaniesBO = new CompaniesBO();
            lblCompany.Text = aCompaniesBO.Select_ByID(aCustomerGroups.IDCompany).Name;

            // Fill All Customer

            dgvAvailableCustomers.DataSource = ConvertListCustomer ((new CustomersBO()).Select_All());

            lueRooms.Properties.DataSource = this.GetAvaiableRoom();
            lueRooms.Properties.ValueMember = "Code";
            lueRooms.Properties.DisplayMember = "Sku";

            RoomsBO aRoomsBO = new RoomsBO();
            Rooms aRooms = new Rooms();
            aRooms = aRoomsBO.Select_ByCodeRoom(this.aBookingRoom.CodeRoom, 1);

            lueRooms.Properties.NullText = aRooms.Sku;
            lueRooms.SelectedText = aRooms.Sku;
            lueRooms.EditValue = aRooms.Code;

            BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();
            List<BookingRoomsMembers> aListBookingRoomsMembers = aBookingRoomsMembersBO.Select_ByIDBookingRoom (this.aBookingRoom.ID);

            dgvSelectCustomers.DataSource = GetCustomers(aListBookingRoomsMembers);

            //this.aChangeRoomEn.InsertItemChangeRooms()
        }
        private void ResetFormWhenTimeChange()
        {
            if (aBookingRs.CustomerType == 1)
            {
                lblCustomerType.Text = "Khách nhà nước";
            }
            else if (aBookingRs.CustomerType == 2)
            {
                lblCustomerType.Text = "Cty ngoài";
            }
            else if (aBookingRs.CustomerType == 3)
            {
                lblCustomerType.Text = "Khách lẻ";
            }
            else if (aBookingRs.CustomerType == 4)
            {
                lblCustomerType.Text = "Khách vãng lai";
            }

            CustomersBO aCustomersBO = new CustomersBO();
            CustomerInfoEN aCustomers = new CustomerInfoEN();
            aCustomers = new CustomerInfoEN (aCustomersBO.Select_ByID(aBookingRs.IDCustomer));

            lblCustomer.Text = aCustomers.Name;
            lblTel.Text = aCustomers.Tel;

            CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO();
            CustomerGroups aCustomerGroups = aCustomerGroupsBO.Select_ByID(aBookingRs.IDCustomerGroup);
            lblGroup.Text = aCustomerGroups.Name;

            CompaniesBO aCompaniesBO = new CompaniesBO();
            lblCompany.Text = aCompaniesBO.Select_ByID(aCustomerGroups.IDCompany).Name;

            // Fill All Customer

            dgvAvailableCustomers.DataSource = ConvertListCustomer ((new CustomersBO()).Select_All());

            lueRooms.Properties.DataSource = this.GetAvaiableRoom();
            lueRooms.Properties.ValueMember = "Code";
            lueRooms.Properties.DisplayMember = "Sku";

            RoomsBO aRoomsBO = new RoomsBO();
            Rooms aRooms = new Rooms();
            aRooms = aRoomsBO.Select_ByCodeRoom(this.aBookingRoom.CodeRoom, 1);

            lueRooms.Properties.NullText = aRooms.Sku;
            lueRooms.SelectedText = aRooms.Sku;
            lueRooms.EditValue = aRooms.Code;

            BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();
            List<BookingRoomsMembers> aListBookingRoomsMembers = aBookingRoomsMembersBO.Select_ByIDBookingRoom (this.aBookingRoom.ID);

            dgvSelectCustomers.DataSource = GetCustomers(aListBookingRoomsMembers);
        }
        public List<RoomServiceInfoEN> Select_Service_ByCodeRoom_ByStatus(string Code, DateTime now,int Status)
        {
            try
            {
                string Sku = string.Empty;
                RoomsBO aRoomsBO = new RoomsBO();
                Rooms aRooms = aRoomsBO.Select_ByCodeRoom(Code,1);
                if(aRooms !=null)
                {
                    Sku = aRooms.Sku;
                }

                int IDBookingRoom=0;
                BookingRsBO aBookingRsBO = new BookingRsBO();
                List<BookingRooms> aListBookingRooms =aDatabaseDA.BookingRooms.Where(p => p.CodeRoom == Code && p.CheckInActual < now && p.CheckOutActual > now && (p.Status == 3 || p.Status == 7)).ToList();
                if(aListBookingRooms.Count > 0)
                {
                    IDBookingRoom = aListBookingRooms[0].ID;
                }
                List<RoomServiceInfoEN> alist = aDatabaseDA.vw__BookingRooms_ServicesInfo__BookingRooms_BookingRoomsServices_Services_ServiceGroups
                                .Where(p => p.BookingRooms_Services_IDBookingRoom == IDBookingRoom && p.BookingRooms_Services_Status !=Status)
                                .Select(p => new RoomServiceInfoEN
                                {
                                    IDBookingRooms = IDBookingRoom,
                                    IDBookingRs = p.BookingRooms_IDBookingR,
                                    CodeRoom = Code,
                                    Sku = Sku,
                                    ID = p.BookingRooms_Services_ID,
                                    Date = p.BookingRooms_Services_Date,
                                    IDService=p.Services_ID,
                                    ServiceName = p.Services_Name,
                                    IDServiceGroup=p.ServiceGroups_ID,
                                    Quantity = p.BookingRooms_Services_Quantity,
                                    CostRef = p.Services_CostRef,
                                    Unit = p.Services_Unit,
                                    Cost = p.BookingRooms_Services_Cost,
                                    PercentTax = p.BookingRooms_Services_PercentTax,
                                    Status=p.BookingRooms_Services_Status

                                }).ToList();

                return alist;
            }
            catch (Exception ex)
            {
                throw new Exception("BookingRooms_ServicesBO.Sel_Service_BySku\n" + ex.ToString());
            }
        }
        public decimal? CalculateCostRoom(string CodeRoom, string PriceType, int CustomerType, int NumCustomer)
        {
            if (NumCustomer > 0)
            {
                CustomersBO aCustomersBO = new CustomersBO();
                ExtraCostBO aExtraCostBO = new ExtraCostBO();
                RoomsBO aRoomsBO = new RoomsBO();
                //List<Customers> aListCustomers = aCustomersBO.SelectListCustomer_ByIDBookingRoom(IDBookingRoom);

                decimal? CostRoom = 0;

                Rooms aRooms = aRoomsBO.Select_ByCodeRoom(CodeRoom, 1);
                CostRoom = aRooms.CostRef;
                string RoomSku = aRooms.Sku;

                decimal ExtraMoneyRoom = Convert.ToDecimal(aExtraCostBO.Select_BySku_ByPriceType_ByNumberPeople(RoomSku, PriceType, NumCustomer).ExtraValue);

                return (CostRoom + ExtraMoneyRoom);
            }
            else
            {
                return 0;
            }
        }
        public void CheckOut(int IDBookingRoom)
        {
            try
            {
                RoomsBO aRoomsBO = new RoomsBO();
                ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();
                ExtraCostBO aExtraCostBO = new ExtraCostBO();
                BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO();
                BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO();

                BookingRooms aBookingRooms = aBookingRoomsBO.Select_ByID(IDBookingRoom);
                List<BookingRoomsMembers> aListCus = aBookingRoomsMembersBO.Select_ByIDBookingRoom(IDBookingRoom);
                aBookingRooms.CheckOutActual = DateTime.Now;
                aBookingRooms.Status = 7;
                aBookingRooms.AddTimeStart = Convert.ToDouble(aReceptionTaskBO.GetAddTimeStart(aBookingRooms.Type.GetValueOrDefault(0), aBookingRooms.CheckInActual));
                aBookingRooms.AddTimeEnd = Convert.ToDouble(aReceptionTaskBO.GetAddTimeEnd(aBookingRooms.Type.GetValueOrDefault(0), aBookingRooms.CheckOutActual));
                aBookingRooms.TimeInUse = Convert.ToDecimal(aReceptionTaskBO.GetTimeInUsed(aBookingRooms.CheckInActual, aBookingRooms.CheckOutActual) * 24 * 60);
                Rooms aRooms = aRoomsBO.Select_ByCodeRoom(aBookingRooms.CodeRoom, 1);
                if (aRooms != null)
                {
                    if (aBookingRooms.Cost == null)
                    {
                        decimal? cost = 0;
                        cost = aBookingRooms.CostRef_Rooms;
                        aBookingRooms.Cost = cost + Convert.ToDecimal(aExtraCostBO.Select_BySku_ByPriceType_ByNumberPeople(aRooms.Sku, aBookingRooms.PriceType, aListCus.Count).ExtraValue);
                    }
                }

                aBookingRoomsBO.Update(aBookingRooms);
            }
            catch (Exception ex)
            {

                throw new Exception("AccountancyBO.CheckOut\n" + ex.ToString());
            }
        }
예제 #19
0
        public List<RoomExtStatusEN> GetStatusRoom(List<string> ListCodeRoom, DateTime now)
        {
            List<RoomExtStatusEN> ret = new List<RoomExtStatusEN>();
            List<sp_RoomExt_GetCurrentStatusRooms_ByListCodeRoom_ByTime_Result> aList = this.aDatabaseDA.sp_RoomExt_GetCurrentStatusRooms_ByListCodeRoom_ByTime(string.Join(",", ListCodeRoom), now,1).ToList();

            RoomExtStatusEN aRoomExtStatusEN = new RoomExtStatusEN();

            for (int i = 0; i < aList.Count; i++)
            {
                aRoomExtStatusEN = new RoomExtStatusEN();
                aRoomExtStatusEN.ID = aList[i].ID;
                aRoomExtStatusEN.Bed1 = aList[i].Bed1;
                aRoomExtStatusEN.Bed2 = aList[i].Bed2;
                aRoomExtStatusEN.CostRef = aList[i].CostRef;
                aRoomExtStatusEN.Code = aList[i].Code;
                aRoomExtStatusEN.Sku = aList[i].Sku;
                aRoomExtStatusEN.Note = aList[i].Note;
                aRoomExtStatusEN.Type = aList[i].Type;
                aRoomExtStatusEN.LevelSku = aList[i].LevelSku;
                aRoomExtStatusEN.OrderSku = aList[i].OrderSku;
                aRoomExtStatusEN.BookingRooms_ID = aList[i].BookingRooms_ID;
                aRoomExtStatusEN.Disable = aList[i].Disable;

                aRoomExtStatusEN.BookingRs_BookingMoney = aList[i].BookingRs_BookingMoney;
                aRoomExtStatusEN.BookingRs_CustomerType = aList[i].BookingRs_CustomerType;
                aRoomExtStatusEN.BookingRs_ID = aList[i].BookingRs_ID;
                aRoomExtStatusEN.BookingRs_Subject = aList[i].BookingRs_Subject;
                aRoomExtStatusEN.CheckInActual = aList[i].CheckInActual;
                aRoomExtStatusEN.CheckInPlan = aList[i].CheckInPlan;
                aRoomExtStatusEN.CheckOutActual = aList[i].CheckOutActual;
                aRoomExtStatusEN.CheckOutPlan = aList[i].CheckOutPlan;
                aRoomExtStatusEN.Color = aList[i].Color;
                aRoomExtStatusEN.Companies_Name = aList[i].Companies_Name;
                aRoomExtStatusEN.CostRef = aList[i].CostRef;
                aRoomExtStatusEN.CustomerGroups_Name = aList[i].CustomerGroups_Name;
                aRoomExtStatusEN.CustomerGroups_ID = aList[i].CustomerGroups_ID;
                aRoomExtStatusEN.Companies_ID = aList[i].Companies_ID;

                aRoomExtStatusEN.Customers_Address = aList[i].Customers_Address;
                aRoomExtStatusEN.Customers_Name = aList[i].Customers_Name;
                aRoomExtStatusEN.Customers_Nationality = aList[i].Customers_Nationality;
                aRoomExtStatusEN.Customers_Tel = aList[i].Customers_Tel;
                aRoomExtStatusEN.Customers_ID = aList[i].Customers_ID;

                if (aList[i].BookingRooms_Status == 1)
                {
                    aRoomExtStatusEN.RoomStatus = 1;
                }
                else if (aList[i].BookingRooms_Status == 2)
                {
                    aRoomExtStatusEN.RoomStatus = 2;
                }
                else if (aList[i].BookingRooms_Status == 3)
                {
                    aRoomExtStatusEN.RoomStatus = 3;
                }
                else if (aList[i].BookingRooms_Status == 5)
                {
                    aRoomExtStatusEN.RoomStatus = 5;
                }
                else if ((aList[i].BookingRooms_Status == 6) || (aList[i].BookingRooms_Status == 7) || (aList[i].BookingRooms_Status == 8))
                {
                    aRoomExtStatusEN.RoomStatus = 0;
                }
                ret.Add(aRoomExtStatusEN);

            }
            ret = ret.Distinct().ToList();

            List<string> aListCodeTempt = aList.Select(p=>p.Code).ToList();

            //-----------------------------------
            // Xoa nhung phong da dang su dung vao thoi diem do, con lai nhung phong trong
            for (int iii = 0 ; iii<aListCodeTempt.Count ; iii++)
            {
                ListCodeRoom.Remove(aListCodeTempt[iii]);
            }
            //-----------------------------------
            // Lay thong tin phong trong
            for (int iii = 0; iii < ListCodeRoom.Count; iii++)
            {
                RoomsBO aRoomsBO = new RoomsBO();
                Rooms aRooms = aRoomsBO.Select_ByCodeRoom(ListCodeRoom[iii],1);
                if (aRooms != null)
                {
                    aRoomExtStatusEN = new RoomExtStatusEN();
                    aRoomExtStatusEN.RoomStatus = 0;
                    aRoomExtStatusEN.Code = aRooms.Code;
                    aRoomExtStatusEN.Sku = aRooms.Sku;
                    aRoomExtStatusEN.Bed1 = aRooms.Bed1;
                    aRoomExtStatusEN.Bed2 = aRooms.Bed2;
                    aRoomExtStatusEN.Type = aRooms.Type;
                    aRoomExtStatusEN.LevelSku = aRooms.LevelSku;
                    aRoomExtStatusEN.OrderSku = aRooms.OrderSku;
                    aRoomExtStatusEN.Disable = aRooms.Disable;
                    ret.Add(aRoomExtStatusEN);
                }
                else
                {
                    throw new Exception("Phòng cần check trạng thái không tồn tại");

                }
            }

            return ret.Distinct().ToList();
        }
        //=======================================================
        //Author: Ngoc
        //Function : GetRevenueRoom
        //=======================================================
        public List<RevenueEN> GetRevenueRoom(DateTime From, DateTime To, List<string> ListCodeRoom)
        {
            try
            {
                ReceptionTaskBO aReceptionTaskBO = new ReceptionTaskBO();
                List<sp_RoomsExt_CalculationRevenue_Result> aListSP = new List<sp_RoomsExt_CalculationRevenue_Result>();
                double UsedDate = new double();
                List<RevenueEN> aListRevenueRoom = new List<RevenueEN>();
                TimeSpan dis = To.Subtract(From);
                double TotalDate = dis.TotalDays;

                RevenueEN aRevenueEN;
                RoomsBO aRoomsBO = new RoomsBO();

                //ListCodeRoom.Count
                for (int i = 0; i < ListCodeRoom.Count; i++)
                {
                    aRevenueEN = new RevenueEN();
                    aRevenueEN.CodeRoom = ListCodeRoom[i];
                    aRevenueEN.Sku = aRoomsBO.Select_ByCodeRoom(ListCodeRoom[i], 1).Sku;
                    aListSP = aDatabaseDA.sp_RoomsExt_CalculationRevenue(ListCodeRoom[i], From, To).ToList();
                    for (int ii = 0; ii < aListSP.Count; ii++)
                    {

                        if (aListSP[ii].TypeCalculationRevenue == 1) // Khach da thanh toan, lay gia theo cost
                        {
                            Double NoTax = Convert.ToDouble(aListSP[ii].Cost) * Convert.ToDouble(aListSP[ii].TimeInUse / 24 / 60);
                            Double Cost = NoTax + NoTax * Convert.ToDouble(aListSP[ii].PercentTax) / 100;

                            Double CostEstimate = Cost;
                            aRevenueEN.Revenue = aRevenueEN.Revenue + CostEstimate;
                        }
                        else if (aListSP[ii].TypeCalculationRevenue == 2) // Khach da check out nhung chua thanh toan, tu dong tinh tien
                        {
                            Double NoTax = Convert.ToDouble(aListSP[ii].Cost) * Convert.ToDouble(aListSP[ii].TimeInUse / 24 /60);
                            Double Cost = NoTax + NoTax * Convert.ToDouble(aListSP[ii].PercentTax) / 100;

                            Double CostEstimate = Cost;
                            aRevenueEN.Revenue = aRevenueEN.Revenue + CostEstimate;
                        }
                        else if (aListSP[ii].TypeCalculationRevenue == 3) // Khach da check in nhung chua check out, lay ngay check out du kien ra de tinh tien
                        {
                            //Double NoTax = Convert.ToDouble(aListSP[ii].Cost) * Convert.ToDouble(aReceptionTaskBO.CaculateBooking(aListSP[ii].ID,aListSP[ii].CheckInActual, aListSP[ii].CheckOutPlan));
                            //Double Cost = NoTax + NoTax * Convert.ToDouble(aListSP[ii].PercentTax) / 100;

                            //Double CostEstimate = Cost;
                            //aRevenueEN.Revenue = aRevenueEN.Revenue + CostEstimate;
                        }
                        else if (aListSP[ii].TypeCalculationRevenue == 4) // khach hang Pending nhung da checkoutActual ,lay ngay checkoutActual de tinh tien
                        {
                            //Double NoTax = Convert.ToDouble(aListSP[ii].Cost) * Convert.ToDouble(aReceptionTaskBO.CaculateBooking(aListSP[ii].ID,aListSP[ii].CheckInActual, aListSP[ii].CheckOutActual)) * Convert.ToDouble(aListSP[ii].CostPendingRoom / 100);
                            //Double Cost = NoTax + NoTax * Convert.ToDouble(aListSP[ii].PercentTax) / 100;

                            //Double CostEstimate = Cost;
                            //aRevenueEN.Revenue = aRevenueEN.Revenue + CostEstimate;
                        }

                    }
                    aListRevenueRoom.Add(aRevenueEN);

                }

                return aListRevenueRoom;
            }
            catch (Exception ex)
            {
                throw new Exception("ReportTaskBO.GetRevenueRoom \n" + ex.ToString());
            }
        }
        //Hiennv    Tạo mới     18/11/2014
        private void btnSelect_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            try
            {
                RoomMemberEN aRoomMemberEN = new RoomMemberEN();
                aRoomMemberEN.RoomSku = viewAvailableRooms.GetFocusedRowCellValue("RoomSku").ToString();
                aRoomMemberEN.RoomCode = viewAvailableRooms.GetFocusedRowCellValue("RoomCode").ToString();
                aRoomMemberEN.RoomTypeDisplay = viewAvailableRooms.GetFocusedRowCellValue("RoomTypeDisplay").ToString();
                aRoomMemberEN.RoomBed1 = Convert.ToInt32(viewAvailableRooms.GetFocusedRowCellValue("RoomBed1").ToString());
                aRoomMemberEN.RoomBed2 = Convert.ToInt32(viewAvailableRooms.GetFocusedRowCellValue("RoomBed2").ToString());
                aRoomMemberEN.RoomCostRef = Convert.ToDecimal(viewAvailableRooms.GetFocusedRowCellValue("RoomCostRef").ToString());

                this.aCheckInEN.InsertRoom(aRoomMemberEN);
                dgvSelectedRooms.DataSource = this.aCheckInEN.aListRoomMembers;
                dgvSelectedRooms.RefreshDataSource();

                RoomMemberEN Temps = aListAvaiableRooms.Where(p => p.RoomSku == viewAvailableRooms.GetFocusedRowCellValue("RoomSku").ToString()).ToList()[0];
                this.aListAvaiableRooms.Remove(Temps);
                dgvAvailableRooms.DataSource = this.aListAvaiableRooms;
                dgvAvailableRooms.RefreshDataSource();

                RoomsBO aRoomsBO = new RoomsBO();
                this.aCurrent_CodeRoom = aRoomMemberEN.RoomCode;
                lblRoomSku.Text = "Phòng số :" + aRoomsBO.Select_ByCodeRoom(this.aCurrent_CodeRoom, 1).Sku;

                dgvSelectedCustomer.DataSource = null;
                dgvSelectedCustomer.DataSource = this.aCheckInEN.GetListCustomerByRoomCode(this.aCurrent_CodeRoom);
                dgvSelectedCustomer.RefreshDataSource();

            }
            catch (Exception ex)
            {
                MessageBox.Show("frmTsk_CheckIn.btnSelect_ButtonClick\n" + ex.ToString(), "Error ", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
        //Hiennv
        public List<ServicesEN> GetListService_ByIDBookingRoom_ByStatus(int IDBookingRoom, int Status)
        {
            try
            {
                List<vw__BookingRooms_ServicesInfo__BookingRooms_BookingRoomsServices_Services_ServiceGroups> aListTemp = new List<vw__BookingRooms_ServicesInfo__BookingRooms_BookingRoomsServices_Services_ServiceGroups>();
                aListTemp = aDatabaseDA.vw__BookingRooms_ServicesInfo__BookingRooms_BookingRoomsServices_Services_ServiceGroups.Where(v => v.BookingRooms_Services_IDBookingRoom == IDBookingRoom && v.BookingRooms_Services_Status != Status).ToList();
                List<ServicesEN> aListReturn = new List<ServicesEN>();
                ServicesEN aServicesEN;
                RoomsBO aRoomsBO = new RoomsBO();

                for (int i = 0; i < aListTemp.Count; i++)
                {
                    aServicesEN = new ServicesEN();
                    aServicesEN.BookingRooms_Services_ID = aListTemp[i].BookingRooms_Services_ID;

                    aServicesEN.IDBookingRoomService = aListTemp[i].BookingRooms_Services_ID;

                    aServicesEN.IDBookingRoom = aListTemp[i].BookingRooms_Services_IDBookingRoom;
                    aServicesEN.CodeRoom = aListTemp[i].BookingRooms_CodeRoom;
                    Rooms aRooms = aRoomsBO.Select_ByCodeRoom(aListTemp[i].BookingRooms_CodeRoom, 1);
                    if (aRooms != null)
                    {
                        aServicesEN.Sku = aRooms.Sku;
                    }
                    aServicesEN.ServiceGroupName = aListTemp[i].ServiceGroups_Name;
                    aServicesEN.IDServiceGroup = aListTemp[i].ServiceGroups_ID;
                    aServicesEN.IDService = aListTemp[i].Services_ID;
                    aServicesEN.Date = aListTemp[i].BookingRooms_Services_Date;
                    aServicesEN.Name = aListTemp[i].Services_Name;
                    aServicesEN.Quantity = aListTemp[i].BookingRooms_Services_Quantity;
                    aServicesEN.Cost = aListTemp[i].BookingRooms_Services_Cost;
                    aServicesEN.CostRef_Service = aListTemp[i].Services_CostRef;
                    aServicesEN.PercentTax = aListTemp[i].BookingRooms_Services_PercentTax;
                    aListReturn.Insert(i, aServicesEN);
                }

                return aListReturn;

            }
            catch (Exception ex)
            {

                throw new Exception("ReceptionTaskBO.GetListService_ByIDBookingRoom_ByStatus\n" + ex.ToString());
            }
        }