Issues (457)

Core/Model/Base/InvoiceLineTrait.php (1 issue)

1
<?php
2
/**
3
 * This file is part of FacturaScripts
4
 * Copyright (C) 2013-2024 Carlos Garcia Gomez <[email protected]>
5
 *
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU Lesser General Public License as
8
 * published by the Free Software Foundation, either version 3 of the
9
 * License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License
17
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
namespace FacturaScripts\Core\Model\Base;
21
22
use FacturaScripts\Core\Base\DataBase\DataBaseWhere;
23
use FacturaScripts\Dinamic\Model\DocTransformation;
24
25
trait InvoiceLineTrait
26
{
27
    abstract public function hasRefundedQuantity(): bool;
28
29
    public function refundedQuantity(): float
30
    {
31
        // si no hay una rectificativa, devolvemos 0
32
        if (false === $this->hasRefundedQuantity()) {
33
            return 0.0;
34
        }
35
36
        // comprobamos líneas de facturas rectificativas
37
        $quantity = 0.0;
38
        $where = [new DataBaseWhere('idlinearect', $this->idlinea)];
39
        foreach (self::all($where, [], 0, 0) as $line) {
40
            $quantity += abs($line->cantidad);
41
        }
42
        if ($quantity) {
43
            return $quantity;
44
        }
45
46
        // comprobamos líneas relacionadas
47
        $docTransformation = new DocTransformation();
48
        $whereTrans = [
49
            new DataBaseWhere('model1', $this->getDocument()->modelClassName()),
0 ignored issues
show
It seems like getDocument() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

49
            new DataBaseWhere('model1', $this->/** @scrutinizer ignore-call */ getDocument()->modelClassName()),
Loading history...
50
            new DataBaseWhere('iddoc1', $this->idfactura),
51
            new DataBaseWhere('idlinea1', $this->idlinea)
52
        ];
53
        foreach ($docTransformation->all($whereTrans, [], 0, 0) as $docTrans) {
54
            $quantity += abs($docTrans->cantidad);
55
        }
56
57
        return $quantity;
58
    }
59
}
60