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 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>
Fixed a bug where materials matching multiple BOM library records would not
appear in the BOM extraction output. Previously, only the first match was
extracted when success=True, but multiple matches set success=False, causing
all materials to be skipped.
Changes:
- Modified M09_BOMExtractor.MatchAllMaterialTypesWithValidation()
- Changed condition from checking 'success' to checking 'rowCount > 0'
- Added loop to process ALL matching rows instead of just the first one
- Moved BuildWorksheetHeaderMap() outside loop for performance
- Enhanced debug logging to show row processing details
Impact:
- "机芯" (Movement) and "边" (Edge) sheets now show all matched materials
- Users can see and manually resolve ambiguous matches in output
- Component sheet handling unchanged (uses different code path)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Change component inventory insufficient from Error to Warning type in error report
- Propagate productionOrderNo to M08_ComponentProcessor functions for proper error tracking
- Update CheckComponentInventory to record warnings instead of errors for insufficient inventory
- Pass productionOrderNo through ProcessComponentRecord call chain
Changes:
- M08_ComponentProcessor: Add productionOrderNo parameter to ProcessComponentRecord and CheckComponentInventory
- M08_ComponentProcessor: Change insufficient inventory Record to RecordWarning
- M08_ComponentProcessor: Use productionOrderNo in all error/warning recordings
- M09_BOMExtractor: Pass productionOrderNo to ProcessComponentRecord call
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Replace "原表行号" (original row number) field with "生产订单号" (production order number) in BOM Extraction System error reporting to improve traceability.
Changes:
- clsErrorLogger: Update Record/RecordWarning signatures to accept OrderNo (String) instead of RowIndex (Long)
- M09_BOMExtractor: Propagate productionOrderNo through validation chain for context-aware error reporting
- M06/M07/M08: Use empty string for system-level errors without production order context
- Error report header: Change column B from "原表行号" to "生产订单号"
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add 生产订单号 as the first column in output (13 columns total)
- Read production order number from column A of input worksheet
- Only display production order number on first row for each product model
- Set material code column to text format to preserve leading zeros
- Update OutputColumns enum indices in M04_Config.bas
- Update ReadInputModels to return 2 columns (order number + model)
- Update ProcessSingleModel, GenerateMaterialRow, GenerateErrorRow signatures
- Update WriteExtractionResults to write 13 columns with text formatting
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Delete default sheets (Sheet1, Sheet2, etc.) created by Workbooks.Add
- Save output workbook as BOM库.xlsx in the same directory as source file
- Auto-close workbook after saving
- Update completion message to show save path
- Use ThisWorkbook.Path to get source file directory
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add COL_IDX_CODE66 constant for column I in M04_Config.bas
- Extend data reading range to include column I in M02_DataIO.ReadSourceData
- Use .Text property for column I to preserve leading zeros
- Update baseInfo array to use column I instead of column C in M01_Main.bas
- Set output code column to text format to prevent numeric conversion
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Implement edge material validation logic that behaves differently based on azxs value:
- When azxs is A0, Z0, or B0: Edge material is NOT required (0 matches = OK, 1+ matches = ERROR)
- When azxs is AH, AT, BH, BT, BZ, ZH, ZT, or ZZ: Standard validation applies (exactly 1 match required)
- Supports dual-value azxs format (e.g., "A0,径向" extracts "A0" for validation)
Changes:
- M09_BOMExtractor.bas:
- Update MatchAllMaterialTypesWithValidation to pass params to validation
- Update ValidateAllMatchResults signature to accept params parameter
- Add "边" to special sheets array
- Implement Phase 3.5: Edge material validation with azxs-based rules
- Update function header comments
- docs/BOM匹配错误判断机制详解.md:
- Add section 6.5: Edge material special handling
- Update error type table with EdgeMaterialError
- Update function index and version history
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add a preprocessing step to the BOM Extraction System to enhance parameter
extraction with mapping values from "对照表" worksheet. For azxs (安装形式)
and lcfw (量程范围), the system now stores both the raw parsed value AND the
mapped value from the lookup table, enabling flexible dual-value matching.
Changes:
- Create M06A_Mapper.bas: New module for value mapping
- Load azxs/lcfw mappings from "对照表" worksheet
- Return dual-value format "raw,mapped" (e.g., "A0,径向")
- Support graceful degradation if "对照表" not found
- Define constants locally to avoid VBA cross-module reference issues
- Modify M06_ModelParser.bas:
- Extract raw parameter values first
- Apply mapping via M06A_Mapper if initialized
- Store dual values for azxs and lcfw parameters
- Modify M07_BOMMatcher.bas:
- Update EvaluateCellCondition() to support dual-value matching
- Split by comma and check if ANY value matches
- Backward compatible with single-value parameters
- Modify M09_BOMExtractor.bas:
- Initialize M06A_Mapper during RunBOMExtraction()
- Add WorksheetExists() helper function
- Log warning if "对照表" worksheet not found
- Define MAPPING_SHEET_NAME constant locally
- Modify M04_Config.bas:
- Add mapping table configuration constants
- MAPPING_SHEET_NAME, MAPPING_COL_LCFW_KEY, etc.
- Update CLAUDE.md:
- Document new M06A_Mapper module
- Update data flow diagram with mapping step
- Document dual-value matching behavior
- Update system architecture diagram
- Update docs/RunBOMExtraction_运行机制详解.md:
- Add M06A_Mapper to all diagrams and documentation
- Add detailed value mapping section
- Update sequence diagrams with mapping flow
- Update parameter examples with dual-value format
- Bump documentation version to 3.0
Example:
Input: Product model "YTHN-100.A0.531.G123.M04.Y3"
Parse: azxs="A0", lcfw="M04"
Map: azxs="A0,径向", lcfw="M04,高压"
Match: BOM库 with azxs="径向" OR "A0" → MATCH
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Fix incorrect azxs transformation (A0→径向 → A0) - M06_ModelParser returns raw values, not transformed values
- Add missing xh (型号) parameter to diagrams and examples (8 params total, not 7)
- Remove misleading cross-connections between parameters (jycz/lcfw don't flow from gclj/bkxs)
- Fix Mermaid parse error by escaping pipe character (| → 管道符)
- Update all example tables to show raw azxs value "A0" instead of "径向"
- Add comprehensive two-phase validation architecture documentation
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Clearly separate BOM Configuration System (M01-M05) and BOM Extraction System (M06-M09)
- Update Project Overview to describe both functional modules
- Update Architecture section to present both systems with their respective modules
- Update Data Flow to show separate workflows for each system
- Rewrite Key Concepts section with clear separation between systems
- Update Development Commands for both BOM Converter and BOM Extractor
- Update Configuration section with complete system constants for both systems
- Update File Structure to accurately reflect VBA_BOMConverter/ directory layout
- Update Important Notes to cover both systems' specific features
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Major refactoring of BOM matching error handling mechanism to separate
matching phase from validation phase, enabling cross-worksheet validation
and non-blocking warnings.
Changes:
- clsErrorLogger: Add warning support
- Add RecordWarning() method for non-blocking issues
- Add HasWarnings and HasIssues properties
- Update PrintReport() to show errors and warnings with color coding
- Add "Type" column to distinguish errors from warnings
- M09_BOMExtractor: Implement two-phase validation
- Replace MatchAllMaterialTypes() with MatchAllMaterialTypesWithValidation()
- Add ValidateAllMatchResults() for unified cross-worksheet validation
- Phase 1 (Collection): Gather all worksheet matches without recording errors
- Phase 2 (Validation): Validate all results with special rules for components
- Phase 3 (Generation): Create final material collection based on validation
- Add ToArray() helper for Collection to Array conversion
- Enhanced component/joint/element validation:
- Support warnings for non-blocking conflicts (e.g., component + joint both matched)
- Better cross-validation between "部件", "接头", "弹性元件" worksheets
- Distinguish between errors (blocking) and warnings (non-blocking)
- Documentation updates:
- Update BOM匹配错误判断机制详解.md to v2.0
- Document two-phase verification approach
- Add warning scenarios and handling
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add BOM library column name constants (名称, 编码, 数量, etc.)
- Add GetBOMConditionFields() and IsConditionField() utility functions
- Refactor ExtractMaterialInfo to use column names instead of hardcoded positions
- Refactor ExtractSingleSubComponent to use column names for 接头/弹性元件
- Refactor ExtractComponentInfo to use column names
- Improve MatchAllMaterialTypes to iterate all worksheets dynamically
- Add debug logging for troubleshooting
This fix resolves issues where worksheets with non-standard column counts
(like 表壳, 罩壳) could not extract material information properly.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add BOM auto-extraction system requirements specification
- Minor property name fixes in M05_PreProcessor (.Pattern -> .pattern)
- Fix .Row property references to .row for consistency
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add complete BOM auto-extraction system with the following modules:
- M06_ModelParser: Parse product model strings to extract parameters
(azxs, bkxs, gclj, jycz, lcfw, fjgn)
- Extracts header part from full model (ignores dial/attachment parts)
- Splits process connection and material code (G123 -> G12, 3)
- Supports multiple additional features with comma/dot separators
- M07_BOMMatcher: Match materials in BOM library
- Exact match, wildcard (empty cell), negative match (!=)
- Special fjgn contains matching logic
- Array-based performance optimization for bulk operations
- M08_ComponentProcessor: Handle component material special logic
- Component inventory check (interface reserved)
- Sub-component extraction (joint + elastic element)
- Combination validation rules (1 component OR 1 joint + 1 element)
- M09_BOMExtractor: Main extraction orchestrator
- Reads input models from worksheet
- Processes each model and matches all material types
- Outputs to "BOM提取结果" worksheet
- Error reporting and non-blocking design
- M06B_TestRunner: Comprehensive unit tests
- 8 test cases for model parsing
- 5 test cases for BOM matching
- 5 test cases for component processing
- M04_Config: Add BOM extraction constants
- BOM library filename and configuration
- Input/output column definitions
- Output column enumeration
- M01_Main: Add RunBOMExtraction entry point
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Rename VBA/ directory to VBA_BOMConverter/ for better clarity.
This change reflects the module's purpose as the BOM converter component.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Extend M05_PreProcessor to support category-specific preprocessing:
- "接头" category: Full preprocessing (azxs + lcfw mapping, OR merging, parentheses simplification)
- "部件" category: Partial preprocessing (azxs mapping only, OR merging, parentheses simplification)
- Other categories: No preprocessing
Add new function ApplyPreprocessingWithoutLcfw() to handle component category preprocessing.
Add unit tests (PP_09 through PP_12) to verify:
- azxs mapping for component category
- lcfw conditions remain unchanged for component category
- OR condition merging and parentheses simplification
Update CLAUDE.md documentation with category-specific preprocessing table.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Simplify the BOM conversion workflow by removing the interactive prompt for preprocessing report generation. This streamlines the main conversion process.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Remove Test_PP_06_FullIntegration_流程详解.md as preprocessing
workflow is now documented in code comments and CLAUDE.md.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Replace character-by-character parsing with regex-based implementation
for value mapping and OR condition merging.
Changes:
- Add ApplyRegexMapping() for regex-based value replacement
* Uses VBScript.RegExp with Late Binding
* Replaces from back to front to avoid position shifts
* Uses regex.Replace() method for precise matching
* Includes EscapeForRegex() to handle special characters
- Add ProcessNestedExpressions() for recursive parenthesis handling
- Add MergeDuplicateORConditions() for OR deduplication
- Add SimplifyParentheses() for smart parenthesis removal
- Remove ProcessAndSimplifyNested() (150+ lines of complex logic)
- Remove ProcessAndSegment(), ProcessAtom(), ParseAtom()
- Remove MergeDuplicateORs(), MaybeRemoveOuterParentheses()
- Remove JoinCollection(), MergeDuplicateAtoms()
Regex patterns used:
- azxs: (azxs)( *=|!= *)([a-zA-Z0-9]{2})
- lcfw: (lcfw)( *=|!= *)([a-zA-Z]\d{1,3})(?=[ \(\)]?)
Processing flow:
1. Apply azxs value mapping (regex)
2. Apply lcfw value mapping (regex)
3. Process nested expressions (recursive OR merge)
4. Merge top-level OR conditions
5. Simplify unnecessary parentheses
Benefits:
- Code reduced from 647 to 553 lines (-15%)
- Core logic simplified significantly
- Better performance: single regex pass vs multiple string traversals
- Improved readability and maintainability
- Precise replacement using regex.Replace() instead of string Replace()
- Preserved late binding and backward compatibility
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add M05_PreProcessor module to handle value mapping and condition
simplification for "接头" category before parsing.
Features:
- Value mapping: azxs codes (A0/AT/AH→径向, B0/BT/BZ/BH→下轴向,
Z0/ZT/ZZ/ZH→中轴向) and lcfw ranges (M01-M11→低压, M12-M16→高压)
- OR condition merging: automatically removes duplicate OR segments
- Smart parentheses handling: removes parentheses for single atoms,
preserves them when needed for logical structure
- Recursive nested expression processing
- Graceful degradation when "对照表" worksheet is missing
Integration:
- Modified M01_Main to initialize preprocessor after M03_Logic
- Preprocessing applied only for "接头" category
- Updated M99_TestRunner with 8 comprehensive test cases
- All tests passing (50 total: 42 core + 8 preprocessing)
Documentation:
- Added detailed flow documentation for Test_PP_06_FullIntegration
with mermaid diagrams in docs/Test_PP_06_FullIntegration_流程详解.md
- Updated CLAUDE.md with preprocessing module description and
documentation guidelines (docs/ vs reference_docs/)
Example transformation:
Input: gclj=M16 AND (azxs=A0 OR azxs=AT) AND (lcfw=M01 OR lcfw=M15)
Output: gclj=M16 AND azxs=径向 AND (lcfw=低压 OR lcfw=高压)
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add comprehensive documentation for Claude Code including:
- VBA module architecture and data flow
- Conditional logic syntax and parsing behavior
- Column mapping and header priority configuration
- Development commands for running converter and tests
- Git workflow and Claude Code integration
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Use github.repository and parse with cut command since
github.repository_name is not available in Gitea Actions.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Use shell variables to properly handle multi-line commit messages
and special characters that cause shell parsing errors.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Replace hardcoded 'AutoBOM' with ${{ github.repository_name }}
- Add repository name to tags for better filtering
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add *.xlsx to gitignore to exclude Excel files from version control
- Remove Chinese documentation files that are no longer needed
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Remove all VBA source files from ClassModules, DocumentModules, and Modules
- Remove vba_metadata.json
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add 生产订单号 field from column A of [产品订单] sheet
- Remove 表头型号 field from output
- Reorder columns to place 生产订单号 as first column
- Update ProcessSingleModel and CreateOutputRowArray signatures
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Implement automatic component inventory verification that marks
orders with insufficient stock as "Component Priority = No".
Key features:
- Reads orders from [产品订单] worksheet
- Parses BOM to identify component category materials
- Validates inventory against [现存量] worksheet
- Allocates stock in order sequence
- Handles missing components with warnings instead of errors
- Provides detailed statistics on completion
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add fjgn (附加功能) field extraction from instrument characteristics
- Extract additional features from model number's instrument feature field
- Merge all fields from index 5 onwards to handle dot separators in features
- Remove oil-fill type (Y+digit) suffix from additional features
- Normalize separators (comma and dot) to comma for consistent parsing
- Implement multi-value matching for fjgn conditions (contains logic)
- fjgn=N1: true if fjgn contains N1
- fjgn!=N1: true if fjgn does not contain N1
- Add fjgn to condition config in MainModule and BIPUploadModule
Fixes issue where additional features with dot separators (e.g., N3.N2.Y3)
were incorrectly parsed by merging all fields from index 5 onwards.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Remove "作者: Auto-generated" and date fields from module headers
- Clean up unnecessary metadata comments
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Rename Quantity to quantity in BomItem for consistent naming convention
- Update references in MainModule to use lowercase quantity
- Add newlines at end of files for consistency
- Update vba_metadata.json with new source path and document module
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Optimize BIPUploadModule and MainModule for better performance:
- Replace cell-by-cell writes with batch array operations
- Collect all output data in memory using Collection objects
- Use WriteBatchData to write all data in single operation
- Add CreateBIPRowArray and CreateOutputRowArray helper functions
- Remove deprecated WriteBIPRow and WriteOutputRow functions
Performance improvement:
- Before: N cell write operations per row (thousands of Excel calls)
- After: 1 batch write operation for all data
- Expected speedup: 10-100x depending on data volume
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Fix bug where error messages from previous orders were accumulating:
- Add ClearErrorMessages() public method to BomExtractor class
- Initialize pErrorMessages as new collection in ExtractBom()
- Replace commented-out pErrorMessages.Clear with proper initialization
- Ensures each order's error information is independent
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Update MainModule to support component priority field:
- Read component priority from column E of [产品订单] worksheet
- Pass component priority to ProcessSingleModel function
- Apply category exclusion logic based on priority flag:
- When "否"/"0"/"FALSE", exclude "部件" category
- Only extract sub-category materials when disabled
- Consistent with BIPUploadModule implementation
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>