<?php
include '../../config/conn.php';

//untuk saldo aman
$saldoaman = mysqli_query($conn, "SELECT * FROM pengaturan_emoney WHERE id='1'");
$aman = mysqli_fetch_array($saldoaman);

$id = $_POST['selector'];
$N = count($id);
for ($i = 0; $i < $N; $i++) {
    $idtran = id_transaksi();

    $tgl = date('Y-m-d', strtotime($_POST['tanggal']));

    $jen = '4';
    $save = mysqli_query($conn, "INSERT INTO transaksi_ewallet(id_transaksi,
                                  rekening,
                                  tgl_transaksi,
                                  debit,
                                  kredit,
                                  keterangan,user_id,jenis) VALUES('$idtran',
                                                 '$id[$i]',
                                                 '$tgl',
                                                 '0',
                                                 '$aman[tarik_serentak]',
                                                 '$_POST[keterangan]','$_SESSION[id]','$jen')");
}

// echo "<script language='javascript'>document.location='?module=pembayaran-dam&aksi=tambah_dam&id=$id_san';</script>";
if (!$save) {
    echo "gagal";
    echo "<script>nSimpan('?module=proses-tarik-serentak');</script>";
} else {
    historysimpan($_POST['id'], $_SESSION['id'], $_SESSION['mac'], $jen);
    echo "<script>ySimpan('?module=proses-tarik-serentak');</script>";
    echo "sukses";
}
