<?php

$host = "localhost";
$user = "basg8396_sikeung";
$pass = "sikeung99";
$database = "basg8396_sikeung";
$conn = new mysqli($host, $user, $pass, $database);


if (mysqli_connect_error()) {
	trigger_error('Koneksi ke database gagal: '  . mysqli_connect_error(), E_USER_ERROR);
}

function id_transaksi()
{

	$newID = date('ymdHis');
	return $newID;
}

function namabulan($bln)
{
	if ($bln == 1) {
		$nama = "Januari";
	} elseif ($bln == 2) {
		$nama = "februari";
	} elseif ($bln == 3) {
		$nama = "Maret";
	} elseif ($bln == 4) {
		$nama = "April";
	} elseif ($bln == 5) {
		$nama = "Mei";
	} elseif ($bln == 6) {
		$nama = "Juni";
	} elseif ($bln == 7) {
		$nama = "Juli";
	} elseif ($bln == 8) {
		$nama = "Agustus";
	} elseif ($bln == 9) {
		$nama = "September";
	} elseif ($bln == 10) {
		$nama = "Oktober";
	} elseif ($bln == 11) {
		$nama = "November";
	} elseif ($bln == 12) {
		$nama = "Desember";
	}
	return $nama;
}


function jenkas($jk)
{

	global $conn; // panggil koneksi

	$jeniskas = mysqli_query($conn, "SELECT * FROM jenis_kas WHERE id='$jk'");
	$jekas = mysqli_fetch_array($jeniskas);
	$nama = "$jekas[nama]";

	return $nama;
}

function persen($id)
{

	global $conn; // panggil koneksi

	$all = mysqli_fetch_array(mysqli_query($conn, "SELECT SUM(debit) as alldebit, SUM(kredit) as allkredit 
	FROM transaksi"));
	$allsaldo = $all['alldebit'] - $all['allkredit'];


	$perkas = mysqli_fetch_array(mysqli_query($conn, "SELECT SUM(debit) as debit, SUM(kredit) as kredit 
	FROM transaksi WHERE jenis_kas='$id'"));
	$kas = $perkas['debit'] - $perkas['kredit'];

	if ($kas < 0) {
		$persen = $kas / $allsaldo * 100;
		$persen = "minus " . $persen;
	} else {
		$persen = $kas / $allsaldo * 100;
	}



	return number_format($persen, 2, ".", "");
}

function persenbar($id)
{

	global $conn; // panggil koneksi

	$all = mysqli_fetch_array(mysqli_query($conn, "SELECT SUM(debit) as alldebit, SUM(kredit) as allkredit 
	FROM transaksi"));
	$allsaldo = $all['alldebit'] - $all['allkredit'];


	$perkas = mysqli_fetch_array(mysqli_query($conn, "SELECT SUM(debit) as debit, SUM(kredit) as kredit 
	FROM transaksi WHERE jenis_kas='$id'"));
	$kas = $perkas['debit'] - $perkas['kredit'];

	if ($kas < 0) {
		$persen = $kas / $allsaldo * 100;
		$persen = "minus " . $persen;
	} else {
		$persen = $kas / $allsaldo * 100;
	}



	return number_format($persen, 1, ".", "");
}


?>