Skip to content

Commit

Permalink
Merge pull request #957 from City-of-Helsinki/UHF-9815
Browse files Browse the repository at this point in the history
UHF-9815: Home care client fee calculator changes
  • Loading branch information
teroelonen authored Apr 15, 2024
2 parents e494732 + abcaf79 commit b42e8ce
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 94 deletions.
2 changes: 1 addition & 1 deletion dist/js/home_care_client_fee.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/js/home_care_service_voucher.min.js

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions src/js/calculator/example-calc.html
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,7 @@
}
},
"shopping_service_prices": {
"first_per_week": 9.37,
"others_per_week": 11.35
"first_per_week": 9.37
},
"meal_service_prices": {
"lunch": 3.9,
Expand Down
22 changes: 2 additions & 20 deletions src/js/calculator/home_care_client_fee/_form.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function getFormData(id, t, { firstPerWeekPrice, othersPerWeekPrice }) {
function getFormData(id, t, { firstPerWeekPrice }) {
return {
form_id: id,
has_required_fields: true,
Expand Down Expand Up @@ -97,6 +97,7 @@ function getFormData(id, t, { firstPerWeekPrice, othersPerWeekPrice }) {
id: 'shopping_service',
label: t('shopping_service'),
required: true,
helper_text: t('shopping_service_per_week_explanation', { first_per_week_price: firstPerWeekPrice }),
radio_items: [
{
name: 'shopping_service',
Expand All @@ -113,25 +114,6 @@ function getFormData(id, t, { firstPerWeekPrice, othersPerWeekPrice }) {
],
},
},
{
group: {
id: 'shopping_service_group',
hide_group: true,
items: [
{
input_integer: {
id: 'shopping_service_per_week',
label: t('shopping_service_per_week'),
unit: t('unit_amount'),
min: 1,
size: 2,
required: true,
helper_text: t('shopping_service_per_week_explanation', { first_per_week_price: firstPerWeekPrice, others_per_week_price: othersPerWeekPrice }),
},
},
],
},
},
{
heading: {
text: t('meal_service_heading'),
Expand Down
33 changes: 9 additions & 24 deletions src/js/calculator/home_care_client_fee/_translations.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,24 +72,19 @@ const translations = {
en: 'Grocery delivery service',
},
shopping_service_paragraph: {
fi: 'Kauppapalvelussa tilaamasi ruokaostokset toimitetaan kotiovellesi. Kauppapalvelun hintaan kuuluu ruokaostosten keräily ja toimitus.',
sv: 'I butiksservicen levereras de livsmedelsinköp som du beställer till din dörr. I priset för butiksservicen ingår insamling och leverans av livsmedelsinköp.',
en: 'The grocery delivery service delivers the groceries that you order through the service to your door. The price of the grocery delivery service includes the collection and delivery of the groceries.',
fi: 'Kauppapalvelussa tilaamasi ruokaostokset toimitetaan kotiovellesi. Kauppapalvelun hintaan kuuluu yksi ruokaostosten keräily ja toimitus viikossa.',
sv: 'Butiksservicen levererar de livsmedelsinköp som du beställer till din dörr. I priset för butiksservicen ingår samling och leverans av livsmedelsinköp en gång i veckan.',
en: 'The grocery delivery service delivers the groceries that you order through the service to your door. The price of the grocery delivery service includes the collection and delivery of the groceries once a week.',
},
shopping_service: {
fi: 'Laske arvioon kauppapalvelu',
sv: 'Inkludera butiksservicen i bedömningen',
en: 'Include the grocery delivery service in the estimate',
},
shopping_service_per_week: {
fi: 'Kauppapalvelun toimitusten määrä viikossa',
sv: 'Antal butiksserviceleveranser per vecka',
en: 'Number of deliveries from the grocery delivery service per week',
},
shopping_service_per_week_explanation: {
fi: 'Yksi toimitus viikossa maksaa ${first_per_week_price} euroa, muut toimitukset ${others_per_week_price} euroa per toimitus.',
sv: 'En leverans per vecka kostar ${first_per_week_price} euro, andra leveranser ${others_per_week_price} euro per leverans.',
en: 'One delivery per week costs ${first_per_week_price} euros, and the other deliveries are ${others_per_week_price} euros per delivery.',
fi: 'Yksi toimitus viikossa maksaa ${first_per_week_price} euroa.',
sv: 'En leverans per vecka kostar ${first_per_week_price} euro.',
en: 'One delivery per week costs ${first_per_week_price} euros.',
},
meal_service_heading: {
fi: 'Ateriapalvelu',
Expand Down Expand Up @@ -181,20 +176,10 @@ const translations = {
sv: '1 butiksleverans per vecka, 4 leveranser ingår i månadspriset.',
en: '1 grocery delivery per week; the monthly fee includes 4 deliveries.',
},
receipt_shopping_service_math_multiple: {
fi: '${delivery_count_per_week} kauppatoimitusta viikossa, kuukausihintaan on laskettu ${delivery_count_per_month} toimitusta.',
sv: '${delivery_count_per_week} butiksleveranser per vecka, i månadspriset ingår ${delivery_count_per_month} leveranser.',
en: '${delivery_count_per_week} grocery deliveries per week; the monthly fee includes ${delivery_count_per_month} deliveries.',
},
receipt_shopping_service_explanation: {
fi: 'Kunkin viikon ensimmäinen toimitus maksaa ${first_per_week} euroa. Muut saman viikon toimitukset maksavat kukin ${others_per_week} euroa.',
sv: 'Den första leveransen för varje vecka kostar ${first_per_week} euro. De övriga leveranserna för samma vecka kostar ${others_per_week} euro.',
en: 'The first delivery of each week costs ${first_per_week} euros. Other deliveries during the same week cost ${others_per_week} euros each.',
},
receipt_shopping_service_algorithm: {
fi: 'Laskuri laskee kuljetukset tasaisesti eri viikoille, mutta voit itse vaikuttaa kauppatoimitusten määrään tarpeesi mukaan.',
sv: 'Räknaren beräknar leveranserna jämnt för olika veckor, men du kan påverka antalet butiksleveranser enligt dina behov.',
en: 'The calculator calculates deliveries evenly for different weeks, but you can set the number of grocery deliveries according to your needs.',
fi: 'Kunkin viikon toimitus maksaa ${first_per_week} euroa.',
sv: 'Leveransen varje vecka kostar ${first_per_week} euro.',
en: 'The delivery each week costs ${first_per_week} euros.',
},
receipt_aria_live: {
fi: 'Kotihoidon asiakasmaksun arvio on ${payment} euroa kuukaudessa, lue lisätietoja lomakkeen alta.',
Expand Down
69 changes: 23 additions & 46 deletions src/js/calculator/home_care_client_fee/home_care_client_fee.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class HomeCareClientFee {
}
}
throw new Error(`Minimum range not found for ${value} from ${range}`);
};
}

// 1. Get proper limits based on given values and the parsed settings.
const maximumPayment = getMinimumRange(monthlyUsage, calculatorSettings.monthly_usage_max_payment);
Expand Down Expand Up @@ -202,7 +202,6 @@ class HomeCareClientFee {
},
shopping_service_prices: {
first_per_week: 9.37,
others_per_week: 11.35,
},
meal_service_prices: {
lunch: 3.9,
Expand All @@ -218,18 +217,9 @@ class HomeCareClientFee {
// Form content
const getFormData = () => form.getFormData(this.id, this.t, {
firstPerWeekPrice: parsedSettings.shopping_service_prices.first_per_week,
othersPerWeekPrice: parsedSettings.shopping_service_prices.others_per_week,
});

const update = () => {
const shoppingService = this.calculator.getFieldValue('shopping_service');

if (shoppingService === '1') {
this.calculator.showGroup('shopping_service_group');
} else {
this.calculator.hideGroup('shopping_service_group');
}

const mealService = this.calculator.getFieldValue('meal_service');

if (mealService === '1') {
Expand All @@ -248,12 +238,7 @@ class HomeCareClientFee {
errorMessages.push(...this.calculator.validateBasics('gross_income_per_month'));
errorMessages.push(...this.calculator.validateBasics('monthly_usage'));
errorMessages.push(...this.calculator.validateBasics('safetyphone'));

errorMessages.push(...this.calculator.validateBasics('shopping_service'));
const shoppingService = this.calculator.getFieldValue('shopping_service');
if (shoppingService === '1') {
errorMessages.push(...this.calculator.validateBasics('shopping_service_per_week'));
}

errorMessages.push(...this.calculator.validateBasics('meal_service'));
const mealService = this.calculator.getFieldValue('meal_service');
Expand All @@ -278,8 +263,7 @@ class HomeCareClientFee {
const grossIncomePerMonthRaw = this.calculator.getFieldValue('gross_income_per_month');
const monthlyUsage = Number(this.calculator.getFieldValue('monthly_usage'));
const safetyphone = this.calculator.getFieldValue('safetyphone');
// Shopping service is set earlier
const shoppingServicePerWeek = Number(this.calculator.getFieldValue('shopping_service_per_week'));
const shoppingService = this.calculator.getFieldValue('shopping_service');
// Meal service is set earlier
const mealServicePerWeek = Number(this.calculator.getFieldValue('meal_service_per_week'));

Expand Down Expand Up @@ -355,39 +339,32 @@ class HomeCareClientFee {
// 6. If shopping service is selected, calculate value for it.
let shoppingPaymentPerWeek = 0;
let shoppingPaymentPerMonth = 0;

const shoppingServicePerWeek = 1;

if (shoppingService === '1') {
// First shopping service per week has cheaper price
// Since shopping service has only one delivery per week we use the first_per_week value.
// There used to be possibility in the calculator to have multiple deliveries per week,
// but it was fixed to one. This is why there is a bit misleading term first_per_week.
shoppingPaymentPerWeek = parsedSettings.shopping_service_prices.first_per_week;
// Others have higher price
shoppingPaymentPerWeek += (shoppingServicePerWeek - 1) * parsedSettings.shopping_service_prices.others_per_week;
shoppingPaymentPerMonth = shoppingPaymentPerWeek * 4;

// Add details to receipt
subtotals.push(
{
title: this.t('shopping_service_heading'),
has_details: true,
details: [
this.t(
(shoppingServicePerWeek === 1) ? 'receipt_shopping_service_math_single' : 'receipt_shopping_service_math_multiple',
{
delivery_count_per_week: shoppingServicePerWeek,
delivery_count_per_month: shoppingServicePerWeek * 4,
}
),
this.t(
'receipt_shopping_service_explanation',
{
first_per_week: this.calculator.formatFinnishEuroCents(parsedSettings.shopping_service_prices.first_per_week),
others_per_week: this.calculator.formatFinnishEuroCents(parsedSettings.shopping_service_prices.others_per_week),
},
),
this.t('receipt_shopping_service_algorithm')
],
sum: this.t('receipt_subtotal_euros_per_month', { value: this.calculator.formatFinnishEuroCents(shoppingPaymentPerMonth) }),
sum_screenreader: this.t('receipt_subtotal_euros_per_month_screenreader', { value: this.calculator.formatEuroCents(shoppingPaymentPerMonth) }),
}
);
subtotals.push({
title: this.t('shopping_service_heading'),
has_details: true,
details: [
this.t('receipt_shopping_service_math_single', {
delivery_count_per_week: shoppingServicePerWeek,
delivery_count_per_month: shoppingServicePerWeek * 4,
}),
this.t('receipt_shopping_service_explanation', {
first_per_week: this.calculator.formatFinnishEuroCents(parsedSettings.shopping_service_prices.first_per_week),
})
],
sum: this.t('receipt_subtotal_euros_per_month', { value: this.calculator.formatFinnishEuroCents(shoppingPaymentPerMonth) }),
sum_screenreader: this.t('receipt_subtotal_euros_per_month_screenreader', { value: this.calculator.formatEuroCents(shoppingPaymentPerMonth) }),
});
}

// 7. If meal service is selected, calculate value for it.
Expand Down

0 comments on commit b42e8ce

Please sign in to comment.