#!/usr/bin/env python3
"""
Create LFCS Timesheet for Week 12 (March 16-21, 2026)
Michael McLoughlin - Dockett 0792 & 0793
"""

import openpyxl
from openpyxl.styles import Font, Alignment, Border, Side
from datetime import datetime

def create_week12_timesheet():
    wb = openpyxl.Workbook()
    ws = wb.active
    ws.title = "Timesheet"
    
    # Week 12 hours - exactly as Michael provided
    week_data = [
        {'day': 'Mon', 'date': '16/3', 'start': '7:00', 'finish': '5:30', 'break': '30min', 'hours': 10},
        {'day': 'Tue', 'date': '17/3', 'start': '7:00', 'finish': '5:30', 'break': '30min', 'hours': 10},
        {'day': 'Wed', 'date': '18/3', 'start': '7:00', 'finish': '5:30', 'break': '30min', 'hours': 10},
        {'day': 'Thur', 'date': '19/3', 'start': '7:00', 'finish': '3:30', 'break': '30min', 'hours': 8},
        {'day': 'Fri', 'date': '20/3', 'start': '7:00', 'finish': '3:30', 'break': '30min', 'hours': 8},
        {'day': 'Sat', 'date': '21/3', 'start': '7:00', 'finish': '3:00', 'break': '—', 'hours': 8},
    ]
    
    total_hours = sum(d['hours'] for d in week_data)
    
    # Styles
    header_font = Font(bold=True, size=16)
    subtitle_font = Font(size=10)
    label_font = Font(bold=True)
    border_thin = Border(
        left=Side(style='thin'),
        right=Side(style='thin'),
        top=Side(style='thin'),
        bottom=Side(style='thin')
    )
    
    # ===== HEADER =====
    ws.merge_cells('A1:H1')
    ws['A1'] = "  LF CONSTRUCTION SERVICES TIMESHEET"
    ws['A1'].font = header_font
    ws['A1'].alignment = Alignment(horizontal='center')
    
    # Licence info
    ws['A3'] = "Licence No  292303c"
    ws['A4'] = "accounts@lfcs.com.au"
    ws['A5'] = "admin@lfcs.com.au"
    ws['A5'].font = subtitle_font
    
    # ===== EMPLOYEE INFO =====
    ws['A7'] = "Name:"
    ws['A7'].font = label_font
    ws.merge_cells('B7:D7')
    ws['B7'] = "Michael McLoughlin"
    
    ws['A8'] = "Dates:"
    ws['A8'].font = label_font
    ws.merge_cells('B8:D8')
    ws['B8'] = "Week 12 (March 16-21, 2026)"
    
    ws['A9'] = "Docket:"
    ws['A9'].font = label_font
    ws.merge_cells('B9:D9')
    ws['B9'] = "0792 & 0793"
    
    # ===== TABLE HEADERS =====
    headers = [
        ('A10', 'Day'),
        ('B10', 'Date'),
        ('C10', 'Start Time'),
        ('D10', 'Finish Time'),
        ('E10', 'Lunch Duration'),
        ('F10', 'Total Hours Worked'),
        ('G10', 'Client / Project Name & Address'),
        ('J10', 'Work Description')
    ]
    
    for cell_ref, text in headers:
        ws[cell_ref] = text
        ws[cell_ref].font = label_font
        ws[cell_ref].border = border_thin
        ws[cell_ref].alignment = Alignment(horizontal='center', wrap_text=True)
    
    ws.merge_cells('G10:I10')  # Client/Project column
    ws.merge_cells('J10:L10')  # Work Description column
    
    # ===== DAY ROWS =====
    row = 12
    for day_data in week_data:
        ws[f'A{row}'] = day_data['day']
        ws[f'A{row}'].border = border_thin
        
        ws[f'B{row}'] = day_data['date']
        ws[f'B{row}'].border = border_thin
        
        ws[f'C{row}'] = day_data['start']
        ws[f'C{row}'].border = border_thin
        
        ws[f'D{row}'] = day_data['finish']
        ws[f'D{row}'].border = border_thin
        
        ws[f'E{row}'] = day_data['break']
        ws[f'E{row}'].border = border_thin
        
        ws[f'F{row}'] = day_data['hours']
        ws[f'F{row}'].border = border_thin
        
        ws[f'G{row}'] = "LF Construction Services - Powerhouse Museum Parramatta"
        ws.merge_cells(f'G{row}:I{row}')
        ws[f'G{row}'].border = border_thin
        
        ws[f'J{row}'] = "General Foreman - Steelfixing/Formwork/Concrete"
        ws.merge_cells(f'J{row}:L{row}')
        ws[f'J{row}'].border = border_thin
        
        row += 1
    
    # Empty Sunday row
    ws[f'A{row}'] = "Sun"
    ws[f'A{row}'].border = border_thin
    for col in ['B', 'C', 'D', 'E', 'F', 'G', 'J']:
        ws[f'{col}{row}'].border = border_thin
    ws.merge_cells(f'G{row}:I{row}')
    ws.merge_cells(f'J{row}:L{row}')
    
    # ===== TOTAL ROW =====
    total_row = row + 2
    ws[f'A{total_row}'] = "Total Hours Worked"
    ws[f'A{total_row}'].font = label_font
    ws[f'F{total_row}'] = total_hours
    ws[f'F{total_row}'].font = Font(bold=True)
    ws[f'F{total_row}'].border = border_thin
    
    # ===== FROM/TO SECTIONS =====
    ws[f'A{total_row+2}'] = "From:"
    ws[f'A{total_row+2}'].font = label_font
    ws[f'B{total_row+2}'] = "Michael McLoughlin"
    
    ws[f'A{total_row+3}'] = "Client / Project Name & Address:"
    ws[f'A{total_row+3}'].font = label_font
    ws.merge_cells(f'B{total_row+3}:L{total_row+3}')
    ws[f'B{total_row+3}'] = "LF Construction Services - Powerhouse Museum Parramatta, 69 Phillip St"
    
    ws[f'A{total_row+4}'] = "To:"
    ws[f'A{total_row+4}'].font = label_font
    ws[f'B{total_row+4}'] = "Joel @ LFCS Office"
    
    # ===== SIGNATURE AREA =====
    ws[f'E{total_row+6}'] = "Signature:"
    ws[f'E{total_row+6}'].font = label_font
    ws.merge_cells(f'F{total_row+6}:H{total_row+6}')
    
    ws[f'E{total_row+7}'] = "Date:"
    ws[f'E{total_row+7}'].font = label_font
    ws[f'F{total_row+7}'] = datetime.now().strftime('%d/%m/%Y')
    
    ws[f'E{total_row+9}'] = "Approval Signature:"
    ws[f'E{total_row+9}'].font = label_font
    ws.merge_cells(f'F{total_row+9}:H{total_row+9}')
    
    # ===== INSTRUCTIONS =====
    ws.merge_cells('G4:L8')
    ws['G4'] = "Please provide the Client / Project Name & Address and the Work Description you completed for that Client"
    ws['G4'].font = Font(italic=True, size=9)
    ws['G4'].alignment = Alignment(wrap_text=True, vertical='top')
    
    # ===== COLUMN WIDTHS =====
    column_widths = {
        'A': 8, 'B': 12, 'C': 10, 'D': 10, 'E': 12, 'F': 12,
        'G': 20, 'H': 5, 'I': 5, 'J': 20, 'K': 5, 'L': 5
    }
    for col, width in column_widths.items():
        ws.column_dimensions[col].width = width
    
    # ===== SAVE =====
    output_path = "/home/ccuser/rateright-growth/rivet/timesheet-Michael-W12-16Mar-21Mar-LFCS.xlsx"
    wb.save(output_path)
    
    print(f"✅ Created Week 12 timesheet: {output_path}")
    print(f"📊 Total hours: {total_hours}")
    print(f"📋 Dockets: 0792 & 0793")
    
    return output_path

if __name__ == "__main__":
    create_week12_timesheet()