CompanyPresenter   C
last analyzed

Complexity

Total Complexity 61

Size/Duplication

Total Lines 484
Duplicated Lines 22.73 %

Coupling/Cohesion

Components 1
Dependencies 9

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 61
c 2
b 0
f 0
lcom 1
cbo 9
dl 110
loc 484
rs 6.018

25 Methods

Rating   Name   Duplication   Size   Complexity  
A startup() 0 4 1
A beforeRender() 0 4 1
A actionDefault() 0 4 1
A renderDefault() 0 5 1
A actionActiveCompanies() 0 8 1
A renderActiveCompanies() 0 5 1
A actionInactiveCompanies() 0 8 1
A renderInactiveCompanies() 0 5 1
A createComponentActiveGrid() 19 19 1
A createComponentInactiveGrid() 19 19 1
B actionDeactivate() 31 31 4
B actionActivate() 31 31 4
A actionUpdate() 0 6 2
A renderUpdate() 0 6 1
B createComponentForm() 0 24 2
B formSubmitted() 0 27 2
C actionDetail() 0 41 16
A renderDetail() 0 16 1
B createComponentBusinessmenGrid() 0 38 4
B actionChangeActive() 10 34 3
A actionBusinessmanDetail() 0 7 1
C createComponentInvestmentsGrid() 0 68 8
A actionUpdateContract() 0 7 1
A actionDownloadContract() 0 7 1
A actionSendContract() 0 7 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like CompanyPresenter often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use CompanyPresenter, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/**
4
 * This file is part of the Investform module for webcms2.
5
 * Copyright (c) @see LICENSE
6
 */
7
8
namespace AdminModule\InvestformModule;
9
10
use Nette\Forms\Form;
11
use WebCMS\InvestformModule\Entity\Businessman;
12
use WebCMS\InvestformModule\Entity\Company;
13
use WebCMS\InvestformModule\Entity\Investment;
14
15
/**
16
 * Description of
17
 *
18
 * @author Jakub Sanda <[email protected]>
19
 */
20
class CompanyPresenter extends BasePresenter
21
{
22
    
23
    private $company;
24
25
    private $companies;
26
27
    private $businessmen;
28
29
    private $newInvestments = 0;
30
31
    private $newInvestmentsAmount = 0;
32
33
    private $openInvestments = 0;
34
35
    private $openInvestmentsAmount = 0;
36
37
    private $closedInvestments = 0;
38
39
    private $closedInvestmentsAmount = 0;
40
41
    private $paidInvestments = 0;
42
43
    private $paidInvestmentsAmount = 0;
44
45
    protected function startup()
46
    {
47
    	parent::startup();
48
    }
49
50
    protected function beforeRender()
51
    {
52
	   parent::beforeRender();
53
    }
54
55
    public function actionDefault($idPage)
56
    {
57
58
    }
59
60
    public function renderDefault($idPage)
61
    {
62
    	$this->reloadContent();
63
    	$this->template->idPage = $idPage;
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing idPage on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
64
    }
65
66
    public function actionActiveCompanies($idPage)
0 ignored issues
show
Unused Code introduced by
The parameter $idPage is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
67
    {
68
        $this->reloadContent();
69
70
        $this->companies = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Company')->findBy(array(
71
            'active' => true
72
        ));
73
    }
74
75
    public function renderActiveCompanies($idPage)
76
    {
77
        $this->template->idPage = $idPage;
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing idPage on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
78
        $this->template->numberOfCompanies = count($this->companies);
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing numberOfCompanies on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
79
    }
80
81
    public function actionInactiveCompanies($idPage)
0 ignored issues
show
Unused Code introduced by
The parameter $idPage is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
82
    {
83
        $this->reloadContent();
84
85
        $this->companies = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Company')->findBy(array(
86
            'active' => false
87
        ));
88
    }
89
90
    public function renderInactiveCompanies($idPage)
91
    {
92
        $this->template->idPage = $idPage;
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing idPage on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
93
        $this->template->numberOfCompanies = count($this->companies);
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing numberOfCompanies on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
94
    }
95
96 View Code Duplication
    protected function createComponentActiveGrid($name)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
97
    {
98
        $grid = $this->createGrid($this, $name, "\WebCMS\InvestformModule\Entity\Company", null, array(
99
            'active = true',
100
        ));
101
102
        $grid->setFilterRenderType(\Grido\Components\Filters\Filter::RENDER_INNER);
103
104
        $grid->addColumnText('name', 'Name')->setSortable();
105
106
        $grid->addColumnText('street', 'Street and number')->setSortable();
107
108
        $grid->addColumnText('zipCity', 'Zip and city')->setSortable();
109
110
        $grid->addActionHref("deactivate", 'Deactivate', 'deactivate', array('idPage' => $this->actualPage->getId()))->getElementPrototype()->addAttributes(array('class' => array('btn', 'btn-primary', 'ajax', 'grey')));
111
        $grid->addActionHref("detail", 'Company detail', 'detail', array('idPage' => $this->actualPage->getId()))->getElementPrototype()->addAttributes(array('class' => array('btn', 'btn-primary', 'green')));
112
113
        return $grid;
114
    }
115
116 View Code Duplication
    protected function createComponentInactiveGrid($name)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
117
    {
118
        $grid = $this->createGrid($this, $name, "\WebCMS\InvestformModule\Entity\Company", null, array(
119
            'active = false',
120
        ));
121
122
        $grid->setFilterRenderType(\Grido\Components\Filters\Filter::RENDER_INNER);
123
124
        $grid->addColumnText('name', 'Name')->setSortable();
125
126
        $grid->addColumnText('street', 'Street and number')->setSortable();
127
128
        $grid->addColumnText('zipCity', 'Zip and city')->setSortable();
129
130
        $grid->addActionHref("activate", 'Activate', 'activate', array('idPage' => $this->actualPage->getId()))->getElementPrototype()->addAttributes(array('class' => array('btn', 'btn-primary', 'ajax', 'grey')));
131
        $grid->addActionHref("detail", 'Company detail', 'detail', array('idPage' => $this->actualPage->getId()))->getElementPrototype()->addAttributes(array('class' => array('btn', 'btn-primary', 'green')));
132
133
        return $grid;
134
    }
135
136 View Code Duplication
    public function actionDeactivate($id, $idPage, $inDetail = false)
0 ignored issues
show
Unused Code introduced by
The parameter $idPage is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
137
    {
138
139
        $this->company = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Company')->find($id);
140
        $this->company->setActive(false);
141
142
        $this->businessmen = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Businessman')->findBy(array(
143
            'company' => $this->company
144
        ));
145
146
        if ($this->businessmen) {
147
            foreach ($this->businessmen as $businessman) {
148
                $businessman->setActive(false);
149
            }
150
        }
151
152
        $this->em->flush();
153
154
        $this->flashMessage('Company has been deactivated', 'success');
155
156
        if ($inDetail) {
157
            $this->forward('detail', array(
158
                'id' => $id,
159
                'idPage' => $this->actualPage->getId()
160
            ));
161
        } else {
162
            $this->forward('activeCompanies', array(
163
                'idPage' => $this->actualPage->getId()
164
            ));
165
        }
166
    }
167
168 View Code Duplication
    public function actionActivate($id, $idPage, $inDetail = false)
0 ignored issues
show
Unused Code introduced by
The parameter $idPage is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
169
    {
170
171
        $this->company = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Company')->find($id);
172
        $this->company->setActive(true);
173
174
        $this->businessmen = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Businessman')->findBy(array(
175
            'company' => $this->company
176
        ));
177
178
        if ($this->businessmen) {
179
            foreach ($this->businessmen as $businessman) {
180
                $businessman->setActive(true);
181
            }
182
        }
183
184
        $this->em->flush();
185
186
        $this->flashMessage('Company has been activated', 'success');
187
188
        if ($inDetail) {
189
            $this->forward('detail', array(
190
                'id' => $id,
191
                'idPage' => $this->actualPage->getId()
192
            ));
193
        } else {
194
            $this->forward('inactiveCompanies', array(
195
                'idPage' => $this->actualPage->getId()
196
            ));
197
        }
198
    }
199
200
201
    public function actionUpdate($id, $idPage)
0 ignored issues
show
Unused Code introduced by
The parameter $idPage is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
202
    {
203
        if ($id) {
204
            $this->company = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Company')->find($id);
205
        }
206
    }
207
208
    public function renderUpdate($idPage)
209
    {
210
        $this->reloadContent();
211
212
        $this->template->idPage = $idPage;
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing idPage on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
213
    }
214
215
    public function createComponentForm($name)
0 ignored issues
show
Unused Code introduced by
The parameter $name is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
216
    {
217
        $form = $this->createForm('form-submit', 'default', null);
0 ignored issues
show
Unused Code introduced by
The call to CompanyPresenter::createForm() has too many arguments starting with 'form-submit'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
218
219
        $form->addText('name', 'Name')->setRequired('Name is mandatory.');
220
        $form->addText('street', 'Street and number');
221
        $form->addText('zipCity', 'Zip and city');
222
        $form->addText('ico', 'Ico');
223
        $form->addText('dic', 'Dic');
224
        $form->addText('email', 'Email')
225
            ->addRule(Form::EMAIL, 'This email is not valid.')
226
            ->setRequired('Email is mandatory.');
227
        $form->addText('phone', 'Phone')->setRequired('Phone is mandatory.');
228
229
        if ($this->company) {
230
            $form->setDefaults($this->company->toArray());
231
        }
232
233
        $form->addSubmit('save', 'Save new company');
234
235
        $form->onSuccess[] = callback($this, 'formSubmitted');
236
237
        return $form;
238
    }
239
240
    public function formSubmitted($form)
241
    {
242
        $values = $form->getValues();
243
244
        if (!$this->company) {
245
            $this->company = new Company;
246
            $this->em->persist($this->company);
247
        }
248
249
        $this->company->setName($values->name);
250
        $this->company->setStreet($values->street);
251
        $this->company->setZipCity($values->zipCity);
252
        $this->company->setIco($values->ico);
253
        $this->company->setDic($values->dic);
254
        $this->company->setEmail($values->email);
255
        $this->company->setPhone($values->phone);     
256
        $this->company->setActive(true);    
257
258
        $this->em->flush();
259
260
        $this->flashMessage('Company has been updated.', 'success');
261
262
        $this->forward('detail', array(
263
            'id' => $this->company->getId(),
264
            'idPage' => $this->actualPage->getId()
265
        ));
266
    }
267
268
    public function actionDetail($id, $idPage)
0 ignored issues
show
Unused Code introduced by
The parameter $idPage is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
269
    {
270
        $this->company = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Company')->find($id);
271
        $this->businessmen = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Businessman')->findBy(array(
272
            'company' => $this->company
273
        ));
274
275
        foreach ($this->businessmen as $businessman) {
276
            $investments = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Investment')->findBy(array(
277
                'businessman' => $businessman
278
            ));
279
280
            if ($investments) {
281
282
                foreach ($investments as $investment) {
283
                    // new investment
284
                    if (!$investment->getContractSend() && !$investment->getContractClosed() && !$investment->getContractPaid()) {
285
                        $this->newInvestments++;
286
                        $this->newInvestmentsAmount += $investment->getInvestment();
287
                    }
288
                    // open investment
289
                    if ($investment->getContractSend() && !$investment->getContractClosed() && !$investment->getContractPaid()) {
290
                        $this->openInvestments++;
291
                        $this->openInvestmentsAmount += $investment->getInvestment();
292
                    }
293
                    // closed investment
294
                    if ($investment->getContractSend() && $investment->getContractClosed() && !$investment->getContractPaid()) {
295
                        $this->closedInvestments++;
296
                        $this->closedInvestmentsAmount += $investment->getInvestment();
297
                    }
298
                    // paid investment
299
                    if ($investment->getContractSend() && $investment->getContractClosed() && $investment->getContractPaid()) {
300
                        $this->paidInvestments++;
301
                        $this->paidInvestmentsAmount += $investment->getInvestment();
302
                    }
303
                }
304
305
            }
306
307
        }
308
    }
309
310
    public function renderDetail($idPage)
311
    {
312
        $this->reloadContent();
313
        $this->template->idPage = $idPage;
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing idPage on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
314
        $this->template->businessmen = $this->businessmen;
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing businessmen on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
315
        $this->template->company = $this->company;
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing company on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
316
317
        $this->template->newInvestments = $this->newInvestments;
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing newInvestments on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
318
        $this->template->openInvestments = $this->openInvestments;
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing openInvestments on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
319
        $this->template->closedInvestments = $this->closedInvestments;
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing closedInvestments on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
320
        $this->template->paidInvestments = $this->paidInvestments;
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing paidInvestments on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
321
        $this->template->newInvestmentsAmount = $this->newInvestmentsAmount;
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing newInvestmentsAmount on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
322
        $this->template->openInvestmentsAmount = $this->openInvestmentsAmount;
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing openInvestmentsAmount on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
323
        $this->template->closedInvestmentsAmount = $this->closedInvestmentsAmount;
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing closedInvestmentsAmount on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
324
        $this->template->paidInvestmentsAmount = $this->paidInvestmentsAmount;
0 ignored issues
show
Documentation introduced by
The property $template is declared private in Nette\Application\UI\Control. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Bug introduced by
Accessing paidInvestmentsAmount on the interface Nette\Templating\ITemplate suggest that you code against a concrete implementation. How about adding an instanceof check?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
Loading history...
325
    }
326
327
    protected function createComponentBusinessmenGrid($name)
328
    {
329
330
        $grid = $this->createGrid($this, $name, "\WebCMS\InvestformModule\Entity\Businessman", null, array(
331
            'company = '.$this->company->getId()
332
        ));
333
334
        $grid->setFilterRenderType(\Grido\Components\Filters\Filter::RENDER_INNER);
335
336
        $grid->addColumnText('name', 'Name')->setCustomRender(function($item) {
337
            if ($item->getName()) {
338
                return $item->getName() . ' ' . $item->getLastname();
339
            } else {
340
                return $item->getBusinessname();
341
            }
342
        });
343
344
        $grid->addColumnText('businessId', 'Business ID');
345
346
        $grid->addColumnText('company', 'Company')->setCustomRender(function($item) {
347
            if ($item->getCompany()) {
348
                return $item->getCompany()->getName();
349
            }
350
        });
351
352
        $grid->addColumnText('active', 'Active')->setCustomRender(function($item) {
353
            if ($item->getActive()) {
354
                return 'Yes';
355
            } else {
356
                return 'No';
357
            }
358
        });
359
360
        $grid->addActionHref("changeActive", 'Change active state', 'changeActive', array('idPage' => $this->actualPage->getId()))->getElementPrototype()->addAttributes(array('class' => array('btn', 'btn-primary', 'ajax', 'green')));
361
        $grid->addActionHref("businessmanDetail", 'Businessman detail', 'businessmanDetail', array('idPage' => $this->actualPage->getId()))->getElementPrototype()->addAttributes(array('class' => array('btn', 'btn-primary', 'green')));
362
363
        return $grid;
364
    }
365
366
    public function actionChangeActive($id, $idPage)
0 ignored issues
show
Unused Code introduced by
The parameter $idPage is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
367
    {
368
        $businessman = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Businessman')->find($id);
369
370
        if (!$businessman->getActive()) {
371
372
            $this->company = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Company')->find($businessman->getCompany()->getId());
373
374 View Code Duplication
            if ($this->company->getActive()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
375
                $businessman->setActive(true);
376
377
                $this->em->flush();
378
379
                $this->flashMessage('Active state has been changed', 'success');
380
            } else {
381
382
                $this->flashMessage('Active state cannot be changed. Company is inactive.', 'error');
383
            }
384
385
        } else {
386
            $businessman->setActive(false);
387
388
            $this->em->flush();
389
390
            $this->flashMessage('Active state has been changed', 'success');
391
        }
392
393
394
        
395
        $this->forward('detail', array(
396
            'id' => $businessman->getCompany()->getId(),
397
            'idPage' => $this->actualPage->getId()
398
        ));
399
    }
400
401
    public function actionBusinessmanDetail($id, $idPage)
0 ignored issues
show
Unused Code introduced by
The parameter $idPage is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
402
    {
403
        $this->forward('Businessman:detail', array(
404
            'id' => $id,
405
            'idPage' => $this->actualPage->getId()
406
        ));
407
    }
408
409
    protected function createComponentInvestmentsGrid($name)
410
    {
411
412
        $businessmenIds = array();
413
        $investments = array();
414
415
        if ($this->businessmen) {
416
            foreach ($this->businessmen as $businessman) {
417
                $businessmenIds[] = $businessman->getId();
418
            }
419
        }
420
421
        if (count($businessmenIds)) {
422
            $investments = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Investment')->findBy(array(
423
                'businessman' =>  $businessmenIds
424
            ));
425
        }
426
427
        $grid = new \Grido\Grid($this, $name);
428
        $grid->setModel($investments);
429
430
        $grid->setFilterRenderType(\Grido\Components\Filters\Filter::RENDER_INNER);
431
432
        $grid->addFilterDateRange('created', 'Created');
433
434
        $grid->addColumnDate('created', 'Created')->setDateFormat(\Grido\Components\Columns\Date::FORMAT_DATETIME);
435
436
        $grid->addColumnText('client_name', 'Client name')->setCustomRender(function($item) {
437
            return $item->getAddress()->getName().' '.$item->getAddress()->getLastname();
438
        });
439
440
        $grid->addColumnText('businessman_name', 'Businessman name')->setCustomRender(function($item) {
441
            if ($item->getBusinessman()->getName()) {
442
                return $item->getBusinessman()->getName() . ' ' . $item->getBusinessman()->getLastname();
443
            } else {
444
                return $item->getBusinessman()->getBusinessname();
445
            }
446
        });
447
448
        $grid->addColumnText('businessId', 'Business Id')->setCustomRender(function($item) {
449
            return $item->getBusinessman()->getBusinessId();
450
        });
451
452
        $grid->addColumnText('investment', 'Investment');
453
        $grid->addColumnText('contractSend', 'Contract send')->setCustomRender(function($item) {
454
            if ($item->getContractSend()) {
455
                return 'Yes';
456
            } else {
457
                return 'No';
458
            }
459
        });
460
        $grid->addColumnText('contractClosed', 'Contract closed')->setCustomRender(function($item) {
461
            return $item->getContractClosed() ? 'Yes' : 'No';
462
        });
463
        $grid->addColumnText('contractPaid', 'Contract paid')->setCustomRender(function($item) {
464
            if ($item->getContractPaid()) {
465
                return 'Yes';
466
            } else {
467
                return 'No';
468
            }
469
        });
470
471
        $grid->addActionHref("sendContract", 'Send', 'sendContract', array('idPage' => $this->actualPage->getId()))->getElementPrototype()->addAttributes(array('class' => array('btn', 'btn-primary', 'ajax', 'purple')));
472
        $grid->addActionHref("downloadContract", 'Download', 'downloadContract', array('idPage' => $this->actualPage->getId()))->getElementPrototype()->addAttributes(array('class' => array('btn', 'btn-primary', 'purple')));
473
        $grid->addActionHref("updateContract", 'Edit', 'updateContract', array('idPage' => $this->actualPage->getId()))->getElementPrototype()->addAttributes(array('class' => array('btn', 'btn-primary', 'ajax', 'green')));
474
475
        return $grid;
476
    }
477
478
    public function actionUpdateContract($id, $idPage)
0 ignored issues
show
Unused Code introduced by
The parameter $idPage is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
479
    {
480
        $this->forward('Investform:update', array(
481
            'id' => $id,
482
            'idPage' => $this->actualPage->getId()
483
        ));
484
    }
485
486
    public function actionDownloadContract($id, $idPage)
0 ignored issues
show
Unused Code introduced by
The parameter $idPage is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
487
    {
488
        $this->forward('Investform:download', array(
489
            'id' => $id,
490
            'idPage' => $this->actualPage->getId()
491
        ));
492
    }
493
494
    public function actionSendContract($id, $idPage)
0 ignored issues
show
Unused Code introduced by
The parameter $idPage is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
495
    {
496
        $this->forward('Investform:send', array(
497
            'id' => $id,
498
            'idPage' => $this->actualPage->getId()
499
        ));
500
    }
501
502
    
503
}
504