Assalamualaikum Warahmatullahi Wabarakatuh... mas Robby dan Mas Buchori dan teman2 PHPMU mohon bantuan koreksi dari script ini (tarif PDAM jika <10 m3 harga mengikuti 10m3 kalau diatas 10 maka 10x tarif1 dan sisanya di hitung tarif ke 2 ) pada line 186
var jumlah2 = $("#jumlah2");
if ((parseInt(total) - 10 ) >=0 <=10 );
{
((parseInt(total) - 10 ) * parseInt(tarif2));
} 0
if ((parseInt(total) - 10 ) <0);
{ 0;
}
else{
10 * parseInt(tarif2);
}
$("#jumlah2 ").val(jumlah2 );
script full
<?php
include "inc/koneksi.php";
include "inc/kode.php";
?>
<div class="panel panel-info">
<div class="panel-heading">
<b>Tambah Pemakaian</b>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-12">
<form method="POST" enctype="multipart/form-data">
<div class="form-group">
<label>ID Pemakaian</label>
<input class="form-control" type="text" name="id_pakai" value="<?php echo $format; ?>" />
</div>
<div class="form-group">
<label>Pelanggan</label>
<select name="id_pelanggan" id="id_pelanggan" class="form-control" required>
<option value=""></option>
<?php
// ambil data dari database
$query = "select * from tb_pelanggan where status='Aktif'";
?>
<option value="<?php echo $row['id_pelanggan'] ?>"><?php echo $row['id_pelanggan'] ?>| <?php echo $row['nama_pelanggan'] ?></option>
<?php
}
?>
</select>
</div>
<div class="form-group">
<label>Bulan</label>
<select name="id_bulan" id="id_bulan" class="form-control" required>
<option value="">-- Pilih Bulan --</option>
<?php
// ambil data dari database
$query = "select * from tb_bulan order by id_bulan asc";
?>
<option value="<?php echo $row['id_bulan'] ?>"> <?php echo $row['nama_bulan'] ?></option>
<?php
}
?>
</select>
</div>
<div class="form-group">
<label>Tahun</label>
<input type="number" class="form-control" min="2021" max="2030" name="tahun" value="2021" placeholder="Masukkan tahun"/>
</div>
<div class="form-group">
<label>Meteran Bulan Lalu</label>
<input type="text" name="awal" id="awal" class="form-control" placeholder="0" readonly="">
</div>
<div class="form-group">
<label>Meteran Bulan Ini</label>
<input type="text" name="akhir" id="akhir" class="form-control" placeholder="Meteran bulan ini">
</div>
<div class="form-group mb-0">
<label>Pemakaian (Bulan Ini - Bulan lalu)</label>
<input type="text" name="total" id="total" class="form-control" placeholder="Pemakaian bulan ini" readonly="" >
</div>
<div class="form-group mb-0">
<?php $sql_cek = "select l.tarif1, l.tarif2, l.tarif3 from tb_layanan l inner join tb_pelanggan p where l.id_layanan=p.id_layanan";
?>
<input type="text" class="form-control" name="tarif1" id="tarif1" value="<?php echo $data_cek['tarif1']; ?>" readonly=""/>
<input type="text" class="form-control" name="tarif2" id="tarif2" value="<?php echo $data_cek['tarif2']; ?>" readonly=""/>
<input type="text" class="form-control" name="tarif3" id="tarif3" value="<?php echo $data_cek['tarif3']; ?>" readonly=""/>
</div>
<div class="form-group mb-0">
<input type="hidden" name="harga" id="harga" class="form-control" readonly="">
</div>
<div class="form-group mb-0">
<input type="text" name="jumlah1" id="jumlah1" class="form-control" readonly="">
</div>
<div class="form-group mb-0">
<input type="text " name="jumlah2" id="jumlah2" class="form-control" readonly="">
</div>
<div class="form-group mb-0">
<input type="text" name="jumlah3" id="jumlah3" class="form-control" readonly="">
</div>
<div>
<input type="submit" name="Simpan" value="Simpan" class="btn btn-success" >
</div>
</div>
</form>
</div>
</div>
</div>
</div>
<?php
if (isset ($_POST['Simpan'])){ //mulai proses simpan data
$sql_simpan = "INSERT INTO tb_pakai (id_pakai, id_pelanggan, bulan, tahun, awal, akhir, pakai) VALUES (
'".$_POST['id_pakai']."',
'".$_POST['id_pelanggan']."',
'".$_POST['id_bulan']."',
'".$_POST['tahun']."',
'".$_POST['awal']."',
'".$_POST['akhir']."',
'".$_POST['total']."');";
$sql_simpan .= "INSERT INTO tb_tagihan (id_pakai, tagihan) VALUES (
'".$_POST['id_pakai']."',
'".$_POST['harga']."')";
if ($query_simpan)
{
echo "<script>
Swal.fire({title: 'Simpan Berhasil',text: '',icon: 'success',confirmButtonText: 'OK'
}).then((result) => {
if (result.value) {
window.location = 'r1.php?halaman=pakai_tampil';
}})</script>";
}else{
echo "<script>
Swal.fire({title: 'Simpan Gagal',text: '',icon: 'error',confirmButtonText: 'OK'
}).then((result) => {
if (result.value) {
window.location = 'r1.php?halaman=pakai_tambah';
}})</script>";
}
//selesai proses simpan data
}
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
$('#id_pelanggan').change(function(){
var id_pelanggan = $(this).val();
$.ajax({
url:"super/pakai/proses-ajax.php",
method:"POST",
data:{id_pelanggan:id_pelanggan},
success:function(data){
$('#awal').val(data);
}
});
});
});
</script>
<script type="text/javascript" src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$("#akhir, #awal").keyup(function() {
var awal = $("#awal").val() || 0;
var akhir = $("#akhir").val();
var total = parseInt(akhir) - parseInt(awal) ;
$("#total").val(total);
var tarif1 = $("#tarif1").val();
var tarif2 = $("#tarif2").val();
var tarif3 = $("#tarif3").val();
var jumlah1 = 10 * parseInt(tarif1);
$("#jumlah1").val(jumlah1);
var jumlah2 = $("#jumlah2");
if ((parseInt(total) - 10 ) >=0 <=10 );
{
((parseInt(total) - 10 ) * parseInt(tarif2));
} 0
if ((parseInt(total) - 10 ) <0);
{ 0;
}
else{
10 * parseInt(tarif2);
}
$("#jumlah2 ").val(jumlah2 );
//var jumlah2 = parseInt(total2) * parseInt(tarif2);
// $("#jumlah2").val(jumlah2);
var jumlah3 = (parseInt(total) - 20) * parseInt(tarif3);
$("#jumlah3").val(jumlah3);
var harga = parseInt(jumlah1) + parseInt(jumlah2);
$("#harga").val(harga);
});
});
</script>