# `Sp_MonthlyStatisticalSalary` (procedure) - **Type:** PROCEDURE - **Deterministic:** NO - **SQL data access:** CONTAINS SQL ## Parameters | # | Mode | Name | Type | |---|---|---|---| | 1 | IN | `sProInParam` | `varchar(10000)` | | 2 | IN | `sLoginId` | `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_MonthlyStatisticalSalary`'`._ ## Narrative **Business context:** 生产管理 → 计件工资 — month-end salary calculator that walks each row of `mftMonthSumReport` (already populated by `Sp_MonthlyStatisticalReport`) and applies every monthly salary-structure plan in `sissalarystructureplan`. Each plan provides a 公式 (formula) that produces one wage component; the proc writes each component into a numbered column `dWageMoney1, dWageMoney2, …` so the form can display per-component pay. **What it does:** Extracts `tYearMonth` from `$.changeValue[0].tYearMonth`; missing returns `sCode=-1` with `sMonthlyStatisticalReportNotChooseMonth`. Opens cursor `curPlan` over `sissalarystructureplan WHERE sCycle='2'` (monthly-cycle plans) ordered by `iOrder`. For each plan row reads `sId, sSalaryItem, sFormulaId, sCycle, sTeamType, iOrder`. Then inner cursor over `mftMonthSumReport WHERE …YYYYMM = tYearMonth`. For each employee row builds `p_sTmpId = sId,sEmployeeId`, `p_sAllTbName = 'mftMonthSumReport,eleemployee'`, `p_sAllType = 'billSlave,billemployee'`, then `CALL Sp_System_ReplaceField(...)` to evaluate the plan's formula against those tables — yielding `p_dAwardMoney`. Dynamically `UPDATE mftMonthSumReport A SET A.dWageMoney{iOrder} = IFNULL(p_dAwardMoney,0) WHERE A.sId = ''`. Formula failure (`sCode < 0`) aborts the whole batch and bubbles up `@sDetail` via `Sp_System_ReplaceField`. **Invocation:** Dispatched dynamically by `GenericProcedureCallServiceImpl.doGenericProcedureCall()` (POST `/procedureCall/doGenericProcedureCall`) — the 月度工资计算 button on a payroll form names `Sp_MonthlyStatisticalSalary` as the action. xly-src ships `script/标版/30100101/Sp_MonthlyStatisticalSalary.sql` (install script). Predecessor: `Sp_MonthlyStatisticalReport`. Daily-cycle equivalent operates on `sCycle='1'` plans via a separate proc.