# `Sp_productionPlan_BtnEventAutoOrderSettime` (procedure)

> 按照锁定计划到货等排序


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `p_sMachineId` | `varchar(100)` |
| 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_productionPlan_BtnEventAutoOrderSettime`'`._

## Narrative

**Business context:** 生产计划管理 → 生管主计划 / 生产排程 — 按照锁定计划到货等排序 (per the COMMENT). Auto-resequencing pass over `mftproductionplanslave` for one machine: re-orders the unstarted rows on the machine timeline using a composite priority of lock-state, work-order state, paper-cut readiness, delivery date, and creation date.

**What it does:** Builds two temp tables (`p_mftproductionplanslave_tmp_update`, `p_mftproductionplanslave_tmp_order`) from `MftProductionPlanSlave` joined with `mftworkordermaster` and `elemachine`, filtered to the chosen machine, `sState <> '5'`, `bProductionReportComplete = 0`, `dProcessQty - dProductionReportQty > 0`, `bBillOutside=0`, `bFrozen=0`. Classifies each row's `iOrderPlanType` (1=locked, 6=`sState=3`, 5=未评审, else 2), sorts by that plus delivery/creation date, then `UPDATE mftproductionplanslave` writing back the new `iOrder` for non-locked rows.

**Invocation:** Called by `Sp_Manufacture_SetTime` after the lock/unlock branches resolve. No xly-src grep hit and no direct UI dispatcher — runs only as a sub-step of the recompute-time chain (so reached indirectly via `Sp_productionPlan_BtnEventCnl` → `Sp_Manufacture_SetTime` and similar).
