 <?php  
    include('../koneksi.php');
    include ('../cek_login.php');
    /*ini_set('display_errors',1);
    error_reporting(E_ALL);*/
$username   = $_SESSION['username'];
$laba = "laba ".substr($_POST['tglat'],1,4);
$no_bukti = "AT".$_SESSION['kode'].date("YmdHi");
$tglat= substr($_POST['tglat'],1,4);
$tglat2= $_POST['tglat'];
$print = mysqli_query($koneksi,"SELECT kode_akun,keterangan,kode,id_jurnal, SUM(kredit-debet)AS shu from bukubesar WHERE year(tanggal)='$tglat' AND kode_akun >='4' ");
   $data2 = mysqli_fetch_array($print);
   extract($data2);
                 
   $query = mysqli_query($koneksi,"insert into bukubesar SET id_jurnal='', no_bukti='$no_bukti',tanggal='$tglat2',kode_akun='2.310.05',debet='0',kredit='$shu',keterangan='$laba',kode='$kode',username='$username',tglsystem='$tglnow' ")or die(mysqli_error($koneksi)); 
   echo "Data Berhasil Disimpan";

    if(isset($_POST['id'])) { 
    $checked_array=$_POST['id'];
    foreach ($_POST['id'] as $key => $value) {
    if(in_array($_POST['id'][$key], $checked_array))
    {
$username   = $_SESSION['username'];
$no_bukti = "AT".$_SESSION['kode'].date("YmdHi");
$tgl = $_POST['tgl'][$key];
/*$tgl = date('Y-m-d',strtotime($_POST['tgl']));
*/
$kode_akun = $_POST['kode_akun'][$key];
$kode   = $_SESSION['kode'];
$keterangan = "Akhir Thn".$_POST['tgl'][$key];
$debet = '';
$kredit = str_replace(",", "", $_POST['debet'][$key]);
$tglat= substr($_POST['tglat'],1,4);
$tglat2= $_POST['tglat'];
$laba = "laba ".substr($_POST['tglat'],1,4);

 
    
 
 /*$query = mysqli_query($koneksi,"insert into bukubesar SET id_jurnal='', no_bukti='$no_bukti',tanggal='$tgl',kode_akun='$kode_akun',debet='$debet',kredit='$kredit',keterangan='$keterangan',kode='$kode',username='$username' ")or die(mysqli_error($koneksi)); 
   echo "Data Berhasil Disimpan";*/
    /*https://www.c-sharpcorner.com/UploadFile/051e29/insert-value-from-checkbox-in-database-mysql-in-php/*/ 
    mysqli_query($koneksi,'INSERT INTO
bukubesar(id_jurnal,no_bukti,tanggal,kode_akun,kode,keterangan,debet,kredit,username)
VALUES (
"",
"' . $no_bukti. '",
"' . $tgl. '",
"' . $kode_akun. '",
"' . $kode. '",
"' . $keterangan. '",
"' . $debet. '",
"' . $kredit. '",
"' . $username. '"

)'
)
or die(mysqli_errno($koneksi).':'.mysqli_error($koneksi));
   
    echo "Data Berhasil Disimpan";



         

}   
   } 
    
    }


  
      
?>