Files
AutoBOM/VBA_BOMConverter/Modules/M04_Config.bas
Misaka_Company e086dee920
All checks were successful
NTFY Notification / notify (push) Successful in 4s
feat: implement BIP upload worksheet with quantity calculation fix
This commit implements the BIP upload worksheet functionality for ERP system integration and fixes a critical bug in quantity calculation.

Changes:
1. Added BIP upload configuration constants to M04_Config.bas
   - BIP_UPLOAD_SHEET_NAME = "BIP上传"
   - BIP_ROW_NUMBER_BASE = 7000
   - BIP_SUPPLY_MODE = "一般发料"
   - BIP_ISSUE_ORG = "重庆布莱迪仪器仪表有限公司"

2. Extended input data reading to 4 columns (M09_BOMExtractor.bas)
   - Column D: Product Code (产品编码)
   - Updated ReadInputModels to read columns A:D

3. Added product code mapping in main flow
   - Created productCodeMap Dictionary to store order number -> product code mappings
   - Stored product codes during input processing loop

4. Created WriteBIPUploadResults function
   - Generates 9-column BIP upload worksheet
   - Implements row number generation (7000 + material sequence number)
   - Resets sequence counter for each new order
   - Includes all rows (including error rows)
   - Formats worksheet with borders, column widths, and freeze panes

5. **CRITICAL FIX**: Corrected quantity calculation logic
   - Added order quantity lookup from inputModels
   - Changed from: materialQty = result(12) (BOM base quantity only)
   - Changed to: finalQty = bomQty * currentOrderQty
   - Applied fix to both "生产数量" (column 3) and "计划出库数量" (column 9)
   - Updated comment to clarify result(12) is BOM base quantity

Output Format (9 columns):
1. 来源单据号 (Source Document Number) - Production Order No
2. 产品编码 (Product Code)
3. 生产数量 (Production Quantity) = Order Qty × Material Qty
4. 行号 (Row Number) = 7000 + sequence (resets per order)
5. 材料编码 (Material Code)
6. 供应方式 (Supply Mode) = "一般发料"
7. 需用日期 (Required Date) = Current date (yyyy/m/d format)
8. 发料组织 (Issue Organization) = "重庆布莱迪仪器仪表有限公司"
9. 计划出库数量 (Planned Output Qty) = Order Qty × Material Qty

Business Rules Implemented:
- Error rows are included (material code is empty, quantities are 0)
- Empty product codes are written as empty strings
- Row numbers reset to 7001 for each new order
- Material quantities are correctly calculated as order quantity × BOM quantity

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-02-26 14:41:58 +08:00

144 lines
5.9 KiB
QBasic
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
' ==============================================================================
' 模块: M04_Config
' 职责: 系统配置、常量定义
' ==============================================================================
Option Explicit
' 源数据列号定义 (根据你的描述)
Public Const COL_IDX_CODE As Long = 3 ' 代号 (C列)
Public Const COL_IDX_NAME As Long = 4 ' 名称 (D列)
Public Const COL_IDX_QTY As Long = 5 ' 数量 (E列)
Public Const COL_IDX_COND As Long = 6 ' 选择条件 (F列)
Public Const COL_IDX_CAT As Long = 8 ' 类别 (H列)
Public Const COL_IDX_CODE66 As Long = 9 ' 66代码 (I列) - NEW
Public Const SRC_START_ROW As Long = 4 ' 数据起始行
' ------------------------------------------------------------------------------
' BOM自动提取系统配置常量
' ------------------------------------------------------------------------------
' BOM库配置
Public Const BOMLIB_FILENAME As String = "BOM库.xlsx"
Public Const BOMLIB_START_ROW As Long = 2 ' BOM库数据起始行第1行是表头
Public Const OUTPUT_SHEET_NAME As String = "BOM提取结果"
' BIP上传工作表配置
Public Const BIP_UPLOAD_SHEET_NAME As String = "BIP上传"
Public Const BIP_ROW_NUMBER_BASE As Long = 7000
Public Const BIP_SUPPLY_MODE As String = "一般发料"
Public Const BIP_ISSUE_ORG As String = "重庆布莱迪仪器仪表有限公司"
' 输入列名称配置
Public Const INPUT_COL_MODEL As String = "型号"
Public Const INPUT_COL_PRODUCT_MODEL As String = "产品型号"
' 输出列枚举
Public Enum OutputColumns
oc_ProductionOrderNo = 1 ' 生产订单号
oc_OriginalModel = 2 ' 原始产品型号
oc_Azxs = 3 ' 安装形式
oc_Bkxs = 4 ' 表壳形式
oc_Gclj = 5 ' 过程连接
oc_Jycz = 6 ' 接液材质
oc_Lcfw = 7 ' 量程范围
oc_Fjgn = 8 ' 附加功能
oc_MaterialType = 9 ' 物料类型
oc_MaterialName = 10 ' 物料名称
oc_MaterialCode = 11 ' 物料编码
oc_MaterialQty = 12 ' 物料数量
oc_Remarks = 13 ' 提取备注
End Enum
' 型号解析常量
Public Const MODEL_SEPARATOR_PIPELINE As String = "|" ' 管道符分隔符
Public Const MODEL_SEPARATOR_DOT As String = "." ' 点号分隔符
Public Const MODEL_SEPARATOR_CARET As String = "^" ' 插入符分隔符(法兰隔膜)
Public Const MODEL_HEADER_MIN_SEGMENTS As Long = 6 ' 表头最小段数
' BOM库工作表列表需要遍历的工作表
Public Const BOMLIB_SHEET_JOINT As String = "接头"
Public Const BOMLIB_SHEET_ELEMENT As String = "弹性元件"
Public Const BOMLIB_SHEET_MOVEMENT As String = "机芯"
Public Const BOMLIB_SHEET_COMPONENT As String = "部件"
Public Const BOMLIB_SHEET_EDGE As String = "边"
' BOM库物料列名常量
Public Const BOMLIB_COL_NAME As String = "名称"
Public Const BOMLIB_COL_CODE As String = "编码"
Public Const BOMLIB_COL_QTY As String = "数量"
Public Const BOMLIB_COL_JOINT_NAME As String = "接头名称"
Public Const BOMLIB_COL_JOINT_CODE As String = "接头编码"
Public Const BOMLIB_COL_JOINT_QTY As String = "接头数量"
Public Const BOMLIB_COL_ELEMENT_NAME As String = "弹性元件名称"
Public Const BOMLIB_COL_ELEMENT_CODE As String = "弹性元件编码"
Public Const BOMLIB_COL_ELEMENT_QTY As String = "弹性元件数量"
' ------------------------------------------------------------------------------
' 现存量工作表配置常量
' ------------------------------------------------------------------------------
Public Const INVENTORY_SHEET_NAME As String = "现存量"
Public Const INVENTORY_HEADER_ROW As Long = 3 ' 表头在第3行
Public Const INVENTORY_COL_CODE As String = "B" ' B列 = 物料编码
Public Const INVENTORY_COL_QTY As String = "J" ' J列 = 库存数量
' BOM库条件字段列表所有可能的条件字段
Public Function GetBOMConditionFields() As Variant
GetBOMConditionFields = Array( _
"azxs", "bkxs", "gclj", "jycz", "lcdw", "lcfw", _
"fjgn", "btcy", "bp", "dskd", "nqlc", "bptx", _
"jddj", "cpdm", "tsjz", "tsyq", "bpts", "kdxh" _
)
End Function
' ------------------------------------------------------------------------------
' 映射表配置常量
' ------------------------------------------------------------------------------
Public Const MAPPING_SHEET_NAME As String = "对照表"
Public Const MAPPING_COL_LCFW_KEY As Long = 1 ' A列 - lcfw原始值
Public Const MAPPING_COL_LCFW_VAL As Long = 2 ' B列 - lcfw映射值
Public Const MAPPING_COL_AZXS_KEY As Long = 4 ' D列 - azxs原始值
Public Const MAPPING_COL_AZXS_VAL As Long = 5 ' E列 - azxs映射值
Public Const MAPPING_START_ROW As Long = 3 ' 数据起始行
' 检查列名是否为条件列
Public Function IsConditionField(ByVal colName As String) As Boolean
Dim fields As Variant
fields = GetBOMConditionFields()
Dim i As Long
Dim lowerColName As String
lowerColName = LCase(Trim(colName))
For i = LBound(fields) To UBound(fields)
If lowerColName = LCase(fields(i)) Then
IsConditionField = True
Exit Function
End If
Next i
IsConditionField = False
End Function
' 获取表头排序索引 (越小越靠前)
Public Function GetHeaderPriority(key As String) As Long
Dim vList As Variant
Dim i As Long
' 定义标准排序顺序
vList = Array("azxs", "bkxs", "gclj", "jycz", "lcdw", "lcfw", _
"fjgn", "btcy", "bp", "dskd", "nqlc", "bptx", _
"jddj", "cpdm", "tsjz", "tsyq", "bpts", "kdxh")
Dim sKey As String
sKey = LCase(Trim(key))
For i = LBound(vList) To UBound(vList)
If sKey = LCase(vList(i)) Then
GetHeaderPriority = i
Exit Function
End If
Next i
' 未知变量排在最后
GetHeaderPriority = 999
End Function