Skip to content

Commit

Permalink
add new report, close #2
Browse files Browse the repository at this point in the history
  • Loading branch information
giansalex committed Jan 20, 2018
1 parent 87ea4e4 commit d5813db
Show file tree
Hide file tree
Showing 6 changed files with 464 additions and 96 deletions.
7 changes: 0 additions & 7 deletions src/Report/HtmlReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,4 @@ private function getTwig($directory, $options)

return $twig;
}

public function toBase64($image)
{
$content = base64_encode($image);

return $content;
}
}
246 changes: 246 additions & 0 deletions src/Report/Templates/invoice2.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<style type="text/css">
.bold,b,strong{font-weight:700}body{background-repeat:no-repeat;background-position:center center;text-align:center;margin:0}.tabla_borde{border:1px solid #666;border-radius:10px}tr.border_bottom td{border-bottom:1px solid #000}tr.border_top td{border-top:1px solid #666}.table-valores-totales tbody>tr>td{border:0}.table-valores-totales>tbody>tr>td:first-child{text-align:right}.table-valores-totales>tbody>tr>td:last-child{border-bottom:1px solid #666;text-align:right;width:30%}hr,img{border:0}table td{font-size:12px}html{font-family:sans-serif;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%;font-size:10px;-webkit-tap-highlight-color:transparent}a{background-color:transparent}a:active,a:hover{outline:0}img{vertical-align:middle}hr{height:0;-webkit-box-sizing:content-box;-moz-box-sizing:content-box;box-sizing:content-box;margin-top:20px;margin-bottom:20px;border-top:1px solid #eee}table{border-spacing:0;border-collapse:collapse}@media print{blockquote,img,tr{page-break-inside:avoid}*,:after,:before{color:#000!important;text-shadow:none!important;background:0 0!important;-webkit-box-shadow:none!important;box-shadow:none!important}a,a:visited{text-decoration:underline}a[href]:after{content:" (" attr(href) ")"}blockquote{border:1px solid #999}img{max-width:100%!important}p{orphans:3;widows:3}.table{border-collapse:collapse!important}.table td{background-color:#fff!important}}a,a:focus,a:hover{text-decoration:none}*,:after,:before{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}a{color:#428bca;cursor:pointer}a:focus,a:hover{color:#2a6496}a:focus{outline:dotted thin;outline:-webkit-focus-ring-color auto 5px;outline-offset:-2px}h6{font-family:inherit;line-height:1.1;color:inherit;margin-top:10px;margin-bottom:10px}p{margin:0 0 10px}blockquote{padding:10px 20px;margin:0 0 20px;font-size:17.5px;border-left:5px solid #eee}table{background-color:transparent}.table{width:100%;max-width:100%;margin-bottom:20px}h6{font-weight:100;font-size:10px}body{line-height:1.42857143;font-family:"open sans","Helvetica Neue",Helvetica,Arial,sans-serif;background-color:#2f4050;font-size:13px;color:#676a6c;overflow-x:hidden}.table>tbody>tr>td{vertical-align:top;border-top:1px solid #e7eaec;line-height:1.42857;padding:8px}.white-bg{background-color:#fff}td{padding:6}.table-valores-totales tbody>tr>td{border-top:0 none!important}
</style>
</head>
<body class="white-bg" style="font-family:'Verdana'">
{% set cp = doc.company %}
<table width="100%">
<tbody><tr>
<td style="padding:30px; !important">
<table width="100%" height="200px" border="0" aling="center" cellpadding="0" cellspacing="0">
<tbody><tr>
<td width="50%" height="90" align="center">
<span><img src="{{ params.system.logo|image_b64 }}" height="80" style="text-align:center" border="0"></span>
</td>
<td width="5%" height="40" align="center"></td>
<td width="45%" rowspan="2" valign="bottom">
<div class="tabla_borde">
<table width="100%" border="0" height="200" cellpadding="6" cellspacing="0">
<tbody><tr>
<td align="center">
<span style="font-family:Tahoma, Geneva, sans-serif; font-size:29px" text-align="center">{{ doc.tipoDoc|doc_name }}</span>
<br>
<span style="font-family:Tahoma, Geneva, sans-serif; font-size:19px" text-align="center">E L E C T R Ó N I C A</span>
</td>
</tr>
<tr>
<td align="center">
&nbsp;
</td>
</tr>
<tr>
<td align="center">
<span style="font-size:15px" text-align="center">R.U.C.: {{ cp.ruc }}</span>
</td>
</tr>
<tr>
<td align="center">
No.: <span>{{ doc.serie }}-{{ doc.correlativo }}</span>
</td>
</tr>
<tr>
<td align="center">
Nro. R.I. Emisor: <span>{{ params.user.resolucion }}</span>
</td>
</tr>
</tbody></table>
</div>
</td>
</tr>
<tr>
<td valign="bottom">
<div class="tabla_borde">
<table width="96%" height="100%" border="0" border-radius="" cellpadding="9" cellspacing="0">
<tbody><tr>
<td align="center">
<strong><span style="font-size:15px">{{ cp.razonSocial }}</span></strong>
</td>
</tr>
<tr>
<td align="left">
<strong>Dirección: </strong>{{ cp.address.direccion }}
</td>
</tr>
<tr>
<td align="left">
{{ params.user.header|raw }}
</td>
</tr>
</tbody></table>
</div>
</td>
</tr>
</tbody></table>
&nbsp;
<div class="tabla_borde">
{% set cl = doc.client %}
<table width="100%" border="0" cellpadding="5" cellspacing="0">
<tbody><tr>
<td width="60%" height="15" align="left"><strong>
Razón Social:
</strong>&nbsp{{ cl.rznSocial }}
</td>
<td width="40%" height="15" align="left"><strong>
{{ cl.tipoDoc|symbol_docident }}:
</strong>&nbsp; &nbsp;
{{ cl.numDoc }}
</td>
</tr>
<tr>
<td width="60%" height="15" align="left"><strong>Fecha Emisión: </strong>&nbsp; &nbsp; {{ doc.fechaEmision|date('d/m/Y') }}</td>
<td width="40%" height="15" align="left"><strong>Dirección: </strong>&nbsp; &nbsp;
{{ params.user.dir_client }}
</td>
</tr>
<tr>
<td width="60%" height="15" align="left"><strong>Tipo Moneda: </strong>&nbsp; &nbsp; {{ doc.tipoMoneda|name_money }} </td>
<td width="40%" height="15" align="left">
</td>
</tr>
</tbody></table>
</div><br>
{% set moneda = doc.tipoMoneda|symbol_money %}
<div class="tabla_borde">
<table width="100%" border="0" cellpadding="5" cellspacing="0">
<tbody>
<tr>
<td align="center" class="bold">Cantidad</td>
<td align="center" class="bold">Código</td>
<td align="center" class="bold">Descripción</td>
<td align="center" class="bold">Valor Unitario</td>
<td align="center" class="bold">Valor Total</td>
</tr>
{% for det in doc.details %}
<tr class="border_top">
<td align="center">
{{ det.cantidad|n_format }}
{{ det.unidad }}
</td>
<td align="center">
{{ det.codProducto }}
</td>
<td align="center" width="300px">
<span>{{ det.descripcion }}</span><br>
</td>
<td align="center">
{{ moneda }}
{{ det.mtoValorUnitario|n_format }}
</td>
<td align="center">
{{ moneda }}
{{ det.mtoValorVenta|n_format }}
</td>
</tr>
{% endfor %}
</tbody>
</table></div>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tbody><tr>
<td width="50%" valign="top">
<table width="100%" border="0" cellpadding="5" cellspacing="0">
<tbody>
<tr>
<td colspan="4">
<br>
<br>
<span style="font-family:Tahoma, Geneva, sans-serif; font-size:12px" text-align="center"><strong>{{ legend(doc.legends, '1000') }} {{ doc.tipoMoneda|name_money }}.</strong></span>
<br>
<br>
<strong>Información Adicional</strong>
</td>
</tr>
</tbody>
</table>

<table width="100%" border="0" cellpadding="5" cellspacing="0">
<tbody>
<tr class="border_top">
<td width="30%" style="font-size: 10px;">
LEYENDA:
</td>
<td width="70%" style="font-size: 10px;">

</td>
</tr>
{% if params.user.extras is defined %}
{% for item in params.user.extras %}
<tr class="border_top">
<td width="30%" style="font-size: 10px;">
{{ item.name|upper }}:
</td>
<td width="70%" style="font-size: 10px;">
{{ item.value }}
</td>
</tr>
{% endfor %}
{% endif %}
</tbody>
</table>
</td>
<td width="50%" valign="top">
<br>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="table table-valores-totales">
<tbody>
<tr class="border_bottom">
<td align="right"><strong>Op. Gravadas:</strong></td>
<td width="120" align="right"><span>{{ moneda }} {{ doc.mtoOperGravadas|n_format }}</span></td>
</tr>
<tr class="border_bottom">
<td align="right"><strong>Op. Inafectas:</strong></td>
<td width="120" align="right"><span>{{ moneda }} {{ doc.mtoOperInafectas|n_format }}</span></td>
</tr>
<tr class="border_bottom">
<td align="right"><strong>Op. Exoneradas:</strong></td>
<td width="120" align="right"><span>{{ moneda }} {{ doc.mtoOperExoneradas|n_format }}</span></td>
</tr>
<tr>
<td align="right"><strong>IGV:</strong></td>
<td width="120" align="right"><span>{{ moneda }} {{ doc.mtoIGV|n_format }}</span></td>
</tr>
<tr>
<td align="right"><strong>ISC:</strong></td>
<td width="120" align="right"><span>{{ moneda }} {{ doc.mtoISC|n_format }}</span></td>
</tr>
<tr>
<td align="right"><strong>Precio Venta:</strong></td>
<td width="120" align="right"><span id="ride-importeTotal" class="ride-importeTotal">{{ moneda }} {{ doc.mtoImpVenta }}</span></td>
</tr>
<tr>
<td align="right"><strong>Otros Cargos:</strong></td>
<td width="120" align="right"><span>{{ moneda }} {{ doc.sumOtrosCargos|n_format }}</span></td>
</tr>
<tr>
<td align="right"><strong>Otros Tributos:</strong></td>
<td width="120" align="right"><span>{{ moneda }} {{ doc.mtoOtrosTributos|n_format }}</span></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody></table>

<br>
<br>
<div style="page-break-after: always;page-break-inside: avoid;">
<hr style="display: block; height: 1px; border: 0; border-top: 1px solid #666; margin: 20px 0; padding: 0;"><table width="100%" border="0" cellpadding="0" cellspacing="0">
<tbody><tr>
<td width="85%">
{% if params.user.footer is defined %}
<blockquote>
{{ params.user.footer|raw }}
</blockquote>
{% endif %}
</td>
<td width="15%" align="right">
<img src="{{ qrCode(doc)|image_b64 }}" alt="Qr Image">
</td>
</tr>
</tbody></table>
</div>
</td>
</tr>
</tbody></table>
</body></html>
51 changes: 51 additions & 0 deletions tests/Report/HtmlReport2Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?php
/**
* Created by PhpStorm.
* User: Administrador
* Date: 20/01/2018
* Time: 02:21 PM
*/

namespace Tests\Greenter\Report;

class HtmlReport2Test extends \PHPUnit_Framework_TestCase
{
use HtmlReportTrait;

public function testGenReport()
{
$report = $this->getReporter();
$inv = $this->getInvoice();
$report->setTemplate('invoice2.html.twig');

try {
$html = $report->render($inv, $this->getParamters());
$this->assertNotEmpty($html);
} catch (\Exception $e) {
echo $e->getMessage();
$this->assertTrue(false);
}
// file_put_contents('file2.html', $html);
}

private function getParamters()
{
$logo = file_get_contents(__DIR__.'/../Resources/logo.png');

return [
'system' => [
'logo' => $logo,
],
'user' => [
'resolucion' => '212321',
'header' => 'Telf: <b>(056) 123375</b>',
'dir_client' => 'AV ITALIA 23423',
'extras' => [
['name' => 'CONDICION DE PAGO', 'value' => 'Efectivo'],
['name' => 'VENDEDOR', 'value' => 'GITHUB SELLER'],
],
'footer' => file_get_contents(__DIR__.'/../Resources/footer.html'),
]
];
}
}
Loading

0 comments on commit d5813db

Please sign in to comment.