
<?php 
    session_start();
    include '../koneksi.php';
    include '../cari_notrans.php';
    
        $tkdc    = $_POST['tkdc'];
        $tkdj    = $_POST['tkdj'];
        $toleh   = $_POST['toleh'];
        $tao     = $_POST['tao'];
        $ttgl_d  = $_POST['ttgl_d'];
        $ttgl_s  = $_POST['ttgl_s'];
        $tnama    = $_POST['tnama'];
        $tjenis    = $_POST['tjenis'];
        $tjumlah  = $_POST['tjumlah'];
        
        $tgle     = $_POST['ttanggal'];
        $takunt  = $_POST['takunt'];

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

    $tnama = addslashes($tnama);            
	$tjenis = addslashes($tjenis);
    $tket = "Terima kolekting $tjenis dari $tnama ";

	$tr='KM' ;
	$td='90' ;
	if ($tkdj=='40401') {
	    $unit='01';
	} else {
	    $unit='02';
	}
	
            //////////////////////////////////////////////////////////////////////////// 
            $data = mysqli_query($koneksi,"SELECT * FROM anggota_trans_ao WHERE kdj='$tkdj' and tanggal BETWEEN '$ttgl_d' AND '$ttgl_s' and ao='$tao' and hapus<>'HAPUS' order by id ASC");
            while($x = mysqli_fetch_array($data)){
                $xid=$x['id'] ;
                $xangg_no=$x['angg_no'] ;
                $xmasuk=$x['masuk'] ;
                $xtanggal=$x['tanggal'] ;
                $xkdj=$x['kdj'] ;
            /////////// 
            $query = mysqli_query($mysqli, "INSERT INTO anggota_trans (notrans,tanggal,angg_no,kdj,kdc,masuk) 
                                    VALUES('$kode3','$xtanggal','$xangg_no','$xkdj','$tkdc','$xmasuk' )")
                                    or die('Ada kesalahan pada query insert : '.mysqli_error($mysqli));            

            /////////// 
            $query = mysqli_query($mysqli, "UPDATE anggota_trans_ao SET notrans='$kode3' where id='$xid' ");
            }                          
            ////////////////////////////////////////////////////////////////////////////

    
    ///////////             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','$takunt','$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','$takunt' )")
                                    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','$tkdj' )")
                                    or die('Ada kesalahan pada query insert : '.mysqli_error($mysqli)); 
    //////////    

    header("location:tugas_lap_trans_tgl_sd_tgl_per_ao.php?ao=$tao&kdj=$tkdj&tgl_d=$ttgl_d&tgl_s=$ttgl_s ");
