# Project plan — PernodIntegration

Evidence date: 2026-10-07.

Source repository: `git@bitbucket.org:overdrive/pernodintegration.git`.

This plan describes what the repository contains. It does not decide what the product should become.

## Product

PernodIntegration is a VB.NET console program that reads staff orders from the SQL Server database `PSOrder` and posts eligible orders to the JD Edwards orchestrator `COR55ZA0012_AddEmployeeSales`.

The in-repo guide `docs/integration-flow.md` calls it a console / Azure WebJob (`OnDemand`) for staff-portal orders. The project file is a .NET Framework 4.7.2 console executable (`OutputType` Exe, `MyType` Console). No WebJob manifest, `settings.job`, or scheduler is in the repository. Whether it is deployed as an Azure WebJob is **Unknown / Requires Confirmation**.

Checkout and the cart-time 12-bottle cap are stated to live in the staff portal, not in this job. That portal is the separate `pernodstaff` repository, which writes `ORDER_HEADER` / `ORDER_DETAIL` in `PSOrder` and refers to this component by name. Provenance: **Documented** in `docs/integration-flow.md`, and **Documented** in Silicon Ark `pernodstaff` (not re-verified against the `pernodstaff` source in this pass).

## Branch reality

Default branch is `main`. `origin/HEAD` points at `main`.

| Line | Tip | Date | What it is |
|---|---|---|---|
| `main` | `ecbc272` | 2026-08-27 | "Merged in josh_work (pull request #2)". 12 commits from `fb583ef` (2025-03-24, "Initial commit") |
| `josh_work` | `054f39a` | 2026-08-26 | "improve tests". This tip is already contained in `main`. The branch is still on the remote. The only commits on `main` that are not on `josh_work` are the two merge commits. |

Full tip recorded for this set: `ecbc2723821a61f5660b08ad7d935b9615fcca66`.

The onboarding scan that created this task recorded tip `016f90f` (2025-06-20, "sonar-project.properties created online with Bitbucket") and a top-level `sonarqube_scan.bat`. That commit is an ancestor of `main`, not the tip. `sonarqube_scan.bat` is not a tracked file at `ecbc272`. Later work on `main` adds `ERROR_LOG` writes, prior-month expiry, the failed-order bottle cap, and the MSTest project (August 2026).

Which environment is deployed, and whether production matches `ecbc272`, is **Unknown / Requires Confirmation**.

## Scope in the repository

In scope of what is implemented on `main`:

- A console executable that obtains an Azure AD access token, then a JD Edwards AIS token, then posts each remaining status-`99` order.
- Prior-calendar-month expiry of unresolved orders to status `22`.
- A current-month rule that cancels the oldest failed orders to status `22` when counted bottles plus failed bottles would exceed 12.
- Inserts into `ERROR_LOG` for token, expiry, overflow, and order-post failures, with secret redaction.
- An MSTest project (`PernodIntegration.Tests`) that runs the send path against SQL Server LocalDB and a stub HTTP handler.
- In-repo flow and test notes: `docs/integration-flow.md`, `docs/tests.md`, `docs/create_test_schema.sql`.
- Bitbucket Pipelines running a SonarQube scan on `main` and on pull requests. The pipeline does not build the solution or run the tests.

Out of scope of the code that was found, or not present as a committed application:

- The staff portal that creates the orders (repository `pernodstaff`).
- A scheduler, Windows service, or Azure WebJob definition.
- A production publish profile, infrastructure template, or secret store. Connection details and credentials are committed in `App.config` and `web.config`.
- Parsing of the JDE JSON response beyond HTTP status.

## System architecture

```text
Operator starts PernodIntegration.exe
  → Module1.Main
      → Azure AD token (login.microsoftonline.com, client id / secret / scope / grant type)
      → JDE AIS token (api host in config, subscription key, JDE user)
      → SQL Server database PSOrder
          ORDER_HEADER, ORDER_DETAIL, ERROR_LOG
      → POST orchestrator COR55ZA0012_AddEmployeeSales
          OAuth bearer on Authorization
          AIS token inside the JSON body
      → UPDATE ORDER_HEADER status 20 or 22
      → INSERT ERROR_LOG
  → Console.WriteLine("Done")
  → Console.ReadLine()  (process waits for input)
```

The committed order URL host is `api-staging.pernod-ricard.io`. Provenance: **Implemented** in `PernodIntegration/App.config`. Whether production uses a different host is **Unknown / Requires Confirmation**.

## Major components

| Component | Path | Role |
|---|---|---|
| Entry point | `PernodIntegration/Module1.vb` | Token fetch, expiry, overflow cancel, order send, error log |
| Order payload | `PernodIntegration/OrderClass.vb` | JSON field names for the orchestrator body |
| AIS token model | `PernodIntegration/TokenClass.vb` | Deserialises `userInfo.token` |
| App config | `PernodIntegration/App.config` | Runtime settings copied to the exe config. Also contains live credentials |
| `web.config` | `PernodIntegration/web.config` | Same app settings as `App.config`. Not included in the vbproj |
| Tests | `PernodIntegration.Tests/` | LocalDB plus `StubJdeHandler` |
| Flow notes | `docs/integration-flow.md` | Status meanings and sequence diagrams |
| Pipeline | `bitbucket-pipelines.yml` | SonarQube only |
| Sonar | `sonar-project.properties` | Project key only |

## Milestones visible in git

| Date | Commit | What changed |
|---|---|---|
| 2025-03-24 | `fb583ef` | Initial commit (Abdurahmaan Ismail) |
| 2025-03-24 | `76e51e7` | Initial code commit (maanie), including the Newtonsoft.Json package tree |
| 2025-04-02 | `6759642` | "Updated code to use new JDE API implementation". The previous request shape was not reconstructed for this document |
| 2025-05-08 | `2bc7054` | "Updated input parameter format" (`Module1.vb`, `OrderClass.vb`) |
| 2025-06-20 | `af08731`, `016f90f` | Bitbucket Pipelines file and Sonar project key added from Bitbucket |
| 2026-08-21 | `7cab054`, merge `3563e40` | Error logging into `ERROR_LOG` |
| 2026-08-26 | `980e107`, `8a1fdf9`, `054f39a` | `orderid` on error rows, expiry, overflow cap, test project, flow docs |
| 2026-08-27 | `ecbc272` | Merge of `josh_work` pull request #2 |

Assembly metadata still says copyright 2022 and version `1.0.0.0` (`AssemblyInfo.vb`). That year is earlier than the first commit. Provenance: **Implemented** attributes. What the 2022 date refers to is **Unknown**.

## Known dependencies

- .NET Framework 4.7.2.
- Newtonsoft.Json 13.0.1, committed under `packages/Newtonsoft.Json.13.0.1/`.
- SQL Server database `PSOrder` for a real run. The committed connection string names a developer SQL Express instance. The test run uses LocalDB database `PernodIntegrationTests`.
- Microsoft identity platform (Azure AD) client-credentials token.
- Pernod Ricard API host for the JDE token request and the orchestrator, with an `Ocp-Apim-Subscription-Key` header.
- Visual Studio / MSBuild and `vstest.console` to build and run tests, as written in `docs/tests.md`. The solution file says Visual Studio Version 16. The `.vs` folder contains both v16 and v17 user files.
- Bitbucket Pipelines SonarQube pipe `sonarsource/sonarqube-scan:3.0.2`, using repository variables `SONAR_HOST_URL` and `SONAR_TOKEN`.

## Current project status

`main` at `ecbc272` contains a working send path, expiry, overflow cancellation, error logging, and nine MSTest methods. The pipeline analyses code with SonarQube and does not execute those tests.

No open milestone list, issue tracker, or roadmap file is in the repository. Nothing in the tree describes planned work.

## Human confirmation

- Is the deployed host an Azure WebJob, a scheduled task, or a manual console run? `Main` ends with `Console.ReadLine()`, which waits before exit.
- Are the committed staging API host and the developer SQL Express connection string what any environment still uses? Credentials are stored in git (`App.config`, `web.config`, and `PernodIntegration/bin/Debug/PernodIntegration.exe.config`). They should be rotated and removed from the repository. Values are intentionally not copied into this document.
- `OAuthScope` and `OAuthGrantType` are read by code and set in the test config (`client_credentials`). They are absent from `App.config` and `web.config`.
- The staff-portal month count documented for `pernodstaff` skips only status `99` rows whose `ERROR_LOG` is component `PernodIntegration` and operation `CreateOrder`. This job treats any `ERROR_LOG` row for the order as a failure, and it excludes status `22` from its own bottle sum. The portal notes do not say status `22` is excluded. If both descriptions are current, cancelling a failed order to `22` can change whether those bottles still count on the portal.
- Production `PSOrder` has more columns than the test script. The live column types and the full status list are not in this repository.
- `sonarqube_scan.bat` was listed by the onboarding scan and is not in git at `ecbc272`.
