|
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
|
|
|
use WebCMS\Entity\User; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Description of |
|
18
|
|
|
* |
|
19
|
|
|
* @author Jakub Sanda <[email protected]> |
|
20
|
|
|
*/ |
|
21
|
|
|
class BusinessmanPresenter extends BasePresenter |
|
22
|
|
|
{ |
|
23
|
|
|
|
|
24
|
|
|
private $businessman; |
|
25
|
|
|
|
|
26
|
|
|
private $businessmen; |
|
27
|
|
|
|
|
28
|
|
|
private $company; |
|
29
|
|
|
|
|
30
|
|
|
private $investments; |
|
31
|
|
|
|
|
32
|
|
|
private $newInvestments; |
|
33
|
|
|
|
|
34
|
|
|
private $newInvestmentsAmount; |
|
35
|
|
|
|
|
36
|
|
|
private $openInvestments; |
|
37
|
|
|
|
|
38
|
|
|
private $openInvestmentsAmount; |
|
39
|
|
|
|
|
40
|
|
|
private $closedInvestments; |
|
41
|
|
|
|
|
42
|
|
|
private $closedInvestmentsAmount; |
|
43
|
|
|
|
|
44
|
|
|
private $paidInvestments; |
|
45
|
|
|
|
|
46
|
|
|
private $paidInvestmentsAmount; |
|
47
|
|
|
|
|
48
|
|
|
private $user; |
|
49
|
|
|
|
|
50
|
|
|
protected function startup() |
|
51
|
|
|
{ |
|
52
|
|
|
parent::startup(); |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
protected function beforeRender() |
|
56
|
|
|
{ |
|
57
|
|
|
parent::beforeRender(); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function actionDefault($idPage) |
|
61
|
|
|
{ |
|
62
|
|
|
$this->user = $this->getUser(); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
public function renderDefault($idPage) |
|
66
|
|
|
{ |
|
67
|
|
|
$this->reloadContent(); |
|
68
|
|
|
|
|
69
|
|
|
$roles = $this->user->getIdentity()->getRoles(); |
|
70
|
|
|
if (count(array_intersect(array('superadmin', 'admin'), $roles)) > 0) { |
|
71
|
|
|
$this->template->show = true; |
|
|
|
|
|
|
72
|
|
|
} else { |
|
73
|
|
|
$this->businessman = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Businessman')->findOneBy(array( |
|
74
|
|
|
'user' => $this->user->getIdentity()->getId() |
|
75
|
|
|
)); |
|
76
|
|
|
|
|
77
|
|
|
$this->investments = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Investment')->findBy(array( |
|
78
|
|
|
'businessman' => $this->businessman |
|
79
|
|
|
)); |
|
80
|
|
|
|
|
81
|
|
|
// $this->openInvestments = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Investment')->findBy(array( |
|
82
|
|
|
// 'businessman' => $this->businessman, |
|
83
|
|
|
// 'contractSend' => false |
|
84
|
|
|
// )); |
|
85
|
|
|
// $this->openInvestmentsAmount = 0; |
|
86
|
|
|
// foreach ($this->openInvestments as $investment) { |
|
87
|
|
|
// $this->openInvestmentsAmount += $investment->getInvestment(); |
|
88
|
|
|
// } |
|
89
|
|
|
|
|
90
|
|
|
// $this->closedInvestments = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Investment')->findBy(array( |
|
91
|
|
|
// 'businessman' => $this->businessman, |
|
92
|
|
|
// 'contractSend' => true |
|
93
|
|
|
// )); |
|
94
|
|
|
// $this->closedInvestmentsAmount = 0; |
|
95
|
|
|
// foreach ($this->closedInvestments as $investment) { |
|
96
|
|
|
// $this->closedInvestmentsAmount += $investment->getInvestment(); |
|
97
|
|
|
// } |
|
98
|
|
|
$this->newInvestments = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Investment')->findBy(array( |
|
99
|
|
|
'businessman' => $this->businessman, |
|
100
|
|
|
'contractSend' => false, |
|
101
|
|
|
'contractClosed' => false, |
|
102
|
|
|
'contractPaid' => false |
|
103
|
|
|
)); |
|
104
|
|
|
$this->newInvestmentsAmount = 0; |
|
105
|
|
|
foreach ($this->newInvestments as $investment) { |
|
106
|
|
|
$this->newInvestmentsAmount += $investment->getInvestment(); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
$this->openInvestments = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Investment')->findBy(array( |
|
110
|
|
|
'businessman' => $this->businessman, |
|
111
|
|
|
'contractSend' => true, |
|
112
|
|
|
'contractClosed' => false, |
|
113
|
|
|
'contractPaid' => false |
|
114
|
|
|
)); |
|
115
|
|
|
$this->openInvestmentsAmount = 0; |
|
116
|
|
|
foreach ($this->openInvestments as $investment) { |
|
117
|
|
|
$this->openInvestmentsAmount += $investment->getInvestment(); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
$this->closedInvestments = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Investment')->findBy(array( |
|
121
|
|
|
'businessman' => $this->businessman, |
|
122
|
|
|
'contractSend' => true, |
|
123
|
|
|
'contractClosed' => true, |
|
124
|
|
|
'contractPaid' => false |
|
125
|
|
|
)); |
|
126
|
|
|
$this->closedInvestmentsAmount = 0; |
|
127
|
|
|
foreach ($this->closedInvestments as $investment) { |
|
128
|
|
|
$this->closedInvestmentsAmount += $investment->getInvestment(); |
|
129
|
|
|
} |
|
130
|
|
|
|
|
131
|
|
|
$this->paidInvestments = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Investment')->findBy(array( |
|
132
|
|
|
'businessman' => $this->businessman, |
|
133
|
|
|
'contractSend' => true, |
|
134
|
|
|
'contractClosed' => true, |
|
135
|
|
|
'contractPaid' => true |
|
136
|
|
|
)); |
|
137
|
|
|
$this->paidInvestmentsAmount = 0; |
|
138
|
|
|
foreach ($this->paidInvestments as $investment) { |
|
139
|
|
|
$this->paidInvestmentsAmount += $investment->getInvestment(); |
|
140
|
|
|
} |
|
141
|
|
|
$this->template->show = false; |
|
|
|
|
|
|
142
|
|
|
$this->template->businessman = $this->businessman; |
|
|
|
|
|
|
143
|
|
|
$this->template->urlCode = $this->presenter->getHttpRequest()->url->baseUrl.$this->actualPage->getSlug().'/?bcode='; |
|
|
|
|
|
|
144
|
|
|
$this->template->investments = $this->investments; |
|
|
|
|
|
|
145
|
|
|
$this->template->newInvestments = count($this->newInvestments); |
|
|
|
|
|
|
146
|
|
|
$this->template->openInvestments = count($this->openInvestments); |
|
|
|
|
|
|
147
|
|
|
$this->template->closedInvestments = count($this->closedInvestments); |
|
|
|
|
|
|
148
|
|
|
$this->template->paidInvestments = count($this->paidInvestments); |
|
|
|
|
|
|
149
|
|
|
$this->template->newInvestmentsAmount = $this->newInvestmentsAmount; |
|
|
|
|
|
|
150
|
|
|
$this->template->openInvestmentsAmount = $this->openInvestmentsAmount; |
|
|
|
|
|
|
151
|
|
|
$this->template->closedInvestmentsAmount = $this->closedInvestmentsAmount; |
|
|
|
|
|
|
152
|
|
|
$this->template->paidInvestmentsAmount = $this->paidInvestmentsAmount; |
|
|
|
|
|
|
153
|
|
|
} |
|
154
|
|
|
|
|
155
|
|
|
$this->template->idPage = $idPage; |
|
|
|
|
|
|
156
|
|
|
} |
|
157
|
|
|
|
|
158
|
|
|
public function actionActiveBusinessmen($idPage) |
|
|
|
|
|
|
159
|
|
|
{ |
|
160
|
|
|
$this->reloadContent(); |
|
161
|
|
|
|
|
162
|
|
|
$this->businessmen = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Businessman')->findBy(array( |
|
163
|
|
|
'active' => true |
|
164
|
|
|
)); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
public function renderActiveBusinessmen($idPage) |
|
168
|
|
|
{ |
|
169
|
|
|
$this->template->idPage = $idPage; |
|
|
|
|
|
|
170
|
|
|
$this->template->numberOfBusinessmen = count($this->businessmen); |
|
|
|
|
|
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
public function actionInactiveBusinessmen($idPage) |
|
|
|
|
|
|
174
|
|
|
{ |
|
175
|
|
|
$this->reloadContent(); |
|
176
|
|
|
|
|
177
|
|
|
$this->businessmen = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Businessman')->findBy(array( |
|
178
|
|
|
'active' => false |
|
179
|
|
|
)); |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
public function renderInactiveBusinessmen($idPage) |
|
183
|
|
|
{ |
|
184
|
|
|
$this->template->idPage = $idPage; |
|
|
|
|
|
|
185
|
|
|
$this->template->numberOfBusinessmen = count($this->businessmen); |
|
|
|
|
|
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
View Code Duplication |
protected function createComponentActiveGrid($name) |
|
|
|
|
|
|
189
|
|
|
{ |
|
190
|
|
|
$grid = $this->createGrid($this, $name, "\WebCMS\InvestformModule\Entity\Businessman", null, array( |
|
191
|
|
|
'active = true', |
|
192
|
|
|
)); |
|
193
|
|
|
|
|
194
|
|
|
$grid->setFilterRenderType(\Grido\Components\Filters\Filter::RENDER_INNER); |
|
195
|
|
|
|
|
196
|
|
|
$grid->addColumnText('name', 'Firstname')->setCustomRender(function($item) { |
|
197
|
|
|
if ($item->getName()) { |
|
198
|
|
|
return $item->getName() . ' ' . $item->getLastname(); |
|
199
|
|
|
} else { |
|
200
|
|
|
return $item->getBusinessname(); |
|
201
|
|
|
} |
|
202
|
|
|
|
|
203
|
|
|
}); |
|
204
|
|
|
|
|
205
|
|
|
$grid->addColumnText('businessId', 'Business ID'); |
|
206
|
|
|
|
|
207
|
|
|
$grid->addColumnText('company', 'Company')->setCustomRender(function($item) { |
|
208
|
|
|
if ($item->getCompany()) { |
|
209
|
|
|
return $item->getCompany()->getName(); |
|
210
|
|
|
} |
|
211
|
|
|
}); |
|
212
|
|
|
|
|
213
|
|
|
$grid->addActionHref("deactivate", 'Deactivate', 'deactivate', array('idPage' => $this->actualPage->getId()))->getElementPrototype()->addAttributes(array('class' => array('btn', 'btn-primary', 'ajax', 'grey'))); |
|
214
|
|
|
$grid->addActionHref("detail", 'Businessman detail', 'detail', array('idPage' => $this->actualPage->getId()))->getElementPrototype()->addAttributes(array('class' => array('btn', 'btn-primary', 'green'))); |
|
215
|
|
|
|
|
216
|
|
|
return $grid; |
|
217
|
|
|
} |
|
218
|
|
|
|
|
219
|
|
View Code Duplication |
protected function createComponentInactiveGrid($name) |
|
|
|
|
|
|
220
|
|
|
{ |
|
221
|
|
|
$grid = $this->createGrid($this, $name, "\WebCMS\InvestformModule\Entity\Businessman", null, array( |
|
222
|
|
|
'active = false', |
|
223
|
|
|
)); |
|
224
|
|
|
|
|
225
|
|
|
$grid->setFilterRenderType(\Grido\Components\Filters\Filter::RENDER_INNER); |
|
226
|
|
|
|
|
227
|
|
|
$grid->addColumnText('name', 'Firstname')->setCustomRender(function($item) { |
|
228
|
|
|
if ($item->getName()) { |
|
229
|
|
|
return $item->getName() . ' ' . $item->getLastname(); |
|
230
|
|
|
} else { |
|
231
|
|
|
return $item->getBusinessname(); |
|
232
|
|
|
} |
|
233
|
|
|
}); |
|
234
|
|
|
|
|
235
|
|
|
$grid->addColumnText('businessId', 'Business ID'); |
|
236
|
|
|
|
|
237
|
|
|
$grid->addColumnText('company', 'Company')->setCustomRender(function($item) { |
|
238
|
|
|
if ($item->getCompany()) { |
|
239
|
|
|
return $item->getCompany()->getName(); |
|
240
|
|
|
} |
|
241
|
|
|
}); |
|
242
|
|
|
|
|
243
|
|
|
$grid->addActionHref("activate", 'Activate', 'activate', array('idPage' => $this->actualPage->getId()))->getElementPrototype()->addAttributes(array('class' => array('btn', 'btn-primary', 'ajax', 'grey'))); |
|
244
|
|
|
$grid->addActionHref("detail", 'Businessman detail', 'detail', array('idPage' => $this->actualPage->getId()))->getElementPrototype()->addAttributes(array('class' => array('btn', 'btn-primary', 'green'))); |
|
245
|
|
|
|
|
246
|
|
|
return $grid; |
|
247
|
|
|
} |
|
248
|
|
|
|
|
249
|
|
|
public function actionDeactivate($id, $idPage, $inDetail = false) |
|
|
|
|
|
|
250
|
|
|
{ |
|
251
|
|
|
|
|
252
|
|
|
$this->businessman = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Businessman')->find($id); |
|
253
|
|
|
$this->businessman->setActive(false); |
|
254
|
|
|
|
|
255
|
|
|
$this->em->flush(); |
|
256
|
|
|
|
|
257
|
|
|
$this->flashMessage('Businessman has been deactivated', 'success'); |
|
258
|
|
|
|
|
259
|
|
|
if ($inDetail) { |
|
260
|
|
|
$this->forward('detail', array( |
|
261
|
|
|
'id' => $id, |
|
262
|
|
|
'idPage' => $this->actualPage->getId() |
|
263
|
|
|
)); |
|
264
|
|
|
} else { |
|
265
|
|
|
$this->forward('activeBusinessmen', array( |
|
266
|
|
|
'idPage' => $this->actualPage->getId() |
|
267
|
|
|
)); |
|
268
|
|
|
} |
|
269
|
|
|
} |
|
270
|
|
|
|
|
271
|
|
|
public function actionActivate($id, $idPage, $inDetail = false) |
|
|
|
|
|
|
272
|
|
|
{ |
|
273
|
|
|
|
|
274
|
|
|
$this->businessman = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Businessman')->find($id); |
|
275
|
|
|
|
|
276
|
|
|
$this->company = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Company')->find($this->businessman->getCompany()->getId()); |
|
277
|
|
|
|
|
278
|
|
View Code Duplication |
if ($this->company->getActive()) { |
|
|
|
|
|
|
279
|
|
|
$this->businessman->setActive(true); |
|
280
|
|
|
|
|
281
|
|
|
$this->em->flush(); |
|
282
|
|
|
|
|
283
|
|
|
$this->flashMessage('Businessman has been activated', 'success'); |
|
284
|
|
|
|
|
285
|
|
|
} else { |
|
286
|
|
|
$this->flashMessage('Active state cannot be changed. Company is inactive.', 'error'); |
|
287
|
|
|
} |
|
288
|
|
|
|
|
289
|
|
|
if ($inDetail) { |
|
290
|
|
|
$this->forward('detail', array( |
|
291
|
|
|
'id' => $id, |
|
292
|
|
|
'idPage' => $this->actualPage->getId() |
|
293
|
|
|
)); |
|
294
|
|
|
} else { |
|
295
|
|
|
$this->forward('inactiveBusinessmen', array( |
|
296
|
|
|
'idPage' => $this->actualPage->getId() |
|
297
|
|
|
)); |
|
298
|
|
|
} |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
public function actionUpdate($id, $idPage) |
|
|
|
|
|
|
302
|
|
|
{ |
|
303
|
|
|
if ($id) { |
|
304
|
|
|
$this->businessman = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Businessman')->find($id); |
|
305
|
|
|
} |
|
306
|
|
|
} |
|
307
|
|
|
|
|
308
|
|
|
public function renderUpdate($idPage) |
|
309
|
|
|
{ |
|
310
|
|
|
$this->reloadContent(); |
|
311
|
|
|
|
|
312
|
|
|
$this->template->idPage = $idPage; |
|
|
|
|
|
|
313
|
|
|
} |
|
314
|
|
|
|
|
315
|
|
|
public function createComponentForm($name) |
|
|
|
|
|
|
316
|
|
|
{ |
|
317
|
|
|
$form = $this->createForm('form-submit', 'default', null); |
|
|
|
|
|
|
318
|
|
|
|
|
319
|
|
|
$form->addText('name', 'Firstname'); |
|
320
|
|
|
$form->addText('lastname', 'Lastname'); |
|
321
|
|
|
$form->addText('businessname', 'Business name') |
|
322
|
|
|
->addConditionOn($form['name'], ~Form::FILLED) |
|
323
|
|
|
->addRule(Form::FILLED, 'Fill in name or business name.'); |
|
324
|
|
|
|
|
325
|
|
|
$users = $this->em->getRepository('\WebCMS\Entity\User')->findAll(); |
|
326
|
|
|
$usersForSelect = array(); |
|
327
|
|
|
if ($users) { |
|
328
|
|
|
$usersForSelect[] = ""; |
|
329
|
|
|
foreach ($users as $user) { |
|
330
|
|
|
$usersForSelect[$user->getId()] = $user->getUsername(); |
|
331
|
|
|
} |
|
332
|
|
|
} |
|
333
|
|
|
|
|
334
|
|
|
$form->addSelect('user', 'User')->setItems($usersForSelect); |
|
335
|
|
|
|
|
336
|
|
|
$form->addText('street', 'Street and number')->setRequired('Street and number is mandatory.'); |
|
337
|
|
|
$form->addText('zipCity', 'Zip and city')->setRequired('Zip and city is mandatory.'); |
|
338
|
|
|
$form->addText('email', 'Email') |
|
339
|
|
|
->addRule(Form::EMAIL, 'This email is not valid.') |
|
340
|
|
|
->setRequired('Email is mandatory.'); |
|
341
|
|
|
$form->addText('phone', 'Phone')->setRequired('Phone is mandatory.'); |
|
342
|
|
|
|
|
343
|
|
|
$companies = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Company')->findAll(); |
|
344
|
|
|
$companiesForSelect = array(); |
|
345
|
|
|
if ($companies) { |
|
346
|
|
|
$companiesForSelect[] = ""; |
|
347
|
|
|
foreach ($companies as $company) { |
|
348
|
|
|
$companiesForSelect[$company->getId()] = $company->getName(); |
|
349
|
|
|
} |
|
350
|
|
|
} |
|
351
|
|
|
|
|
352
|
|
|
$form->addSelect('company', 'Company')->setItems($companiesForSelect); |
|
353
|
|
|
|
|
354
|
|
|
if ($this->businessman) { |
|
355
|
|
|
$form->setDefaults($this->businessman->toArray()); |
|
356
|
|
|
|
|
357
|
|
|
$form->addText('businessIdDisabled', 'Generated businessman ID') |
|
358
|
|
|
->setValue($this->businessman->getBusinessId()) |
|
359
|
|
|
->setDisabled(); |
|
360
|
|
|
|
|
361
|
|
|
$form->addText('businessUrlDisabled', 'Generated businessman URL') |
|
362
|
|
|
->setValue($this->presenter->getHttpRequest()->url->baseUrl.$this->actualPage->getSlug().'/?bcode='.$this->businessman->getBusinessUrl()) |
|
363
|
|
|
->setDisabled(); |
|
364
|
|
|
|
|
365
|
|
|
$form->addHidden('businessId', $this->businessman->getBusinessId()); |
|
366
|
|
|
$form->addHidden('businessUrl', $this->businessman->getBusinessUrl()); |
|
367
|
|
|
} else { |
|
368
|
|
|
//generated values |
|
369
|
|
|
$exists = true; |
|
370
|
|
|
while($exists){ |
|
371
|
|
|
$businessId = mt_rand(10000,99999); |
|
372
|
|
|
|
|
373
|
|
|
$businessman = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Businessman')->findBy(array( |
|
374
|
|
|
'businessId' => $businessId |
|
375
|
|
|
)); |
|
376
|
|
|
|
|
377
|
|
|
if (!$businessman) $exists = false; |
|
378
|
|
|
} |
|
379
|
|
|
|
|
380
|
|
|
$form->addText('businessIdDisabled', 'Generated businessman ID') |
|
381
|
|
|
->setValue($businessId); |
|
|
|
|
|
|
382
|
|
|
|
|
383
|
|
|
$businessUrl = bin2hex(mcrypt_create_iv(10, MCRYPT_DEV_URANDOM)); |
|
384
|
|
|
$form->addText('businessUrlDisabled', 'Generated businessman URL') |
|
385
|
|
|
->setValue($this->presenter->getHttpRequest()->url->baseUrl.$this->actualPage->getSlug().'/?bcode='.$businessUrl) |
|
386
|
|
|
->setDisabled(); |
|
387
|
|
|
$form->addHidden('businessUrl', $businessUrl); |
|
388
|
|
|
|
|
389
|
|
|
} |
|
390
|
|
|
|
|
391
|
|
|
$form->addSubmit('save', 'Save new businessman'); |
|
392
|
|
|
|
|
393
|
|
|
$form->onSuccess[] = callback($this, 'formSubmitted'); |
|
394
|
|
|
|
|
395
|
|
|
return $form; |
|
396
|
|
|
} |
|
397
|
|
|
|
|
398
|
|
|
public function formSubmitted($form) |
|
399
|
|
|
{ |
|
400
|
|
|
$values = $form->getValues(); |
|
401
|
|
|
$sendEmail = false; |
|
402
|
|
|
|
|
403
|
|
|
if(!$this->businessman){ |
|
404
|
|
|
$this->businessman = new Businessman; |
|
405
|
|
|
$this->businessman->setActive(true); |
|
406
|
|
|
$this->em->persist($this->businessman); |
|
407
|
|
|
$sendEmail = true; |
|
408
|
|
|
} |
|
409
|
|
|
|
|
410
|
|
|
$this->businessman->setName($values->name); |
|
411
|
|
|
$this->businessman->setLastname($values->lastname); |
|
412
|
|
|
$this->businessman->setBusinessname($values->businessname); |
|
413
|
|
|
$this->businessman->setStreet($values->street); |
|
414
|
|
|
$this->businessman->setZipCity($values->zipCity); |
|
415
|
|
|
$this->businessman->setEmail($values->email); |
|
416
|
|
|
$this->businessman->setPhone($values->phone); |
|
417
|
|
|
|
|
418
|
|
|
if ($values->user) { |
|
419
|
|
|
$user = $this->em->getRepository('\WebCMS\Entity\User')->find($values->user); |
|
420
|
|
|
$this->businessman->setUser($user); |
|
421
|
|
|
} |
|
422
|
|
|
|
|
423
|
|
|
|
|
424
|
|
|
$company = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Company')->find($values->company); |
|
425
|
|
|
$this->businessman->setCompany($company); |
|
426
|
|
|
|
|
427
|
|
|
if (isset($values->businessId)) { |
|
428
|
|
|
$this->businessman->setBusinessId($values->businessId); |
|
429
|
|
|
} else { |
|
430
|
|
|
$this->businessman->setBusinessId($values->businessIdDisabled); |
|
431
|
|
|
} |
|
432
|
|
|
|
|
433
|
|
|
$this->businessman->setBusinessUrl($values->businessUrl); |
|
434
|
|
|
|
|
435
|
|
|
//send email |
|
436
|
|
|
if($sendEmail){ |
|
437
|
|
|
$mail = new \Nette\Mail\Message; |
|
438
|
|
|
$mail->addTo($values->email); |
|
439
|
|
|
|
|
440
|
|
|
$domain = str_replace('www.', '', $this->getHttpRequest()->url->host); |
|
441
|
|
|
|
|
442
|
|
|
if($domain !== 'localhost') $mail->setFrom('no-reply@' . $domain); |
|
443
|
|
|
else $mail->setFrom('[email protected]'); // TODO move to settings |
|
444
|
|
|
|
|
445
|
|
|
$mailBody = '<h2><u>Vaše obchodní údaje</u></h2>'; |
|
446
|
|
|
$mailBody .= '<table><tbody>'; |
|
447
|
|
|
$mailBody .= '<tr><td><strong>Jméno: </strong></td><td>'.$values->name.' '.$values->lastname.'</td></tr>'; |
|
448
|
|
|
$mailBody .= '<tr><td><strong>Email: </strong></td><td><a href="mailto:'.$values->email.'">'.$values->email.'</a></td></tr>'; |
|
449
|
|
|
$mailBody .= '<tr><td><strong>Tel. číslo: </strong></td><td>'.$values->phone.'</td></tr>'; |
|
450
|
|
|
$mailBody .= '<tr><td><strong>Obchodní URL: </strong></td><td><a href="https://www.zajistenainvestice.cz/obchodnici?bcode='.$values->businessUrl.'">www.zajistenainvestice.cz</td></tr>'; |
|
451
|
|
|
$mailBody .= '</tbody></table>'; |
|
452
|
|
|
|
|
453
|
|
|
if (isset($user)) { |
|
454
|
|
|
|
|
455
|
|
|
$mailBody .= '<h3><u>Vaše přístupové údaje</u></h3>'; |
|
456
|
|
|
$mailBody .= '<table><tbody>'; |
|
457
|
|
|
$mailBody .= '<tr><td><strong>Přístup: </strong></td><td><a href="https://www.zajistenainvestice.cz/admin">www.zajistenainvestice.cz/admin</a></td></tr>'; |
|
458
|
|
|
$mailBody .= '<tr><td><strong>Login: </strong></td><td>'.$user->getUsername().'</td></tr>'; |
|
459
|
|
|
$mailBody .= '<tr><td><strong>Heslo: </strong></td><td>'.$this->settings->get('Businessman password', 'InvestformModule', 'text')->getValue().'</td></tr>'; |
|
|
|
|
|
|
460
|
|
|
$mailBody .= '</tbody></table>'; |
|
461
|
|
|
|
|
462
|
|
|
} |
|
463
|
|
|
|
|
464
|
|
|
$mail->setSubject('Byl Vám založen účet na www.zajistenainvestice.cz'); |
|
465
|
|
|
$mail->setHtmlBody($mailBody); |
|
466
|
|
|
|
|
467
|
|
|
try { |
|
468
|
|
|
$mail->send(); |
|
469
|
|
|
$this->flashMessage('Email has been sent', 'success'); |
|
470
|
|
|
} catch (\Exception $e) { |
|
471
|
|
|
$this->flashMessage('Cannot send email.', 'danger'); |
|
472
|
|
|
} |
|
473
|
|
|
} |
|
474
|
|
|
|
|
475
|
|
|
$this->em->flush(); |
|
476
|
|
|
|
|
477
|
|
|
$this->flashMessage('Businessman has been updated.', 'success'); |
|
478
|
|
|
|
|
479
|
|
|
$this->forward('detail', array( |
|
480
|
|
|
'id' => $this->businessman->getId(), |
|
481
|
|
|
'idPage' => $this->actualPage->getId() |
|
482
|
|
|
)); |
|
483
|
|
|
} |
|
484
|
|
|
|
|
485
|
|
|
public function actionDetail($id, $idPage) |
|
|
|
|
|
|
486
|
|
|
{ |
|
487
|
|
|
$this->businessman = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Businessman')->find($id); |
|
488
|
|
|
$this->investments = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Investment')->findBy(array( |
|
489
|
|
|
'businessman' => $this->businessman |
|
490
|
|
|
)); |
|
491
|
|
|
|
|
492
|
|
|
$this->newInvestments = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Investment')->findBy(array( |
|
493
|
|
|
'businessman' => $this->businessman, |
|
494
|
|
|
'contractSend' => false, |
|
495
|
|
|
'contractClosed' => false, |
|
496
|
|
|
'contractPaid' => false |
|
497
|
|
|
)); |
|
498
|
|
|
$this->newInvestmentsAmount = 0; |
|
499
|
|
|
foreach ($this->newInvestments as $investment) { |
|
500
|
|
|
$this->newInvestmentsAmount += $investment->getInvestment(); |
|
501
|
|
|
} |
|
502
|
|
|
|
|
503
|
|
|
$this->openInvestments = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Investment')->findBy(array( |
|
504
|
|
|
'businessman' => $this->businessman, |
|
505
|
|
|
'contractSend' => true, |
|
506
|
|
|
'contractClosed' => false, |
|
507
|
|
|
'contractPaid' => false |
|
508
|
|
|
)); |
|
509
|
|
|
$this->openInvestmentsAmount = 0; |
|
510
|
|
|
foreach ($this->openInvestments as $investment) { |
|
511
|
|
|
$this->openInvestmentsAmount += $investment->getInvestment(); |
|
512
|
|
|
} |
|
513
|
|
|
|
|
514
|
|
|
$this->closedInvestments = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Investment')->findBy(array( |
|
515
|
|
|
'businessman' => $this->businessman, |
|
516
|
|
|
'contractSend' => true, |
|
517
|
|
|
'contractClosed' => true, |
|
518
|
|
|
'contractPaid' => false |
|
519
|
|
|
)); |
|
520
|
|
|
$this->closedInvestmentsAmount = 0; |
|
521
|
|
|
foreach ($this->closedInvestments as $investment) { |
|
522
|
|
|
$this->closedInvestmentsAmount += $investment->getInvestment(); |
|
523
|
|
|
} |
|
524
|
|
|
|
|
525
|
|
|
$this->paidInvestments = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Investment')->findBy(array( |
|
526
|
|
|
'businessman' => $this->businessman, |
|
527
|
|
|
'contractSend' => true, |
|
528
|
|
|
'contractClosed' => true, |
|
529
|
|
|
'contractPaid' => true |
|
530
|
|
|
)); |
|
531
|
|
|
$this->paidInvestmentsAmount = 0; |
|
532
|
|
|
foreach ($this->paidInvestments as $investment) { |
|
533
|
|
|
$this->paidInvestmentsAmount += $investment->getInvestment(); |
|
534
|
|
|
} |
|
535
|
|
|
} |
|
536
|
|
|
|
|
537
|
|
|
public function renderDetail($idPage) |
|
538
|
|
|
{ |
|
539
|
|
|
$this->reloadContent(); |
|
540
|
|
|
$this->template->idPage = $idPage; |
|
|
|
|
|
|
541
|
|
|
$this->template->urlCode = $this->presenter->getHttpRequest()->url->baseUrl.$this->actualPage->getSlug().'/?bcode='; |
|
|
|
|
|
|
542
|
|
|
$this->template->businessman = $this->businessman; |
|
|
|
|
|
|
543
|
|
|
$this->template->investments = $this->investments; |
|
|
|
|
|
|
544
|
|
|
$this->template->newInvestments = count($this->newInvestments); |
|
|
|
|
|
|
545
|
|
|
$this->template->openInvestments = count($this->openInvestments); |
|
|
|
|
|
|
546
|
|
|
$this->template->closedInvestments = count($this->closedInvestments); |
|
|
|
|
|
|
547
|
|
|
$this->template->paidInvestments = count($this->paidInvestments); |
|
|
|
|
|
|
548
|
|
|
$this->template->newInvestmentsAmount = $this->newInvestmentsAmount; |
|
|
|
|
|
|
549
|
|
|
$this->template->openInvestmentsAmount = $this->openInvestmentsAmount; |
|
|
|
|
|
|
550
|
|
|
$this->template->closedInvestmentsAmount = $this->closedInvestmentsAmount; |
|
|
|
|
|
|
551
|
|
|
$this->template->paidInvestmentsAmount = $this->paidInvestmentsAmount; |
|
|
|
|
|
|
552
|
|
|
} |
|
553
|
|
|
|
|
554
|
|
|
protected function createComponentInvestmentsGrid($name) |
|
555
|
|
|
{ |
|
556
|
|
|
|
|
557
|
|
|
if (!$this->businessman) { |
|
558
|
|
|
$this->businessman = $this->em->getRepository('\WebCMS\InvestformModule\Entity\Businessman')->findOneBy(array( |
|
559
|
|
|
'user' => $this->user->getIdentity()->getId() |
|
560
|
|
|
)); |
|
561
|
|
|
} |
|
562
|
|
|
|
|
563
|
|
|
$grid = $this->createGrid($this, $name, "\WebCMS\InvestformModule\Entity\Investment", null, array( |
|
564
|
|
|
'businessman = '.$this->businessman->getId() |
|
565
|
|
|
)); |
|
566
|
|
|
|
|
567
|
|
|
$grid->setFilterRenderType(\Grido\Components\Filters\Filter::RENDER_INNER); |
|
568
|
|
|
|
|
569
|
|
|
$grid->addFilterDateRange('created', 'Created'); |
|
570
|
|
|
|
|
571
|
|
|
$grid->addColumnDate('created', 'Created')->setDateFormat(\Grido\Components\Columns\Date::FORMAT_DATETIME); |
|
572
|
|
|
|
|
573
|
|
|
$grid->addColumnText('client_name', 'Client name')->setCustomRender(function($item) { |
|
574
|
|
|
return $item->getAddress()->getName().' '.$item->getAddress()->getLastname(); |
|
575
|
|
|
}); |
|
576
|
|
|
|
|
577
|
|
|
$grid->addColumnText('investment', 'Investment'); |
|
578
|
|
|
$grid->addColumnText('contractSend', 'Contract send')->setCustomRender(function($item) { |
|
579
|
|
|
if ($item->getContractSend()) { |
|
580
|
|
|
return 'Yes'; |
|
581
|
|
|
} else { |
|
582
|
|
|
return 'No'; |
|
583
|
|
|
} |
|
584
|
|
|
}); |
|
585
|
|
|
$grid->addColumnText('contractClosed', 'Contract closed')->setCustomRender(function($item) { |
|
586
|
|
|
return $item->getContractClosed() ? 'Yes' : 'No'; |
|
587
|
|
|
}); |
|
588
|
|
|
$grid->addColumnText('contractPaid', 'Contract paid')->setCustomRender(function($item) { |
|
589
|
|
|
if ($item->getContractPaid()) { |
|
590
|
|
|
return 'Yes'; |
|
591
|
|
|
} else { |
|
592
|
|
|
return 'No'; |
|
593
|
|
|
} |
|
594
|
|
|
}); |
|
595
|
|
|
|
|
596
|
|
|
|
|
597
|
|
|
$grid->addActionHref("sendContract", 'Send', 'sendContract', array('idPage' => $this->actualPage->getId()))->getElementPrototype()->addAttributes(array('class' => array('btn', 'btn-primary', 'ajax', 'purple'))); |
|
598
|
|
|
$grid->addActionHref("downloadContract", 'Download', 'downloadContract', array('idPage' => $this->actualPage->getId()))->getElementPrototype()->addAttributes(array('class' => array('btn', 'btn-primary', 'purple'))); |
|
599
|
|
|
$grid->addActionHref("updateContract", 'Edit', 'updateContract', array('idPage' => $this->actualPage->getId()))->getElementPrototype()->addAttributes(array('class' => array('btn', 'btn-primary', 'ajax', 'green'))); |
|
600
|
|
|
|
|
601
|
|
|
return $grid; |
|
602
|
|
|
} |
|
603
|
|
|
|
|
604
|
|
|
public function actionUpdateContract($id, $idPage) |
|
|
|
|
|
|
605
|
|
|
{ |
|
606
|
|
|
$this->forward('Investform:update', array( |
|
607
|
|
|
'id' => $id, |
|
608
|
|
|
'idPage' => $this->actualPage->getId() |
|
609
|
|
|
)); |
|
610
|
|
|
} |
|
611
|
|
|
|
|
612
|
|
|
public function actionDownloadContract($id, $idPage) |
|
|
|
|
|
|
613
|
|
|
{ |
|
614
|
|
|
$this->forward('Investform:download', array( |
|
615
|
|
|
'id' => $id, |
|
616
|
|
|
'idPage' => $this->actualPage->getId() |
|
617
|
|
|
)); |
|
618
|
|
|
} |
|
619
|
|
|
|
|
620
|
|
|
public function actionSendContract($id, $idPage) |
|
|
|
|
|
|
621
|
|
|
{ |
|
622
|
|
|
$this->forward('Investform:send', array( |
|
623
|
|
|
'id' => $id, |
|
624
|
|
|
'idPage' => $this->actualPage->getId(), |
|
625
|
|
|
'from' => 'businessman' |
|
626
|
|
|
)); |
|
627
|
|
|
} |
|
628
|
|
|
|
|
629
|
|
|
|
|
630
|
|
|
} |
|
631
|
|
|
|
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@propertyannotation to your class or interface to document the existence of this variable.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.