# Templates folder — `Multi_Empresa/templates/`

This folder holds the **clean base versions** of every system that can be
sold from the "New System Client" panel.

For each catalog entry, you need a folder + an `install.sql` inside.

## Required structure

```
templates/
├── _README.md                          ← this file
├── Trucking-base/                      ← clean Trucking files (no client data)
│   ├── BackEnd/  ...
│   ├── FrontEnd/ ...
│   ├── Includes/ ...
│   └── install.sql                     ← Empty schema only (no INSERT)
├── Daycare-base/
│   ├── ...
│   └── install.sql
├── Produce-base/
│   ├── ...
│   └── install.sql
├── OfficeAdmin-base/                   ← (TaxServices system, sold as "Office Admin")
│   ├── ...
│   └── install.sql
└── GeneralSales-base/                  ← (Genesys Construction, sold as "General Sales")
    ├── ...
    └── install.sql
```

## How to generate `install.sql` for each system

The install file must contain ONLY the structure (CREATE TABLE), NO data.
Generate it from a working copy of each system database:

```bash
# Trucking
mysqldump --no-data --skip-comments --skip-add-drop-table \
  trucking_db > Trucking-base/install.sql

# Daycare
mysqldump --no-data --skip-comments --skip-add-drop-table \
  daycare_db > Daycare-base/install.sql

# Produce
mysqldump --no-data --skip-comments --skip-add-drop-table \
  jv_produce_db > Produce-base/install.sql

# Office Admin (TaxServices)
mysqldump --no-data --skip-comments --skip-add-drop-table \
  griceldatax_db > OfficeAdmin-base/install.sql

# General Sales (Genesys Construction)
mysqldump --no-data --skip-comments --skip-add-drop-table \
  general_sales > GeneralSales-base/install.sql
```

## How to generate the base folder for each system

Copy the latest **clean** version of the system files (without any client
specific data — no logo, no receipts, no sample records). The provisioning
engine will:

1. Copy this folder verbatim into `<parent>/<NewClientFolder>/`
2. Skip `install.sql` (it's only for DB load)
3. Patch the `define('DB_NAME', '...')` line in the system's config file

**The system's config file path** is hard-coded in `ProvisioningEngine.php`
under each profile (`config_file` key):

| System         | Config file (relative)          |
|----------------|---------------------------------|
| Trucking       | `Includes/DbConnect.php`        |
| Daycare        | `Include/IncDb.php`             |
| Produce        | `Includes/IncDatabase.php`      |
| Office Admin   | `Includes/config.php`           |
| General Sales  | `Main_Php/Bkeconfig.php`        |

Make sure the base folder you upload contains a config file at exactly that
path with a `define('DB_NAME', '...')` line — that's all the engine needs.

## Adding a new system to the catalog

Edit `core/ProvisioningEngine.php`, add a new entry to `self::$CATALOG`:

```php
'NewKey' => [
    'display_name'    => 'My New System',
    'description'     => '...',
    'icon'            => '🆕',
    'color'           => '#7C4DFF',
    'price_suggested' => 999,
    'template_folder' => 'NewKey-base',
    'sql_file'        => 'install.sql',
    'config_file'     => 'path/to/config.php',
    'company_table'   => 'company',
    'company_map'     => [
        'cname' => 'company_name',  // DB column => form field
        ...
    ],
    'users_table'     => 'users',
    'users_create'    => 'createNewKeyUser',  // method to add to engine
    'extras'          => ['ai_config', 'email_config'],
],
```

Then create the `templates/NewKey-base/` folder with the system's clean
files and `install.sql`, and add the matching `createNewKeyUser` method
in the engine.
