# Web Frontend (Ordering Platform)

PHP/CodeIgniter 4 web application serving as the customer-facing ordering platform. Handles product browsing, ordering, user authentication, payments, and document signing.

## Tech Stack

- PHP 8.3+
- CodeIgniter 4.6
- MySQL
- DomPDF (PDF generation)
- DocuSign (e-signatures)
- Opayo (payment gateway)
- PHPMailer (email)
- JWT Authentication

## Prerequisites

- PHP 8.3 or higher with extensions: intl, mbstring, json, mysqlnd, libcurl
- MySQL 5.7+
- Composer

## Getting Started

1. Install dependencies:
   ```bash
   composer install
   ```

2. Copy `env` to `.env` and configure:
   ```
   CI_ENVIRONMENT = development

   app.baseURL = 'http://localhost:8087/'
   app.uploads_baseurl = http://localhost:8001/uploads

   database.default.hostname = localhost
   database.default.database = orderuk
   database.default.username = root
   database.default.password =
   database.default.DBDriver = MySQLi
   database.default.port = 3306
   ```

3. Start the development server:
   ```bash
   php spark serve --host 0.0.0.0 --port 8087
   ```
   The app runs at `http://localhost:8087`.

## Environment Variables

In addition to the basic configuration above, the following are needed for full functionality:

```
# Opayo Payment Gateway
opayo.form_registration_url = https://sandbox.opayo.eu.elavon.com/gateway/service/vspform-register.vsp
opayo.vendorName = uniteduk
opayo.integrationKey = <your-key>
opayo.integrationPasswd = <your-password>
opayo.encryptionPassword = <your-encryption-key>

# DocuSign
DOCUSIGN_INTEGRATION_KEY = <your-key>
DOCUSIGN_USER_ID = <your-user-id>
DOCUSIGN_ACCOUNT_ID = <your-account-id>
DOCUSIGN_ENVIRONMENT = sandbox

# Google reCAPTCHA v2
RECAPTCHA_SITE_KEY = <your-site-key>
RECAPTCHA_SECRET_KEY = <your-secret-key>
```

## Project Structure

```
app/
  Controllers/    # Page controllers (Home, Customer, Employees, etc.)
  Models/         # Database models (Cms, Employee, Product, etc.)
  Views/          # HTML/PHP view templates
  Config/         # Configuration files
  Filters/        # Request filters (BranchFilter, Auth)
  Services/       # Business logic services
  Database/       # Migrations and seeds
public/
  index.php       # Application entry point
  .htaccess       # Apache URL rewriting
  assets/         # Public assets
  css/            # Stylesheets
  js/             # JavaScript files
  images/         # Image files
writable/
  logs/           # Application logs
  cache/          # Cache storage
  session/        # Session data
  docusign/       # DocuSign documents
  keys/           # Encryption keys
```

## Deployment

- Point web server document root to the `public/` directory
- Ensure `writable/` directory has write permissions
- Configure `.env` with production database and service credentials
- Set `CI_ENVIRONMENT = production`
