Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mindexpert7546/nutrition-jasper-report

It's represent to get the jasper report the through Services , Table , and more ....
https://github.com/mindexpert7546/nutrition-jasper-report

grails grails3 groovy-language

Last synced: 10 days ago
JSON representation

It's represent to get the jasper report the through Services , Table , and more ....

Awesome Lists containing this project

README

        

# Nutrition-Jasper-Report
It's represent to get the jasper report the through Services , Table , and more ....

![Screenshot 2023-11-15 172909](https://github.com/mindexpert7546/Nutrition-Jasper-Report/assets/89348788/1f6b9a19-4759-4e7b-a003-4b9807275eb3)
![Screenshot 2023-11-15 172929](https://github.com/mindexpert7546/Nutrition-Jasper-Report/assets/89348788/d37ace40-651d-470e-bc3d-6f75d14e40c8)

## Dependency grails 3.x
```
//Extra dependency to getting the jasper report
compile "com.lowagie:itext:2.1.7"
compile("net.sf.jasperreports:jasperreports:5.6.1") {
exclude group: 'antlr', module: 'antlr'
exclude group: 'commons-logging', module: 'commons-logging'
exclude group: 'org.apache.ant', module: 'ant'
exclude group: 'mondrian', module: 'mondrian'
exclude group: 'commons-javaflow', module: 'commons-javaflow'
exclude group: 'net.sourceforge.barbecue', module: 'barbecue'
exclude group: 'xml-apis', module: 'xml-apis'
exclude group: 'xalan', module: 'xalan'
exclude group: 'org.codehaus.groovy', module: 'groovy-all'
exclude group: 'org.hibernate ', module: 'hibernate'
exclude group: 'javax.xml.soap', module: 'saaj-api'
exclude group: 'javax.servlet', module: 'servlet-api'
exclude group: 'org.springframework', module: 'spring-core'
exclude group: 'org.beanshell', module: 'bsh'
exclude group: 'org.springframework', module: 'spring-beans'
exclude group: 'jaxen', module: 'jaxen'
exclude group: 'net.sf.barcode4j ', module: 'barcode4j'
exclude group: 'org.apache.xmlgraphics', module: 'batik-svg-dom'
exclude group: 'org.apache.xmlgraphics', module: 'batik-xml'
exclude group: 'org.apache.xmlgraphics', module: 'batik-awt-util'
exclude group: 'org.apache.xmlgraphics', module: 'batik-dom'
exclude group: 'org.apache.xmlgraphics', module: 'batik-css'
exclude group: 'org.apache.xmlgraphics', module: 'batik-gvt'
exclude group: 'org.apache.xmlgraphics', module: 'batik-script'
exclude group: 'org.apache.xmlgraphics', module: 'batik-svggen'
exclude group: 'org.apache.xmlgraphics', module: 'batik-util'
exclude group: 'org.apache.xmlgraphics', module: 'batik-bridge'
exclude group: 'javax.persistence', module: 'persistence-api'
exclude group: 'eclipse', module: 'jdtcore'
exclude group: 'org.olap4j', module: 'olap4j'
}

compile "org.apache.poi:poi:3.10-FINAL"
compile "commons-io:commons-io:2.5"
compile 'net.sf.jasperreports:jasperreports:6.20.0'
```
## Sample code for Domain class
### Nutrition Details
```
package com.iinterchange

class NutritionDetails {
String nutrient
int total
int goal
String metric
static constraints = {
metric blank:true
}
}
```
### Profile Details
```
package com.iinterchange

class ProfileDetails {

String name
String dob
int age

static constraints = {
}
}
```
## Service Class for Jasper Report

```
package com.iinterchange

import grails.transaction.Transactional

import net.sf.jasperreports.engine.JasperCompileManager
import net.sf.jasperreports.engine.JasperExportManager
import net.sf.jasperreports.engine.JasperFillManager
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource

@Transactional
class JasperReportService {

def grailsApplication

def generateProductReport(def data, Map parameters) {
// Compile the JasperReport template
def reportPath = grailsApplication.parentContext.getResource("./reports/nutritionReport.jrxml").file.toString()
def jasperReport = JasperCompileManager.compileReport(reportPath)

// Fill the report with data and parameters
def jasperPrint = JasperFillManager.fillReport(
jasperReport,
parameters,
new JRBeanCollectionDataSource(data)
)

return jasperPrint
}
}

```
## Controller code :
```
package com.iinterchange

import grails.transaction.Transactional
import net.sf.jasperreports.engine.JasperExportManager
import com.iinterchange.NutritionDetails
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource

@Transactional
class ProfileDetailsController {

def jasperReportService

def index() {
// Fetch data from the database or any other source
def data = ProfileDetails.list()
def nutritionDetailsList = NutritionDetails.list()
JRBeanCollectionDataSource nutritionDataSource= new JRBeanCollectionDataSource(nutritionDetailsList)

// Create parameters map
def fileParams = [:]

if (data) {
// If data is not empty, fill parameters
def firstProfile = data.first()
fileParams.put("name", firstProfile.name)
fileParams.put("dob", firstProfile.dob)
fileParams.put("age", firstProfile.age)
fileParams.put("MainDataSet",nutritionDataSource)
// Add more parameters as needed
} else {
// If data is empty, use default values
fileParams.put("name", "Default Name")
fileParams.put("dob", "Default DOB")
fileParams.put("age", 0) // Default age
// Add more default values as needed
}

// Generate the Jasper report using the service
def jasperPrint = jasperReportService.generateProductReport(data, fileParams)

// Export the report to PDF and send it as the response
response.setHeader('Content-Disposition', 'inline; filename=ProductReport.pdf')
response.setContentType('application/pdf')
JasperExportManager.exportReportToPdfStream(jasperPrint, response.outputStream)
}
}
```
## Jasper Code :
```



<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>


<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>


<box>
<pen lineWidth="0.5" lineColor="#000000"/>
<topPen lineWidth="0.5" lineColor="#000000"/>
<leftPen lineWidth="0.5" lineColor="#000000"/>
<bottomPen lineWidth="0.5" lineColor="#000000"/>
<rightPen lineWidth="0.5" lineColor="#000000"/>
</box>







































































































































































```