-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexport_excel.php
160 lines (147 loc) · 3.48 KB
/
export_excel.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
<?php
session_start();
include 'db.php';
if (!$conn) {
die("<script>alert('Gagal tersambung dengan database.')</script>");
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Export Data Ke Excel</title>
</head>
<body>
<style type="text/css">
body {
font-family: sans-serif;
}
table {
margin: 20px auto;
border-collapse: collapse;
}
table th,
table td {
border: 1px solid #3c3c3c;
padding: 3px 8px;
}
a {
background: blue;
color: #fff;
padding: 8px 10px;
text-decoration: none;
border-radius: 2px;
}
</style>
<?php
$includeTime = $_GET['include_time'] ?? true;
$tangwaltok = toDate_ID($_GET['tanggal_awal'], false);
$tangkirtok = toDate_ID($_GET['tanggal_akhir'], false);
$name_for_project = $tangwaltok . ' - ' . $tangkirtok;
$exportTitle = 'Data_' . $tangwaltok . '_' . $tangkirtok . '.xls';
$filename = $name_for_project . ".xls";
header("Content-type: application/vnd-ms-excel");
header('Content-disposition: attachment; filename=Laporan Data Suspek ' . $filename);
?>
<center>
<h4>Laporan Datasuspek<br>
Terminal 1 Bandara Juanda Surabaya<br>
Periode
<?= $tangwaltok ?> hingga
<?= $tangkirtok ?>
</h4>
</center>
<table border="1" width="100%">
<tr>
<th class="text-center">No</th>
<th class="text-center">Nomor Penerbangan</th>
<th class="text-center">Nama Penumpang</th>
<th class="text-center">Nomor HP</th>
<th class="text-center">Nama Barang</th>
<th class="text-center">Kategori Barang</th>
<th class="text-center">Jumlah</th>
<th class="text-center">Tanggal</th>
</tr>
<!-- Menampilkan Data yang ada di Database -->
<?php
$no = 1;
$tangwal = $_GET['tanggal_awal'] . " 00:00:00";
$tangkir = $_GET['tanggal_akhir'] . " 23:59:59";
$tampil = mysqli_query($conn, "SELECT * FROM `tb_suspek` WHERE tanggal_simpan BETWEEN '$tangwal' AND '$tangkir' ORDER BY tanggal_simpan ASC");
while ($data = mysqli_fetch_array($tampil)) {
?>
<tr>
<td>
<?= $no++ ?>
</td>
<td>
<?= $data['nomor_penerbangan'] ?>
</td>
<td>
<?= $data['nama_penumpang'] ?>
</td>
<td>
<?= $data['nomor'] ?>
</td>
<td>
<?= $data['nama_barang'] ?>
</td>
<td>
<?= $data['kategori_barang'] ?>
</td>
<td>
<?= $data['jumlah'] ?>
<td>
<?= toDate_ID($data['tanggal_simpan'], $includeTime) ?>
</td>
<?php } ?>
</tr>
</table>
<br>
<br>
<center>
<table>
<tr>
<th></th>
<th class="text-center">Mengetahui</th>
</tr>
</table>
</center>
<br>
<br>
<br>
<table>
<tr>
<td></td>
<td>_____________________</td>
</tr>
</table>
<?php
function toDate_ID($tanggal, $includeTime = false)
{
$date = new DateTime($tanggal);
$date_now = $date->format('d-m-Y');
$hour_now = $date->format('H:i:s');
$month = array(
1 => 'Januari',
'Februari',
'Maret',
'April',
'Mei',
'Juni',
'Juli',
'Agustus',
'September',
'Oktober',
'November',
'Desember'
);
$var = explode('-', $date_now);
$formattedDate = $var[0] . ' ' . $month[(int) $var[1]] . ' ' . $var[2];
if ($includeTime) {
$formattedDate .= ' ' . $hour_now;
}
return $formattedDate;
}
?>
</body>
</html>