-- 1.0.364：工单齐套率(MFRate)计算与领料单回写
-- 1) NbrMaster 增加 MFRate 列（齐套率）
-- 2) NbrDetail 增加 SatisfyQty 列（可领数量）
-- 幂等可重跑。

-- ALTER NbrMaster: 增加 MFRate 列
SET @ddl := (SELECT IF(
  EXISTS(SELECT 1 FROM information_schema.COLUMNS
         WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='NbrMaster' AND COLUMN_NAME='MFRate'),
  'SELECT 1',
  'ALTER TABLE NbrMaster ADD COLUMN MFRate DECIMAL(18,5) NULL DEFAULT NULL COMMENT ''齐套率'' AFTER source_system'));
PREPARE s FROM @ddl; EXECUTE s; DEALLOCATE PREPARE s;

-- ALTER NbrDetail: 增加 SatisfyQty 列
SET @ddl := (SELECT IF(
  EXISTS(SELECT 1 FROM information_schema.COLUMNS
         WHERE TABLE_SCHEMA=DATABASE() AND TABLE_NAME='NbrDetail' AND COLUMN_NAME='SatisfyQty'),
  'SELECT 1',
  'ALTER TABLE NbrDetail ADD COLUMN SatisfyQty DECIMAL(18,5) NULL DEFAULT NULL COMMENT ''可领数量（基于齐套率）'' AFTER CurrQtyOpened'));
PREPARE s FROM @ddl; EXECUTE s; DEALLOCATE PREPARE s;
