Skip to content

Commit

Permalink
add members
Browse files Browse the repository at this point in the history
  • Loading branch information
udibagas committed Sep 15, 2019
1 parent fd33bff commit 0558017
Show file tree
Hide file tree
Showing 40 changed files with 1,066 additions and 187 deletions.
44 changes: 44 additions & 0 deletions .env-prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
APP_NAME="MITRATEKNIK PARKING SYSTEM"
APP_ENV=local
APP_KEY=
APP_DEBUG=true
APP_URL=http://localhost

LOG_CHANNEL=stack

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=parking_system
DB_USERNAME=parking_system
DB_PASSWORD="Bismillah1@#$%"

BROADCAST_DRIVER=log
CACHE_DRIVER=file
QUEUE_CONNECTION=sync
SESSION_DRIVER=file
SESSION_LIFETIME=120

REDIS_HOST=127.0.0.1
REDIS_PASSWORD=null
REDIS_PORT=6379

MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

AWS_ACCESS_KEY_ID=
AWS_SECRET_ACCESS_KEY=
AWS_DEFAULT_REGION=us-east-1
AWS_BUCKET=

PUSHER_APP_ID=
PUSHER_APP_KEY=
PUSHER_APP_SECRET=
PUSHER_APP_CLUSTER=mt1

MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}"
MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}"
10 changes: 10 additions & 0 deletions app/GroupMember.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class GroupMember extends Model
{
protected $fillable = ['name', 'description', 'contact_person_name', 'contact_person_email', 'contact_person_phone'];
}
72 changes: 72 additions & 0 deletions app/Http/Controllers/GroupMemberController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests\GroupMemberRequest;
use App\GroupMember;

class GroupMemberController extends Controller
{
public function __construct()
{
$this->middleware('role:1');
}

/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$sort = $request->sort ? $request->sort : 'name';
$order = $request->order == 'ascending' ? 'asc' : 'desc';

return GroupMember::when($request->keyword, function ($q) use ($request) {
return $q->where('name', 'LIKE', '%' . $request->keyword . '%')
->orWhere('description', 'LIKE', '%' . $request->keyword . '%');
})->orderBy($sort, $order)->paginate($request->pageSize);
}

/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(GroupMemberRequest $request)
{
return GroupMember::create($request->all());
}

/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(GroupMemberRequest $request, GroupMember $groupMember)
{
$groupMember->update($request->all());
return $groupMember;
}

/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy(GroupMember $groupMember)
{
$groupMember->delete();
return ['message' => 'Data telah dihapus'];
}

public function getList()
{
return GroupMember::orderBy('name', 'ASC')->get();
}
}
14 changes: 14 additions & 0 deletions app/Http/Controllers/MemberVehicleController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Http\Controllers;

use App\MemberVehicle;

class MemberVehicleController extends Controller
{
public function destroy(MemberVehicle $memberVehicle)
{
$memberVehicle->delete();
return ['message' => 'Data berhasil disimpan'];
}
}
4 changes: 4 additions & 0 deletions app/Http/Controllers/ParkingGateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ public function testCamera(ParkingGate $parkingGate)

public function testPrinter(ParkingGate $parkingGate)
{
if ($parkingGate->type == 'IN' && $parkingGate->printer_type == 'local') {
return response(['message' => 'PRINTER GATE IN SERIAL TIDAK BISA DITEST DARI WEB'], 500);
}

try {
if ($parkingGate->printer_type == "network") {
$connector = new NetworkPrintConnector($parkingGate->printer_ip_address, 9100);
Expand Down
80 changes: 62 additions & 18 deletions app/Http/Controllers/ParkingMemberController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Http\Request;
use App\ParkingMember;
use App\Http\Requests\ParkingMemberRequest;
use Illuminate\Support\Facades\DB;

class ParkingMemberController extends Controller
{
Expand All @@ -23,14 +24,21 @@ public function index(Request $request)
$sort = $request->sort ? $request->sort : 'name';
$order = $request->order == 'ascending' ? 'asc' : 'desc';

return ParkingMember::when($request->keyword, function ($q) use ($request) {
return $q->where('name', 'LIKE', '%' . $request->keyword . '%')
->orWhere('card_number', 'LIKE', '%' . $request->keyword . '%')
->orWhere('plate_number', 'LIKE', '%' . $request->keyword . '%');
return ParkingMember::selectRaw('
parking_members.*,
group_members.name AS `group`,
CASE WHEN expiry_date < DATE(NOW()) THEN 1 ELSE 0 END AS `expired`
')
->join('group_members', 'group_members.id', '=', 'parking_members.group_member_id', 'LEFT')
->when($request->keyword, function ($q) use ($request) {
return $q->where('parking_members.name', 'LIKE', '%' . $request->keyword . '%')
->orWhere('parking_members.card_number', 'LIKE', '%' . $request->keyword . '%');
})->when($request->is_active, function ($q) use ($request) {
return $q->whereIn('is_active', $request->is_active);
})->when($request->vehicle_type, function ($q) use ($request) {
return $q->whereIn('vehicle_type', $request->vehicle_type);
return $q->whereIn('parking_members.is_active', $request->is_active);
})->when($request->expired == ['y'], function ($q) {
return $q->whereRaw('parking_members.expiry_date < DATE(NOW())');
})->when($request->expired == ['n'], function ($q) {
return $q->whereRaw('parking_members.expiry_date >= DATE(NOW())');
})->orderBy($sort, $order)->paginate($request->pageSize);
}

Expand All @@ -42,7 +50,24 @@ public function index(Request $request)
*/
public function store(ParkingMemberRequest $request)
{
return ParkingMember::create($request->all());
try {
DB::transaction(function () use ($request) {
$id = DB::table('parking_members')->insertGetId($request->only([
'group_member_id', 'name', 'card_number',
'is_active', 'expiry_date', 'email', 'phone',
'paid', 'register_date', 'billing_cycle', 'fare'
]));

DB::table('member_vehicles')->insert(array_map(function($vehicle) use ($id) {
$vehicle['parking_member_id'] = $id;
return $vehicle;
}, $request->vehicles));
});
} catch (\Exception $e) {
return response(['message' => 'Data gagal disimpan. ' . $e->getMessage()], 500);
}

return ['message' => 'Data berhasil disimpan'];
}

/**
Expand All @@ -58,17 +83,14 @@ public function show(ParkingMember $parkingMember)

public function search(Request $request)
{
// harus salah 1, kalo gak plat ya kartu
if (!$request->plate_number && !$request->card_number) {
if (!$request->card_number) {
return response(['message' => 'No member found'], 404);
}

$member = ParkingMember::when($request->plate_number, function($q) use ($request) {
return $q->where('plate_number', $request->plate_number);
})->when($request->card_number, function($q) use ($request) {
return $q->where('card_number', 'LIKE', '%'.$request->card_number.'%');
})->where('expiry_date', '>=', date('Y-m-d'))
->where('is_active', 1)->first();
$member = ParkingMember::where('is_active', 1)
->where('expiry_date', '>=', date('Y-m-d'))
->where('card_number', 'LIKE', '%'.$request->card_number)
->first();

if (!$member) {
return response(['message' => 'No member found'], 404);
Expand All @@ -86,8 +108,30 @@ public function search(Request $request)
*/
public function update(ParkingMemberRequest $request, ParkingMember $parkingMember)
{
$parkingMember->update($request->all());
return $parkingMember;
try {
DB::transaction(function () use ($request, $parkingMember) {
DB::table('parking_members')
->where('id', $parkingMember->id)
->update($request->only([
'group_member_id', 'name', 'card_number',
'is_active', 'expiry_date', 'email', 'phone',
'paid', 'register_date', 'billing_cycle', 'fare'
]));

DB::table('member_vehicles')
->where('parking_member_id', $parkingMember->id)
->delete();

DB::table('member_vehicles')->insert(array_map(function($vehicle) use ($parkingMember) {
$vehicle['parking_member_id'] = $parkingMember->id;
return $vehicle;
}, $request->vehicles));
});
} catch (\Exception $e) {
return response(['message' => 'Data gagal disimpan. ' . $e->getMessage()], 500);
}

return ['message' => 'Data berhasil disimpan'];
}

/**
Expand Down
30 changes: 30 additions & 0 deletions app/Http/Requests/GroupMemberRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class GroupMemberRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return auth()->check();
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required'
];
}
}
36 changes: 36 additions & 0 deletions app/Http/Requests/MemberVehicleRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class MemberVehicleRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return auth()->check();
}

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'parking_member_id' => 'required|exists:parking_members,id',
'vehicle_type' => 'required',
'plate_number' => 'required',
'merk' => 'required',
'type' => 'required',
'tahun' => 'required|digits:4',
'warna' => 'required',
];
}
}
18 changes: 12 additions & 6 deletions app/Http/Requests/ParkingMemberRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ public function rules()
return [
'name' => 'required',
'card_number' => 'required',
'plate_number' => 'required',
'vehicle_type' => 'required|in:MOBIL,MOTOR',
'is_active' => 'boolean',
'expiry_date' => 'required|date',
'phone' => 'required',
'email' => 'required|email'
'email' => 'required|email',
'group_member_id' => 'required',
'paid' => 'boolean',
'register_date' => 'required|date',
'billing_cycle' => 'numeric',
'fare' => 'numeric'
];
}

Expand All @@ -40,12 +43,15 @@ public function attributes()
return [
'name' => 'Nama',
'card_number' => 'Nomor Kartu',
'plate_number' => 'Nomor Plat',
'vehicle_type' => 'Jenis Kendaraan',
'is_active' => 'Aktif',
'expiry_date' => 'Tanggal Kedaluarsa',
'phone' => 'Nomor HP',
'email' => 'ALamat Email'
'email' => 'ALamat Email',
'group_member_id' => 'Group',
'paid' => 'Berbayar',
'register_date' => 'Tanggal Daftar',
'billing_cycle' => 'Siklus Pembayaran',
'fare' => 'Tarif'
];
}
}
14 changes: 14 additions & 0 deletions app/MemberVehicle.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class MemberVehicle extends Model
{
protected $fillable = [
'parking_member_id', 'vehicle_type',
'plate_number', 'merk', 'type',
'tahun', 'warna',
];
}
Loading

0 comments on commit 0558017

Please sign in to comment.