diff --git a/dist/js/service_housing_service_voucher.min.js b/dist/js/service_housing_service_voucher.min.js new file mode 100644 index 000000000..273d3cc19 --- /dev/null +++ b/dist/js/service_housing_service_voucher.min.js @@ -0,0 +1 @@ +!function(){"use strict";var e={getFormData:function(e,t){return{form_id:e,has_required_fields:!0,items:[{input_float:{id:"net_income_per_month",label:t("net_income_per_month"),unit:t("unit_euro"),min:0,size:8,required:!0,strip:"[€eE ]",helper_text:t("net_income_per_month_explanation")}},{input_float:{id:"service_provider_price",label:t("service_provider_price"),unit:t("unit_euro"),min:0,size:8,required:!0,strip:"[€eE ]",helper_text:t("service_provider_price_explanation")}}]}}};var t={net_income_per_month:{fi:"Nettotulot kuukaudessa",sv:null,en:null},net_income_per_month_explanation:{fi:"Nettotulot tarkoittavat tuloja verojen vähentämisen jälkeen. Tuloihin lasketaan eläkkeet, elatusavut, elinkorot, elatustuki sekä muut jatkuvat henkilökohtaiset tulot ja pääomasta tai omaisuudesta(kuten korko-, osinko- ja vuokratulot). Eläkkeen saajan hoitotukea, asumistukea, rintamalisää tai sotavammalain mukaista elinkorkoa ei huomioida.",sv:null,en:null},service_provider_price:{fi:"Palveluntuottajan kuukausihinta",sv:null,en:null},service_provider_price_explanation:{fi:"Valitsemasi palveluntuottajan perimä palveluasumisen kuukausihinta.",sv:null,en:null},receipt_estimate_of_payment:{fi:"Arvio palveluasumisen palvelusetelistä",sv:null,en:null},receipt_estimated_payment_prefix:{fi:"Omavastuuosuus eli sinulle maksettavaksi jäävä asiakasmaksu on",sv:null,en:null},receipt_estimated_payment_suffix:{fi:"euroa kuukaudessa.",sv:null,en:null},receipt_estimated_payment_explanation:{fi:"Tämä arvio on suuntaa antava. Tarkka arvo lasketaan kotihoidon tekemän päätöksen mukaan.",sv:null,en:null},receipt_estimate_is_based_on:{fi:"Palveluasumisen hinta palvelusetelillä ostettuna muodostuu seuraavasti:",sv:null,en:null},receipt_subtotal_full_price:{fi:"Palveluasumisen kokonaiskustannus",sv:null,en:null},receipt_subtotal_city_price:{fi:"Kaupunki maksaa palvelusetelillä yksityiselle tuottajalle ",sv:null,en:null},receipt_subtotal_self_price:{fi:"Sinulle maksettavaksi jäävä osuus eli omavastuu",sv:null,en:null},receipt_subtotal_euros_per_month:{fi:"${value} €/kk",sv:null,en:null},receipt_subtotal_euros_per_month_screenreader:{fi:"${value} euroa kuukaudessa",sv:null,en:null},receipt_additional_details:{fi:"Lisähuomiot:",sv:null,en:null},receipt_aria_live:{fi:"Omavastuuosuus eli sinulle maksettavaksi jäävä asiakasmaksu on ${payment} euroa kuukaudessa, lue lisätietoja lomakkeen alta.",sv:null,en:null}};class a{constructor(a,i){this.id=a;const s=JSON.parse(i),l=()=>{},u=()=>{const e=[];if(e.push(...this.calculator.validateBasics("net_income_per_month")),e.push(...this.calculator.validateBasics("service_provider_price")),e.length)return{error:{title:this.t("missing_input"),message:e}};const t=Number(this.calculator.getFieldValue("net_income_per_month")),a=Number(this.calculator.getFieldValue("service_provider_price")),i=this.calculator.getMinimumRange(t,s.voucher_from_net_income),l=Math.max(0,a-i),u=[];u.push({title:this.t("receipt_subtotal_full_price"),has_details:!1,details:[],sum:this.t("receipt_subtotal_euros_per_month",{value:this.calculator.formatFinnishEuroCents(a)}),sum_screenreader:this.t("receipt_subtotal_euros_per_month_screenreader",{value:this.calculator.formatEuroCents(a)})},{title:this.t("receipt_subtotal_city_price"),has_details:!1,details:[],sum:this.t("receipt_subtotal_euros_per_month",{value:this.calculator.formatFinnishEuroCents(i)}),sum_screenreader:this.t("receipt_subtotal_euros_per_month_screenreader",{value:this.calculator.formatEuroCents(i)})},{title:this.t("receipt_subtotal_self_price"),has_details:!1,details:[],sum:this.t("receipt_subtotal_euros_per_month",{value:this.calculator.formatFinnishEuroCents(l)}),sum_screenreader:this.t("receipt_subtotal_euros_per_month_screenreader",{value:this.calculator.formatEuroCents(l)})});const n={id:this.id,title:this.t("receipt_estimate_of_payment"),total_prefix:this.t("receipt_estimated_payment_prefix"),total_value:this.calculator.formatFinnishEuroCents(l),total_suffix:this.t("receipt_estimated_payment_suffix"),total_explanation:this.t("receipt_estimated_payment_explanation"),hr:!0,breakdown:{title:this.t("receipt_estimate_is_based_on"),subtotals:u,additional_details:null}};return{receipt:this.calculator.getPartialRender("{{>receipt}}",n),ariaLive:this.t("receipt_aria_live",{payment:l})}},n={submit:e=>{this.calculator.clearResult(),e.preventDefault();const t=u();this.calculator.renderResult(t)},keydown:()=>{},change:()=>{},reset:()=>{window.setTimeout(l,1),this.calculator.clearResult(),this.calculator.showAriaLiveText(this.t("reset_aria_live"))}};this.calculator=window.HelfiCalculator({name:"home_care_client_payment",translations:t}),this.t=(e,t)=>this.calculator.translate(e,t),this.settings=this.calculator.parseSettings(i),this.calculator.init({id:a,formData:(()=>e.getFormData(this.id,this.t))(),eventHandlers:n})}}window.helfi_calculator=window.helfi_calculator||{},window.helfi_calculator.service_housing_service_voucher=(e,t)=>new a(e,t)}(); \ No newline at end of file diff --git a/src/js/calculator/example-calc.html b/src/js/calculator/example-calc.html index aba8bfc3c..ed6b93702 100644 --- a/src/js/calculator/example-calc.html +++ b/src/js/calculator/example-calc.html @@ -348,7 +348,40 @@ } } `; - drupalSettings.service_housing_service_voucher = `{}`; + drupalSettings.service_housing_service_voucher = ` +{ + "voucher_from_net_income": { + "0": 3300, + "900.01": 3200, + "1000.01": 3100, + "1100.01": 3000, + "1200.01": 2900, + "1300.01": 2800, + "1400.01": 2700, + "1500.01": 2600, + "1600.01": 2500, + "1700.01": 2400, + "1800.01": 2300, + "1900.01": 2200, + "2000.01": 2100, + "2100.01": 2000, + "2200.01": 1900, + "2300.01": 1800, + "2400.01": 1700, + "2500.01": 1600, + "2600.01": 1500, + "2700.01": 1400, + "2800.01": 1300, + "2900.01": 1200, + "3000.01": 1100, + "3100.01": 1000, + "3200.01": 900, + "3300.01": 800, + "3400.01": 700, + "3500.01": 600 + } +} +`; drupalSettings.family_with_kids_home_service_client_payment = `{}`; drupalSettings.daycare_payment = ` { @@ -508,10 +541,10 @@

House cleaning service voucher

- + + + + +
+
+

Täytä tiedot palvelusetelin arvon arvioimiseksi

+
+ +
+ + +
+
+
diff --git a/src/js/calculator/service_housing_service_voucher/_form.js b/src/js/calculator/service_housing_service_voucher/_form.js new file mode 100644 index 000000000..903339717 --- /dev/null +++ b/src/js/calculator/service_housing_service_voucher/_form.js @@ -0,0 +1,34 @@ +function getFormData(id, t) { + return { + form_id: id, + has_required_fields: true, + items: [ + { + input_float: { + id: 'net_income_per_month', + label: t('net_income_per_month'), + unit: t('unit_euro'), + min: 0, + size: 8, + required: true, + strip: '[€eE ]', + helper_text: t('net_income_per_month_explanation'), + }, + }, + { + input_float: { + id: 'service_provider_price', + label: t('service_provider_price'), + unit: t('unit_euro'), + min: 0, + size: 8, + required: true, + strip: '[€eE ]', + helper_text: t('service_provider_price_explanation'), + }, + }, + ] + }; +} + +export default { getFormData }; diff --git a/src/js/calculator/service_housing_service_voucher/_translations.js b/src/js/calculator/service_housing_service_voucher/_translations.js new file mode 100644 index 000000000..2535d74ff --- /dev/null +++ b/src/js/calculator/service_housing_service_voucher/_translations.js @@ -0,0 +1,86 @@ +/* eslint-disable no-template-curly-in-string */ + +const translations = { + net_income_per_month: { + fi: 'Nettotulot kuukaudessa', + sv: null, + en: null, + }, + net_income_per_month_explanation: { + fi: 'Nettotulot tarkoittavat tuloja verojen vähentämisen jälkeen. Tuloihin lasketaan eläkkeet, elatusavut, elinkorot, elatustuki sekä muut jatkuvat henkilökohtaiset tulot ja pääomasta tai omaisuudesta(kuten korko-, osinko- ja vuokratulot). Eläkkeen saajan hoitotukea, asumistukea, rintamalisää tai sotavammalain mukaista elinkorkoa ei huomioida.', + sv: null, + en: null, + }, + service_provider_price: { + fi: 'Palveluntuottajan kuukausihinta', + sv: null, + en: null, + }, + service_provider_price_explanation: { + fi: 'Valitsemasi palveluntuottajan perimä palveluasumisen kuukausihinta.', + sv: null, + en: null, + }, + receipt_estimate_of_payment: { + fi: 'Arvio palveluasumisen palvelusetelistä', + sv: null, + en: null, + }, + receipt_estimated_payment_prefix: { + fi: 'Omavastuuosuus eli sinulle maksettavaksi jäävä asiakasmaksu on', + sv: null, + en: null, + }, + receipt_estimated_payment_suffix: { + fi: 'euroa kuukaudessa.', + sv: null, + en: null, + }, + receipt_estimated_payment_explanation: { + fi: 'Tämä arvio on suuntaa antava. Tarkka arvo lasketaan kotihoidon tekemän päätöksen mukaan.', + sv: null, + en: null, + }, + receipt_estimate_is_based_on: { + fi: 'Palveluasumisen hinta palvelusetelillä ostettuna muodostuu seuraavasti:', + sv: null, + en: null, + }, + receipt_subtotal_full_price: { + fi: 'Palveluasumisen kokonaiskustannus', + sv: null, + en: null, + }, + receipt_subtotal_city_price: { + fi: 'Kaupunki maksaa palvelusetelillä yksityiselle tuottajalle ', + sv: null, + en: null, + }, + receipt_subtotal_self_price: { + fi: 'Sinulle maksettavaksi jäävä osuus eli omavastuu', + sv: null, + en: null, + }, + receipt_subtotal_euros_per_month: { + fi: '${value} €/kk', + sv: null, + en: null, + }, + receipt_subtotal_euros_per_month_screenreader: { + fi: '${value} euroa kuukaudessa', + sv: null, + en: null, + }, + receipt_additional_details: { + fi: 'Lisähuomiot:', + sv: null, + en: null, + }, + receipt_aria_live: { + fi: 'Omavastuuosuus eli sinulle maksettavaksi jäävä asiakasmaksu on ${payment} euroa kuukaudessa, lue lisätietoja lomakkeen alta.', + sv: null, + en: null, + }, +}; + +export default translations; diff --git a/src/js/calculator/service_housing_service_voucher/service_housing_service_voucher.js b/src/js/calculator/service_housing_service_voucher/service_housing_service_voucher.js new file mode 100644 index 000000000..1862263e2 --- /dev/null +++ b/src/js/calculator/service_housing_service_voucher/service_housing_service_voucher.js @@ -0,0 +1,185 @@ +import form from './_form'; +import translations from './_translations'; + +class ServiceHousingServiceVoucher { + constructor(id, settings) { + this.id = id; + const parsedSettings = JSON.parse(settings); + + // Expecting settings to follow this JSON format: + /* + const parsedSettings = { + voucher_from_net_income: { + '0': 3300, + '900.01': 3200, + '1000.01': 3100, + '1100.01': 3000, + '1200.01': 2900, + '1300.01': 2800, + '1400.01': 2700, + '1500.01': 2600, + '1600.01': 2500, + '1700.01': 2400, + '1800.01': 2300, + '1900.01': 2200, + '2000.01': 2100, + '2100.01': 2000, + '2200.01': 1900, + '2300.01': 1800, + '2400.01': 1700, + '2500.01': 1600, + '2600.01': 1500, + '2700.01': 1400, + '2800.01': 1300, + '2900.01': 1200, + '3000.01': 1100, + '3100.01': 1000, + '3200.01': 900, + '3300.01': 800, + '3400.01': 700, + '3500.01': 600, + }, + }; + // */ + // Form content + const getFormData = () => form.getFormData(this.id, this.t); + + const update = () => { + }; + + const validate = () => { + const errorMessages = []; + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // Validate basics from form + errorMessages.push(...this.calculator.validateBasics('net_income_per_month')); + errorMessages.push(...this.calculator.validateBasics('service_provider_price')); + + // Check if any missing input errors were found + if (errorMessages.length) { + return { + error: { + title: this.t('missing_input'), + message: errorMessages + }, + }; + } + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // Get field values for calculating. + const netIncomePerMonth = Number(this.calculator.getFieldValue('net_income_per_month')); + // const netIncomePerMonthRaw = this.calculator.getFieldValue('gross_income_per_month'); + const serviceProviderPrice = Number(this.calculator.getFieldValue('service_provider_price')); + + + // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + // Calculate results + + const voucherValue = this.calculator.getMinimumRange(netIncomePerMonth, parsedSettings.voucher_from_net_income); + const selfPayment = Math.max(0, serviceProviderPrice - voucherValue); + + // console.log( + // '\n netIncomePerMonth', netIncomePerMonth, + // '\n serviceProviderPrice', serviceProviderPrice, + // '\n', + // '\n voucherValue', voucherValue, + // '\n selfPayment', selfPayment, + // ); + + const subtotals = []; + + subtotals.push( + { + title: this.t('receipt_subtotal_full_price'), + has_details: false, + details: [], + sum: this.t('receipt_subtotal_euros_per_month', { value: this.calculator.formatFinnishEuroCents(serviceProviderPrice) }), + sum_screenreader: this.t('receipt_subtotal_euros_per_month_screenreader', { value: this.calculator.formatEuroCents(serviceProviderPrice) }), + }, + { + title: this.t('receipt_subtotal_city_price'), + has_details: false, + details: [], + sum: this.t('receipt_subtotal_euros_per_month', { value: this.calculator.formatFinnishEuroCents(voucherValue) }), + sum_screenreader: this.t('receipt_subtotal_euros_per_month_screenreader', { value: this.calculator.formatEuroCents(voucherValue) }), + }, + { + title: this.t('receipt_subtotal_self_price'), + has_details: false, + details: [], + sum: this.t('receipt_subtotal_euros_per_month', { value: this.calculator.formatFinnishEuroCents(selfPayment) }), + sum_screenreader: this.t('receipt_subtotal_euros_per_month_screenreader', { value: this.calculator.formatEuroCents(selfPayment) }), + }, + ); + + const additionalDetails = null; + + const receiptData = { + id: this.id, + title: this.t('receipt_estimate_of_payment'), + total_prefix: this.t('receipt_estimated_payment_prefix'), + total_value: this.calculator.formatFinnishEuroCents(selfPayment), + total_suffix: this.t('receipt_estimated_payment_suffix'), + total_explanation: this.t('receipt_estimated_payment_explanation'), + hr: true, + breakdown: { + title: this.t('receipt_estimate_is_based_on'), + subtotals, + additional_details: additionalDetails, + }, + }; + + const receipt = this.calculator.getPartialRender( + '{{>receipt}}', + receiptData, + ); + + return { + receipt, + ariaLive: this.t('receipt_aria_live', { payment: selfPayment }), + }; + }; + + const eventHandlers = { + submit: (event) => { + this.calculator.clearResult(); + event.preventDefault(); + const result = validate(); + this.calculator.renderResult(result); + }, + keydown: () => { + update(); + // this.calculator.clearResult(); + }, + change: () => { + update(); + // this.calculator.clearResult(); + // validate(); + }, + reset: () => { + window.setTimeout(update, 1); + this.calculator.clearResult(); + this.calculator.showAriaLiveText(this.t('reset_aria_live')); + }, + }; + + // Prepare calculator for translations + this.calculator = window.HelfiCalculator({ name: 'home_care_client_payment', translations }); + + // Create shortcut for translations + this.t = (key, value) => this.calculator.translate(key, value); + + // Parse settings to js + this.settings = this.calculator.parseSettings(settings); + + // Initialize calculator + this.calculator.init({ + id, + formData: getFormData(), + eventHandlers, + }); + } +} + +window.helfi_calculator = window.helfi_calculator || {}; +window.helfi_calculator.service_housing_service_voucher = (id, settings) => new ServiceHousingServiceVoucher(id, settings); diff --git a/templates/paragraphs/paragraph--calculator.html.twig b/templates/paragraphs/paragraph--calculator.html.twig index 75cbcbf9f..d05d6c450 100644 --- a/templates/paragraphs/paragraph--calculator.html.twig +++ b/templates/paragraphs/paragraph--calculator.html.twig @@ -28,9 +28,9 @@ 'home_care_service_voucher', 'home_care_client_payment', 'daycare_payment', + 'service_housing_service_voucher', ] %} {# - 'service_housing_service_voucher', 'family_with_kids_home_service_client_payment', 'oral_health_care_procedure', #}