# `Sp_System_ProductionCostTest` (procedure)

> @author:杨恒林
							@date:20210523 封存
							@describe: 从成本月结表中，拿到工单数据，计算本月成本数据后回写到成本月结表	注意点：
							1.本期期初成本从本工单最近一次月结成本表中获取，不一定就是上期
							2.在制品是指所有入库数小于工单数的工单


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sProInParam` | `varchar(10000)` |
| 2 | IN | `iSecond` | `int` |
| 3 | IN | `sMakePerson` | `varchar(100)` |
| 4 | IN | `sBrId` | `varchar(100)` |
| 5 | IN | `sSuId` | `varchar(100)` |
| 6 | OUT | `sReturn` | `varchar(4000)` |
| 7 | OUT | `sCode` | `int` |

## Body

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

## Narrative

**Business context:** 成本管理 → 工单成本核算 — `Test` development-staging copy of `Sp_System_ProductionCost` from 杨恒林 (@date:20210523 封存, per the header comment). Same algorithm: pulls work-order rows from the cost monthly-summary, computes the period's cost data, writes back to `accordercostanalysis`/`accworkcenter`/`accdepart`. Period opening cost comes from the work order's most recent month-end cost row; 在制品 = work orders where inbound qty < ordered qty.

**What it does:** Same shape as `Sp_System_ProductionCostBak`/`Sp_System_ProductionCost`: parses `$.params[0].value[0].sId` (skips the `JSON_VALID` defensive checks the active version added), reads `NetMoney`/`NetPrice` settings, joins `sysaccountperiod` to get period bounds, then iterates cost-centre and expense ids to build dynamic UPDATE SQL into `accordercostanalysis`/`accworkcenter` for 本期作业汇总, 直接材料, 发外发票, 计件工资, 期初/期末. Differs from `_Bak` only in the parameter-validation prelude (less defensive).

**Invocation:** Status: appears orphaned. No `gdsmodule` binding, no form-master, no other-proc, no xly-src match. `Test` suffix and `封存` author tag identify this as a developer sandbox copy kept alongside `_Bak` for A/B comparison — not wired to any production button. Candidate for cleanup.
