Corpen’s Excel synchronization system lets administrators move large datasets in and out of the platform without manual data entry. Every module that manages master records — associates, demographics, accounting transactions, and insurance policies — ships with its own Export and Import class built onDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/corpentunida-org/corpen/llms.txt
Use this file to discover all available pages before exploring further.
maatwebsite/excel ^3.1 and phpoffice/phpspreadsheet ^1.30. The workflow is always the same: download a template populated with live data, adjust it offline, re-upload, review a preview, and confirm the upsert into the database.
Installed Packages
| Package | Version | Purpose |
|---|---|---|
maatwebsite/excel | ^3.1 | Laravel wrapper for reading and writing Excel files |
phpoffice/phpspreadsheet | ^1.30 | Underlying spreadsheet engine (reads .xlsx, .xls, .csv) |
composer.json and are auto-discovered by Laravel. No manual service provider registration is required.
Export and Import Classes
Corpen organises its Excel classes underapp/Exports/ and app/Imports/, grouped by domain:
Exports
app/Exports/Asociado/AsociadosExport.php— full associate master dump (48 columns)app/Exports/Demografia/DemografiaExport.php— multi-sheet export (Paises, Regiones, Subregiones, Ciudades, Direcciones)app/Exports/Demografia/CiudadExport.php,DireccionExport.php,PaisExport.php,RegionExport.php,SubregionExport.php— individual geographic-level sheets used byDemografiaExportapp/Exports/ReporteSiniestrosExport.php— insurance claims report with styled headers and a summary rowapp/Exports/TransaccionesExport.php— accounting extract transactions
app/Imports/Asociado/AsociadosImport.php— associates upsert with date transformation and boolean inferenceapp/Imports/Cartera/ExcelMorososImport.php— portfolio delinquent-account importapp/Imports/Contabilidad/TransaccionesImport.php— accounting transactions upsert (chunks of 1 000, deduped byid_transaccion)app/Imports/Demografia/DemografiaImport.php— multi-sheet import mapping each tab to a domain import classapp/Imports/ExcelImport.php— insurance policy import (SegPoliza)app/Imports/PolizasImport.php— bulk insurance policy sync with gender and parentesco validationapp/Imports/ExcelExport.php— generic reusable export used by one-off reports
Modules with Excel Sync
| Module | Route prefix | Export downloads | Import uploads |
|---|---|---|---|
| Associates | /asociados/sincronizar | maestro_asociados_<date>.xlsx | Upsert on cedula |
| Demographics | /demograficos/sincronizar | demografia_maestra.xlsx (multi-sheet) | Multi-sheet upsert |
| Accounting | /contabilidad/sincronizar | Data_Transacciones.xlsx | Hash-dedup upsert in batches of 1 000 |
| Insurance claims | /seguros/reclamacion/informe/excel | Siniestros report | — |
How Exports Work
An Export class implementsFromCollection (to pull data from Eloquent) and WithHeadings (to name the columns). Call Excel::download() from a controller action to stream the file directly to the browser.
How Imports Work
An Import class implementsToCollection (or ToModel) and WithHeadingRow so that column names in the first spreadsheet row are used as array keys. After instantiating the import and calling Excel::import(), call getRows() to retrieve the parsed data for validation before touching the database.
Multi-Sheet Imports: Demographics
The Demographics module usesWithMultipleSheets to route each Excel tab to its own import class. The sheet name in the file must match the key in sheets() exactly.
DemografiaExport uses WithMultipleSheets as well, generating the five tabs in a single download so users always get a correctly-named template:
Session-Based Validation UX
Corpen never writes to the database on the first upload. Instead it shows an interactive preview so administrators can catch errors before they propagate. Associates flow — the parsed rows are stored in Laravel Cache (keyed by user ID and timestamp). The preview view shows each row with new / update badges and lets the user correctcedula, nombre1, and apellido1 inline before confirming.
Demographics flow — the uploaded file is saved to storage/app/imports/ via $request->file()->store('imports') and the path is stored in the PHP session. Confirmation triggers Excel::import(new DemografiaImport(), $path) and then deletes the temporary file.
Accounting flow — ExcelSyncController uses Excel::toArray() for a direct row-by-row scan, computes a hash per transaction ({account}-{timestamp}-{amount}-{cedula}), and flags duplicates in memory before rendering the preview. Confirmation sends the edited JSON back as registros_json and runs an upsert in batches of 1 000.
Full Import Workflow
Navigate to the sync page for the target module and click Descargar Excel. The file contains all current records with correct column headers — use it as both a reference and a blank template for new data.
Open the file in Excel or LibreOffice Calc. Keep the header row in row 1 unchanged. Date columns (
fecha_nacimiento, fecha_expedicion, etc.) accept both ISO format (2024-03-15) and Excel serial numbers. Boolean columns (escaneado, cargado_ecm, validado_archivo) accept SI, SÍ, TRUE, VERDADERO, V, or 1.Return to the sync page and upload the modified file. Corpen validates the MIME type (
xlsx, xls, csv) and size (up to 60 MB for accounting, 10 MB for demographics). The file is parsed in memory — no permanent storage occurs at this step.Corpen displays a table showing each row alongside a Nuevo or Actualizar badge and flags any duplicate rows it detected. For associates, you can correct key fields directly in the table. Rows with an empty
cedula are automatically excluded.The accounting sync upsert runs inside
DB::transaction() and processes rows in chunks of 1 000. If the database rejects any chunk — for example, due to a constraint violation — the entire transaction rolls back and no rows are written. Re-upload a corrected file to retry.Styled Reports with WithStyles
ReporteSiniestrosExport demonstrates how to add visual formatting to a report. It implements WithStyles from PhpSpreadsheet to bold the header row, apply a grey fill, and highlight the final summary row in yellow: