<?php
require_once("conn.php");

$conn = mysqli_connect($db_server, $db_username, $db_password);
mysqli_select_db($conn,$db_database);
if (!$conn) { echo "ERROR#".mysqli_error(); exit; }

$tanggalnya=date("Y-m-d H:i:s");
$kodetrx='';
$kodemutasi='';

$tgl = $_GET['tanggal'];
$idata = mysqli_query($conn,"SELECT * FROM transaksi where kode=(select max(kode) from transaksi where tanggal<='".$tgl." 23:59:59')");
$idata2 = mysqli_query($conn,"SELECT * FROM mutasi where kode=(select max(kode) from mutasi where tanggal<='".$tgl." 23:59:59')");

while ($baris=mysqli_fetch_array($idata))
	{
	$kodetrx= $baris['kode'];
	}

while ($baris=mysqli_fetch_array($idata2))
	{
	$kodemutasi= $baris['kode'];
	}
	
$hps = mysqli_query($conn,"DELETE FROM transaksi where kode<='$kodetrx'");
$hps2 = mysqli_query($conn,"DELETE FROM mutasi where kode<='$kodemutasi'");
$hps3 = mysqli_query($conn,"DELETE FROM trx2");
$hps4 = mysqli_query($conn,"REPAIR TABLE `transaksi`");
$hps5 = mysqli_query($conn,"DELETE FROM notifikasi where tanggal<'".$tgl." 00:00:00'");
$hps6 = mysqli_query($conn,"DELETE FROM csv");
echo $hps;
?>
