# `Sp_InsertVoucher` (procedure)


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

## Parameters

| # | Mode | Name | Type |
|---|---|---|---|
| 1 | IN | `sMakePerson_s` | `varchar(100)` |
| 2 | IN | `sBrId` | `varchar(100)` |
| 3 | IN | `sSuId` | `varchar(100)` |
| 4 | IN | `tStartDate` | `datetime` |
| 5 | IN | `tEndDate` | `datetime` |
| 6 | OUT | `sReturn` | `varchar(1000)` |
| 7 | OUT | `sCode` | `int` |

## Body

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

## Narrative

**Business context:** 财务管理 → 财务凭证 — legacy hard-coded voucher generator for 销售发票 (`salsalesinvoicemaster`). Predecessor of the `Sp_InsertVoucher_Universals*` template-driven family. Loops the month's `bCheck=1` sales invoices grouped by `dCurrencyRate, sAccountNo, sCustomerId, sMReserve1` and writes one `udfvouchermaster`/`udfvoucherslave` per group, with the account routing 国内 vs 国外 invoices to different `sAccountNo` lines (`5102.04`, etc.) according to hand-coded if-branches.

**What it does:** Bails out if any `udfvouchermaster` row already exists for the current `YEAR(SYSDATE())/MONTH(SYSDATE())` — the proc is single-run-per-month. Otherwise opens cursor over `salsalesinvoicemaster` between `tStartDate..tEndDate`, calls `Sp_Sis_GetConst` for localised constants and `SP_Sis_GetMaxNo` for the voucher number, then `Insert Into udfvouchermaster`/`udfvoucherslave` for each rate-account-customer-MReserve1 group. Does not back-write to the source invoice.

**Invocation:** Status: appears orphaned. No `gdsmodule` hook, no `gdsconfigformmaster` reference, no Java grep hit anywhere in `xly-src/`, and the modern path runs through `Sp_InsertVoucher_Universals_Pro` (dispatched by `GenericProcedureCallServiceImpl.doGenericProcedureCall()`). One DB caller — `Sp_InsertVoucher_salsaleschecking` — references the name but is itself a per-form variant in the same legacy family. Candidate for maintainer audit / removal once retention rules confirm no scheduled job calls it.
