<?php 
    include '../koneksi.php';
    include '../cari_notrans.php';
    
        $toleh    = $_POST['toleh'];
        $tnama    = $_POST['tnama'];
        $talamat  = $_POST['talamat'];
        $tangg_no = $_POST['tangg_no'];
        $tdebet   = $_POST['tdebet'];
        $tjumlah  = $_POST['tjumlah'];
        $tgle     = $_POST['ttanggal'];
        $tkredit  = $_POST['tkredit'];

	$nominal = str_replace("Rp.", "", $tjumlah);
	$nominal = str_replace(".", "", $nominal);
	$nominal = str_replace(",", "", $nominal); 

        $sql1 = mysqli_query($koneksi, "SELECT perk AS tperk FROM nawal WHERE noperk='$tkredit' ");
                list($tperk) = mysqli_fetch_array($sql1);
                
    $tnama = addslashes($tnama);            
	$tperk = addslashes($tperk);
    $tket = "Penerimaan $tperk dari $tnama, $talamat";

	$tr='KM' ;
	$td='10' ;
	if ($tkredit=='40401') {
	    $unit='01';
	} else {
	    $unit='02';
	}
        /////////// 
    $query = mysqli_query($mysqli, "INSERT INTO anggota_trans (notrans,tanggal,angg_no,kdj,kdc,masuk) 
                                    VALUES('$kode3','$tgle','$tangg_no','$tkredit','$tkdc','$nominal' )")
                                    or die('Ada kesalahan pada query insert : '.mysqli_error($mysqli));
    
    ///////////             MENYIMPAN KE TABEL KAS
    $query = mysqli_query($mysqli, "INSERT INTO kas (tanggal,notrans,unit,kdc,keterangan,tr,td,jumlah,noperk,oleh,jam)  
                                    VALUES('$tgle','$kode3','$unit','$tkdc','$tket','$tr','$td','$nominal','$tkredit','$toleh',(now()) )")
                                    or die('Ada kesalahan pada query insert : '.mysqli_error($mysqli));
                                  
    ///////////             MENYIMPAN KE TABEL JOR DEBET
    $query = mysqli_query($mysqli, "INSERT INTO jor (tanggal,notrans,unit,kdc,keterangan,tr,td,debet,noperk)  
                                    VALUES('$tgle','$kode3','$unit','$tkdc','$tket','$tr','$td','$nominal','$tdebet' )")
                                    or die('Ada kesalahan pada query insert : '.mysqli_error($mysqli));
    
    ///////////             MENYIMPAN KE TABEL JOR KREDIT
    $query = mysqli_query($mysqli, "INSERT INTO jor (tanggal,notrans,unit,kdc,keterangan,tr,td,kredit,noperk)  
                                    VALUES('$tgle','$kode3','$unit','$tkdc','$tket','$tr','$td','$nominal','$tkredit' )")
                                    or die('Ada kesalahan pada query insert : '.mysqli_error($mysqli)); 
    //////////    

      $tgl_d        = '2025-01-01' ;
      $tgl_s        = $tgl_sekarang ;
  
    $tgl_skr    = date('Y-m-d');
    $harinya    = (date('d', strtotime($tgl_skr)))-1 ;
    $tg_skr     = strtotime("$tgl_skr");
    $tgl_dr     = date('Y-m-d', strtotime("-$harinya day", $tg_skr));        
    
        header("location:@_angg_tgl_sd_tgl.php?tanggal_d=$tgl_dr&tanggal_s=$tgl_skr");
        
?>        