-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_supplier.php
155 lines (137 loc) · 4.81 KB
/
data_supplier.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
<?php
require_once "layouts/header.php";
require_once "app/koneksi.php";
?>
<div class="row">
<div class="col-12">
<div class="card">
<div class="card-header">
<!-- tombah tambah data -->
<div class="row">
<div class="col-md-6">
<!-- Judul Halaman -->
<h4>Data Supplier</h4>
</div>
<div class="col-md-6 text-right">
<a href="#" class="btn btn-primary" data-toggle="modal" data-target="#formModal">TAMBAH</a>
</div>
</div>
</div>
<!-- /.card-header -->
<div class="card-body">
<table id="datatable" class="table table-bordered table-striped">
<thead>
<tr>
<th class="text-center">No</th>
<th>Nama Supplier</th>
<th>Kontak</th>
<th>Alamat</th>
<th class="text-center">Aksi</th>
</tr>
</thead>
<tbody>
<?php
$no = 1;
$supplier = $conn->query("SELECT * FROM supplier");
while ($data = $supplier->fetch_assoc()) :
?>
<tr>
<td class="text-center"><?= $no; ?></td>
<td><?= $data['nama'] ?></td>
<td><?= $data['kontak'] ?></td>
<td><?= $data['alamat'] ?></td>
<td class="text-center">
<a href="#" class="btn btn-success btn-xs" data-toggle="modal" data-target="#formModal" onclick='editForm(`<?= json_encode($data) ?>`)'>
<i class="fas fa-edit"></i>
</a>
<a href="#" class="btn btn-danger btn-xs" data-toggle="modal" data-target="#deleteModal" onclick='deleteModal(`hapus_supplier.php?id=<?= $data["id"] ?>`, `Supplier: <?= $data["nama"] ?>`)'>
<i class="fas fa-trash"></i>
</a>
</td>
</tr>
<?php $no++; ?>
<?php endwhile; ?>
</tbody>
</table>
</div>
<!-- /.card-body -->
</div>
<!-- /.card -->
</div>
<!-- /.col -->
</div>
<!-- /.row -->
<!-- Modal -->
<!-- Form Modal untuk tambah dan Edit Data -->
<div class="modal fade" id="formModal" tabindex="-1" role="dialog" aria-labelledby="formModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<!-- atur form disini -->
<form action="tambah_supplier.php" method="POST" id="form" class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="formModalLabel">Tambah Data Supplier</h5>
<button class="close" type="button" data-dismiss="modal" aria-label="Close" onclick="resetForm()">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<!-- edit untuk mengubah isi form -->
<input type="hidden" name="id" id="id" value="">
<div class="form-group">
<label for="nama">Nama Supplier</label>
<input type="text" name="nama" id="nama" class="form-control">
</div>
<div class="form-group">
<label for="kontak">Kontak Supplier</label>
<input type="number" name="kontak" id="kontak" class="form-control">
</div>
<div class="form-group">
<label for="alamat">Alamat Supplier</label>
<textarea name="alamat" id="alamat" class="form-control"></textarea>
</div>
</div>
<div class="modal-footer">
<!-- ubah tombol form -->
<button class="btn btn-secondary" type="reset" data-dismiss="modal" onclick="resetForm()">Cancel</button>
<input type="submit" class="btn btn-primary" value="Tambah">
</div>
</form>
</div>
</div>
<!-- coding untuk form edit -->
<script>
// fungsi untuk edit siswa
function editForm(data) {
// parse json data menjadi objek
data = JSON.parse(data);
// ikuti pola sesuaikan dengan id pada form modal data
// ubah action dari form menjadi edit
// let editAction = window.location.href + '&aksi=edit';
let editAction = 'update_supplier.php';
// console.log(window.location);
$('#form').attr('action', editAction);
// ubah judul form
$('#formModalLabel').html('Edit Data Barang');
// ubah tombol tambah menjadi edit
$('#form input[type=submit]').val('Edit');
// ubah dan tambahkan sesuai form kalian
$('#id').val(data.id);
$('#nama').val(data.nama);
$('#kontak').val(data.kontak);
$('#alamat').val(data.alamat);
}
// datatable
$(function() {
$("#datatable").DataTable({
"responsive": true,
"lengthChange": false,
"pageLength": 5,
// "scrollY": 500,
// "scrollX": true,
"scrollCollapse": true,
"autoWidth": false,
"ordering": false,
"info": false
});
});
</script>
<?php require_once "layouts/footer.php" ?>