Sp_Check_sSiv.md 2.43 KB

Sp_Check_sSiv (procedure)

销售发票单据保存之前数据校验

  • Type: PROCEDURE
  • Deterministic: NO
  • SQL data access: CONTAINS SQL

Parameters

# Mode Name Type
1 IN sTableName varchar(100)
2 IN sGuid varchar(100)
3 IN sFormGuid varchar(100)
4 IN sLoginId varchar(100)
5 IN sBrId varchar(100)
6 IN sSuId varchar(100)
7 IN iFlag int
8 OUT sCode int
9 OUT sReturn varchar(4000)

Body

Body is not pre-cached. To inspect: mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE PROCEDURESpCheck_sSiv'._

Narrative

Business context: 销售管理 → 销售送货流程 → 销售发票单据 — post-save validator on salsalesinvoicemaster/salsalesinvoiceslave. Enforces that one invoice cannot mix 材料销售 (CLDD-prefixed) and 成品销售 orders, classifies sBussinessType from the source order, recomputes 不含税/税额 from sistax, converts foreign-currency totals via siscurrency, and re-derives tGetPayDate from the customer's 收款条件 (sispayment.iAfterDeliverDay).

What it does: Counts distinct sFormId across the slave's source orders — aborts with sMaterialSaleProductCantInvoice if >1. Updates sBussinessType based on sOrderNo prefix, rewrites slave dProductNoTaxMoney/dProductTaxMoney via sistax.dRate, recomputes dProductMoney from qty×price when drift >0.1, copies sBillType from salsalesorderslave, refreshes dProductForeignMoney from dCurrencyRate. On form 1691254111217011538642820 (manual-entry variant) cross-checks dTotalMoney = dProductNoTaxMoney + dProductTaxMoney per slave and aborts with sProductTaxNotSame if any product mismatches. Computes tGetPayDate = tInvoiceDate + sispayment.iAfterDeliverDay. Recomputes dRemainderQty/dCostQty for partial returns. When bAdvance=1, derives master 税额/不含税/外币 from dAdvanceMoney. Builds a temp table to validate that total invoiced qty per sSrcSlaveId does not exceed the upstream 对账 qty (salsalescheckingslave).

Invocation: Bound to gdsmodule.sSaveProName on 销售发票单据 (sId 15780358080007074056281633539000) — 销售管理 → 销售送货流程 (KPI流程操作菜单). Dispatched by BusinessBaseServiceImpl.checkUpdate(..., "sSaveProName") after the save batch commits. Pre-save peer is Sp_beforeSave_sSiv.