Skip to content

Commit

Permalink
gate out jos
Browse files Browse the repository at this point in the history
  • Loading branch information
udibagas committed Nov 21, 2019
1 parent 328cc98 commit bbf3589
Show file tree
Hide file tree
Showing 10 changed files with 322 additions and 39 deletions.
101 changes: 88 additions & 13 deletions app/Http/Controllers/MemberRenewalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\ParkingGate;
use App\ParkingMember;
use App\Setting;
use Illuminate\Support\Facades\DB;
use Mike42\Escpos\PrintConnectors\NetworkPrintConnector;
use Mike42\Escpos\PrintConnectors\FilePrintConnector;
use Mike42\Escpos\Printer;
Expand All @@ -32,7 +33,9 @@ public function index(Request $request)
')
->join('parking_members', 'parking_members.id', '=', 'member_renewals.parking_member_id')
->join('users', 'users.id', '=', 'member_renewals.user_id')
->when($request->keyword, function($q) use ($request) {
->when($request->dateRange, function($q) use ($request) {
return $q->whereRaw("DATE(member_renewals.updated_at) BETWEEN '{$request->dateRange[0]}' AND '{$request->dateRange[1]}' ");
})->when($request->keyword, function($q) use ($request) {
return $q->where('parking_members.name', 'LIKE', '%'.$request->keyword.'%')
->orWhere('parking_members.card_number', 'LIKE', '%'.$request->keyword.'%')
->orWhere('users.name', 'LIKE', '%'.$request->keyword.'%');
Expand Down Expand Up @@ -87,12 +90,12 @@ public function destroy(MemberRenewal $memberRenewal)

public function printSlip(MemberRenewal $memberRenewal)
{
$parkingGate = ParkingGate::where('type', 'OUT')->where('active', 1)->first();
// $parkingGate = ParkingGate::where('type', 'OUT')->where('active', 1)->first();
$setting = Setting::first();

if (!$parkingGate) {
return response(['message' => 'TIDAK ADA PRINTER YANG DIPILIH'], 404);
}
// if (!$parkingGate) {
// return response(['message' => 'TIDAK ADA PRINTER YANG DIPILIH'], 404);
// }

if (!$setting) {
return response(['message' => 'BELUM ADA SETTING'], 500);
Expand All @@ -102,15 +105,22 @@ public function printSlip(MemberRenewal $memberRenewal)
return response(['message' => 'LOKASI BELUM DISET'], 500);
}

try {
if ($parkingGate->printer_type == "network") {
$connector = new NetworkPrintConnector($parkingGate->printer_ip_address, 9100);
} else if ($parkingGate->printer_type == "local") {
$connector = new FilePrintConnector($parkingGate->printer_device);
} else {
return response(['message' => 'INVALID PRINTER'], 500);
}
// try {
// if ($parkingGate->printer_type == "network") {
// $connector = new NetworkPrintConnector($parkingGate->printer_ip_address, 9100);
// } else if ($parkingGate->printer_type == "local") {
// $connector = new FilePrintConnector($parkingGate->printer_device);
// } else {
// return response(['message' => 'INVALID PRINTER'], 500);
// }

// $printer = new Printer($connector);
// } catch (\Exception $e) {
// return response(['message' => 'KONEKSI KE PRINTER GAGAL. ' . $e->getMessage()], 500);
// }

try {
$connector = new NetworkPrintConnector(env('PRINTER_ADDRESS'), 9100);
$printer = new Printer($connector);
} catch (\Exception $e) {
return response(['message' => 'KONEKSI KE PRINTER GAGAL. ' . $e->getMessage()], 500);
Expand Down Expand Up @@ -138,4 +148,69 @@ public function printSlip(MemberRenewal $memberRenewal)

return ['message' => 'SILAKAN AMBIL SLIP'];
}

public function report(Request $request)
{
$sql = "SELECT DATE(created_at) AS tanggal,
COUNT(id) AS jumlah,
SUM(amount) AS pendapatan
FROM member_renewals
WHERE DATE(created_at) BETWEEN :start AND :end
GROUP BY DATE(created_at)";

$data = DB::select($sql, [
':start' => $request->dateRange[0],
':end' => $request->dateRange[1]
]);

if ($request->action == 'print') {
$this->printReport($data);
}

return $data;
}

protected function printReport($data)
{
$setting = Setting::first();

if (!$setting) {
return response(['message' => 'BELUM ADA SETTING'], 500);
}

if (!$setting->location_name) {
return response(['message' => 'LOKASI BELUM DISET'], 500);
}

try {
$connector = new NetworkPrintConnector(env('PRINTER_ADDRESS'), 9100);
$printer = new Printer($connector);
} catch (\Exception $e) {
return response(['message' => 'KONEKSI KE PRINTER GAGAL. ' . $e->getMessage()], 500);
}

try {
$printer->setJustification(Printer::JUSTIFY_CENTER);
$printer->text("LAPORAN PENDAPATAN ANGGOTA\n");
$printer->text($setting->location_name."\n");
$printer->text("\n\n");

$printer->setJustification(Printer::JUSTIFY_LEFT);

$printer->text(str_pad('TANGGAL', 15, ' ') . str_pad('JUMLAH', 15, ' ') . str_pad('PENDAPATAN', 15, ' ') . "\n");

foreach ($data as $d) {
$printer->text(str_pad(date('d/M/Y', strtotime($d->tanggal)), 15, ' ')
. str_pad(number_format($d->jumlah, 0, ',', '.'), 15, ' ')
. str_pad(number_format($d->pendapatan, 0, ',', '.'), 15, ' ') . "\n");
}

$printer->cut();
$printer->close();
} catch (\Exception $e) {
return response(['message' => 'GAGAL MENCETAK SLIP.' . $e->getMessage()], 500);
}

return ['message' => 'SILAKAN AMBIL SLIP'];
}
}
31 changes: 29 additions & 2 deletions controller_test.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,42 @@
import socket
import sys

if len(sys.argv) == 1:
print('Please specify device model: enet, compass')
sys.exit()

if len(sys.argv) == 2:
print('Please specify device ip')
sys.exit()

if sys.argv[1] == 'enet':
port = 4000
prefix = b':'
suffix = b';'

elif sys.argv[1] == 'compass':
port = 5000
prefix = b'\xa6'
suffix = b'\xa9'

else:
print('Invalid device model. Please choose either enet or compass')
sys.exit()

with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(3)

try:
s.connect(('192.168.1.100', 5000))
s.connect((sys.argv[2], port))
except Exception:
print('Failed to connect to controller')
sys.exit()

while True:
cmd = input('> ')
s.sendall(b"".join([b'\xa6', cmd.encode(), b'\xa9']))

if cmd == 'quit' or cmd == 'exit':
break

s.sendall(b"".join([prefix, cmd.encode(), suffix]))
print(':' + str(s.recv(64)))
2 changes: 1 addition & 1 deletion public/js/app.js

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions resources/js/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,18 @@ export default {
},
logout() {
axios.post('/logout', { token: this.$store.state.token }).then(r => {
this.$message({
message: 'Anda telah keluar',
type: 'success',
showClose: true
})
}).catch(e => {
this.$message({
message: 'Token tidak sesuai',
type: 'error',
showClose: true
})
}).finally(() => {
window.localStorage.removeItem('user')
window.localStorage.removeItem('token')
this.$store.state.user = {}
Expand Down
61 changes: 41 additions & 20 deletions resources/js/pages/GateOutApp.vue
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ export default {
} else {
let params = { barcode_number: this.formModel.barcode_number }
axios.get('/parkingTransaction/search', { params: params }).then(r => {
this.snapshot_in = r.data.snapshot_in
this.formModel.id = r.data.id
this.formModel.gate_in_id = r.data.gate_in_id
this.formModel.time_in = r.data.time_in
this.formModel.is_member = r.data.is_member
this.formModel.time_out = now
this.$forceUpdate()
this.setDuration()
if (r.data.is_member) {
if (r.data.member.expired) {
this.$alert('Kartu telah habis masa berlaku', 'Perhatian', {
Expand All @@ -258,6 +268,7 @@ export default {
confirmButtonText: 'OK',
confirmButtonClass: 'bg-red',
})
this.formModel.is_member = 0;
return
}
Expand All @@ -271,31 +282,41 @@ export default {
})
}
let vehicle = r.data.member.vehicles.find(v => v.plate_number == this.formModel.plate_number)
if (!vehicle) {
this.$alert('Nomor plat tidak cocok dengan kartu. Nomor plat yang terdaftar adalah '
+ r.data.member.vehicles.map(v => v.plate_number).join(', '), 'Notifikasi', {
type: 'warning',
center: true,
roundButton: true,
confirmButtonText: 'SAYA TELAH MEMBACA NOTIFIKASI INI',
confirmButtonClass: 'bg-red'
})
if (this.setting.disable_plat_nomor) {
this.$confirm('Plat nomor yang terdaftar atas kartu ini adalah '
+ r.data.member.vehicles.map(v => v.plate_number).join(', '), 'Perhatian', {
type: 'warning',
center: true,
roundButton: true,
confirmButtonText: 'SESUAI',
cancelButtonText: 'TIDAK SESUAI',
}).then(() => {
if (r.data.member.vehicles.length == 1) {
this.formModel.vehicle_type = r.data.member.vehicles[0].vehicle_type
}
this.update(false)
}).catch(() => {
this.formModel.is_member = 0;
return
})
} else {
let vehicle = r.data.member.vehicles.find(v => v.plate_number == this.formModel.plate_number)
if (!vehicle) {
this.$alert('Plat nomor tidak cocok dengan kartu. Nomor plat yang terdaftar adalah '
+ r.data.member.vehicles.map(v => v.plate_number).join(', '), 'Perhatian', {
type: 'warning',
center: true,
roundButton: true,
confirmButtonText: 'OK',
confirmButtonClass: 'bg-red'
})
}
}
this.formModel.fare = 0
}
this.snapshot_in = r.data.snapshot_in
this.formModel.id = r.data.id
this.formModel.gate_in_id = r.data.gate_in_id
this.formModel.time_in = r.data.time_in
this.formModel.is_member = r.data.is_member
this.formModel.time_out = now
this.$forceUpdate()
this.setDuration()
// member auto open sesuai setingan
if (r.data.is_member && !r.data.member.expired && this.setting.member_auto_open) {
this.update(false)
Expand Down
4 changes: 3 additions & 1 deletion resources/js/pages/Member.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<el-tab-pane lazy label="Member"><ParkingMember /></el-tab-pane>
<el-tab-pane lazy label="Group Member"><GroupMember /></el-tab-pane>
<el-tab-pane lazy label="Pembayaran"><MemberRenewal /></el-tab-pane>
<el-tab-pane lazy label="Laporan Pendapatan"><MembershipReport /></el-tab-pane>
</el-tabs>
</div>
</template>
Expand All @@ -15,9 +16,10 @@
import ParkingMember from './ParkingMember'
import MemberRenewal from './MemberRenewal'
import GroupMember from './GroupMember'
import MembershipReport from './MembershipReport'
export default {
components: { ParkingMember, MemberRenewal, GroupMember }
components: { ParkingMember, MemberRenewal, GroupMember, MembershipReport }
}
</script>

Expand Down
16 changes: 15 additions & 1 deletion resources/js/pages/MemberRenewal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
<el-form-item>
<el-button @click="openForm({})" type="primary"><i class="el-icon-plus"></i> INPUT PEMBAYARAN KEANGGOTAAN</el-button>
</el-form-item>
<el-form-item>
<el-date-picker
@change="requestData"
v-model="dateRange"
format="dd/MMM/yyyy"
value-format="yyyy-MM-dd"
type="daterange"
range-separator="-"
start-placeholder="Dari tanggal"
end-placeholder="Sampai tanggal">
</el-date-picker>
</el-form-item>
<el-form-item style="margin-right:0;">
<el-input v-model="keyword" placeholder="Search" prefix-icon="el-icon-search" :clearable="true" @change="(v) => { keyword = v; requestData(); }">
<el-button @click="() => { page = 1; keyword = ''; requestData(); }" slot="append" icon="el-icon-refresh"></el-button>
Expand Down Expand Up @@ -84,7 +96,7 @@

<el-form-item label="Siklus Pembayaran" :class="formErrors.billing_cycle ? 'is-error' : ''">
<el-input type="number" v-model="formModel.billing_cycle" style="width: 30%"></el-input>
<el-select v-model="formModel.billing_cycle_unit" style="width:66%;float:right;clear: right;">
<el-select placeholder="Pilih" v-model="formModel.billing_cycle_unit" style="width:66%;float:right;clear: right;">
<el-option v-for="(s, i) in $store.state.siklus" :value="s.value" :label="s.label" :key="i"></el-option>
</el-select>
<div class="el-form-item__error" v-if="formErrors.billing_cycle">{{formErrors.billing_cycle[0]}}</div>
Expand Down Expand Up @@ -128,6 +140,7 @@ export default {
sort: 'created_at',
order: 'descending',
loading: false,
dateRange: ''
}
},
computed: {
Expand Down Expand Up @@ -236,6 +249,7 @@ export default {
pageSize: this.pageSize,
sort: this.sort,
order: this.order,
dateRange: this.dateRange
}
this.loading = true;
Expand Down
Loading

0 comments on commit bbf3589

Please sign in to comment.