# Features — edi_sage_middleware (TransactFlow Document Sync)

Evidence date: 2026-10-16.

Source: `git@bitbucket.org:overdrive/edi_sage_middleware.git`, `main` at `75823ee` (2026-04-21).

"Current" means present in the maintained tree `BSBC Source Code` and reachable from the running form, unless a row says otherwise. There is no feature flag file.

## Current — invoice export

| Feature | Behaviour | Source |
|---|---|---|
| Date range | From and to date pickers, defaulting to now on startup | `frmMain.vb`, `frmMain.Designer.vb` |
| Process Invoices | Blocks while the invoice list worker is busy | `cmdProcessInvoices_Click` |
| Invoice query | `SO_GETINVOICES` for accounts 5261 and 6960, transaction code `INV`, external order present, not prefixed `CRN` | `SO_GETINVOICES.sql` |
| Detail query | `SO_GETINVOICEDETAILS` for one reference | `SO_GETINVOICEDETAILS.sql` |
| Pipe-delimited CSV | 27 fields, no header row | `frmMain.vb` loop 0–26 |
| Retailer folders | `SHOPRITE` for 5261 (comment: Checkers), `PNP` for 6960 | `frmMain.vb` |
| FTP upload | `FtpWebRequest` upload to `ftp://<host>/<file>` | `FTPFile` |
| Upload retry | `RETRY_UPLOAD\<retailer>\` retried at the start of the next invoice run | `ProcessRetryFiles` |
| Progress and log | Progress bar and colourised timestamped log | `pbProgress`, `Globals.Log` |
| Invoice zip | `Backup\Invoices_Uploaded_<timestamp>.zip`, then delete the zipped files | `CreateZipFile` |
| 90-day zip cleanup | Deletes zips whose name timestamp is older than 90 days | `CleanupOldZipFiles` |
| Invoice email | HTML "TransactFlow Document Processing Report" | `SendProcessingReport` |

## Current — order import

| Feature | Behaviour | Source |
|---|---|---|
| Process Orders | Does not use the invoice dates | `cmdProcessOrders_Click` |
| Order FTP | Separate host, username, and password from the invoice FTP | Settings `OrderFTP*` |
| File filter | Names starting `Order_` and ending `.csv` | `DownloadOrderFiles` |
| Remove from FTP | Delete after a successful download, before Sage insert | `DeleteOrderFileFromFTP` |
| Retry folder first | `ORDERS\Retry\*.csv` processed before new downloads | `ProcessOrderRetryFiles` |
| Pipe parse | Up to 35 fields, grouped by purchase-order number | `ProcessOrderFile` |
| Batch insert | Temp table `#SO_INSERTORDER_LINES` then `dbo.SO_INSERTORDER` | `InsertOrderBatchIntoDatabase`, `SilOve_INSERTORDER.sql` |
| Partial lines | Unresolved barcode, bad quantity, or bad price skipped; the rest of the PO can insert | `SilOve_INSERTORDER.sql` |
| Back order document | `InvNum` DocType 4, DocState 1, order number `SO` + 8 digits | `SilOve_INSERTORDER.sql` |
| Duplicate PO | Result 2, file moved to Processed, not zipped | `IsOrderAlreadyExistsError` |
| GLN miss and truncation | Moved to Processed, not zipped, not retried | `IsNoClientMatchError`, `IsDataTruncatedError` |
| Order zip | `Backup\Orders_Uploaded_<timestamp>.zip`, flat names, sources kept until Processed is cleared | `CreateZipFile` call with `deleteAfterZip:=False` |
| Order email | HTML report with retry failures, new failures, and three skip sections | `SendOrderProcessingReport` |

## Current — settings and distribution

| Feature | Behaviour | Source |
|---|---|---|
| SQL settings | Server, invoice database, order database. Defaults `localhost` and `BSBC_Test` | `cmdSaveSQL_Click`, `Settings.settings` |
| Two FTP accounts | Invoice upload and order download. Passwords stored with DPAPI | `cmdSaveFTP_Click`, `EnhancedSecureSettings.vb` |
| Local folder | Browse saves `XMLPath`. Empty path becomes `C:\Temp\BSBC_Export` | `Button1_Click`, `frmMain_Load` |
| Email settings | SMTP host, port, username, password, from, to, SSL. Test email button | `cmdSaveEmail_Click`, `cmdTestEmail_Click` |
| ClickOnce | Install from `https://overdriveqa.co.za/BSBC_App_Update/`, startup update when network-deployed | `Sage2GS1Xml.vbproj`, `frmMain_Load` |
| Helpdesk label | `021 448 5759` and `helpdesk@overdrive.co.za` | `frmMain.Designer.vb` |

## Current — other trees still in Git

| Feature | Behaviour | Source |
|---|---|---|
| ADE PNP export | Timer every 10 minutes, procedure `SUN_INVOICE_spSel`, files under `c:\xprocure\`, FTP folder `PNPInvoices` | `ADE Source Code/Project/Form1.cs` |
| Older BSBC export | Title "BSBC Invoice Export", procedures `SUN_GETINVOICES` and `SUN_GETINVOICEDETAILS`, 23 CSV fields, FTP test prompt | `BSBC_FTP_Integration/.../frmMain.vb` |

`.gitignore` says these two trees are excluded from ongoing work. They are still tracked. Provenance: **Documented** intent, **Implemented** files.

## Completed

These are in `main` and are what the buttons do today. "Completed" here means the commit landed, not that a person signed off a release.

| Item | Evidence |
|---|---|
| Local invoice copy and 90-day zip | `c728aba` (`#482_BSBC`), `CreateZipFile` |
| Retry upload | `faf0b88` (`#711`), `RETRY_UPLOAD` |
| Error log and email | `4698d78` (`#680_BSBC`), `SendEmail` |
| Startup ClickOnce update | `406acc0`, `frmMain_Load` |
| Orders in | `2092bf0` through `24d196d` |
| Duplicate SO number lock, address copy, unit of measure | `d444c0c`, `SilOve_INSERTORDER.sql` |
| Pack-adjusted `fQuantityUR` and `fQtyChangeUR` | `75823ee` |

## In development

No branch other than `main` was on the remote. No unfinished feature branch is visible. Commented-out and uncalled methods on `main` are listed under the inactive section below. They are not described anywhere as work in progress.

Provenance: **Implemented** as a single-branch repository. A private local branch on a developer PC would not be visible here.

## Planned

No roadmap, issue list, or comment that states a next feature was found.

`ValidateOrderData` and `InsertOrderIntoDatabase` (`SUN_INSERTORDER`) are earlier code paths the current buttons do not call. Calling them a plan would be a guess. Provenance: **Unknown**. They are unused code.

## Recently changed

Relative to `5b9772a` (2026-01-19), which the onboarding issue recorded as the tip:

| Commit | Date | Change that affects behaviour |
|---|---|---|
| `5ecb54a` | 2026-02-12 | Message: OrdersIn stored procedure updates |
| `24d196d` | 2026-03-05 | Order FTP and failure handling, partial orders, order zip, retry, `SO_INSERTORDER` |
| `d444c0c` | 2026-03-16 | Error classification, unit of measure, client address on the document, table lock while allocating `SO########` |
| `f50af70` | 2026-03-17 | Message: version update after publish. ClickOnce revision in the project file is 17 |
| `75823ee` | 2026-04-21 | Line quantities `fQuantityUR` and `fQtyChangeUR` follow the pack-adjusted quantity, and `fQtyChangeUR` is written |

The 2026-04-21 diff only touches `SilOve_INSERTORDER.sql`.

## Deprecated / removed / not on the active path

| Item | Evidence | Status |
|---|---|---|
| GS1 / EAN.UCC SOAP invoice | `SUN_SAGE2XML.sql`, VAT rate 14 in the script, seller GLN `6009900156101` | File present. No call from `frmMain.vb` |
| Per-line `SUN_INSERTORDER` | `InsertOrderIntoDatabase` | Method present. No caller |
| Order field validator | `ValidateOrderData` | Method present. Call commented out |
| Invoice FTP test | `TestFTPConnection` on the maintained form | Method present. No button handler. The older tree still asks before process |
| XML username and password settings | `My.Settings.XMLUsername`, designer fields `edtXMLUsername` / `edtXMLPassword` | Not read or saved by `frmMain.vb` |
| SQL username and password settings | `My.Settings.SQLUsername` / `SQLPassword` | Not saved by the SQL button. Connector ignores the arguments it is given |
| Auto-update settings | `AutoUpdateEnabled`, `UpdateCheckInterval`, `UpdateServerUrl`, `LastUpdateCheck` | Not read. ClickOnce code updates on startup instead |
| `BSBC_FTP_Integration` | `.gitignore` comment, older form | Still tracked |
| ADE exporter | `.gitignore` comment, `Form1.cs` | Still tracked |
| Sonar scanner files | Named in the OVER-102 discovery note | Not in the Git tree at `75823ee` |

## Not features of this repository

- A web portal, API, or login.
- A definition of `SUN_INVOICE_spSel`, `SUN_GETINVOICES`, or `SUN_GETINVOICEDETAILS`.
- Proof that the SQL scripts have been deployed.
- A link, in this repo, to Silicon Ark projects `edi_shopfront` or `sagegs1xml`.

## Feature to requirement map

| Feature | Requirement |
|---|---|
| Process Invoices | FR-001, FR-002, FR-003, FR-004 |
| Retry upload and zip | FR-005, FR-006 |
| Process Orders | FR-001, FR-007, FR-008, FR-009, FR-010, FR-011 |
| Email | FR-012 |
| ClickOnce | FR-013 |
| ADE timer export | FR-014 |
