// ===============================================================================
        // 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();
            }
        }
        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();
        }
        private decimal EstimateCostRoomInLastDayBeforeTax(BookingRoomUsedEN LastDay)
        {
            int BookingRoom_Type = LastDay.Type.GetValueOrDefault(0);
               int BookingRoom_Status = LastDay.Status.GetValueOrDefault(0);
               double AddTimeStart = LastDay.AddTimeStart.GetValueOrDefault(0);
               double AddTimeEnd = LastDay.AddTimeEnd.GetValueOrDefault(0);
               decimal Cost = LastDay.Cost.GetValueOrDefault(0);

               if ((BookingRoom_Type == 0) && (BookingRoom_Type == 2))// Khong tinh checkInsom
               {
               return Cost * (decimal)0.5;
               }
               else //if ((BookingRoom_Type == 1) && (BookingRoom_Type == 3))// Khong tinh checkInsom
               {
               return Cost * ((decimal)0.5 + (decimal)AddTimeEnd);
               }
        }
        private decimal EstimateCostRoomInUseBeforeTax(BookingRoomUsedEN RoomInUse)
        {
            //int BookingRoom_Type = RoomInUse.Type.GetValueOrDefault(0);
               //int BookingRoom_Status = RoomInUse.Status.GetValueOrDefault(0);
               //double AddTimeStart = RoomInUse.AddTimeStart.GetValueOrDefault(0);
               //double AddTimeEnd = RoomInUse.AddTimeEnd.GetValueOrDefault(0);
               //decimal Cost = RoomInUse.Cost.GetValueOrDefault(0);

               //if ((BookingRoom_Type == 0) && (BookingRoom_Type == 2))// Khong tinh checkInsom
               //{
               //    return Cost * (decimal)0.5;
               //}
               //if ((BookingRoom_Type == 1) && (BookingRoom_Type == 3))// Khong tinh checkInsom
               //{
               //    return Cost * ((decimal)0.5 + (decimal)AddTimeEnd);
               //}

               //else return Cost;

               return 0;
        }
        public int SaveBookingRoom(BookingRoomUsedEN aBookingRoomUsedEN)
        {
            DatabaseDA aDatabaseDA = new DatabaseDA();
            BookingRooms aTemp = aDatabaseDA.BookingRooms.Where(a => a.ID == aBookingRoomUsedEN.ID).ToList()[0];
            aTemp.ID = aBookingRoomUsedEN.ID;
            aTemp.IDBookingR = aBookingRoomUsedEN.IDBookingR;
            aTemp.CodeRoom = aBookingRoomUsedEN.CodeRoom;
            aTemp.Cost = aBookingRoomUsedEN.Cost;
            aTemp.PercentTax = aBookingRoomUsedEN.PercentTax;
            aTemp.CostRef_Rooms = aBookingRoomUsedEN.CostRef_Rooms;
            aTemp.Note = aBookingRoomUsedEN.Note;
            aTemp.CheckInPlan = aBookingRoomUsedEN.CheckInPlan;
            aTemp.CheckInActual = aBookingRoomUsedEN.CheckInActual;
            aTemp.CheckOutPlan = aBookingRoomUsedEN.CheckOutPlan;
            aTemp.CheckOutActual = aBookingRoomUsedEN.CheckOutActual;
            aTemp.BookingStatus = aBookingRoomUsedEN.BookingStatus;
            aTemp.Status = aBookingRoomUsedEN.Status;

            aTemp.StartTime = aBookingRoomUsedEN.StartTime;
            aTemp.EndTime = aBookingRoomUsedEN.EndTime;

            aTemp.IsAllDayEvent = aBookingRoomUsedEN.IsAllDayEvent;
            aTemp.Color = aBookingRoomUsedEN.Color;
            aTemp.IsRecurring = aBookingRoomUsedEN.IsRecurring;
            aTemp.IsEditable = aBookingRoomUsedEN.IsEditable;
            aTemp.AdditionalColumn1 = aBookingRoomUsedEN.AdditionalColumn1;
            aTemp.CostPendingRoom = aBookingRoomUsedEN.CostPendingRoom;
            aTemp.TimeInUse = aBookingRoomUsedEN.TimeInUse;
            aTemp.AddTimeStart = aBookingRoomUsedEN.AddTimeStart;
            aTemp.AddTimeEnd = aBookingRoomUsedEN.AddTimeEnd;

            aTemp.Type = aBookingRoomUsedEN.Type;

            aTemp.Disable = aBookingRoomUsedEN.Disable;
            aTemp.IndexSubPayment = aBookingRoomUsedEN.IndexSubPayment;
            aTemp.AcceptDate = aBookingRoomUsedEN.AcceptDate;
            aTemp.InvoiceDate = aBookingRoomUsedEN.InvoiceDate;
            aTemp.InvoiceNumber = aBookingRoomUsedEN.InvoiceNumber;

            foreach (ServiceUsedEN item in aBookingRoomUsedEN.ListServiceUsed)
            {
                this.SaveServiceUsed(item, 1);
            }
            aTemp.PriceType = aBookingRoomUsedEN.PriceType;
            aDatabaseDA.BookingRooms.AddOrUpdate(aTemp);
            return aDatabaseDA.SaveChanges();
        }