<?php
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 aktiva_tb (akun, keterangan, nominal, kode_unit, bulan, tahun, reg) VALUES (%s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['akun'], "text"),
                       GetSQLValueString($_POST['keterangan'], "text"),
                       GetSQLValueString($_POST['nominal'], "text"),
                       GetSQLValueString($_POST['kode_unit'], "text"),
                       GetSQLValueString($_POST['bulan'], "text"),
                       GetSQLValueString($_POST['tahun'], "text"),
                       GetSQLValueString($_POST['reg'], "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(){
            $('#bbkas').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="100%" border="0" align="center" cellpadding="5" cellspacing="5">
  <tr>
    <td><h3 style="color:#036">Form Input Data Aktiva</h3></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 width="100" align="left" nowrap="nowrap">Perkiraan</td>
            <td width="10" align="left" nowrap="nowrap">:</td>
            <td><select name="akun" size="1" id="akun">
              <option value="1210">Tanah</option>
              <option value="1220">Gedung</option>
              <option value="1230">Kendaraan</option>
              <option value="1240">Inventaris</option>
            </select></td>
          </tr>
          <tr valign="baseline">
            <td align="left" valign="top" nowrap="nowrap">Keterangan</td>
            <td align="left" valign="top" nowrap="nowrap">:</td>
            <td><textarea name="keterangan" id="keterangan" cols="30" rows="3"></textarea></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="left">Nominal</td>
            <td nowrap="nowrap" align="left">:</td>
            <td><input type="text" name="nominal" id="rupiah" value="" size="20" /></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="left">&nbsp;</td>
            <td nowrap="nowrap" align="left">&nbsp;</td>
            <td><input name="show" type="text" id="rupiah2" style="opacity:10" size="20" readonly="readonly" /></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="left">Kode unit</td>
            <td nowrap="nowrap" align="left">:</td>
            <td><input name="kode_unit" type="text" value="<?php echo $_SESSION['kode'];?>" size="20" readonly="readonly" /></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="left">Bulan</td>
            <td nowrap="nowrap" align="left">:</td>
            <td><select name="bulan" id="bulan">
              <option value="Januari">Januari</option>
              <option value="Februari">Februari</option>
              <option value="Maret">Maret</option>
              <option value="April">April</option>
              <option value="Mei">Mei</option>
              <option value="Juni">Juni</option>
              <option value="Juli">Juli</option>
              <option value="Agustus">Agustus</option>
              <option value="September">September</option>
              <option value="Oktober">Oktober</option>
              <option value="November">November</option>
              <option value="Desember">Desember</option>
            </select></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="left">Tahun</td>
            <td nowrap="nowrap" align="left">:</td>
            <td><input name="tahun" type="text" value="" size="4" />
            <input name="reg" type="hidden" required="required" id="reg" value="<?php echo $_SESSION['kode'].'-'.$reg;?>" size="30" readonly="readonly" /></td>
          </tr>
          <tr valign="baseline">
            <td nowrap="nowrap" align="left">&nbsp;</td>
            <td nowrap="nowrap" align="left">&nbsp;</td>
            <td><input type="submit" value="Input Data Aktiva" class="button" /></td>
          </tr>
        </table>
        <input type="hidden" name="MM_insert" value="form2" />
    </form></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 Aktiva</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="bbkas">
      <thead>
        <tr height="40" class="form_body">
          <th align="center" width="100">No</th>
          <th align="center">Kode Aktiva</th>
          <th align="center">Keterangan</th>
          <th align="center">Nominal</th>
          <th align="center">Bulan</th>
          <th align="center">Tahun</th>
        </tr>
        </thead>
      <tbody>
      
        <?php        mysql_select_db("csabrude_akurat");
					          $sql = mysql_query("SELECT * From aktiva_tb where kode_unit='$_SESSION[kode]' order by akun asc");
					          $no = 1;
							
                    while ($r = mysql_fetch_array($sql)) {
                      echo "<tr height='25'>
          <td align='center'>$no</td>
		  <td align='center'>$r[akun]</td>
            <td align='left'>$r[keterangan]</td>
			<td align='right'>";?><?php echo formatRupiah($r['nominal']);?><?php echo"</td>
			<td align='center'>$r[bulan]</td>
			<td align='center'>$r[tahun]</td>
          </tr>";
                      $no++;
                    }
                    ?>
      </tbody>
      <tfoot>
        <tr>
       <th colspan="3" align="center">Saldo</th>
          <th align="right"><?php echo '-';?></th>
          <th align="right"><?php echo '-';?></th>
          <th align="right"><?php echo '-';?></th>
        </tr>
      </tfoot>
    </table></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
  </tr>
</table>
<p>&nbsp;</p>
<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>
