Kostenberechnung gefixt
This commit is contained in:
parent
8e41074a26
commit
4784c93337
@ -184,10 +184,10 @@ Domains jährlich: <span id="costDomain">0</span> €<br>
|
||||
<input id="os">
|
||||
|
||||
<label>Kosten Monat</label>
|
||||
<input id="kosten_monat">
|
||||
<input id="kosten_monat" type="number" step="0.01">
|
||||
|
||||
<label>Kosten Jahr</label>
|
||||
<input id="kosten_jahr">
|
||||
<input id="kosten_jahr" type="number" step="0.01">
|
||||
|
||||
<label>Providername</label>
|
||||
<input id="providername">
|
||||
|
||||
@ -1,5 +1,42 @@
|
||||
window.resources = []
|
||||
|
||||
function normalizeCostValue(value){
|
||||
if(!value) return ""
|
||||
|
||||
return String(value).replace(",", ".")
|
||||
}
|
||||
|
||||
function formatCostValue(value){
|
||||
if(!Number.isFinite(value)) return ""
|
||||
|
||||
return value.toFixed(2)
|
||||
}
|
||||
|
||||
function setupResourceCostSync(){
|
||||
const monthInput = document.getElementById("kosten_monat")
|
||||
const yearInput = document.getElementById("kosten_jahr")
|
||||
|
||||
if(!monthInput || !yearInput) return
|
||||
|
||||
monthInput.addEventListener("input", () => {
|
||||
const month = parseFloat(normalizeCostValue(monthInput.value))
|
||||
|
||||
if(Number.isFinite(month)){
|
||||
yearInput.value = formatCostValue(month * 12)
|
||||
}
|
||||
})
|
||||
|
||||
yearInput.addEventListener("input", () => {
|
||||
const year = parseFloat(normalizeCostValue(yearInput.value))
|
||||
|
||||
if(Number.isFinite(year)){
|
||||
monthInput.value = formatCostValue(year / 12)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
document.addEventListener("DOMContentLoaded", setupResourceCostSync)
|
||||
|
||||
window.loadResources = async function(){
|
||||
|
||||
window.resources = await api(API + "/resources/active")
|
||||
@ -86,11 +123,16 @@ window.saveResource = async function(){
|
||||
const id = document.getElementById("resource_id").value
|
||||
const field = id => document.getElementById(id).value
|
||||
|
||||
let kostenMonat=document.getElementById("kosten_monat").value
|
||||
let kostenJahr=document.getElementById("kosten_jahr").value
|
||||
let kostenMonat=normalizeCostValue(document.getElementById("kosten_monat").value)
|
||||
let kostenJahr=normalizeCostValue(document.getElementById("kosten_jahr").value)
|
||||
|
||||
if(kostenMonat) kostenMonat=kostenMonat.replace(",",".")
|
||||
if(kostenJahr) kostenJahr=kostenJahr.replace(",",".")
|
||||
if(kostenMonat && !kostenJahr){
|
||||
kostenJahr = formatCostValue(parseFloat(kostenMonat) * 12)
|
||||
}
|
||||
|
||||
if(kostenJahr && !kostenMonat){
|
||||
kostenMonat = formatCostValue(parseFloat(kostenJahr) / 12)
|
||||
}
|
||||
|
||||
const data={
|
||||
name: field("name"),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user