Untuk postingan kali ini kami akan membahas mengenai Menu User Admin, dimana pada menu user admin ini terdapat sub2 menu :
1. Tambah Data Barang
2. Update Harga Jual
Sebelum Mulai Siapin dulu seangkikr kopi, :D
Kita lanjut dengan pokok bahasan pertama (Tambah Data Barang), Pada postingan sebelumnya kita telah membahas mengenai Menu Insert dan Edit User. Yang memverivikasi user tersebut kelaknya akan login sebagai Hash apa agar seuai dengan kepentingan user tersebut.
1. Tambah Data Barang
Pada menu Tambah Data Barang ini kita akan membuat sebuah form input dan juga import data dari data exel. Download terlebih dahulu file excel rider disini. Setelah di download extract file tersebut,
Pada menu Tambah Data Barang ini kita akan membuat sebuah form input dan juga import data dari data exel. Download terlebih dahulu file excel rider disini. Setelah di download extract file tersebut,
kemudian buat folder admin di dalam folder pages yang telah ada sebelumnya dan pastekan file excel_reader.php yang di extract tadi.
Selanjutnya ketikan kode berikut :
Simpan dengan nama entry.php pada folder admin.
Kemudian ketik kode berikut :
Kode diatas merupakan kode untuk import data dengan file excel (.xls). Simpan kode diatas dengan nama import.php pada folder admin.
Ketik kode berikut :
Kode diatas merupakan kode yang berfunsi sebagai edti data barang. dan simpan dengan nama barangedit.php pada folder admin.
dan pada file _main-nav.php cari potongan kode berikut :
Ubah dengan :
Maka ketika di jalankan akan tampil seperti berikut :
ketika di klik logo Excel (import excel) maka akan muncul form baru sepeti berikut :
disini kita upload file excel dengan format .xls :
2. Update Harga Jual
Ketikan kode berikut :
Kode diatas berfungsi untuk menampilkan data barang dan harga barang, simpan dengan nama harga.php.
Ketikan kode berikut :
Kode diatas berfungsi untuk menambahkan atau edit harga barang, simpan dengan nama hargaedit.php.
ketika logo pencil pada field Action di klik maka akan muncul seperti berikut ;
Sekarang kita dapat input dan edit harga barang sesuai dengan yang kita inginkan.
Sekian dulu postingan kali ini. Simak terus Postingan2 selanjutnya, terima kasih.
NB : Source code dalam artikel yang berkelanjutan ini akan kami dokumentasikan, dan kami share link downloadnya di akhir project.
Selanjutnya ketikan kode berikut :
<?php
ob_start();
?>
<script src="js/jquery-ui.js"></script>
<h2>Tambah Data Barang</h2>
<form name="form1" method="post" action="" autocomplete="on">
<table width="50%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<td>PLU: </td>
<td><input type="text" name="BRG_PLU" id="BRG_PLU"></td>
<td>Barcode: </td>
<td><input type="text" name="BRG_BARCODE" id="BRG_BARCODE"></td>
</td>
</tr>
<tr>
<td>
<td>Deskripsi Panjang: </td>
<td><input type="text" name="BRG_DESK" id="BRG_DESK"></td>
<td>Deskripsi Pendek: </td>
<td><input type="text" name="BRG_DESKP" id="BRG_DESKP"></td>
</td>
</tr>
<tr>
<td>
<td>Frac: </td>
<td><input type="text" name="BRG_FRAC" id="BRG_FRAC"></td>
<td>Unit: </td>
<td>
<select name="BRG_UNIT" id="BRG_UNIT">
<option value="PCS">PCS</option>
<option value="CTN">CTN</option>
<option value="KG">KG</option>
<option value="RCG">RCG</option>
<option value="BAL">BAL</option>
<option value="SAK">SAK</option>
<option value="SLP">SLP</option>
</select>
</td>
</td>
</tr>
<tr>
<td> </td>
<td><p></p><input type="submit" class="btn btn-primary" name="button" id="button" value="Tambah"></td>
<td> </td>
<td><a href="?cat=admin&page=IMPORT"><img src="img/excel.ico"/>IMPORT_DATA</a></td>
</tr>
</table>
</form>
<?php
ob_end_flush();
?>
<!----------------------------------------------------------------------------------------------------------------------------------------->
<form name="form1" method="POST" action="" autocomplete="on">
<table width="50%" border="0" cellspacing="0" cellpadding="0">
<h3>Data BARANG</h3>
<tr>
<td>CARI : <input type="text" name="cari" id="cari"><input type="submit" class="btn btn-primary" value="CARI"></td>
</tr>
</table>
</form>
<form name="form1" method="POST" action="?cat=admin&page=admin&act=1">
<span >
<table width="100%" border="1" cellspacing="1" cellpadding="1" class="table table-striped">
<td>PLU</td>
<td>DESK</td>
<td>FRAC</td>
<td>UNIT</td>
<td>BARCODE</td>
<td colspan=2>Action</td>
<?php
if(isset($_POST['cari']))
{
$cari = $_POST['cari'];
$data=mysql_query(("select * from TABEL_BARANG
where BRG_PLU='".$cari."' OR BRG_DESK = '".$cari."' order by BRG_PLU asc")) or die(mysql_error());
}
else{
$data = mysql_query("select * from TABEL_BARANG order by BRG_PLU asc ");
}
$no = 1;
while($d = mysql_fetch_array($data)){
?>
<tr>
<td><?php echo $d['BRG_PLU']; ?></td>
<td><?php echo $d['BRG_DESK']; ?></td>
<td><?php echo $d['BRG_FRAC']; ?></td>
<td><?php echo $d['BRG_UNIT']; ?></td>
<td><?php echo $d['BRG_BARCODE']; ?></td>
<td><a href="?cat=admin&page=barangedit&id=<?php echo ($d['BRG_PLU']); ?>"><img src="img/edit.png"/></a></td>
<td><a href="?cat=admin&page=entry&del=1&id=<?php echo ($d['BRG_PLU']); ?>"><img src="img/delete.png"/></a></td>
</tr>
<?php
}
?>
</table>
</span>
</form>
<?php
if(isset($_POST['button']))
{
$newDate = date("Y-m-d H:i:s");
$USER = $_SESSION['login_user'];
//$newDate = date("Y-m-d", strtotime($_POST['BRG_TGL_CREATE']));
$q=mysql_query("INSERT INTO `POS`.`tabel_barang` (`BRG_PLU` ,`BRG_DESK`,`BRG_DESKP` ,`BRG_FRAC`,`BRG_UNIT` ,`BRG_BARCODE`)
VALUES ('".$_POST['BRG_PLU']."','".$_POST['BRG_DESK']."','".$_POST['BRG_DESKP']."','".$_POST['BRG_FRAC']."','".$_POST['BRG_UNIT']."',
'".$_POST['BRG_BARCODE']."')") or die(mysql_error());
if($q)
{ //ST_CREATE_BY ST_CREATE_DT ST_MODIFY_BY ST_MODIFY_DT
$q1=mysql_query("INSERT INTO `POS`.`tabel_stock` (`ST_PLU` ,`ST_QTY_AWAL`,`ST_QTY_AKHIR`,`ST_ACOST`,`ST_ACOST_LAMA`,
`ST_CREATE_BY`,`ST_CREATE_DT`,`ST_MODIFY_BY`,`ST_MODIFY_DT`)
VALUES ('".$_POST['BRG_PLU']."','','','','','".$USER."', '".$newDate."','','')") or die(mysql_error());
if($q1)
{
echo "<script>window.location='?cat=admin&page=entry'</script>";
}
}
}
?>
<!----------------------------------------------------------------------------------------------------------------------------------------->
<?php
if(isset($_GET['del']))
{
$ids=$_GET['id'];
$ff=mysql_query("Delete from tabel_barang Where (BRG_PLU)='".$ids."'");
if($ff)
{
echo "<script>window.location='?cat=admin&page=entry'</script>";
}
}
?>
Simpan dengan nama entry.php pada folder admin.
Kemudian ketik kode berikut :
<?php
ob_start();
?>
<?php
//memanggil file excel_reader
require "excel_reader.php";
//jika tombol import ditekan
if(isset($_POST['submit'])){
$target = basename($_FILES['filebarang']['name']) ;
move_uploaded_file($_FILES['filebarang']['tmp_name'], $target);
$data = new Spreadsheet_Excel_Reader($_FILES['filebarang']['name'],false);
// menghitung jumlah baris file xls
$baris = $data->rowcount($sheet_index=0);
// jika kosongkan data dicentang jalankan kode berikut
$drop = isset( $_POST["drop"] ) ? $_POST["drop"] : 0 ;
if($drop == 1){
// kosongkan tabel pegawai
$truncate ="TRUNCATE TABLE tabel_barang";
mysql_query($truncate);
};
// import data excel mulai baris ke-2 (karena tabel xls ada header pada baris 1)
for ($i=2; $i<=$baris; $i++)
{
// membaca data (kolom ke-1 sd terakhir)
$BRG_PLU = $data->val($i, 1);
$BRG_DESK = $data->val($i, 2);
$BRG_DESKP = $data->val($i, 3);
$BRG_FRAC = $data->val($i, 4);
$BRG_UNIT = $data->val($i, 5);
$BRG_BARCODE= $data->val($i, 6);
$newDate = date("Y-m-d H:i:s");
$USER = $_SESSION['login_user'];
// setelah data dibaca, masukkan ke tabel pegawai sql
$query = "INSERT into tabel_barang (BRG_PLU,BRG_DESK,BRG_DESKP,BRG_UNIT,BRG_FRAC,BRG_BARCODE)
values('$BRG_PLU','$BRG_DESK','$BRG_DESKP','$BRG_UNIT','$BRG_FRAC','$BRG_BARCODE')";
$hasil = mysql_query($query);
$query2 = "INSERT INTO `POS`.`tabel_stock` (`ST_PLU` ,`ST_QTY_AWAL`,`ST_QTY_AKHIR`,`ST_ACOST`,`ST_ACOST_LAMA`,
`ST_CREATE_BY`,`ST_CREATE_DT`,`ST_MODIFY_BY`,`ST_MODIFY_DT`)
VALUES ('".$_POST['BRG_PLU']."','','','','','".$USER."', '".$newDate."','','')";
$hasil2 = mysql_query($query2);
}
if(!$hasil){
// jika import gagal
die(mysql_error());
}else{
// jika impor berhasil
echo "Data berhasil diimpor.";
}
// hapus file xls yang udah dibaca
unlink($_FILES['filebarang']['name']);
}
?>
<script src="js/jquery-ui.js"></script>
<h2>IMPORT Data Barang</h2>
<?php
ob_end_flush();
?>
<form name="myForm" id="myForm" onSubmit="return validateForm()" action="?cat=admin&page=admin&page=import" method="post" enctype="multipart/form-data"> --->
<input type="file" id="filebarang" name="filebarang" />
<input type="submit" name="submit" value="Import" /><br/>
<label><input type="checkbox" name="drop" value="1" /> <u>Kosongkan DATA LAMA DULU.</u> </label>
</form>
<script type="text/javascript">
// validasi form (hanya file .xls yang diijinkan)
function validateForm()
{
function hasExtension(inputID, exts) {
var fileName = document.getElementById(inputID).value;
return (new RegExp('(' + exts.join('|').replace(/\./g, '\\.') + ')$')).test(fileName);
}
if(!hasExtension('filebarang', ['.xls'])){
alert("Hanya file XLS (Excel 2003) yang diijinkan.");
return false;
}
}
</script>
<form name="form1" method="POST" action="?cat=admin&page=admin&act=1">
<span >
<table width="100%" border="1" cellspacing="1" cellpadding="1" class="table table-striped">
<td>PLU</td>
<td>DESK</td>
<td>DESK PEND</td>
<td>FRAC</td>
<td>UNIT</td>
<td>BARCODE</td>
<td colspan=2>Action</td>
<?php
if(isset($_POST['cari']))
{
$cari = $_POST['cari'];
$data=mysql_query(("select * from TABEL_BARANG
where BRG_PLU='".$cari."' OR BRG_DESK like '%".$cari."%' order by BRG_PLU asc")) or die(mysql_error());
}
else{
$data = mysql_query("select * from TABEL_BARANG order by BRG_PLU asc ");
}
$no = 1;
while($d = mysql_fetch_array($data)){
?>
<tr>
<td><?php echo $d['BRG_PLU']; ?></td>
<td><?php echo $d['BRG_DESK']; ?></td>
<td><?php echo $d['BRG_DESKP']; ?></td>
<td><?php echo $d['BRG_FRAC']; ?></td>
<td><?php echo $d['BRG_UNIT']; ?></td>
<td><?php echo $d['BRG_BARCODE']; ?></td>
<td><a href="?cat=admin&page=BARANGEDIT&id=<?php echo ($d['BRG_PLU']); ?>"><img src="img/edit.png"/></a></td>
<td><a href="?cat=admin&page=entry&del=1&id=<?php echo ($d['BRG_PLU']); ?>"><img src="img/delete.png"/></a></td>
</tr>
<?php
}
?>
</table>
</span>
</form>
<?php
if(isset($_GET['act']))
{
$rs=mysql_query("Insert into jenis_barang (`JNS_KODE`,`JNS_NAMA`) values ('".$_POST['JNS_KODE']."','".md5($_POST['JNS_NAMA'])."','".$_POST['jenis']."')") or die(mysql_error());
if($rs)
{
echo "<script>window.location='?cat=admin&page=admin'</script>";
}
}
?>
<?php
if(isset($_GET['del']))
{
$ids=$_GET['id'];
$ff=mysql_query("Delete from barang Where sha1(BRG_PLU)='".$ids."'");
if($ff)
{
echo "<script>window.location='?cat=admin&page=entry'</script>";
}
}
?>
<!----------------------------------------------------------------------------------------------------------------------------------------->
<?php
if(isset($_POST['button']))
{
//$newDate = date("Y-m-d", strtotime($_POST['BRG_TGL_CREATE']));
$q=mysql_query("INSERT INTO `bazar`.`tabel_barang` (`BRG_PLU` ,`BRG_DESK` ,`BRG_UNIT` ,`BRG_FRAC`)
VALUES ('".$_POST['BRG_PLU']."','".$_POST['BRG_DESK']."','".$_POST['BRG_UNIT']."','".$_POST['BRG_FRAC']."')") or die(mysql_error());
if($q)
{
echo "<script>window.location='?cat=admin&page=entry'</script>";
}
}
?>
Kode diatas merupakan kode untuk import data dengan file excel (.xls). Simpan kode diatas dengan nama import.php pada folder admin.
Ketik kode berikut :
<?php
ob_start();
if(isset($_GET['id']))
{
$rs=mysql_query("
SELECT * FROM `tabel_barang` where BRG_PLU='".$_GET['id']."'
");
?>
<form name="form1" method="post" action="?cat=admin&page=barangedit&id=<?php echo $_GET['id']; ?>&edit=1">
<span >
<table width="100%" border="1" cellspacing="1" cellpadding="1" class="table table-striped">
<tr>
<td>PLU</td>
<td>DESK Panjang</td>
<td>DESK Pendek</td>
<td>UNIT</td>
<td>FRAC</td>
<td>BARCODE</td>
</tr>
<?php
while($row = mysql_fetch_array($rs))
{
?>
<tr>
<td><input style="width:50px;" type="textAREA" name="BRG_PLU" id="BRG_PLU" value="<?php echo $row['BRG_PLU']; ?>" ></td>
<td><input style="width:250px;" type="textAREA" name="BRG_DESK" id="BRG_DESK" value="<?php echo $row['BRG_DESK']; ?>"></td>
<td><input style="width:250px;" type="textAREA" name="BRG_DESKP" id="BRG_DESKP" value="<?php echo $row['BRG_DESKP']; ?>" ></td>
<td><select style="width:70px;" name="BRG_UNIT" id="BRG_UNIT">
<option value="PCS">PCS</option>
<option value="CTN">CTN</option>
<option value="KG">KG</option>
<option value="RCG">RCG</option>
<option value="BAL">BAL</option>
<option value="SAK">SAK</option>
<option value="SLP">SLP</option>
</select>
</td>
<td><input style="width:45px;" type="textAREA" name="BRG_FRAC" id="BRG_FRAC" value="<?php echo $row['BRG_FRAC']; ?>" ></td>
<td><input style="width:100px;" type="textAREA" name="BRG_BARCODE" id="BRG_BARCODE" value="<?php echo $row['BRG_BARCODE']; ?>" ></td>
</tr>
<?php
}
?>
<tr>
<td> </td>
<td colspan='2'>
<input type="submit" class="btn btn-primary" name="button" id="button" value="UPDATE">
<input type="button" class="btn btn-danger" name="reset" id="reset" value="Cancel" onclick="window.location='?cat=admin&page=entry'">
</td>
</tr>
</table>
</span>
</form>
<?php
}
?>
<?php
if(isset($_GET['edit']))
{
$BRG_PLU = $_POST['BRG_PLU'];
$BRG_DESK = $_POST['BRG_DESK'];
$BRG_DESKP = $_POST['BRG_DESKP'];
$BRG_UNIT = $_POST['BRG_UNIT'];
$BRG_FRAC = $_POST['BRG_FRAC'];
$BRG_BARCODE = $_POST['BRG_BARCODE'];
$newDate = date("Y-m-d H:i:s");
$USER = $_SESSION['login_user'];
$rs=mysql_query("Update `POS`.`tabel_stock` set ST_PLU='".$BRG_PLU."', ST_MODIFY_BY='".$USER."', ST_MODIFY_DT='".$newDate."'
WHERE ST_PLU='".$_GET['id']."'");
if($rs)
{
$q1=mysql_query("Update tabel_barang SET BRG_PLU='".$BRG_PLU."', BRG_DESK='".$BRG_DESK."',BRG_DESKP='".$BRG_DESKP."',
BRG_UNIT='".$BRG_UNIT."',BRG_FRAC='".$BRG_FRAC."',BRG_BARCODE='".$BRG_BARCODE."'
WHERE BRG_PLU='".$_GET['id']."'
") or die(mysql_error());
if($q1)
{
echo "<script>window.location='?cat=admin&page=entry'</script>";
}
}
}
?>
Kode diatas merupakan kode yang berfunsi sebagai edti data barang. dan simpan dengan nama barangedit.php pada folder admin.
dan pada file _main-nav.php cari potongan kode berikut :
<!--MENU admin-->
<?php
if($_SESSION['login_hash']=="admin")
{
?>
<li class="dropdown"><a href="#"><span class="icon-th-list"></span>MENU A</a>
<ul>
<li><a href="#"><span class="icon-pencil"></span>SUB MENU 1A</a></li>
<li><a href="#"><span class="icon-pencil"></span>SUB MENU 2A</a></li>
</ul>
</li>
<li class="dropdown"><a href="#"><span class="icon-th-list"></span>MENU B</a>
<ul>
<li><a href="#"><span class="icon-pencil"></span>SUB MENU 1B</a></li>
<li><a href="#"><span class="icon-pencil"></span>SUB MENU 2B</a></li>
</ul>
</li>
Ubah dengan :
<!--MENU admin-->
<?php
if($_SESSION['login_hash']=="admin")
{
?>
<li class="dropdown"><a href="#"><span class="icon-th-list"></span>Master</a>
<ul>
<li><a href="?cat=admin&page=entry"><span class="icon-pencil"></span>Input Data Barang</a></li>
<li><a href="#"><span class="icon-pencil"></span>SUB MENU 2A</a></li>
</ul>
</li>
<li class="dropdown"><a href="#"><span class="icon-th-list"></span>MENU B</a>
<ul>
<li><a href="#"><span class="icon-pencil"></span>SUB MENU 1B</a></li>
<li><a href="#"><span class="icon-pencil"></span>SUB MENU 2B</a></li>
</ul>
</li>
Maka ketika di jalankan akan tampil seperti berikut :
ketika di klik logo Excel (import excel) maka akan muncul form baru sepeti berikut :
2. Update Harga Jual
Pada menu Upate Harga Jual ini kita akan membuat form update harga jaul pada tabel tabel_harga dengan mekanisme dimana ketika pada tabel tabel_harga belum terdapat item yang akan di edit maka datanya akan di insertkan jika ada maka harga akan di update.
<?php
ob_start();
?>
<script src="js/jquery-ui.js"></script>
<h2>Update Harga Barang</h2>
<?php
ob_end_flush();
?>
<!----------------------------------------------------------------------------------------------------------------------------------------->
<form name="form1" method="POST" action="" autocomplete="on">
<table width="50%" border="0" cellspacing="0" cellpadding="0">
<h3>Data BARANG</h3>
<tr>
<td>CARI : <input type="text" name="cari" id="cari"><input type="submit" class="btn btn-primary" value="CARI"></td>
</tr>
</table>
</form>
<form name="form1" method="POST" action="?cat=admin&page=admin&act=1">
<span >
<table width="100%" border="1" cellspacing="1" cellpadding="1" class="table table-striped">
<td>PLU</td>
<td>DESK</td>
<td>FRAC</td>
<td>UNIT</td>
<td>ACOST</td>
<td>HARGA JUAL</td>
<td colspan=2>Action</td>
<?php
if(isset($_POST['cari']))
{
$cari = $_POST['cari']; //HRG_PLU HRG_HARGA_LAMA HRG_HARGA_BARU HRG_CREATE_DT HRG_CREATE_BY HRG_MODIFY_DT HRG_MODIFY_BY
$data=mysql_query(("select * from TABEL_BARANG LEFT JOIN tabel_harga ON BRG_PLU=HRG_PLU
LEFT JOIN TABEL_STOCK ON BRG_PLU=ST_PLU
where BRG_PLU='".$cari."' OR BRG_DESK = '".$cari."' order by BRG_PLU asc")) or die(mysql_error());
}
else{
$data = mysql_query("select * from TABEL_BARANG LEFT JOIN tabel_harga ON BRG_PLU=HRG_PLU
LEFT JOIN TABEL_STOCK ON BRG_PLU=ST_PLU order by BRG_PLU asc ");
}
$no = 1;
while($d = mysql_fetch_array($data)){
?>
<tr>
<td><?php echo $d['BRG_PLU']; ?></td>
<td><?php echo $d['BRG_DESK']; ?></td>
<td><?php echo $d['BRG_FRAC']; ?></td>
<td><?php echo $d['BRG_UNIT']; ?></td>
<td><?php echo $d['ST_ACOST']; ?></td>
<td><?php echo $d['HRG_HARGA_BARU']; ?></td>
<td><a href="?cat=admin&page=hargaedit&id=<?php echo ($d['BRG_PLU']); ?>"><img src="img/edit.png"/></a></td>
</tr>
<?php
}
?>
</table>
</span>
</form>
Kode diatas berfungsi untuk menampilkan data barang dan harga barang, simpan dengan nama harga.php.
<?php
ob_start();
if(isset($_GET['id']))
{
$rs=mysql_query("
select * from TABEL_BARANG LEFT JOIN tabel_harga ON BRG_PLU=HRG_PLU
LEFT JOIN TABEL_STOCK ON BRG_PLU=ST_PLU
where BRG_PLU='".$_GET['id']."'
");
?>
<form name="form1" method="post" action="?cat=admin&page=hargaedit&id=<?php echo $_GET['id']; ?>&edit=1">
<span >
<table width="100%" border="1" cellspacing="1" cellpadding="1" class="table table-striped">
<tr>
<td>PLU</td>
<td>DESK</td>
<td>UNIT</td>
<td>FRAC</td>
<td>ACOST</td>
<td>HARGA LAMA</td>
<td>HARGA BARU</td>
</tr>
<?php
while($row = mysql_fetch_array($rs))
{
?>
<tr>
<td><input style="width:50px;" type="textAREA" name="BRG_PLU" id="BRG_PLU" value="<?php echo $row['BRG_PLU']; ?>" disabled="disabled"></td>
<td><input style="width:350px;" type="textAREA" name="BRG_DESK" id="BRG_DESK" value="<?php echo $row['BRG_DESK']; ?>"disabled="disabled"></td>
<td><input style="width:30px;" type="textAREA" name="UNIT" id="UNIT" value="<?php echo $row['BRG_UNIT']; ?>" disabled="disabled"></td>
<td><input style="width:30px;" type="textAREA" name="BRG_FRAC" id="BRG_FRAC" value="<?php echo $row['BRG_FRAC']; ?>" disabled="disabled"></td>
<td>Rp.<input style="width:80px;" type="textAREA" name="ST_ACOST" id="ST_ACOST" value="<?php echo $row['ST_ACOST']; ?>" disabled="disabled"></td>
<td>Rp.<input style="width:80px;" type="textAREA" name="HRG_HARGA_LAMA" id="HRG_HARGA_LAMA" value="<?php echo $row['HRG_HARGA_BARU']; ?>"disabled="disabled" ></td>
<td>Rp.<input style="width:60px;" type="text" name="HRG_HARGA_BARU" id="HRG_HARGA_BARU">
</tr>
<?php
}
?>
<tr>
<td> </td>
<td colspan='2'>
<input type="submit" class="btn btn-primary" name="button" id="button" value="UPDATE">
<input type="button" class="btn btn-danger" name="reset" id="reset" value="Cancel" onclick="window.location='?cat=admin&page=harga'">
</td>
</tr>
</table>
</span>
</form>
<?php
}
?>
<?php
if(isset($_GET['edit']))
{ //HRG_PLU HRG_HARGA_LAMA HRG_HARGA_BARU HRG_CREATEDT HRG_CREATE_BY HRG_MODIFY_DT HRG_MODIFY_BY
$BRG_PLU = $_POST['BRG_PLU'];
$HRG_HARGA_LAMA = $_POST['HRG_HARGA_LAMA'];
$HRG_HARGA_BARU = $_POST['HRG_HARGA_BARU'];
$newDate = date("Y-m-d H:i:s");
$USER = $_SESSION['login_user'];
$cek=mysql_query("
SELECT COUNT(HRG_PLU) ITEM, HRG_HARGA_BARU FROM tabel_harga
WHERE HRG_PLU='".$_GET['id']."' GROUP BY HRG_HARGA_BARU
");
while ($cek1=mysql_fetch_array($cek))
{
$cekx=$cek1[ITEM];
$h=$cek1[HRG_HARGA_BARU];
}
if ($cekx==0)
{
$rs=mysql_query("insert into tabel_harga (HRG_PLU,HRG_HARGA_LAMA,HRG_HARGA_BARU,HRG_CREATE_DT,HRG_CREATE_BY,HRG_MODIFY_DT,HRG_MODIFY_BY)
values('".$_GET['id']."','$HRG_HARGA_LAMA','$HRG_HARGA_BARU','$newDate','$USER','','')");
{
echo "<script>window.location='?cat=admin&page=harga'</script>";
}
}
else
{
$rsx=mysql_query("Update tabel_harga SET HRG_HARGA_BARU='".$HRG_HARGA_BARU."', HRG_HARGA_LAMA='".$h."', HRG_MODIFY_DT='".$newDate."',HRG_MODIFY_BY='".$USER."'
WHERE HRG_PLU='".$_GET['id']."'
");
{
echo "<script>window.location='?cat=admin&page=harga'</script>";
}
}
}
?>
Kode diatas berfungsi untuk menambahkan atau edit harga barang, simpan dengan nama hargaedit.php.
dan pada file _main-nav.php cari potongan kode berikut :
Ubah menjadi :
Maka ketika di jalankan akan tampil seperti berikut :
<!--MENU admin-->
<?php
if($_SESSION['login_hash']=="admin")
{
?>
<li class="dropdown"><a href="#"><span class="icon-th-list"></span>Master</a>
<ul>
<li><a href="?cat=admin&page=entry"><span class="icon-pencil"></span>Input Data Barang</a></li>
<li><a href="#"><span class="icon-pencil"></span>SUB MENU 2A</a></li>
</ul>
</li>
<li class="dropdown"><a href="#"><span class="icon-th-list"></span>MENU B</a>
<ul>
<li><a href="#"><span class="icon-pencil"></span>SUB MENU 1B</a></li>
<li><a href="#"><span class="icon-pencil"></span>SUB MENU 2B</a></li>
</ul>
</li>
Ubah menjadi :
<!--MENU admin-->
<?php
if($_SESSION['login_hash']=="admin")
{
?>
<li class="dropdown"><a href="#"><span class="icon-th-list"></span>Master</a>
<ul>
<li><a href="?cat=admin&page=entry"><span class="icon-pencil"></span>Input Data Barang</a></li>
<li><a href="?cat=admin&page=harga"><span class="icon-pencil"></span>Update Harga Jual</a></li>
</ul>
</li>
<li class="dropdown"><a href="#"><span class="icon-th-list"></span>MENU B</a>
<ul>
<li><a href="#"><span class="icon-pencil"></span>SUB MENU 1B</a></li>
<li><a href="#"><span class="icon-pencil"></span>SUB MENU 2B</a></li>
</ul>
</li>
Maka ketika di jalankan akan tampil seperti berikut :
Sekarang kita dapat input dan edit harga barang sesuai dengan yang kita inginkan.
Sekian dulu postingan kali ini. Simak terus Postingan2 selanjutnya, terima kasih.
NB : Source code dalam artikel yang berkelanjutan ini akan kami dokumentasikan, dan kami share link downloadnya di akhir project.