ImpuestoProducto::test()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 1
eloc 4
c 1
b 1
f 1
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
namespace FacturaScripts\Plugins\fsRepublicaDominicana\Model;
3
4
5
use FacturaScripts\Core\Base\DataBase;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Base\DataBase 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...
6
use FacturaScripts\Core\Template\ModelClass;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Template\ModelClass 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...
7
use FacturaScripts\Core\Template\ModelTrait;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Template\ModelTrait 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...
8
use FacturaScripts\Core\Session;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Session 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...
9
use FacturaScripts\Core\Tools;
10
use FacturaScripts\Dinamic\Model\Impuesto;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Dinamic\Model\Impuesto 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...
11
12
class ImpuestoProducto extends ModelClass
13
{
14
    use ModelTrait;
15
16
    /** @var string */
17
    public $codimpuesto;
18
19
    /** @var bool */
20
    public $compra;
21
22
    /** @var string */
23
    public $creationdate;
24
25
    /** @var int */
26
    public $id;
27
28
    /** @var int */
29
    public $idempresa;
30
31
    /** @var int */
32
    public $idproducto;
33
34
    /** @var string */
35
    public $lastnick;
36
37
    /** @var string */
38
    public $lastupdate;
39
40
    /** @var string */
41
    public $nick;
42
43
    /** @var bool */
44
    public $venta;
45
46
    /** @var @var int */
0 ignored issues
show
Documentation Bug introduced by
The doc comment @var at position 0 could not be parsed: Unknown type name '@var' at position 0 in @var.
Loading history...
47
    public $porcentaje;
48
49
    public function clear(): void
50
    {
51
        parent::clear();
52
        $this->compra = false;
53
        $this->creationdate = Tools::dateTime();
54
        $this->idempresa = 0;
55
        $this->idproducto = null;
56
        $this->nick = Session::get('user')->nick ?? null;
57
        $this->venta = false;
58
        $this->porcentaje = 0;
59
    }
60
61
    public static function primaryColumn(): string
62
    {
63
        return "id";
64
    }
65
66
    public static function tableName(): string
67
    {
68
        return "impuestosproductos";
69
    }
70
71
    public function test(): bool
72
    {
73
        $this->codimpuesto = Tools::noHtml($this->codimpuesto);
74
        $this->lastnick = Tools::noHtml($this->lastnick);
75
        $this->nick = Tools::noHtml($this->nick);
76
        return parent::test();
77
    }
78
79
    protected function saveInsert(array $values = []): bool
80
    {
81
        $this->lastupdate = null;
82
        $this->lastnick = null;
83
        return parent::saveInsert($values);
84
    }
85
86
    protected function saveUpdate(array $values = []): bool
87
    {
88
        $this->lastupdate = Tools::dateTime();
89
        $this->lastnick = Session::get('user')->nick ?? null;
90
        return parent::saveUpdate($values);
91
    }
92
93
    public function getTaxByProduct($idproducto, $rdtaxid, $use = 'venta'): ?ImpuestoProducto
94
    {
95
        $dataBase = new DataBase();
96
        $sql = "SELECT * FROM impuestosproductos WHERE idproducto = " .
97
                (int)$idproducto .
98
                " AND codimpuesto = '" . $dataBase->escapeString($rdtaxid) . "'" .
99
                " AND " . $use . " = true" . ";";
100
        $data = $dataBase->select($sql);
101
        if (empty($data) === true || in_array($data[0], [null, ''], true)) {
102
            return null;
103
        }
104
        $impuestos = new Impuesto();
105
        $impuesto = $impuestos->get($data[0]['codimpuesto']);
106
        $data[0]['porcentaje'] = $impuesto->iva;
107
        return new ImpuestoProducto($data[0]);
108
    }
109
}
110