diff --git a/core/templates/core/payroll_dashboard.html b/core/templates/core/payroll_dashboard.html index 0c3b74c..b41e550 100644 --- a/core/templates/core/payroll_dashboard.html +++ b/core/templates/core/payroll_dashboard.html @@ -308,6 +308,12 @@ data-worker-name="{{ wd.worker.name }}"> +
{% csrf_token %} @@ -1389,6 +1395,59 @@ document.addEventListener('DOMContentLoaded', function() { }); } + // === QUICK ADJUST BUTTON === + // Opens the Add Adjustment modal with one worker pre-checked + // and their most recent project pre-selected. + var _quickAdjustOpen = false; // Flag to distinguish quick-adjust from header button + document.querySelectorAll('.quick-adjust-btn').forEach(function(btn) { + btn.addEventListener('click', function() { + _quickAdjustOpen = true; + var workerId = this.dataset.workerId; + var projectId = this.dataset.workerProject; + + // Uncheck all workers, then check only the target worker + addAdjWorkerCheckboxes.forEach(function(cb) { + cb.checked = (cb.value === workerId); + }); + updateWorkerCount(); + + // Pre-select the worker's most recent project (if available) + if (projectId && addAdjProject) { + addAdjProject.value = projectId; + } + + // Reset type to default (Bonus) and trigger field visibility update + if (addAdjType) { + addAdjType.value = 'Bonus'; + toggleProjectField(); + } + + // Open the modal + var modal = new bootstrap.Modal(document.getElementById('addAdjustmentModal')); + modal.show(); + }); + }); + + // When the modal is opened from the HEADER button (not quick-adjust), + // clear any pre-selected workers and project from a previous quick-adjust. + var addAdjModal = document.getElementById('addAdjustmentModal'); + if (addAdjModal) { + addAdjModal.addEventListener('show.bs.modal', function() { + if (_quickAdjustOpen) { + _quickAdjustOpen = false; + return; // Quick-adjust already set the values + } + // Reset: uncheck all workers, clear project, reset type + addAdjWorkerCheckboxes.forEach(function(cb) { cb.checked = false; }); + updateWorkerCount(); + if (addAdjProject) addAdjProject.value = ''; + if (addAdjType) { + addAdjType.value = 'Bonus'; + toggleProjectField(); + } + }); + } + // Form validation: ensure at least one worker is selected before submit. // Without this, the form would submit and silently create 0 adjustments. var addAdjForm = document.querySelector('#addAdjustmentModal form'); diff --git a/core/views.py b/core/views.py index f6a6848..2274fe2 100644 --- a/core/views.py +++ b/core/views.py @@ -921,6 +921,9 @@ def payroll_dashboard(request): has_loan = Loan.objects.filter(worker=worker, active=True).exists() + # Most recent project — used by the "Adjust" button to pre-select project + last_project_id = unpaid_logs[-1].project_id if unpaid_logs else None + workers_data.append({ 'worker': worker, 'unpaid_count': log_count, @@ -935,6 +938,7 @@ def payroll_dashboard(request): 'is_overdue': is_overdue, 'has_loan': has_loan, 'earliest_unpaid': earliest_unpaid, + 'last_project_id': last_project_id, }) outstanding_total += max(total_payable, Decimal('0.00')) unpaid_wages_total += log_amount