<?php
include "../../inc/inc.koneksi.php";

$tglawal    =$_POST[tglawal];
$tglakhir   =$_POST[tglakhir];

$sql    = mysql_query("SELECT * FROM interface");
$r 	    = mysql_fetch_assoc($sql);
$dobbm		= $r[do_bbm];
$prem   	= $r[premium];
$solar  	= $r[solar];
$ptmx   	= $r[pertamax];
$ptmp   	= $r[ptm_plus];
$ptlt   	= $r[pertalite];
$dex        = $r[ptmn_dex];
$dexlite 	= $r[dexlite];
$solek   	= $r[solar_eko];
$nosubdo	= substr($dobbm,0,3);
$nosubbk	= substr($nobank,0,3);

mysql_query("DELETE FROM rekapjur WHERE jurnal='TBD' AND tanggal BETWEEN '$tglawal' AND '$tglakhir'");

$sql=mysql_query("SELECT * FROM tebus_do WHERE tanggal BETWEEN '$tglawal' AND '$tglakhir' AND batal='' ");

while($r=mysql_fetch_array($sql)){
    $kode	 	=$r[kode_do];
    $tanggal 	=$r[tanggal];
    $nobukti 	=$r[nobukti];
    $nobank 	=$r[nobank];
    $namabank   =$r[namabank];
    $jenis	 	=$r[jenis];
    $jmlliter	=$r[jml_liter];
    $jumlah  	=$r[jml_harga];
    $jmlsetor	=$r[jml_setor];
    $user	 	=$r[user];

    if($jenis=='Premium')
	    $kodest=$prem;
    else if($jenis=='Bio Solar')
	    $kodest=$solar;
    else if($jenis=='Pertamax')
	    $kodest=$ptmx;
    else if($jenis=='Pertamax Turbo')
	    $kodest=$ptmp;
    else if($jenis=='Pertalite')
	    $kodest=$ptlt;
    else if($jenis=='Pertamina Dex')
	    $kodest=$dex;
    else if($jenis=='Dexlite')
	    $kodest=$dexlite;
    else
	    $kodest=$solek;

    $bpdo = $dobbm.substr($kodest,2,4);
    $bppj = $bipajak.substr($kodest,2,4);

    mysql_query("INSERT INTO rekapjur (kode_tr,jurnal,tanggal,no_bukti,no_urut,noakun,nosub,nobp,debet,keterangan,user) VALUES('$kode','TBD','$tanggal','$nobukti','1','$dobbm','$nosubdo','$bpdo','$jumlah','Penebusan DO $jenis $jmlliter liter','$user')");
    mysql_query("INSERT INTO rekapjur (kode_tr,jurnal,tanggal,no_bukti,no_urut,noakun,nosub,kredit,keterangan,user) VALUES('$kode','TBD','$tanggal','$nobukti','1','$nobank','$nosubbk','$jmlsetor','Penebusan DO $jenis $jmlliter liter','$user')");
}
echo "Data penebusan do tanggal $tglawal s/d $tglakhir telah diposting ulang.";
?>
