Skip to content

Commit 74d171f

Browse files
committed
use periodic event for Netreg
1 parent 8f66c0c commit 74d171f

File tree

8 files changed

+137
-53
lines changed

8 files changed

+137
-53
lines changed

app/Http/Controllers/Network/AdminInternetController.php

+4-6
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ public function index(): View
2525
{
2626
$this->authorize('handleAny', InternetAccess::class);
2727

28-
return view('network.admin.app', [
29-
'activation_date' => InternetAccess::getInternetDeadline()->format('Y-m-d H:i'),
30-
]);
28+
return view('network.admin.app');
3129
}
3230

3331
/**
@@ -46,7 +44,7 @@ public function indexInternetAccesses(): LengthAwarePaginator
4644
->select('internet_accesses.*')
4745
->with('user')
4846
)
49-
->sortable(['auto_approved_mac_slots', 'has_internet_until', 'user.name'])
47+
->sortable(['auto_approved_mac_slots', 'has_internet_until', 'user.name', 'netreg_paid'])
5048
->filterable(['auto_approved_mac_slots', 'has_internet_until', 'user.name'])
5149
->paginate();
5250

@@ -84,10 +82,10 @@ public function extend(Request $request, InternetAccess $internetAccess): Carbon
8482
$this->authorize('extend', $internetAccess);
8583

8684
$request->validate([
87-
'has_internet_until' => 'nullable|date',
85+
'has_internet_until' => 'date',
8886
]);
8987

90-
return $internetAccess->extendInternetAccess($request->get('has_internet_until'));
88+
return $internetAccess->extendInternetAccess(Carbon::parse($request->get('has_internet_until')));
9189
}
9290

9391
/**

app/Http/Controllers/StudentsCouncil/EconomicController.php

+48-14
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,39 @@
22

33
namespace App\Http\Controllers\StudentsCouncil;
44

5+
use App\Events\KKTNetregPeriodStart;
56
use App\Http\Controllers\Controller;
67
use App\Http\Controllers\Network\InternetController;
78
use App\Models\Checkout;
9+
use App\Models\Internet\InternetAccess;
810
use App\Models\PaymentType;
11+
use App\Models\PeriodicEvent;
912
use App\Models\Role;
1013
use App\Models\RoleObject;
1114
use App\Models\Semester;
1215
use App\Models\Transaction;
1316
use App\Models\User;
1417
use App\Models\WorkshopBalance;
1518
use App\Utils\CheckoutHandler;
19+
use App\Utils\PeriodicEventController;
1620
use Carbon\Carbon;
21+
use Illuminate\Auth\Access\AuthorizationException;
22+
use Illuminate\Http\RedirectResponse;
1723
use Illuminate\Http\Request;
1824
use Illuminate\Support\Collection;
1925
use Illuminate\Support\Facades\Auth;
2026
use Illuminate\Support\Facades\Mail;
2127
use Illuminate\Support\Facades\Validator;
2228

23-
class EconomicController extends Controller
29+
class EconomicController extends PeriodicEventController
2430
{
2531
use CheckoutHandler;
2632

33+
public function __construct()
34+
{
35+
parent::__construct(PeriodicEvent::KKT_NETREG_PAYMENT_PERIOD);
36+
}
37+
2738
/**
2839
* Return the route base for the checkout of the students council.
2940
*/
@@ -32,6 +43,35 @@ public static function routeBase(): string
3243
return 'economic_committee';
3344
}
3445

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+
3575
/**
3676
* Return the checkout of the students council.
3777
*/
@@ -51,7 +91,9 @@ public function index()
5191
return view(
5292
'student-council.economic-committee.app',
5393
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()
5597
])
5698
);
5799
}
@@ -107,9 +149,9 @@ public static function payKKTNetregLogic(User $payer, User $receiver, int $kkt_a
107149

108150
WorkshopBalance::generateBalances(Semester::current());
109151

110-
$new_expiry_date = $payer->internetAccess->extendInternetAccess();
152+
$payer->internetAccess->update(['netreg_paid' => true, 'has_internet_until' => null]);
111153

112-
return [$kkt, $netreg, $new_expiry_date];
154+
return [$kkt, $netreg];
113155
}
114156

115157
/**
@@ -128,21 +170,13 @@ public function payKKTNetreg(Request $request)
128170

129171
$payer = User::findOrFail($request->user_id);
130172
// 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);
140174

141175
Mail::to($payer)->queue(new \App\Mail\Transactions(
142176
$payer->name,
143177
[$kkt, $netreg],
144178
"Tranzakció létrehozva",
145-
$internet_expiration_message
179+
"Az internet hozzáférésed meg lett hosszabbítva."
146180
));
147181

148182
return redirect()->back()->with('message', __('general.successfully_added'));

app/Models/Internet/InternetAccess.php

+21-12
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
* @property mixed $user_id
2323
* @property string $wifi_username
2424
* @property Carbon $has_internet_until
25+
* @property boolean $netreg_paid
2526
* @property string $wifi_password
2627
* @property User $user
2728
* @property WifiConnection[]|Collection $wifiConnections
@@ -46,10 +47,17 @@ class InternetAccess extends Model
4647
{
4748
protected $primaryKey = 'user_id';
4849

49-
protected $fillable = ['user_id', 'wifi_username', 'has_internet_until', 'wifi_password'];
50+
protected $fillable = [
51+
'user_id',
52+
'wifi_username',
53+
'has_internet_until', // custom value, usually for guests
54+
'netreg_paid', // whether the collegist paid for current period
55+
'wifi_password',
56+
];
5057

5158
protected $casts = [
5259
'has_internet_until' => 'datetime',
60+
'netreg_paid' => 'boolean'
5361
];
5462

5563
protected const PASSWORD_LENGTH = 8;
@@ -92,7 +100,7 @@ public function macAddresses(): HasMany
92100
*/
93101
public function isActive(): bool
94102
{
95-
return $this->has_internet_until != null && $this->has_internet_until > date('Y-m-d');
103+
return $this->has_internet_until != null ? $this->has_internet_until > date('Y-m-d') : $this->netreg_paid;
96104
}
97105

98106
/**
@@ -123,25 +131,26 @@ public function resetPassword(): void
123131
* @param string|Carbon|null $newDate
124132
* @return Carbon
125133
*/
126-
public function extendInternetAccess(Carbon|string $newDate = null): Carbon
134+
public function extendInternetAccess(Carbon $newDate): Carbon
127135
{
128-
if ($newDate != null) {
129-
$newDate = Carbon::parse($newDate);
130-
} else {
131-
$newDate = InternetAccess::getInternetDeadline();
132-
}
133136
$this->update(['has_internet_until' => $newDate]);
134137

135138
return $newDate;
136139
}
137140

138141
/**
139-
* Get the current date until the internet accesses should be set.
140-
* @return \Carbon\Carbon
142+
* Reset's all collegists 'netreg_paid' field and sets the 'has_internet_until' instead to a new date.
143+
* @param Carbon $newDate
144+
* @return void
141145
*/
142-
public static function getInternetDeadline(): \Carbon\Carbon
146+
public static function resetInternetAccessPeriod(Carbon $newDate): void
143147
{
144-
return Semester::next()->getStartDate()->addMonth();
148+
$collegists = User::collegists()->pluck('id');
149+
150+
InternetAccess::whereIn('user_id', $collegists)->update([
151+
'netreg_paid' => false,
152+
'has_internet_until' => $newDate
153+
]);
145154
}
146155

147156
/**
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*/
12+
public function up(): void
13+
{
14+
Schema::table('internet_accesses', function (Blueprint $table) {
15+
$table->boolean('netreg_paid')->default(false);
16+
});
17+
}
18+
19+
/**
20+
* Reverse the migrations.
21+
*/
22+
public function down(): void
23+
{
24+
Schema::table('internet_accesses', function (Blueprint $table) {
25+
$table->dropColumn('netreg_paid');
26+
});
27+
}
28+
};

resources/views/network/admin/internet_access.blade.php

+8-20
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
<span class="card-title">Internetelérés</span>
22
<blockquote>
3-
<p>Az aktuális internetelérés határidő: <span class="coli-text text-orange">{{ $activation_date }}</span></p>
4-
<p>Collegisták esetén a Netreg befizetésekor automatikusan beállítja a rendszer a hozzáférésüket eddig a
5-
dátumig.</p>
3+
<p>Collegisták esetén a Netreg befizetésekor automatikusan beállítja a rendszer a hozzáférésüket a következő periódusig.</p>
64
<p>Vendégek esetén belépéskor meg kell adniuk a kiköltözés dátumát, amihez szinkronizáljuk az internet
75
hozzáférésüket. Ha egy volt colis kér netet, csak adj neki vendég jogosultságot, és első belépéskor be tudja
86
állítani már a netet magának.</p>
@@ -16,21 +14,7 @@
1614
<script type="text/javascript" src="{{ mix('js/moment.min.js') }}"></script>
1715
<script type="application/javascript">
1816
$(document).ready(function () {
19-
var activation_date = new Date("{{ $activation_date }}");
2017
var now = new Date();
21-
var extendAction = function (cell, formatterParams, onRendered) {
22-
var data = cell.getRow().getData();
23-
var active = (new Date(data.has_internet_until))
24-
onRendered(function () {
25-
$('.tooltipped').tooltip();
26-
});
27-
return $(`<button class="btn-floating tooltipped" style="margin-right: 10px" data-position="top" data-tooltip="Meghosszabbít: {{$activation_date}}">
28-
<i class="material-icons">update</i></button>
29-
`)
30-
.click(function () {
31-
sendExtendRequest(cell, data.user_id, "{{ $activation_date }}");
32-
}).toggle(data.has_internet_until == null || active < activation_date)[0];
33-
};
3418
3519
var revokeAction = function (cell, formatterParams, onRendered) {
3620
var data = cell.getRow().getData();
@@ -57,7 +41,7 @@
5741
if (value) {
5842
value = moment(value).format("YYYY. MM. DD. HH:mm");
5943
} else {
60-
value = 'Nincs hozzáférés'
44+
value = 'N/A'
6145
}
6246
const data = cell.getRow().getData();
6347
return $("<input type=\"text\" class=\"datepicker\" value=\"" + value + "\"/>")
@@ -134,13 +118,17 @@
134118
minWidth: 150,
135119
},
136120
{
137-
title: "Internetelérés",
121+
title: "Netreg fizetett",
122+
field: "netreg_paid",
123+
minWidth: 50,
124+
},
125+
{
126+
title: "Egyéni hozzáférés eddig",
138127
field: "has_internet_until",
139128
sorter: "datetime",
140129
formatter: dateFormatter,
141130
minWidth: 50,
142131
},
143-
{title: "", field: "state", headerSort: false, formatter: extendAction, width: 80},
144132
{title: "", field: "state", headerSort: false, formatter: revokeAction, width: 80},
145133
],
146134
ajaxResponse: function (url, params, response) {

resources/views/student-council/economic-committee/app.blade.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<div class="row">
1212
<div class="col s12">
1313
@include('utils.checkout.status')
14+
@include('student-council.economic-committee.period')
1415
<div class="row">
1516
@can('addKKTNetreg', \App\Models\Checkout::class)
1617
<div class="col s12">
@@ -29,7 +30,7 @@
2930
A Netreg tranzakcióid a <a href="{{route('admin.checkout')}}"> rendszergazdai kasszában</a> láthatod.
3031
</blockquote>
3132
@can('administrate', $checkout)
32-
<blockquote>A gazdasági alelnök, a kulturális bizottság tagjai és a rendszergazdák szedhetnek be KKT-t/Netreget. Ezeket a tranzakciókat a tartozások alatt találod.</blockquote>
33+
<blockquote>A gazdasági alelnök, a rendszergazdák, és a KKT jogosultsággal rendelkező collegisták szedhetnek be KKT-t/Netreget. Ezeket a tranzakciókat a tartozások alatt találod.</blockquote>
3334
@endcan
3435
<x-input.select l=4 :elements="$users_not_paid" id="user_id" text="general.user" :formatter="function($user) { return $user->uniqueName; }" />
3536
<x-input.text m=6 l=4 id="kkt" text="KKT" type="number" required min="0" :value="config('custom.kkt')" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
@can('administrate', $checkout)
2+
<div class="card">
3+
<form action="{{route('kktnetreg.period.update')}}" method="POST">
4+
@csrf
5+
<div class="card-content">
6+
<div class="card-title">
7+
KKT / Netreg fizetés időszak
8+
</div>
9+
@if($periodicEvent?->isActive())
10+
<blockquote>Jelenleg a KKT/Netreg fizetési időszak aktív. A határidő: {{$periodicEvent?->endDate()}}. </blockquote>
11+
@else
12+
<blockquote>Jelenleg a KKT/Netreg fizetési időszak nem aktív. Az aktiváláshoz add meg a határidőt, ami az internet hozzáférés vége lesz.</blockquote>
13+
<div class="row">
14+
<!-- These are using html datetime-local attribute because we don't have datetime picker. The labels are not compatible with our components. -->
15+
<x-input.select m="3" id="semester_id" :elements="\App\Models\Semester::all()" :value="$periodicEvent?->semester_id" :default="\App\Models\Semester::current()->id" helper="Szemeszter"/>
16+
<x-input.text m="3" id="end_date" type="datetime-local" without-label helper="Határidő" :value="$periodicEvent?->end_date"/>
17+
</div>
18+
<blockquote class="error">Megnyitás után a határidő nem módosítható, de a határidő lejárata után is lehet még fizetést felvinni.</blockquote>
19+
20+
<x-input.button floating class="right" icon="save"/>
21+
@endif
22+
</div>
23+
</form>
24+
</div>
25+
@endcan

routes/web.php

+1
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,7 @@
225225
Route::post('/economic_committee/mark_as_paid/{user}', [EconomicController::class, 'markAsPaid'])->name('economic_committee.pay');
226226
Route::post('/economic_committee/to_checkout', [EconomicController::class, 'toCheckout'])->name('economic_committee.to_checkout');
227227

228+
Route::post('/admission/kktnetreg/period/update', [EconomicController::class, 'updatePaymentPeriod'])->name('kktnetreg.period.update');
228229
Route::get('/economic_committee/kktnetreg', [EconomicController::class, 'indexKKTNetreg'])->name('kktnetreg');
229230
Route::post('/economic_committee/kktnetreg/pay', [EconomicController::class, 'payKKTNetreg'])->name('kktnetreg.pay');
230231
Route::get('/economic_committee/calculate_workshop_balance', [EconomicController::class, 'calculateWorkshopBalance'])->name('economic_committee.workshop_balance');

0 commit comments

Comments
 (0)