Update Hours Calculator with special work: parsing multiple cases. e.g.sp1234, sp 1234, 1234sp, 1234 sp

This commit is contained in:
2026-01-23 11:31:29 -05:00
parent 0fd480daa8
commit fbc1606e7d
2 changed files with 22 additions and 18 deletions
+1 -1
View File
@@ -18,7 +18,7 @@
</div> </div>
<div class="header-actions"> <div class="header-actions">
{% if session.role in ['admin', 'payroll'] %} {% if session.role in ['admin', 'payroll', 'accounting'] %}
<a href="{{ url_for('import_time_attendance') }}" class="btn btn-primary"> <a href="{{ url_for('import_time_attendance') }}" class="btn btn-primary">
<i class="fas fa-upload"></i> <i class="fas fa-upload"></i>
Import Excel Data Import Excel Data
+21 -17
View File
@@ -34,8 +34,14 @@ def parse_employee_id_for_work_type(employee_id: str) -> Tuple[str, str]:
""" """
Parse employee ID to extract base ID and work type (supports SP, PW, PT) Parse employee ID to extract base ID and work type (supports SP, PW, PT)
Handles multiple formats:
- Suffix with space: "1234 SP", "1234 PW", "1234 PT"
- Suffix without space: "1234SP", "1234PW", "1234PT"
- Prefix with space: "SP 1234", "PW 1234", "PT 1234"
- Prefix without space: "SP1234", "PW1234", "PT1234"
Args: Args:
employee_id: Employee ID string (e.g., "1234", "1234 SP", "1234 PW", "1234 PT") employee_id: Employee ID string in any of the above formats
Returns: Returns:
Tuple of (base_employee_id, work_type) Tuple of (base_employee_id, work_type)
@@ -46,23 +52,21 @@ def parse_employee_id_for_work_type(employee_id: str) -> Tuple[str, str]:
employee_id_clean = str(employee_id).strip().upper() employee_id_clean = str(employee_id).strip().upper()
# Check for SP (Special Project) # Define work type codes
sp_pattern = r'^(\d+)\s*SP$' work_type_codes = ['SP', 'PW', 'PT']
sp_match = re.match(sp_pattern, employee_id_clean)
if sp_match:
return sp_match.group(1), 'SP'
# Check for PW (Periodic Work) for work_type in work_type_codes:
pw_pattern = r'^(\d+)\s*PW$' # Pattern 1: Suffix with optional space - "1234 SP" or "1234SP"
pw_match = re.match(pw_pattern, employee_id_clean) suffix_pattern = rf'^(\d+)\s*{work_type}$'
if pw_match: suffix_match = re.match(suffix_pattern, employee_id_clean)
return pw_match.group(1), 'PW' if suffix_match:
return suffix_match.group(1), work_type
# Check for PT (Part-Time)
pt_pattern = r'^(\d+)\s*PT$' # Pattern 2: Prefix with optional space - "SP 1234" or "SP1234"
pt_match = re.match(pt_pattern, employee_id_clean) prefix_pattern = rf'^{work_type}\s*(\d+)$'
if pt_match: prefix_match = re.match(prefix_pattern, employee_id_clean)
return pt_match.group(1), 'PT' if prefix_match:
return prefix_match.group(1), work_type
# Default to regular work # Default to regular work
return employee_id_clean, 'regular' return employee_id_clean, 'regular'