File size: 2,169 Bytes
2fef75a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# modules/pdf_generator.py - PDF generation functions
import io
from reportlab.lib.pagesizes import A4
from reportlab.platypus import SimpleDocTemplate, Paragraph, Spacer, Table, TableStyle
from reportlab.lib.styles import getSampleStyleSheet, ParagraphStyle
from reportlab.lib.units import inch
from reportlab.lib import colors
from reportlab.lib.enums import TA_CENTER

def generate_basic_report(student_data, term_data, marks, design):
    """Generate basic PDF report"""
    buffer = io.BytesIO()
    doc = SimpleDocTemplate(buffer, pagesize=A4)
    story = []
    styles = getSampleStyleSheet()
    
    # Title
    title_style = ParagraphStyle(
        'CustomTitle',
        parent=styles['Heading1'],
        fontSize=14,
        textColor=colors.black,
        alignment=TA_CENTER
    )
    
    story.append(Paragraph(f"<b>{design.school_name}</b>", title_style))
    story.append(Paragraph(f"END OF TERM {term_data['term_number']} REPORT", title_style))
    story.append(Spacer(1, 0.2*inch))
    
    # Student info
    student_info = [
        ['NAME:', student_data['name'], 'CLASS:', student_data['class_name']],
        ['REG NO:', student_data['registration_number'], 'TERM:', term_data['term_name']]
    ]
    
    student_table = Table(student_info, colWidths=[1*inch, 2*inch, 1*inch, 2*inch])
    student_table.setStyle(TableStyle([
        ('FONTNAME', (0,0), (0,-1), 'Helvetica-Bold'),
        ('FONTNAME', (2,0), (2,-1), 'Helvetica-Bold'),
        ('GRID', (0,0), (-1,-1), 1, colors.black),
    ]))
    
    story.append(student_table)
    story.append(Spacer(1, 0.2*inch))
    
    # Results table
    results_data = [['SUBJECT', 'SCORE', 'GRADE']]
    for _, row in marks.iterrows():
        results_data.append([row['subject'], f"{row['total']:.0f}", row['grade']])
    
    results_table = Table(results_data, colWidths=[2*inch, 1*inch, 1*inch])
    results_table.setStyle(TableStyle([
        ('BACKGROUND', (0,0), (-1,0), colors.grey),
        ('FONTNAME', (0,0), (-1,0), 'Helvetica-Bold'),
        ('GRID', (0,0), (-1,-1), 1, colors.black),
    ]))
    
    story.append(results_table)
    
    doc.build(story)
    return buffer.getvalue()