<?php
mysql_select_db($database_sistem, $sistem);
$query_unit = "SELECT * FROM user_tb";
$unit = mysql_query($query_unit, $sistem) or die(mysql_error());
$row_unit = mysql_fetch_assoc($unit);
$totalRows_unit = mysql_num_rows($unit);

if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
  $insertSQL = sprintf("INSERT INTO bank_tb (kode_unit, no_rek, nama_bank, kode_bank, jenis, nominal) VALUES (%s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['kode_unit'], "text"),
                       GetSQLValueString($_POST['no_rek'], "text"),
                       GetSQLValueString($_POST['nama_bank'], "text"),
                       GetSQLValueString($_POST['kode_bank'], "text"),
                       GetSQLValueString($_POST['jenis'], "text"),
                       GetSQLValueString($_POST['nominal'], "text"));

  mysql_select_db($database_sistem, $sistem);
  $Result1 = mysql_query($insertSQL, $sistem) or die(mysql_error());
}
?>
<script type="text/javascript" charset="utf-8">
          $(document).ready(function(){
            $('#indexbank, #indexbank2').dataTable({
					     "oLanguage": {
						      "sLengthMenu": "Tampilkan _MENU_ data per halaman",
						      "sSearch": "Pencarian: ", 
						      "sZeroRecords": "Maaf, tidak ada data yang ditemukan",
						      "sInfo": "Menampilkan _START_ s/d _END_ dari _TOTAL_ data",
						      "sInfoEmpty": "Menampilkan 0 s/d 0 dari 0 data",
						      "sInfoFiltered": "(di filter dari _MAX_ total data)",
						      "oPaginate": {
						          "sFirst": "<<",
						          "sLast": ">>", 
						          "sPrevious": "<", 
						          "sNext": ">"
					       }
				      },
              "sPaginationType":"full_numbers",
              "bJQueryUI":true
            });
          })    
        </script>

<table width="95%" border="0" align="center" cellpadding="5" cellspacing="5">
  <tr>
    <td><h3>Form Input Data Bank</h3></td>
  </tr>
  <tr>
    <td><hr /></td>
  </tr>
  <tr>
    <td><form action="<?php echo $editFormAction; ?>" method="post" name="form2" id="form2">
        <table align="left" cellpadding="4" cellspacing="4" class="isi_tabel">
          <tr valign="baseline">
            <td align="left" valign="top" nowrap="nowrap">Nama Unit</td>
            <td align="left" valign="top" nowrap="nowrap">:</td>
            <td><select name="kode_unit">
              <?php
do {  
?>
              <option value="<?php echo $row_unit['kode_unit']?>"<?php if (!(strcmp($row_unit['kode_unit'], $row_unit['kode_unit']))) {echo "selected=\"selected\"";} ?>><?php echo $row_unit['nama_unit']?></option>
              <?php
} while ($row_unit = mysql_fetch_assoc($unit));
  $rows = mysql_num_rows($unit);
  if($rows > 0) {
      mysql_data_seek($unit, 0);
	  $row_unit = mysql_fetch_assoc($unit);
  }
?>
            </select></td>
          </tr>
          <tr valign="baseline">
            <td align="left" valign="top" nowrap="nowrap">No. Rekening</td>
            <td align="left" valign="top" nowrap="nowrap">:</td>
            <td><input type="text" name="no_rek" value="" size="32" /></td>
          </tr>
          <tr valign="baseline">
            <td align="left" valign="top" nowrap="nowrap">Nama Bank</td>
            <td align="left" valign="top" nowrap="nowrap">:</td>
            <td><input type="text" name="nama_bank" value="" size="32" /></td>
          </tr>
          <tr valign="baseline">
            <td align="left" valign="top" nowrap="nowrap">Kode Bank</td>
            <td align="left" valign="top" nowrap="nowrap">:</td>
            <td valign="baseline"><table>
              <tr>
                <td align="center">Bank 1</td>
              </tr>
              <tr>
                <td align="center"><input type="radio" name="kode_bank" value="Bank 1" /></td>
              </tr>
              <tr>
                <td align="center">Bank 2</td>
              </tr>
              <tr>
                <td align="center"><input type="radio" name="kode_bank" value="Bank 2" /></td>
              </tr>
              <tr>
                <td align="center">Bank 3</td>
              </tr>
              <tr>
                <td align="center"><input type="radio" name="kode_bank" value="Bank 3" /></td>
              </tr>
              <tr>
                <td align="center">Bank 4</td>
              </tr>
              <tr>
                <td align="center"><input type="radio" name="kode_bank" value="Bank 4" /></td>
              </tr>
              <tr>
                <td align="center">Bank 5</td>
              </tr>
              <tr>
                <td><input type="radio" name="kode_bank" value="Bank 5" /></td>
              </tr>
              </table>
              <table>
                <tr>
                  <td align="center">Deposito 1</td>
                </tr>
                <tr>
                  <td align="center"><input type="radio" name="kode_bank" value="Deposito 1" /></td>
                </tr>
                <tr>
                  <td align="center">Deposito 2</td>
                </tr>
                <tr>
                  <td align="center"><input type="radio" name="kode_bank" value="Deposito 2" /></td>
                </tr>
                <tr>
                  <td align="center">Deposito 3</td>
                </tr>
                <tr>
                  <td align="center"><input type="radio" name="kode_bank" value="Deposito 3" /></td>
                </tr>
                <tr>
                  <td align="center">Deposito 4</td>
                </tr>
                <tr>
                  <td align="center"><input type="radio" name="kode_bank" value="Deposito 4" /></td>
                </tr>
                <tr>
                  <td align="center">Deposito 5</td>
                </tr>
                <tr>
                  <td align="center"><input type="radio" name="kode_bank" value="Deposito 5" /></td>
                </tr>
            </table></td>
          </tr>
          <tr valign="baseline">
            <td align="left" valign="top" nowrap="nowrap">Jenis Account</td>
            <td align="left" valign="top" nowrap="nowrap">:</td>
            <td valign="baseline"><table>
              <tr>
                <td><input name="jenis" type="radio" value="Bank" checked="checked" />
                  Bank</td>
              </tr>
              <tr>
                <td><input type="radio" name="jenis" value="Deposito" />
                  Deposito</td>
              </tr>
            </table></td>
          </tr>
          <tr valign="baseline">
            <td align="left" valign="top" nowrap="nowrap">Nominal</td>
            <td align="left" valign="top" nowrap="nowrap">:</td>
            <td><input name="nominal" id="rupiah" type="text" value="0" size="20" /></td>
          </tr>
          <tr valign="baseline">
            <td align="left" valign="top" nowrap="nowrap">&nbsp;</td>
            <td align="left" valign="top" nowrap="nowrap">&nbsp;</td>
            <td><input name="show" type="text" id="rupiah2" style="opacity:10" size="20" readonly="readonly" /></td>
          </tr>
          <tr valign="baseline">
            <td align="left" valign="top" nowrap="nowrap">&nbsp;</td>
            <td align="left" valign="top" nowrap="nowrap">&nbsp;</td>
            <td><input name="Submit" type="submit" class="button" value="Input Data Bank" /></td>
          </tr>
          <tr valign="baseline">
            <td align="left" valign="top" nowrap="nowrap">&nbsp;</td>
            <td align="left" valign="top" nowrap="nowrap">&nbsp;</td>
            <td><input name="Reset" type="reset" class="button" value="Reset" /></td>
          </tr>
        </table>
        <input type="hidden" name="MM_insert" value="form2" />
      </form>
    <p>&nbsp;</p></td>
  </tr>
  <tr>
    <td><hr /></td>
  </tr>
  <tr>
    <td><h3>Tabel  Daftar Nama Bank</h3></td>
  </tr>
  <tr>
    <td><table width="90%" align="center"  bgcolor="#FFFFFF" class="display" id="indexbank">
      <thead>
        <tr height="40" class="form_body">
          <th align="center" width="100">No</th>
          <th align="center">Kode Bank</th>
          <th align="center">No. Rekening</th>
          <th align="center">Nama Bank</th>
          <th align="center">Saldo</th>
          <th align="center">Kode Unit</th>
        </tr>
        </thead>
      <tbody>
      
        <?php        mysql_select_db("csabrude_akurat");
					          $sql = mysql_query("SELECT * From bank_tb where jenis='Bank' order by kode_unit, kode_bank asc");
					          $no = 1;
							$ttljumlah=0;
                    while ($r = mysql_fetch_array($sql)) 
					{
						$jumlahnya=$r['nominal'];
						$ttljumlah=$ttljumlah+$jumlahnya;
						
                      echo "<tr height='25'>
          <td align='center'>$no</td>
		  <td align='center'>$r[kode_bank]</td>
            <td align='center'>$r[no_rek]</td>
			<td align='left'>$r[nama_bank]</td>
			<td align='right'>";?><?php echo formatRupiah($r['nominal']);?><?php echo"</td>
			<td align='center'>$r[kode_unit]</td>
          </tr>";
                      $no++;
                    }
                    ?>
      </tbody>
      <tfoot>
        <tr>
       <th colspan="3" align="center">Saldo</th>
          <th align="right"><?php echo '-';?></th>
          <th align="right"><?php echo formatRupiah($ttljumlah);?></th>
          <th align="right"><?php echo '-';?></th>
        </tr>
      </tfoot>
    </table>
    <p>&nbsp;</p></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
<p>&nbsp;</p>

<table width="95%" border="0" align="center" cellpadding="5" cellspacing="5">
  <tr>
    <td><h3 style="color:#036">Form Update Data</h3></td>
  </tr>
  <tr>
    <td><table width="400" border="0" cellpadding="1" class="isi_tabel">
      <tr>
        <td width="100">Kode Bank</td>
        <td width="10">:</td>
        <td>-</td>
      </tr>
      <tr>
        <td>No. Rekening</td>
        <td>:</td>
        <td>-</td>
      </tr>
      <tr>
        <td>Nama Bank</td>
        <td>:</td>
        <td>-</td>
      </tr>
      <tr>
        <td>Saldo</td>
        <td>:</td>
        <td>-</td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><input class="button" type="submit" name="update" id="update" value="Update Data" disabled="disabled" /></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td><table width="400" class="isi_tabel">
        <tr>
          <td width="100">Tabel</td>
          <td width="10">:</td>
          <td>Daftar Nama Bank</td>
        </tr>
        <tr>
          <td>Unit</td>
          <td>:</td>
          <td><?php echo $_SESSION['nama'];?></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
          <td>&nbsp;</td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td><table width="100%" align="center"  bgcolor="#FFFFFF" class="display" id="indexbank2">
      <thead>
        <tr height="40" class="form_body">
          <th align="center" width="100">No</th>
          <th align="center">Kode Bank</th>
          <th align="center">No. Rekening</th>
          <th align="center">Nama Bank</th>
          <th align="center">Saldo</th>
          <th align="center">Proses</th>
        </tr>
        </thead>
      <tbody>
      
        <?php        mysql_select_db("csabrude_akurat");
					          $sql = mysql_query("SELECT * From bank_tb where kode_unit='$_SESSION[kode]' and jenis='Bank' order by kode_bank asc");
					          $no = 1;
							$ttljumlah=0;
                    while ($r = mysql_fetch_array($sql)) 
					{
						$jumlahnya=$r['nominal'];
						$ttljumlah=$ttljumlah+$jumlahnya;
                      echo "<tr height='25'>
          <td align='center'>$no</td>
		  <td align='center'>$r[kode_bank]</td>
            <td align='center'>$r[no_rek]</td>
			<td align='left'>$r[nama_bank]</td>
			<td align='right'>";?><?php echo formatRupiah($r['nominal']);?><?php echo"</td>
			<td align='center'>";?><a href="?section=Setting&module=saldo_awal_bank&no_rek=<?php echo $r['no_rek'];?>">Proses</a><?php echo"</td>
          </tr>";
                      $no++;
                    }
                    ?>
      </tbody>
      <tfoot>
        <tr>
       <th colspan="3" align="center">Saldo</th>
          <th align="right"><?php echo '-';?></th>
          <th align="right"><?php echo formatRupiah($ttljumlah);?></th>
          <th align="right"><?php echo '-';?></th>
        </tr>
      </tfoot>
    </table>
    <p>&nbsp;</p></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
        <script type="text/javascript">
		
		var rupiah = document.getElementById('rupiah');
		rupiah.addEventListener('keyup', function(e){
			// tambahkan 'Rp.' pada saat form di ketik
			// gunakan fungsi formatRupiah() untuk mengubah angka yang di ketik menjadi format angka
			rupiah.value = formatRupiah(this.value, 'Rp. ');
		});
			var rupiah = document.getElementById('rupiah2');
		rupiah.addEventListener('keyup', function(e){
			// tambahkan 'Rp.' pada saat form di ketik
			// gunakan fungsi formatRupiah() untuk mengubah angka yang di ketik menjadi format angka
			rupiah.value = formatRupiah(this.value, 'Rp. ');
		});
 
		/* Fungsi formatRupiah */
		function formatRupiah(angka, prefix){
			var number_string = angka.replace(/[^,\d]/g, '').toString(),
			split   		= number_string.split(','),
			sisa     		= split[0].length % 3,
			rupiah     		= split[0].substr(0, sisa),
			ribuan     		= split[0].substr(sisa).match(/\d{3}/gi);
 
			// tambahkan titik jika yang di input sudah menjadi angka ribuan
			if(ribuan){
				separator = sisa ? '.' : '';
				rupiah += separator + ribuan.join('.');
			}
 
			rupiah = split[1] != undefined ? rupiah + ',' + split[1] : rupiah;
			return prefix == undefined ? rupiah : (rupiah ? 'Rp. ' + rupiah : '');
		}
	</script>