Catatan Kaki
<?php
function hitung_tagihan_awal($harga, $jumlah){
$hitung_tagihan_awal = $harga * $jumlah;
return $hitung_tagihan_awal;
}
$cabang = array("Harmoni", "Sarinah", "Grogol","Senayan","Pluit", "Cempaka");
array_multisort($cabang,SORT_ASC);
$hargaSatuan=50000;
?>
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css/style.css"> <!-- input css-->
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- Bootstrap CSS -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<title>Pulsa Sejahtera</title>
</head>
<body>
<div class="container">
<div class="row justify-content-center">
<div class="col-6">
<div class="card">
<h3>Form Pemesanan Pulsa</h3>
<img src="img/logo.png" width='10%' height='10%'>
<!-- Form untuk memasukkan data pemesanan. -->
<form action="" method="post" id="formPemesanan">
<div class="card-body">
<!-- Masukan pilihan lokasi cabang resto. -->
<div class="form-floating mb-3">
<select id="cabang" name="cabang" class="form-control">
<option value="">- Pilih Cabang -</option>
<option value= "Harmoni"> </option>
<option value= "Sarinah"> Sarinah</option>
<option value= "Grogol"> Grogol</option>
<option value= "Senayan"> Senayan</option>
<option value= "Pluit"> Pluit</option>
<option value= "Cempaka"> Cempaka</option>
<?php
for ($i=0; $i<count ($cabang); $i++){
echo "<option value='".$cabang[$i].">$cabang[$i]</option>";
}
?>
</select>
<label for="floatingInput">Cabang : </label>
</div>
</div>
<div class="form-floating mb-3">
<input type="text" class="form-control" name="nama" id="nama" required>
<label for="floatingInput2">Nama Pelanggan</label>
</div>
<div class="form-floating mb-3">
<input type="text" class="form-control" name="noHP" id="noHP" maxlength="16" required>
<label for="floatingInput2">Nomor HP</label>
</div>
<div class="form-floating mb-3">
<input type="number" class="form-control" name="jumlahPesanan" id="jumlahPesanan" maxlength="4" required>
<label for="floatingInput2">Jumlah Kotak</label>
</div>
<div class="row">
<div class="col-lg-2"><button class="btn btn-primary" type="submit" form="formPemesanan" value="Pesan" name="Pesan">Pesan</button></div>
<div class="col-lg-2"></div>
</div>
</form>
</div>
</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
<?php
$file = "data.json";
$konten = file_get_contents($file);
$data = json_decode($konten, true);
if(isset($_POST['Pesan'])) {
$dataPesanan[] = array(
'cabang' => $_POST['cabang'],
'nama' => $_POST['nama'],
'noHP' => $_POST['noHP'],
'jumlahPesanan' => $_POST['jumlahPesanan']
);
$berkas = "data.json";
$dataJson = json_encode($dataPesanan, JSON_PRETTY_PRINT);
file_put_contents($file, $dataJson);
$dataJson = file_get_contents($file, $dataJson);
$dataPesanan = json_decode($dataJson, true);
foreach($dataPesanan as $key => $dataPesanan)
{
$tagihanAwal = hitung_tagihan_awal($dataPesanan['jumlahPesanan'], $hargaSatuan);
$diskon = 0;
if($tagihanAwal>=1000000){
$diskon = (5/100) * $tagihanAwal;
}
$tagihanAkhir = $tagihanAwal - $diskon;
echo "
<h5>Data Pemesanan</h5>
<hr/>
<div class='table'>
<div class='row'>
<div class='col-lg-2'>Cabang:</div>
<div class='col-lg-2'>".$dataPesanan['cabang']."</div>
</div>
<div class='row'>
<div class='col-lg-2'>Nama Pelanggan:</div>
<div class='col-lg-2'>".$dataPesanan['nama']."</div>
</div>
<div class='row'>
<div class='col-lg-2'>Nomor HP:</div>
<div class='col-lg-2'>".$dataPesanan['noHP']."</div>
</div>
<div class='row'>
<div class='col-lg-2'>Jumlah Kotak:</div>
<div class='col-lg-2'>".$dataPesanan['jumlahPesanan']." box</div>
</div>
<div class='row'>
<div class='col-lg-2'>Tagihan Awal:</div>
<div class='col-lg-2'>Rp".number_format($tagihanAwal, 0, ".", ".").",-</div>
</div>
<div class='row'>
<div class='col-lg-2'>Diskon:</div>
<div class='col-lg-2'>Rp".number_format($diskon, 0, ".", ".").",-</div>
</div>
<div class='row'>
<div class='col-lg-2'>Tagihan Akhir:</div>
<div class='col-lg-2'>Rp".number_format($tagihanAkhir, 0, ".", ".").",-</div>
</div>
</div>
";
}
}
?>
</body>
</html>