//Hiennv 26/11/2014 Viet lai phuong thuc checkInForRoomBooking public bool NewCheckInForRoomBooking(CheckInEN aCheckInEN) { try { CustomersBO aCustomersBO = new CustomersBO(); List<Customers> aListCustomersTemp = aCustomersBO.Select_All(); BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO(); List<BookingRooms> aListBookingRoomTemp = aBookingRoomsBO.Select_All(); int IDBookingRooms = 0; int IDCompany = 0; int IDCustomerGroup = 0; int IDCustomer = 0; int Result = 0; string customerType = string.Empty; if (aCheckInEN.CustomerType == 0) { customerType = "Tất cả loại khác"; } else if (aCheckInEN.CustomerType == 1) { customerType = "Khách nhà nước"; } else if (aCheckInEN.CustomerType == 2) { customerType = "Khách đoàn"; } else if (aCheckInEN.CustomerType == 3) { customerType = "Khách lẻ"; } else if (aCheckInEN.CustomerType == 4) { customerType = "Khách vãng lai"; } else if (aCheckInEN.CustomerType == 5) { customerType = "Khách bộ ngoại giao"; } else { customerType = string.Empty; } #region Them moi cong ty khi cong ty chua co if (aCheckInEN.IDCompany > 0) { IDCompany = aCheckInEN.IDCompany; } else { CompaniesBO aCompaniesBO = new CompaniesBO(); Companies aCompanies = new Companies(); if (aCheckInEN.NameCompany.Length > 250) { aCompanies.Name = aCheckInEN.NameCompany.Substring(0, 250); } else { aCompanies.Name = aCheckInEN.NameCompany; } aCompanies.TaxNumberCode = string.Empty; aCompanies.Address = string.Empty; aCompanies.Type = aCheckInEN.CustomerType; aCompanies.Status = 1; aCompanies.Disable = false; IDCompany = aCompaniesBO.Insert(aCompanies); } #endregion #region Them moi nhom vao trong cong ty CustomerGroupsBO aCustomerGroupsBO = new CustomerGroupsBO(); CustomerGroups aCustomerGroups; aCustomerGroups = aCustomerGroupsBO.Select_ByIDCompanyAndIDCustomerGroup(IDCompany, aCheckInEN.IDCustomerGroup); if (aCustomerGroups == null) { aCustomerGroups = new CustomerGroups(); string nameGroup = "[" + customerType + "][" + aCheckInEN.NameCompany + "][" + DateTime.Now.ToString() + "]"; aCustomerGroups.IDCompany = IDCompany; if (nameGroup.Length > 250) { aCustomerGroups.Name = nameGroup.Substring(0, 250); } else { aCustomerGroups.Name = nameGroup; } aCustomerGroups.Type = 1; aCustomerGroups.Status = 1; aCustomerGroups.Disable = false; IDCustomerGroup = aCustomerGroupsBO.Insert(aCustomerGroups); } else { IDCustomerGroup = aCheckInEN.IDCustomerGroup; } #endregion string subject = "[" + customerType + "][" + aCheckInEN.NameCompany + "][" + DateTime.Now.ToString() + "]"; BookingRsBO aBookingRsBO = new BookingRsBO(); BookingRs aBookingRs = aBookingRsBO.Select_ByID(aCheckInEN.IDBookingR); if (aBookingRs != null) { aBookingRs.CreatedDate = DateTime.Now; aBookingRs.CustomerType = aCheckInEN.CustomerType; aBookingRs.BookingType = aCheckInEN.BookingType; if (subject.Length > 250) { aBookingRs.Subject = subject.Substring(0, 250); } else { aBookingRs.Subject = subject; } aBookingRs.IDCustomerGroup = IDCustomerGroup; aBookingRs.IDCustomer = aCheckInEN.IDCustomer; aBookingRs.IDSystemUser = aCheckInEN.IDSystemUser; aBookingRs.PayMenthod = aCheckInEN.PayMenthod; aBookingRs.StatusPay = aCheckInEN.StatusPay; aBookingRs.BookingMoney = aCheckInEN.BookingMoney; aBookingRs.ExchangeRate = aCheckInEN.ExchangeRate; aBookingRs.Level = 0;// de mac dinh hien tai chua dung den aBookingRs.Note = string.Empty; aBookingRs.Description = string.Empty; aBookingRs.DatePay = aCheckInEN.CheckOutPlan; aBookingRs.DateEdit = aCheckInEN.CheckInActual; aBookingRs.Status = aCheckInEN.Status; aBookingRs.Type = aCheckInEN.Type; aBookingRs.Disable = aCheckInEN.Disable; aBookingRsBO.Update(aBookingRs); } //========================================================== BookingRooms aBookingRooms; BookingRoomsMembers aBookingRoomsMembers; for (int i = 0; i < aCheckInEN.aListRoomMembers.Count; i++) { List<BookingRooms> aListBookingRoom = aListBookingRoomTemp.Where(r => r.ID == aCheckInEN.aListRoomMembers[i].IDBookingRooms).ToList(); if (aListBookingRoom.Count > 0) { aBookingRooms = new BookingRooms(); aBookingRooms = aListBookingRoom[0]; aBookingRooms.IDBookingR = aCheckInEN.IDBookingR; aBookingRooms.CodeRoom = aCheckInEN.aListRoomMembers[i].RoomCode; aBookingRooms.PercentTax = 10; aBookingRooms.CostRef_Rooms = aCheckInEN.aListRoomMembers[i].RoomCostRef; aBookingRooms.Cost = aCheckInEN.aListRoomMembers[i].RoomCostRef; aBookingRooms.CheckInPlan = aCheckInEN.CheckInActual; aBookingRooms.CheckInActual = aCheckInEN.CheckInActual; aBookingRooms.CheckOutPlan = aCheckInEN.CheckOutPlan; aBookingRooms.CheckOutActual = aCheckInEN.CheckOutActual; aBookingRooms.StartTime = aCheckInEN.CheckInActual; aBookingRooms.EndTime = aCheckInEN.CheckOutPlan; aBookingRooms.BookingStatus = 1; aBookingRooms.Type = 3; //Tính CheckIn sớm và CheckOut muộn aBookingRooms.Status = aCheckInEN.Status; aBookingRooms.PriceType = "G1"; aBookingRoomsBO.Update(aBookingRooms); IDBookingRooms = aCheckInEN.aListRoomMembers[i].IDBookingRooms; } else { aBookingRooms = new BookingRooms(); aBookingRooms.IDBookingR = aCheckInEN.IDBookingR; aBookingRooms.CodeRoom = aCheckInEN.aListRoomMembers[i].RoomCode; aBookingRooms.PercentTax = 10; aBookingRooms.CostRef_Rooms = aCheckInEN.aListRoomMembers[i].RoomCostRef; aBookingRooms.Cost = aCheckInEN.aListRoomMembers[i].RoomCostRef; aBookingRooms.CheckInPlan = aCheckInEN.CheckInActual; aBookingRooms.CheckInActual = aCheckInEN.CheckInActual; aBookingRooms.CheckOutPlan = aCheckInEN.CheckOutPlan; aBookingRooms.CheckOutActual = aCheckInEN.CheckOutActual; aBookingRooms.StartTime = aCheckInEN.CheckInActual; aBookingRooms.EndTime = aCheckInEN.CheckOutPlan; aBookingRooms.BookingStatus = 1; aBookingRooms.Type = 3; //Tính CheckIn sớm và CheckOut muộn aBookingRooms.Status = aCheckInEN.Status; aBookingRooms.PriceType = "G1"; //add new bookingRoom IDBookingRooms = aBookingRoomsBO.Insert(aBookingRooms); } //----------------------------------------------------------- aBookingRoomsMembers = new BookingRoomsMembers(); aBookingRoomsMembers.IDBookingRoom = IDBookingRooms; BookingRoomsMembersBO aBookingRoomsMembersBO = new BookingRoomsMembersBO(); for (int ii = 0; ii < aCheckInEN.aListRoomMembers[i].ListCustomer.Count; ii++) { Customers aCustomers; List<Customers> aListCustomers = aListCustomersTemp.Where(c => c.ID == aCheckInEN.aListRoomMembers[i].ListCustomer[ii].ID).ToList(); if (aListCustomers.Count > 0) { IDCustomer = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].ID; aCustomers = aListCustomers[0]; aCustomers.Name = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Name; aCustomers.Identifier1 = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Identifier1; aCustomers.Birthday = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Birthday; aCustomers.Gender = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Gender; aCustomers.Tel = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Tel; aCustomers.Nationality = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Nationality; aCustomersBO.Update(aCustomers); } else { aCustomers = new Customers(); aCustomers.Name = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Name; aCustomers.Identifier1 = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Identifier1; aCustomers.Birthday = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Birthday; aCustomers.Gender = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Gender; aCustomers.Tel = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Tel; aCustomers.Nationality = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Nationality; //Them moi khach hang IDCustomer = aCustomersBO.Insert(aCustomers); } aBookingRoomsMembers.IDCustomer = IDCustomer; aBookingRoomsMembers.PurposeComeVietnam = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].PurposeComeVietnam; aBookingRoomsMembers.DateEnterCountry = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].DateEnterCountry; aBookingRoomsMembers.EnterGate = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].EnterGate; aBookingRoomsMembers.TemporaryResidenceDate = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].TemporaryResidenceDate; aBookingRoomsMembers.LimitDateEnterCountry = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].LimitDateEnterCountry; aBookingRoomsMembers.Organization = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Organization; aBookingRoomsMembers.LeaveDate = aCheckInEN.aListRoomMembers[i].ListCustomer[ii].LeaveDate; //add new bookingRoomMember aBookingRoomsMembersBO.Insert(aBookingRoomsMembers); #region them nguoi vao trong customergroup_customer string nameCustomerGroup_customer = "[" + customerType + "][" + aCheckInEN.aListRoomMembers[i].ListCustomer[ii].Name + "]"; CustomerGroups_CustomersBO aCustomerGroups_CustomersBO = new CustomerGroups_CustomersBO(); CustomerGroups_Customers aCustomerGroups_Customers = new CustomerGroups_Customers(); if (nameCustomerGroup_customer.Length > 150) { aCustomerGroups_Customers.Name = nameCustomerGroup_customer.Substring(0, 150); } else { aCustomerGroups_Customers.Name = nameCustomerGroup_customer; } aCustomerGroups_Customers.Type = 1; aCustomerGroups_Customers.Status = 1; aCustomerGroups_Customers.Disable = false; aCustomerGroups_Customers.FromDate = DateTime.Now; aCustomerGroups_Customers.ToDate = DateTime.Now; aCustomerGroups_Customers.IDCustomer = IDCustomer; aCustomerGroups_Customers.IDCustomerGroup = IDCustomerGroup; aCustomerGroups_CustomersBO.Insert(aCustomerGroups_Customers); #endregion // dung de cap nhap lai nguoi dai dien khi dat phong if (aCheckInEN.aListRoomMembers[i].ListCustomer[ii].PepoleRepresentative == true) { aBookingRsBO = new BookingRsBO(); aBookingRs = new BookingRs(); aBookingRs = aBookingRsBO.Select_ByID(aCheckInEN.IDBookingR); if (aBookingRs != null) { aBookingRs.IDCustomer = IDCustomer; Result = aBookingRsBO.Update(aBookingRs); } } else { if (ii == (aCheckInEN.aListRoomMembers[i].ListCustomer.Count - 1)) { if (Result == 0) { aBookingRsBO = new BookingRsBO(); aBookingRs = new BookingRs(); aBookingRs = aBookingRsBO.Select_ByID(aCheckInEN.IDBookingR); if (aBookingRs != null) { aBookingRs.IDCustomer = IDCustomer; aBookingRsBO.Update(aBookingRs); } } } } } } return true; } catch (Exception ex) { return false; } }
//Ngoc da sua lai ten ham 26/12/2014 public List<BookingRStatusPayViewEN> GetListBookingRByStatus(DateTime? From, DateTime? To, int? CustomerType, string StatusPay) { List<sp_BookingRsExt_GetInfo_ByTime_ByCustomerType_ByStatusPay_Result> aListTemp = new List<sp_BookingRsExt_GetInfo_ByTime_ByCustomerType_ByStatusPay_Result>(); aListTemp = aDatabaseDA.sp_BookingRsExt_GetInfo_ByTime_ByCustomerType_ByStatusPay(From, To, CustomerType, StatusPay).ToList(); List<BookingRStatusPayViewEN> aListReturn = new List<BookingRStatusPayViewEN>(); BookingRStatusPayViewEN aBookingRStatusPayViewEN; CompaniesBO aCompaniesBO = new CompaniesBO(); List<Companies> aListCompaniesTemp = aCompaniesBO.Select_All(); BookingRoomsBO aBookingRoomsBO = new BookingRoomsBO(); List<BookingRooms> aListBookingRoomTemp = aBookingRoomsBO.Select_All(); for (int i = 0; i < aListTemp.Count; i++) { aBookingRStatusPayViewEN = new BookingRStatusPayViewEN(); aBookingRStatusPayViewEN.IDBookingR = aListTemp[i].BookingRs_ID; aBookingRStatusPayViewEN.CreatedDate = aListTemp[i].BookingRs_CreatedDate; aBookingRStatusPayViewEN.Customer_Name = aListTemp[i].Customers_Name; aBookingRStatusPayViewEN.Subject = aListTemp[i].BookingRs_Subject; aBookingRStatusPayViewEN.IDCustomer = aListTemp[i].Customers_ID; aBookingRStatusPayViewEN.IDCustomerGroup = aListTemp[i].CustomerGroups_ID; aBookingRStatusPayViewEN.BookingRs_Status = aListTemp[i].BookingRs_Status; aBookingRStatusPayViewEN.CustomerGroups_Name = aListTemp[i].CustomerGroups_Name; int IDCompany = !String.IsNullOrEmpty(aListTemp[i].Companies_ID.ToString()) ? Convert.ToInt32(aListTemp[i].Companies_ID) : 0; if (aListCompaniesTemp.Where(c => c.ID == IDCompany).ToList().Count > 0) { aBookingRStatusPayViewEN.NameCompany = aListCompaniesTemp.Where(c => c.ID == IDCompany).ToList()[0].Name; } else { aBookingRStatusPayViewEN.NameCompany = string.Empty; } aBookingRStatusPayViewEN.StatusPay = aListTemp[i].BookingRs_StatusPay; aBookingRStatusPayViewEN.BookingMoney = aListTemp[i].BookingRs_BookingMoney; aBookingRStatusPayViewEN.Sku = aListTemp[i].Rooms_Sku; aBookingRStatusPayViewEN.IDBookingH = aListTemp[i].BookingRs_BookingHs_IDBookingH; aBookingRStatusPayViewEN.BookingHs_Status = aListTemp[i].BookingHs_Status; aBookingRStatusPayViewEN.BookingHs_StatusPay = aListTemp[i].BookingHs_StatusPay; aBookingRStatusPayViewEN.BookingHs_Type = aListTemp[i].BookingHs_Type; aBookingRStatusPayViewEN.BookingHs_Disable = aListTemp[i].BookingHs_Disable; aBookingRStatusPayViewEN.BookingHs_Subject = aListTemp[i].BookingHs_Subject; List<BookingRooms> aListBookingRooms = aListBookingRoomTemp.Where(br => br.IDBookingR == aListTemp[i].BookingRs_ID && br.CodeRoom == aListTemp[i].Rooms_Code).ToList(); if (aListBookingRooms.Count > 0) { switch (aListBookingRooms[0].Status) { case 3: aBookingRStatusPayViewEN.BookingRoomStatusPayDisplay = "Đã check in"; break; case 5: aBookingRStatusPayViewEN.BookingRoomStatusPayDisplay = "Pending"; break; case 7: aBookingRStatusPayViewEN.BookingRoomStatusPayDisplay = "Đã check out nhưng chưa thanh toán"; break; case 8: aBookingRStatusPayViewEN.BookingRoomStatusPayDisplay = "Đã thanh toán"; break; default: aBookingRStatusPayViewEN.BookingRoomStatusPayDisplay = "Chưa xác định"; break; } aBookingRStatusPayViewEN.IDBookingRoom = aListBookingRooms[0].ID; aBookingRStatusPayViewEN.BookingRooms_CodeRoom = aListBookingRooms[0].CodeRoom; aBookingRStatusPayViewEN.CheckInActual = aListBookingRooms[0].CheckInActual; aBookingRStatusPayViewEN.CheckOut = aListBookingRooms[0].CheckOutPlan; } switch (aBookingRStatusPayViewEN.StatusPay) { case 1: aBookingRStatusPayViewEN.BookingRStatusPayDisplay = "Chưa thanh toán"; break; case 2: aBookingRStatusPayViewEN.BookingRStatusPayDisplay = "Tạm ứng"; break; case 3: aBookingRStatusPayViewEN.BookingRStatusPayDisplay = "Đã thanh toán"; break; default: aBookingRStatusPayViewEN.BookingRStatusPayDisplay = "Chưa xác định"; break; } switch (aListTemp[i].BookingRs_CustomerType) { case 1: aBookingRStatusPayViewEN.CustomerTypeDisplay = "Nhà nước"; break; case 2: aBookingRStatusPayViewEN.CustomerTypeDisplay = "Khách đoàn"; break; case 3: aBookingRStatusPayViewEN.CustomerTypeDisplay = "Khách lẻ"; break; case 4: aBookingRStatusPayViewEN.CustomerTypeDisplay = "Khách vãng lai"; break; case 5: aBookingRStatusPayViewEN.CustomerTypeDisplay = "Khách bộ ngoại giao"; break; default: aBookingRStatusPayViewEN.CustomerTypeDisplay = "Chưa xác định"; break; } aListReturn.Add(aBookingRStatusPayViewEN); } return aListReturn; }