# Factur-X Order System

A PHP generic order recording system with Factur-X compliant invoice generation.

## Features

- **Order Recording**: Secure order management with per-customer database isolation
- **Factur-X Compliance**: Generate invoices compliant with French Factur-X standard
- **Admin Panel**: Customer interface for order tracking and invoice management
- **Security**: Validated orders are immutable and cannot be edited or deleted
- **Multi-tenant**: Configurable system for per-customer deployment

## Architecture

```
factur-x/
├── src/                    # Core library
│   ├── OrderManager.php   # Main order handling
│   ├── InvoiceGenerator.php # Factur-X invoice generation
│   ├── Database.php        # Database abstraction
│   └── Config.php         # Configuration management
├── admin/                 # Admin panel
│   ├── index.php         # Dashboard
│   ├── orders.php        # Order management
│   └── invoices.php      # Invoice management
├── config/               # Configuration templates
│   └── config.example.php
├── sql/                  # Database schemas
│   └── schema.sql
└── examples/            # Usage examples
```

## Installation

```bash
composer install
```

## Configuration

Copy `config/config.example.php` to your customer's directory and customize:

```php
return [
    'database' => [
        'host' => 'localhost',
        'name' => 'customer_orders',
        'user' => 'customer_user',
        'password' => 'secure_password'
    ],
    'company' => [
        'name' => 'Your Company',
        'address' => 'Your Address',
        'siret' => '12345678901234'
    ]
];
```

## Usage

```php
require 'vendor/autoload.php';

use FacturX\OrderManager;

$config = include 'config/config.php';
$orderManager = new OrderManager($config);

// Create an order
$orderId = $orderManager->createOrder([
    'customer_name' => 'John Doe',
    'customer_email' => 'john@example.com',
    'items' => [
        ['name' => 'Product 1', 'quantity' => 2, 'price' => 29.99],
        ['name' => 'Product 2', 'quantity' => 1, 'price' => 49.99]
    ]
]);

// Validate and lock order
$orderManager->validateOrder($orderId);

// Generate Factur-X invoice
$invoice = $orderManager->generateInvoice($orderId);
```

## Security Features

- Per-customer database isolation
- Immutable validated orders
- Secure configuration management
- Input validation and sanitization

## License

MIT License
