---
# System prepended metadata

title: Jasper Service PPSDM

---

# Jasper Service PPSDM

## How to Use

Make sure you have defined these attributes in **environment file (.env)** :
* **JASPER_USERNAME** : JasperServer username
* **JASPER_PASSWORD** : JasperServer password
* **JASPER_HOST** : Path to reports folder

### Make URL

This function helps you to **make an url to JasperReport**.

#### Params
* **name** : JasperReport name
* **params** : JasperReport parameter
* **ext** : Extension for the response **(default : html)**

#### Lets Code
```
use App\Services\JasperServerService as Jasper;

...

Jasper::makeURL('jumlah_jenjang', ['id' => 12], 'pdf');
```

### Get HTML

This function helps you **convert JasperServer response to HTML** (**default : html**).

#### Params
* **name** : JasperReport name
* **params** : JasperReport parameter

#### Lets Code
```
use App\Services\JasperServerService as Jasper;

...

Jasper::getHTML('jumlah_jenjang', ['id' => 12]);
```

### Get Response

This function helps you to **get response from JasperServer**. The response depends on the extension that you have defined in **makeUrl** function (**default : html**). 

#### Params
* **name** : JasperReport name
* **params** : JasperReport parameter

#### Lets Code
```
use App\Services\JasperServerService as Jasper;

...

Jasper::getResponse('jumlah_jenjang', ['id' => 12]);
```

### Get File

This function helps you to **convert JasperServer response to file** (**default : pdf**).

#### Params
* **name** : JasperReport name
* **filename** : JasperReport file name
* **params** : JasperReport parameter

#### Lets Code
```
use App\Services\JasperServerService as Jasper;

...

Jasper::getFile('jumlah_jenjang', 'statistics', ['id' => 12], 'pdf');
```

### Embed HTML

This function helps you to **embed JasperReport in laravel blade**.

#### Params
* **name** : JasperReport name

#### Lets Code
```
...
// count_terverifikasi is an example of JasperReport name
@includeJasperHTML(count_terverifikasi)
...
```

### Embed File

This function helps you to **embed JasperReport file in laravel blade**.

#### Lets Code

Add this code in your controller
```
use App\Services\JasperServerService as Jasper;

...

public function jasper($id)
{
    $download = Jasper::getFile(
        'Evaluation_Report',
        'Evaluasi ',
        ['id' => $id]
    );

    return $download;
}
```

Defined the path in your **web.php**
```
...
Route::get('jasper/{id}','Controller@jasper')
    ->name('jasperfile');     
...
```

Use the path you have defined in **iframe tag**
```
...
<div class="ui segment full-width">
    <iframe style="height: 65vh;width: 100%" src="{{ route('jasperfile', $id) }}"></iframe>
</div>
...
```

#### Download File

You can use the embed path to download file, just **defined the url in href attribute**.
```
<a class="ui right floated button red" href="{{ route('jasperfile', $id) }}"><i class="icon print"></i> Print</a>
```

### Embed JasperReport Table

This function helps you to **embed JasperReport table in laravel blade**.

#### Params
* **name** : JasperReport name
* **params** : JasperReport parameters
* **maxCol** : Table column (**default : 30**)

**Note** : 

defined **maxCol** to **remove the unused row**. 
**Unused Row : Row with 0px and 30px (default) height.**

#### Lets Code
```
...
// jumlah_jenjang is an example of JasperReport name
<h1>Jumlah Pejabat JF PPBJ berdasarkan Jenjang</h1>
@includeJasperTable(['name' => 'jumlah_jenjang', 'params' => []])
</div>

...

@push('script')
<script src="{{ asset('js/jasper/script.js') }}" type="text/javascript"></script>
@endpush
```