# `Sp_CalcAttribDate` (procedure) - **Type:** PROCEDURE - **Deterministic:** NO - **SQL data access:** CONTAINS SQL ## Parameters | # | Mode | Name | Type | |---|---|---|---| | 1 | IN | `sGuid` | `varchar(50)` | | 2 | IN | `sBrId` | `varchar(100)` | | 3 | IN | `sSuId` | `varchar(100)` | ## Body _Body is not pre-cached. To inspect: `mysql --defaults-file=~/.my.cnf -e 'SHOW CREATE PROCEDURE `Sp_CalcAttribDate`'`._ ## Narrative **Business context:** 生产管理 / 上报 — date-attribution helper that resolves which calendar day a production-report slave (`mftproductionreportslave`) should belong to. The shop runs across shift boundaries, so the slave row's `tVestingDate` (归属日期) is not always the same as `tCreateDate`; the team type (白班/晚班) and the machine's `sOffWork`/`sShiftsWork` cut-off govern which day the output is credited to for shift-based wage and KPI roll-ups. **What it does:** Cursors over `viw_mftproductionreport` (optionally narrowed by `sGuid`) where `bInvalid=0`. For each row, reads `elemachine.sOffWork`, `sShiftsWork`, `sWorkType`. When `sWorkType='1'` (day-only) sets `tVestingDate` to the create date with `sTeamType='1'`. Otherwise compares the create-time-of-day to the shift cut-off (`tShiftsWork`) and assigns the date to either the same day or the previous day, with `sTeamType` updated accordingly on `mftproductionreportslave`. **Invocation:** Called by procedure `Sp_Calc_sPpr` (生产上报审核 audit handler) — re-derives the slave's vesting date whenever an upstream report is audited. No direct Java caller; no form-master binding.