<?php
error_reporting(0);
date_default_timezone_set('Asia/Jakarta');

include("common.php");
include("classMySQL.php");
$db = new db_mysql($server_name, $userdb, $passdb, $databasename,"");
include("function.php");
require_once('class.phpmailer.php');
include("class.smtp.php");

mysql_connect($server_name, $userdb, $passdb) or die ("Could not connect to database");
mysql_select_db($databasename);
?>
<?php
$sqlccc="SELECT * FROM member WHERE status='1'"; 
$dtccc=mysql_query($sqlccc);
if($dtccc === FALSE) {
    die(mysql_error());
}
 while($rowccc= mysql_fetch_array($dtccc)){
  $usernamez = $rowccc['username'];
 $setpaketz = $rowccc['harga'];
  if($setpaketz == 1){
$flushnyax = $flushnya1; 
}else if($setpaketz == 2){	  
$flushnyax = $flushnya2;
}else if($setpaketz == 3){	  
$flushnyax = $flushnya3;
}else if($setpaketz == 4){	  
$flushnyax = $flushnya4;
}else if($setpaketz == 5){	  
$flushnyax = $flushnya5;
}else if($setpaketz == 6){	  
$flushnyax = $flushnya6;
}else if($setpaketz == 7){	  
$flushnyax = $flushnya7;
}else if($setpaketz == 8){	  
$flushnyax = $flushnya8;
}else if($setpaketz == 9){	  
$flushnyax = $flushnya9;
}else if($setpaketz == 10){	  
$flushnyax = $flushnya10;
}else{}


$trans_codex = substr(str_shuffle(str_repeat("WZTYG31113I3N16ZU3F4248V2JY1Q86NYRIL233V5JD3U356BG3Q182Y5I2J598C3VPJ8S213MI741UD84Z1Z", 32)), 6, 11);

$omsetkirix=omsetkiri($usernamez);
$omsetkananx=omsetkanan($usernamez);
$totpas = total_pasangan($usernamez);
$totflush=total_flush_member($usernamez);
$totaldiambil=total_pasangan_diambil($usernamez);
$diambil = $totaldiambil+$totflush;
$omsetkirinya = $omsetkirix-$diambil;
$omsetkananya = $omsetkananx-$diambil;

if($omsetkirinya < $omsetkananya){
$omsetkakikecil=$omsetkirinya;
}else{
$omsetkakikecil=$omsetkananya;
}



$kompasangannya=($komisi_pasangane/100)*$omsetkakikecil;
$tgl_skre = (date("Y-m-d"));
$dtfrome = "$tgl_skre 00:00:00";
$dttoe = "$tgl_skre 23:59:59";
$cekflushnya=total_pasangan_flush($usernamez, $dtfrome, $dttoe);
$batasflush = $flushnyax-$cekflushnya;

if($batasflush > 0){
	
	if($kompasangannya > 0){

	if($kompasangannya > $batasflush){
		$bonuspasangan = $batasflush;
	}else{
		$bonuspasangan = $kompasangannya;
	}

$getebnps=(100/$komisi_pasangane);
$getflusnya = $bonuspasangan*$getebnps;
$flushdata = $omsetkakikecil-$getflusnya;
if($bonuspasangan > 0){	

$jenis = "Pairing bonus ".$komisi_pasangane."% from omset small leg ".rupiah($omsetkakikecil)."";

//$tocashpoin=(50/100)*$bonuspasangan;
//$topurchase=(20/100)*$bonuspasangan;
//$toregister=(50/100)*$bonuspasangan;


$db->insert("komisi", "", "'', '$usernamez', '$bonuspasangan', '$clientdate', '0', '', 'kompasangan', 'administrator', '".$trans_codex."_ps', ''");
//$db->insert("dataewalet", "", "'', '".$trans_codex."_ps', 'administrator', '$bonuspasangan', 'Pairing bonus', '$usernamez', '$clientdate', 1, '$clientdate'");
//$db->insert("databwalet", "", "'', '".$trans_codex."_ps', 'administrator', '$tocashpoin', '50% Pairing Bonus', '$usernamez', '$clientdate', 1, '$clientdate'");
//$db->insert("datadwalet", "", "'', '".$trans_codex."_ps', 'administrator', '$topurchase', '20% Pairing bonus', '$usernamez', '$clientdate', 1, '$clientdate'");
//$db->insert("datacwalet", "", "'', '".$trans_codex."_ps', 'administrator', '$toregister', '50% Pairing bonus', '$usernamez', '$clientdate', 1, '$clientdate'");



















$db->insert("datapass", "", "'', '".$trans_codex."_ps', '$usernamez', '$omsetkirinya', '$omsetkananya', '$omsetkakikecil', '$kompasangannya', '$bonuspasangan', '$batasflush', '$flushdata', '$totflush', '$totaldiambil', '$cekflushnya', '$totpas', '$omsetkananx', '$omsetkirix'");




$db->insert("totpass", "", "'', '$usernamez', '$getflusnya', '$clientdate', '$trans_codex'");





}
if($flushdata > 0){	
$db->insert("flushdata", "", "'', '".$trans_codex."_ps', '$usernamez', '$flushdata', '$clientdate'");
}
}
}else {
if($omsetkakikecil > 0){		
$db->insert("flushdata", "", "'', '".$trans_codex."_ps', '$usernamez', '$omsetkakikecil', '$clientdate'");
}
}
} 
?>

<?php
mysql_close();
?>
