Completed
Push — master ( 35135d...676ec5 )
by Esteban De La Fuente
02:22
created

Dte::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * LibreDTE
5
 * Copyright (C) SASCO SpA (https://sasco.cl)
6
 *
7
 * Este programa es software libre: usted puede redistribuirlo y/o
8
 * modificarlo bajo los términos de la Licencia Pública General Affero de GNU
9
 * publicada por la Fundación para el Software Libre, ya sea la versión
10
 * 3 de la Licencia, o (a su elección) cualquier versión posterior de la
11
 * misma.
12
 *
13
 * Este programa se distribuye con la esperanza de que sea útil, pero
14
 * SIN GARANTÍA ALGUNA; ni siquiera la garantía implícita
15
 * MERCANTIL o de APTITUD PARA UN PROPÓSITO DETERMINADO.
16
 * Consulte los detalles de la Licencia Pública General Affero de GNU para
17
 * obtener una información más detallada.
18
 *
19
 * Debería haber recibido una copia de la Licencia Pública General Affero de GNU
20
 * junto a este programa.
21
 * En caso contrario, consulte <http://www.gnu.org/licenses/agpl.html>.
22
 */
23
24
namespace sasco\LibreDTE\Sii\Dte\PDF;
25
26
/**
27
 * Clase para generar el PDF de un documento tributario electrónico (DTE)
28
 * chileno.
29
 * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
30
 * @version 2018-11-04
31
 */
32
class Dte extends \sasco\LibreDTE\PDF
33
{
34
35
    use \sasco\LibreDTE\Sii\Dte\Base\DteImpreso;
36
37
    protected $logo; ///< Datos del logo que se ubicará en el PDF (ruta, datos y/o posición)
38
    protected $papelContinuo = false; ///< Indica si se usa papel continuo o no (=0 papel carta, otro valor contínuo en PDF)
39
    protected $ecl = 5; ///< error correction level para PHP >= 7.0.0
40
    protected $papel_continuo_alto = 5000; ///< Alto exageradamente grande para autocálculo de alto en papel continuo
41
    protected $timbre_pie = true; ///< Indica si el timbre va al pie o no (va pegado al detalle)
42
    protected $item_detalle_posicion = 0; ///< Posición del detalle del item respecto al nombre
43
    protected $detalle_fuente = 10; ///< Tamaño de la fuente para el detalle en hoja carta
44
45
    protected $detalle_cols = [
46
        'CdgItem' => ['title'=>'Código', 'align'=>'left', 'width'=>20],
47
        'NmbItem' => ['title'=>'Item', 'align'=>'left', 'width'=>0],
48
        'IndExe' => ['title'=>'IE', 'align'=>'left', 'width'=>'7'],
49
        'QtyItem' => ['title'=>'Cant.', 'align'=>'right', 'width'=>15],
50
        'UnmdItem' => ['title'=>'Unidad', 'align'=>'left', 'width'=>22],
51
        'PrcItem' => ['title'=>'P. unitario', 'align'=>'right', 'width'=>22],
52
        'DescuentoMonto' => ['title'=>'Descuento', 'align'=>'right', 'width'=>22],
53
        'RecargoMonto' => ['title'=>'Recargo', 'align'=>'right', 'width'=>22],
54
        'MontoItem' => ['title'=>'Total item', 'align'=>'right', 'width'=>22],
55
    ]; ///< Nombres de columnas detalle, alineación y ancho
56
57
    public static $papel = [
58
        0  => 'Hoja carta',
59
        57 => 'Papel contínuo 57mm',
60
        75 => 'Papel contínuo 75mm',
61
        80 => 'Papel contínuo 80mm',
62
    ]; ///< Tamaño de papel que es soportado
63
64
    /**
65
     * Constructor de la clase
66
     * @param papelContinuo =true indica que el PDF se generará en formato papel continuo (si se pasa un número será el ancho del PDF en mm)
67
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
68
     * @version 2016-10-06
69
     */
70
    public function __construct($papelContinuo = false)
71
    {
72
        parent::__construct();
73
        $this->SetTitle('Documento Tributario Electrónico (DTE) de Chile by LibreDTE');
74
        $this->papelContinuo = $papelContinuo === true ? 80 : $papelContinuo;
0 ignored issues
show
Documentation Bug introduced by
It seems like $papelContinuo === true ? 80 : $papelContinuo can also be of type integer. However, the property $papelContinuo is declared as type boolean. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
75
    }
76
77
    /**
78
     * Método que asigna la ubicación del logo de la empresa
79
     * @param logo URI del logo (puede ser local o en una URL)
80
     * @param posicion Posición respecto a datos del emisor (=0 izq, =1 arriba)
81
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
82
     * @version 2016-08-04
83
     */
84
    public function setLogo($logo, $posicion = 0)
85
    {
86
        $this->logo = [
87
            'uri' => $logo,
88
            'posicion' => (int)$posicion,
89
        ];
90
    }
91
92
    /**
93
     * Método que asigna la posición del detalle del Item respecto al nombre
94
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
95
     * @version 2016-08-05
96
     */
97
    public function setPosicionDetalleItem($posicion)
98
    {
99
        $this->item_detalle_posicion = (int)$posicion;
100
    }
101
102
    /**
103
     * Método que asigna el tamaño de la fuente para el detalle
104
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
105
     * @version 2016-08-03
106
     */
107
    public function setFuenteDetalle($fuente)
108
    {
109
        $this->detalle_fuente = (int)$fuente;
110
    }
111
112
    /**
113
     * Método que asigna el ancho e las columnas del detalle desde un arreglo
114
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
115
     * @version 2016-08-03
116
     */
117
    public function setAnchoColumnasDetalle(array $anchos)
118
    {
119
        foreach ($anchos as $col => $ancho) {
120
            if (isset($this->detalle_cols[$col]) and $ancho) {
121
                $this->detalle_cols[$col]['width'] = (int)$ancho;
122
            }
123
        }
124
    }
125
126
    /**
127
     * Método que asigna si el tumbre va al pie (por defecto) o va pegado al detalle
128
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
129
     * @version 2017-10-05
130
     */
131
    public function setTimbrePie($timbre_pie = true)
132
    {
133
        $this->timbre_pie = (bool)$timbre_pie;
134
    }
135
136
    /**
137
     * Método que agrega un documento tributario, ya sea en formato de una
138
     * página o papel contínuo según se haya indicado en el constructor
139
     * @param dte Arreglo con los datos del XML (tag Documento)
140
     * @param timbre String XML con el tag TED del DTE
141
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
142
     * @version 2017-07-13
143
     */
144
    public function agregar(array $dte, $timbre = null)
145
    {
146
        $this->dte = $dte['Encabezado']['IdDoc']['TipoDTE'];
147
        // papel hoja carta
148
        if (!$this->papelContinuo) {
149
            $this->agregarNormal($dte, $timbre);
150
        }
151
        // papel contínuo 57mm
152
        else if ($this->papelContinuo==57) {
153
            $this->agregarContinuo57($dte, $timbre);
154
        }
155
        // papel contínuo 75 o 80mm
156
        else {
157
            $this->agregarContinuo($dte, $timbre, $this->papelContinuo);
158
        }
159
    }
160
161
    /**
162
     * Método que agrega una página con el documento tributario
163
     * @param dte Arreglo con los datos del XML (tag Documento)
164
     * @param timbre String XML con el tag TED del DTE
165
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
166
     * @version 2017-11-07
167
     */
168
    private function agregarNormal(array $dte, $timbre)
169
    {
170
        // agregar página para la factura
171
        $this->AddPage();
172
        // agregar cabecera del documento
173
        $y[] = $this->agregarEmisor($dte['Encabezado']['Emisor']);
0 ignored issues
show
Coding Style Comprehensibility introduced by
$y was never initialized. Although not strictly required by PHP, it is generally a good practice to add $y = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
174
        $y[] = $this->agregarFolio(
175
            $dte['Encabezado']['Emisor']['RUTEmisor'],
176
            $dte['Encabezado']['IdDoc']['TipoDTE'],
177
            $dte['Encabezado']['IdDoc']['Folio'],
178
            !empty($dte['Encabezado']['Emisor']['CmnaOrigen']) ? $dte['Encabezado']['Emisor']['CmnaOrigen'] : null
179
        );
180
        // datos del documento
181
        $this->setY(max($y));
182
        $this->Ln();
183
        $y = [];
184
        $y[] = $this->agregarDatosEmision($dte['Encabezado']['IdDoc'], !empty($dte['Encabezado']['Emisor']['CdgVendedor'])?$dte['Encabezado']['Emisor']['CdgVendedor']:null);
185
        $y[] = $this->agregarReceptor($dte['Encabezado']);
186
        $this->setY(max($y));
187
        $this->agregarTraslado(
188
            !empty($dte['Encabezado']['IdDoc']['IndTraslado']) ? $dte['Encabezado']['IdDoc']['IndTraslado'] : null,
189
            !empty($dte['Encabezado']['Transporte']) ? $dte['Encabezado']['Transporte'] : null
190
        );
191
        if (!empty($dte['Referencia'])) {
192
            $this->agregarReferencia($dte['Referencia']);
193
        }
194
        $this->agregarDetalle($dte['Detalle']);
195
        if (!empty($dte['DscRcgGlobal'])) {
196
            $this->agregarSubTotal($dte['Detalle']);
197
            $this->agregarDescuentosRecargos($dte['DscRcgGlobal']);
198
        }
199 View Code Duplication
        if (!empty($dte['Encabezado']['IdDoc']['MntPagos'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
200
            $this->agregarPagos($dte['Encabezado']['IdDoc']['MntPagos']);
201
        }
202
        // agregar observaciones
203
        $this->x_fin_datos = $this->getY();
204
        $this->agregarObservacion($dte['Encabezado']['IdDoc']);
205
        if (!$this->timbre_pie) {
206
            $this->Ln();
207
        }
208
        $this->x_fin_datos = $this->getY();
209
        $this->agregarTotales($dte['Encabezado']['Totales'], !empty($dte['Encabezado']['OtraMoneda']) ? $dte['Encabezado']['OtraMoneda'] : null);
210
        // agregar timbre
211
        $this->agregarTimbre($timbre);
212
        // agregar acuse de recibo y leyenda cedible
213
        if ($this->cedible and !in_array($dte['Encabezado']['IdDoc']['TipoDTE'], $this->sinAcuseRecibo)) {
214
            $this->agregarAcuseRecibo();
215
            $this->agregarLeyendaDestino($dte['Encabezado']['IdDoc']['TipoDTE']);
216
        }
217
    }
218
219
    /**
220
     * Método que agrega una página con el documento tributario en papel
221
     * contínuo
222
     * @param dte Arreglo con los datos del XML (tag Documento)
223
     * @param timbre String XML con el tag TED del DTE
224
     * @param width Ancho del papel contínuo en mm
225
     * @author Pablo Reyes (https://github.com/pabloxp)
226
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
227
     * @version 2017-10-24
228
     */
229
    private function agregarContinuo(array $dte, $timbre, $width, $height = 0)
230
    {
231
        // determinar alto de la página y agregarla
232
        $this->logo = null;
233
        $x_start = 1;
234
        $y_start = 1;
235
        $offset = 14;
236
        // determinar alto de la página y agregarla
237
        $this->AddPage('P', [$height ? $height : $this->papel_continuo_alto, $width]);
238
        // agregar cabecera del documento
239
        $y = $this->agregarFolio(
240
            $dte['Encabezado']['Emisor']['RUTEmisor'],
241
            $dte['Encabezado']['IdDoc']['TipoDTE'],
242
            $dte['Encabezado']['IdDoc']['Folio'],
243
            $dte['Encabezado']['Emisor']['CmnaOrigen'],
244
            $x_start, $y_start, $width-($x_start*4), 10,
245
            [0,0,0]
246
        );
247
        $y = $this->agregarEmisor($dte['Encabezado']['Emisor'], $x_start, $y+2, $width-($x_start*45), 8, 9, [0,0,0]);
248
        // datos del documento
249
        $this->SetY($y);
250
        $this->Ln();
251
        $this->setFont('', '', 8);
252
        $this->agregarDatosEmision($dte['Encabezado']['IdDoc'], !empty($dte['Encabezado']['Emisor']['CdgVendedor'])?$dte['Encabezado']['Emisor']['CdgVendedor']:null, $x_start, $offset, false);
253
        $this->agregarReceptor($dte['Encabezado'], $x_start, $offset);
254
        $this->agregarTraslado(
255
            !empty($dte['Encabezado']['IdDoc']['IndTraslado']) ? $dte['Encabezado']['IdDoc']['IndTraslado'] : null,
256
            !empty($dte['Encabezado']['Transporte']) ? $dte['Encabezado']['Transporte'] : null,
257
            $x_start, $offset
258
        );
259
        if (!empty($dte['Referencia'])) {
260
            $this->agregarReferencia($dte['Referencia'], $x_start, $offset);
261
        }
262
        $this->Ln();
263
        $this->agregarDetalleContinuo($dte['Detalle']);
264
        if (!empty($dte['DscRcgGlobal'])) {
265
            $this->Ln();
266
            $this->Ln();
267
            $this->agregarSubTotal($dte['Detalle'], $x_start);
268
            $this->agregarDescuentosRecargos($dte['DscRcgGlobal'], $x_start);
269
        }
270 View Code Duplication
        if (!empty($dte['Encabezado']['IdDoc']['MntPagos'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
271
            $this->Ln();
272
            $this->Ln();
273
            $this->agregarPagos($dte['Encabezado']['IdDoc']['MntPagos'], $x_start);
274
        }
275
        $this->agregarTotales($dte['Encabezado']['Totales'], !empty($dte['Encabezado']['OtraMoneda']) ? $dte['Encabezado']['OtraMoneda'] : null, $this->y+6, 23, 17);
276
        // agregar acuse de recibo y leyenda cedible
277 View Code Duplication
        if ($this->cedible and !in_array($dte['Encabezado']['IdDoc']['TipoDTE'], $this->sinAcuseRecibo)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
278
            $this->agregarAcuseReciboContinuo(3, $this->y+6, 68, 34);
279
            $this->agregarLeyendaDestinoContinuo($dte['Encabezado']['IdDoc']['TipoDTE']);
280
        }
281
        // agregar timbre
282
        $y = $this->agregarObservacion($dte['Encabezado']['IdDoc'], $x_start, $this->y+6);
283
        $this->agregarTimbre($timbre, -10, $x_start, $y+6, 70, 6);
284
        // si el alto no se pasó, entonces es con autocálculo, se elimina esta página y se pasa el alto
285
        // que se logró determinar para crear la página con el alto correcto
286 View Code Duplication
        if (!$height) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
287
            $this->deletePage($this->PageNo());
288
            $this->agregarContinuo($dte, $timbre, $width, $this->getY()+30);
289
        }
290
    }
291
292
    /**
293
     * Método que agrega una página con el documento tributario
294
     * @param dte Arreglo con los datos del XML (tag Documento)
295
     * @param timbre String XML con el tag TED del DTE
296
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
297
     * @version 2018-11-04
298
     */
299
    private function agregarContinuo57(array $dte, $timbre, $width = 57, $height = 0)
300
    {
301
        // determinar alto de la página y agregarla
302
        $this->AddPage('P', [$height ? $height : $this->papel_continuo_alto, $width]);
303
        $x = 1;
304
        $y = 5;
305
        $this->SetXY($x,$y);
306
        // agregar datos del documento
307
        $this->setFont('', '', 8);
308
        $this->MultiTexto(!empty($dte['Encabezado']['Emisor']['RznSoc']) ? $dte['Encabezado']['Emisor']['RznSoc'] : $dte['Encabezado']['Emisor']['RznSocEmisor'], $x, null, '', $width-2);
309
        $this->MultiTexto($dte['Encabezado']['Emisor']['RUTEmisor'], $x, null, '', $width-2);
310
        $this->MultiTexto('Giro: '.(!empty($dte['Encabezado']['Emisor']['GiroEmis']) ? $dte['Encabezado']['Emisor']['GiroEmis'] : $dte['Encabezado']['Emisor']['GiroEmisor']), $x, null, '', $width-2);
311
        $this->MultiTexto($dte['Encabezado']['Emisor']['DirOrigen'].', '.$dte['Encabezado']['Emisor']['CmnaOrigen'], $x, null, '', $width-2);
312
        if (!empty($dte['Encabezado']['Emisor']['Sucursal'])) {
313
            $this->MultiTexto('Sucursal: '.$dte['Encabezado']['Emisor']['Sucursal'], $x, null, '', $width-2);
314
        }
315
        if (!empty($this->casa_matriz)) {
316
            $this->MultiTexto('Casa matriz: '.$this->casa_matriz, $x, null, '', $width-2);
317
        }
318
        $this->MultiTexto($this->getTipo($dte['Encabezado']['IdDoc']['TipoDTE']).' N° '.$dte['Encabezado']['IdDoc']['Folio'], $x, null, '', $width-2);
319
        $this->MultiTexto('Fecha: '.date('d/m/Y', strtotime($dte['Encabezado']['IdDoc']['FchEmis'])), $x, null, '', $width-2);
320
        // si no es boleta no nominativa se agregan datos receptor
321
        if ($dte['Encabezado']['Receptor']['RUTRecep']!='66666666-6') {
322
            $this->Ln();
323
            $this->MultiTexto('Receptor: '.$dte['Encabezado']['Receptor']['RUTRecep'], $x, null, '', $width-2);
324
            $this->MultiTexto($dte['Encabezado']['Receptor']['RznSocRecep'], $x, null, '', $width-2);
325
            if (!empty($dte['Encabezado']['Receptor']['GiroRecep'])) {
326
                $this->MultiTexto('Giro: '.$dte['Encabezado']['Receptor']['GiroRecep'], $x, null, '', $width-2);
327
            }
328
            if (!empty($dte['Encabezado']['Receptor']['DirRecep'])) {
329
                $this->MultiTexto($dte['Encabezado']['Receptor']['DirRecep'].', '.$dte['Encabezado']['Receptor']['CmnaRecep'], $x, null, '', $width-2);
330
            }
331
        }
332
        $this->Ln();
333
        // hay un sólo detalle
334
        if (!isset($dte['Detalle'][0])) {
335
            $this->MultiTexto($dte['Detalle']['NmbItem'].': $'.$this->num($dte['Detalle']['MontoItem']), $x, null, '', $width-2);
336
        }
337
        // hay más de un detalle
338
        else {
339
            foreach ($dte['Detalle'] as $d) {
340
                $this->MultiTexto($d['NmbItem'].': $'.$this->num($d['MontoItem']), $x, null, '', $width-2);
341
            }
342
            if (in_array($dte['Encabezado']['IdDoc']['TipoDTE'], [39, 41])) {
343
                $this->MultiTexto('TOTAL: $'.$this->num($dte['Encabezado']['Totales']['MntTotal']), $x, null, '', $width-2);
344
            }
345
        }
346
        // si no es boleta se coloca EXENTO, NETO, IVA y TOTAL si corresponde
347
        if (!in_array($dte['Encabezado']['IdDoc']['TipoDTE'], [39, 41])) {
348 View Code Duplication
            if (!empty($dte['Encabezado']['Totales']['MntExe'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
349
                $this->MultiTexto('EXENTO: $'.$this->num($dte['Encabezado']['Totales']['MntExe']), $x, null, '', $width-2);
350
            }
351 View Code Duplication
            if (!empty($dte['Encabezado']['Totales']['MntNeto'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
352
                $this->MultiTexto('NETO: $'.$this->num($dte['Encabezado']['Totales']['MntNeto']), $x, null, '', $width-2);
353
            }
354 View Code Duplication
            if (!empty($dte['Encabezado']['Totales']['IVA'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
355
                $this->MultiTexto('IVA: $'.$this->num($dte['Encabezado']['Totales']['IVA']), $x, null, '', $width-2);
356
            }
357
            $this->MultiTexto('TOTAL: $'.$this->num($dte['Encabezado']['Totales']['MntTotal']), $x, null, '', $width-2);
358
        }
359
        // agregar acuse de recibo y leyenda cedible
360 View Code Duplication
        if ($this->cedible and !in_array($dte['Encabezado']['IdDoc']['TipoDTE'], $this->sinAcuseRecibo)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
361
            $this->agregarAcuseReciboContinuo(-1, $this->y+6, $width+2, 34);
362
            $this->agregarLeyendaDestinoContinuo($dte['Encabezado']['IdDoc']['TipoDTE']);
363
        }
364
        // agregar timbre
365
        if (!empty($dte['Encabezado']['IdDoc']['TermPagoGlosa'])) {
366
            $this->Ln();
367
            $this->MultiTexto('Observación: '.$dte['Encabezado']['IdDoc']['TermPagoGlosa']."\n\n", $x);
368
        }
369
        $this->agregarTimbre($timbre, -11, $x, $this->GetY()+6, 55, 6);
370
        // si el alto no se pasó, entonces es con autocálculo, se elimina esta página y se pasa el alto
371
        // que se logró determinar para crear la página con el alto correcto
372 View Code Duplication
        if (!$height) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
373
            $this->deletePage($this->PageNo());
374
            $this->agregarContinuo57($dte, $timbre, $width, $this->getY()+30);
375
        }
376
    }
377
378
    /**
379
     * Método que agrega los datos de la empresa
380
     * Orden de los datos:
381
     *  - Razón social del emisor
382
     *  - Giro del emisor (sin abreviar)
383
     *  - Dirección casa central del emisor
384
     *  - Dirección sucursales
385
     * @param emisor Arreglo con los datos del emisor (tag Emisor del XML)
386
     * @param x Posición horizontal de inicio en el PDF
387
     * @param y Posición vertical de inicio en el PDF
388
     * @param w Ancho de la información del emisor
389
     * @param w_img Ancho máximo de la imagen
390
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
391
     * @version 2018-06-15
392
     */
393
    protected function agregarEmisor(array $emisor, $x = 10, $y = 15, $w = 75, $w_img = 30, $font_size = null, array $color = null)
394
    {
395
        // logo del documento
396
        if (isset($this->logo)) {
397
            $this->Image(
398
                $this->logo['uri'],
399
                $x,
400
                $y,
401
                !$this->logo['posicion']?$w_img:null, $this->logo['posicion']?($w_img/2):null,
402
                'PNG',
403
                (isset($emisor['url'])?$emisor['url']:''),
404
                'T'
405
            );
406
            if ($this->logo['posicion']) {
407
                $this->SetY($this->y + ($w_img/2));
408
                $w += 40;
409
            } else {
410
                $x = $this->x+3;
411
            }
412
        } else {
413
            $this->y = $y-2;
414
            $w += 40;
415
        }
416
        // agregar datos del emisor
417
        $this->setFont('', 'B', $font_size ? $font_size : 14);
418
        $this->SetTextColorArray($color===null?[32, 92, 144]:$color);
419
        $this->MultiTexto(!empty($emisor['RznSoc']) ? $emisor['RznSoc'] : $emisor['RznSocEmisor'], $x, $this->y+2, 'L', $w);
420
        $this->setFont('', 'B', $font_size ? $font_size : 9);
421
        $this->SetTextColorArray([0,0,0]);
422
        $this->MultiTexto(!empty($emisor['GiroEmis']) ? $emisor['GiroEmis'] : $emisor['GiroEmisor'], $x, $this->y, 'L', $w);
423
        $comuna = !empty($emisor['CmnaOrigen']) ? $emisor['CmnaOrigen'] : null;
424
        $ciudad = !empty($emisor['CiudadOrigen']) ? $emisor['CiudadOrigen'] : \sasco\LibreDTE\Chile::getCiudad($comuna);
425
        $this->MultiTexto($emisor['DirOrigen'].($comuna?(', '.$comuna):'').($ciudad?(', '.$ciudad):''), $x, $this->y, 'L', $w);
426
        if (!empty($emisor['Sucursal'])) {
427
            $this->MultiTexto('Sucursal: '.$emisor['Sucursal'], $x, $this->y, 'L', $w);
428
        }
429
        if (!empty($this->casa_matriz)) {
430
            $this->MultiTexto('Casa matriz: '.$this->casa_matriz, $x, $this->y, 'L', $w);
431
        }
432
        $contacto = [];
433
        if (!empty($emisor['Telefono'])) {
434
            if (!is_array($emisor['Telefono']))
435
                $emisor['Telefono'] = [$emisor['Telefono']];
436
            foreach ($emisor['Telefono'] as $t)
437
                $contacto[] = $t;
438
        }
439
        if (!empty($emisor['CorreoEmisor'])) {
440
            $contacto[] = $emisor['CorreoEmisor'];
441
        }
442
        if ($contacto) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $contacto of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
443
            $this->MultiTexto(implode(' / ', $contacto), $x, $this->y, 'L', $w);
444
        }
445
        return $this->y;
446
    }
447
448
    /**
449
     * Método que agrega el recuadro con el folio
450
     * Recuadro:
451
     *  - Tamaño mínimo 1.5x5.5 cms
452
     *  - En lado derecho (negro o rojo)
453
     *  - Enmarcado por una línea de entre 0.5 y 1 mm de espesor
454
     *  - Tamaño máximo 4x8 cms
455
     *  - Letras tamaño 10 o superior en mayúsculas y negritas
456
     *  - Datos del recuadro: RUT emisor, nombre de documento en 2 líneas,
457
     *    folio.
458
     *  - Bajo el recuadro indicar la Dirección regional o Unidad del SII a la
459
     *    que pertenece el emisor
460
     * @param rut RUT del emisor
461
     * @param tipo Código o glosa del tipo de documento
462
     * @param sucursal_sii Código o glosa de la sucursal del SII del Emisor
463
     * @param x Posición horizontal de inicio en el PDF
464
     * @param y Posición vertical de inicio en el PDF
465
     * @param w Ancho de la información del emisor
466
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
467
     * @version 2016-12-02
468
     */
469
    protected function agregarFolio($rut, $tipo, $folio, $sucursal_sii = null, $x = 130, $y = 15, $w = 70, $font_size = null, array $color = null)
470
    {
471
        if ($color===null) {
472
            $color = $tipo ? ($tipo==52 ? [0,172,140] : [255,0,0]) : [0,0,0];
473
        }
474
        $this->SetTextColorArray($color);
475
        // colocar rut emisor, glosa documento y folio
476
        list($rut, $dv) = explode('-', $rut);
477
        $this->setFont ('', 'B', $font_size ? $font_size : 15);
478
        $this->MultiTexto('R.U.T.: '.$this->num($rut).'-'.$dv, $x, $y+4, 'C', $w);
479
        $this->setFont('', 'B', $font_size ? $font_size : 12);
480
        $this->MultiTexto($this->getTipo($tipo), $x, null, 'C', $w);
481
        $this->setFont('', 'B', $font_size ? $font_size : 15);
482
        $this->MultiTexto('N° '.$folio, $x, null, 'C', $w);
483
        // dibujar rectángulo rojo
484
        $this->Rect($x, $y, $w, round($this->getY()-$y+3), 'D', ['all' => ['width' => 0.5, 'color' => $color]]);
485
        // colocar unidad del SII
486
        $this->setFont('', 'B', $font_size ? $font_size : 10);
487
        if ($tipo) {
488
            $this->Texto('S.I.I. - '.\sasco\LibreDTE\Sii::getDireccionRegional($sucursal_sii), $x, $this->getY()+4, 'C', $w);
0 ignored issues
show
Bug introduced by
It seems like $sucursal_sii defined by parameter $sucursal_sii on line 469 can also be of type null; however, sasco\LibreDTE\Sii::getDireccionRegional() does only seem to accept object<sasco\LibreDTE\de>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
489
        }
490
        $this->SetTextColorArray([0,0,0]);
491
        $this->Ln();
492
        return $this->y;
493
    }
494
495
    /**
496
     * Método que agrega los datos de la emisión del DTE que no son los dato del
497
     * receptor
498
     * @param IdDoc Información general del documento
499
     * @param x Posición horizontal de inicio en el PDF
500
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
501
     * @version 2017-06-15
502
     */
503
    protected function agregarDatosEmision($IdDoc, $CdgVendedor, $x = 10, $offset = 22, $mostrar_dia = true)
504
    {
505
        // si es hoja carta
506
        if ($x==10) {
507
            $y = $this->GetY();
508
            // fecha emisión
509
            $this->setFont('', 'B', null);
510
            $this->MultiTexto($this->date($IdDoc['FchEmis'], $mostrar_dia), $x, null, 'R');
511
            $this->setFont('', '', null);
512
            // período facturación
513
            if (!empty($IdDoc['PeriodoDesde']) and !empty($IdDoc['PeriodoHasta'])) {
514
                $this->MultiTexto('Período del '.date('d/m/y', strtotime($IdDoc['PeriodoDesde'])).' al '.date('d/m/y', strtotime($IdDoc['PeriodoHasta'])), $x, null, 'R');
515
            }
516
            // pago anticicado
517 View Code Duplication
            if (!empty($IdDoc['FchCancel'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
518
                $this->MultiTexto('Pagado el '.$this->date($IdDoc['FchCancel'], false), $x, null, 'R');
519
            }
520
            // fecha vencimiento
521 View Code Duplication
            if (!empty($IdDoc['FchVenc'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
522
                $this->MultiTexto('Vence el '.$this->date($IdDoc['FchVenc'], false), $x, null, 'R');
523
            }
524
            // forma de pago nacional
525 View Code Duplication
            if (!empty($IdDoc['FmaPago'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
526
                $this->MultiTexto('Venta: '.strtolower($this->formas_pago[$IdDoc['FmaPago']]), $x, null, 'R');
527
            }
528
            // forma de pago exportación
529 View Code Duplication
            if (!empty($IdDoc['FmaPagExp'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
530
                $this->MultiTexto('Venta: '.strtolower($this->formas_pago_exportacion[$IdDoc['FmaPagExp']]), $x, null, 'R');
531
            }
532
            // vendedor
533
            if (!empty($CdgVendedor)) {
534
                $this->MultiTexto('Vendedor: '.$CdgVendedor, $x, null, 'R');
535
            }
536
            $y_end = $this->GetY();
537
            $this->SetY($y);
538
        }
539
        // papel contínuo
540
        else {
541
            // fecha de emisión
542
            $this->setFont('', 'B', null);
543
            $this->Texto('Emisión', $x);
544
            $this->Texto(':', $x+$offset);
545
            $this->setFont('', '', null);
546
            $this->MultiTexto($this->date($IdDoc['FchEmis'], $mostrar_dia), $x+$offset+2);
547
            // forma de pago nacional
548
            if (!empty($IdDoc['FmaPago'])) {
549
                $this->setFont('', 'B', null);
550
                $this->Texto('Venta', $x);
551
                $this->Texto(':', $x+$offset);
552
                $this->setFont('', '', null);
553
                $this->MultiTexto($this->formas_pago[$IdDoc['FmaPago']], $x+$offset+2);
554
            }
555
            // forma de pago exportación
556
            if (!empty($IdDoc['FmaPagExp'])) {
557
                $this->setFont('', 'B', null);
558
                $this->Texto('Venta', $x);
559
                $this->Texto(':', $x+$offset);
560
                $this->setFont('', '', null);
561
                $this->MultiTexto($this->formas_pago_exportacion[$IdDoc['FmaPagExp']], $x+$offset+2);
562
            }
563
            // pago anticicado
564
            if (!empty($IdDoc['FchCancel'])) {
565
                $this->setFont('', 'B', null);
566
                $this->Texto('Pagado el', $x);
567
                $this->Texto(':', $x+$offset);
568
                $this->setFont('', '', null);
569
                $this->MultiTexto($this->date($IdDoc['FchCancel'], $mostrar_dia), $x+$offset+2);
570
            }
571
            // fecha vencimiento
572
            if (!empty($IdDoc['FchVenc'])) {
573
                $this->setFont('', 'B', null);
574
                $this->Texto('Vence el', $x);
575
                $this->Texto(':', $x+$offset);
576
                $this->setFont('', '', null);
577
                $this->MultiTexto($this->date($IdDoc['FchVenc'], $mostrar_dia), $x+$offset+2);
578
            }
579
            $y_end = $this->GetY();
580
        }
581
        return $y_end;
582
    }
583
584
    /**
585
     * Método que agrega los datos del receptor
586
     * @param receptor Arreglo con los datos del receptor (tag Receptor del XML)
587
     * @param x Posición horizontal de inicio en el PDF
588
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
589
     * @version 2017-06-15
590
     */
591
    protected function agregarReceptor(array $Encabezado, $x = 10, $offset = 22)
592
    {
593
        $receptor = $Encabezado['Receptor'];
594 View Code Duplication
        if (!empty($receptor['RUTRecep']) and $receptor['RUTRecep']!='66666666-6') {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
595
            list($rut, $dv) = explode('-', $receptor['RUTRecep']);
596
            $this->setFont('', 'B', null);
597
            $this->Texto('R.U.T.', $x);
598
            $this->Texto(':', $x+$offset);
599
            $this->setFont('', '', null);
600
            $this->MultiTexto($this->num($rut).'-'.$dv, $x+$offset+2);
601
        }
602 View Code Duplication
        if (!empty($receptor['RznSocRecep'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
603
            $this->setFont('', 'B', null);
604
            $this->Texto('Señor(es)', $x);
605
            $this->Texto(':', $x+$offset);
606
            $this->setFont('', '', null);
607
            $this->MultiTexto($receptor['RznSocRecep'], $x+$offset+2, null, '', $x==10?105:0);
608
        }
609 View Code Duplication
        if (!empty($receptor['GiroRecep'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
610
            $this->setFont('', 'B', null);
611
            $this->Texto('Giro', $x);
612
            $this->Texto(':', $x+$offset);
613
            $this->setFont('', '', null);
614
            $this->MultiTexto($receptor['GiroRecep'], $x+$offset+2);
615
        }
616
        if (!empty($receptor['DirRecep'])) {
617
            $this->setFont('', 'B', null);
618
            $this->Texto('Dirección', $x);
619
            $this->Texto(':', $x+$offset);
620
            $this->setFont('', '', null);
621
            $ciudad = !empty($receptor['CiudadRecep']) ? $receptor['CiudadRecep'] : (
622
                !empty($receptor['CmnaRecep']) ? \sasco\LibreDTE\Chile::getCiudad($receptor['CmnaRecep']) : ''
623
            );
624
            $this->MultiTexto($receptor['DirRecep'].(!empty($receptor['CmnaRecep'])?(', '.$receptor['CmnaRecep']):'').($ciudad?(', '.$ciudad):''), $x+$offset+2);
625
        }
626
        if (!empty($receptor['Extranjero']['Nacionalidad'])) {
627
            $this->setFont('', 'B', null);
628
            $this->Texto('Nacionalidad', $x);
629
            $this->Texto(':', $x+$offset);
630
            $this->setFont('', '', null);
631
            $this->MultiTexto(\sasco\LibreDTE\Sii\Aduana::getNacionalidad($receptor['Extranjero']['Nacionalidad']), $x+$offset+2);
632
        }
633
        if (!empty($receptor['Extranjero']['NumId'])) {
634
            $this->setFont('', 'B', null);
635
            $this->Texto('N° ID extranj.', $x);
636
            $this->Texto(':', $x+$offset);
637
            $this->setFont('', '', null);
638
            $this->MultiTexto($receptor['Extranjero']['NumId'], $x+$offset+2);
639
        }
640
        $contacto = [];
641
        if (!empty($receptor['Contacto']))
642
            $contacto[] = $receptor['Contacto'];
643
        if (!empty($receptor['CorreoRecep']))
644
            $contacto[] = $receptor['CorreoRecep'];
645 View Code Duplication
        if (!empty($contacto)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
646
            $this->setFont('', 'B', null);
647
            $this->Texto('Contacto', $x);
648
            $this->Texto(':', $x+$offset);
649
            $this->setFont('', '', null);
650
            $this->MultiTexto(implode(' / ', $contacto), $x+$offset+2);
651
        }
652 View Code Duplication
        if (!empty($Encabezado['RUTSolicita'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
653
            list($rut, $dv) = explode('-', $Encabezado['RUTSolicita']);
654
            $this->setFont('', 'B', null);
655
            $this->Texto('RUT solicita', $x);
656
            $this->Texto(':', $x+$offset);
657
            $this->setFont('', '', null);
658
            $this->MultiTexto($this->num($rut).'-'.$dv, $x+$offset+2);
659
        }
660 View Code Duplication
        if (!empty($receptor['CdgIntRecep'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
661
            $this->setFont('', 'B', null);
662
            $this->Texto('Cód. recep.', $x);
663
            $this->Texto(':', $x+$offset);
664
            $this->setFont('', '', null);
665
            $this->MultiTexto($receptor['CdgIntRecep'], $x+$offset+2, null, '', $x==10?105:0);
666
        }
667
        return $this->GetY();
668
    }
669
670
    /**
671
     * Método que agrega los datos del traslado
672
     * @param IndTraslado
673
     * @param Transporte
674
     * @param x Posición horizontal de inicio en el PDF
675
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
676
     * @version 2016-08-03
677
     */
678
    protected function agregarTraslado($IndTraslado, array $Transporte = null, $x = 10, $offset = 22)
679
    {
680
        // agregar tipo de traslado
681 View Code Duplication
        if ($IndTraslado) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
682
            $this->setFont('', 'B', null);
683
            $this->Texto('Tipo oper.', $x);
684
            $this->Texto(':', $x+$offset);
685
            $this->setFont('', '', null);
686
            $this->MultiTexto($this->traslados[$IndTraslado], $x+$offset+2);
687
        }
688
        // agregar información de transporte
689
        if ($Transporte) {
690
            $transporte = '';
691
            if (!empty($Transporte['DirDest']) and !empty($Transporte['CmnaDest'])) {
692
                $transporte .= 'a '.$Transporte['DirDest'].', '.$Transporte['CmnaDest'];
693
            }
694
            if (!empty($Transporte['RUTTrans']))
695
                $transporte .= ' por '.$Transporte['RUTTrans'];
696
            if (!empty($Transporte['Patente']))
697
                $transporte .= ' en vehículo '.$Transporte['Patente'];
698
            if (isset($Transporte['Chofer']) and is_array($Transporte['Chofer'])) {
699 View Code Duplication
                if (!empty($Transporte['Chofer']['NombreChofer']))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
700
                    $transporte .= ' con chofer '.$Transporte['Chofer']['NombreChofer'];
701 View Code Duplication
                if (!empty($Transporte['Chofer']['RUTChofer']))
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
702
                    $transporte .= ' ('.$Transporte['Chofer']['RUTChofer'].')';
703
            }
704 View Code Duplication
            if ($transporte) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
705
                $this->setFont('', 'B', null);
706
                $this->Texto('Traslado', $x);
707
                $this->Texto(':', $x+$offset);
708
                $this->setFont('', '', null);
709
                $this->MultiTexto(ucfirst(trim($transporte)), $x+$offset+2);
710
            }
711
        }
712
        // agregar información de aduana
713
        if (!empty($Transporte['Aduana']) and is_array($Transporte['Aduana'])) {
714
            $col = 0;
715
            foreach ($Transporte['Aduana'] as $tag => $codigo) {
716
                if ($codigo===false)
717
                    continue;
718
                $glosa = \sasco\LibreDTE\Sii\Aduana::getGlosa($tag);
719
                $valor = \sasco\LibreDTE\Sii\Aduana::getValor($tag, $codigo);
720
                if ($glosa!==false and $valor!==false) {
721
                    if ($tag=='TipoBultos' and $col) {
722
                        $col = abs($col-110);
723
                        $this->Ln();
724
                    }
725
                    $this->setFont('', 'B', null);
726
                    $this->Texto($glosa, $x+$col);
727
                    $this->Texto(':', $x+$offset+$col);
728
                    $this->setFont('', '', null);
729
                    $this->Texto($valor, $x+$offset+2+$col);
730
                    if ($tag=='TipoBultos')
731
                        $col = abs($col-110);
732
                    if ($col)
733
                        $this->Ln();
734
                    $col = abs($col-110);
735
                }
736
            }
737
            if ($col)
738
                $this->Ln();
739
        }
740
    }
741
742
    /**
743
     * Método que agrega las referencias del documento
744
     * @param referencias Arreglo con las referencias del documento (tag Referencia del XML)
745
     * @param x Posición horizontal de inicio en el PDF
746
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
747
     * @version 2017-09-25
748
     */
749
    protected function agregarReferencia($referencias, $x = 10, $offset = 22)
750
    {
751
        if (!isset($referencias[0]))
752
            $referencias = [$referencias];
753
        foreach($referencias as $r) {
754
            $texto = $r['NroLinRef'].' - ';
755
            if (!empty($r['TpoDocRef'])) {
756
                $texto .= $this->getTipo($r['TpoDocRef']).' ';
757
            }
758
            if (!empty($r['FolioRef'])) {
759
                if (is_numeric($r['FolioRef'])) {
760
                    $texto .= ' N° '.$r['FolioRef'].' ';
761
                } else {
762
                    $texto .= ' '.$r['FolioRef'].' ';
763
                }
764
            }
765
            if (!empty($r['FchRef'])) {
766
                $texto .= 'del '.date('d/m/Y', strtotime($r['FchRef']));
767
            }
768
            if (isset($r['RazonRef']) and $r['RazonRef']!==false) {
769
                $texto = $texto.': '.$r['RazonRef'];
770
            }
771
            $this->setFont('', 'B', null);
772
            $this->Texto('Referencia', $x);
773
            $this->Texto(':', $x+$offset);
774
            $this->setFont('', '', null);
775
            $this->MultiTexto($texto, $x+$offset+2);
776
        }
777
    }
778
779
    /**
780
     * Método que agrega el detalle del documento
781
     * @param detalle Arreglo con el detalle del documento (tag Detalle del XML)
782
     * @param x Posición horizontal de inicio en el PDF
783
     * @param y Posición vertical de inicio en el PDF
784
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
785
     * @version 2018-11-04
786
     */
787
    protected function agregarDetalle($detalle, $x = 10, $html = true)
788
    {
789
        if (!isset($detalle[0]))
790
            $detalle = [$detalle];
791
        $this->setFont('', '', $this->detalle_fuente);
792
        // titulos
793
        $titulos = [];
794
        $titulos_keys = array_keys($this->detalle_cols);
795
        foreach ($this->detalle_cols as $key => $info) {
796
            $titulos[$key] = $info['title'];
797
        }
798
        // normalizar cada detalle
799
        $dte_exento = in_array($this->dte, [34, 110, 111, 112]);
800
        foreach ($detalle as &$item) {
801
            // quitar columnas
802
            foreach ($item as $col => $valor) {
803
                if ($col=='DscItem' and !empty($item['DscItem'])) {
804
                    $item['NmbItem'] .= !$this->item_detalle_posicion ? ($html?'<br/>':"\n") : ': ';
805
                    if ($html) {
806
                        $item['NmbItem'] .= '<span style="font-size:0.7em">'.$item['DscItem'].'</span>';
807
                    } else {
808
                        $item['NmbItem'] .= $item['DscItem'];
809
                    }
810
                }
811
                if ($col=='DescuentoPct' and !empty($item['DescuentoPct'])) {
812
                    $item['DescuentoMonto'] = $item['DescuentoPct'].'%';
813
                }
814
                if ($col=='RecargoPct' and !empty($item['RecargoPct'])) {
815
                    $item['RecargoMonto'] = $item['RecargoPct'].'%';
816
                }
817
                if (!in_array($col, $titulos_keys) or ($dte_exento and $col=='IndExe')) {
818
                    unset($item[$col]);
819
                }
820
            }
821
            // ajustes a IndExe
822
            if (isset($item['IndExe'])) {
823
                if ($item['IndExe']==1)
824
                    $item['IndExe'] = 'EX';
825
                else if ($item['IndExe']==2)
826
                    $item['IndExe'] = 'NF';
827
            }
828
            // agregar todas las columnas que se podrían imprimir en la tabla
829
            $item_default = [];
830
            foreach ($this->detalle_cols as $key => $info)
831
                $item_default[$key] = false;
832
            $item = array_merge($item_default, $item);
833
            // si hay código de item se extrae su valor
834
            if ($item['CdgItem']) {
835
                $item['CdgItem'] = $item['CdgItem']['VlrCodigo'];
836
            }
837
            // dar formato a números
838
            foreach (['QtyItem', 'PrcItem', 'DescuentoMonto', 'RecargoMonto', 'MontoItem'] as $col) {
839
                if ($item[$col]) {
840
                    $item[$col] = is_numeric($item[$col]) ? $this->num($item[$col]) : $item[$col];
841
                }
842
            }
843
        }
844
        // opciones
845
        $options = ['align'=>[]];
846
        $i = 0;
847
        foreach ($this->detalle_cols as $info) {
848
            if (isset($info['width']))
849
                $options['width'][$i] = $info['width'];
850
            $options['align'][$i] = $info['align'];
851
            $i++;
852
        }
853
        // agregar tabla de detalle
854
        $this->Ln();
855
        $this->SetX($x);
856
        $this->addTableWithoutEmptyCols($titulos, $detalle, $options);
857
    }
858
859
    /**
860
     * Método que agrega el detalle del documento
861
     * @param detalle Arreglo con el detalle del documento (tag Detalle del XML)
862
     * @param x Posición horizontal de inicio en el PDF
863
     * @param y Posición vertical de inicio en el PDF
864
     * @author Pablo Reyes (https://github.com/pabloxp)
865
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
866
     * @version 2016-12-13
867
     */
868
    protected function agregarDetalleContinuo($detalle, $x = 3)
869
    {
870
        $this->SetY($this->getY()+1);
871
        $p1x = $x;
872
        $p1y = $this->y;
873
        $p2x = $this->getPageWidth() - 2;
874
        $p2y = $p1y;  // Use same y for a straight line
875
        $style = array('width' => 0.2,'color' => array(0, 0, 0));
876
        $this->Line($p1x, $p1y, $p2x, $p2y, $style);
877
        $this->Texto($this->detalle_cols['NmbItem']['title'], $x+1, $this->y, ucfirst($this->detalle_cols['NmbItem']['align'][0]), $this->detalle_cols['NmbItem']['width']);
878
        $this->Texto($this->detalle_cols['PrcItem']['title'], $x+15, $this->y, ucfirst($this->detalle_cols['PrcItem']['align'][0]), $this->detalle_cols['PrcItem']['width']);
879
        $this->Texto($this->detalle_cols['QtyItem']['title'], $x+35, $this->y, ucfirst($this->detalle_cols['QtyItem']['align'][0]), $this->detalle_cols['QtyItem']['width']);
880
        $this->Texto($this->detalle_cols['MontoItem']['title'], $x+45, $this->y, ucfirst($this->detalle_cols['MontoItem']['align'][0]), $this->detalle_cols['MontoItem']['width']);
881
        $this->Line($p1x, $p1y+4, $p2x, $p2y+4, $style);
882
        if (!isset($detalle[0]))
883
            $detalle = [$detalle];
884
        $this->SetY($this->getY()+2);
885
        foreach($detalle as  &$d) {
886
            $this->MultiTexto($d['NmbItem'], $x+1, $this->y+4, ucfirst($this->detalle_cols['NmbItem']['align'][0]), $this->detalle_cols['NmbItem']['width']);
887
            $this->Texto(number_format($d['PrcItem'],0,',','.'), $x+15, $this->y, ucfirst($this->detalle_cols['PrcItem']['align'][0]), $this->detalle_cols['PrcItem']['width']);
888
            $this->Texto($this->num($d['QtyItem']), $x+35, $this->y, ucfirst($this->detalle_cols['QtyItem']['align'][0]), $this->detalle_cols['QtyItem']['width']);
889
            $this->Texto($this->num($d['MontoItem']), $x+45, $this->y, ucfirst($this->detalle_cols['MontoItem']['align'][0]), $this->detalle_cols['MontoItem']['width']);
890
        }
891
        $this->Line($p1x, $this->y+4, $p2x, $this->y+4, $style);
892
    }
893
894
    /**
895
     * Método que agrega el subtotal del DTE
896
     * @param detalle Arreglo con los detalles del documentos para poder
897
     * calcular subtotal
898
     * @param x Posición horizontal de inicio en el PDF
899
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
900
     * @version 2016-08-17
901
     */
902
    protected function agregarSubTotal(array $detalle, $x = 10) {
903
        $subtotal = 0;
904
        if (!isset($detalle[0])) {
905
            $detalle = [$detalle];
906
        }
907
        foreach($detalle as  &$d) {
908
            if (!empty($d['MontoItem'])) {
909
                $subtotal += $d['MontoItem'];
910
            }
911
        }
912
        if ($this->papelContinuo) {
913
            $this->Texto('Subtotal: '.$this->num($subtotal), $x);
914
        } else {
915
            $this->Texto('Subtotal:', 77, null, 'R', 100);
916
            $this->Texto($this->num($subtotal), 177, null, 'R', 22);
917
        }
918
        $this->Ln();
919
    }
920
921
    /**
922
     * Método que agrega los descuentos y/o recargos globales del documento
923
     * @param descuentosRecargos Arreglo con los descuentos y/o recargos del documento (tag DscRcgGlobal del XML)
924
     * @param x Posición horizontal de inicio en el PDF
925
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
926
     * @version 2018-05-29
927
     */
928
    protected function agregarDescuentosRecargos(array $descuentosRecargos, $x = 10)
929
    {
930
        if (!isset($descuentosRecargos[0])) {
931
            $descuentosRecargos = [$descuentosRecargos];
932
        }
933
        foreach($descuentosRecargos as $dr) {
934
            $tipo = $dr['TpoMov']=='D' ? 'Descuento' : 'Recargo';
935
            if (!empty($dr['IndExeDR'])) {
936
                $tipo .= ' EX';
937
            }
938
            $valor = $dr['TpoValor']=='%' ? $dr['ValorDR'].'%' : $this->num($dr['ValorDR']);
939
            if ($this->papelContinuo) {
940
                $this->Texto($tipo.' global: '.$valor.(!empty($dr['GlosaDR'])?(' ('.$dr['GlosaDR'].')'):''), $x);
941
            } else {
942
                $this->Texto($tipo.(!empty($dr['GlosaDR'])?(' ('.$dr['GlosaDR'].')'):'').':', 77, null, 'R', 100);
943
                $this->Texto($valor, 177, null, 'R', 22);
944
            }
945
            $this->Ln();
946
        }
947
    }
948
949
    /**
950
     * Método que agrega los pagos del documento
951
     * @param pagos Arreglo con los pagos del documento
952
     * @param x Posición horizontal de inicio en el PDF
953
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
954
     * @version 2016-07-24
955
     */
956
    protected function agregarPagos(array $pagos, $x = 10)
957
    {
958
        if (!isset($pagos[0]))
959
            $pagos = [$pagos];
960
        $this->Texto('Pago(s) programado(s):', $x);
961
        $this->Ln();
962
        foreach($pagos as $p) {
963
            $this->Texto('  - '.$this->date($p['FchPago'], false).': $'.$this->num($p['MntPago']).'.-'.(!empty($p['GlosaPagos'])?(' ('.$p['GlosaPagos'].')'):''), $x);
964
            $this->Ln();
965
        }
966
    }
967
968
    /**
969
     * Método que agrega los totales del documento
970
     * @param totales Arreglo con los totales (tag Totales del XML)
971
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
972
     * @version 2017-10-05
973
     */
974
    protected function agregarTotales(array $totales, $otra_moneda, $y = 190, $x = 145, $offset = 25)
975
    {
976
        $y = (!$this->papelContinuo and !$this->timbre_pie) ? $this->x_fin_datos : $y;
977
        // normalizar totales
978
        $totales = array_merge([
979
            'TpoMoneda' => false,
980
            'MntNeto' => false,
981
            'MntExe' => false,
982
            'TasaIVA' => false,
983
            'IVA' => false,
984
            'IVANoRet' => false,
985
            'CredEC' => false,
986
            'MntTotal' => false,
987
            'MontoNF' => false,
988
            'MontoPeriodo' => false,
989
            'SaldoAnterior' => false,
990
            'VlrPagar' => false,
991
        ], $totales);
992
        // glosas
993
        $glosas = [
994
            'TpoMoneda' => 'Moneda',
995
            'MntNeto' => 'Neto $',
996
            'MntExe' => 'Exento $',
997
            'IVA' => 'IVA ('.$totales['TasaIVA'].'%) $',
998
            'IVANoRet' => 'IVA no retenido $',
999
            'CredEC' => 'Desc. 65% IVA $',
1000
            'MntTotal' => 'Total $',
1001
            'MontoNF' => 'Monto no facturable $',
1002
            'MontoPeriodo' => 'Monto período $',
1003
            'SaldoAnterior' => 'Saldo anterior $',
1004
            'VlrPagar' => 'Valor a pagar $',
1005
        ];
1006
        // agregar impuestos adicionales y retenciones
1007
        if (!empty($totales['ImptoReten'])) {
1008
            $ImptoReten = $totales['ImptoReten'];
1009
            $MntTotal = $totales['MntTotal'];
1010
            unset($totales['ImptoReten'], $totales['MntTotal']);
1011
            if (!isset($ImptoReten[0])) {
1012
                $ImptoReten = [$ImptoReten];
1013
            }
1014
            foreach($ImptoReten as $i) {
1015
                $totales['ImptoReten_'.$i['TipoImp']] = $i['MontoImp'];
1016
                if (!empty($i['TasaImp'])) {
1017
                    $glosas['ImptoReten_'.$i['TipoImp']] = \sasco\LibreDTE\Sii\ImpuestosAdicionales::getGlosa($i['TipoImp']).' ('.$i['TasaImp'].'%) $';
1018
                } else {
1019
                    $glosas['ImptoReten_'.$i['TipoImp']] = \sasco\LibreDTE\Sii\ImpuestosAdicionales::getGlosa($i['TipoImp']).' $';
1020
                }
1021
            }
1022
            $totales['MntTotal'] = $MntTotal;
1023
        }
1024
        // agregar cada uno de los totales
1025
        $this->setY($y);
1026
        $this->setFont('', 'B', null);
1027
        foreach ($totales as $key => $total) {
1028
            if ($total!==false and isset($glosas[$key])) {
1029
                $y = $this->GetY();
1030
                if (!$this->cedible or $this->papelContinuo) {
1031
                    $this->Texto($glosas[$key].' :', $x, null, 'R', 30);
1032
                    $this->Texto($this->num($total), $x+$offset, $y, 'R', 30);
1033
                    $this->Ln();
1034
                } else {
1035
                    $this->MultiTexto($glosas[$key].' :', $x, null, 'R', 30);
1036
                    $y_new = $this->GetY();
1037
                    $this->Texto($this->num($total), $x+$offset, $y, 'R', 30);
1038
                    $this->SetY($y_new);
1039
                }
1040
            }
1041
        }
1042
        // agregar totales en otra moneda
1043
        if (!empty($otra_moneda)) {
1044
            if (!isset($otra_moneda[0])) {
1045
                $otra_moneda = [$otra_moneda];
1046
            }
1047
            $this->setFont('', '', null);
1048
            $this->Ln();
1049
            foreach ($otra_moneda as $om) {
1050
                $y = $this->GetY();
1051
                if (!$this->cedible or $this->papelContinuo) {
1052
                    $this->Texto('Total '.$om['TpoMoneda'].' :', $x, null, 'R', 30);
1053
                    $this->Texto($this->num($om['MntTotOtrMnda']), $x+$offset, $y, 'R', 30);
1054
                    $this->Ln();
1055
                } else {
1056
                    $this->MultiTexto('Total '.$om['TpoMoneda'].' :', $x, null, 'R', 30);
1057
                    $y_new = $this->GetY();
1058
                    $this->Texto($this->num($om['MntTotOtrMnda']), $x+$offset, $y, 'R', 30);
1059
                    $this->SetY($y_new);
1060
                }
1061
            }
1062
            $this->setFont('', 'B', null);
1063
        }
1064
    }
1065
1066
    /**
1067
     * Método que coloca las diferentes observaciones que puede tener el documnto
1068
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
1069
     * @version 2018-06-15
1070
     */
1071
    protected function agregarObservacion($IdDoc, $x = 10, $y = 190)
1072
    {
1073
        $y = (!$this->papelContinuo and !$this->timbre_pie) ? $this->x_fin_datos : $y;
1074
        if (!$this->papelContinuo and $this->timbre_pie) {
1075
            $y -= 15;
1076
        }
1077
        $this->SetXY($x, $y);
1078
        if (!empty($IdDoc['TermPagoGlosa'])) {
1079
            $this->MultiTexto('Observación: '.$IdDoc['TermPagoGlosa']);
1080
        }
1081
        if (!empty($IdDoc['MedioPago']) or !empty($IdDoc['TermPagoDias'])) {
1082
            $pago = [];
1083
            if (!empty($IdDoc['MedioPago'])) {
1084
                $medio = 'Medio de pago: '.(!empty($this->medios_pago[$IdDoc['MedioPago']]) ? $this->medios_pago[$IdDoc['MedioPago']] : $IdDoc['MedioPago']);
1085
                if (!empty($IdDoc['BcoPago'])) {
1086
                    $medio .= ' a '.$IdDoc['BcoPago'];
1087
                }
1088
                if (!empty($IdDoc['TpoCtaPago'])) {
1089
                    $medio .= ' en cuenta '.strtolower($IdDoc['TpoCtaPago']);
1090
                }
1091
                if (!empty($IdDoc['NumCtaPago'])) {
1092
                    $medio .= ' N° '.$IdDoc['NumCtaPago'];
1093
                }
1094
                $pago[] = $medio;
1095
            }
1096
            if (!empty($IdDoc['TermPagoDias'])) {
1097
                $pago[] = 'Días de pago: '.$IdDoc['TermPagoDias'];
1098
            }
1099
            $this->SetXY($x, $this->GetY());
1100
            $this->MultiTexto(implode(' / ', $pago));
1101
        }
1102
        return $this->GetY();
1103
    }
1104
1105
    /**
1106
     * Método que agrega el timbre de la factura
1107
     *  - Se imprime en el tamaño mínimo: 2x5 cms
1108
     *  - En el lado de abajo con margen izquierdo mínimo de 2 cms
1109
     * @param timbre String con los datos del timbre
1110
     * @param x Posición horizontal de inicio en el PDF
1111
     * @param y Posición vertical de inicio en el PDF
1112
     * @param w Ancho del timbre
1113
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
1114
     * @version 2018-04-12
1115
     */
1116
    protected function agregarTimbre($timbre, $x_timbre = 10, $x = 10, $y = 190, $w = 70, $font_size = 8)
1117
    {
1118
        $y = (!$this->papelContinuo and !$this->timbre_pie) ? $this->x_fin_datos : $y;
1119
        if ($timbre!==null) {
1120
            $style = [
1121
                'border' => false,
1122
                'padding' => 0,
1123
                'hpadding' => 0,
1124
                'vpadding' => 0,
1125
                'module_width' => 1, // width of a single module in points
1126
                'module_height' => 1, // height of a single module in points
1127
                'fgcolor' => [0,0,0],
1128
                'bgcolor' => false, // [255,255,255]
1129
                'position' => $this->papelContinuo ? 'C' : 'S',
1130
            ];
1131
            $ecl = version_compare(phpversion(), '7.0.0', '<') ? -1 : $this->ecl;
1132
            $this->write2DBarcode($timbre, 'PDF417,,'.$ecl, $x_timbre, $y, $w, 0, $style, 'B');
1133
            $this->setFont('', 'B', $font_size);
1134
            $this->Texto('Timbre Electrónico SII', $x, null, 'C', $w);
1135
            $this->Ln();
1136
            $this->Texto('Resolución '.$this->resolucion['NroResol'].' de '.explode('-', $this->resolucion['FchResol'])[0], $x, null, 'C', $w);
1137
            $this->Ln();
1138
            if ($w>=60) {
1139
                $this->Texto('Verifique documento: '.$this->web_verificacion, $x, null, 'C', $w);
1140
            } else {
1141
                $this->Texto('Verifique documento:', $x, null, 'C', $w);
1142
                $this->Ln();
1143
                $this->Texto($this->web_verificacion, $x, null, 'C', $w);
1144
            }
1145
        }
1146
    }
1147
1148
    /**
1149
     * Método que agrega el acuse de rebido
1150
     * @param x Posición horizontal de inicio en el PDF
1151
     * @param y Posición vertical de inicio en el PDF
1152
     * @param w Ancho del acuse de recibo
1153
     * @param h Alto del acuse de recibo
1154
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
1155
     * @version 2018-04-13
1156
     */
1157
    protected function agregarAcuseRecibo($x = 83, $y = 190, $w = 60, $h = 40)
1158
    {
1159
        $y = (!$this->papelContinuo and !$this->timbre_pie) ? $this->x_fin_datos : $y;
1160
        $this->SetTextColorArray([0,0,0]);
1161
        $this->Rect($x, $y, $w, $h, 'D', ['all' => ['width' => 0.1, 'color' => [0, 0, 0]]]);
1162
        $this->setFont('', 'B', 10);
1163
        $this->Texto('Acuse de recibo', $x, $y+1, 'C', $w);
1164
        $this->setFont('', 'B', 8);
1165
        $this->Texto('Nombre', $x+2, $this->y+8);
1166
        $this->Texto('_________________________', $x+18);
1167
        $this->Texto('RUN', $x+2, $this->y+6);
1168
        $this->Texto('_________________________', $x+18);
1169
        $this->Texto('Fecha', $x+2, $this->y+6);
1170
        $this->Texto('_________________________', $x+18);
1171
        $this->Texto('Recinto', $x+2, $this->y+6);
1172
        $this->Texto('_________________________', $x+18);
1173
        $this->Texto('Firma', $x+2, $this->y+8);
1174
        $this->Texto('_________________________', $x+18);
1175
        $this->setFont('', 'B', 7);
1176
        $this->MultiTexto('El acuse de recibo que se declara en este acto, de acuerdo a lo dispuesto en la letra b) del Art. 4°, y la letra c) del Art. 5° de la Ley 19.983, acredita que la entrega de mercaderías o servicio (s) prestado (s) ha (n) sido recibido (s).'."\n", $x, $this->y+6, 'J', $w);
1177
    }
1178
1179
    /**
1180
     * Método que agrega el acuse de rebido
1181
     * @param x Posición horizontal de inicio en el PDF
1182
     * @param y Posición vertical de inicio en el PDF
1183
     * @param w Ancho del acuse de recibo
1184
     * @param h Alto del acuse de recibo
1185
     * @author Pablo Reyes (https://github.com/pabloxp)
1186
     * @version 2015-11-17
1187
     */
1188
    protected function agregarAcuseReciboContinuo($x = 3, $y = null, $w = 68, $h = 40)
1189
    {
1190
        $this->SetTextColorArray([0,0,0]);
1191
        $this->Rect($x, $y, $w, $h, 'D', ['all' => ['width' => 0.1, 'color' => [0, 0, 0]]]);
1192
        $style = array('width' => 0.2,'color' => array(0, 0, 0));
1193
        $this->Line($x, $y+22, $w+3, $y+22, $style);
1194
        //$this->setFont('', 'B', 10);
1195
        //$this->Texto('Acuse de recibo', $x, $y+1, 'C', $w);
1196
        $this->setFont('', 'B', 6);
1197
        $this->Texto('Nombre', $x+2, $this->y+8);
1198
        $this->Texto('_____________________________________________', $x+12);
1199
        $this->Texto('RUN', $x+2, $this->y+6);
1200
        $this->Texto('________________', $x+12);
1201
        $this->Texto('Firma', $x+32, $this->y+0.5);
1202
        $this->Texto('___________________', $x+42.5);
1203
        $this->Texto('Fecha', $x+2, $this->y+6);
1204
        $this->Texto('________________', $x+12);
1205
        $this->Texto('Recinto', $x+32, $this->y+0.5);
1206
        $this->Texto('___________________', $x+42.5);
1207
1208
        $this->setFont('', 'B', 5);
1209
        $this->MultiTexto('El acuse de recibo que se declara en este acto, de acuerdo a lo dispuesto en la letra b) del Art. 4°, y la letra c) del Art. 5° de la Ley 19.983, acredita que la entrega de mercaderías o servicio (s) prestado (s) ha (n) sido recibido (s).'."\n", $x+2, $this->y+8, 'J', $w-3);
1210
    }
1211
1212
    /**
1213
     * Método que agrega la leyenda de destino
1214
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
1215
     * @version 2018-09-10
1216
     */
1217
    protected function agregarLeyendaDestino($tipo, $y = 190, $font_size = 10)
1218
    {
1219
        $y = (!$this->papelContinuo and !$this->timbre_pie and $this->x_fin_datos<=$y) ? $this->x_fin_datos : $y;
1220
        $y += 48;
1221
        $this->setFont('', 'B', $font_size);
1222
        $this->Texto('CEDIBLE'.($tipo==52?' CON SU FACTURA':''), null, $y, 'R');
1223
    }
1224
1225
    /**
1226
     * Método que agrega la leyenda de destino
1227
     * @author Esteban De La Fuente Rubio, DeLaF (esteban[at]sasco.cl)
1228
     * @version 2017-10-05
1229
     */
1230
    protected function agregarLeyendaDestinoContinuo($tipo)
1231
    {
1232
        $this->setFont('', 'B', 8);
1233
        $this->Texto('CEDIBLE'.($tipo==52?' CON SU FACTURA':''), null, $this->y+6, 'R');
1234
    }
1235
1236
}
1237