public void CalculateCustomerData(int customerID, PackageBaseData package, FeeRate fee, PricingModelData modelData, System.Web.WebPages.Html.ModelStateDictionary ModelState) { /* IMPORTANT: we calculate here the service duration for one session based on some custom variables for housekeeper pricing, * final price and fees are calculated in the standard code using the package Duration field, because of that * we only update package.Duration here for later complete price calculation */ // Get customer input var nbeds = Request[String.Format("bedrooms-number[{0}]", package.ID)].AsInt(); var nbaths = Request[String.Format("bathrooms-number[{0}]", package.ID)].AsInt(); // get provider rate var providerRate = GetProviderCleaningRate(package); // Apply formula, changed by the providerRate (variation from the average) var duration = ApplyFormula(nbeds, nbaths) * providerRate; // Create time object from duration, rounded to quarter-hours (15 minutes blocks) var timeDuration = ASP.LcHelpers.RoundTimeToQuarterHour(TimeSpan.FromMinutes(duration), ASP.LcHelpers.RoundingType.Up); // Create variables object with the specific data used in this calculation (will be saved later by the normal packages process) // Provider values get included in the object, something that is wanted for historic purposes on database. PricingVariables pricingvars = PricingVariables.FromPackageBaseData(package); pricingvars["BathsNumber"].Value = nbaths; pricingvars["BedsNumber"].Value = nbeds; // Change package with the information: package.Duration = timeDuration; modelData.ProviderInput = providerRate; modelData.CustomerInput = pricingvars; }
public void CalculateCustomerData(int customerID, PackageBaseData package, FeeRate fee, PricingModelData modelData, System.Web.WebPages.Html.ModelStateDictionary ModelState) { /* IMPORTANT: we set here the service duration for one session based on the customer value (from the form), * update the hourly-price from provider variable value * and the hourly-surcharge based on the variables. * Final price and fees are calculated in the standard code using the package Duration field and HourlySurcharge field, because of that * the final price is not calculated here. */ // TOREVIEW: Needs input data validation with ModelState and check ModelState.IsValid at LcPricingModel? // Getting variables PricingVariables pricingvars = PricingVariables.FromPackageBaseData(package); TimeSpan timeDuration = TimeSpan.Zero; decimal hourlySurcharge = 0; // Iterating customer variables: foreach (var pvar in pricingvars) { if (pvar.Value.Def.IsCustomerVariable) { // Setting value from the form pvar.Value.Value = LcUtils.GetTypedValue(Request[String.Format("{0}[{1}]", pvar.Key, package.ID)], null, pvar.Value.Def.DataType); // For the 'Hours:2' customer variable, we get it form the form and set the duration with it. if (pvar.Key == "Hours") { // Create time object from duration, rounded to quarter-hours (15 minutes blocks) var duration = pvar.Value.GetValue <double>(0); timeDuration = ASP.LcHelpers.RoundTimeToQuarterHour(TimeSpan.FromHours(duration), ASP.LcHelpers.RoundingType.Up); } else { // For other variables, we calculate it using the general formula and its added to the hourly surcharge // Get the provider var, we need its values. var provar = pricingvars.GetCalculateWithVariableFor(pvar.Value); // General formula for 1 hour: (CustomerValueInputVariable - ProviderNumberIncludedVariable) * ProviderPriceVariable // EXCEPT when CustomerValueInputVariable is equal or less than ProviderNumberIncludedVariable, then is 0 decimal amount = 0; if (pvar.Value.GetValue <decimal>(0) > (provar.ProviderNumberIncluded ?? 0)) { amount = (pvar.Value.GetValue <decimal>(0) - (provar.ProviderNumberIncluded ?? 0)) * provar.GetValue <decimal>(0); } // Add to the hourly surcharge hourlySurcharge += amount; } } } // Update package data: package.Duration = timeDuration; package.HourlySurcharge = hourlySurcharge; modelData.CustomerInput = pricingvars; }