Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_save_path("klien/login/sess");
- @session_start();
- include("connect/connect.php");
- $kd="PR".date("y").date("m").date("d")."01";
- $sql="SELECT no_per FROM tpermintaan;";
- $result = mysql_query($sql);
- if($result)
- {
- while($row = mysql_fetch_array($result))
- {
- $kode=$row['no_per'];
- }
- if(substr($kode,2,-2)==date("ymd"))
- {
- $kode=substr($kode,-2);
- $kd="PR".date("y").date("m").date("d").str_pad(++$kode,2,"0",STR_PAD_LEFT);
- }
- }
- $sql = "SELECT * FROM tstok";
- $result = mysql_query($sql);
- $option_barang='';
- if ($result){
- while ($data = mysql_fetch_array($result)) {
- $option_barang.="<option value=\"".$data['KD_BRG']."\">".$data['NAMA']."</option>\n";
- }
- }
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Permintaan</title>
- <style type="text/css">
- .add:hover {cursor:pointer;}
- </style>
- </head>
- <body>
- <fieldset>
- <legend>
- <h3>Buat Permintaan</h3>
- </legend>
- <form method="post" id="myfrm" action="?menu=simpan_permintaan">
- <table>
- <tr>
- <td>No Permintaan</option></td>
- <td>:</td>
- <td> <?php echo $kd; ?><input type='hidden' name='no_per' value="<?php echo $kd; ?>" /></td>
- </tr>
- <!--<tr>
- <td>Tanggal Permintaan</td>
- <td>:</td>
- <td><input type='text' name='tanggal' value="<?php echo $_POST['tanggal']; ?>" /></td>
- </tr>-->
- <tr>
- <td>Nama</td>
- <td>:</td>
- <td><?php echo $_SESSION['username'];?> <input type="hidden" name="nama" value="<?php echo $_SESSION['username'];?>"/></td>
- </tr>
- <tr>
- <td>Nama Barang</td>
- <td>:</td>
- <td>
- <select size="1" id="kd_brg">
- <?php echo $option_barang;?>
- </select>
- <input type="hidden" name="stok" id="stok" value="0"/>
- </td>
- </tr>
- <tr>
- <td>Jumlah</td>
- <td>:</td>
- <td>
- <input type="text" id="jumlah" size="3" maxlength="2" />
- <img src="images/add.gif" id="add" class="add" />
- </td>
- </tr>
- <tr>
- <td>Kode Barang</td>
- <td width="312">Nama Barang</td>
- <td width="119">Jumlah</td>
- </tr>
- <tr>
- <td>
- <input type="button" name="simpan" id="simpan" value="Simpan" />
- <input type="button" name="cancel" id="cancel" value="Cancel" />
- </td>
- </tr>
- </table>
- </form>
- </fieldset>
- <script type="text/javascript" src="js/jquery.min.js"></script>
- <script type="text/javascript">
- $(document).ready(function() {
- $('#add').click(function() {
- if(validation() != ''){
- alert(validation());
- } else
- $("#data").children('tbody').append(newRow());
- });
- $('#kd_brg').change(function(){
- $.ajax(
- {
- type: "POST",
- url: "get_stok.php",
- data: "kd="+ this.value,
- dataType: "json",
- success: function(data)
- {
- if(data.result<=0){
- alert('no available stock');
- }
- $('#stok').val(data.result);
- },
- error: function(data){
- alert('Ajax error');
- }
- }
- )
- });
- $('#simpan').click(function(){
- $("#myfrm").submit();
- });
- });
- function validation(){
- var msg='';
- if($('#jumlah').value > $('#stok').value){
- msg='jumlah yang dimasukkan lebih dari stok yang tersedia';
- }
- return msg;
- }
- function newRow() {
- var kode = $("select#kd_brg").val();
- var jumlah = $("#jumlah").val();
- var nama = $("#kd_brg option:selected").text();
- if(jumlah == '' || jumlah == 0) {
- alert('jumlah kosong');
- return false;
- }
- if($("#" + kode).length > 0) {
- alert('data sudah ada');
- return false;
- }
- var text = "<tr>" +
- "<td><input value='" + kode + "' name='kode[]' id = '" + kode + "' readonly /></td>" +
- "<td><input value='" + nama + "' name='nbarang[]' size=50 readonly /></td>" +
- "<td><input value='" + jumlah + "' name='jml[]' readonly /></td>" +
- "</tr>";
- return text;
- };
- </script>
- </body>
- </html>
- /////////-- file : get_stok.php ---//////////
- <?php
- //filename: get_stok.php
- $kd=isset($_POST['kd'])?$_POST['kd']:'';
- $sql = "SELECT stok FROM tstok WHERE kd_brg='".$kd."'";
- if($result = mysql_query($sql)){
- $row=mysql_fetch_row($result);
- $data['result']=$row['stok'];
- }
- return json_encode($data);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement