Monday, November 11, 2019

(Part 5) Membangun Aplikasi Kasir atau Point of Sales (POS) Dengan PHP dan MYSQL (Menu User Gudang)

Pada Postingan kali ini kita akan membahas mengenai pembuatan untuk Menu User Gudang. Dimana pada Menu User Gudang ini terdapat Sub Menu Penerimaan Barang, dimana ketika User degnan login Hash nya sebagai GUDANG akan diarahkan pada menu ini.
Langka2 yang harus kita lakukan terlebih dahulu yaitu membuat folder Gudang di dalam folder Pages seperti pada postingan sebelumnya Menus User Admin. Selanjutnya Ketikan kode berikut :

<?php ob_start(); ?> <script src="js/jquery-ui.js"></script> <h2>PENERIMAAN BARANG</h2> <!-----------------------------------------------------------------------------------------------------------------------------------------> <form name="form1" method="POST" action="" autocomplete="on"> <table width="50%" border="0" cellspacing="0" cellpadding="0"> <tr> <td>PLU : <input type="text" name="cari" id="cari"><input type="hidden" class="btn btn-primary" value=""></td> </tr> </table> </form> <form name="form1" method="POST" action="?cat=GUDANG&page=PENERIMAAN"> <span> <table width="100%" border="1" cellspacing="1" cellpadding="1" class="table table-striped"> <?php if(isset($_POST['cari'])) { $cari = $_POST['cari']; $data=mysql_query((" SELECT BRG_PLU, BRG_DESK, BRG_FRAC, BRG_UNIT, BRG_BARCODE, ST_QTY_AWAL, ST_QTY_AKHIR, ST_ACOST,ST_ACOST_LAMA FROM TABEL_BARANG LEFT JOIN TABEL_STOCK ON BRG_PLU=ST_PLU WHERE BRG_PLU ='".$cari."' OR BRG_BARCODE like '%".$cari."%' ")) or die(mysql_error()); } else{ } $no = 1; $d1 = mysql_query(" SELECT DISTINCT(TP_NODOC) FROM POS.TABEL_PENERIMAAN WHERE TP_TGL='".date('Y-m-d')."' ") or die(mysql_error()); $j1=mysql_num_rows($d1); $urut = $j1 + 1; if( $j1 >= 9) { $urut_doc = ''.date('ymd').'0'.$urut.''; //191110010 -191110099 } elseif( $j1 >= 99) { $urut_doc = ''.date('ymd').''.$urut.''; //191110100 - .... } else { $urut_doc = ''.date('ymd').'00'.$urut.''; //191110001 -191110009 } error_reporting(0); while($d = mysql_fetch_array($data)){ ?> <form name="form" method="post" action="?cat=gudang&page=penerimaan"> <tr> <td>DOC</td> <td>PLU</td> <td>DESK</td> <td>STOCK</td> <td>LACOST</td> <td>HARAG</td> <td>QTY TERIMA</td> </tr> <tr> <td><input style="width:65px;" type="textAREA" name="doc" id="doc" value="<?php echo $urut_doc ?>"disabled="disabled" ></td> <td><input style="width:55px;" type="textAREA" name="BRG_PLU" value="<?php echo $d['BRG_PLU']; ?>"disabled="disabled" ></td> <td><input style="width:350px;" type="textAREA" name="BRG_DESK" id="BRG_DESK" value="<?php echo $d['BRG_DESK']; ?>"disabled="disabled" ></td> <td><input style="width:50px;" type="textAREA" name="ST_QTY_AKHIR" id="ST_QTY_AKHIR" value="<?php echo $d['ST_QTY_AKHIR']; ?>"disabled="disabled" ></td> <td><input style="width:50px;" type="textAREA" name="ST_ACOST_LAMA" id="ST_ACOST_LAMA" value="<?php echo $d['ST_ACOST_LAMA']; ?>"disabled="disabled" ></td> <td><input style="width:60px;" type="text" name="harga" id="harga"></td> <td><input style="width:20px;" type="text" name="TAMBAH" id="TAMBAH"></td> <td> <input type="hidden" name="BRG_PLU" value="<?php echo $d['BRG_PLU']; ?>"> <input type="submit" class="btn btn-primary" name="button" id="button" value="TAMBAH"></td> </tr> </form> <?php } ?> </table> </span> </form> <table width="100%" border="1" cellspacing="1" cellpadding="1" class="table table-striped"> <tr> <td>NO.</td> <td>DOC</td> <td>PLU</td> <td>DESK</td> <td>STOCK</td> <td>HARGA</td> <td>QTY TERIMA</td> </tr> <?php $data = mysql_query("SELECT TEMP_NODOC, TEMP_PLU,brg_desk, TEMP_QTY, TEMP_HARGA_BELI,ST_QTY_AKHIR FROM TEMP_PENERIMAAN LEFT JOIN tabel_barang ON TEMP_PLU=brg_plu LEFT JOIN tabel_stock ON TEMP_PLU=ST_PLU"); $no = 1; while($d = mysql_fetch_array($data)){ ?> <tr> <td><?php echo $no++; ?></td> <td><?php echo $d['TEMP_NODOC']; ?></td> <td><?php echo $d['TEMP_PLU']; ?></td> <td><?php echo $d['brg_desk']; ?></td> <td><?php echo $d['ST_QTY_AKHIR'];?></td> <td><?php echo $d['TEMP_HARGA_BELI']; ?></td> <td><?php echo $d['TEMP_QTY'];?></td> </tr> <?php } ?> <!------- PROSES INSERT KE TABEL TEMP_PENERIMAAN KETIKA DI KLIK BUTTON TAMABAH------> <?php if(isset($_POST['button'])) { $d1 = mysql_query(" SELECT DISTINCT(TP_NODOC) FROM POS.TABEL_PENERIMAAN WHERE TP_TGL='".date('Y-m-d')."' ") or die(mysql_error()); $j1=mysql_num_rows($d1); $urut = $j1 + 1; if( $j1 >= 9) { $urut_doc = ''.date('ymd').'0'.$urut.''; //191110010 -191110099 } elseif( $j1 >= 99) { $urut_doc = ''.date('ymd').''.$urut.''; //191110100 - .... } else { $urut_doc = ''.date('ymd').'00'.$urut.''; //191110001 -191110009 } $TEMP_PLU = $_POST['BRG_PLU']; $harga = $_POST['harga']; $ST_QTY_AKHIR = $_POST['ST_QTY_AKHIR']; $newDate = date("Y-m-d H:i:s"); $USER = $_SESSION['login_user']; $TAMBAH = $_POST['TAMBAH']; if (($TAMBAH ==0) OR ($harga ==0)) { echo "<STRONG><h2><font color='#FF0000'>QTY ATAU HARGA TIDAK BOLEH KOSONG </font></h2></STRONG>"; } else { $q=mysql_query(" INSERT INTO `pos`.`TEMP_PENERIMAAN` (`TEMP_NODOC`,`TEMP_PLU` ,`TEMP_QTY`,`TEMP_HARGA_BELI`,`TEMP_TGL`,`TEMP_CREATE_BY`) VALUES ('".$urut_doc."','".$TEMP_PLU."','".$TAMBAH."','".$harga."','".$newDate."','".$USER."') ") or die(mysql_error()); if($q) { echo "<script>window.location='?cat=GUDANG&page=PENERIMAAN'</script>"; } } } ?> <!-------PROSES INSERT KE TABEL TEMP_PENERIMAAN KETIKA DI KLIK BUTTON SIMPAN----------> <form name="form" method="post" action="?cat=GUDANG&page=PENERIMAAN"> <tr> <td colspan='8'><input type="submit" class="btn btn-primary" name="SIMPAN" id="SIMPAN" value="SIMPAN"> </td> <?php if (isset($_POST['SIMPAN'])) //TEMP_NODOC, TEMP_PLU, TEMP_QTY, TEMP_HARGA_BELI, TEMP_TGL, TEMP_CREATE_BY { $rU=mysql_query("SELECT TEMP_NODOC, TEMP_PLU, TEMP_QTY, TEMP_HARGA_BELI, TEMP_TGL, TEMP_CREATE_BY, ST_QTY_AKHIR,ST_ACOST,ST_ACOST_LAMA, (ST_QTY_AWAL+TEMP_QTY) SET_QTYAWAL, (ST_QTY_AKHIR+TEMP_QTY) SET_QTYAKHIR FROM TEMP_PENERIMAAN LEFT JOIN TABEL_STOCK ON TEMP_PLU=ST_PLU"); while ($rR=mysql_fetch_array($rU)){ // Ubah format harga dengan fungsi number_format $TEMP_NODOC=$rR['TEMP_NODOC']; $TEMP_PLU=$rR['TEMP_PLU']; $SET_QTYAWAL=$rR['SET_QTYAWAL']; $SET_QTYAKHIR=$rR['SET_QTYAKHIR']; $TEMP_HARGA_BELI=$rR['TEMP_HARGA_BELI']; $ST_ACOST=$rR['ST_ACOST']; $newDate = date("Y-m-d H:i:s"); $USER = $_SESSION['login_user']; //ST_QTY_AWAL ST_QTY_AKHIR ST_ACOST ST_ACOST_LAMA ST_CREATE_BY ST_CREATE_DT ST_MODIFY_BY ST_MODIFY_DT $Z=mysql_query("UPDATE TABEL_STOCK SET ST_QTY_AWAL ='".$SET_QTYAWAL."', ST_QTY_AKHIR ='".$SET_QTYAKHIR."',ST_MODIFY_BY='".$USER."', ST_MODIFY_DT='".$newDate."', ST_ACOST='".$TEMP_HARGA_BELI."', ST_ACOST_LAMA='".$ST_ACOST."' WHERE ST_PLU='".$TEMP_PLU."' ") or die(mysql_error()); } if($Z) { $X=mysql_query("INSERT INTO tabel_penerimaan (SELECT * FROM temp_penerimaan)") or die(mysql_error()); if($X) { $ZX=mysql_query("TRUNCATE TABLE temp_penerimaan") or die(mysql_error()); if($ZX) { echo "<script>window.location='cetakBPB'</script>"; } } } } ?> </tr> </form> </table> <?php ob_end_flush(); ?>

Simpan dengan nama penerimaan.php pada folder gudang.
Selanjutnya Ketikan kode berikut :

<html> <head> <style type='text/css'> body { font-family: calibri; } table { border-collapse: collapse; } td { min-width: 0px; overflow-y: auto; overflow-x: hidden; } </style> </head> <body> <button onclick="myFunction()"><img src='img/Print.png'></button> <script src="js/jquery-ui.js"></script> <script> function myFunction() { window.print(); } </script> <!DOCTYPE HTML> <?php include("_db.php"); ?> <body> <?php //TP_NODOC TP_PLU TP_QTY TP_HARGA_BELI TP_TGL TP_CREATE_BY $d1 = mysql_query("SELECT SUM(TP_QTY*TP_HARGA_BELI) TTL, COUNT(TP_PLU) TITEM, MAX(TP_TGL) TGL, TP_CREATE_BY, TP_NODOC FROM tabel_penerimaan WHERE TP_NODOC IN (SELECT MAX(TP_NODOC) X FROM tabel_penerimaan) GROUP BY TP_CREATE_BY, TP_NODOC ") or die(mysql_error()); while($data = mysql_fetch_array($d1)){ $TP_TOTAL_HARGA=$data['TTL']; $hasilRP=number_format($TP_TOTAL_HARGA,0,",","."); $TITEM=$data['TITEM']; $TP_TGL=$data['TGL']; $TP_CREATE_BY=$data['TP_CREATE_BY']; $TP_NODOC=$data['TP_NODOC']; } echo" </tbody> </table> "; echo" <table border='0'> <thead> <tr> <td colspan=5> <strong><center><font size='2'>BUKTI PENERIMAAN BARANG<br> ".$TP_TGL." &nbsp NOBPB : ".$TP_NODOC." &nbsp ".$TP_CREATE_BY." </br> </font></center></strong> </td> </tr> <tr> <td colspan=5>---------------------------------------------------------------------------------------------------------------------------------------</td> </tr> </thead> </table> "; echo " <table border='0'> <thead> <tr> <td><font size='2'>ITEM</font></td> <td><font size='2'>DESKRIPSI</font></td> <td><font size='2'>QTY</font></td> <td><font size='2'>PRICE</font></td> <td><font size='2'>GROSS</font></td> </tr> <tr> <td colspan=5>---------------------------------------------------------------------------------------------------------------------------------------</td> </tr> </thead> <tbody> "; ////TP_NODOC TP_PLU TP_QTY TP_HARGA_BELI TP_TGL TP_CREATE_BY $data = mysql_query("SELECT TP_PLU,BRG_DESKP, TP_QTY,TP_HARGA_BELI, (TP_QTY*TP_HARGA_BELI) TTL, TP_TGL,TP_CREATE_BY,TP_NODOC FROM tabel_penerimaan LEFT JOIN tabel_barang ON TP_PLU=BRG_PLU WHERE TP_NODOC IN (SELECT MAX(TP_NODOC) X FROM tabel_penerimaan)"); $no = 1; while($d = mysql_fetch_array($data)){ $TP_HARGA_BELI=$d['TP_HARGA_BELI']; $TP_QTY=$d['TP_QTY']; $TP_HARGA_BELIRP=number_format($TP_HARGA_BELI,0,",","."); $TP_TOTAL_HARGA=$d['TTL']; $TP_TOTAL_HARGARP=number_format($TP_TOTAL_HARGA,0,",","."); ?> <tr> <td><font size="2"><?php echo $d['TP_PLU']; ?></font></br></td> <td><font size="2"><?php echo $d['BRG_DESKP']; ?> </font></br></td> <td><font size="2"><?php echo $d['TP_QTY'];?> </font></td> <td><font size="2"><?php echo "$TP_HARGA_BELIRP"?> </br></font></td> <td><font size="2"><br><?php echo "$TP_TOTAL_HARGARP" ?> </br></font></td> </tr> <?php } echo" <tr> <td colspan=5>---------------------------------------------------------------------------------------------------------------------------------------</td> </tr> <tr> <td colspan=2><center><strong><font size='2'>TOAL :</font></center></strong></td> <td colspan=2><strong><font size='2'><div style=’text-align:right;’> ".$TITEM." &nbsp Item</div> <td><strong><font size='2'><div style=’text-align:right;’>".$hasilRP."</div> </font></strong></td> </tr> </tbody> </table> "; echo " <table border='0'> <thead> <tr> <td colspan=5>---------------------------------------------------------------------------------------------------------------------------------------</td> </tr> </thead> </table> "; ?> <button onclick="goBack()"> KEMBALI </button> <script> function goBack() { window.history.back(); } </script> </script> </body> </html>

Kode diatas untuk mencetak dokumen penerimaan. 
Simpan dengan nama cetakBPB.php pada folder POS.

Selanjutnya kita tambahkan pada sub menu untuk gudang dengan cara buka file _main-nav.php 

Ketik kode berikut tepat dibawah tanda " </li>  " pda baris 23:

<!--MENU GUDANG--> <?php }elseif($_SESSION['login_hash']=="gudang") { ?> <li class="dropdown"><a href="#"><span class="icon-th-list"></span>Master</a> <ul> <li><a href="?cat=gudang&page=penerimaan"><span class="icon-pencil"></span>Penerimaan Barang</a></li> </ul> </li>

Kemudian simpan.

Hasilnya seperti berikut :
Ketika di inputkan item nya :

Ketika di klik button "SIMPAN" data akan otomatis mengupdate stock akhir pada tabel Tabel_stock.
dan mencetak dokumen :
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.

0 komentar:

Post a Comment

follow

Follow My Blog

baner ak

Click the Flag to translate this blog into English =>> English








Twitter Delicious Facebook Digg Stumbleupon Favorites More