Skip to content

Commit

Permalink
add card type field
Browse files Browse the repository at this point in the history
  • Loading branch information
Bagas Udi Sahsangka committed Aug 23, 2021
1 parent 657fda9 commit 42de78d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/Http/Controllers/MemberController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public function index(Request $request)
$q->selectRaw($request->columns);
})->when($request->status, function ($q) use ($request) {
$q->whereIn('status', $request->status);
})->when($request->card_type, function ($q) use ($request) {
$q->whereIn('card_type', $request->card_type);
})->when($request->group_member_id, function ($q) use ($request) {
$q->whereIn('group_member_id', $request->group_member_id);
})->when($request->expired == ['y'] || $request->expired == 'y', function ($q) {
Expand Down
32 changes: 32 additions & 0 deletions database/migrations/2021_08_23_103127_add_card_type_on_member.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class AddCardTypeOnMember extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('members', function (Blueprint $table) {
$table->string('card_type', 10)->default('RFID')->nullable();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('members', function (Blueprint $table) {
$table->dropColumn('card_type');
});
}
}
17 changes: 11 additions & 6 deletions parking.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def login():

if r.status_code == 200:
response = r.json()
API_HEADERS = {"Authorization": "Bearer " + response['token']}
API_HEADERS = {"Authorization": "Bearer " + response["token"]}
return True

return False
Expand Down Expand Up @@ -68,8 +68,8 @@ def send_notification(gate, message):
return True


def check_card(gate, nomor_kartu):
payload = {"nomor_kartu": nomor_kartu, "status": 1}
def check_card(gate, nomor_kartu, card_type="RFID"):
payload = {"nomor_kartu": nomor_kartu, "status": 1, "card_type": card_type}
try:
r = requests.get(
API_URL + "/member/search", params=payload, timeout=3, headers=API_HEADERS
Expand Down Expand Up @@ -201,14 +201,19 @@ def gate_in_thread(gate):

if b"W" in push_button_or_card or b"X" in push_button_or_card:
delimiter = "W"
card_type = "RFID"

if (b"X" in push_button_or_card):
if b"X" in push_button_or_card:
delimiter = "X"
card_type = "UHF"

nomor_kartu = (
str(push_button_or_card).split(delimiter)[1].split("\\xa9")[0]
str(push_button_or_card)
.split(delimiter)[1]
.split("\\xa9")[0]
)
member = check_card(gate, str(int(nomor_kartu, 16)))

member = check_card(gate, str(int(nomor_kartu, 16)), card_type)
time.sleep(0.1) # kasih jeda biar audio bisa play

if not member:
Expand Down

0 comments on commit 42de78d

Please sign in to comment.