1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the vseth-musikzimmer-pay project. |
5
|
|
|
* |
6
|
|
|
* (c) Florian Moser <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace App\Controller\Administration; |
13
|
|
|
|
14
|
|
|
use App\Controller\Administration\Base\BaseController; |
15
|
|
|
use App\Entity\User; |
16
|
|
|
use App\Enum\PaymentRemainderStatusType; |
17
|
|
|
use App\Form\User\EditDiscountType; |
18
|
|
|
use App\Model\Breadcrumb; |
19
|
|
|
use App\Service\Interfaces\PaymentServiceInterface; |
20
|
|
|
use Symfony\Component\Form\Extension\Core\Type\SubmitType; |
21
|
|
|
use Symfony\Component\Form\FormInterface; |
22
|
|
|
use Symfony\Component\HttpFoundation\Request; |
23
|
|
|
use Symfony\Component\HttpFoundation\Response; |
24
|
|
|
use Symfony\Component\Routing\Annotation\Route; |
25
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @Route("/user") |
29
|
|
|
*/ |
30
|
|
|
class UserController extends BaseController |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @Route("/{user}/edit_discount", name="administration_user_edit_discount") |
34
|
|
|
* |
35
|
|
|
* @return Response |
36
|
|
|
*/ |
37
|
|
|
public function editDiscountAction(Request $request, User $user, TranslatorInterface $translator, PaymentServiceInterface $userPaymentService) |
38
|
|
|
{ |
39
|
|
|
$discountBefore = $user->getDiscount(); |
40
|
|
|
|
41
|
|
|
//create persist callable |
42
|
|
|
$myOnSuccessCallable = function (FormInterface $form) use ($user, $translator, $discountBefore, $userPaymentService) { |
43
|
|
|
if (($user->getDiscount() !== 0 || $user->getMarkedAsPayed()) && $user->getDiscountDescription() === null) { |
44
|
|
|
$errorText = $translator->trans('edit_discount.error.no_discount_description', [], 'administration_user'); |
45
|
|
|
$this->displayError($errorText); |
46
|
|
|
} else { |
47
|
|
|
$this->fastSave($user); |
48
|
|
|
|
49
|
|
|
// close invoice if discount has changed |
50
|
|
|
if ($user->getDiscount() !== $discountBefore || $user->getMarkedAsPayed()) { |
51
|
|
|
$userPaymentService->refreshPaymentStatus($user); |
52
|
|
|
if ($user->getPaymentRemainderStatus() === PaymentRemainderStatusType::PAYMENT_STARTED) { |
53
|
|
|
$userPaymentService->closeInvoice($user); |
54
|
|
|
} |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
$successfulText = $translator->trans('form.successful.updated', [], 'framework'); |
58
|
|
|
$this->displaySuccess($successfulText); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
return $form; |
62
|
|
|
}; |
63
|
|
|
|
64
|
|
|
//handle the form |
65
|
|
|
$buttonLabel = $translator->trans('form.submit_buttons.update', [], 'framework'); |
66
|
|
|
$myForm = $this->handleForm( |
67
|
|
|
$this->createForm(EditDiscountType::class, $user) |
68
|
|
|
->add('submit', SubmitType::class, ['label' => $buttonLabel, 'translation_domain' => false]), |
69
|
|
|
$request, |
70
|
|
|
$myOnSuccessCallable |
71
|
|
|
); |
72
|
|
|
|
73
|
|
|
if ($myForm instanceof Response) { |
74
|
|
|
return $myForm; |
75
|
|
|
} |
76
|
|
|
|
77
|
|
|
return $this->render('administration/user/edit.html.twig', ['form' => $myForm->createView(), 'user' => $user]); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* @Route("/{user}/close_invoice", name="administration_user_close_invoice") |
82
|
|
|
* |
83
|
|
|
* @return Response |
84
|
|
|
*/ |
85
|
|
|
public function closeInvoiceAction(User $user, TranslatorInterface $translator, PaymentServiceInterface $userPaymentService) |
86
|
|
|
{ |
87
|
|
|
$userPaymentService->closeInvoice($user); |
88
|
|
|
|
89
|
|
|
$invoiceClosed = $translator->trans('close_invoice.successful', ['email' => $user->getEmail()], 'administration_user'); |
90
|
|
|
$this->displaySuccess($invoiceClosed); |
91
|
|
|
|
92
|
|
|
return $this->redirectToRoute('administration'); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* @Route("/{user}/send_payment_remainder", name="administration_user_send_payment_remainder") |
97
|
|
|
* |
98
|
|
|
* @return Response |
99
|
|
|
*/ |
100
|
|
|
public function sendPaymentRemainderAction(User $user, TranslatorInterface $translator, PaymentServiceInterface $userPaymentService) |
101
|
|
|
{ |
102
|
|
|
$userPaymentService->sendPaymentRemainder($user); |
103
|
|
|
|
104
|
|
|
$invoiceClosed = $translator->trans('send_payment_remainder.successful', ['email' => $user->getEmail()], 'administration_user'); |
105
|
|
|
$this->displaySuccess($invoiceClosed); |
106
|
|
|
|
107
|
|
|
return $this->redirectToRoute('administration'); |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
/** |
111
|
|
|
* get the breadcrumbs leading to this controller. |
112
|
|
|
* |
113
|
|
|
* @return Breadcrumb[] |
114
|
|
|
*/ |
115
|
|
|
protected function getIndexBreadcrumbs() |
116
|
|
|
{ |
117
|
|
|
return array_merge(parent::getIndexBreadcrumbs(), [ |
118
|
|
|
new Breadcrumb( |
119
|
|
|
$this->generateUrl('administration'), |
120
|
|
|
$this->getTranslator()->trans('index.title', [], 'administration') |
121
|
|
|
), |
122
|
|
|
]); |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
|