diff --git a/scripts/build-fastreport-cli.sh b/scripts/build-fastreport-cli.sh new file mode 100755 index 00000000..b9b9e587 --- /dev/null +++ b/scripts/build-fastreport-cli.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash +set -e + +SCRIPT_VERSION="0.0.1" + +# ===================================================== +# FASTREPORT CLI Build Script +# ----------------------------------------------------- +# Generación de ejecutables .NET para Linux y Windows +# ===================================================== +# Uso: +# ./build-fastreport-cli.sh +# +# ===================================================== + +PROJECT="../tools/fastreport-cli/FastReportCliGenerator.csproj" +OUTPUT="../tools/fastreport-cli/publish" +CONFIG="Release" + +echo "🛠️ Build para Linux x64..." +dotnet publish "$PROJECT" \ + -c $CONFIG \ + -r linux-x64 \ + --self-contained true \ + -p:PublishSingleFile=true \ + -p:IncludeNativeLibrariesForSelfExtract=true \ + -o "$OUTPUT/linux" + +echo "🛠️ Build para Windows x64..." +dotnet publish "$PROJECT" \ + -c $CONFIG \ + -r win-x64 \ + --self-contained true \ + -p:PublishSingleFile=true \ + -p:IncludeNativeLibrariesForSelfExtract=true \ + -o "$OUTPUT/windows" + +echo "✅ Builds generados en $OUTPUT/" diff --git a/tools/fastreport-cli/.gitignore b/tools/fastreport-cli/.gitignore new file mode 100644 index 00000000..c1addb6c --- /dev/null +++ b/tools/fastreport-cli/.gitignore @@ -0,0 +1,484 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. +## +## Get latest from `dotnet new gitignore` + +# dotenv files +.env + +# User-specific files +*.rsuser +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Mono auto generated files +mono_crash.* + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +[Ww][Ii][Nn]32/ +[Aa][Rr][Mm]/ +[Aa][Rr][Mm]64/ +bld/ +[Bb]in/ +[Oo]bj/ +[Ll]og/ +[Ll]ogs/ + +# Visual Studio 2015/2017 cache/options directory +.vs/ +# Uncomment if you have tasks that create the project's static files in wwwroot +#wwwroot/ + +# Visual Studio 2017 auto generated files +Generated\ Files/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUnit +*.VisualState.xml +TestResult.xml +nunit-*.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +# Benchmark Results +BenchmarkDotNet.Artifacts/ + +# .NET +project.lock.json +project.fragment.lock.json +artifacts/ + +# Tye +.tye/ + +# ASP.NET Scaffolding +ScaffoldingReadMe.txt + +# StyleCop +StyleCopReport.xml + +# Files built by Visual Studio +*_i.c +*_p.c +*_h.h +*.ilk +*.meta +*.obj +*.iobj +*.pch +*.pdb +*.ipdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*_wpftmp.csproj +*.log +*.tlog +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opendb +*.opensdf +*.sdf +*.cachefile +*.VC.db +*.VC.VC.opendb + +# Visual Studio profiler +*.psess +*.vsp +*.vspx +*.sap + +# Visual Studio Trace Files +*.e2e + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# AxoCover is a Code Coverage Tool +.axoCover/* +!.axoCover/settings.json + +# Coverlet is a free, cross platform Code Coverage Tool +coverage*.json +coverage*.xml +coverage*.info + +# Visual Studio code coverage results +*.coverage +*.coveragexml + +# NCrunch +_NCrunch_* +.*crunch*.local.xml +nCrunchTemp_* + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +# publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# Note: Comment the next line if you want to checkin your web deploy settings, +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# Microsoft Azure Web App publish settings. Comment the next line if you want to +# checkin your Azure Web App publish settings, but sensitive information contained +# in these scripts will be unencrypted +PublishScripts/ + +# NuGet Packages +*.nupkg +# NuGet Symbol Packages +*.snupkg +# The packages folder can be ignored because of Package Restore +**/[Pp]ackages/* +# except build/, which is used as an MSBuild target. +!**/[Pp]ackages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/[Pp]ackages/repositories.config +# NuGet v3's project.json files produces more ignorable files +*.nuget.props +*.nuget.targets + +# Microsoft Azure Build Output +csx/ +*.build.csdef + +# Microsoft Azure Emulator +ecf/ +rcf/ + +# Windows Store app package directories and files +AppPackages/ +BundleArtifacts/ +Package.StoreAssociation.xml +_pkginfo.txt +*.appx +*.appxbundle +*.appxupload + +# Visual Studio cache files +# files ending in .cache can be ignored +*.[Cc]ache +# but keep track of directories ending in .cache +!?*.[Cc]ache/ + +# Others +ClientBin/ +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.jfm +*.pfx +*.publishsettings +orleans.codegen.cs + +# Including strong name files can present a security risk +# (https://github.com/github/gitignore/pull/2483#issue-259490424) +#*.snk + +# Since there are multiple workflows, uncomment next line to ignore bower_components +# (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) +#bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm +ServiceFabricBackup/ +*.rptproj.bak + +# SQL Server files +*.mdf +*.ldf +*.ndf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings +*.rptproj.rsuser +*- [Bb]ackup.rdl +*- [Bb]ackup ([0-9]).rdl +*- [Bb]ackup ([0-9][0-9]).rdl + +# Microsoft Fakes +FakesAssemblies/ + +# GhostDoc plugin setting file +*.GhostDoc.xml + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat +node_modules/ + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + +# Visual Studio 6 auto-generated workspace file (contains which files were open etc.) +*.vbw + +# Visual Studio 6 auto-generated project file (contains which files were open etc.) +*.vbp + +# Visual Studio 6 workspace and project file (working project files containing files to include in project) +*.dsw +*.dsp + +# Visual Studio 6 technical files +*.ncb +*.aps + +# Visual Studio LightSwitch build output +**/*.HTMLClient/GeneratedArtifacts +**/*.DesktopClient/GeneratedArtifacts +**/*.DesktopClient/ModelManifest.xml +**/*.Server/GeneratedArtifacts +**/*.Server/ModelManifest.xml +_Pvt_Extensions + +# Paket dependency manager +.paket/paket.exe +paket-files/ + +# FAKE - F# Make +.fake/ + +# CodeRush personal settings +.cr/personal + +# Python Tools for Visual Studio (PTVS) +__pycache__/ +*.pyc + +# Cake - Uncomment if you are using it +# tools/** +# !tools/packages.config + +# Tabs Studio +*.tss + +# Telerik's JustMock configuration file +*.jmconfig + +# BizTalk build output +*.btp.cs +*.btm.cs +*.odx.cs +*.xsd.cs + +# OpenCover UI analysis results +OpenCover/ + +# Azure Stream Analytics local run output +ASALocalRun/ + +# MSBuild Binary and Structured Log +*.binlog + +# NVidia Nsight GPU debugger configuration file +*.nvuser + +# MFractors (Xamarin productivity tool) working folder +.mfractor/ + +# Local History for Visual Studio +.localhistory/ + +# Visual Studio History (VSHistory) files +.vshistory/ + +# BeatPulse healthcheck temp database +healthchecksdb + +# Backup folder for Package Reference Convert tool in Visual Studio 2017 +MigrationBackup/ + +# Ionide (cross platform F# VS Code tools) working folder +.ionide/ + +# Fody - auto-generated XML schema +FodyWeavers.xsd + +# VS Code files for those working on multiple tools +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +# Windows Installer files from build outputs +*.cab +*.msi +*.msix +*.msm +*.msp + +# JetBrains Rider +*.sln.iml +.idea + +## +## Visual studio for Mac +## + + +# globs +Makefile.in +*.userprefs +*.usertasks +config.make +config.status +aclocal.m4 +install-sh +autom4te.cache/ +*.tar.gz +tarballs/ +test-results/ + +# Mac bundle stuff +*.dmg +*.app + +# content below from: https://github.com/github/gitignore/blob/master/Global/macOS.gitignore +# General +.DS_Store +.AppleDouble +.LSOverride + +# Icon must end with two \r +Icon + + +# Thumbnails +._* + +# Files that might appear in the root of a volume +.DocumentRevisions-V100 +.fseventsd +.Spotlight-V100 +.TemporaryItems +.Trashes +.VolumeIcon.icns +.com.apple.timemachine.donotpresent + +# Directories potentially created on remote AFP share +.AppleDB +.AppleDesktop +Network Trash Folder +Temporary Items +.apdisk + +# content below from: https://github.com/github/gitignore/blob/master/Global/Windows.gitignore +# Windows thumbnail cache files +Thumbs.db +ehthumbs.db +ehthumbs_vista.db + +# Dump file +*.stackdump + +# Folder config file +[Dd]esktop.ini + +# Recycle Bin used on file shares +$RECYCLE.BIN/ + +# Windows Installer files +*.cab +*.msi +*.msix +*.msm +*.msp + +# Windows shortcuts +*.lnk + +# Vim temporary swap files +*.swp diff --git a/tools/fastreport-cli/FastReportCliGenerator.csproj b/tools/fastreport-cli/FastReportCliGenerator.csproj new file mode 100644 index 00000000..ea92c89e --- /dev/null +++ b/tools/fastreport-cli/FastReportCliGenerator.csproj @@ -0,0 +1,24 @@ + + + + Exe + net10.0 + enable + enable + true + true + win-x64;linux-x64 + + + + 1.0 + 1.0 + 1.0 + + + + + + + + diff --git a/tools/fastreport-cli/Program.cs b/tools/fastreport-cli/Program.cs new file mode 100644 index 00000000..e25dd7f4 --- /dev/null +++ b/tools/fastreport-cli/Program.cs @@ -0,0 +1,106 @@ +using FastReport; +using FastReport.Data.JsonConnection; +using FastReport.Export.Html; +using FastReport.Export.PdfSimple; +using System; +using System.Reflection; + +class Program +{ + static int Main(string[] args) + { + // Si el usuario pasa --version, mostrar versión y salir + if (args.Length == 1 && (args[0] == "--version" || args[0] == "-v")) + { + var version = Assembly.GetExecutingAssembly().GetName().Version; + Console.WriteLine($"FastReportCliGenerator version {version}"); + return 0; + } + + Console.WriteLine($"Running FastReportCliGenerator version {Assembly.GetExecutingAssembly().GetName().Version}"); + if (args.Length < 4) + { + Console.Error.WriteLine("Usage: FastReportCliGenerator --format="); + return 1; + } + + + string frxPath = args[0]; + string jsonPath = args[1]; + string outputPath = args[2]; + string formatArg = args[3].ToLower(); + + // Extrae el formato + string format = "html"; + if (formatArg.StartsWith("--format=")) + { + format = formatArg.Split('=')[1]; + } + + try + { + // Leer JSON en memoria + string jsonData = File.ReadAllText(jsonPath); + + using var report = new Report(); + + // Cargar el informe + report.Load(frxPath); + + // 2) Busca la conexión JSON ya definida + JsonDataSourceConnection? jsonConn = null; + foreach (var conn in report.Dictionary.Connections) + { + if (conn is JsonDataSourceConnection jdc) + { + jsonConn = jdc; + break; + } + } + + if (jsonConn == null) + { + throw new Exception("No JSON data connection found in report."); + } + + // 3) Cambia la cadena de conexión para usar el JSON real + // "Json=" es la clave usada por FastReport para indicar JSON embebido + jsonConn.ConnectionString = $"Json={jsonData}"; + + // 4) Crea las tablas internas basadas en ese JSON + jsonConn.CreateAllTables(); + + // 5) Preparar el reporte + report.Prepare(); + + if (format == "pdf") + { + // Exportar a PDF + using var pdfExport = new PDFSimpleExport(); + using var fs = new FileStream(outputPath, FileMode.Create); + pdfExport.Export(report, fs); + Console.WriteLine($"Generated PDF: {outputPath}"); + } + else + { + // Exportar a HTML + using var htmlExport = new HTMLExport + { + EmbedPictures = true, + SinglePage = true, + SubFolder = false + }; + using var fs = new FileStream(outputPath, FileMode.Create); + report.Export(htmlExport, fs); + Console.WriteLine($"Generated HTML: {outputPath}"); + } + + return 0; + } + catch (Exception ex) + { + Console.Error.WriteLine("Error generating report: " + ex.Message); + return 2; + } + } +} diff --git a/tools/fastreport-cli/README.md b/tools/fastreport-cli/README.md new file mode 100644 index 00000000..2437ed17 --- /dev/null +++ b/tools/fastreport-cli/README.md @@ -0,0 +1,153 @@ +# 📘 FastReport CLI — Generador de informes HTML/PDF + +Este proyecto es un **ejecutable .NET CLI** que carga plantillas `.frx`, inyecta datos en formato JSON usando **JsonDataConnection** y exporta el informe resultante a **HTML**. Ideal para integrarse desde otros servicios (p. ej., Node.js) y generar facturas, listados u otros documentos. + + + + +## 🛠️ Requisitos previos + +Antes de compilar o ejecutar este proyecto, necesitas: + +### 💡 1. **Instalar .NET 10 SDK** + +.NET 10 es la versión recomendada con soporte moderno (mensajes y descargas oficiales disponibles en la web de Microsoft). [Microsoft](https://dotnet.microsoft.com/en-us/download/dotnet/10.0) + + + + +### 🐧 **Ubuntu / Linux** + + + 1. Abre una terminal. + + 2. Actualiza la caché de paquetes: + + + 3. Instala el SDK de .NET 10: + + + 4. Verifica la instalación: + + +Esto instalará las herramientas necesarias para compilar y ejecutar aplicaciones .NET. [Microsoft Learn](https://learn.microsoft.com/en-us/dotnet/core/install/linux-ubuntu-install) + +**Nota:** Si no está disponible en los repositorios puede que necesites usar el script oficial `dotnet-install.sh` o los paquetes binarios de la web de .NET. [Microsoft Learn](https://learn.microsoft.com/es-es/dotnet/core/install/linux-scripted-manual) + + + + + +### 🪟 **Windows** + + + 1. Descarga el instalador del SDK de .NET 10 desde la página oficial de descargas de .NET. [Microsoft](https://dotnet.microsoft.com/en-us/download/dotnet/10.0) + + 2. Ejecuta el instalador y sigue los pasos. + + 3. Verifica con: + + +Windows instalará todo lo necesario para compilar y ejecutar proyectos .NET. + + + + +## 📁 Estructura del proyecto + +El proyecto CLI está bajo una carpeta como: + +Este proyecto usa **FastReport.OpenSource** y **JsonDataConnection** para leer JSON y producir HTML. + + + + +## 🧱 Compilar el ejecutable + +Una vez instalado .NET 10 SDK, abre la terminal o línea de comando en la raíz del proyecto y ejecuta: + +Esto compilará el proyecto en modo `Release`. + + + + +## 📦 Publicar ejecutables (Linux y Windows) + +Puedes generar **ejecutables independientes (self-contained)** para cada plataforma. + +### 🐧 Linux + + + +### 🪟 Windows + + +Esto generará binarios en: + +Los ejecutables **no requieren .NET preinstalado** para ejecutarse. + + + + +## 🧪 Ejecutar el generador + +Una vez publicado, puedes ejecutar el generador desde shell con: + +o en Windows. + + + + + +## 📌 Integración desde otras aplicaciones + +Puedes invocar este ejecutable desde Node.js u otros servicios usando la ruta y parámetros indicados, por ejemplo usando `child_process` en Node.js para generar HTML y luego convertirlo a PDF con Puppeteer o similar. + + + + +## ⚠️ Requisitos adicionales en Linux + +Si tu reporte usa gráficos o fuentes, puede necesitar librerías gráficas nativas como **libgdiplus** en Linux para compatibilidad con System.Drawing: + +Esto evita errores de carga nativa en tiempo de ejecución (especialmente si FastReport genera gráficos o renderiza texto). (Requisito común para librerías que usan GDI+ en Linux) + + + + +## 🧠 Buenas prácticas + + + - Mantén tu `.frx` y tus datos JSON sincronizados (los campos usados en la plantilla deben estar presentes en tu JSON). + + - Versiona el ejecutable en tus pipelines o CI para que siempre sepas qué versión se está usando. + + - Genera el HTML desde .NET y luego conviértelo a PDF en tu API principal según necesites. + + + + + +## 📦 Resumen de comandos útiles + +| Acción | Comando | +| ------------------------------ | ------------------------------------------------------------ | +| Instalar .NET 10 SDK en Ubuntu | `sudo apt install -y dotnet-sdk-10.0` ([Microsoft Learn][1]) | +| Ver versión de .NET | `dotnet --version` | +| Compilar proyecto | `dotnet build …` | +| Publicar para Linux | `dotnet publish … -r linux-x64` | +| Publicar para Windows | `dotnet publish … -r win-x64` | + +[1]: https://learn.microsoft.com/en-us/dotnet/core/install/linux-ubuntu-install?utm_source=chatgpt.com "Install .NET SDK or .NET Runtime on Ubuntu" + + + + +## 📚 Recursos + + + - Página oficial de descargas de **.NET 10** — [https://dotnet.microsoft.com/en-US/download/dotnet/10.0](https://dotnet.microsoft.com/en-US/download/dotnet/10.0) [Microsoft](https://dotnet.microsoft.com/en-us/download/dotnet/10.0) + + - Documentación de instalación de .NET en **Ubuntu** — [https://learn.microsoft.com/en-us/dotnet/core/install/linux-ubuntu-install](https://learn.microsoft.com/en-us/dotnet/core/install/linux-ubuntu-install) [Microsoft Learn](https://learn.microsoft.com/en-us/dotnet/core/install/linux-ubuntu-install) + + - Documentación de instalación en **Windows** — [https://learn.microsoft.com/es-es/dotnet/core/install/windows](https://learn.microsoft.com/es-es/dotnet/core/install/windows) [Microsoft Learn](https://learn.microsoft.com/es-es/dotnet/core/install/windows) diff --git a/tools/fastreport-cli/publish/linux/FastReportCliGenerator b/tools/fastreport-cli/publish/linux/FastReportCliGenerator new file mode 100755 index 00000000..3c6346c9 Binary files /dev/null and b/tools/fastreport-cli/publish/linux/FastReportCliGenerator differ diff --git a/tools/fastreport-cli/publish/windows/FastReportCliGenerator.exe b/tools/fastreport-cli/publish/windows/FastReportCliGenerator.exe new file mode 100755 index 00000000..331db3ea Binary files /dev/null and b/tools/fastreport-cli/publish/windows/FastReportCliGenerator.exe differ diff --git a/uecko-erp.sln b/uecko-erp.sln new file mode 100644 index 00000000..e6369d30 --- /dev/null +++ b/uecko-erp.sln @@ -0,0 +1,32 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.5.2.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tools", "tools", "{07C2787E-EAC7-C090-1BA3-A61EC2A24D84}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "fastreport-cli", "fastreport-cli", "{1C34789F-0E1A-CA83-9858-BEAA929278B6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FastReportCliGenerator", "tools\fastreport-cli\FastReportCliGenerator.csproj", "{A8ED47CA-7B74-F26D-058D-6D6FD981B253}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {A8ED47CA-7B74-F26D-058D-6D6FD981B253}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A8ED47CA-7B74-F26D-058D-6D6FD981B253}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A8ED47CA-7B74-F26D-058D-6D6FD981B253}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A8ED47CA-7B74-F26D-058D-6D6FD981B253}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {1C34789F-0E1A-CA83-9858-BEAA929278B6} = {07C2787E-EAC7-C090-1BA3-A61EC2A24D84} + {A8ED47CA-7B74-F26D-058D-6D6FD981B253} = {1C34789F-0E1A-CA83-9858-BEAA929278B6} + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {AF858B63-A8CD-4661-B6E0-451742E4C40E} + EndGlobalSection +EndGlobal