Website : rimsha.abasa.com
backdoor
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
www
/
mudeerapi.abasa.com
/
nodetest
/
Filename :
TENURE_MONTH_SELECTION_FLOW.md
back
Copy
# Tenure Month Selection - Visual Flow ## User Flow Example ``` User: Farzam Khan Join Date: January 15, 2025 Current Date: April 18, 2026 Tenures: Tenure 1: Jan 15, 2025 → Jan 14, 2026 (12 paid leaves allocated) Tenure 2: Jan 15, 2026 → Jan 14, 2027 (12 paid leaves allocated) ← Current ``` ### Scenario A: Viewing Current Month (April 2026) ``` ┌─────────────────────────────────────────────────────┐ │ Attendance Page │ │ │ │ Filters: [Current Month ▼] [April 2026 ▼] │ └─────────────────────────────────────────────────────┘ │ │ GET /user/:id/leave-info?month=2026-04 ▼ ┌─────────────────────────────────────────────────────┐ │ Backend calculates: │ │ - Target: April 2026 │ │ - Tenure: Jan 15, 2026 → Jan 14, 2027 (Tenure 2) │ │ - Count leaves from Jan 15, 2026 to today │ └─────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────┐ │ Response: │ │ { │ │ leaveYear: 2026, │ │ tenureLabel: "Current Tenure (Jan 15, 2026 – │ │ Jan 14, 2027)", │ │ isCurrentTenure: true, │ │ paidLeaves: { allocated: 12, used: 6 }, │ │ ... │ │ } │ └─────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────┐ │ ┌─────────────────────────────────────────────────┐│ │ │ Attendance Summary – Current Tenure ││ │ │ (Jan 15, 2026 – Jan 14, 2027) ││ │ │ ││ │ │ [0] [0] [0] [6/12] [0] ││ │ │ Presents Lates Absents Paid Unpaid ││ │ │ Leaves Leaves ││ │ └─────────────────────────────────────────────────┘│ │ │ │ Calendar showing April 2026 attendance → │ └─────────────────────────────────────────────────────┘ ``` ### Scenario B: User Selects August 2025 ``` ┌─────────────────────────────────────────────────────┐ │ Attendance Page │ │ │ │ Filters: [Current Month ▼] [August 2025 ▼] ← User │ └─────────────────────────────────────────────────────┘ │ │ GET /user/:id/leave-info?month=2025-08 ▼ ┌─────────────────────────────────────────────────────┐ │ Backend calculates: │ │ - Target: August 2025 │ │ - Tenure: Jan 15, 2025 → Jan 14, 2026 (Tenure 1) │ │ - Count leaves from Jan 15, 2025 to Jan 14, 2026 │ └─────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────┐ │ Response: │ │ { │ │ leaveYear: 2025, │ │ tenureLabel: "Tenure 1 (Jan 15, 2025 – │ │ Jan 14, 2026)", │ │ isCurrentTenure: false, │ │ paidLeaves: { allocated: 12, used: 13 }, │ │ ... │ │ } │ └─────────────────────────────────────────────────────┘ │ ▼ ┌─────────────────────────────────────────────────────┐ │ ┌─────────────────────────────────────────────────┐│ │ │ Attendance Summary – Tenure 1 ││ │ │ (Jan 15, 2025 – Jan 14, 2026) ││ │ │ ││ │ │ [20] [3] [2] [13/12] [1] ││ │ │ Presents Lates Absents Paid Unpaid ││ │ │ Leaves Leaves ││ │ └─────────────────────────────────────────────────┘│ │ │ │ Calendar showing August 2025 attendance → │ │ (Shows days from entire past tenure) │ └─────────────────────────────────────────────────────┘ ``` ## Technical Implementation ### Before (Broken) ```javascript // Frontend: attendance/page.tsx const { data: leaveInfo } = useQuery({ queryKey: ['leaveInfo', selectedUserId], // ❌ No month dependency queryFn: async () => { const response = await axios.get( `${API_BASE_URL}/user/${selectedUserId}/leave-info`, // ❌ No month param getAuthHeaders() ); return response.data; }, enabled: !!selectedUserId, }); // Backend always returned current tenure, regardless of what was shown on calendar ``` ### After (Fixed) ```javascript // Frontend: attendance/page.tsx const { data: leaveInfo } = useQuery({ queryKey: ['leaveInfo', selectedUserId, dateValue], // ✅ Includes month queryFn: async () => { const monthParam = dateValue ? `?month=${dateValue}` : ''; const response = await axios.get( `${API_BASE_URL}/user/${selectedUserId}/leave-info${monthParam}`, // ✅ Passes month getAuthHeaders() ); return response.data; }, enabled: !!selectedUserId, }); // Backend: leave.controller.js export const getUserLeaveInfo = async (req, res) => { // Derive target date from ?month=yyyy-MM, or use today let targetDate = new Date(); if (req.query.month) { const [y, m] = req.query.month.split('-').map(Number); if (!isNaN(y) && !isNaN(m)) { targetDate = new Date(Date.UTC(y, m - 1, 1)); // ✅ Use selected month } } const { tenureIndex, start, end } = getTenureForDate(joinedOn, targetDate); // ✅ Calculate correct tenure // ... rest of logic }; ``` ## Key Benefits 1. **Consistency**: Summary always matches the calendar view 2. **Historical Accuracy**: Can review past tenure statistics correctly 3. **Automatic**: No manual intervention needed, just change the month filter 4. **All Screens**: Works on attendance, leave request add, and leave detail pages 5. **Backward Compatible**: Still returns `leaveYear` for fallback display