# ACT Maker Automated document generation tool for creating ACT (acceptance certificate) documents from ESFS XML receipts. ## Features - 📄 **Automated Document Generation**: Process multiple receipts at once - 🔄 **Template-based**: Uses customizable DOCX templates - 🌍 **Russian Language Support**: Converts numbers to Russian words with proper grammar - 📊 **Batch Processing**: Handles multiple XML files and receipts - ⚙️ **Configurable**: Command-line arguments for flexibility ## Project Structure ``` act_maker/ ├── main.py # Main entry point ├── merge_documents.py # Standalone document merger utility ├── requirements.txt # Python dependencies ├── README.md # This file ├── .user_name # User configuration (your name) ├── draft.docx # DOCX template file ├── result.docx # Final merged output (auto-generated) ├── esfs/ # Input folder for XML receipts │ └── *.xml # ESFS receipt XML files ├── .temp_docs/ # Temporary buffer (auto-created, auto-deleted) │ └── act_*.docx # Individual documents (only with --keep-temp) └── utils/ # Utility modules ├── __init__.py ├── number_converter.py # Number to Russian words converter ├── receipt_parser.py # XML receipt parser ├── document_processor.py # DOCX template processor └── document_merger.py # Document merging logic ``` ## Installation 1. **Clone or download this project** 2. **Create a virtual environment** (recommended): ```bash python3 -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate ``` 3. **Install dependencies**: ```bash pip install -r requirements.txt ``` ## Configuration 1. **Create `.user_name` file** with your name: ``` ИП Пупкин Василий Алибабаевич ``` 2. **Prepare your template** (`draft.docx`) with the following tags: - `` - Your name in UPPERCASE (bold) - `` - Your name in original case with last word on new line (bold) - `` - Contract date (bold) - `` - Price in numbers (bold) - `` - Price in words (normal) - `` - Today's date (bold) 3. **Place XML receipts** in the `esfs/` folder ## Usage ### Basic Usage Process all receipts and create a merged document: ```bash python main.py ``` This will: 1. Parse all XML files from `esfs/` folder 2. Generate individual documents in `.temp_docs/` folder 3. Merge all documents into `result.docx` 4. Clean up temporary files ### Advanced Usage Keep temporary files for inspection: ```bash python main.py --keep-temp ``` Customize paths and output file: ```bash python main.py --template my_template.docx \ --esfs-folder input_xmls \ --output my_result.docx \ --user-config .my_name ``` ### Command-Line Arguments | Argument | Default | Description | |----------|---------|-------------| | `--template` | `draft.docx` | Path to DOCX template file | | `--esfs-folder` | `esfs` | Folder containing XML receipt files | | `--output` | `result.docx` | Output merged document file | | `--user-config` | `.user_name` | Config file containing user name | | `--keep-temp` | `false` | Keep temporary files after merging | ### Standalone Document Merger You can also merge existing DOCX files using the standalone merger: ```bash python merge_documents.py --input-folder my_docs --output merged.docx ``` ## How It Works 1. **Parse XML Receipts**: Scans the ESFS folder for XML files and extracts receipt data 2. **Extract Data**: Gets contract dates, prices, and creation dates from each receipt 3. **Convert Numbers**: Converts prices to Russian words (e.g., 87000 → "восемьдесят семь тысяч") 4. **Fill Template**: Replaces tags in the DOCX template with actual data 5. **Generate Individual Documents**: Saves each filled document to `.temp_docs/` buffer 6. **Merge Documents**: Combines all documents into a single `result.docx` file with page breaks 7. **Cleanup**: Removes temporary files (unless `--keep-temp` is specified) ## Template Tags All tags are replaced with proper formatting (bold where specified): - **``**: Full name in UPPERCASE and bold - **``**: Full name with last word on new line, bold - **``**: Date in format "2 ноября 2024", bold - **``**: Integer price (e.g., "87000"), bold - **``**: Price in words (e.g., "восемьдесят семь тысяч"), regular font - **``**: Date in format "1 апреля 2026", bold ## Example Output Input receipt with price `87000` and date `2024-11-02` will generate: - Contract date: **2 ноября 2024** - Price: **87000** сом (восемьдесят семь тысяч) - Name: **ИП ИВАНОВ ИВАН ИВАНОВИЧ** / **ИП Иванов Иван** **Иванович** ## Development ### Running Tests Test the number converter: ```bash python -c "from utils import NumberToWords; c = NumberToWords(); print(c.convert(87000))" ``` ### Project Components - **NumberToWords**: Converts integers to Russian words with proper grammar - **ReceiptParser**: Extracts data from ESFS XML receipts - **DocumentProcessor**: Fills DOCX templates while preserving formatting - **DocumentMerger**: Merges multiple DOCX files into a single document with page breaks ## Requirements - Python 3.12+ - python-docx 1.1.2 ## License This is a utility tool for internal use. ## Support For issues or questions, please check the code documentation or modify according to your needs.