<?php
$PID = "casher_retur";
session_start();
require_once("../lib/dbconn.php");

/*echo "<pre>";
echo print_r($_POST);
echo "</pre>";*/

$cek1 = getFromTable("select count(id) from tbl_pembayaran");
$id = $cek1 + 1;

$bayar = str_replace(",","",$_POST[bayar]);
$diskon = str_replace(",","",$_POST[diskon]);

$cek2 = getFromTable("select count(no_booking)
	from tbl_pembayaran where tgl_bayar = CURRENT_DATE
	and jns_bayar = 'RETUR' ");
$cek3 = str_pad(((int) $cek2 + 1), 3, "0", STR_PAD_LEFT);
$tgl = date("d");
$bln = date("m");
$thn = date("y");

$kwt = "RET-".$thn.$bln.$tgl.$cek3;

mysql_query("insert into tbl_pembayaran (
			id, tgl_bayar, wkt_bayar, jns_bayar, 
			cara_bayar, nm_pembayar, jml_bayar, diskon, 
			materai, sisa, user_input, no_booking, no_kwitansi) values (
			$id, CURRENT_DATE, CURRENT_TIME, 'RETUR',
			'".$_POST[cab]."', '".$_POST[nm_pembayar]."', $bayar, $diskon,
			0, 0, '".$_SESSION[nama_usr]."', '".$_POST[idx]."', '".$kwt."')");
			
mysql_query("update tbl_booking set down_paymen = 0 where id_booking = '".$_POST[idx]."'");
	?>
<SCRIPT language="JavaScript">
	sWin = window.open('../includes/cetak_retur.php?idx=<?php echo $_POST[idx];?>', 'xWin','top=0,left=0,width=750,height=550,menubar=no,scrollbars=yes');
	sWin.focus();  
</SCRIPT>
<?php
echo "<script language='JavaScript'>document.location='../index2.php?p=casher_retur&idx=".$_POST[idx]."'</script>";
?>