# `Sp_InsertVoucher_mitproductionmaterials` (procedure)


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sProInParam` | `varchar(10000)` |
| 2 | IN | `sMakePerson_s` | `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_InsertVoucher_mitproductionmaterials`'`._

## Narrative

**Business context:** 财务 / 自动凭证 — generates accounting vouchers for 生产领料 (production material-issue) bills `mitproductionmaterialsmaster` (via `viw_mitproductionmaterials`) over a chosen date range. Companion `Sp_InsertVoucher_mitproductionmaterialsBF` covers the 报废出库 (scrap-out) branch (`sFormId='192116810113315268872698730'`) which this proc deliberately excludes.

**What it does:** Parses date range from `$.changeValue[0].pChooseDate`. Pre-flight `SELECT EXISTS` on `viw_mitproductionmaterials WHERE bCheck=1 AND sSReserve4<>'' AND iVouchermark=0 AND sFormId<>'<scrap-out>' AND tCreateDate IN (start,end)`. Cursors `GROUP BY sSReserve4` (the cost-allocation key on the issue slip); per group allocates a voucher number with `SP_Sis_GetMaxNo`, inserts master + debit/credit slave rows summing the material costs and flips `iVouchermark=1` on the consumed issue rows.

**Invocation:** Status: appears orphaned. No form-master/`gdsmodule`/workflow/other-routine reference and no xly-src match besides install script `script/标版/30100101/Sp_InsertVoucher_mitproductionmaterials.sql`. Signature matches the `GenericProcedureCallServiceImpl.doGenericProcedureCall()` voucher-button shape; likely superseded by `Sp_InsertVoucher_Universal*`. Candidate for maintainer audit.
