SalesLineMod::renderField()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 3
eloc 6
c 1
b 1
f 1
nc 3
nop 4
dl 0
loc 11
rs 10
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\Contract\SalesLineModInterface;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Contract\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\Translator;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\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\Core\Tools;
25
26
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\ImpuestoProducto;
27
28
class SalesLineMod implements SalesLineModInterface
29
{
30
31
    public function apply(SalesDocument &$model, array &$lines, array $formData): void
32
    {
33
        // TODO: Implement apply() method.
34
    }
35
36
    /**
37
     * @param array $formData
38
     * @param SalesDocumentLine $line
39
     * @param string $id
40
     * @return void
41
     */
42
    public function applyToLine(array $formData, SalesDocumentLine &$line, string $id): void
43
    {
44
        $line->rdtaxisc = $formData['rdtaxisc_' . $id] ?? null;
45
        $line->rdtaxcdt = $formData['rdtaxcdt_' . $id] ?? null;
46
    }
47
48
    public function assets(): void
49
    {
50
    }
51
52
    public function map(array $lines, SalesDocument $model): array
53
    {
54
        return [];
55
    }
56
57
    public function newModalFields(): array
58
    {
59
        return ['rdtaxisc', 'rdtaxcdt'];
60
    }
61
62
    public function newFields(): array
63
    {
64
        return [];
65
    }
66
67
    public function newTitles(): array
68
    {
69
        return [];
70
    }
71
72
    public function renderField(string $idlinea, SalesDocumentLine $line, SalesDocument $model, string $field): ?string
73
    {
74
        $i18n = new Translator();
75
        
76
        if ($field === 'rdtaxisc') {
77
            return $this->rdTax($i18n, $idlinea, $line, $model, $field);
78
        }
79
        if ($field === 'rdtaxcdt') {
80
            return $this->rdTax($i18n, $idlinea, $line, $model, $field);
81
        }
82
        return null;
83
    }
84
85
    public function renderTitle(SalesDocument $model, string $field): ?string
86
    {
87
        return null;
88
    }
89
90
    protected function rdTax($i18n, $idlinea, $line, $model, $field): string
91
    {
92
        $attributes = $model->editable ?
93
            'name="'. $field .'_' . $idlinea . '"' :
94
            'disabled=""';
95
96
        $title = $this->rdTaxTitle($i18n, $field);
97
        $lineTax = $this->productoTaxValue($line->idproducto, $field);
98
        //$line->$field = $lineTax->porcentaje;
99
        $fieldValue = is_null($lineTax) ? 0 : $lineTax->porcentaje;
100
101
        return '<div class="col-6">'
102
            . $title
103
            . '<input type="number" ' . $attributes . ' value="' . $fieldValue. '" class="form-control" readonly=""/>'
104
            . '</div>'
105
            . '</div>';
106
    }
107
108
    protected function rdTaxTitle($i18n, $field): string
109
    {
110
        return '<div class="mb-2">' . $i18n->trans($field);
111
    }
112
113
    protected function productoTaxValue($idproducto, $rdtaxid): ?ImpuestoProducto
114
    {
115
        if (null !== $idproducto) {
116
            $taxProducts = new ImpuestoProducto();
117
            $taxType = ($rdtaxid === 'rdtaxisc') ? "ISC" : "CDT";
118
            return $taxProducts->getTaxByProduct($idproducto, $taxType, 'venta');
119
        }
120
        return null;
121
    }
122
123
    public function getFastLine(SalesDocument $model, array $formData): ?SalesDocumentLine
124
    {
125
        // TODO: Implement getFastLine() method.
126
    }
127
}