Passed
Push — master ( 9a172a...9c608c )
by Joe Nilson
03:46 queued 13s
created

SalesLineMod::rdTax()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 3
eloc 11
c 1
b 1
f 1
nc 4
nop 5
dl 0
loc 16
rs 9.9
1
<?php
2
/*
3
 * Copyright (C) 2023 Joe Nilson <[email protected]>
4
 *
5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Lesser General Public License as
7
 * published by the Free Software Foundation, either version 3 of the
8
 * License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU Lesser General Public License for more details.
14
 * You should have received a copy of the GNU Lesser General Public License
15
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 */
17
18
namespace FacturaScripts\Plugins\fsRepublicaDominicana\Mod;
19
20
use FacturaScripts\Core\Base\Contract\SalesLineModInterface;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Base...t\SalesLineModInterface was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
21
use FacturaScripts\Core\Base\Translator;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Base\Translator was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
use FacturaScripts\Core\Model\Base\SalesDocument;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Model\Base\SalesDocument was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
23
use FacturaScripts\Core\Model\Base\SalesDocumentLine;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Model\Base\SalesDocumentLine was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
24
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\ImpuestoProducto;
25
26
class SalesLineMod implements SalesLineModInterface
27
{
28
29
    public function apply(SalesDocument &$model, array &$lines, array $formData)
30
    {
31
        // TODO: Implement apply() method.
32
    }
33
34
    public function applyToLine(array $formData, SalesDocumentLine &$line, string $id)
35
    {
36
        $line->rdtaxisc = $formData['rdtaxisc_' . $id] ?? null;
37
        $line->rdtaxcdt = $formData['rdtaxcdt_' . $id] ?? null;
38
    }
39
40
    public function assets(): void
41
    {
42
    }
43
44
    public function map(array $lines, SalesDocument $model): array
45
    {
46
        return [];
47
    }
48
49
    public function newModalFields(): array
50
    {
51
        return ['rdtaxisc', 'rdtaxcdt'];
52
    }
53
54
    public function newFields(): array
55
    {
56
        return [];
57
    }
58
59
    public function newTitles(): array
60
    {
61
        return [];
62
    }
63
64
    public function renderField(Translator $i18n, string $idlinea, SalesDocumentLine $line, SalesDocument $model, string $field): ?string
65
    {
66
        if ($field === 'rdtaxisc') {
67
            return $this->rdTax($i18n, $idlinea, $line, $model, $field);
68
        }
69
        if ($field === 'rdtaxcdt') {
70
            return $this->rdTax($i18n, $idlinea, $line, $model, $field);
71
        }
72
        return null;
73
    }
74
75
    public function renderTitle(Translator $i18n, SalesDocument $model, string $field): ?string
76
    {
77
        return null;
78
    }
79
80
    protected function rdTax($i18n, $idlinea, $line, $model, $field): string
81
    {
82
        $attributes = $model->editable ?
83
            'name="'. $field .'_' . $idlinea . '"' :
84
            'disabled=""';
85
86
        $title = $this->rdTaxTitle($i18n, $field);
87
        $lineTax = $this->productoTaxValue($line->idproducto, $field);
88
        //$line->$field = $lineTax->porcentaje;
89
        $fieldValue = is_null($lineTax) ? 0 : $lineTax->porcentaje;
90
91
        return '<div class="col-6">'
92
            . $title
93
            . '<input type="number" ' . $attributes . ' value="' . $fieldValue. '" class="form-control" readonly=""/>'
94
            . '</div>'
95
            . '</div>';
96
    }
97
98
    protected function rdTaxTitle($i18n, $field): string
99
    {
100
        return '<div class="mb-2">' . $i18n->trans($field);
101
    }
102
103
    protected function productoTaxValue($idproducto, $rdtaxid): ?ImpuestoProducto
104
    {
105
        $taxProducts = new ImpuestoProducto();
106
        $taxType = ($rdtaxid === 'rdtaxisc') ? "ISC" : "CDT";
107
        return $taxProducts->getTaxByProduct($idproducto, $taxType, 'venta');
108
    }
109
}