2
2
3
3
namespace App \Http \Controllers \StudentsCouncil ;
4
4
5
+ use App \Events \KKTNetregPeriodStart ;
5
6
use App \Http \Controllers \Controller ;
6
7
use App \Http \Controllers \Network \InternetController ;
7
8
use App \Models \Checkout ;
9
+ use App \Models \Internet \InternetAccess ;
8
10
use App \Models \PaymentType ;
11
+ use App \Models \PeriodicEvent ;
9
12
use App \Models \Role ;
10
13
use App \Models \RoleObject ;
11
14
use App \Models \Semester ;
12
15
use App \Models \Transaction ;
13
16
use App \Models \User ;
14
17
use App \Models \WorkshopBalance ;
15
18
use App \Utils \CheckoutHandler ;
19
+ use App \Utils \PeriodicEventController ;
16
20
use Carbon \Carbon ;
21
+ use Illuminate \Auth \Access \AuthorizationException ;
22
+ use Illuminate \Http \RedirectResponse ;
17
23
use Illuminate \Http \Request ;
18
24
use Illuminate \Support \Collection ;
19
25
use Illuminate \Support \Facades \Auth ;
20
26
use Illuminate \Support \Facades \Mail ;
21
27
use Illuminate \Support \Facades \Validator ;
22
28
23
- class EconomicController extends Controller
29
+ class EconomicController extends PeriodicEventController
24
30
{
25
31
use CheckoutHandler;
26
32
33
+ public function __construct ()
34
+ {
35
+ parent ::__construct (PeriodicEvent::KKT_NETREG_PAYMENT_PERIOD );
36
+ }
37
+
27
38
/**
28
39
* Return the route base for the checkout of the students council.
29
40
*/
@@ -32,6 +43,35 @@ public static function routeBase(): string
32
43
return 'economic_committee ' ;
33
44
}
34
45
46
+ /**
47
+ * Update the PeriodicEvent for the payments.
48
+ *
49
+ * @param Request $request
50
+ * @return RedirectResponse
51
+ * @throws AuthorizationException
52
+ */
53
+ public function updatePaymentPeriod (Request $ request ): RedirectResponse
54
+ {
55
+ $ this ->authorize ('administrate ' , Checkout::studentsCouncil ());
56
+ if ($ this ->periodicEvent ()) {
57
+ throw new \Exception ('Már meglévő periódus módosítása nem lehetséges. ' );
58
+ }
59
+
60
+ $ request ->validate ([
61
+ 'semester_id ' => 'required|exists:semesters,id ' ,
62
+ 'end_date ' => 'required|date|after:now '
63
+ ]);
64
+
65
+ $ semester = Semester::find ($ request ->semester_id );
66
+ $ startDate = Carbon::parse (now ());
67
+ $ endDate = Carbon::parse ($ request ->end_date );
68
+
69
+ $ this ->updatePeriodicEvent ($ semester , $ startDate , $ endDate );
70
+ InternetAccess::resetInternetAccessPeriod ($ endDate );
71
+
72
+ return back ()->with ('message ' , __ ('general.successful_modification ' ));
73
+ }
74
+
35
75
/**
36
76
* Return the checkout of the students council.
37
77
*/
@@ -51,7 +91,9 @@ public function index()
51
91
return view (
52
92
'student-council.economic-committee.app ' ,
53
93
array_merge ($ this ->getData ($ this ->checkout ()), [
54
- 'users_not_paid ' => User::hasToPayKKTNetreg ()->get ()
94
+ 'users_not_paid ' => User::hasToPayKKTNetreg ()->get (),
95
+ 'periodicEvent ' => $ this ->periodicEvent (),
96
+ 'isPaymentPeriod ' => $ this ->isActive ()
55
97
])
56
98
);
57
99
}
@@ -107,9 +149,9 @@ public static function payKKTNetregLogic(User $payer, User $receiver, int $kkt_a
107
149
108
150
WorkshopBalance::generateBalances (Semester::current ());
109
151
110
- $ new_expiry_date = $ payer ->internetAccess ->extendInternetAccess ( );
152
+ $ payer ->internetAccess ->update ([ ' netreg_paid ' => true , ' has_internet_until ' => null ] );
111
153
112
- return [$ kkt , $ netreg, $ new_expiry_date ];
154
+ return [$ kkt , $ netreg ];
113
155
}
114
156
115
157
/**
@@ -128,21 +170,13 @@ public function payKKTNetreg(Request $request)
128
170
129
171
$ payer = User::findOrFail ($ request ->user_id );
130
172
// the current user will be the receiver
131
- [$ kkt , $ netreg , $ new_internet_expire_date ]
132
- = self ::payKKTNetregLogic ($ payer , Auth::user (), $ request ->kkt , $ request ->netreg );
133
-
134
- $ internet_expiration_message = null ;
135
- if ($ new_internet_expire_date !== null ) {
136
- $ internet_expiration_message = __ ('internet.expiration_extended ' , [
137
- 'new_date ' => Carbon::parse ($ new_internet_expire_date )->format ('Y-m-d ' ),
138
- ]);
139
- }
173
+ [$ kkt , $ netreg ] = self ::payKKTNetregLogic ($ payer , Auth::user (), $ request ->kkt , $ request ->netreg );
140
174
141
175
Mail::to ($ payer )->queue (new \App \Mail \Transactions (
142
176
$ payer ->name ,
143
177
[$ kkt , $ netreg ],
144
178
"Tranzakció létrehozva " ,
145
- $ internet_expiration_message
179
+ " Az internet hozzáférésed meg lett hosszabbítva. "
146
180
));
147
181
148
182
return redirect ()->back ()->with ('message ' , __ ('general.successfully_added ' ));
0 commit comments