# Project plan — stock_control (RGBC Stock Control)

Evidence date: 2026-10-02.

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

Inspected revision: `master` at `02bce8cb3a549cef413afd459559880bb1e30f2e` (2026-03-16, "reverted back 'allow zero opening stock' and 'always use previous period's closing' changes").

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

There is no prior Silicon Ark folder for this repository. The only Markdown in the source tree is `Stock_Control/Scripts/README.md`.

## Product

The page title and master page heading are **RGBC Stock Control**. The solution and assembly are named **Stock_Control**. The footer on `Admin.Master` reads "Version 2.0.0" and "1 January 2026". `AssemblyInfo.vb` sets `AssemblyVersion` to `1.2.4.0`, `AssemblyFileVersion` to `1.0.0.0`, and copyright "Copyright © 2008".

What the letters RGBC expand to is **Unknown / Requires Confirmation**. No expansion was found in code or in the documents that exist in the tree.

**Inferred** purpose, from the screens and SQL: a monthly stock-planning grid for finished-goods SKUs. Users review opening stock, forecast (QF), brand-manager adjustment (BMA), actual sales, orders, receipts, exports, damages, repack, closing stock, and months of cover. Data is imported from Excel workbooks and a Cognos 14 text file into a SQL Server database. The environment template names that database `Superbowl`.

Provenance: branding is **Implemented** in `Admin.Master` and `AssemblyInfo.vb`. The planning purpose is **Inferred** from `ProductPeriod.aspx`, `Import.aspx.vb`, and `sqlDB.vb`. The database name is **Documented** in `.env.example` as the example catalog, not proven to be the live catalog.

## Branch reality

Default branch is `master`. `origin/HEAD` was not re-checked beyond `git ls-remote` returning `02bce8c` as `HEAD`. Local clone was on `master` tracking `origin/master`. No other remote branches were inspected.

History starts at `1c27535` (2020-01-14, "initial commit") and has 21 commits through `02bce8c`. Long gaps sit between 2021-03-09 and 2024-06-19, and between 2024-06-19 and 2026-01-27.

Recent subjects that change product behaviour:

| Commit | Date | Subject |
|---|---|---|
| `95ff378` | 2026-01-29 | Exclude the comp product brands from all dropdowns |
| `f3a9158` | 2026-01-27 | exclude products marked as Comp Products |
| `d5bf3ba` | 2026-02-04 | exclude comp products from import |
| `9ab3391` / `e96efdd` / `1d856ae` | 2026-02-03 to 2026-02-05 | Security enhancements, env bugfix, styling |
| `d2bf192` | 2026-02-12 | For period month 2, the end of the 12-month range is January of the next year |
| `6550ac6` | 2026-02-26 | Use the previous month's closing as each month's opening |
| `02bce8c` | 2026-03-16 | Reverted the zero-opening and previous-period-closing changes |

`6550ac6` is no longer the behaviour on `master`. See [Current project status](#current-project-status).

## Scope in the repository

In scope of what is present on `master`:

- One ASP.NET Web Forms site, Visual Basic, .NET Framework, solution `Stock_Control.sln` (Visual Studio 15).
- Windows-identity login against `mstUser` for domain `StockControl`.
- Product-period grid (`ProductPeriod.aspx`), including a brand-level 9-litre view, direct-sales row, Excel export, and a confirm action that writes `stkConfirm` or `stkConfirmSM`.
- File import from `Imports\` into `stkProductPeriod` and related tables (`Import.aspx`), plus an import-log screen (`ImportList.aspx`).
- Variance report (`BMAReport.aspx`) and stock-control report (`SCReport.aspx`).
- Brand and user maintenance pages (`BrandList.aspx`, `BrandDetails.aspx`, `UserList.aspx`, `UserDetails.aspx`). They are not linked from the master menu.
- Customer quota-forecast allocation (`RepQF.vb`), triggered by a button on the import list with hard-coded dates.
- Connection string loaded from a `.env` file or the process environment (`SecureConfig.vb`). `.env` is gitignored. `.env.example` is committed.
- One-off SQL scripts under `Stock_Control/Scripts/`.
- Sample spreadsheets and `Imports/cognos14.txt` committed under `Stock_Control/Imports/` and `Stock_Control/Imported/`.

Out of scope of what was found, or present only as comments or dead code:

- A README, changelog, test project, CI pipeline, Docker file, or SonarQube project file inside git. The onboarding issue listed `sonar-project.properties` and `sonarqube_scan.bat` at the scan-host path. Those files are not in this revision. **Unknown** whether they were local scan files.
- Cognos 24 import. The calls are commented out in `Import.aspx.vb`.
- Excel imports named Receipts, Damages, and Repack. The file-name checks are commented out. Those columns still exist on the grid and in the balance formula.
- SMTP or any mail send. The confirm button is named `btnEmail` and does not construct a mail message. A `mailto:` link is rendered for the brand manager address.
- Background workers, queues, or scheduled jobs inside this repository.
- An API surface. Pages are Web Forms postbacks and `SqlDataSource` controls.

## System architecture

```text
Browser
  → IIS or the Visual Studio development server (port 4130 in the project file)
      → ASP.NET Web Forms (VB), master page Admin.Master
          → index.aspx matches Windows logon name to mstUser
          → Pages call sqlDB (ad-hoc SQL, SqlClient)
          → SQL Server
              connection name csStockControl
              example catalog Superbowl (.env.example)

Import.aspx
  → reads Imports\*.xls via Jet OLEDB 4.0, sheet Import$
  → reads Imports\cognos14.txt via Jet text driver
  → writes stkProductPeriod, stgCognos14, stkImportLog, and other tables
  → moves or copies the file into Imported\

RepQF
  → reads dwfSales, stkProductPeriod, mstCustomer, mstPrincipal
  → deletes and reinserts dwfQF for a date range
```

`sqlDB.sql_update_Customer_dw` updates `dwdCustomer` from Superbowl-style master tables (`mstCustomer`, `mstBranch`, `mstRep`, and others). No page in this tree calls that function. Whether another application owns those masters is **Unknown / Requires Confirmation**. The SQL text is evidence that this database is shared with a wider sales model.

## Major components

| Component | Role |
|---|---|
| `index.aspx` | Login. `Default.aspx` redirects here. |
| `Admin.Master` | Menu, user label, version footer. Gate when `blnDebug` is false. |
| `ProductPeriod.aspx` | Home. 15-month grid, save, calculate, confirm, Excel export. |
| `ImportList.aspx` / `Import.aspx` | Import log and file import. |
| `BMAReport.aspx` | Months-cover variance against the brand target. |
| `SCReport.aspx` | Pivot of a chosen `stkProductPeriod` column. |
| `Brand*.aspx`, `User*.aspx` | Brand and user maintenance. Not on the menu. |
| `sqlDB.vb` | SQL strings and a shared `SqlConnection`. |
| `SecureConfig.vb` | Loads `.env` from the solution root. |
| `RepQF.vb` | Allocates SKU forecast to customers. |
| `Scripts/*.sql` | One-off data fixes. The recalc script describes logic that `02bce8c` reverted. |

## Milestones visible in the code

These are comments and commit subjects, not a project plan.

| Label in code or commit | Date | What it records |
|---|---|---|
| Copyright 2008 | `AssemblyInfo.vb` | Assembly copyright year |
| v1.2.6 | `RepQF.vb` | Quota forecast changed from rep to customer |
| v1.2.8a–c | 2009-10-06 | Current-month QF checkbox, pivot export, varietal and category filters |
| v1.2.9 | 2010-06-15 / 2013-01-14 | Brand managers edit BMA from the next month; 9L view prefers opening imports when not zero |
| v1.2.10 | 2016-11-09 | BM Adjustments Excel import |
| v1.3.0 | 2018-01-08 | Zero opening-stock import handling |
| Direct sales | 2021-03-08 | Grid row for documents whose number starts with `Y` |
| v1.3.1 / v1.3.2 | 2026-02, then reverted 2026-03-16 | Previous-period closing chain and zero-opening behaviour. Reverted on `master` |
| UI "Version 2.0.0" | footer date 1 January 2026 | Does not match `AssemblyVersion` 1.2.4.0 |

## Known dependencies

- .NET Framework. The project file targets `v4.6.2`. `Web.config` compilation `targetFramework` is `4.8`. Which runtime is installed on the host is **Unknown**.
- SQL Server, database name illustrated as `Superbowl`, connection string `STOCK_CONTROL_CONNECTION_STRING`.
- Microsoft Jet OLEDB 4.0 for `.xls` and delimited text. Jet is 32-bit. Whether the app pool is 32-bit is **Unknown**.
- Windows authentication (`Web.config` `authentication mode="Windows"`).
- IIS or the legacy Visual Studio development server. `UseIIS` is false. Development server port is 4130.
- Active Directory, only as the source of `Request.LogonUserIdentity.Name`. The failure text says login is controlled through Active Directory. No directory API calls were found.
- Shared tables with a sales warehouse (`dwfSales`, `mstProduct`, `mstCustomer`, `mstPrincipal`). Owning application is **Unknown**. A separate Silicon Ark folder `superbowl` exists. It does not mention this repository.

## Implementation plan

No roadmap, issue tracker, or milestone document is in the repository. The implementation plan is **Unknown / Requires Confirmation**.

What the tree shows as the current maintenance pattern:

- Behaviour changes land as small commits on `master`.
- One-off SQL under `Stock_Control/Scripts/` is documented as manual SSMS execution, with a backup warning in `Scripts/README.md`.
- Secrets stay out of `Web.config` and are read from `.env` at runtime (`1d856ae` and related commits).

## Current project status

**Implemented and current on `master`:** the Web Forms site described above, with comp products excluded from dropdowns and from import, connection strings loaded from the environment, and opening-balance recalculation in `Import.updatePPBalance` using the pre-v1.3.1 in-memory chain (first row of a product uses `dblOpening`; later rows use the closing just computed; `dblOpeningImports` replaces opening only when it is greater than zero).

**Conflict inside the repo, requires confirmation:**

- Commit `02bce8c` says the zero-opening and previous-period-closing changes were reverted.
- The comment at the top of `Import.aspx.vb` says the revert restores logic "so opening import (including zeros) sticks".
- The code copies `dblOpeningImports` onto opening only when the value is greater than zero. A later period in the same product then takes the previous row's computed closing, which discards an imported zero.
- `Scripts/Recalc_stkProductPeriod_OpeningClosing.sql` and `Scripts/README.md` still describe the v1.3.2 previous-period-closing rules and say to run the script after deploying v1.3.2.
- `Scripts/Set_Zero_Opening_Feb2026.sql` says v1.3.2 will overwrite forced zeros if import runs again.

The code in `updatePPBalance` is the implemented behaviour. The script headers describe the reverted behaviour. Which one operations should follow is **Requires Confirmation**.

**Not established:** production URL, IIS site name, who operates imports, whether `UserList.aspx` and `BrandList.aspx` are still used, whether the QF button is still used, and whether the committed spreadsheets under `Imports/` and `Imported/` are safe to keep in git.
