<?php
error_reporting(0);
include('../koneksi.php');
if (isset($_GET['rekening']) AND isset($_GET['tgl'])){
$rekening = $_POST['rekening'];
}
$no_bukti     = "ST".$_SESSION['nokode'].date("YmdHis");
$username     = $_SESSION['username'];
$kode         = $_SESSION['kode'];
$kodetab     = $_POST['jtabungan'];
$rekening     = $_POST['rekening'];
//$register     = $_POST['register'];
$tgl          = date('Y-m-d',strtotime($_POST['tgl']));
$nominal        = str_replace(",", "", $_POST['nominal']);
$nominal2        = $_POST['nominal'];
$keterangan   = $_POST['keterangan'];
$tglnow = date("Y-d-m H:i:s");

// Retrieve registrant data
//$register = substr($rekening, 0, 10);
$pesan = mysqli_fetch_assoc(mysqli_query($koneksi, "SELECT a.nim AS nim,a.nama AS nama,a.ibu as ibu, a.wali as wali, a.nohp AS nohp,sum(b.kredit-b.debet) AS saldoTab,b.keterangan as keterangan FROM registrasi a LEFT JOIN mutasitabungan b ON a.id=b.id WHERE b.rekening='$rekening'"));
  $saldoTab =$pesan['saldoTab']+$nominal;
    $nohp = $pesan['nohp'];
    $nama = $pesan['nama'];
    $nim = $pesan['nim'];
    $barang = 'a';
    $saldoTarik  =$pesan['saldoTab']-$nominal;
$judul = "*MMU A-39 REJOSARI*";
$tglpsn = $tgl;                
    // Set payment method
    $metodebayar = ($kodetab == "S") ? "Setor Tabungan" : (($carabayar == "T") ? "Tarik" :"Tarik");
    $jmlangsuran = number_format($jumlah, 0);
    $kantor = "*MMU A-39*";
    $rekeningpesan = $nim;
    $ket2 = $keterangan;
    $hasilket = preg_replace('/104.*$/', '', $ket2);
    $keteranganpesan = trim($hasilket);

$rekBank =  '105';
$nameBank = 'bca';
$waCenter = '082245392496';
// Wa

$chekrek = mysqli_query($koneksi,"SELECT rekening,blokir,tutup FROM bukutabungan WHERE rekening = '$rekening' 
");
$block = mysqli_fetch_assoc(mysqli_query($koneksi,"SELECT rekening,blokir,tutup FROM bukutabungan WHERE rekening = '$rekening' 
"));
if($rekening==""||$kodetab==""||$tgl==""||$nominal==""||$keterangan==""){
	echo "<script type='text/javascript'>alert('Data Masih ada yang kosong...!');
window.location = '../home.php?home=c1b1f59dbfe51b882c8b0dd09c86c1ca';
</script>";
}elseif($rekening=="0"||$kodetab=="0"||$tgl=="0"||$nominal=="0"||$keterangan=="0"){
	echo "<script type='text/javascript'>alert('Data Masih ada yang kosong...!');
window.location = '../home.php?home=c1b1f59dbfe51b882c8b0dd09c86c1ca';
</script>";
}else if(mysqli_num_rows($chekrek) <=0) {
	echo "<script type='text/javascript'>alert('Belum Buka Buku Tabungan...!');
window.location = '../home.php?home=e2160291e45e35a256062c679ab2ed0c';
</script>";
}else if($block['tutup']=='1') {
	
echo "<script type='text/javascript'>
        alert('Buku Tabungan Telah ditutup...! {$block['tutup']}');
        window.location = '../home.php?home=c1b1f59dbfe51b882c8b0dd09c86c1ca';
      </script>";
 }else if($block['blokir']=='1') {
	
echo "<script type='text/javascript'>
        alert('Buku Tabungan Telah blokir...! {$block['tutup']}');
        window.location = '../home.php?home=c1b1f59dbfe51b882c8b0dd09c86c1ca';
      </script>";

	}else{
if($kodetab=="S"){
$query = mysqli_query($koneksi,"INSERT INTO mutasitabungan SET no_bukti='$no_bukti', rekening='$rekening',debet='0',kredit='$nominal',keterangan='$keterangan',kodetab='$kodetab',tgl='$tgl',username='$username' ")or die(mysqli_error($koneksi));
$query = mysqli_query($koneksi,"INSERT INTO bukubesar SET no_bukti='$no_bukti',tanggal='$tgl',kode_akun='1.100.10',debet='$nominal',kredit='0',keterangan='$keterangan',kode='$kode',username='$username' ")or die(mysqli_error($koneksi));
$query = mysqli_query($koneksi,"INSERT INTO bukubesar SET no_bukti='$no_bukti',tanggal='$tgl',kode_akun='2.220.10',debet='0',kredit='$nominal',keterangan='$keterangan',kode='$kode',username='$username' ")or die(mysqli_error($koneksi));
// Insert message into the database
$waSetor = mysqli_query($koneksi, "INSERT INTO message SET number='$nohp',tgl='$tglpsn',judul='$judul', penErima='$nama', PenGirim='$kantor', rekening='$nim',kewajiban='$barang',sisaKewajiban='$saldoTab', nominal='$nominal', keterangan='$keteranganpesan', metodeBayar='$metodebayar',kodeFilTer='Setor' ") or die(mysqli_error($koneksi));
$DeleteWA = mysqli_query($koneksi, "DELETE FROM message WHERE status='1' OR status='2' ") or die(mysqli_error($koneksi));
}else{
$query = mysqli_query($koneksi,"INSERT INTO mutasitabungan SET no_bukti='$no_bukti', rekening='$rekening',debet='$nominal',kredit='0',keterangan='$keterangan',kodetab='$kodetab',tgl='$tgl',username='$username' ")or die(mysqli_error($koneksi));
$query = mysqli_query($koneksi,"INSERT INTO bukubesar SET  no_bukti='$no_bukti',tanggal='$tgl',kode_akun='1.100.10',debet='0',kredit='$nominal',keterangan='$keterangan',kode='$kode',username='$username' ")or die(mysqli_error($koneksi));
$query = mysqli_query($koneksi,"INSERT INTO bukubesar SET no_bukti='$no_bukti',tanggal='$tgl',kode_akun='2.220.10',debet='$nominal',kredit='0',keterangan='$keterangan',kode='$kode',username='$username' ")or die(mysqli_error($koneksi));
// Insert message into the database
$waSetor = mysqli_query($koneksi, "INSERT INTO message SET number='$nohp',tgl='$tglpsn',judul='$judul', penErima='$nama', PenGirim='$kantor', rekening='$nim',kewajiban='$barang',sisaKewajiban='$saldoTarik', nominal='$nominal', keterangan='$keteranganpesan', metodeBayar='$metodebayar',kodeFilTer='Tarik' ") or die(mysqli_error($koneksi));
$DeleteWA = mysqli_query($koneksi, "DELETE FROM message WHERE status='1' OR status='2' ") or die(mysqli_error($koneksi)); 
}
 



echo  "<script type='text/javascript'>alert('Data Yang Bpk Input Berhasil');
window.location = '../home.php?home=c1b1f59dbfe51b882c8b0dd09c86c1ca';
</script>";


/*echo "<script type='text/javascript'>alert('Data Yang Bpk Input Berhasil');
window.location = '../home.php?home=c1b1f59dbfe51b882c8b0dd09c86c1ca';
</script>";*/

 }   




?>
