<?php 	
	include('conexao.php');
	session_start();

	if(!isset($_SESSION["login"]) || !isset($_SESSION["senha"])){
		header("Location: cuide.php");
		exit;	
	}
	
	?> 
<!doctype html>
<html lang="fr">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
  <title>SiGA</title>
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300italic,700,700italic">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.1/css/all.css" integrity="sha384-50oBUHEmvpQ+1lW4y57PTFmhCaXp0ML5d60M1M7uH2+nqUivzIebhndOJK28anvf" crossorigin="anonymous">
  <link rel="stylesheet" href="assets/css/milligram/milligram.min.css">
  <link rel="stylesheet" href="assets/css/omega.css">
  <link rel="stylesheet" href="assets/css/style.css">
  
</head>
<body id="app">
<?php include("menu.php");?>
<main>
<section>
	Ol&aacute;: <?php include('logado.php');?>
</section>
<div class="container">
<p>&nbsp;&nbsp;&nbsp;&nbsp;<span class="chapter">Cobrança</span>Vendedores registados</p>
<div class="bloc">
<div class="bloc--content">

<p>

	<?php
	include ("conexao.php");
	
	if(isset($_POST['proc']))
	{
		$cod = $_POST['proc'];
		$sql = mysqli_query($mysqli,"SELECT m.nome,m.mercado, m.codigo, m.tipotaxa,t.id, t.periodo, t.taxa
		FROM msing m
		INNER JOIN taxas t ON t.id = m.tipotaxa
		WHERE m.codigo =$cod");
		$result = mysqli_fetch_array($sql);
		$mer=$result['mercado'];
        $rr=mysqli_num_rows($sql);
        
        if($rr<1){
		
	        echo '<div class="alert alert-danger alert-dismissible">
                  <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                  A consulta não obteve resultado.</div>
                </div>';
	    }
		else{
		$r=mysqli_query($mysqli,"SELECT * from mercados where id=$mer");
		$res = mysqli_fetch_array($r);$ms=$res['nome'];

    ?>
	<script language="JavaScript"> 
		function taxatotal() 
		{
			form.pago.value = (form.taxa.value*1) + (form.multa.value*1);
			form.pago2.value = (((form.taxa.value*1) + (form.multa.value*1)).toFixed(2));
			var mesx = form.mes.value;
			form.mesp.value = mesx.substr(1,2);
		}
		function datar()
			{
			var dia = form.data.value;
            var mes = form.data.value;
            //var mes = form.data.value;
            /*var mes = data.substr(5,7);
            var ms = data.substr(4,4);
            form.mes.value = ms;*/
			form.dia.value = dia.substr(8,9);
            form.mes.value = mes.substr(4,4);
			}
	</script>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

<script  type="text/javascript">
$(function() {
    $( "#dia" ).datepicker({
	dateFormat: 'yy-mm-dd',
	dayNames: ['Domingo','Segunda','Terça','Quarta','Quinta','Sexta','Sábado','Domingo'],
	dayNamesMin: ['Dom','Seg','Ter','Qua','Qui','Sex','S&aacute;b','Dom'],
	dayNamesShort: ['Dom','Seg','Ter','Qua','Qui','Sex','Sáb','Dom'],
	monthNamesShort: ['Janeiro','Fevereiro','Mar&ccedil;o','Abril','Maio','Junho','Julho','Agosto','Setembro','Outubro','Novembro','Dezembro'],
        showOn: "button",
        buttonImage: "images/calendario.png",
        buttonImageOnly: true,
		changeMonth: true,
        changeYear: true
    });
});
</script>
	<br><br>
	<form name="form" method="post" action="paga.php?cod=msing">
	<div class="form-group">
	 <label for="usr">Name do comerciante:</label>
	 <input name="nome" class="form-control" type="text" value="<?php print $result['nome']?>" readonly>
	 <input name="id" class="form-control" type="hidden" value="<?php print $result['codigo']?>" readonly>
	 <input name="agente" class="form-control" type="hidden" value="<?php print $Nome?>" readonly>
	 <input name="mercado" class="form-control" type="hidden" value="<?php print $mer?>" readonly>
	 </div>	
	<div class="form-group">
	 <input name="" class="form-control" type="hidden" value="<?php print $ms?>" readonly>
	 <input name="taxa" class="form-control" type="hidden" value="<?php print $result['taxa']?>" readonly>
	 </div>
	<div class="form-group">
	 <input name="" class="form-control" type="hidden" value="<?php print number_format($result['taxa'],2)?>" readonly>
	 <input type="hidden" class="form-control" name="data" value="<?php echo date('Y-m-d');?>">
	 </div>
    <div class="form-group">
	 <label for="usr">Mes ref.:</label>
	 <select name="refer" required class="form-control" >
		<option value=" "> -- Mes 
		<?php
            $sql = "SELECT * FROM meses ORDER BY id";
            $res = mysqli_query($mysqli, $sql );
            while ( $row = mysqli_fetch_assoc( $res ) ) {
                    echo '<option value="'.$row['id'].'">'.$row['mes'].'</option>';
            }
        ?>
		</select>
	 </div>
	<div class="form-group">
	 <label for="usr">Multa aplicado:</label>
	 <input name="multa" class="form-control" type="text" value="0" onBlur="taxatotal()" autocomplete="off" autofocus="true">
	 <input name="pago" class="form-control" type="hidden" value="<?php print $result['taxa']?>" readonly>
	 </div>
	 
	<div class="form-group">
	 <label for="usr">Valor a pagar:</label>
	 <input name="pago2" class="form-control" type="text" value="<?php print number_format($result['taxa'],2)?>" readonly>
	 </div>
	<br>
	<div class="form-group">
	<input name="pgmr" class="btn btn-primary" type="submit" value="Pagamento">
	</div><br>
	</form>
	
	<?php 
            
        }
	    
	    }else{
        ?>
    	<form action="#" method="post" data-toggle="validator" role="form">
		<input type="number"  class="form-control" name="proc"  placeholder="Procurar pelo codigo do comerciante" onfocus="this.value='';" autocomplete="off" data-error="Por favor, informe um e-mail correto." required>	    
		<div class="help-block with-errors"></div><br>
		 <input type="submit" class="btn btn-primary" value="Procurar">
	</form>
    <?php
    }
	?>
	</div>
</div>
</div>
</main>
<script defer src="https://use.fontawesome.com/releases/v5.8.1/js/all.js" integrity="sha384-g5uSoOSBd7KkhAMlnQILrecXvzst9TdC09/VM+pjDTCM+1il8RHz5fKANTFFb+gQ" crossorigin="anonymous"></script>
<script src="assets/js/omega.js"></script>
</body>
</html>