feat: implement inventory comparison worksheet for component materials
All checks were successful
NTFY Notification / notify (push) Successful in 5s

Add new "库存比对" worksheet that displays component inventory status
alongside material requirements for production planning.

Changes:
- M04_Config: Add INVENTORY_COMPARISON_SHEET_NAME constant
- M08_ComponentProcessor: Enhance component processing to return both
  component and sub-components when inventory insufficient; add
  GetComponentInventoryInfo() read-only function for inventory lookup
- M09_BOMExtractor: Add WriteInventoryComparisonResults() function
  to generate inventory comparison worksheet with 7 columns showing
  material code, name, required quantity, stock quantity, and status

Output format:
- Columns: 序号, 生产订单号, 物料编码, 物料名称, 所需数量, 库存数量, 库存充足
- Color coding: Green (sufficient) / Red (insufficient)
- Sequence numbering: 10+0, 10+1 per order

Backward compatibility: Existing BOM提取结果 and BIP上传 worksheets
remain unchanged.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-02-26 17:55:20 +08:00
parent e086dee920
commit c696057cd4
3 changed files with 373 additions and 4 deletions

View File

@@ -174,16 +174,28 @@ Public Function ProcessComponentRecord( _
Set headerMap = M07_BOMMatcher.BuildWorksheetHeaderMap(wsComponent)
' 步骤4: 检查部件库存
Dim componentInfo As Object
If CheckComponentInventory(wsComponent, matchedRowNum, headerMap, orderQty, productionOrderNo) Then
' 库存充足,返回部件物料
Dim componentInfo As Object
Set componentInfo = ExtractComponentInfo(wsComponent, matchedRowNum, headerMap, "部件")
componentInfo("remarks") = ""
componentInfo("isStockSufficient") = True
If Not componentInfo Is Nothing Then
materials.Add componentInfo
End If
Else
' 库存不足,提取子件(接头+弹性元件)
' 【关键修复】库存不足时,同时返回部件(标记)和子件
' 步骤1: 返回部件信息(用于库存比对表)
Set componentInfo = ExtractComponentInfo(wsComponent, matchedRowNum, headerMap, "部件")
componentInfo("remarks") = "部件无库存,使用子件"
componentInfo("isStockSufficient") = False
If Not componentInfo Is Nothing Then
materials.Add componentInfo
End If
' 步骤2: 返回子件信息用于BOM提取结果和BIP上传
Dim subComponents As Collection
Set subComponents = ExtractSubComponents(wsComponent, matchedRowNum, headerMap)
@@ -405,6 +417,7 @@ Private Function ExtractComponentInfo( _
End If
componentInfo("remarks") = ""
componentInfo("isStockSufficient") = True ' 默认值,会在 ProcessComponentRecord 中被覆盖
Set ExtractComponentInfo = componentInfo
Exit Function
@@ -567,6 +580,87 @@ ErrorHandler:
Set ExtractSingleSubComponent = Nothing
End Function
' ------------------------------------------------------------------------------
' 获取部件库存信息(用于库存比对工作表)
'
' 输入:
' componentCode - 部件编码
' bomQty - BOM需求量单个产品
' orderQty - 订单数量
'
' 输出:
' Object - 库存信息字典
' .stockQty - 库存数量
' .requiredQty - 所需数量 (orderQty × bomQty)
' .accumulatedDemand - 累计需求量
' .totalDemand - 总需求量 (累计需求 + 当前需求)
' .isSufficient - 库存是否充足 (True/False)
'
' 注意:
' - 此函数是只读的,不会修改 g_AccumulatedDemandDict
' - 库存充足性判断基于累计需求量,但仅返回结果,不更新状态
' ------------------------------------------------------------------------------
Public Function GetComponentInventoryInfo( _
ByVal componentCode As String, _
ByVal bomQty As Long, _
ByVal orderQty As Long _
) As Object
On Error GoTo ErrorHandler
Dim invInfo As Object
Set invInfo = CreateObject("Scripting.Dictionary")
' 步骤1: 获取库存数量
Dim stockQty As Long
stockQty = 0 ' 默认值为0
If Not g_InventoryDict Is Nothing And g_InventoryDict.Exists(componentCode) Then
stockQty = g_InventoryDict(componentCode)
End If
' 步骤2: 计算需求量
Dim requiredQty As Long
requiredQty = orderQty * bomQty
Dim accumulatedDemand As Long
accumulatedDemand = 0
If Not g_AccumulatedDemandDict Is Nothing Then
If g_AccumulatedDemandDict.Exists(componentCode) Then
accumulatedDemand = g_AccumulatedDemandDict(componentCode)
End If
End If
Dim totalDemand As Long
totalDemand = accumulatedDemand + requiredQty
' 步骤3: 判断库存是否充足
Dim isSufficient As Boolean
isSufficient = (stockQty >= totalDemand)
' 步骤4: 返回库存信息
invInfo("stockQty") = stockQty
invInfo("requiredQty") = requiredQty
invInfo("accumulatedDemand") = accumulatedDemand
invInfo("totalDemand") = totalDemand
invInfo("isSufficient") = isSufficient
Set GetComponentInventoryInfo = invInfo
Exit Function
ErrorHandler:
' 出错时返回默认值(库存不足)
Dim errorInfo As Object
Set errorInfo = CreateObject("Scripting.Dictionary")
errorInfo("stockQty") = 0
errorInfo("requiredQty") = orderQty * bomQty
errorInfo("accumulatedDemand") = 0
errorInfo("totalDemand") = orderQty * bomQty
errorInfo("isSufficient") = False
Set GetComponentInventoryInfo = errorInfo
End Function
' ------------------------------------------------------------------------------
' 验证部件组合是否有效
'