Created
December 18, 2019 00:07
-
-
Save kadzany/30fb57d43c5bdf664cdf3ac0efc9f81c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Mpdf\Mpdf; | |
use Mpdf\MpdfException; | |
class LatihanGeneratorService extends BaseGeneratorService | |
{ | |
function generate() | |
{ | |
$mpdf = new Mpdf(); | |
$simpegReportingService = new SimpegReportingService(new SimpegReportingDao()); | |
$result = $simpegReportingService->getReportingBySqlResult(' | |
select | |
nama, | |
case when status then \'Stock Ada\' | |
else \'Stock Habis\' end as \'status\', | |
tingkat_pendidikan | |
from | |
latihan | |
order by id; | |
'); | |
$tblString = '<table cellspacing="0" width="100%">'; | |
$tblString .= '<thead><tr> | |
<td align="center" width="5%" style="font-weight: bold; background-color: lightblue; font-family: Arial;">NO</td> | |
<td align="center" width="40%" style="font-weight: bold; background-color: lightblue; font-family: Arial;">NAMA</td> | |
<td align="center" width="40%" style="font-weight: bold; background-color: lightblue; font-family: Arial;">STATUS</td> | |
<td align="center" width="15%" style="font-weight: bold; background-color: lightblue; font-family: Arial;">TINGKAT PENDIDIKAN</td></tr></thead>'; | |
// empty data template if data is 0 | |
if(count($result->getData()) == 0){ | |
$tblString .= '<tr>'; | |
$tblString .= '<td colspan="4"> Data not found </td>'; | |
$tblString .= '</tr>'; | |
} | |
$num = 1; | |
foreach ($result->getData() as $datum) { | |
$tblString .= '<tr>'; | |
$tblString .= '<td>'; | |
$tblString .= $num; | |
$tblString .= '</td>'; | |
$tblString .= '<td>'; | |
$tblString .= $datum['nama']; | |
$tblString .= '</td>'; | |
$tblString .= '<td align="center">'; | |
$tblString .= $datum['status']; | |
$tblString .= '</td>'; | |
$tblString .= '<td align="right">'; | |
$tblString .= $datum['tingkat_pendidikan']; | |
$tblString .= '</td>'; | |
$tblString .= '</tr>'; | |
$num++; | |
} | |
$tblString .= '</table>'; | |
$htmlString = ' | |
<html> | |
<head> | |
<style> | |
h4{ | |
font-family: Arial; | |
} | |
table{ | |
border-top: 1px solid black; | |
border-left: 1px solid black; | |
} | |
td{ | |
border-bottom: 1px solid black; | |
border-right: 1px solid black; | |
font-family: Arial; | |
font-size: 11px; | |
margin: 0px; | |
padding: 5px; | |
} | |
</style> | |
</head> | |
<body> | |
<h4>REPORT DEMO</h4>'; | |
$htmlString .= $tblString . '</body></html>'; | |
try { | |
$mpdf->WriteHTML($htmlString); | |
} catch (MpdfException $e) { | |
throw $e; | |
} | |
$mpdf->Output(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment