Buat database dg nama : test_c_summary
a. Buat satu tabel dg nama transaksi
# | Name | Type |
---|---|---|
1 | no_trans | int(11) |
2 | tgl_trans | date |
Masukan Record Berikut:
no_trans | tgl_trans |
---|---|
1 | awal bulan ini |
2 | akhir bulan ini |
2 | awal bulan depan |
3 | akhir bulan depan |
Inputkan awal bulan besok dengan tgl awal bulan besok, misalkan bulan besok adalah bulan september maka awal bulan depan adalah 2015-09-01 , akhhir bulan depan adalah 2015-09-30
b. buat tabel detail
# | Name | Type |
---|---|---|
1 | no_trans | int(11) |
2 | item | varchar(11) |
3 | qty | int(11) |
3 | price | double |
Isi tabel detail:
no_trans | item | qty | price |
---|---|---|---|
1 | A01 | 2 | 150 |
1 | A02 | 5 | 250 |
2 | A01 | 1 | 150 |
3 | A02 | 2 | 250 |
4 | A01 | 1 | 150 |
Buat tampilan seperti berikut:
Ketentuan :
- Data yang tampil ada data / nomor transaksi (dari tanggal awal sampai akhir, tanpa filter)
- Harga avg harga adalah rata2 harga beli (untuk nomor transaksi yang tampil di tabel detail)
- Jumlah beli adalah banyaknya item yang dibeli (untuk nomor transaksi yang tampil di tabel detail)
- Total adalah harga*jumlah (untuk nomor transaksi yang tampil di tabel detail)
- Filter data data dilakukan dg menggunakan between, dari tgl awal sampai tgl akhir.
Source Code
<?php
$host="localhost";
$user="root";
$pass="";
$db="test_c_summary";
$koneksi=mysqli_connect($host,$user,$pass)or die(mysql_error());
mysqli_select_db($koneksi,$db);
?>
fungsi.php
<?php
function tgl ($parameter){
$tanggal = substr($parameter, 8, 2);
$bulan = substr($parameter, 5, 2);
$tahun = substr($parameter, 0, 2);
return $tanggal."/". $bulan. "/". $tahun;
}
?>
tampil.php
<?php
include "koneksi.php";
include "fungsi.php";
?>
<?php $avg=mysqli_query($koneksi,"SELECT AVG(price) AS rata2 FROM detail WHERE no_trans='1'");
$data=mysqli_fetch_array($avg);?>
<?php $sum=mysqli_query($koneksi,"SELECT SUM(qty) AS jml FROM detail WHERE no_trans='1'");
$data1=mysqli_fetch_array($sum);?>
<?php $total=mysqli_query($koneksi,"SELECT SUM(qty*price) as total FROM detail where no_trans='1'");
while($data2=mysqli_fetch_array($total)){?>
<?php $query = mysqli_query($koneksi,"SELECT * FROM transaksi ORDER BY no_trans,tgl_trans DESC");
while ($no_trans[]=mysqli_fetch_array($query)) ?>
<?php $query = mysqli_query($koneksi,"SELECT * FROM detail WHERE no_trans BETWEEN 2 and 4");
while($data[]=mysqli_fetch_array($query)) ?>
<?php $query = mysqli_query($koneksi,"SELECT * FROM detail WHERE no_trans BETWEEN 2 and 4");
while($data[]=mysqli_fetch_array($query))?>
<?php $query = mysqli_query($koneksi,"SELECT (qty*price) as kali FROM detail WHERE no_trans BETWEEN 2 and 4");
while($data1[]=mysqli_fetch_array($query))?>
<body>
<h1>Summary Faktur</h1>
Cari Dari Tgl : <input type="date" name="tgl_trans"><br>
Sampai Tgl: <input type="date"><br>
<input type="submit" value="Cari" name="tgl_trans"><br>
<table border="2" bordercolor=#0000CD>
<tr>
<td> No Trans </td>
<td> Tgl Trans </td>
<td> Avg Harga </td>
<td> Jumlah Beli </td>
<td> Total </td>
</tr>
<tr>
<td>
<?php echo $no_trans[0]['no_trans']; ?></td>
<td><?php echo tgl ($no_trans[0]['tgl_trans']);?></td>
<td><?php echo $data['rata2'];?></td>
<td><?php echo $data1['jml'];?></td>
<td><?php echo $data2['total'];}?></td>
</tr>
<tr>
<td><?php echo $no_trans[1]['no_trans']; ?></td>
<td><?php echo tgl ($no_trans[1]['tgl_trans']);?></td>
<td><?php echo $data[1]['price'];?></td>
<td><?php echo $data[1]['qty'];?></td>
<td><?php echo $data1[1]['kali'];?></td>
</tr>
<tr>
<td><?php echo $no_trans[2]['no_trans']; ?></td>
<td><?php echo tgl ($no_trans[2]['tgl_trans']);?></td>
<td><?php echo $data[2]['price'];?></td>
<td><?php echo $data[2]['qty'];?></td>
<td><?php echo $data1[2]['kali'];?></td>
</tr>
<tr>
<td><?php echo $no_trans[3]['no_trans']; ?></td>
<td><?php echo tgl ($no_trans[3]['tgl_trans']);?></td>
<td><?php echo $data[3]['price'];?></td>
<td><?php echo $data[3]['qty'];?></td>
<td><?php echo $data1[3]['kali'];?></td>
</tr>
<tr>
<td colspan="5"><h1>Grand Total :<?php $query = mysqli_query($koneksi,"SELECT SUM(qty*price) as hasil FROM detail");
while($data=mysqli_fetch_array($query)){ ?>
<?php echo $data['hasil'];
} ?></h1></td>
</tr>
</table>
</body>
0 comments:
Posting Komentar
Komen dong