Overview
The transformation process bridges two systems:- Source: Database tables (Compra, CompraItem, Material, Micro)
- Target: Siigo support documents with company-specific product lists
- Separates products by company (Corprecam vs Reciclemos)
- Maps material codes to Siigo product codes
- Structures data for automated form filling
- Handles multi-company workflows
Core Transformation
transfromDs()
Transforms database purchase data into a structured support document.| Parameter | Type | Description |
|---|---|---|
compra | Compra | Purchase record with provider and micro-route info |
compraItems | CompraItem[] | Array of purchased items with quantities and prices |
materiales | Material[] | Material catalog with codes and company associations |
micros | Micro | Micro-route information |
DocumentoSoporte
Transformation Flow
Map Purchase Items
Converts each
CompraItem to a Products object by:- Finding the corresponding material by
mat_id - Extracting the material code
- Copying quantity and unit price
- Including the company ID (
emp_id_fk)
Separate by Company
Uses
reduce() to partition products into two arrays:- Corprecam: Products where
empresa === 1 - Reciclemos: Products where
empresa === 2
Usage Example
Data Mapping
Database to Document:| Source Field | Target Field | Transformation |
|---|---|---|
compra.comp_asociado | proveedor_id | Direct copy |
micros.mic_nom | micro_id | Convert to string |
compraItems[].citem_material | - | Used to lookup material |
materiales[].mat_codigo | productos[].codigo | Material lookup |
compraItems[].citem_cantidad | productos[].cantidad | Direct copy |
compraItems[].citem_valor_unitario | productos[].precio | Direct copy |
materiales[].emp_id_fk | productos[].empresa | Used for company separation |
Workflow Automation
playwright_corprecam_reciclemos()
Automated workflow to create a support document in Siigo using Playwright.| Parameter | Type | Description | Example |
|---|---|---|---|
documentoSoporte | P[] | Array of products to add | [{codigo: "MAT-001", cantidad: 10, precio: 5000}] |
documentoSoporteLabelCode | string | Document type code | "25470" |
bodegaRiohacha | string | Warehouse name | " BODEGA DE RIOHACHA " |
cuentaContable | string | Payment account name | " CAJA RIOHACHA " |
proveedor_id | string | Provider NIT | "900123456" |
USER | string | Siigo username | "[email protected]" |
PASSWORD | string | Siigo password | "password123" |
nit_empresa | string | Company NIT | "900142913" or "901328575" |
Process Each Product
For each product in the array:
- Prepares a new row
- Selects the product by code
- Selects warehouse (first item only, Corprecam only)
- Fills quantity and price
Usage Example
Company-Specific Behavior
Corprecam (900142913):- Document type selection is required
- Warehouse selection happens for the first item
- Uses “CAJA RIOHACHA” account
- No document type selection
- No warehouse selection needed
- Uses “Efectivo” account
Integration with Main Workflow
The transformation functions integrate with the main workflow inmain.ts:
run_playwright() (main.ts:12-41):
Type Definitions
Source Types
Fromtypes/types.ts:
Target Types
Dependencies
Complete Example
End-to-end transformation and automation:Related Documentation
- Core Functions - Browser automation functions used by the workflow
- Helpers - String and retry utilities
- Data Models - Complete type definitions
- Workflow - High-level orchestration