<!DOCTYPE html>
<html lang="en">
<head>
<!-- Main navbar -->
<?php 
use App\Libraries\MyEncrypt;
use App\Helpers\site_helper;
use App\Helpers\form_helper;
$this->db = db_connect();
$this->session = session();
$this->common_model = model('CommonModel');
$this->form_validation =  \Config\Services::validation();

echo view('admin/common_header'); ?>
<!-- /main navbar -->

<!-- select box theme JS files -->
<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/forms/selects/bootstrap_select.min.js');?>"></script>

<!-- Theme JS files -->
<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/tables/datatables/datatables.min.js');?>"></script>
<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/tables/datatables/extensions/responsive.min.js');?>"></script>
<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/forms/selects/select2.min.js');?>"></script>

<script type="text/javascript" src="<?php echo base_url('assets/js/core/app.js');?>"></script>
<script type="text/javascript" src="<?php echo base_url('assets/js/pages/datatables_responsive.js');?>"></script>
<!-- /theme JS files -->

<!-- notify JS files -->
<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/notifications/jgrowl.min.js');?>"></script>

<!-- Theme JS files -->
<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/notifications/bootbox.min.js');?>"></script>
<script type="text/javascript" src="<?php echo base_url('assets/js/plugins/notifications/sweet_alert.min.js');?>"></script>



<style type="text/css">
.icons-list a[data-action="reload1"]:after {
content: '\e9fb';
}
.btns {
padding: 5px;
}
</style>
</head>

<body class="navbar-top-md-md pace-done">

<!-- Fixed navbars wrapper -->
<div class="navbar-fixed-top">

<!-- Main navbar -->
<?php echo view('admin/mainnav'); ?>
<!-- /main navbar -->


<!-- Second navbar -->
<?php echo view('admin/secondnav'); ?>
<!-- /second navbar -->

</div>
<!-- /fixed navbars wrapper -->


<!-- Page header -->
<?php echo view('admin/'.$module_name.'_header'); ?>
<!-- /page header -->


<!-- Page container -->
<div class="page-container">

<!-- Page content -->
<div class="page-content">

<!-- Main content -->
<div class="content-wrapper">

<form method="post" id="pending_withdraw" action="<?php echo $action;?>">
<!-- Basic responsive configuration -->
<div class="panel panel-flat">

<div class="panel-heading">
<div class="col-md-11">
<h5 class=""><?php echo $page_title; ?></h5>
</div>
<div style="clear:both;"><Br></div>


<div id="data_load" style="color:red;" align="center"></div>

<div class="log"></div>

<!-- <div class="col-md-2">
<div class="heading-elements">
<ul class="icons-list">

<li><a data-action="collapse"></a></li>
<li><a data-action="reload"></a></li>
<li><a data-action="close"></a></li>
</ul>
</div>
</div> -->

</div>
<?php $currency_info = defaultcurrency();?>
<?php
$withdraw_data = $this->common_model->GetSettingall('withdraw');

foreach ($withdraw_data as $row) 
{
$withdata[$row->site_key] = $row->site_value;
}


?>

<table class="table datatable-responsive-row-control table-hover">

<thead>
<tr>
<th></th>
<th class=""><?php echo lang('language_lang.lbl_date');?></th>
<th class=""><?php echo lang('language_lang.lbl_transaction_id');?></th>
<th class=""><?php echo lang('language_lang.lbl_user_name');?></th>
<th class=""><?php echo lang('language_lang.lbl_amount');?></th>
<th class=""><?php echo lang('language_lang.lbl_payment_gateway');?></th>
<th class=""><?php echo lang('language_lang.lbl_options');?></th>
</tr>
</thead>
<tbody>
<?php 
if($history) {

$row_count = count($history);

foreach ($history as $row) {


$coinid=$row->currency;

$condition = "coid ='".$coinid."'";
$cointable = $this->common_model->GetRow('coin_info',$condition);
$pay_mode=$cointable->pay_mode;

if($row->ac_mode=='1')
{
if($coinid < 6)
{
if($pay_mode=='5')
$payment_id='7';
else
$payment_id=$coinid;
}
else
{
if($pay_mode=='5')
$payment_id='7';
else if($pay_mode=='6')
$payment_id='8';

}

$private=$form_data['private_key'];

$public=$form_data['public_key'];
$from=$form_data['btc_address'];
$to=$row->address;
$condition = "payment_key in('status') AND payment_id = '".$payment_id."'";
$this->finance_model = model('finance_model');
$payment = $this->finance_model->PaymentName($condition);

// echo $this->db->last_query();
// exit();

$payment_name=$payment->payment_name;
}
else
{
if($cointable->coin_type=='1')
$payment_name="Wire transfer";
else
$payment_name='Wallet Address Pay';
}


if($row->payment_id==1)
{
	$payment_name = "Profit Wallet";
}

if($row->payment_id==2)
{
	$payment_name = "Reward Wallet";
}

if($row->payment_id==3)
{
	$payment_name = "Cash Wallet";
}

$currency=$row->currency;

$find_name=$this->db->query("select * from coin_info where coid='$currency'");
$det=$find_name->getResult();

if($row->bank_name=='')
$bank_name='---';
else
$bank_name=$row->bank_name;

if($row->account_number=='')
$account_number='---';
else
$account_number=$row->account_number;

if($row->swift_code=='')
$swift_code='---';
else
$swift_code=$row->swift_code;

$amount1=$row->amount*100000000;
$usid=$row->uusersid;
$referral1=$this->db->query("SELECT * FROM uusers WHERE uusersid='".$usid."'")->getResult();
$user=$referral1[0];

?>
<tr>
	<?php $myencrypt = new MyEncrypt; ?>
<td></td>
<td class=""><?php echo date('Y-m-d H:i:s', strtotime($row->date));?></td>
<td class=""><?php echo $row->transactionid;?></td>
<td class=""><?php echo $user->email;?></td>
<td class=""><?php echo number_format($row->amount, $det[0]->coin_decimal, '.', '').' USDT';?></td>
<td class=""><?php echo ucfirst($payment_name);?></td>
<td class="text-center">
<a class="btns" data-popup="tooltip" title="<?php echo lang('language_lang.lbl_approve_withdraw');?>"  href="javascript:void(0)" onClick="payouts('<?php echo $myencrypt->encode($row->historyid);?>')" ><i class="fa fa-thumbs-up"></i></a>

<a class="btns" data-popup="tooltip" title="<?php echo lang('language_lang.lbl_cancel_withdraw');?>"  href="javascript:void(0)" onClick="cancelpayouts('<?php echo $myencrypt->encode($row->historyid);?>')" ><i class="fa fa-thumbs-down"></i></a>
</td>
</tr>
<?php 
}

}  
else 
{ 
?>

<?php 
} 
?>
</tbody>
</table>

</div>
</form>


</div>
<!-- /main content -->

</div>
<!-- /page content -->


<!-- Footer -->
<div class="footer text-muted">
<?php echo site_footer();?>
</div>
<!-- /footer -->

</div>
<!-- /page container -->
<!--<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>-->
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">

(function($) {

$(document).ready(function() {

$('.datatable-responsive-withdraw').DataTable({
responsive: {
details: {
type: 'column',
target: 'tr'
}
},
columnDefs: [
{
className: 'control',
orderable: false,
targets:   0
},
{ 
width: "100px",
targets: [8]
},
{ 
orderable: false,
targets: [8]
},
{ 
orderable: false,
targets: [1]
}
],
order: [2, 'asc']

});

$.jGrowl.defaults.closer = false;


<?php if($this->session->getFlashData('error_message')) { ?>
$.jGrowl("<?php echo $this->session->getFlashData('error_message');?>", {
header: '<?php echo lang("language_lang.error");?>',
theme: 'bg-danger'
});
<?php } ?>

<?php if($this->session->getFlashData('success_message')) { ?>
$.jGrowl("<?php echo $this->session->getFlashData('success_message');?>", {
header: '<?php echo lang("language_lang.success");?>',
theme: 'bg-success'
});
<?php } ?>



$('#icon-bck').on('click',function() {
window.history.back();
});

$('#checkall').on('click', function() {
if($('#checkall').prop('checked'))
$(':checkbox').prop('checked', true);
else
$(':checkbox').prop('checked', false);
})

$('.panel [data-action=reload1]').click(function (e) {
e.preventDefault();
var block = $(this).parent().parent().parent().parent().parent();
jQuery.ajax({
url:'<?php echo base_url();?>admin/finance/pendingwithdraw',
beforeSend: function() {
$(block).block({ 
message: '<i class="icon-spinner2 spinner"></i>',
overlayCSS: {
backgroundColor: '#fff',
opacity: 0.8,
cursor: 'wait',
'box-shadow': '0 0 0 1px #ddd'
},
css: {
border: 0,
padding: 0,
backgroundColor: 'none'
}
});
$('.panel .panel-heading').find('.dataTables_wrapper').remove();

$('#DataTables_Table_0_wrapper').remove();
},
complete: function() {
$(block).unblock();
},
success : function(resp)
{
$('.panel .panel-heading').after(resp);
location.reload();
}
});

});

});

})(jQuery);

function PaySelected() {

if(jQuery('.case:checked').length) {
jQuery.ajax({
type: 'post',
url : '<?php echo base_url('admin/masspayout/pendingwithdraw');?>',
// data : jQuery('#pending_withdraw').serialize(),
data : jQuery('input[type=\'checkbox\']'),

beforeSend: function(){

$('.panel').block({ 
message: '<i class="icon-spinner2 spinner"></i>',
overlayCSS: {
backgroundColor: '#fff',
opacity: 0.8,
cursor: 'wait',
'box-shadow': '0 0 0 1px #ddd'
},
css: {
border: 0,
padding: 0,
backgroundColor: 'none'
}
});

},
success : function(resp)
{
if(resp) {

console.log(resp);
console.log({elapsed_time});
}
},
complete: function(){
jQuery('.panel').unblock();
}
}); 
} else {
console.log('no box checked');
}
}

function payouts(id) {



document.getElementById('data_load').innerHTML='Please Wait Payment Processing.......';



$.ajax({
url: "<?php echo base_url('admin/masspayout/singleuserpay_internal');?>",
type: "post",
data: {'id':id} ,
success: function (response) {
//document.getElementById('data_load').innerHTML='';

//location.reload();
window.location="<?php echo base_url();?>/admin/finance/pendingpayouts";

},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
}
});

}

function cancelpayouts(id) 
{

/*swal({
title: "An input!",
text: "Write something interesting:",
input: 'text',
showCancelButton: true ,
},
function(inputValue){
if (inputValue === false) {
return false;
} else {
	//window.location.href = "<?php echo base_url('admin/masspayout/Deleterequest/');?>"+'/'+id;
}
});*/

swal({
title: "Confirm Reject",
text: "Enter Reason For Reject:",
type: "input",
showCancelButton: true,
closeOnConfirm: false,
animation: "slide-from-top"
},
function(inputValue){
if (inputValue === false) return false;
	if (inputValue === "") {
swal.showInputError("You need to write something!");
return false
}
//swal("Nice!", "You wrote: " + inputValue, "success");
$.ajax({
url: "<?php echo base_url('admin/masspayout/Deleterequest/');?>",
type: "post",
data: {'id':id,'text':inputValue} ,
success: function (response) {
window.location="<?php echo base_url();?>/admin/finance/pendingpayouts";

},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
}
});


}
);

}

</script>
</body>
</html>
