Rend les lignes de tarifs directement modifiables

This commit is contained in:
Alexandre NOEL 2026-09-08 01:04:34 +02:00
commit f41504c852
5 changed files with 34 additions and 22 deletions

View file

@ -140,7 +140,7 @@
<h3 class="card-title"><?= h(t('pricing.grid')) ?></h3>
</div>
<div class="table-responsive">
<table class="table table-vcenter mb-0">
<table class="table table-vcenter table-hover mb-0">
<thead>
<tr>
<th><?= h(t('pricing.structure')) ?></th>
@ -150,10 +150,15 @@
<th class="text-end"><?= h(t('pricing.catalog')) ?></th>
<th class="text-end"><?= h(t('pricing.estimated_cost')) ?></th>
<th><?= h(t('pricing.state')) ?></th>
<th class="text-end"><?= h(t('common.actions')) ?></th>
</tr>
</thead>
<tbody><?php foreach ($tariffs as $t): ?><tr>
<tbody><?php foreach ($tariffs as $t): ?><tr class="tariff-edit cursor-pointer" tabindex="0"
aria-label="<?= h(t('pricing.edit_tariff') . ' : ' . $t['label']) ?>"
data-id="<?= (int)$t['id'] ?>" data-clinic="<?= (int)$t['clinic_contact_id'] ?>"
data-label="<?= h($t['label']) ?>" data-amount="<?= h(number_format($t['amount_cents'] / 100, 2, '.', '')) ?>"
data-category="<?= h($t['category']) ?>" data-group="<?= h($t['discount_group']) ?>"
data-unit="<?= h($t['unit_label']) ?>" data-medication="<?= (int)($t['medication_id'] ?? 0) ?>"
data-active="<?= (int)$t['active'] ?>">
<td><?= h($t['clinic_name']) ?></td>
<td class="fw-semibold"><?= h($t['label']) ?><div class="text-muted small">
<?= h(t('pricing.per_unit', ['unit' => $t['unit_label']])) ?></div>
@ -166,28 +171,25 @@
<td><span
class="badge <?= $t['active'] ? 'bg-green-lt' : 'bg-secondary-lt' ?>"><?= $t['active'] ? t('pricing.active') : t('pricing.inactive') ?></span>
</td>
<td class="text-end"><div class="btn-list justify-content-end">
<button class="btn btn-sm btn-icon btn-outline-primary tariff-edit" type="button"
title="<?= h(t('pricing.edit_tariff')) ?>" aria-label="<?= h(t('pricing.edit_tariff')) ?>"
data-id="<?= (int)$t['id'] ?>" data-clinic="<?= (int)$t['clinic_contact_id'] ?>"
data-label="<?= h($t['label']) ?>" data-amount="<?= h(number_format($t['amount_cents'] / 100, 2, '.', '')) ?>"
data-category="<?= h($t['category']) ?>" data-group="<?= h($t['discount_group']) ?>"
data-unit="<?= h($t['unit_label']) ?>" data-medication="<?= (int)($t['medication_id'] ?? 0) ?>"
data-active="<?= (int)$t['active'] ?>"><span aria-hidden="true">✏️</span></button>
<form method="post" action="/settings/pricing/tariff/delete" onsubmit="return confirm(<?= h(json_encode(t('pricing.delete_confirm'), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES)) ?>)">
<input type="hidden" name="id" value="<?= (int)$t['id'] ?>"><button class="btn btn-sm btn-icon btn-outline-danger" type="submit" title="<?= h(t('common.delete')) ?>" aria-label="<?= h(t('common.delete')) ?>"><span aria-hidden="true">🗑️</span></button>
</form>
</div></td>
</tr><?php endforeach; ?></tbody>
</table>
</div>
</div>
<script>
document.querySelectorAll('.tariff-edit').forEach((button) => button.addEventListener('click', () => {
const editTariff = (row) => {
const fields = {tariffId:'id',tariffClinic:'clinic',tariffLabel:'label',tariffAmount:'amount',tariffCategory:'category',tariffGroup:'group',tariffUnit:'unit',tariffMedication:'medication'};
Object.entries(fields).forEach(([id, key]) => { document.getElementById(id).value = button.dataset[key] || ''; });
document.getElementById('tariffActive').checked = button.dataset.active === '1';
Object.entries(fields).forEach(([id, key]) => { document.getElementById(id).value = row.dataset[key] || ''; });
document.getElementById('tariffActive').checked = row.dataset.active === '1';
document.getElementById('tariffForm').scrollIntoView({behavior:'smooth', block:'start'});
document.getElementById('tariffLabel').focus({preventScroll:true});
}));
};
document.querySelectorAll('.tariff-edit').forEach((row) => {
row.addEventListener('click', () => editTariff(row));
row.addEventListener('keydown', (event) => {
if (event.key === 'Enter' || event.key === ' ') {
event.preventDefault();
editTariff(row);
}
});
});
</script>