<?php include('fncr-geral/configuracao_geral.php');
$pagina = "gameid";
$blq_pag = "gameid";
include('fncr-geral/permissoes_restricao.php');

/*
// Registros da agenda
$sql_registros = $bd->getConexao()->prepare('
SELECT clubes_agenda.*,
  clubes_agenda_acao.descricao,
  clubes.id as clube_id,
  clubes.nome as clube,
  clubes.cancelado,
  clubes.bloqueio,
  clubes.data_cadastro,
  clubes.light,
  clubes.cidade,
  clubes.uf,
  clubes.status as status_clube,
  DATE_FORMAT(clubes_agenda.data_cadastro,"%d/%m/%Y") AS cadastro,
  DATE_FORMAT(clubes_agenda.data_agendado,"%d/%m/%Y") AS agendado,
  DATE_FORMAT(clubes_agenda.data_realizado,"%d/%m/%Y") AS realizado,
  agenda.qtd_acoes_agenda
  FROM clubes_agenda
    LEFT JOIN clubes ON clubes.id = clubes_agenda.id_clube
    LEFT JOIN clubes_agenda_acao ON clubes_agenda_acao.id = clubes_agenda.id_acao
    LEFT JOIN (
            SELECT id_clube, count(DISTINCT id) as qtd_acoes_agenda
            FROM clubes_agenda
            WHERE status = 1
            GROUP BY id_clube
          ) agenda on agenda.id_clube = clubes.id
  WHERE data_agendado BETWEEN (:sql_data_ini) AND (:sql_data_fim)
  ORDER BY data_agendado ASC');
$sql_registros->bindValue(':sql_data_ini', $sql_data_ini, PDO::PARAM_STR);
$sql_registros->bindValue(':sql_data_fim', $sql_data_fim, PDO::PARAM_STR);
if( $sql_registros->execute() ) { $resul_registros = $sql_registros->fetchall(PDO::FETCH_ASSOC);}
*/

if(isset($_POST['gameid']) && $_POST['gameid'] == 'config_forma_pgto') {

  foreach($_POST['ev_liberado'] as $id_fpgto=>$value){
    $sql = $bd->getConexao()->prepare('UPDATE gameid_formas_pgto SET
      ev_liberado = :ev_liberado,
      ev_txconv = :ev_txconv,
      ev_txconv_valor = :ev_txconv_valor,
      ev_txop_percent = :ev_txop_percent,
      clube_liberado = :clube_liberado,
      clube_txconv = :clube_txconv,
      clube_txconv_valor = :clube_txconv_valor,
      clube_txop_percent = :clube_txop_percent
    WHERE id = :id');
    $sql->bindValue(':ev_liberado', $_POST['ev_liberado'][$id_fpgto], PDO::PARAM_STR);
    $sql->bindValue(':ev_txconv', $_POST['ev_txconv'][$id_fpgto], PDO::PARAM_STR);
    $sql->bindValue(':ev_txconv_valor', $_POST['ev_txconv_valor'][$id_fpgto], PDO::PARAM_STR);
    $sql->bindValue(':ev_txop_percent', $_POST['ev_txop_percent'][$id_fpgto], PDO::PARAM_STR);
    $sql->bindValue(':clube_liberado', $_POST['clube_liberado'][$id_fpgto], PDO::PARAM_STR);
    $sql->bindValue(':clube_txconv', $_POST['clube_txconv'][$id_fpgto], PDO::PARAM_STR);
    $sql->bindValue(':clube_txconv_valor', $_POST['clube_txconv_valor'][$id_fpgto], PDO::PARAM_STR);
    $sql->bindValue(':clube_txop_percent', $_POST['clube_txop_percent'][$id_fpgto], PDO::PARAM_STR);
    $sql->bindValue(':id', $id_fpgto, PDO::PARAM_STR);
    if( $sql->execute() );
  }

  $mensagem = "ok";
}

$sql = $bd->getConexao()->prepare('
SELECT
  pg.*,
  serv.nome as servico
FROM gameid_formas_pgto pg
  LEFT JOIN pgtos_ext_formas_pgto ext ON ext.id = pg.pgto_ext_id
  LEFT JOIN pgtos_ext_servico serv ON serv.id = ext.ext_servico_id');
if($sql->execute()){$resul_gameid_formas_pgto = $sql->fetchall(PDO::FETCH_ASSOC);}


?>
<!DOCTYPE html>
<html lang="pt-br">
<head>
    <?php include('fncr-geral/html-head.php');?>

<script type="text/javascript">


</script>

</head>
<body>

<!-- BARRA SUPERIOR -->
<?php include('barra-sup.php');?>
<!-- MENU PRINCIPAL -->
<?php include('menu.php');?>

<section id="content">

<div class="clearfix padder bg-fncr-clearfix">
<h3 class="m-b">GameID</h3>
</div>

<section id="content" class="content-sidebar bg-white" style="padding-bottom: 100px">
<section class="main">
<br>

  <div class="col-lg-10">

    <form method="post" action="" data-validate="parsley" enctype="multipart/form-data">
      <input type="hidden" name="gameid" value="config_forma_pgto"/>
      <section class="panel">
        <header class="panel-heading">
          <button type="submit" class="btn btn-sm btn-primary text-center pull-right">SALVAR</button>
          <div style="margin-top: 5px">Configurações - Formas de Pagamento</div>
        </header>
        <div class="table-responsive">
          <table class="table table-striped b-t text-small">
            <thead>
            <tr>
              <th width="20" rowspan="2">ID</th>
              <th rowspan="2">Forma Pgto</th>
              <th class="text-center" colspan="2">Tipo</th>
              <th class="text-center" colspan="4">Evento</th>
              <th class="text-center" colspan="4">Clube</th>
            </tr>
            <tr>
              <th class="text-center" width="150">Operação</th>
              <th class="text-center" width="100">Serviço</th>
              <th class="text-center" width="120">Liberado</th>
              <th class="text-center" width="120">Taxa Conv.</th>
              <th class="text-center" width="120">Taxa Conv. (R$)</th>
              <th class="text-center" width="120">Taxa Op. (%)</th>
              <th class="text-center" width="120">Liberado</th>
              <th class="text-center" width="120">Taxa Conv.</th>
              <th class="text-center" width="120">Taxa Conv. (R$)</th>
              <th class="text-center" width="120">Taxa Op. (%)</th>
            </tr>
            </thead>
            <tbody>
            <?php foreach($resul_gameid_formas_pgto as $l){ $k=$l['id'];
              $tipo = $l['intermediado'] ? "<i class='fa fa-retweet' style='color: #0F769F'></i> Intermediado" : "<i class='fa fa-bank' style='color: #07c400'></i> Clube";
              if($l['pgto_ext_id']>0) $tipo = "<i class='fa fa-external-link' style='color: #aa00c4'></i> Pgto Externo"
            ?>
              <tr>
                <td><?php echo $l['id']?></td>
                <td><?php echo $l['nome']?></td>
                <td><?php echo $tipo?></td>
                <td><?php echo $l['pgto_ext_id']>0 ? $l['servico'] : ""?></td>
                <td style="padding: 0">
                  <select class="form-control" name="ev_liberado[<?php echo $k?>]" style="width: 100%">
                    <option value="0" <?php echo $l['ev_liberado']==0 ? 'selected' : ''; ?>>Bloqueado</option>
                    <option value="1" <?php echo $l['ev_liberado']==1 ? 'selected' : ''; ?>>Liberado</option>
                  </select>
                </td>
                <td style="padding: 0">
                  <select class="form-control" name="ev_txconv[<?php echo $k?>]" style="width: 100%">
                    <option value="0" <?php echo $l['ev_txconv']==0 ? 'selected' : ''; ?>>Isento</option>
                    <option value="1" <?php echo $l['ev_txconv']==1 ? 'selected' : ''; ?>>Cobrar</option>
                  </select>
                </td>
                <td style="padding: 0">
                  <input type="text" name="ev_txconv_valor[<?php echo $k?>]" class="form-control text-center" value="<?php echo echomoeda($l['ev_txconv_valor'])?>" style="height: 30px">
                </td>
                <td style="padding: 0">
                  <input type="text" name="ev_txop_percent[<?php echo $k?>]" class="form-control text-center" value="<?php echo echomoeda($l['ev_txop_percent'])?>" style="height: 30px">
                </td>
                <td style="padding: 0">
                  <select class="form-control" name="clube_liberado[<?php echo $k?>]" style="width: 100%">
                    <option value="0" <?php echo $l['clube_liberado']==0 ? 'selected' : ''; ?>>Bloqueado</option>
                    <option value="1" <?php echo $l['clube_liberado']==1 ? 'selected' : ''; ?>>Liberado</option>
                  </select>
                </td>
                <td style="padding: 0">
                  <select class="form-control" name="clube_txconv[<?php echo $k?>]" style="width: 100%">
                    <option value="0" <?php echo $l['clube_txconv']==0 ? 'selected' : ''; ?>>Isento</option>
                    <option value="1" <?php echo $l['clube_txconv']==1 ? 'selected' : ''; ?>>Cobrar</option>
                  </select>
                </td>
                <td style="padding: 0">
                  <input type="text" name="clube_txconv_valor[<?php echo $k?>]" class="form-control text-center" value="<?php echo echomoeda($l['clube_txconv_valor'])?>" style="height: 30px">
                </td>
                <td style="padding: 0">
                  <input type="text" name="clube_txop_percent[<?php echo $k?>]" class="form-control text-center" value="<?php echo echomoeda($l['clube_txop_percent'])?>" style="height: 30px">
                </td>
              </tr>
            <?php } ?>
            </tbody>
          </table>
        </div>
      </section>
    </form>

  </div>

</section>
</section>
</section>

<!-- FOOTER -->
<?php include('footer.php');?>

<!-- app -->
<script src="js/app.js"></script>
<script src="js/app.plugin.js"></script>
<script src="js/app.data.js"></script>
<!-- Sparkline Chart -->
<script src="js/charts/sparkline/jquery.sparkline.min.js"></script>
<!-- Easy Pie Chart -->
<script src="js/charts/easypiechart/jquery.easy-pie-chart.js"></script>
  <!-- select2 -->
<script src="js/select2/select2.min.js"></script>
  <!-- fuelux -->
<script src="js/fuelux/fuelux.js"></script>
<!-- datepicker -->
<script src="js/datepicker/bootstrap-datepicker.js"></script>
<!-- slider -->
<script src="js/slider/bootstrap-slider.js"></script>
<!-- file input -->
<script src="js/file-input/bootstrap.file-input.js"></script>
<!-- combodate -->
<script src="js/combodate/moment.min.js"></script>
<script src="js/combodate/combodate.js"></script>
<!-- parsley -->
<script src="js/parsley/parsley.min.js"></script>

</body>
</html>
<?php $bd = null; $bd_fn = null;?>