# Super Admin Result Creation (Auto-Approve + Auto-Generate PDFs)

## What This Adds

A new **Create Result [AUTO]** menu in Super Admin panel that lets Super Admin create
student + result + payment in ONE single-page form. On submit:
- Status is set to **'generated'** (auto-approved — NO approval workflow)
- BOTH PDFs (certificate + marksheet) are generated immediately via Pattern System
- Institute shown: **GMIND INSTITUTE SULTANPUR** (hardcoded)
- Branch Code shown: **GMBR01** (hardcoded)

## Files in this ZIP

```
gmind/
├── routes/
│   └── super-admin.php                          (UPDATE — added 4 new routes)
└── super-admin/
    ├── Controllers/
    │   └── SuperAdminCertGenController.php      (NEW — 850+ lines)
    └── Views/
        ├── layout.php                            (UPDATE — added sidebar menu)
        └── cert_gen/
            ├── create.php                        (NEW — single-page form)
            └── index.php                        (NEW — results list)
```

## How to Deploy

1. Extract this ZIP on your server. The folder structure matches your existing
   `/gmind/` installation, so you can either:
   - Extract directly into your web root (merging with existing files), OR
   - Extract locally and upload individual files via FTP/cPanel

2. **Files to upload** (5 total):

   **NEW files (3):**
   - `/gmind/super-admin/Controllers/SuperAdminCertGenController.php`
   - `/gmind/super-admin/Views/cert_gen/create.php`
   - `/gmind/super-admin/Views/cert_gen/index.php`

   **UPDATE files (2):**
   - `/gmind/routes/super-admin.php`
   - `/gmind/super-admin/Views/layout.php`

## How to Use

1. Login to Super Admin panel
2. Click new sidebar menu: **Create Result [AUTO]** (green AUTO badge)
3. Click **"Create New Result"** button
4. Fill the single-page form:
   - **Student Details**: Name, Father, Mother, DOB, Email, Mobile, Address
   - **Course & Session**: Select course (subjects auto-load), pick completion month
   - **Subjects & Marks**: Enter obtained marks (auto-caps at max, live % calculation)
   - **Payment Details**: Mode, amount, txn ID (for record only — no wallet deduction)
5. Click **"Submit & Auto-Generate PDFs"**
6. Both PDFs are generated instantly — View/Download from the list page

## New Routes

| Method | URL | Action |
|--------|-----|--------|
| GET  | `/super-admin/cert-gen`              | List all super-admin-generated results |
| GET  | `/super-admin/cert-gen/new`          | Show create form |
| POST | `/super-admin/cert-gen/store`        | Save + auto-approve + generate PDFs |
| GET  | `/super-admin/cert-gen/download/{id}`| View/Download a generated PDF |

## Prerequisites

The selected course MUST have:
1. **Certificate template** + **Marksheet template** mapped (via Old Mapping page)
2. **Pattern assigned** (via Assign to Courses page) — must be a LOCKED pattern
3. Pattern must have background images uploaded for BOTH certificate and marksheet

If any of these are missing, the certificate record is still created with status='generated',
but the PDF will not be generated (error logged). You can verify by checking the certificate
timeline entries.

## Key Constants (in SuperAdminCertGenController.php)

```php
private const DEFAULT_INSTITUTE_NAME = 'GMIND INSTITUTE SULTANPUR';
private const DEFAULT_BRANCH_CODE    = 'GMBR01';
```

These appear in the PDF wherever the `branch_name` and `branch_code` pattern fields are placed.

## Notes

- branch_id is set to 0 (no branch association) — these records are filtered separately
  from branch-submitted certificates in the Super Admin Documents list.
- No wallet deduction occurs (this is super admin direct creation, not branch flow).
- Audit log entry `sa_student_created` is written for traceability.
- Timeline entries: `approved` (auto) + `pdf_generated` are written to certificate_timeline table.
