# ngauge-indicator

FTP/SFTP XML order ingestion module for NGauge/Yii2.

## Features

- Pulls XML files from FTP or SFTP servers.
- Stores downloaded files in local runtime spool.
- Converts XML payloads to normalized JSON.
- Imports orders into carts/cartlines.
- Uses a module-local `Cart` model extending `\\backend\\models\\Cartsbe`.
- Runs through two recurring queue jobs:
  - Download job.
  - Process/import job.
- Sends summary emails for each processing run including issues.

## Module Registration

Add module to web + console configs (example):

```php
return [
    'bootstrap' => ['indicator'],
    'modules' => [
        'indicator' => [
            'class' => 'PortalPeople\\indicator\\Module',
        ],
    ],
];
```

## Configuration

Use UI at `/indicator/config/index` or set params manually under `plugins.indicator` in params-local.

Example:

```php
return [
    'plugins' => [
        'indicator' => [
            'enabled' => true,
            'protocol' => 'sftp',
            'host' => 'sftp.example.com',
            'port' => 22,
            'username' => 'import-user',
            'password' => 'secret',
            'remotePath' => '/outbound',
            'deleteAfterDownload' => false,
            'passiveMode' => true,
            'pickupIntervalSeconds' => 900,
            'summaryEmail' => 'ops@example.com',
            'defaultAccountCode' => 'ZUPA001',
        ],
    ],
];
```

## Jobs

The module exposes two recurring queue jobs discovered by `ngauge-queues`:

- `PortalPeople\\indicator\\jobs\\DownloadFilesJob`
- `PortalPeople\\indicator\\jobs\\ProcessFilesJob`

## Console Commands

```bash
php yii indicator/import/download
php yii indicator/import/process
php yii indicator/import/run
```

## Notes

- SFTP requires the PHP `ssh2` extension.
- FTP uses PHP ext-ftp.
- Downloaded files are stored under `@runtime/indicator/inbox`.
- Processed and failed files are moved to `@runtime/indicator/processed` and `@runtime/indicator/failed`.
