39 lines
2.1 KiB
PHP
39 lines
2.1 KiB
PHP
<div class="col-12"><label class="form-label"><?= h(t('animal.tariff_record')) ?> <span
|
||
class="text-muted">(<?= h(mb_strtolower(t('common.optional'))) ?>)</span></label><select class="form-select"
|
||
name="tariff_id">
|
||
<option value=""><?= h(t('animal.no_expense')) ?></option><?php $expenseClinic = '';
|
||
foreach (($expenseTariffs ?? []) as $t):if ($expenseClinic !== $t['clinic_name']):if ($expenseClinic !== ''):?>
|
||
</optgroup><?php endif;
|
||
$expenseClinic = $t['clinic_name'];?><optgroup label="<?= h($expenseClinic) ?>"><?php endif;?><option
|
||
value="<?= (int)$t['id'] ?>" data-clinic="<?= (int)$t['clinic_contact_id'] ?>"><?= h($t['label']) ?> ·
|
||
<?= number_format($t['effective_cents'] / 100, 2, ',', ' ') ?> €
|
||
<?= h(t('animal.net')) ?><?= (float)$t['discount_percent'] > 0 ? ' (−' . number_format((float)$t['discount_percent'], 0) . ' %)' : '' ?>
|
||
</option><?php endforeach;
|
||
if ($expenseClinic !== ''):?></optgroup><?php endif;?>
|
||
</select>
|
||
<div class="form-hint"><?= h(t('animal.expense_hint')) ?></div>
|
||
</div>
|
||
<script>
|
||
document.addEventListener('DOMContentLoaded', () => {
|
||
document.querySelectorAll('form').forEach(form => {
|
||
const clinic = form.querySelector('select[name="clinic_contact_id"]');
|
||
const tariff = form.querySelector('select[name="tariff_id"]');
|
||
if (!clinic || !tariff || tariff.dataset.clinicFilterReady) return;
|
||
tariff.dataset.clinicFilterReady = '1';
|
||
const sync = () => {
|
||
const clinicId = clinic.value;
|
||
[...tariff.options].forEach(option => {
|
||
if (!option.dataset.clinic) return;
|
||
option.hidden = !clinicId || option.dataset.clinic !== clinicId;
|
||
option.disabled = option.hidden;
|
||
});
|
||
[...tariff.querySelectorAll('optgroup')].forEach(group => {
|
||
group.hidden = ![...group.querySelectorAll('option')].some(option => !option.hidden);
|
||
});
|
||
if (tariff.selectedOptions[0]?.hidden) tariff.value = '';
|
||
};
|
||
clinic.addEventListener('change', sync);
|
||
sync();
|
||
});
|
||
});
|
||
</script>
|