# `Sp_ProductionOrder_ReturnOutSide` (procedure)

> @author:zhucx 
		     @date: 2022/12/02
				 @describe: 生产订单-成品外购，返回重排按钮


- **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_ProductionOrder_ReturnOutSide`'`._

## Narrative

**Business context:** 生产管理 → 订单生产流程 → 销售订单->生产工单 — 返回重排 ("return / re-schedule") toolbar action for whole-bill outsourcing rows. Reverses `Sp_ProductionOrder_OutSide`, sending the slave row back into in-house production scheduling — but refuses to do so for products whose master record (`eleproduct.iOutSide=1`) is configured as inherently outsourced.

**What it does:** Walks `$.params[*].value[*].sSlaveId`. For each `salsalesorderslave.sId`, checks `EXISTS (SELECT 1 FROM salsalesorderslave a JOIN eleproduct b ON a.sProductId=b.sId WHERE a.sId=p_sId AND b.iOutSide=1)`; if so, aborts with `Fun_Sis_GetConst('sProductionOrderProductHaveData')` (产品内置属性,无需返回重排). Otherwise `UPDATE salsalesorderslave a LEFT JOIN eleproduct b ON a.sProductId=b.sId SET a.bOutside=0, a.bProductionOrder=0, a.tProductionOrder=SYSDATE(), a.sProductionOrder=sMakePerson, a.dAuxiliaryQty=0 WHERE b.iOutSide=0 AND a.sId=p_sId`.

**Invocation:** Dispatched dynamically by `GenericProcedureCallServiceImpl.doGenericProcedureCall()` — 返回重排 toolbar button on 销售订单->生产工单. xly-src ships `script/标版/30100101/Sp_ProductionOrder_ReturnOutSide.sql` (install script only; no Java caller).
