Gunakan Library:
https://drive.google.com/file/d/1kt6Py4ijXea_uKr_O0uQh6LrfLNJ7dFC/view?usp=sharing
Gunakan Script CRUDS Tabel BARANG
<?php
require_once 'XLS/vendor/autoload.php';
use Shuchkin\SimpleXLSX;
$tanggal=WKT(date("Y-m-d"));
$pro="simpan";
$status="Tersedia";
$nama_barang="";
$deskripsi="";
$keterangan="";
$gambar0="avatar.jpg";
$gambar="avatar.jpg";
?>
<script type="text/javascript">
function PRINT(pk){
win=window.open('barang/barang_print.php?pk='+pk,'win','width=1000, height=400, menubar=0, scrollbars=1, resizable=0, location=0, toolbar=0, status=0'); }
</script>
<script language="JavaScript">
function buka(url) {window.open(url, 'window_baru', 'width=800,height=600,left=320,top=100,resizable=1,scrollbars=1');}
</script>
<?php
$sql="select `id_barang` from `$tbbarang` order by `id_barang` desc";
$jum= getJum($conn,$sql);
$kd="BRG";
if($jum > 0){
$d=getField($conn,$sql);
$idmax=$d['id_barang'];
$urut=substr($idmax,3,2)+1;//01
if($urut<10){$idmax="$kd"."0".$urut;}
else{$idmax="$kd".$urut;}
}
else{$idmax="$kd"."01";}
$id_barang=$idmax;
?>
<?php
if(isset($_GET["pro"]) && $_GET["pro"]=="ubah"){
$id_barang=$_GET["kode"];
$sql="select * from `$tbbarang` where `id_barang`='$id_barang'";
$d=getField($conn,$sql);
$id_barang=$d["id_barang"];
$id_barang0=$d["id_barang"];
$nama_barang=$d["nama_barang"];
$deskripsi=$d["deskripsi"];
$gambar=$d["gambar"];
$gambar0=$d["gambar"];
$keterangan=$d["keterangan"];
$pro="ubah";
}
?>
<link rel="stylesheet" href="jsacordeon/jquery-ui.css">
<link rel="stylesheet" href="resources/demos/style.css">
<script src="jsacordeon/jquery-1.12.4.js"></script>
<script src="jsacordeon/jquery-ui.js"></script>
<script>
$( function() {
$( "#accordion" ).accordion({
collapsible: true
});
} );
</script>
<script type="text/javascript" src="jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
mode : "textareas",
theme : "advanced",
});
</script>
<div id="accordion">
<h4>Tambah Barang</h4>
<div>
<form name="import_export_form" method="post" action="" enctype="multipart/form-data">
<table width="60%">
<tr>
<td><label class="btn btn-dark">Pilih File Datalatih (.xls):</label>
<td><input type="file" id="excelfile" required name="excelfile" class="btn btn-light"/>
<td><input type="submit" id="import" value="IMPORT" name="IMPORT" class="btn btn-warning"/>
<td><a href="downloadgetfile.php?file=DataLatih.xlsx">
<input type="button" id="import" value="DOWNLOAD" name="Download" class="btn btn-success"/>
</a>
</tr>
</table>
</form><br>
<hr>
<?php
if(isset($_POST['IMPORT'])){
$filename = $_FILES['excelfile']['tmp_name'];
$nf = $_FILES['excelfile']['name'];
$n=0;
process($conn, "Truncate tb_barang");
process($conn, "Truncate tb_transaksi");
$sukses=0;
$tanggal0=date("Y-m-d");
$pelanggan0="";
$xlsx = new SimpleXLSX($filename);
if ( $xlsx->success() ) {
foreach( $xlsx->rows() as $r ) {
if(!empty($r[3]) && $n>1){
$tanggal = $r[0];//Tanggal
$pelanggan= $r[1];//Pelanggan
$nama_barang= $r[2];//Keterangan
$jumlah= $r[3];//Qty
$unit= $r[4];//Unit
$harga= $r[5];//Harga
$subtotal= $r[6];//subtotal
if($tanggal==""){$tanggal=$tanggal0;}
if($pelanggan==""){$pelanggan=$pelanggan0;}
$nama_barang = str_replace('\'', '', $nama_barang);
$nama_barang = str_replace("'", '', $nama_barang);
$nama_barang = str_replace('\"', '', $nama_barang);
$keterangan=$unit;
$deskripsi="Satuan $unit, Harga $harga";
$sqla="select `nama_barang` from `$tbbarang` where `nama_barang` like '%$nama_barang%'";
$juma= getJum($conn,$sqla);
if($juma <1){
$sql="select `id_barang` from `$tbbarang` order by `id_barang` desc";
$jum= getJum($conn,$sql);
$kd="BRG";
if($jum > 0){
$d=getField($conn,$sql);
$idmax=$d['id_barang'];
$urut=substr($idmax,3,2)+1;//01
if($urut<10){$idmax="$kd"."0".$urut;}
else{$idmax="$kd".$urut;}
}
else{$idmax="$kd"."01";}
$id_barang=$idmax;
$sql="INSERT INTO `$tbbarang` (
`id_barang` ,
`nama_barang` ,
`deskripsi` ,
`gambar` ,
`keterangan`
) VALUES (
'$id_barang',
'$nama_barang',
'$deskripsi',
'avatar.jpg',
'$keterangan'
)";
$simpan=process($conn,$sql);
}//blm ada
$tanggal0=$tanggal;
$pelanggan0=$pelanggan;
$sukses++;
echo "$sql<hr>";
$id_barang=getIDBarang($conn,$nama_barang);
$sql=" INSERT INTO `$tbtransaksi` (
`tanggal` ,
`id_barang` ,
`frekuensi` ,
`persediaan` ,
`pembelian` ,
`pemakaian` ,
`sisa` ,
`keterangan`
) VALUES (
'$tanggal',
'$id_barang',
'$jumlah',
'',
'',
'',
'',
'$pelanggan ($jumlah x Rp. $harga =RP. $subtotal)'
)";
$simpan=process($conn,$sql);
}
$n++;
}//for
echo "<script>alert('Import Data $nf Sebanyak $sukses Item berhasil disimpan... !');document.location.href='?mnu=barang';</script>";
} else {
echo 'xlsx error: '.$xlsx->error();
}
}//isset
?>
<form action="" method="post" enctype="multipart/form-data">
<table class="table table-bordered">
<tr>
<th width="180"><label for="id_barang">ID Barang</label>
<th width="12">:
<th colspan="2"><b><?php echo $id_barang;?></b></tr>
<tr>
<td><label for="nama_barang">Nama Barang</label>
<td>:<td width="458"><input required name="nama_barang" class="form-control" type="text" id="nama_barang" value="<?php echo $nama_barang;?>" size="25" />
</td>
</tr>
<tr>
<td height="24"><label for="deskripsi">Deskripsi</label>
<td>:<td><textarea name="deskripsi" cols="25" required="required" class="form-control" id="dekripsi"><?php echo $deskripsi;?></textarea></td>
</tr>
<tr>
<td height="24"><label for="gambar">Gambar</label>
<td>:<td colspan="2">
<input class="form-control" name="gambar" type="file" id="gambar" size="20" />
=> <a href='#' onclick='buka("barang/zoom.php?id=<?php echo $id_barang;?>")'><?php echo $gambar0;?></a></td>
</tr>
<tr>
<td height="24"><label for="keterangan">Keterangan</label>
<td>:<td>
<textarea name="keterangan" class="form-control" cols="55" rows="2"><?php echo $keterangan;?></textarea>
</td>
</tr>
<tr>
<td>
<td>
<td colspan="2">
<input name="Simpan" type="submit" id="Simpan" value="Simpan" />
<input name="pro" type="hidden" id="pro" value="<?php echo $pro;?>" />
<input name="gambar0" type="hidden" id="gambar0" value="<?php echo $gambar0;?>" />
<input name="id_barang" type="hidden" id="id_barang" value="<?php echo $id_barang;?>" />
<input name="id_barang0" type="hidden" id="id_barang0" value="<?php echo $id_barang0;?>" />
<a href="?mnu=barang"><input name="Batal" type="button" id="Batal" value="Batal" /></a>
</td></tr>
</table>
</form>
<br />
</div>
<h4>Data Barang :</h4>
<div>
| <img src='ypathicon/print.png' title='PRINT' OnClick="PRINT('<?php echo $status;?>')"> |
<br>
<table class="table table-bordered">
<tr bgcolor="#cccccc">
<th width="3%">No</td>
<th width="3%">IDBRG</td>
<th width="10%">Gambar</td>
<th width="30%">Nama Barang</td>
<th width="20%">Keterangan</td>
<th width="13%">Menu</td>
</tr>
<?php
$sql="select * from `$tbbarang` order by `id_barang` desc";
$jum=getJum($conn,$sql);
if($jum > 0){
//---------------------------
$batas = 10;
$page = 1;
if(isset($_GET['page'])){
$page = $_GET['page'];
}
if(empty($page)){$posawal = 0;$page = 1;}
else{$posawal = ($page-1) * $batas;}
$sql2 = $sql." LIMIT $posawal,$batas";
$no = $posawal+1;
//-------------------------------
$arr=getData($conn,$sql2);
foreach($arr as $d) {
$id_barang=$d["id_barang"];
$nama_barang=ucwords($d["nama_barang"]);
$deskripsi=$d["deskripsi"];
$gambar=$d["gambar"];
$gambar0=$d["gambar"];
$keterangan=$d["keterangan"];
$color="#dddddd";
if($no %2==0){$color="#eeeeee";}
echo"<tr bgcolor='$color'>
<td>$no</td>
<td><div align='center'>";
echo"<a href='#' onclick='buka(\"barang/zoom.php?id=$id_barang\")'>
<img src='$YPATH/$gambar' width='40' height='40' /></a></div>";
echo"</td>
<td>$id_barang</td>
<td><b>$nama_barang </b></td>
<td><small>$deskripsi <i>$keterangan</i></small></td>
<td><div align='center'>
<a href='?mnu=barang&pro=ubah&kode=$id_barang'><img src='ypathicon/ub.png' title='ubah'></a>
<a href='?mnu=barang&pro=hapus&kode=$id_barang&nama_barang=$nama_barang'><img src='ypathicon/ha.png' title='hapus'
onClick='return confirm(\"Apakah Anda benar-benar akan menghapus $nama_barang pada data barang ?..\")'></a></div></td>
</tr>";
$no++;
}//for dalam
}//if
else{echo"<tr><td colspan='6'><blink>Maaf, Data barang belum tersedia...</blink></td></tr>";}
?>
</table>
<?php
$jmldata = $jum;
if($jmldata>0){
if($batas<1){$batas=1;}
$jmlhal = ceil($jmldata/$batas);
echo "<div class=paging>";
if($page > 1){
$prev=$page-1;
echo "<span class=prevnext><a href='$_SERVER[PHP_SELF]?page=$prev&mnu=barang'>« Prev</a></span> ";
}
else{echo "<span class=disabled>« Prev</span> ";}
for($i=1;$i<=$jmlhal;$i++)
if ($i != $page){echo "<a href='$_SERVER[PHP_SELF]?page=$i&mnu=barang'>$i</a> ";}
else{echo " <span class=current>$i</span> ";}
if($page < $jmlhal){
$next=$page+1;
echo "<span class=prevnext><a href='$_SERVER[PHP_SELF]?page=$next&mnu=barang'>Next »</a></span>";
}
else{ echo "<span class=disabled>Next »</span>";}
echo "</div>";
}//if jmldata
$jmldata = $jum;
echo "<p align=center>Total data <b>$jmldata</b> item</p>";
echo"</div>";
?>
</div>
<?php
if(isset($_POST["Simpan"])){
$pro=strip_tags($_POST["pro"]);
$id_barang=strip_tags($_POST["id_barang"]);
$id_barang0=strip_tags($_POST["id_barang0"]);
$nama_barang=strip_tags($_POST["nama_barang"]);
$deskripsi=$_POST["deskripsi"];
$gambar0=strip_tags($_POST["gambar0"]);
if ($_FILES["gambar"] != "") {
move_uploaded_file($_FILES["gambar"]["tmp_name"],"$YPATH/".$_FILES["gambar"]["name"]);
$gambar=$_FILES["gambar"]["name"];
}
else {$gambar=$gambar0;}
if(strlen($gambar)<1){$gambar=$gambar0;}
$keterangan=$_POST["keterangan"];
if($pro=="simpan"){
$sql=" INSERT INTO `$tbbarang` (
`id_barang` ,
`nama_barang` ,
`deskripsi` ,
`gambar` ,
`keterangan`
) VALUES (
'$id_barang',
'$nama_barang',
'$deskripsi',
'$gambar',
'$keterangan'
)";
$simpan=process($conn,$sql);
if($simpan) {echo "<script>alert('Data $nama_barang berhasil disimpan !');document.location.href='?mnu=barang';</script>";}
else{echo"<script>alert('Data $nama_barang gagal disimpan...');document.location.href='?mnu=barang';</script>";}
}
else{
$sql="update `$tbbarang` set
`nama_barang`='$nama_barang',
`deskripsi`='$deskripsi',
`gambar`='$gambar' ,
`keterangan`='$keterangan'
where `id_barang`='$id_barang0'";
$ubah=process($conn,$sql);
if($ubah) {echo "<script>alert('Data $nama_barang berhasil diubah !');document.location.href='?mnu=barang';</script>";}
else{echo"<script>alert('Data $nama_barang gagal diubah...');document.location.href='?mnu=barang';</script>";}
}//else simpan
}
?>
<?php
if(isset($_GET["pro"]) && $_GET["pro"]=="hapus"){
$id_barang=$_GET["kode"];
$nama_barang=$_GET["nama_barang"];
$sql="delete from `$tbbarang` where `id_barang`='$id_barang'";
$hapus=process($conn,$sql);
if($hapus) {echo "<script>alert('Data $nama_barang berhasil dihapus !');document.location.href='?mnu=barang';</script>";}
else{echo"<script>alert('Data $nama_barang gagal dihapus...');document.location.href='?mnu=barang';</script>";}
}
?>
Tidak ada komentar:
Posting Komentar