Fix Sundry Creditors follow-up FY dropdown
This commit is contained in:
@@ -21,12 +21,12 @@
|
|||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
<label class="space-y-1 text-sm"><span class="font-semibold text-slate-700">Analysis FY</span>
|
<label class="space-y-1 text-sm"><span class="font-semibold text-slate-700">Analysis FY</span>
|
||||||
<select name="financial_year" class="w-full rounded-xl border border-slate-300 px-3 py-2">
|
<select name="financial_year" data-creditor-analysis-fy class="w-full rounded-xl border border-slate-300 px-3 py-2">
|
||||||
{% for fy in fy_options %}<option value="{{ fy }}" {% if fy == selected_fy %}selected{% endif %}>{{ fy }}</option>{% endfor %}
|
{% for fy in fy_options %}<option value="{{ fy }}" {% if fy == selected_fy %}selected{% endif %}>{{ fy }}</option>{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
</label>
|
</label>
|
||||||
<label class="space-y-1 text-sm"><span class="font-semibold text-slate-700">Follow-up FY (optional)</span>
|
<label class="space-y-1 text-sm"><span class="font-semibold text-slate-700">Follow-up FY (optional)</span>
|
||||||
<select name="follow_up_fy" class="w-full rounded-xl border border-slate-300 px-3 py-2">
|
<select name="follow_up_fy" data-creditor-follow-up-fy class="w-full rounded-xl border border-slate-300 px-3 py-2">
|
||||||
<option value="">Do not trace later payments</option>
|
<option value="">Do not trace later payments</option>
|
||||||
{% for fy in fy_options %}{% if fy > selected_fy %}<option value="{{ fy }}" {% if fy == follow_up_fy %}selected{% endif %}>{{ fy }}</option>{% endif %}{% endfor %}
|
{% for fy in fy_options %}{% if fy > selected_fy %}<option value="{{ fy }}" {% if fy == follow_up_fy %}selected{% endif %}>{{ fy }}</option>{% endif %}{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
@@ -143,6 +143,67 @@
|
|||||||
|
|
||||||
<script>
|
<script>
|
||||||
(function () {
|
(function () {
|
||||||
|
// Keep Follow-up FY synchronized with the Analysis FY on the client side.
|
||||||
|
// Previously the server rendered follow-up options only for the FY that was
|
||||||
|
// active when the page loaded. If the user changed Analysis FY in the form
|
||||||
|
// (for example 2026-27 -> 2021-22), the Follow-up FY control still showed
|
||||||
|
// 2027-28 until the page was submitted. Rebuild it immediately from the FY
|
||||||
|
// values already supplied by the server, without changing any accounting or
|
||||||
|
// FIFO calculation logic.
|
||||||
|
var analysisFySelect = document.querySelector('[data-creditor-analysis-fy]');
|
||||||
|
var followUpFySelect = document.querySelector('[data-creditor-follow-up-fy]');
|
||||||
|
|
||||||
|
function fyStartYear(value) {
|
||||||
|
var match = String(value || '').match(/^(\d{4})-\d{2}$/);
|
||||||
|
return match ? parseInt(match[1], 10) : null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (analysisFySelect && followUpFySelect) {
|
||||||
|
var fyUniverse = Array.from(analysisFySelect.options)
|
||||||
|
.map(function (option) { return String(option.value || '').trim(); })
|
||||||
|
.filter(function (value) { return fyStartYear(value) !== null; });
|
||||||
|
|
||||||
|
function rebuildFollowUpYears() {
|
||||||
|
var selectedFy = String(analysisFySelect.value || '').trim();
|
||||||
|
var selectedStart = fyStartYear(selectedFy);
|
||||||
|
var previousFollowUp = String(followUpFySelect.value || '').trim();
|
||||||
|
|
||||||
|
while (followUpFySelect.options.length) {
|
||||||
|
followUpFySelect.remove(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
var emptyOption = document.createElement('option');
|
||||||
|
emptyOption.value = '';
|
||||||
|
emptyOption.textContent = 'Do not trace later payments';
|
||||||
|
followUpFySelect.appendChild(emptyOption);
|
||||||
|
|
||||||
|
if (selectedStart === null) return;
|
||||||
|
|
||||||
|
var laterYears = fyUniverse
|
||||||
|
.filter(function (fy) {
|
||||||
|
var start = fyStartYear(fy);
|
||||||
|
return start !== null && start > selectedStart;
|
||||||
|
})
|
||||||
|
.sort(function (a, b) { return fyStartYear(a) - fyStartYear(b); });
|
||||||
|
|
||||||
|
laterYears.forEach(function (fy) {
|
||||||
|
var option = document.createElement('option');
|
||||||
|
option.value = fy;
|
||||||
|
option.textContent = fy;
|
||||||
|
followUpFySelect.appendChild(option);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (laterYears.indexOf(previousFollowUp) !== -1) {
|
||||||
|
followUpFySelect.value = previousFollowUp;
|
||||||
|
} else {
|
||||||
|
followUpFySelect.value = '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
analysisFySelect.addEventListener('change', rebuildFollowUpYears);
|
||||||
|
rebuildFollowUpYears();
|
||||||
|
}
|
||||||
|
|
||||||
function applyBucket(detailRow, bucket) {
|
function applyBucket(detailRow, bucket) {
|
||||||
if (!detailRow) return;
|
if (!detailRow) return;
|
||||||
detailRow.querySelectorAll('[data-creditor-lot]').forEach(function (lot) {
|
detailRow.querySelectorAll('[data-creditor-lot]').forEach(function (lot) {
|
||||||
|
|||||||
Reference in New Issue
Block a user