<?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'];
    $tangs       = $_POST['tangs'];

    $tsektor     = $_POST['tsektor'];
    $tgle       = $_POST['ttgl'];

    $jam    = date('d-m-Y  H:i:s'); //kombinasi jam dan tanggal

    $nol=0;
    $no='';

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

	$nominal_a = str_replace("Rp.", "", $tangs);
	$nominal_a = str_replace(".", "", $nominal_a);
	$nominal_a = str_replace(",", "", $nominal_a); 
	
	$tket='Pemerimaan Hutang Usaha dari '.$tnama.' - '.$talamat.'.';
	$takunt_d  = $_POST['takunt'];
	$takunt_k  = '21102';
    $tr        = 'KM';
    $td        = '22';
    
    $query = mysqli_query($mysqli, "INSERT INTO hutang (notrans,tanggal,bank,alamat,norek,kdc,pokok,angsuran,jkw) 
                                    VALUES('$kode3','$tgle','$tnama','$talamat','$tnomor','$tkdc','$nominal','$nominal_a','$tjkw' )")
                                    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','$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','$tket','$tr','$td','$nominal','$takunt_d' )")
                                    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,kredit,noperk) 
                                    VALUES('$tgle','$kode3','$tkdc','$tket','$tr','$td','$nominal','$takunt_k' )")
                                    or die('Ada kesalahan pada query insert : '.mysqli_error($mysqli));   
                                    
    header("location:@_hutang_trans.php");
