Пример #1
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);
        }
Пример #2
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);
        }