<?php
require_once('../wu-engine/wu_init.php');
$page_name = 'Ручной вывод средств';
$page_keys = 'вывод,выплаты';
$page_desc = 'Ручной вывод средств';
$prevurl_1 = '/'.ADMINPATH.'/';
$prevname_1 = 'Панель управления';
$online_title = 'В панели управления';
$online_url = '/';
include('../wu-engine/wu_header.php');
include('../wu-engine/wu-functions/wu_pagination.php');
include('../wu-engine/wu-functions/wu_functions.php');
if(!USER_LOGGED) { header ("Location: /"); exit; }
?>

<div id="modal_stat" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title"><i class="icon-stats"></i> Статистика</h4>
</div>
<div class="modal-body with-padding">
<div id="stat_res"></div>
</div>
<div class="modal-footer">
<button class="btn btn-warning" data-dismiss="modal">Закрыть</button>
</div>
</div>
</div>
</div>

<?php
$num = 20; //Сколько выводить на странице
if (isset($_GET['page'])) { $page = intval($_GET['page']); if ($page == 0) { $page = 1; } } else { $page = 1; }
$qu = mysqli_fetch_assoc(mysqli_query($connect_db, "SELECT count(`id`) AS `cnt` FROM `".DB_PREFIX."_adm_cash_out`"));
$co = $qu['cnt'];
$total = intval(($co - 1) / $num) + 1;
$page = intval($page);
if(empty($page) or $page < 0) $page = 1;
if($page > $total) $page = $total;
$start = $page * $num - $num;
$qr = mysqli_query($connect_db, "SELECT ".DB_PREFIX."_adm_cash_out.id,n,s,dt,ti,log FROM `".DB_PREFIX."_adm_cash_out` INNER JOIN ".DB_PREFIX."_pay_systems ON ".DB_PREFIX."_adm_cash_out.ps = ".DB_PREFIX."_pay_systems.id INNER JOIN ".DB_PREFIX."_users ON ".DB_PREFIX."_adm_cash_out.usr = ".DB_PREFIX."_users.uid ORDER BY id DESC LIMIT $start, $num");
if ($co > 0) {
?>
<div class="panel panel-default img40">
<div class="panel-heading"><h6 class="panel-title"><i class="icon-credit"></i> Заявки на ручной вывод средств</h6></div>
<div class="table-responsive">
<table class="table table-hover text-center">
<thead>
<tr>
<th class="text-center">#</th>
<th class="text-center">Пользователь</th>
<th class="text-center">Платёжная система</th>
<th class="text-center">Номер кошелька</th>
<th class="text-center">Сумма</th>
<th class="text-center">Дата</th>
<th class="text-center">Действия</th>
</tr>
</thead>
<tbody>
<?php while($row = mysqli_fetch_assoc($qr)) { ?>
<tr>
<td><?php echo $row['id']; ?></td>
<td><?php echo $row['log']; ?></td>
<td><?php echo $row['ti']; ?></td>
<td><?php echo $row['n']; ?></td>
<td><?php echo number_format($row['s'],2,'.',','); ?> руб.</td>
<td><?php echo wudate($row['dt']); ?></td>
<td>
<a href="javascript://" onclick="out_ok('<?php echo $row['id']; ?>');" class="btn btn-success btn-small">Выплачено</a>
<a href="javascript://" onclick="out_cancel('<?php echo $row['id']; ?>');" class="btn btn-danger btn-small">Отклонить</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<?php
$pageNav = new SimPageNav();
$pages = ceil($co/$num);
echo $pageNav->getLinks($pages, 1, $page, 10, 'page');
} else { echo '<div class="alert alert-info fade in"><i class="icon-info"></i> Нет заявок на ручной вывод средств</div>'; }
?>

</div>
</div>

<div id="modal_cancel" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title"><i class="icon-remove"></i> Отклонение заявки #<font id="todel"></font></h4>
</div>
<div class="modal-body with-padding">
<label>Введите причину отклонения:</label>
<textarea class="form-control" placeholder="Причина отклонения" id="msg"></textarea>
<select class="form-control" id="fast_enter">
<option selected="" value="sel">Быстрый ввод</option>
<option value="webupper">Отмена выплаты</option>
<option value="webupper">Неверный формат кошелька</option>
<option value="webupper">Блокировка аккаунта</option>
</select>
</div>
<div class="modal-footer">
<button type="button" id="icancel" class="btn btn-danger" data-loading-text="<i class='icon-spinner7 spin'></i> Отклоняем">Отклонить</button>
<button type="button" class="btn btn-warning" data-dismiss="modal">Отмена</button>
</div>
</div>
</div>
</div>


<div id="modal_ok" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog modal-sm">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title"><i class="icon-checkmark3"></i> Подтверждение заявки #<font id="took"></font></h4>
</div>
<div class="modal-body with-padding">
<div class="alert alert-info"><center>Вы действительно произвели выплату?</center></div>
</div>
<div class="modal-footer">
<button type="button" id="iok" class="btn btn-success" data-loading-text="<i class='icon-spinner7 spin'></i> Подтверждаем">Подтвердить</button>
<button type="button" class="btn btn-warning" data-dismiss="modal">Отмена</button>
</div>
</div>
</div>
</div>

<script type="text/javascript">
//Быстрый ввод
$('#fast_enter').bind("change keyup paste input", function() {
if ($(this).val() != 'sel') {
var reas = $('#fast_enter  option:selected').text();
$('#msg').text(reas);
$(this).val('sel');
}
});

//Предудаление заявки
var out_to_del;
function out_cancel(id){
out_to_del = id;
$('#todel').text(id);
$('#modal_cancel').modal('show');
};

//Удаление заявки
$('#icancel').click(function(){
var reas = $('#msg').val();
var data = {'id': out_to_del, 'reas': reas};
wu_response('/wu-engine/wu-actions/adm_cashout_del.php', data, 'icancel', '1', function(wu_result) {
if (wu_result == '0') {
notif_e('Заявка не найдена');
}
if (wu_result == '1') {
$(location).attr('href','/<?php echo ADMINPATH; ?>/cashout');
}
if (wu_result == '2') {
notif_e('Вы не ввели причину отклонения');
}
if (wu_result == 'wu-error') {
wu_err();
}
});
});

//Предподтверждение заявки
var out_to_ok;
function out_ok(id){
out_to_ok = id;
$('#took').text(id);
$('#modal_ok').modal('show');
};

//Подтверждение заявки
$('#iok').click(function(){
var data = {'id': out_to_ok};
wu_response('/wu-engine/wu-actions/adm_cashout_ok.php', data, 'iok', '1', function(wu_result) {
if (wu_result == '0') {
notif_e('Заявка не найдена');
}
if (wu_result == '1') {
$(location).attr('href','/<?php echo ADMINPATH; ?>/cashout');
}
if (wu_result == 'wu-error') {
wu_err();
}
});
});
</script>


<?php include('../wu-engine/wu_footer.php'); ?>