/// <summary>
        /// Tính giá cho một loại phòng
        /// </summary>
        /// <returns></returns>
        public static double Calculate(RoomClass rclass, RoomTypex rtype, int adult, int child, bool isSingle, SailsTrip trip, Cruise cruise, TripOption option, DateTime startDate, SailsModule Module, IList policies, double childPrice, double agencySup, Agency agency)
        {
            // Lấy về bảng giá áp dụng cho thời điểm xuất phát
            if (trip == null)
            {
                return(0);
            }
            SailsPriceConfig priceConfig = Module.SailsPriceConfigGet(rclass, rtype, trip, cruise, option, startDate,
                                                                      BookingType.Double, agency);

            if (priceConfig == null)
            {
                throw new PriceException(string.Format("There isn't any price for {0} {1} room in trip {2} on {3}", rclass.Name, rtype.Name, trip.Name, startDate));
            }
            #region -- Giá phòng --
            double price;
            // Biến để lưu giá trị single supplement nếu là booking single
            double singlesup = 0;
            if (isSingle)
            {
                if (agencySup > 0)
                {
                    singlesup = agencySup;
                }
                else
                {
                    singlesup = priceConfig.SpecialPrice; //Module.ApplyPriceFor(priceConfig.SpecialPrice, policies);
                }
            }

            // Tính giá phòng theo người lớn

            // Đơn giá của phòng (đã áp dụng chính sách)
            double unitPrice;
            if (priceConfig.Table.Agency == null)
            {
                //unitPrice = Module.ApplyPriceFor(priceConfig.NetPrice, policies);
            }
            else
            {
                //unitPrice = priceConfig.NetPrice;
            }
            if (rtype.IsShared)
            {
                // Giá phòng twin phòng đơn giá x số lượng người lớn / 2 + đơn giá x tỉ lệ dành cho child x số child / 2
                // (Thực ra adult = 1/2, child =0/1)
                //price = unitPrice * adult / 2 + unitPrice * child * childPrice / 100 / 2;
                // Cộng thêm singlesup (nếu không phải single thì là + 0)
                //price += singlesup;
            }
            else
            {
                // Giá phòng double phòng đơn giá x số lượng người lớn / 2 + đơn giá x tỉ lệ dành cho child x số child / 2
                //price = unitPrice * adult / 2 + unitPrice * child * childPrice / 100 / 2;
                // Cộng thêm singlesup (nếu không phải single thì là + 0)
                //price += singlesup;
            }
            #endregion

            //return price;

            return(0.0);
        }
Example #2
0
        public virtual double Calculate(SailsModule Module, Agency agency, double childPrice, double agencySup, bool customPrice, double roomTotal)
        {
            Role applyRole;

            if (agency != null && agency.Role != null)
            {
                applyRole = agency.Role;
            }
            else
            {
                applyRole = Module.RoleGetById(4);
            }
            double total = roomTotal;

            #region -- Lấy danh sách chính sách giá --
            Role role;
            if (Agency != null && Agency.Role != null)
            {
                role = Agency.Role;
            }
            else
            {
                role = applyRole;
            }
            IList _policies = Module.AgencyPolicyGetByRole(role);
            #endregion

            #region -- Giá dịch vụ --

            IList services      = Module.ExtraOptionGetBooking();
            IList servicePrices = Module.ServicePriceGetByBooking(this);

            foreach (ExtraOption extra in services)
            {
                double child = Child;

                double unitPrice = -1;
                // Với mỗi dịch vụ ưu tiên lấy giá nhập trước
                foreach (BookingServicePrice price in servicePrices)
                {
                    if (price.ExtraOption == extra)
                    {
                        unitPrice = price.UnitPrice;
                    }
                }

                if (unitPrice < 0)
                {
                    unitPrice = Module.ApplyPriceFor(extra.Price, _policies);
                }

                if (extra.IsIncluded)
                {
                    // Nếu dịch vụ đã include thì xem xem có không check không để trừ
                    if (!_extraServices.Contains(extra))
                    {
                        total -= unitPrice * (Adult + child * childPrice / 100);
                    }
                }
                else
                {
                    // Nếu là dịch vụ chưa include thì xem có có không để cộng
                    if (_extraServices.Contains(extra))
                    {
                        total += unitPrice * (Adult + child * childPrice / 100);
                    }
                }
            }

            //TODO: Cần phải check cả dịch vụ dành cho từng khách nữa

            #endregion

            return(total);
        }
        public virtual double Calculate(SailsModule Module, IList policies, double childPrice, double agencySup, Agency agency)
        {
            // Lấy về kiểu phòng
            RoomClass rclass = RoomClass;
            RoomTypex rtype  = RoomType;

            int adult = Adult;
            int child = Child;

            double price = Calculate(rclass, rtype, adult, child, IsSingle, _book.Trip, _book.Cruise, _book.TripOption, _book.StartDate, Module,
                                     policies, childPrice, agencySup, agency);

            return(price);
        }
Example #4
0
        public virtual double Calculate(SailsModule Module, Agency agency, double childPrice, double agencySup, bool customPrice, bool singleService)
        {
            Role applyRole;

            if (agency != null && agency.Role != null)
            {
                applyRole = agency.Role;
            }
            else
            {
                applyRole = Module.RoleGetById(4);
            }
            double total = 0;

            Role role;

            if (Agency != null && Agency.Role != null)
            {
                role = Agency.Role;
            }
            else
            {
                role = applyRole;
            }
            IList _policies = Module.AgencyPolicyGetByRole(role);

            #region -- Giá dịch vụ --

            IList services      = Module.ExtraOptionGetBooking();
            IList servicePrices = Module.ServicePriceGetByBooking(this);

            foreach (ExtraOption extra in services)
            {
                double child     = Child;
                double unitPrice = -1;
                foreach (BookingServicePrice price in servicePrices)
                {
                    if (price.ExtraOption == extra)
                    {
                        unitPrice = price.UnitPrice;
                    }
                }
                if (unitPrice < 0)
                {
                    unitPrice = Module.ApplyPriceFor(extra.Price, _policies);
                }

                if (extra.IsIncluded)
                {
                    // Nếu dịch vụ đã include thì xem xem có không check không để trừ
                    if (!_extraServices.Contains(extra))
                    {
                        total -= unitPrice * (Adult + child * childPrice / 100);
                    }
                }
                else
                {
                    // Nếu là dịch vụ chưa include thì xem có có không để cộng
                    if (_extraServices.Contains(extra))
                    {
                        total += unitPrice * (Adult + child * childPrice / 100);
                    }
                }
            }

            //TODO: Cần phải check cả dịch vụ dành cho từng khách nữa

            ////foreach (ExtraOption extra in _extraServices)
            ////{
            ////    if (services.Contains(extra))
            ////    {
            ////        total += Module.ApplyPriceFor(extra.Price, _policies)*Adult;
            ////    }
            ////}
            #endregion

            #region -- giá phòng --
            // Tính giá theo từng phòng
            IList cServices = Module.ExtraOptionGetCustomer();
            foreach (BookingRoom broom in _bookosBookingRooms)
            {
                if (customPrice)
                {
                    double tempTotal = 0;
                    foreach (Customer customer in broom.RealCustomers)
                    {
                        tempTotal += customer.Total;
                    }
                    if (tempTotal > 0)
                    {
                        total += tempTotal;
                    }
                    else
                    {
                        total += broom.Total;
                    }
                }
                else
                {
                    total += broom.Calculate(Module, _policies, childPrice, agencySup, Agency);
                }

                if (singleService)
                {
                    // Ngoài giá phòng còn có thể có dịch vụ cá nhân
                    foreach (Customer customer in broom.RealCustomers)
                    {
                        // Baby không tính dịch vụ
                        if (customer.Type == CustomerType.Baby)
                        {
                            continue;
                        }

                        foreach (ExtraOption service in cServices)
                        {
                            CustomerService customerService = Module.CustomerServiceGetByCustomerAndService(customer,
                                                                                                            service);
                            if (customerService != null)
                            {
                                double rate = 1;
                                //if (customer.IsChild)
                                //{
                                //    rate = childPrice / 100;
                                //}

                                double unitPrice = -1;
                                foreach (BookingServicePrice price in servicePrices)
                                {
                                    if (price.ExtraOption == service)
                                    {
                                        unitPrice = price.UnitPrice;
                                    }
                                }
                                if (unitPrice < 0)
                                {
                                    unitPrice = Module.ApplyPriceFor(service.Price, _policies);
                                }

                                if (service.IsIncluded && customerService.IsExcluded)
                                {
                                    // Nếu dịch vụ có included mà lại bị excluded thì trừ
                                    total -= unitPrice * rate;
                                }

                                if (!service.IsIncluded && !customerService.IsExcluded)
                                {
                                    // Nếu dịch vụ không included mà lại có thì cộng
                                    total += unitPrice * rate;
                                }
                            }
                        }
                    }
                }
            }

            #endregion

            return(total);
        }