# `Sp_ProductAgingAnalysis` (procedure)

> 产品账龄分析


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

## Parameters

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

## Body

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

## Narrative

**Business context:** 销售管理 / 库存 → 产品账龄分析 — paged report that ages on-hand finished-goods inventory by how long each `eleproduct` × `siswarehouse` lot has been sitting in stock, with the customer/sales-rep affiliation pulled from the originating sales-order chain. The header dates `tStartDate=2024-01-01` and `tEndDate=NOW()` are currently hard-coded — the report ignores user-supplied period bounds.

**What it does:** Builds temp tables `P_Tmp_sFromId`, `P_Tmp_product_List`, `P_Tmp_product_List_Group`, `P_Tmp_product_List_return` by `CALL Sp_Sis_GetProductInventoryFormGuid` to enumerate the relevant inventory-form ids, then aggregates `eleproductstock`, `PitProductStore`, and joins `viw_salsalesorder`, `elecustomer`, `eleproductcustomer`, `eleproduct`, `sislocation`, `siswarehouse`, `SisCurrency`, `SisSalesMan`, `sisproductclassify`. `Fun_GetLookCustomer(sLoginId, sBrId, sSuId)` enforces per-user customer-visibility scope. Final paging and dynamic `bFilter` splicing delegated to the standard outstanding-query helper.

**Invocation:** No form-master, gdsmodule hook, or other-routine caller references the name. Sister variants exist: `Sp_ProductAgingAnalysis_detail` (drill-down), `Sp_ProductAgingAnalysis_new` (rep/order-maker filter overload), `Sp_ProductAgingAnalysis_YM` (month-end snapshot off `eleproductstockmonth`). xly-src ships `script/标版/optimize/Sp_ProductAgingAnalysis.sql` only. The report appears wired through a `gdsconfigformmaster` row whose `sSqlStr` is not on the live `xlyweberp_saas_ai` instance — likely registered only in customer-specific deployments. Audit candidate on stock builds.
