{"version":3,"sources":["webpack://metamatrix.web/./static/scripts/incomeinsurancecalculator/incomeTaxService.js","webpack://metamatrix.web/./static/scripts/incomeinsurancecalculator/incomeinsurancecalculator.js","webpack://metamatrix.web/webpack/bootstrap","webpack://metamatrix.web/webpack/runtime/define property getters","webpack://metamatrix.web/webpack/runtime/hasOwnProperty shorthand","webpack://metamatrix.web/webpack/startup"],"names":[],"mappings":";;;;;;;;;;AAAA,CAAgB;;AAEhB;;AAEA;AACA;AACA;AACA,oDAAoD,OAAO,QAAQ,KAAK,SAAS,MAAM,UAAU,OAAO;;AAExG;;AAEA;AACA;AACA;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;;AAEA,+DAA+D,OAAO,QAAQ,KAAK,SAAS,MAAM,UAAU,OAAO;AACnH;;AAEA;AACA;AACA;;AAEA;;AAEA;;AAEA,E;;;;;;;;;ACpCA,CAAmD;;AAEpC;;AAEf;AACA;AACA,oCAAoC,+DAAgB;AACpD;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA,+CAA+C,wBAAwB,0BAA0B;AACjG;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;;AAEA;AACA;;AAEA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB;;AAEjB;AACA;AACA;;AAEA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;;AAEA,iBAAiB;;AAEjB;;AAEA;;AAEA,aAAa;AACb;AACA;AACA;AACA;AACA,aAAa;;AAEb;;AAEA;;AAEA;;AAEA;;AAEA;AACA;AACA;AACA;AACA,SAAS;;AAET;AACA;AACA;AACA;AACA;AACA,aAAa;AACb;AACA;AACA;AACA;AACA;AACA,yBAAyB;AACzB;AACA,qBAAqB;AACrB;AACA;AACA,qBAAqB;AACrB,iBAAiB;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,iBAAiB;AACjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,yBAAyB;AACzB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS;AACT;;AAEA;AACA;AACA;AACA;;AAEA;;AAEA,0FAA0F,iBAAiB,E;;;;;;UCjL3G;UACA;;UAEA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;UACA;;UAEA;UACA;;UAEA;UACA;UACA;;;;;WCrBA;WACA;WACA;WACA;WACA,wCAAwC,yCAAyC;WACjF;WACA;WACA,E;;;;;WCPA,wF;;;;;UCAA;UACA;UACA;UACA;UACA","file":"scripts/incomeinsurancecalculator.js","sourcesContent":["export default class IncomeTaxService {\r\n\r\n async getTax(income, year, table = 30, column = 1) {\r\n\r\n if (!year) {\r\n year = new Date().getFullYear();\r\n }\r\n const url = `/api/IncomeTax/GetTax?income=${income}&year=${year}&table=${table}&column=${column}`;\r\n\r\n const response = await fetch(url);\r\n\r\n if (response.ok) {\r\n return await response.text();\r\n }\r\n\r\n throw new Error(\"Couldn't get Tax\");\r\n\r\n }\r\n\r\n async getIncomeAfterTax(income, year, table = 30, column = 1) {\r\n\r\n if (!year) {\r\n year = new Date().getFullYear();\r\n }\r\n\r\n const url = `/api/IncomeTax/GetIncomeAfterTax?income=${income}&year=${year}&table=${table}&column=${column}`;\r\n const response = await fetch(url);\r\n\r\n if (response.ok) {\r\n return await response.text();\r\n }\r\n\r\n throw new Error(\"Couldn't get IncomeAfterTax\");\r\n\r\n }\r\n\r\n};","import IncomeTaxService from \"./incomeTaxService\";\r\n\r\nexport default class incomeInsuranceCalculatorComponent extends HTMLDivElement {\r\n\r\n constructor() {\r\n super();\r\n this.incomeTaxService = new IncomeTaxService();\r\n this.onFormSubmit = this.onFormSubmit.bind(this);\r\n }\r\n\r\n connectedCallback(e) {\r\n this.formElement.addEventListener(\"submit\", this.onFormSubmit, false);\r\n }\r\n\r\n disconnectedCallback() {\r\n this.formElement.removeEventListener(\"submit\", this.onFormSubmit);\r\n }\r\n\r\n get canvasElement() {\r\n return this.getElementsByTagName(\"canvas\")[0];\r\n }\r\n\r\n get formElement() {\r\n return this.querySelector(\"[data-insurance-calculator-form]\");\r\n }\r\n\r\n get formInputElement() {\r\n return this.formElement.querySelector(\"[data-insurance-calculator-form-input]\");\r\n }\r\n\r\n get hiddenResultElement() {\r\n return this.querySelector(\"[data-insurance-calculator-result]\");\r\n }\r\n\r\n get periods() {\r\n return this.dataset.periods.split(\",\");\r\n }\r\n\r\n get insurances() {\r\n return this.dataset.insurances.split(\";\").map(function (item) { return JSON.parse(item) });\r\n }\r\n\r\n get salary() {\r\n return this.formInputElement.value.match(/\\d+/g).join('');\r\n }\r\n\r\n get salaryColor() {\r\n return this.dataset.salarycolor;\r\n }\r\n\r\n refreshChart() {\r\n\r\n this.incomeTaxService.getIncomeAfterTax(this.salary)\r\n .then(data => {\r\n\r\n const salary = data;\r\n\r\n // Prepare the periods array\r\n let periods = [\"Lön\"];\r\n periods.push(...this.periods);\r\n\r\n // Prepare the datasets array\r\n let datasets = [{\r\n label: \"Lön\",\r\n data: [salary, 0, 0, 0],\r\n backgroundColor: this.salaryColor,\r\n barThickness: 'flex'\r\n }];\r\n\r\n let compensationSumForPeriod1 = 0;\r\n let compensationSumForPeriod2 = 0;\r\n let compensationSumForPeriod3 = 0;\r\n\r\n // Fill the datasets with our compensations\r\n datasets.push(...this.insurances.map(function (item) {\r\n\r\n const compensationForPeriod1 = Math.max(Math.min(item.Compensation1 * salary, item.Ceiling1) - compensationSumForPeriod1, 0);\r\n const compensationForPeriod2 = Math.max(Math.min(item.Compensation2 * salary, item.Ceiling2) - compensationSumForPeriod2, 0);\r\n const compensationForPeriod3 = Math.max(Math.min(item.Compensation3 * salary, item.Ceiling3) - compensationSumForPeriod3, 0);\r\n\r\n compensationSumForPeriod1 += compensationForPeriod1;\r\n compensationSumForPeriod2 += compensationForPeriod2;\r\n compensationSumForPeriod3 += compensationForPeriod3;\r\n\r\n return {\r\n label: item.Label,\r\n data: [0, compensationForPeriod1, compensationForPeriod2, compensationForPeriod3],\r\n backgroundColor: item.Color,\r\n barThickness: 'flex'\r\n }\r\n\r\n }));\r\n\r\n this.renderChart(periods, datasets);\r\n\r\n this.hiddenResultElement.classList.remove(\"hidden\");\r\n\r\n })\r\n .catch(error => {\r\n console.log(error);\r\n if (this.chart) this.chart.destroy();\r\n this.hiddenResultElement.classList.add(\"hidden\");\r\n });\r\n\r\n }\r\n\r\n renderChart(labels, datasets) {\r\n\r\n this.canvasElement.classList.remove(\"hidden\");\r\n\r\n if (this.chart) this.chart.destroy();\r\n\r\n let sek = new Intl.NumberFormat('sv-SE', {\r\n style: 'currency',\r\n currency: 'SEK',\r\n maximumFractionDigits: 0\r\n });\r\n\r\n this.chart = new Chart(this.canvasElement, {\r\n type: 'bar',\r\n data: {\r\n labels: labels,\r\n datasets: datasets\r\n },\r\n options: {\r\n scales: {\r\n yAxes: [{\r\n ticks: {\r\n beginAtZero: true\r\n },\r\n stacked: true\r\n }],\r\n xAxes: [{\r\n stacked: true\r\n }]\r\n },\r\n legend: {\r\n display: false,\r\n position: 'bottom',\r\n labels: {\r\n fontSize: 20,\r\n padding: 20,\r\n fontColor: 'black'\r\n }\r\n },\r\n tooltips: {\r\n mode: 'x',\r\n titleFontSize: 16,\r\n titleMarginBottom: 10,\r\n bodyFontSize: 12,\r\n footerFontSize: 12,\r\n footerMarginTop: 10,\r\n filter: tooltipItem => tooltipItem.value > 0,\r\n callbacks: {\r\n footer: function (items) {\r\n return 'Totalt: ' + sek.format(items.reduce((partialSum, a) => partialSum + parseFloat(a.value), 0)) + \"/mån\";\r\n },\r\n label: function (tooltipItem, data) {\r\n var label = data.datasets[tooltipItem.datasetIndex].label || '';\r\n if (label) {\r\n label = \" \" + label + \": \" + sek.format(tooltipItem.value) + \"/mån\";\r\n }\r\n return label;\r\n }\r\n }\r\n }\r\n }\r\n });\r\n }\r\n\r\n onFormSubmit(event) {\r\n event.preventDefault();\r\n this.refreshChart();\r\n }\r\n\r\n}\r\n\r\ncustomElements.define('income-insurance-calculator', incomeInsuranceCalculatorComponent, { extends: \"div\" });","// The module cache\nvar __webpack_module_cache__ = {};\n\n// The require function\nfunction __webpack_require__(moduleId) {\n\t// Check if module is in cache\n\tif(__webpack_module_cache__[moduleId]) {\n\t\treturn __webpack_module_cache__[moduleId].exports;\n\t}\n\t// Create a new module (and put it into the cache)\n\tvar module = __webpack_module_cache__[moduleId] = {\n\t\t// no module.id needed\n\t\t// no module.loaded needed\n\t\texports: {}\n\t};\n\n\t// Execute the module function\n\t__webpack_modules__[moduleId](module, module.exports, __webpack_require__);\n\n\t// Return the exports of the module\n\treturn module.exports;\n}\n\n","// define getter functions for harmony exports\n__webpack_require__.d = (exports, definition) => {\n\tfor(var key in definition) {\n\t\tif(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {\n\t\t\tObject.defineProperty(exports, key, { enumerable: true, get: definition[key] });\n\t\t}\n\t}\n};","__webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))","// startup\n// Load entry module and return exports\n__webpack_require__(24);\n// This entry module is referenced by other modules so it can't be inlined\nvar __webpack_exports__ = __webpack_require__(356);\n"],"sourceRoot":""}