# `Sp_Sale_ProductInventory_Outdated` (procedure)


- **Type:** PROCEDURE
- **Deterministic:** NO
- **SQL data access:** CONTAINS SQL

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `iType` | `int` |
| 2 | IN | `sBrId` | `varchar(100)` |
| 3 | IN | `sSuId` | `varchar(100)` |
| 4 | IN | `bFilter` | `varchar(5000)` |
| 5 | IN | `sUnTaskFormId` | `varchar(100)` |
| 6 | IN | `pageNum` | `int` |
| 7 | IN | `pageSize` | `int` |
| 8 | OUT | `totalCount` | `int` |
| 9 | IN | `countCloumn` | `varchar(5000)` |
| 10 | OUT | `countMapJson` | `longtext` |
| 11 | IN | `sFilterOrderBy` | `varchar(5000)` |
| 12 | IN | `sGroupby_select_sql` | `varchar(5000)` |
| 13 | IN | `sGroupby_group_sql` | `varchar(5000)` |

## Body

_Body is not pre-cached. To inspect: `mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE PROCEDURE `Sp_Sale_ProductInventory_Outdated`'`._

## Narrative

**Business context:** 销售 / 库存 → 呆滞产品 (stale-inventory) dashboard — paged report of finished goods in `eleproductstock` with positive qty that have not been moved through 成品入库 (`viw_pitproductinstore`) recently, grouped by 呆滞天数 buckets (0-30天 / 30-60天 / 60-90天 / 90-180天 / 180天以上). Drives the sales/inventory team's stale-product review and KPI 呆滞 (obsolete) flagging.

**What it does:** Builds TEMP `TMP_TmpDatedProducts` (clone of `eleproductstock` plus `dLastUseDayBefore` = days since the last 成品入库 of that product on `sFormId='192116810113315228246447250'`). Inserts current stock filtered to `dProductQty>0` and brand/sub. Adds many display columns (product/customer/warehouse names, sales-rep, order/qty/price/money, in-store qty, deliver qty, 呆滞 KPI fields). Populates them via `UPDATE … INNER JOIN eleproduct/elecustomer/siswarehouse/viw_mftworkorder/viw_salsalesorder/sissalesman/viw_pitproductinstore`. Computes `bDeliverComplete` per slave; bins `dLastUseDayBefore` into `Scycle` text. Hands the final SQL to the standard paging helper for `bFilter`, `pageNum/pageSize`, `totalCount`, `countMapJson`, `sFilterOrderBy`, `sGroupby_*`.

**Invocation:** Status: appears orphaned in this DB snapshot. Signature matches the form-master report contract (with extras `iType`, `sUnTaskFormId`); expected to bind to a 呆滞产品 form via `gdsconfigformmaster.sSqlStr`, but no binding exists here. Install + optimize scripts ship in `script/标版/30100101/` and `script/标版/optimize/Sp_Sale_ProductInventory_Outdated.sql`. Candidate for maintainer audit.
