Eigenanteil-Checkbox: aktivierbar nur bei Ausgabe + 4920/4925 + 19%

This commit is contained in:
fds2610 2026-03-29 14:17:00 +02:00
parent f794bc2fa4
commit b2ec028137

View file

@ -346,7 +346,7 @@ $suppliers = $suppliers ?? [];
<input type="search" placeholder="Kontonr. oder Bezeichnung filtern…" class="konto-filter"
data-target="kategorie_konto_id" autocomplete="off" style="margin-bottom:.3rem">
<select id="kategorie_konto_id" name="kategorie_konto_id" required size="6"
onchange="showKontoArt('kategorie_konto_id','kategorie_konto_art',this)">
onchange="showKontoArt('kategorie_konto_id','kategorie_konto_art',this);updateEigenanteilState()">
<option value="">– Konto wählen –</option>
<?php foreach (['Betriebsausgabe', 'Betriebseinnahme', 'Privat'] as $art): ?>
<?php if (empty($kontenGruppen[$art])) continue; ?>
@ -410,9 +410,9 @@ $suppliers = $suppliers ?? [];
</div>
</div>
<div class="form-group" style="margin-bottom:.75rem">
<label style="display:flex;align-items:center;gap:.5rem;cursor:pointer">
<input type="checkbox" name="eigenanteil_30" value="1">
<div class="form-group" id="eigenanteil_group" style="margin-bottom:.75rem;opacity:.35;pointer-events:none">
<label style="display:flex;align-items:center;gap:.5rem;cursor:not-allowed">
<input type="checkbox" id="eigenanteil_30_cb" name="eigenanteil_30" value="1" disabled>
30% Eigenanteil buchen
</label>
</div>
@ -448,12 +448,38 @@ function filterKategorieKonten(buchungstyp) {
select.selectedIndex = 0;
}
}
updateEigenanteilState();
}
function updateEigenanteilState() {
const group = document.getElementById('eigenanteil_group');
const cb = document.getElementById('eigenanteil_30_cb');
if (!group || !cb) return;
const buchungstyp = document.querySelector('input[name="buchungstyp"]:checked');
const kategorieEl = document.getElementById('kategorie_konto_id');
const ustSatzEl = document.getElementById('ust_satz_select');
const istAusgabe = buchungstyp && buchungstyp.value === 'Ausgabe';
const selectedOpt = kategorieEl && kategorieEl.options[kategorieEl.selectedIndex];
const kontonummer = selectedOpt ? (selectedOpt.getAttribute('data-search') || '').split(' ')[0] : '';
const istTelInternet = kontonummer === '4920' || kontonummer === '4925';
const ist19 = ustSatzEl && ustSatzEl.value === '19';
const aktiv = istAusgabe && istTelInternet && ist19;
group.style.opacity = aktiv ? '1' : '.35';
group.style.pointerEvents = aktiv ? '' : 'none';
group.querySelector('label').style.cursor = aktiv ? 'pointer' : 'not-allowed';
cb.disabled = !aktiv;
if (!aktiv) cb.checked = false;
}
// Initial filtern
document.addEventListener('DOMContentLoaded', function() {
const checked = document.querySelector('input[name="buchungstyp"]:checked');
if (checked) filterKategorieKonten(checked.value);
updateSteuerartVisibility();
updateEigenanteilState();
});
function updateSteuerartVisibility() {
@ -468,5 +494,6 @@ function updateSteuerartVisibility() {
steuerartGroup.style.display = 'none';
if (steuerartSelect) steuerartSelect.value = 'normal';
}
updateEigenanteilState();
}
</script>