NormalizeNotaDebitoJob   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 33
dl 0
loc 60
ccs 28
cts 32
cp 0.875
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A execute() 0 43 2
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * LibreDTE: Biblioteca PHP (Núcleo).
7
 * Copyright (C) LibreDTE <https://www.libredte.cl>
8
 *
9
 * Este programa es software libre: usted puede redistribuirlo y/o modificarlo
10
 * bajo los términos de la Licencia Pública General Affero de GNU publicada por
11
 * la Fundación para el Software Libre, ya sea la versión 3 de la Licencia, o
12
 * (a su elección) cualquier versión posterior de la misma.
13
 *
14
 * Este programa se distribuye con la esperanza de que sea útil, pero SIN
15
 * GARANTÍA ALGUNA; ni siquiera la garantía implícita MERCANTIL o de APTITUD
16
 * PARA UN PROPÓSITO DETERMINADO. Consulte los detalles de la Licencia Pública
17
 * General Affero de GNU para obtener una información más detallada.
18
 *
19
 * Debería haber recibido una copia de la Licencia Pública General Affero de
20
 * GNU junto a este programa.
21
 *
22
 * En caso contrario, consulte <http://www.gnu.org/licenses/agpl.html>.
23
 */
24
25
namespace libredte\lib\Core\Package\Billing\Component\Document\Worker\Normalizer\Job;
26
27
use Derafu\Backbone\Abstract\AbstractJob;
28
use Derafu\Backbone\Attribute\Job;
29
use Derafu\Backbone\Contract\JobInterface;
30
use Derafu\Repository\Contract\RepositoryManagerInterface;
31
use libredte\lib\Core\Package\Billing\Component\Document\Contract\DocumentBagInterface;
32
use libredte\lib\Core\Package\Billing\Component\Document\Worker\Normalizer\Trait\NormalizeDescuentosRecargosTrait;
33
use libredte\lib\Core\Package\Billing\Component\Document\Worker\Normalizer\Trait\NormalizeDetalleTrait;
34
use libredte\lib\Core\Package\Billing\Component\Document\Worker\Normalizer\Trait\NormalizeImpuestoAdicionalRetencionTrait;
35
use libredte\lib\Core\Package\Billing\Component\Document\Worker\Normalizer\Trait\NormalizeIvaMntTotalTrait;
36
37
/**
38
 * Normalizador del documento nota de débito.
39
 */
40
#[Job(name: 'normalize_nota_debito', worker: 'normalizer', component: 'document', package: 'billing')]
41
class NormalizeNotaDebitoJob extends AbstractJob implements JobInterface
42
{
43
    // Traits usados por este normalizador.
44
    use NormalizeDetalleTrait;
45
    use NormalizeDescuentosRecargosTrait;
46
    use NormalizeImpuestoAdicionalRetencionTrait;
47
    use NormalizeIvaMntTotalTrait;
48
49
    public function __construct(
50
        protected RepositoryManagerInterface $repositoryManager
51
    ) {
52
    }
53
54
    /**
55
     * {@inheritDoc}
56
     */
57 1
    public function execute(DocumentBagInterface $bag): void
58
    {
59 1
        $data = $bag->getNormalizedData();
60
61
        // Completar con nodos por defecto.
62 1
        $data = array_replace_recursive([
63 1
            'Encabezado' => [
64 1
                'IdDoc' => false,
65 1
                'Emisor' => false,
66 1
                'Receptor' => false,
67 1
                'RUTSolicita' => false,
68 1
                'Totales' => [
69 1
                    'MntNeto' => 0,
70 1
                    'MntExe' => 0,
71 1
                    'TasaIVA' => $bag->getTipoDocumento()->getDefaultTasaIVA(),
72 1
                    'IVA' => false,
73 1
                    'ImptoReten' => false,
74 1
                    'IVANoRet' => false,
75 1
                    'CredEC' => false,
76 1
                    'MntTotal' => 0,
77 1
                ],
78 1
            ],
79 1
        ], $data);
0 ignored issues
show
Bug introduced by
It seems like $data can also be of type null; however, parameter $replacements of array_replace_recursive() does only seem to accept array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

79
        ], /** @scrutinizer ignore-type */ $data);
Loading history...
80
81
        // Actualizar los datos normalizados.
82 1
        $bag->setNormalizedData($data);
83
84
        // Normalizar datos.
85 1
        $this->normalizeDetalle($bag);
86 1
        $this->normalizeDescuentosRecargos($bag);
87 1
        $this->normalizeImpuestoAdicionalRetencion($bag);
88 1
        $this->normalizeIvaMntTotal($bag);
89
90 1
        $data = $bag->getNormalizedData();
91
92
        // Corregir monto neto e IVA.
93 1
        if (!$data['Encabezado']['Totales']['MntNeto']) {
94
            $data['Encabezado']['Totales']['MntNeto'] = 0;
95
            $data['Encabezado']['Totales']['TasaIVA'] = false;
96
        }
97
98
        // Actualizar los datos normalizados.
99 1
        $bag->setNormalizedData($data);
100
    }
101
}
102