Passed
Push — master ( 8e49de...855750 )
by Joe Nilson
03:05
created

EditFacturaCliente::createViews()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright (C) 2020 joenilson.
5
 *
6
 * This library is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU Lesser General Public
8
 * License as published by the Free Software Foundation; either
9
 * version 3 of the License, or (at your option) any later version.
10
 *
11
 * This library 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 GNU
14
 * Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public
17
 * License along with this library; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA 02110-1301  USA
20
 */
21
22
namespace FacturaScripts\Plugins\fsRepublicaDominicana\Controller;
23
24
use FacturaScripts\Core\Base\DataBase\DataBaseWhere;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Base\DataBase\DataBaseWhere 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...
25
use FacturaScripts\Core\Model\Base\ModelOnChangeClass;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Model\Base\ModelOnChangeClass 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...
26
use FacturaScripts\Dinamic\Lib\AssetManager;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Dinamic\Lib\AssetManager 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...
27
use FacturaScripts\Dinamic\Lib\BusinessDocumentGenerator;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Dinamic\L...sinessDocumentGenerator 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...
28
use FacturaScripts\Dinamic\Model\Cliente;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Dinamic\Model\Cliente 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...
29
use FacturaScripts\Dinamic\Model\FacturaCliente;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Dinamic\Model\FacturaCliente 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...
30
use FacturaScripts\Core\Controller\EditFacturaCliente as ParentClass;
0 ignored issues
show
Bug introduced by
The type FacturaScripts\Core\Controller\EditFacturaCliente 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...
31
use FacturaScripts\Plugins\fsRepublicaDominicana\Model\NCFRango;
32
33
/**
34
 * Description of EditFacturaCliente
35
 *
36
 * @author joenilson
37
 */
38
class EditFacturaCliente extends ParentClass
39
{
40
    /**
41
     * Shows the document opertation type selector.
42
     *
43
     * @var bool
44
     */
45
    public $showDocOperation = false;
46
    /**
47
     * Shows the document sub-type selector.
48
     *
49
     * @var bool
50
     */
51
    public $showDocSubType = true;
52
    
53
    protected function createViews()
54
    {
55
        parent::createViews();
56
        $this->customWidgetValues();
57
    }
58
    
59
    public function customWidgetValues()
60
    {
61
        //TODO
62
    }
63
64
    /**
65
     *
66
     * @return bool
67
     */
68
//    protected function subjectChangedAction()
69
//    {
70
//        $this->setTemplate(false);
71
//
72
//        //Client data
73
//        $cliente0 = new Cliente();
74
//
75
//        /// loads model
76
//        $data = $this->getBusinessFormData();
77
//        $cliente = $cliente0->get($data['subject']['codcliente']);
78
//        $data['form']['codsubtipodoc'] = (isset($data['form']['codsubtipodoc'])) ? $cliente->codsubtipodoc : "02";
79
//        $data['form']['codoperaciondoc'] = (isset($data['form']['codoperaciondoc'])) ? "01" : "LIMPIO";
80
//        $data['form']['ncftipopago'] = (!isset($data['form']['ncftipopago'])) ? $cliente->ncftipopago : "";
81
//
82
//        $merged = array_merge($data['custom'], $data['final'], $data['form'], $data['subject']);
83
//        $this->views[$this->active]->loadFromData($merged);
84
//
85
//        /// update subject data?
86
//        if (!$this->views[$this->active]->model->exists()) {
87
//            $this->views[$this->active]->model->updateSubject();
88
//        }
89
//
90
//        $this->response->setContent(json_encode($this->views[$this->active]->model));
91
//        return false;
92
//    }
93
94
    /**
95
     *
96
     * @return bool
97
     */
98
    protected function newRefundAction()
99
    {
100
        $invoice = new FacturaCliente();
101
        if (false === $invoice->loadFromCode($this->request->request->get('idfactura'))) {
102
            $this->toolBox()->i18nLog()->warning('record-not-found');
103
            return false;
104
        }
105
106
        $lines = [];
107
        $quantities = [];
108
        foreach ($invoice->getLines() as $line) {
109
            $quantity = (float) $this->request->request->get('refund_' . $line->primaryColumnValue(), '0');
110
            if (empty($quantity)) {
111
                continue;
112
            }
113
114
            $quantities[$line->primaryColumnValue()] = 0 - $quantity;
115
            $lines[] = $line;
116
        }
117
118
        if (empty($quantities)) {
119
            $this->toolBox()->i18nLog()->warning('no-selected-item');
120
            return false;
121
        }
122
123
        $generator = new BusinessDocumentGenerator();
124
        $properties = [
125
            'codigorect' => $invoice->codigo,
126
            'codserie' => $this->request->request->get('codserie'),
127
            'fecha' => $this->request->request->get('fecha'),
128
            'idfacturarect' => $invoice->idfactura,
129
            'observaciones' => $this->request->request->get('observaciones'),
130
            'ncftipoanulacion' => $this->request->request->get('ncf-cancellation-type'),
131
            'codsubtipodoc' => '04'
132
        ];
133
        if ($generator->generate($invoice, $invoice->modelClassName(), $lines, $quantities, $properties)) {
134
            foreach ($generator->getLastDocs() as $doc) {
135
                $this->toolBox()->i18nLog()->notice('record-updated-correctly');
136
                $this->redirect($doc->url() . '&action=save-ok');
137
                return true;
138
            }
139
        }
140
141
        $this->toolBox()->i18nLog()->error('record-save-error');
142
        return false;
143
    }
144
}
145