# `Sp_productionMainPlan_BtnEventPlanning` (procedure)

> 主计划：投入规划


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

## Parameters

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

## Body

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

## Narrative

**Business context:** 生产管理 / 主计划 → 投入规划 — planner-grid "push into planning" button. Promotes selected 新工单 rows to 规划中 (`sState='2'`), assigns them the next sequence number, and asks `Sp_Manufacture_InsertMftPlan` to expand the work-order's slave processes into `mftproductionplanslave` rows so the scheduler has something to lay down. Refuses if the source work-order is unaudited or if the plan row is frozen.

**What it does:** Validates `sProInParam` is JSON (`JSON_VALID`). Parses `$.params[*].value[*].sId`. For each plan id, joins `mftproductionplan` to `mftworkordermaster` to fetch `(sSrcId, sSrcNo, bFrozen, bCheck)`. Refuses with localised `sProductionMainOrderUnChecked` when `bCheck=0` (work-order unaudited) or `sProductionMainPlainDj` when `bFrozen=1` (plan frozen). Picks `MAX(iOrder)` over `sState IN ('2','3','7')`, then `CALL Sp_Manufacture_InsertMftPlan(p_sWorkOrderGuid, p_sWorkOrderBillNo, 1, '', sBrId, sSuId, p_sCount, @sReturn)` to fan out the slaves, then `UPDATE mftproductionplan SET sState='2', iOrder=MAX+1` on the master.

**Invocation:** Standard `Sp_<Module>_BtnEvent*` slot — dispatched by `GenericProcedureCallServiceImpl.doGenericProcedureCall()` when the 主计划 grid's 投入规划 button names this procedure. xly-src ships `script/标版/30100101/schedule/Sp_productionMainPlan_BtnEventPlanning.sql` and the proc also appears in `planTmp.sql`. No form-master or gdsmodule binding.
