<?
	if (isset($_SESSION['valid_admin'])) {
?>

<?
//*********************************************************************************
// Original Website By : Niadesain.com Di Jual melalui http://niadesain.com
// Please Call / SMS : 081384745483 (support@niadesain.com)
// Niadesain.com - Jasa Pembuatan Website Paling Murah dan Paling Lengkap
//*********************************************************************************
?>
<script type="text/javascript">
<!--
function confirmation(mid, page, action) {
	var answer = confirm("Proses Withdrawl tgl : " + mid )
	if (answer){
		//alert("Bye bye!")
		window.location = "?m=withdrawl";
		
	}
	
}
//-->
</script>
<style type="text/css">
<!--
.style1 {
	color: #FF0000;
	font-weight: bold;
}
.style2 {color: #FF0000}
-->
</style>

<h2 align="center"><img src="images/icon-48-user.png" width="48" height="48" align="absmiddle" />Withdrawl dan Pembayaran Komisi </h2>

<?
switch($page) {
	default :
//---pagination----------------
$limit = '50'; // How many results should be shown at a time
$scroll = '0'; // Do you want the scroll function to be on (1 = YES, 2 = NO)
$scrollnumber = '50'; // How many elements to the record bar are shown at a time when the scroll function is on
//-------------pagination--------------
if (!isset ($_GET['show'])) {

	$display = 1;
	
} else {

	$display = $_GET['show'];
	
}
$start = (($display * $limit) - $limit);


//if($uidm == 001) {

//$db->select("*", "member", $kat);
$where = "a.status='$kat'";
if($mid) {
	$wherekom = "userid='$mid'";
}	
if($kat == "") {
	$numrows = $db->count_records("transfer", "");
	$db->select("a.id, a.userid, a.tglminta, a.tglbayar, a.rp, a.status, a.tujuan, b.nama, b.tglaktif, b.bank", "transfer as a inner join banner_kanan as b on a.userid=b.username", $wherekom, "a.id DESC", "", "", "$start, $limit");

} else {
	$numrows = $db->count_records("transfer", $where);	
	$db->select("a.id, a.userid, a.tglminta, a.tglbayar, a.rp, a.status, a.tujuan, b.nama, b.tglaktif, b.bank", "transfer as a inner join banner_kanan as b on a.userid=b.username", $where, "a.id DESC", "", "", "$start, $limit");

}
$sel = "selected";
?>
<table width="1000" border="0" align="center" cellpadding="5" cellspacing="0">
  <tr>
    <td colspan="9" align="center" style="padding:0"><table width="100%" border="0" cellspacing="0" cellpadding="0" style="padding:0; margin:0">
      <tr>
        <td><form action="" method="post" name="form1" id="form1" style="margin:0; padding:0">
          <label> Status Withdrawl :
            <select name="select" onchange="location =  this.options[this.selectedIndex].value" class="form">
            <option value="?m=withdrawl" selected="selected" <? echo $pilih; ?>>Semua</option>
            <option value="?m=withdrawl&amp;kat=0&amp;sel2=<?= $sel; ?>" <? echo $sel2; ?>>Pending</option>
            <option value="?m=withdrawl&amp;kat=1&amp;sel3=<?= $sel; ?>" <? echo $sel3; ?>>Done</option>
          </select>
          </label>
          &nbsp;&nbsp;
        Total: <b><?= $numrows; ?></b> withdrawl
        -<span class="style1"> Transfer komisi sesuai Nominal transfer (Nominal tsb adalah sisa potongan admin dan pph) 
        </span>
        </form></td>
        <td>&nbsp;</td>
      </tr>
    </table></td>
  </tr>
  <tr class="tbl_header">
    <td width="4%" align="center">#</td>
    <td width="9%" align="center">Tanggal</td>
    <td width="10%" align="center">Username</td>
    <td width="20%" align="center">Nama Lengkap</td>
    <td width="21%" align="center">Ditransfer Ke</td>
    
    <td width="13%" align="center">Jumlah Komisi</td>
    <td width="13%" align="center">Withdrawl</td>
    <td width="10%" align="center">Status</td>
  </tr>
<?

$j=$db->num_rows();
$nom =1 + $start;
//while($row = $db->fetch_row()) {
for($i=0;$i<$j;$i++) {
	$user = $db->result($i, "a.userid");
	if(is_odd($i) > 0) {
		$class = "tblrow_ganjil";
	} else {
		$class = "tblrow_genap";
	} 	
	if( $db->result($i, "status") > 0) {
		$aktif = "<a href='#' onclick=\"confirmation('". $db->result($i, "tglbayar")."', 'activation', 'Disable')\" style='cursor:hand'>DONE</a>";
	} else {
		$aktif = "<form name='form3' method='post' action='?m=withdrawl&page=proses&tombol=konfirm'>"
				."<input name='uid' type='hidden' id='uid' value='".$db->result($i, "id")."' size='25' />"
				."<input name='mid' type='hidden' id='mid' value='".$db->result($i, "userid")."' size='25' />"
				."<input name='w' type='hidden' id='w' value='1' size='25' />"
				."<input name='tujuan' type='hidden' id='tujuan' value='".$db->result($i, "tujuan")."' size='25' />"
				."<input name='jumlah' type='hidden' id='jumlah' value='".$db->result($i, "rp")."' size='25' />"
				."<input type='submit' name='button' id='button' value='PROSES' /></form>";
	}
$tgl = $db->result($i, "tglminta");	
$sql=mysql_query("select a.tglaktif, b.paket from banner_kanan as a inner join upline as b on a.username=b.username where a.username='$user'");
$dt = mysql_fetch_row($sql);
$tgaktif = $dt[0];	
$biayatrf = $db->result($i, "rp")*($db->config("potpph"))/100;
$potongan = $db->config("potadmin") + $biayatrf;
$tarikk2 = $db->result($i, "rp") - $potongan;
$dtfrom2 = $tgaktif;
$dtto = date("Y-m-d");
if($dt[1] > 1) {
	$total0 = $db->komisipaket($user, "AND (tglbayar BETWEEN '$dtfrom' AND '$dtto')");	
} else {
	$total0 = $db->totalkomisi( $user, "AND (tglbayar BETWEEN '$tgaktif' AND '".$db->result($i, "tglbayar")."') and status=0");
}	
$widrl = $db->bayarkomisi($user, "AND (tglbayar BETWEEN '$tgaktif' AND '".$db->result($i, "tglbayar")."')");
$total0 = $total0 - $widrl;

	$tujuan = $db->result($i, "tujuan");
$tw = $tw + $total0;
?>
 
  <tr class="<?= $class; ?>">
    <td width="4%"><?= $nom; ?> </td>
    <td width="9%"><?= date("d-m-Y", strtotime( $tgl)); ?></td>
    <td width="10%"><a href="?m=member&page=detilkomisi&bulan=<?= $bln; ?>&tahun=<?= $thn; ?>&mid=<?= $user; ?>"><?=  $user; ?></a></td>
    <td><?= $db->result($i, "nama"); ?></td>
    <td><?= $db->result($i, "bank"); ?></td>
    
    <td align="right"><?= rupiah($total0); ?></td>
    <td align="right">WD: <?= rupiah($db->result($i, "rp")); ?>
      <br />
      <span class="style2">Transfer : 
    <?= rupiah($tarikk2); ?></span> <br />      <br /></td>
    <td align="center"><?= $aktif; ?></td>
  </tr>
<?
	$nom++;
	}
?>	  
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
  <tr>
    <td align="center">
     <?php

//}
//

$paging = ceil ($numrows / $limit);

// Display the navigation
if ($display > 1) {
	
	$previous = $display - 1;
	
?>
  <a href="?m=withdrawl&kat=<?= $kat; ?>&show=1" style="font-size:10px; color:#0000CC"><< Awal </a> | <a href="?m=withdrawl&kat=<?= $kat; ?>&show=<?= $previous; ?>" style="font-size:10px; color:#0000CC">< Sebelumnya </a> |
  <?php

}

if ($numrows != $limit) {
	
	if ($scroll == 1) {
	
		if ($paging > $scrollnumber) {
			
			$first = $display;
			
			$last = ($scrollnumber - 1) + $display;
			
		}
	
	} else {
	
		$first = 1;
			
		$last = $paging;
			
	}
	
	if ($last > $paging ) {
			
		$first = $paging - ($scrollnumber - 1);
			
		$last = $paging;
			
	}
	
	for ($i = $first;$i <= $last;$i++){
		
		if ($display == $i) {
			
?>
[ <b>
<?= $i ?>
</b> ]
<?php
			
		} else {
			
?>
[ <a href="?m=withdrawl&kat=<?= $kat; ?>&show=<?= $i; ?>" style="font-size:10px; color:#0000CC">
<?= $i; ?>
</a> ]
<?php
		
		}
	
	}

}

if ($display < $paging) {

	$next = $display + 1;
	
?>
| <a href="?m=withdrawl&kat=<?= $kat; ?>&show=<?= $next; ?>" style="font-size:10px; color:#0000CC">Selanjutnya ></a> | <a href="?m=withdrawl&kat=<?= $kat; ?>&show=<?= $paging; ?>" style="font-size:10px; color:#0000CC">Terakhir >></a>
<?php

}
//
?>
    </td>
  </tr>
</table>
<?
	break;
	
	case proses :
?>
<h3>Proses Transfer Komisi</h3>
<?
if($tombol == "proses") {
	$kode = kwitansi();
	$tgbyr = date("Y-m-d", strtotime($theDate2));
	$time = (date("H:i:s"));
	$uraian = "transfer komisi untuk $mid via $tujuan";
	if($w == 0) {
			$db->insert("transfer", "", "'', '$mid', '$tgbyr $time', '$tgbyr $time', '$jumlah', 1, '$tujuan', '$kode'");
			//----input ke data transaksi---
		if($tujuan == "bank") {	
			$db->insert("transaksi", "", "'', '$kode', '$mid', '$jumlah', '$clientdate', '$uraian', 0");
		}		
	} else {
		$db->update("transfer", "status=1, tglbayar='$tgbyr $time', kode='$kode'", "id='$uid'");
		//----input ke data transaksi---
			$db->insert("transaksi", "", "'', '$kode', '$mid', '$jumlah', '$clientdate', '$uraian', 0");	
	}	
	
				
?>
<div id="notice"><img src="images/notice-info.png" width="29" height="29" align="absmiddle" />Withdrawl member telah berhasil dicatat ke dalam database! </div>
    <p align="center"><a href="?m=withdrawl">Kembali ke daftar Withdrawl</a></p>
	<?	
		// begin ---- kirim sms notifikasi 
			// www.niadesain.com 
			//require_once('smsclass.php'); // panggil class  
			//$nohp  = $db->dataku("hp", $mid);
			//$pesan = "Selamat! Withdraw anda username: ".$mid.", sebesar: ".rupiah($jumlah)." ,Telah ditransfer ke ".$db->dataku("bank", $mid).".(www.456smartsystem.com)";
			//$sms = new smsreguler();
			//$sms->username = '456smartsystem';
			//$sms->password = 'sm455eys';
			//$sms->apikey   = '63f86892ae30534a2c13ca9055972aff';
			//$sms->setTo($nohp);
			//$sms->setText($pesan);
			//$sts=$sms->smssend();
			// end ----	
?>

<?
	
	//echo $tgbyr;
	
}

if($tombol == "konfirm") {
	$sql=mysql_query("select tglbayar from komisi where username='$mid' order by tglbayar asc");
	$dt = mysql_fetch_row($sql);
	$tgaktif = $dt[0];	
	$dtfrom2 = $tgaktif;
	$dtto = date("Y-m-d H:i:s");
	$total0 = $db->totalkomisi( $mid, "AND (tglbayar BETWEEN '$tgaktif' AND '$dtto') and status=0");
	$widrl = $db->bayarkomisi($mid, "AND (tglbayar BETWEEN '$tgaktif' AND '$dtto')");
	$tarik = $total0 - $widrl;
?>    

<form id="form3" name="form2" method="post" action="?m=withdrawl&amp;page=proses">
  <table width="80%" border="0" align="center" cellpadding="3" cellspacing="0">
    <tr class="tbl_header">
      <td colspan="2" align="center">KONFIRMASI TRANSFER KOMISI</td>
    </tr>
    <tr>
      <td width="46%" align="right">Username :</td>
      <td width="54%"><strong>
        <?= $mid; ?>
      </strong></td>
    </tr>
    <tr>
      <td align="right">Nama member :</td>
      <td><strong>
        <?= $db->dataku("nama", $mid); ?>
      </strong></td>
    </tr>
    <tr>
      <td align="right" valign="top">Ditransfer ke :</td>
      <td><?= $tujuan; ?>
      <input name="tujuan" type="hidden" id="tujuan" value="<?= $tujuan; ?>" size="10" /></td>
    </tr>
    <tr>
      <td align="right">Jumlah WD :</td>
      <td><?
	//  echo $tarik;
		if($jumlah > $tarik) {
			$jml = "<span  style='color:#FF0000'><b>Komisi yang ditransfer melebihi jumlah komisi yang diperoleh</b></span>";
			$dis = "disabled";
		} else {	
			$jml = rupiah($jumlah); 
		}	
	  echo $jml;
	  	
	  ?><label>
        <input name="jumlah" type="hidden" id="jumlah" value="<?= $jumlah; ?>" size="10" />
        <input name="uid" type="hidden" id="uid" value="<?= $uid; ?>" size="10" />
        <input name="tombol" type="hidden" id="tombol" value="proses" size="10" />
        <input name="w" type="hidden" id="w" value="<?= $w; ?>" size="10" />
        <input name="mid" type="hidden" id="mid" value="<?= $mid; ?>" size="10" />
      </label></td>
    </tr>
    <tr>
      <td align="right">Tanggal transfer :</td>
      <td><input name="dis" type="hidden" id="dis" value="disabled" size="12" readonly />
      <input name="theDate2" type="text" id="theDate2" value="<?= date("d-m-Y"); ?>" size="12" readonly />
      </td>
    </tr>
    <tr>
      <td colspan="2" align="center"><label>
        <input type="submit" name="button2" id="button2" value="PROSES" <?= $dis; ?> />
      </label></td>
    </tr>
  </table>
</form>
<?
} else {
?>
<form id="form2" name="form2" method="post" action="?m=withdrawl&page=proses">
  <table width="80%" border="0" align="center" cellpadding="3" cellspacing="0">
    <tr>
      <td width="46%" align="right">Username :</td>
      <td width="54%"><strong><?= $mid; ?></strong></td>
    </tr>
    <tr>
      <td align="right">Nama member :</td>
      <td><strong><?= $db->dataku("nama", $mid); ?></strong></td>
    </tr>
    <tr>
      <td align="right" valign="top">Ditransfer ke :</td>
      <td><label>
        <select name="tujuan" id="tujuan">
          <option value="bank"><?= $db->dataku("bank", $mid); ?></option>
          <option value="E-walet">E-Walet</option>
        </select>
      </label></td>
    </tr>
    <tr>
      <td align="right">Jumlah WD :</td>
      <td><label>
        <input name="jumlah" type="text" id="jumlah" value="<?= $jumlah; ?>" size="10" />
        <input name="uid" type="hidden" id="uid" value="<?= $uid; ?>" size="10" />
        <input name="tombol" type="hidden" id="tombol" value="konfirm" size="10" />
        <input name="w" type="hidden" id="w" value="<?= $w; ?>" size="10" />
        <input name="mid" type="hidden" id="mid" value="<?= $mid; ?>" size="10" />
      </label></td>
    </tr>
    <tr>
      <td align="right">Tanggal transfer :</td>
      <td><input name="theDate2" type="text" value="<?= date("d-m-Y"); ?>" size="12" readonly />
      </td>
    </tr>
    <tr>
      <td colspan="2" align="center"><label>
        <input type="submit" name="button" id="button" value="PROSES" <?= $dis; ?> />
      </label></td>
    </tr>
  </table>
</form>
<?
	}
	break;
}
?>		
<?
} else {
echo "<meta http-equiv=\"refresh\" content=\"1; url=illegal.html\">";
}
?>