Halama penjualan :
<?php include "_header.php"; ?>
<div class="card mt-3">
<div class="card-header">
<h5>DATA PENJUALAN</h5>
<a href="tambahpenjualan.php" class="btn btn-primary btn-sm">Tambah</a>
</div>
<div class="card-body">
<table class="table table-bordered table-striped">
<thead class="thead-dark">
<tr>
<th scope="col">#</th>
<th scope="col">Tanggal</th>
<th scope="col">Total Harga</th>
<th scope="col">Pelanggan</th>
<th scope="col">Status</th>
<th scope="col">Aksi</th>
</tr>
</thead>
<tbody>
<?php
include 'koneksi.php';
$no = 1; //untuk membuat no urut data
$data = mysqli_query($koneksi, "SELECT * FROM penjualan JOIN pelanggan ON pelanggan.pelanggan_id = penjualan.pelanggan_id");
foreach ($data as $p) {
?>
<tr>
<th scope="row">
<?= $no++ ?>
</th>
<td><?= $p['tanggal'] ?></td>
<td><?= $p['total_harga'] ?></td>
<td><?= $p['nama_pelanggan'] ?></td>
<td><?= $p['status_bayar'] ?></td>
<td>
<a href="detail-penjualan.php?penjualan_id=<?=$p['penjualan_id'] ?>" class="btn btn-primary btn-sm">Detail</a>
<a href="edit-penjualan.php?penjualan_id=<?=$p['penjualan_id'] ?>" class="btn btn-primary btn-sm">Edit</a>
<a href="hapus-penjualan.php?penjualan_id=<?=$p['penjualan_id'] ?>" class="btn btn-danger btn-sm">Hapus</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<?php include "_footer.php"; ?>
Tambha Penjualan
<?php include "_header.php"; ?>
<div class="card mt-3">
<div class="card-header">
<h5>TAMBAH PENJUALAN</h5>
<a href="penjualan.php" class="btn btn-danger btn-sm">KEMBALI</a>
</div>
<div class="card-body">
<form method="POST" action="simpandata.php">
<div class="form-group">
<label>Tanggal</label>
<input type="datetime" class="form-control" name="tanggal" value="<?= date('Y-m-d H:i:s') ?>">
</div>
<div class="form-group">
<label>Nama Pelanggan</label>
<select class="form-control" name="pengguna_id" required>
<option value="">Pilih Pelanggan</option>
<?php
include 'koneksi.php';
$data = mysqli_query($koneksi, "SELECT * FROM pelanggan");
foreach ($data as $p) {
?>
<option value="<?= $p['pelanggan_id'] ?>">
<?= $p['nama_pelanggan'] ?> (<?= $p['alamat'] ?>)
</option>
<?php } ?>
</select>
</div>
<div class="row">
<div class="form-group col-md-6 ">
<label>Nama Produk</label>
<select class="form-control" name="produk_id" required>
<option value="">Pilih Produk</option>
<?php
include 'koneksi.php';
$data = mysqli_query($koneksi, "SELECT * FROM produk");
foreach ($data as $p) {
?>
<option value="<?= $p['produk_id'] ?>">
<?= $p['nama_produk'] ?> (<?= $p['harga'] ?>)
</option>
<?php } ?>
</select>
</div>
<div class="form-group col-md-6 ">
<label>Jumlah Produk</label>
<input type="number" class="form-control" name="qty" minlength="1" value="1" required>
</div>
</div>
<div class="form-group">
<label>Status Bayar</label>
<select class="form-control" name="status" required>
<option value="LUNAS">LUNAS</option>
<option value="BELUM LUNAS">BELUM LUNAS</option>
</select>
</div>
<button type="submit" class="btn btn-primary">SIMPAN</button>
</form>
</div>
</div>
<?php include "_footer.php"; ?>
simpanpenjualan
<?php
session_start();
include 'koneksi.php';
$tanggal = $_POST['tanggal'];
$pengguna_id = $_POST['pengguna_id'];
$produk_id = $_POST['produk_id'];
$qty = $_POST['qty'];
$status = $_POST['status'];
$amnilproduk = mysqli_query($koneksi,"SELECT * from produk where produk_id='$produk_id'");
$dataproduk = mysqli_fetch_assoc($amnilproduk);
$subtotal = $dataproduk['harga']*$qty;
$totalharga = $subtotal;
// penjualan_id tanggal total_harga pelanggan_id status_bayar
mysqli_query($koneksi,"INSERT into penjualan values('','$tanggal','$totalharga','$pengguna_id', '$status')");
$last_id = $koneksi->insert_id;
// detail_id penjualan_id produk_id qty sub_total
mysqli_query($koneksi,"INSERT into detail_penjualan values('','$last_id','$produk_id','$qty', '$subtotal')");
header("location:penjualan.php");
?>
DETAIL PENJUALAN
<?php include "_header.php";
$dd = $_GET['penjualan_id'];
include 'koneksi.php';
$data = mysqli_query($koneksi, "SELECT * FROM penjualan
JOIN pelanggan ON pelanggan.pelanggan_id = penjualan.pelanggan_id
JOIN detail_penjualan ON detail_penjualan.penjualan_id = penjualan.penjualan_id
JOIN produk ON produk.produk_id = detail_penjualan.produk_id
WHERE penjualan.penjualan_id = $dd
");
$detail = mysqli_fetch_assoc($data);
?>
<div class="card mt-3">
<div class="card-header">
<h5>DETAIL PENJUALAN</h5>
<a href="penjualan.php" class="btn btn-danger btn-sm">Kembali</a>
</div>
<div class="card-body">
<table class="">
<tr>
<td width="30%">Tanggal</td>
<td width="1px">:</td>
<td ><?= $detail['tanggal'] ?></td>
</tr>
<tr>
<td>Nama Pelanggan</td>
<td>:</td>
<td ><?= $detail['nama_pelanggan'] ?></td>
</tr>
<tr>
<td>Total belanja</td>
<td>:</td>
<td ><?= $detail['total_harga'] ?></td>
</tr>
<tr>
<td>Status Bayar</td>
<td>:</td>
<td ><?= $detail['status_bayar'] ?></td>
</tr>
</table>
<h6 class="mt-4">List Produk</h6>
<table class="table table-bordered">
<tr>
<th>Nama Produk</th>
<th >Harga</th>
<th>QTY</th>
</tr>
<tr>
<td ><?= $detail['nama_produk'] ?></td>
<td ><?= $detail['qty'] ?></td>
<td ><?= $detail['harga'] ?></td>
</tr>
</table>
</div>
</div>
<?php include "_footer.php"; ?>
DATABSE
0 Komentar