Advertisement
cdsatrian

cek pinjaman dan harga taksir

Sep 22nd, 2013
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.48 KB | None | 0 0
  1. <!-- cut here -->
  2. <form name="input_data" id="input_data" action="insertpinjaman.php" method="post">
  3. <table border='0' border='#CC3366' cellpadding='3' cellspacing='0' style='border-collapse:collapse'>
  4.   <tbody>
  5.     <tr>
  6.       <td>No.Pinjaman</td>
  7.       <td><input type="text" name="id_pinjam" required value="<?php echo kdauto("pinjaman","P"); ?>" readonly /></td>
  8.     </tr>
  9.     <tr>
  10.     <tr>
  11.       <td>No.Nasabah</td>
  12.       <td><select name="no_nasabah" required="required">
  13.       <?php
  14.       $no_nasabah= mysql_query("select no_nasabah from nasabah");
  15.       while ($row = mysql_fetch_array($no_nasabah)){
  16.         echo "<option value =$row[no_nasabah]>$row[no_nasabah]</option>";
  17.       }
  18.       ?>
  19.       </select>
  20.       </td>
  21.     </tr>
  22.     <tr>
  23.        <td>Barang</td>
  24.        <td>
  25.          <select id="barang"  name="barang" required="required">
  26.          <?php
  27.           $tipe= mysql_query("select tipe,hargataksir from nilaitaksir");
  28.                 $hargataksir=array();
  29.           while ($row = mysql_fetch_array($tipe)){
  30.                     $hargataksir[]=array($row[tipe],$row[hargataksir]);
  31.               echo "<option value='{$row[tipe]}'>{$row[tipe]}</option>\n";
  32.           }
  33.         ?>
  34.         </select>
  35.       </td>
  36.     </tr>
  37.     <tr>
  38.       <td>Pinjaman</td>
  39.       <td><input type="text" name="pinjaman" id="pinjaman" maxlength="100" required="required" /></td>
  40.     </tr>
  41.     <tr>
  42.       <td>Tanggal</td>
  43.       <td>
  44.     <input type="date" name="tanggal" maxlength="100" required="required" value="<?php echo date('Y-m-d'); ?>" />  
  45.       </td>
  46.     <tr>
  47.     <td>Status</td>
  48.       <td>
  49.         <select name='status' required="required">
  50.           <option value='Belum'>Belum</option>
  51.       </select>
  52.       </td>
  53.     </tr>
  54.     <tr>
  55.       <td align="right">
  56.         <input type="button" id="submit" name="submit" value="Simpan" onSubmit="javascript:cek_harga();"/>
  57.       </td>
  58.       <td>
  59.         <input type="button" value="Batal" onClick="self.history.back()">
  60.       </td>
  61.     </tr>
  62.   </tbody>
  63. </table>  
  64. <script>
  65. <?php
  66. echo "var hargataksir=new Array();\n";
  67. foreach($hargataksir AS $data)
  68. {
  69.   echo "hargataksir['".$data[0]."']=".str_replace('.','',$data[1]).";\n";
  70. }
  71. ?>
  72.   $(document).ready(function(){
  73.     $('#submit').click(function(){
  74.       if(parseFloat(hargataksir[$('#barang').val()])>=parseFloat($('#pinjaman').val()))
  75.       {
  76.         $('#input_data').submit();  
  77.       }
  78.       else
  79.       {
  80.           alert('terlalu besar');
  81.       }
  82.     });
  83.   });
  84. </script>
  85. <?php
  86. //-- CATATAN
  87. * form ditambah attribute 'id="input_data"'
  88. * input type="submit" diganti input type="button" dan ditambah attribute 'id="submit"'
  89. ?>
  90.  
  91. //--untuk sisi server-nya bisa dibuat:
  92. <?php
  93. //panggil file config.php untuk menghubung ke server
  94. include('conn-db.php');
  95. //tangkap data dari form
  96. $harga_taksir = $_POST['harga_taksir'];
  97. $id_pinjam = $_POST['id_pinjam'];
  98. $no_nasabah = $_POST['no_nasabah'];
  99. $barang = $_POST['barang'];
  100. $pinjaman = $_POST['pinjaman'];
  101. $tanggal = $_POST['tanggal'];
  102. $status = $_POST['status'];
  103. $jatuh_tempo = date('Y-m-d',strtotime('+30 day',strtotime($tanggal)));
  104. $sql="IF NOT EXIST(SELECT 1 FROM  nilaitaksir WHERE hargataksir<$pinjaman AND tipe='$barang')
  105.      INSERT INTO pinjaman
  106.      (id_pinjam, barang, no_nasabah, tanggal, tanggal_perpanjang, pinjaman, status, jatuh_tempo)
  107.      VALUES
  108.      ('$id_pinjam', '$barang', '$no_nasabah', '$tanggal', '$tanggal', '$pinjaman', '$status', '$jatuh_tempo')"
  109. $query = mysql_query($sql) or die(mysql_error());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement