Skip to content

Commit

Permalink
fix filters, update templates
Browse files Browse the repository at this point in the history
  • Loading branch information
giansalex committed Jan 20, 2018
1 parent d5813db commit c092e1a
Show file tree
Hide file tree
Showing 7 changed files with 173 additions and 76 deletions.
13 changes: 5 additions & 8 deletions src/Report/Extension/ReportTwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,17 @@ class ReportTwigExtension extends \Twig_Extension
public function getFilters()
{
return [
new \Twig_SimpleFilter('doc_name', DocumentFilter::class.'::getNameDoc'),
new \Twig_SimpleFilter('symbol_money', DocumentFilter::class.'::getSymbolCurrency'),
new \Twig_SimpleFilter('name_money', DocumentFilter::class.'::getNameCurrency'),
new \Twig_SimpleFilter('symbol_docident', DocumentFilter::class.'::getSymbolDocIdentidad'),
new \Twig_SimpleFilter('image_b64', ImageFilter::class.'::toBase64'),
new \Twig_SimpleFilter('n_format', FormatFilter::class.'::number'),
new \Twig_SimpleFilter('catalog', ['Greenter\Report\Filter\DocumentFilter', 'getValueCatalog']),
new \Twig_SimpleFilter('image_b64', ['Greenter\Report\Filter\ImageFilter', 'toBase64']),
new \Twig_SimpleFilter('n_format', ['Greenter\Report\Filter\FormatFilter', 'number']),
];
}

public function getFunctions()
{
return [
new \Twig_SimpleFunction('legend', ResolveFilter::class.'::getValueLegend'),
new \Twig_SimpleFunction('qrCode', ResolveFilter::class.'::getQr'),
new \Twig_SimpleFunction('legend', ['Greenter\Report\Filter\ResolveFilter', 'getValueLegend']),
new \Twig_SimpleFunction('qrCode', ['Greenter\Report\Filter\ResolveFilter', 'getQr']),
];
}
}
76 changes: 39 additions & 37 deletions src/Report/Filter/DocumentFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,50 +13,52 @@
*/
class DocumentFilter
{
public function getNameDoc($tipo)
{
switch (trim($tipo)) {
case '01': return 'FACTURA';
case '03': return 'BOLETA';
case '07': return 'NOTA DE CRÉDITO';
case '08': return 'NOTA DE DÉBITO';
case '09': return 'GUÍA DE REMISIÓN';
case '20': return 'RETENCIÓN';
case '40': return 'PERCEPCIÓN';
}
/**
* @var array
*/
private $store;

return '';
}

public function getSymbolCurrency($code)
/**
* DocumentFilter constructor.
*/
public function __construct()
{
switch (trim($code)) {
case 'PEN': return 'S/';
case 'USD': return '$';
case 'EUR': return '';
}

return $code;
$this->store = [
'01' => [
'01' => 'FACTURA',
'03' => 'BOLETA',
'07' => 'NOTA DE CRÉDITO',
'08' => 'NOTA DE DÉBITO',
'09' => 'GUÍA DE REMISIÓN',
'20' => 'RETENCIÓN',
'40' => 'PERCEPCIÓN',
],
'02' => [
'PEN' => 'S/',
'USD' => '$',
'EUR' => '',
],
'021' => [
'PEN' => 'SOLES',
'USD' => 'DÓLARES AMERICANOS',
'EUR' => 'EUROS',
],
'06' => [
'0' => 'N/D',
'1' => 'DNI',
'6' => 'RUC',
],
];
}

public function getNameCurrency($code)
public function getValueCatalog($value, $code)
{
switch (trim($code)) {
case 'PEN': return 'SOLES';
case 'USD': return 'DÓLARES AMERICANOS';
case 'EUR': return 'EUROS';
if (!isset($this->store[$code])) {
return '';
}

return $code;
}

public function getSymbolDocIdentidad($code)
{
switch (trim($code)) {
case '1': return 'DNI';
case '6': return 'RUC';
}
$items = $this->store[$code];

return '';
return isset($items[$value]) ? $items[$value] : '';
}
}
16 changes: 14 additions & 2 deletions src/Report/HtmlReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ public function __construct($templatesDir = '', $optionTwig = [])
$templatesDir = __DIR__ . '/Templates';
}

$this->twig = $this->getTwig($templatesDir, $optionTwig);
if (!isset($optionTwig['autoescape'])) {
$optionTwig['autoescape'] = false;
}

$this->twig = $this->buildTwig($templatesDir, $optionTwig);
}

/**
Expand Down Expand Up @@ -72,12 +76,20 @@ public function setTemplate($template)
$this->template = $template;
}

/**
* @return \Twig_Environment
*/
public function getTwig()
{
return $this->twig;
}

/**
* @param $directory
* @param $options
* @return \Twig_Environment
*/
private function getTwig($directory, $options)
private function buildTwig($directory, $options)
{
$loader = new \Twig_Loader_Filesystem($directory);
$twig = new \Twig_Environment($loader, $options);
Expand Down
26 changes: 13 additions & 13 deletions src/Report/Templates/invoice.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@
<div id="client" style="max-width: 60%">
<div class="to">EMITIDO A:</div>
{% set cl = doc.client %}
<h2 class="ruc"><b>{{ cl.tipoDoc|symbol_docident }}</b> {{ cl.numDoc }}</h2>
<h2 class="ruc"><b>{{ cl.tipoDoc|catalog('06') }}</b> {{ cl.numDoc }}</h2>
<span class="name">{{ cl.rznSocial }}</span>
<div class="address"><i>{{ cl.address.direccion }}</i></div>
</div>
<div id="invoice">
{% set serieNro = doc.serie ~ '-' ~ doc.correlativo %}
<h1>{{ doc.tipoDoc|doc_name }} ELECTRÓNICA</h1>
<h1>{{ doc.tipoDoc|catalog('01') }} ELECTRÓNICA</h1>
<h1>{{ serieNro }}</h1>
<div class="date">EMITIDO: {{ doc.fechaEmision|date('d/m/Y') }}</div>
</div>
Expand All @@ -200,7 +200,7 @@
</tr>
</thead>
<tbody>
{% set moneda = doc.tipoMoneda|symbol_money %}
{% set moneda = doc.tipoMoneda|catalog('02') %}
{% for det in doc.details %}
<tr>
<td class="no">{{ det.cantidad|n_format }}</td>
Expand All @@ -218,65 +218,65 @@
<tr>
<td colspan="2"></td>
<td colspan="2">Op. Gravadas</td>
<td>{{ moneda }}{{ doc.mtoOperGravadas|n_format }}</td>
<td>{{ moneda }} {{ doc.mtoOperGravadas|n_format }}</td>
</tr>
{% if doc.mtoOperInafectas %}
<tr>
<td colspan="2"></td>
<td colspan="2">Op. Inafectas</td>
<td>{{ moneda }}{{ doc.mtoOperInafectas|n_format }}</td>
<td>{{ moneda }} {{ doc.mtoOperInafectas|n_format }}</td>
</tr>
{% endif %}
{% if doc.mtoOperExoneradas %}
<tr>
<td colspan="2"></td>
<td colspan="2">Op. Exoneradas</td>
<td>{{ moneda }}{{ doc.mtoOperExoneradas|n_format }}</td>
<td>{{ moneda }} {{ doc.mtoOperExoneradas|n_format }}</td>
</tr>
{% endif %}
{% if doc.mtoOperGratuitas %}
<tr>
<td colspan="2"></td>
<td colspan="2">Op. Gratuitas</td>
<td>{{ moneda }}{{ doc.mtoOperGratuitas|n_format }}</td>
<td>{{ moneda }} {{ doc.mtoOperGratuitas|n_format }}</td>
</tr>
{% endif %}
<tr>
<td colspan="2"></td>
<td colspan="2">IGV (18%)</td>
<td>{{ moneda }}{{ doc.mtoIGV|n_format }}</td>
<td>{{ moneda }} {{ doc.mtoIGV|n_format }}</td>
</tr>
{% if doc.mtoISC %}
<tr>
<td colspan="2"></td>
<td colspan="2">ISC</td>
<td>{{ moneda }}{{ doc.mtoISC|n_format }}</td>
<td>{{ moneda }} {{ doc.mtoISC|n_format }}</td>
</tr>
{% endif %}
{% if doc.mtoOtrosTributos %}
<tr>
<td colspan="2"></td>
<td colspan="2">Otros Tributos</td>
<td>{{ moneda }}{{ doc.mtoOtrosTributos|n_format }}</td>
<td>{{ moneda }} {{ doc.mtoOtrosTributos|n_format }}</td>
</tr>
{% endif %}
<tr>
<td colspan="2"></td>
<td colspan="2">TOTAL</td>
<td>{{ moneda }}{{ doc.mtoImpVenta|n_format }}</td>
<td>{{ moneda }} {{ doc.mtoImpVenta|n_format }}</td>
</tr>
</tfoot>
</table>
<hr>
<div style="margin: 20px 0;width: 100%;text-align: center">
<span>
<b>IMPORTE EN LETRAS</b> {{ legend(doc.legends, '1000') }} {{ doc.tipoMoneda|name_money }}
<b>IMPORTE EN LETRAS</b> {{ legend(doc.legends, '1000') }} {{ doc.tipoMoneda|catalog('021') }}
</span>
</div>
<div class="clearfix">
<div style="float: left">
<div id="notices">
<div class="notice">Representación Impresa de la {{ doc.tipoDoc|doc_name }} ELECTRÓNICA.</div>
<div class="notice">Representación Impresa de la {{ doc.tipoDoc|catalog('01') }} ELECTRÓNICA.</div>
</div>
</div>
<div id="qrcode">
Expand Down
31 changes: 17 additions & 14 deletions src/Report/Templates/invoice2.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
<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">
<td width="45%" rowspan="2" valign="bottom" style="padding-left:0">
<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>
<span style="font-family:Tahoma, Geneva, sans-serif; font-size:29px" text-align="center">{{ doc.tipoDoc|catalog('01') }}</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>
Expand Down Expand Up @@ -51,7 +51,7 @@
</td>
</tr>
<tr>
<td valign="bottom">
<td valign="bottom" style="padding-left:0">
<div class="tabla_borde">
<table width="96%" height="100%" border="0" border-radius="" cellpadding="9" cellspacing="0">
<tbody><tr>
Expand All @@ -74,8 +74,8 @@
</td>
</tr>
</tbody></table>
&nbsp;
<div class="tabla_borde">
{% set moneyName = doc.tipoMoneda|catalog('021') %}
{% set cl = doc.client %}
<table width="100%" border="0" cellpadding="5" cellspacing="0">
<tbody><tr>
Expand All @@ -84,7 +84,7 @@
</strong>&nbsp{{ cl.rznSocial }}
</td>
<td width="40%" height="15" align="left"><strong>
{{ cl.tipoDoc|symbol_docident }}:
{{ cl.tipoDoc|catalog('06') }}:
</strong>&nbsp; &nbsp;
{{ cl.numDoc }}
</td>
Expand All @@ -96,13 +96,13 @@
</td>
</tr>
<tr>
<td width="60%" height="15" align="left"><strong>Tipo Moneda: </strong>&nbsp; &nbsp; {{ doc.tipoMoneda|name_money }} </td>
<td width="60%" height="15" align="left"><strong>Tipo Moneda: </strong>&nbsp; &nbsp; {{ moneyName }} </td>
<td width="40%" height="15" align="left">
</td>
</tr>
</tbody></table>
</div><br>
{% set moneda = doc.tipoMoneda|symbol_money %}
{% set moneda = doc.tipoMoneda|catalog('02') %}
<div class="tabla_borde">
<table width="100%" border="0" cellpadding="5" cellspacing="0">
<tbody>
Expand Down Expand Up @@ -146,7 +146,7 @@
<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>
<span style="font-family:Tahoma, Geneva, sans-serif; font-size:12px" text-align="center"><strong>{{ legend(doc.legends, '1000') }} {{ moneyName }}.</strong></span>
<br>
<br>
<strong>Información Adicional</strong>
Expand Down Expand Up @@ -221,18 +221,21 @@
</td>
</tr>
</tbody></table>

<br>
<br>
<div style="page-break-after: always;page-break-inside: avoid;">
{% if max_items is defined and doc.details|length > max_items %}
<div style="page-break-after:always;"></div>
{% endif %}
<div>
<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>
<blockquote>
{% if params.user.footer is defined %}
{{ params.user.footer|raw }}
</blockquote>
{% endif %}
{% endif %}
<span style="font-size: 8pt">Representación Impresa de la {{ doc.tipoDoc|catalog('01') }} ELECTRÓNICA.</span>
</blockquote>
</td>
<td width="15%" align="right">
<img src="{{ qrCode(doc)|image_b64 }}" alt="Qr Image">
Expand Down
Loading

0 comments on commit c092e1a

Please sign in to comment.