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

ImpuestoProducto::saveInsert()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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