<?php 
    include '../koneksi.php';
    include '../cari_notrans.php';

    $tnomor      = $_POST['tnomor'];
    $tkdc        = $_POST['tkdc'];
    $tkdk        = $_POST['tkdk'];
    $toleh       = $_POST['toleh'];
    $tnama       = $_POST['tnama'];
    $talamat     = $_POST['talamat'];
    $tpokok      = $_POST['tpokok'];
    $tjkw        = $_POST['tjkw'];
    $tbunga      = $_POST['tbunga'];
    $tgle        = $_POST['ttgl'];

    $nol=0;
    $no='';
    $tjumlah=$tpokok+$tjumlah ;
    
	$nominal = str_replace("Rp.", "", $tpokok);
	$nominal = str_replace(".", "", $nominal);
	$nominal = str_replace(",", "", $nominal);

	$nominal_a = str_replace("Rp.", "", $tbunga);
	$nominal_a = str_replace(".", "", $nominal_a);
	$nominal_a = str_replace(",", "", $nominal_a); 

//	$nominal_j = str_replace("Rp.", "", $tjumlah);
//	$nominal_j = str_replace(".", "", $nominal_j);
//	$nominal_j = str_replace(",", "", $nominal_j);

    $nominal_j=$nominal+$nominal_a ;
	
	$tket='Bayar angsuran hutang kepada '.$tnama.' - '.$talamat.'.';
	$tket1='Bayar angsuran pokok hutang kepada '.$tnama.' - '.$talamat.'.';
	$tket2='Bayar angsuran bunga hutang kepada '.$tnama.' - '.$talamat.'.';		
	$takunt_k  = $_POST['takunt'];
	$takunt_d1 = '21102';
	$takunt_d2 = '52101';
    $tr        = 'KK';
    $td        = '23';
	
    $query = mysqli_query($mysqli, "INSERT INTO hutang_angs (notrans,tanggal,norek,kdc,byrpokok,byrbunga) 
                                    VALUES('$kode3','$tgle','$tnomor','$tkdc','$nominal','$nominal_a' )")
                                    or die('Ada kesalahan pada query insert : '.mysqli_error($mysqli));
    ///////////             MENYIMPAN KE TABEL KAS
    $query = mysqli_query($mysqli, "INSERT INTO kas (tanggal,notrans,kdc,keterangan,tr,td,jumlah,noperk,oleh,jam) 
                                    VALUES('$tgle','$kode3','$tkdc','$tket','$tr','$td','$nominal_j','$takunt_k','$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,kdc,keterangan,tr,td,debet,noperk) 
                                    VALUES('$tgle','$kode3','$tkdc','$tket1','$tr','$td','$nominal','$takunt_d1' )")
                                    or die('Ada kesalahan pada query insert : '.mysqli_error($mysqli));
    ///////////             MENYIMPAN KE TABEL JOR DEBET
    $query = mysqli_query($mysqli, "INSERT INTO jor (tanggal,notrans,kdc,keterangan,tr,td,debet,noperk) 
                                    VALUES('$tgle','$kode3','$tkdc','$tket2','$tr','$td','$nominal_a','$takunt_d2' )")
                                    or die('Ada kesalahan pada query insert : '.mysqli_error($mysqli));                                    
    ///////////             MENYIMPAN KE TABEL JOR KREDIT
    $query = mysqli_query($mysqli, "INSERT INTO jor (tanggal,notrans,kdc,keterangan,tr,td,kredit,noperk) 
                                    VALUES('$tgle','$kode3','$tkdc','$tket','$tr','$td','$nominal_j','$takunt_k' )")
                                    or die('Ada kesalahan pada query insert : '.mysqli_error($mysqli));   
                                    
    header("location:@_hutang_trans.php");
