-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclass.php
378 lines (304 loc) · 9.33 KB
/
class.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
<?php
class Koneksi
{
protected $con;
public function __construct()
{
$this->con = new mysqli("localhost", "root", "", "dbdapurperdana");
}
public function getError()
{
if ($this->con->connect_errno) {
return "Failed Connect: " . $this->con->connect_errno;
}
}
public function __destruct()
{
$this->con->close();
}
}
class User extends Koneksi
{
public function __construct()
{
parent::__construct();
}
// lanjut ntar
public function daftar($user, $nama, $pwd, $role)
{
$stmt = $this->con->prepare("INSERT INTO user VALUES(?, ?, ?, ?)");
$stmt->bind_param("ssss", $user, $pwd, $nama, $role);
$stmt->execute();
$result = "";
if (!$stmt->error) {
$result = "Pendaftaran berhasil";
header("location: index.php");
} else {
$result = "Pendaftaran gagal";
}
return $result;
}
public function getUser($id)
{
$stmt = $this->con->prepare("SELECT * FROM user WHERE id = ?");
$stmt->bind_param("s", $id);
$stmt->execute();
$result = $stmt->get_result();
return $result;
}
public function cekLogin($uname)
{
$stmt = $this->con->prepare("SELECT * FROM user WHERE username=?");
$stmt->bind_param("s", $uname);
$stmt->execute();
$result = $stmt->get_result();
return $result;
}
}
class Barang extends Koneksi
{
public function __construct()
{
parent::__construct();
}
public function bacaDataById($search)
{
$stmt = $this->con->prepare("SELECT * FROM barang WHERE id LIKE ? ");
$stmt->bind_param("i", $search);
$stmt->execute();
$result = $stmt->get_result();
return $result;
}
public function bacaData($search)
{
$stmt = $this->con->prepare("SELECT * FROM barang WHERE nama LIKE ? ");
$stmt->bind_param("s", $search);
$stmt->execute();
$result = $stmt->get_result();
return $result;
}
//UNTUK SEARCH
public function getTotalData($kategori, $search)
{
// $stmt = $this->con->prepare("SELECT * FROM barang WHERE id_kategori LIKE ? AND nama LIKE ?");
$stmt = $this->con->prepare("SELECT b.* FROM barang b INNER JOIN kategori_barang kb ON b.id_kategori = kb.id WHERE kb.nama LIKE ? AND b.nama LIKE ? ORDER BY b.id");
$stmt->bind_param("ss", $kategori, $search);
$stmt->execute();
$result = $stmt->get_result();
return $result;
}
public function tambahBarang($nama, $hargabeli, $hargajual, $url, $stok, $idkategori)
{
// $idbarang,
$stmt = $this->con->prepare('INSERT INTO barang(nama,harga_beli,harga_jual,url,stok_tersedia,id_kategori) VALUES(?, ?, ?, ?, ?, ?)');
$stmt->bind_param('siisii', $nama, $hargabeli, $hargajual, $url, $stok, $idkategori);
$stmt->execute();
}
public function updateBarang($idbarang, $nama, $hbeli, $hjual, $url, $stok, $idkategori)
{
$stmt = $this->con->prepare('UPDATE barang SET nama=?, harga_beli=?, harga_jual=?, url=?, stok_tersedia=?, id_kategori=? WHERE id=?');
$stmt->bind_param("siisiii", $nama, $hbeli, $hjual, $url, $stok, $idkategori, $idbarang);
$stmt->execute();
}
public function hapusBarang($idbarang)
{
$stmt = $this->con->prepare('DELETE FROM barang WHERE id=?');
$stmt->bind_param("i", $idbarang);
$stmt->execute();
}
// UNTUK STOK
public function bacaStok($idbarang)
{
$stmt = $this->con->prepare("SELECT nama, stok_tersedia, harga_jual FROM barang WHERE id LIKE ? ");
$stmt->bind_param("i", $idbarang);
$stmt->execute();
$result = $stmt->get_result();
return $result;
}
public function updateStok($idbarang, $stok)
{
$stmt = $this->con->prepare('UPDATE barang SET stok_tersedia=? WHERE id=?');
$stmt->bind_param("ii", $stok, $idbarang);
$stmt->execute();
}
}
class Kategori extends Koneksi
{
public function __construct()
{
parent::__construct();
}
public function bacaData($search)
{
$stmt = $this->con->prepare("SELECT * FROM kategori_barang WHERE nama LIKE ? ");
$stmt->bind_param("s", $search);
$stmt->execute();
$result = $stmt->get_result();
return $result;
}
public function bacaDataById($search)
{
$stmt = $this->con->prepare("SELECT * FROM kategori_barang WHERE id LIKE ? ");
$stmt->bind_param("i", $search);
$stmt->execute();
$result = $stmt->get_result();
return $result;
}
public function tambahKategori($nama, $url)
{
$stmt = $this->con->prepare('INSERT INTO kategori_barang(nama, url) VALUES(?, ?)');
$stmt->bind_param('ss', $nama, $url);
$stmt->execute();
}
public function updateKategori($idkategori, $nama, $url)
{
$stmt = $this->con->prepare('UPDATE kategori_barang SET nama=?, url=? WHERE id=?');
$stmt->bind_param("ssi", $nama, $url, $idkategori);
$stmt->execute();
}
public function hapusKategori($idkategori)
{
$stmt = $this->con->prepare('DELETE FROM kategori_barang WHERE id=?');
$stmt->bind_param("i", $idkategori);
$stmt->execute();
}
}
class Supplier extends Koneksi
{
public function __construct()
{
parent::__construct();
}
public function updateSupplier($idsupplier, $namasupplier, $alamat, $notelepon)
{
$stmt = $this->con->prepare('UPDATE supplier SET nama=?, alamat=?, nomor_telepon=? WHERE id=?');
$stmt->bind_param("sssi", $namasupplier, $alamat, $notelepon, $idsupplier);
$stmt->execute();
}
public function bacaData($search)
{
$stmt = $this->con->prepare("SELECT * FROM supplier WHERE nama LIKE ?");
$stmt->bind_param("s", $search);
$stmt->execute();
$result = $stmt->get_result();
return $result;
}
public function bacaDataById($id)
{
$stmt = $this->con->prepare("SELECT * FROM supplier WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
return $result;
}
public function tambahSupplier($namasupplier, $alamat, $notelepon)
{
$stmt = $this->con->prepare('INSERT INTO supplier(nama, alamat, nomor_telepon) VALUE(?, ?, ?)');
$stmt->bind_param("sss", $namasupplier, $alamat, $notelepon);
$stmt->execute();
}
public function hapusSupplier($idsupplier)
{
$stmt = $this->con->prepare('DELETE FROM supplier WHERE id=?');
$stmt->bind_param("i", $idsupplier);
$stmt->execute();
}
}
class DetailPenjualan extends Koneksi
{
public function __construct()
{
parent::__construct();
}
public function bacaData($search)
{
$stmt = $this->con->prepare("SELECT tp.id_transaksi Kode, DATE_FORMAT(tp.tanggal,'%Y-%m-%d') Hari, DATE_FORMAT(tp.tanggal,'%H:%i:%s') Waktu, b.nama, dtp.jumlah_terjual, dtp.total, tp.metode_pembayaran, b.harga_beli, dtp.total-harga_beli untung
FROM transaksi_penjualan tp INNER JOIN detail_transaksi_penjualan dtp ON tp.id_transaksi = dtp.id_transaksi_penjualan
INNER JOIN barang b ON dtp.id_barang = b.id WHERE tp.tanggal LIKE ?");
$stmt->bind_param("s", $search);
$stmt->execute();
$result = $stmt->get_result();
return $result;
}
public function getId()
{
$stmt = $this->con->prepare("SELECT MAX(id_transaksi) id FROM transaksi_penjualan");
$stmt->execute();
$result = $stmt->get_result();
return $result;
}
public function tambahDataTransaksiPenjualan($idkaryawan, $metodepembayaran = 'Tunai', $jumlahtotal = 0)
{
$stmt = $this->con->prepare('INSERT INTO transaksi_penjualan(metode_pembayaran, jumlah_total, id_user) VALUE(?, ?, ?)');
$stmt->bind_param("sii", $metodepembayaran, $jumlahtotal, $idkaryawan);
$stmt->execute();
}
public function tambahDataDetailTransaksiPenjualan($idtransaksi, $idbarang, $jumlah, $harga, $total, $diskon = 0)
{
$stmt = $this->con->prepare('INSERT INTO detail_transaksi_penjualan(jumlah_terjual, harga_satuan, total, diskon, id_transaksi_penjualan, id_barang) VALUE(?, ?, ?, ?, ?, ?)');
$stmt->bind_param("iiiiii", $jumlah, $harga, $total, $diskon, $idtransaksi, $idbarang);
$stmt->execute();
}
}
class Penyesuaian extends Koneksi
{
public function __construct()
{
parent::__construct();
}
public function bacaData($search)
{
$stmt = $this->con->prepare("SELECT * FROM penyesuaian WHERE keterangan LIKE ?");
$stmt->bind_param("s", $search);
$stmt->execute();
$result = $stmt->get_result();
return $result;
}
public function tambahPenyesuaian($keterangan, $stok, $idbarang)
{
$stmt = $this->con->prepare('INSERT INTO penyesuaian(keterangan, stok_penyesuaian, id_barang) VALUE(?, ?, ?)');
$stmt->bind_param("sii", $keterangan, $stok, $idbarang);
$stmt->execute();
}
}
class Pegawai extends Koneksi
{
public function __construct()
{
parent::__construct();
}
public function updatePegawai($idpegawai, $usernamepegawai, $password, $namapegawai, $role)
{
$stmt = $this->con->prepare('UPDATE user SET username=?, password=?, nama=?, role=? WHERE id=?');
$stmt->bind_param("ssssi", $usernamepegawai, $password, $namapegawai, $role, $idpegawai);
$stmt->execute();
}
public function bacaData($search)
{
$stmt = $this->con->prepare("SELECT * FROM user WHERE nama LIKE ?");
$stmt->bind_param("s", $search);
$stmt->execute();
$result = $stmt->get_result();
return $result;
}
public function bacaDataById($id)
{
$stmt = $this->con->prepare("SELECT * FROM user WHERE id = ?");
$stmt->bind_param("i", $id);
$stmt->execute();
$result = $stmt->get_result();
return $result;
}
public function tambahPegawai($usernamepegawai, $password, $namapegawai, $role)
{
$stmt = $this->con->prepare('INSERT INTO user(username, password, nama, role) VALUE(?, ?, ?, ?)');
$stmt->bind_param("ssss", $usernamepegawai, $password, $namapegawai, $role);
$stmt->execute();
}
public function hapusPegawai($idpegawai)
{
$stmt = $this->con->prepare('DELETE FROM user WHERE id=?');
$stmt->bind_param("i", $idpegawai);
$stmt->execute();
}
}