Postingan lainnya
Menghitung otomatis dan langsung menambah baris baru dengan JQuery untuk kasir
Saya mau melakukan perhitungan secara otomatis dengan jquery, tapi karena masih belajar jquerynya tidak bisa jalan, kode seperti dibawah, mohon koreksinya
<div class="box">
<div class="box-header with-border">
<h3 class="box-title">Daftar Barang</h3>
</div>
<div class="box-body">
<table class="table table-bordered" id='Tabelbelibarang'>
<tr>
<th>#</th>
<th>Nama</th>
<th>Jenis</th>
<th>Jumlah</th>
<th>Harga Beli</th>
<th>Harga Jual</th>
<th>Retur</th>
<th>Total</th>
<th>Batal</th>
</tr>
<tr>
<td>1.</td>
<td><input type="text" class="form-control" name="jenis_barang" id="jenis_barang" placeholder="Nama Barang" ></td>
<td><?php echo form_error('id_kategori_barang') ?>
<select name="id_kategori_barang" class="form-control select2">
<?php
foreach ($jns_barang as $jns){
echo "<option value='$jns->id_kategori_barang'>$jns->jenis_barang</option>";
}
?>
</select>
</td>
<td><input type="number" class="form-control" name="jml_brg" id="jml_brg" placeholder="Jumlah Barang" ></td>
<td><input type="number" class="form-control" name="hrg_beli" id="hrg_beli" placeholder="Harga Beli Barang" ></td>
<td><input type="number" class="form-control" name="jenis_barang" id="jenis_barang" placeholder="Harga Jual Barang" ></td>
<td><?php
$style='class="form-control"';
echo form_dropdown('retur',$retur,'',$style);?></td>
<td><input type="number" class="form-control" name="tot_beli" id="tot_beli" disabled value=""></td>
</tr>
</table>
<br>
<div class="row">
<div class="col-md-6">
<button id='BarisBaru' type="button" class='btn btn-default'>Baris Baru</button>
</div>
</div>
</div>
<!-- /.box-body -->
<div class="box-footer clearfix">
<div class="row">
<div class="col-md-3" style="float:right; padding: 10px; display:block;">
<div class="form-group">
<label>Bayar</label>
<input type="number" class="form-control" name="jenis_barang" id="jenis_barang" placeholder="Jumlah Barang" >
<label>Diskon</label>
<input type="number" class="form-control" name="jenis_barang" id="jenis_barang" placeholder="Jumlah Barang" >
<label>Kurang</label>
<input type="number" class="form-control" name="jenis_barang" id="jenis_barang" placeholder="Jumlah Barang" >
</div>
<button id='BarisBaru' type="button" class='btn btn-default'>Simpan</button>
</div>
<div class="col-md-7" style="margin-top: 10px;">
<div class="callout callout-info" style="position: relative;top: 50%;">
<h4 id="total_semua">Total : Rp 0. </h4>
</div>
</div>
</div>
</div>
</div>
<script>
$ (document).ready(function(){
$('.jml_brg').keyup(function(){
subtot();
});
$('.tot_beli').change(function(){
subtot();
});
});
function subtot(){
var sum = 0;
$('#Tabelbelibarang tbody tr').each(function(){
var jml_brg = $(this).find('input[jml_brg]').val();
var harga_beli = $(this).find('.input[hrg_beli]').val();
var sub_total = (jml_brg*harga_beli)sum+harga_beli;
$(this).find('.total_semua').text(''+total_semua);
});
$('.total_semua').text(sum);
}
</script>
tampilan seperti ini
0
2 Jawaban:
mungkin tinggal buat variable total dengan nilai default 0, dan ketika ada tambah baris baru langsung di tambahkan saja harga nya kalau batal di kurang harganya
0