feat: type=Salary auto-scopes Add-Adjustment picker to managers

When type=Salary: set pay-type filter to Managers-only, hide daily
rows, and untick any selected daily worker so a Salary can never
silently target a daily worker. Re-applied on the Pay-Salary open
path (the show.bs.modal reset clears it first). Pure JS; verified by
manual checklist; suite stays 207/207.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Konrad du Plessis 2026-05-16 22:20:46 +02:00
parent 0c705129f6
commit 31ee9e2e3c

View File

@ -1948,6 +1948,41 @@ document.addEventListener('DOMContentLoaded', function() {
addAdjPayImmediatelyGroup.style.display =
(payNowTypes.indexOf(addAdjType.value) !== -1) ? '' : 'none';
}
// === Salary → managers-only picker scope ===
// Salary is a managers-only adjustment (Worker.pay_type='fixed').
// To make it IMPOSSIBLE to accidentally pay a Salary to a daily
// worker, when the type is Salary we: (1) set the pay-type
// filter to "Managers only", (2) hide every non-manager row,
// and (3) UNTICK any non-manager that was already selected so a
// stray daily-worker tick can't ride along hidden into a bad
// Salary adjustment. For any other type we reset the filter to
// "All" and re-show every row (we do NOT re-tick anything — the
// user re-selects deliberately). Re-grab the filter <select> by
// id here rather than relying on the outer `addAdjPayTypeFilter`
// var, because this function also runs at init time (before that
// var is assigned).
var _ptFilter = document.getElementById('addAdjPayTypeFilter');
if (_ptFilter) {
var _isSalary = (addAdjType.value === 'Salary');
_ptFilter.value = _isSalary ? 'fixed' : '';
addAdjWorkerCheckboxes.forEach(function(cb) {
var row = cb.closest('.form-check');
if (!row) return;
var rowType = row.getAttribute('data-pay-type') || '';
if (_isSalary && rowType !== 'fixed') {
// Non-manager while Salary: hide AND untick it.
row.style.display = 'none';
cb.checked = false;
} else {
// Manager (any type) or any row when not Salary:
// ensure visible; leave its checked state alone.
row.style.display = '';
}
});
// Reflect any auto-untick in the "X worker(s) selected"
// counter (function-hoisted, safe to call here).
updateWorkerCount();
}
}
if (addAdjType) {
addAdjType.addEventListener('change', toggleProjectField);
@ -2104,6 +2139,12 @@ document.addEventListener('DOMContentLoaded', function() {
}
if (_paySalaryOpen) {
_paySalaryOpen = false;
// The reset block above just cleared the pay-type
// filter + re-showed all rows. Type is already 'Salary'
// (set by the Pay-Salary button), so re-run the
// chokepoint to restore Managers-only scope + untick
// any non-manager.
toggleProjectField();
return; // Pay-Salary already set type=Salary
}
// Reset: uncheck all workers, clear project, reset type