Files
tilbudgivern/docs/features/INSTALLATION_MANUAL_INTEGRATION.md
alexpolo1 4a372d2e28 clean up
2025-10-30 18:28:58 +00:00

6.0 KiB

Installation Manual Integration in Quote Generation

Overview

Updated the quote and PDF generation services to use installation manuals (montagevejledninger) from the database instead of hardcoded descriptions.

Changes Made

1. pdfGenerationService.js

Location: backend/src/services/pdfGenerationService.js

Changes:

  • Made generateWorkDescription() async
  • Queries installation_manuals table for each material
  • Extracts installation steps and key points from database
  • Displays top 5 installation steps per material
  • Shows key points/tips for each material
  • Falls back to generic descriptions if no manual found
  • Updated HTML generation to await the async method

Example Output:

MONTAGE INSTRUKTIONER:

280 Montagevejledning Boelgepladetag (Cembrit)
  1. Kontroller rethed på lægter og spær med retholt eller snor
  2. Monter Cembrit Plastudhængsklodser med ventilation ved tagfod
  3. Fastgør lægter i henhold til gældende anvisninger
  4. Placer Cembrit Bølgeplader på lægterne
  5. Monter 2 tagskruer i hver bølgeplade
  
  Vigtige punkter:
  • Sørg for minimum 14˚ taghældning
  • Fjern bore- og skærestøv straks efter bearbejdning
  • Opbevar plader på tørt og plant underlag

2. quoteTemplateService.js

Location: backend/src/services/quoteTemplateService.js

Changes:

  • Made generateWorkDescription() async
  • Same installation manual integration as pdfGenerationService
  • Includes Smart Pakker descriptions (already existing)
  • Includes task descriptions from project_tasks table
  • Updated call site to await the method

Priority Order:

  1. Smart Pakker descriptions (if available)
  2. Task descriptions from database (if available)
  3. Installation manual steps (from materials)
  4. Fallback to generic material-based descriptions

3. Database Integration

Table Used: installation_manuals

Key Columns:

  • product_name - Material name (used for matching)
  • manufacturer - Manufacturer name
  • installation_steps - JSON array of installation steps
  • key_points - JSON array of important tips/notes
  • time_estimate_per_unit - Time estimate for labor calculations
  • required_tools - JSON array of required tools
  • safety_requirements - JSON array of safety notes

Query Logic:

SELECT product_name, manufacturer, installation_steps, key_points
FROM installation_manuals
WHERE LOWER(product_name) LIKE LOWER('%material_name%')
ORDER BY created_at DESC
LIMIT 1

Benefits

1. Data-Driven Descriptions

  • No more hardcoded descriptions
  • Descriptions come from actual installation manuals
  • Easy to update via database

2. Professional & Accurate

  • Real manufacturer installation instructions
  • Step-by-step guidance
  • Safety notes and key points included

3. Scalable

  • Add new materials by uploading their installation manuals
  • System automatically finds and uses them
  • No code changes needed for new materials

4. Fallback Safety

  • If no manual found, falls back to generic descriptions
  • Never shows empty descriptions
  • Maintains professional appearance

Usage

Adding New Installation Manuals

Upload a PDF and the system will extract:

  1. Product name and manufacturer
  2. Installation steps (parsed into array)
  3. Key points and safety notes
  4. Time estimates for labor

Or insert directly via SQL:

INSERT INTO installation_manuals 
(product_name, manufacturer, installation_steps, key_points)
VALUES (
  'Cembrit Bølgeplader B7',
  'Cembrit',
  '["Step 1", "Step 2", "Step 3"]',
  '["Vigtig punkt 1", "Vigtig punkt 2"]'
);

Testing

Generate a quote for a project:

curl -X POST http://localhost:4031/api/quotes/generate-static \
  -H "Content-Type: application/json" \
  -d '{"projectId": 19, "calculationId": 1}'

The work description will now include installation manual steps!

OpenAI Service Integration

The openaiService.js can be used to:

  • Generate enhanced quote text with AI
  • Refine existing quotes based on feedback
  • Classify and clean OCR-extracted installation manuals

Smart Package Management

The smartPackageManagementService.js already uses installation manuals for:

  • Package work descriptions
  • Task step-by-step instructions
  • Time estimates per task

Database Schema

Current installation_manuals table structure:

id                     INT(11) AUTO_INCREMENT
product_name           VARCHAR(255)
manufacturer           VARCHAR(255)
manual_url             TEXT
manual_filename        VARCHAR(255)
manual_type            ENUM('installation','manual','safety')
installation_steps     LONGTEXT (JSON)
time_estimate_per_unit DECIMAL(5,2)
time_unit              ENUM('per_sqm','per_piece','per_project')
required_tools         LONGTEXT (JSON)
safety_requirements    LONGTEXT (JSON)
material_requirements  LONGTEXT (JSON)
skill_level            ENUM('let','medium','svær')
weather_conditions     TEXT
key_points             LONGTEXT (JSON)
created_at             TIMESTAMP
updated_at             TIMESTAMP

Next Steps

  1. Add more installation manuals - Upload PDFs for common materials
  2. AI Enhancement - Use OpenAI to enhance descriptions when needed
  3. Multi-language Support - Store manuals in multiple languages
  4. Image Support - Include diagrams from installation manuals
  5. Video Links - Add links to installation video tutorials

Status

COMPLETED - Backend services updated and restarted (54th restart) TESTED - Installation manual from database successfully parsed FALLBACK - Generic descriptions work when manual not found PENDING - Test with real project containing materials with manuals

Files Changed

  1. /backend/src/services/pdfGenerationService.js - Made async, added manual lookup
  2. /backend/src/services/quoteTemplateService.js - Made async, added manual lookup
  3. PM2 restart count: 54

Date: 2025-10-25
Author: GitHub Copilot
Status: Deployed to production