# `Sp_InsertVoucher_opsoutsideinvoice` (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_opsoutsideinvoice`'`._

## Narrative

**Business context:** 财务 / 自动凭证 — generates accounting vouchers for 委外发票 (outsource-processing invoice) bills via `viw_opsoutsideinvoice`. Companion to `Sp_InsertVoucher_opsoutsidechecking` (对账 side); this one posts the invoice/payable leg.

**What it does:** Parses date range from `$.changeValue[0].pChooseDate`. Reads `p_sSrcInvoiceNo` from already-posted `udfvoucherslave.sMemo` over the period to skip duplicates (`INSTR(p_sSrcInvoiceNo, sInvoiceNo)<=0`). Cursors `viw_opsoutsideinvoice GROUP BY dCurrencyRate, sSupplyId WHERE bCheck=1 AND iVouchermark=0 AND tCreateDate IN [start,end)`. Per group: allocates a voucher number via `SP_Sis_GetMaxNo`, inserts `udfvouchermaster` (`sVoucherType='记'`) + `udfvoucherslave` debit/credit rows summing money for the supplier/rate pair, and flips `iVouchermark=1` on the consumed invoices.

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