<?php
#
# Projeto :  Lucato 
# Data : 20/02/2004
# 
# ROBO Detalhe
#

    //*******************************************************************	
	// INCLUDES nao alterar a ordem dos includes
    //*******************************************************************	
	include "includes/library.php";
	include "includes/session.php";
 	include "includes/top_comum.php";
	
?>
<script>
	
	function cadastro(){
		$("#lista_impostos").hide();
		$("#lista_clientes").hide();
		
		$.post("gravar_configurar_imposto.php",$("#configurar_impostos").serialize()).done(function(data){
			if (data.trim()=="OK"){
				$("#titulo_imposto").html("<h1>Obrigado por configurar o(s) imposto(s) para os cliente(s)</h1>");
			}else{
				$("#modal_formulario").html(data);
				$("#alerta").modal();
				$("#lista_clientes").show();
				$("#lista_impostos").show();
			}
		})
		return false;
	}
	
	
	$(document).ready(function(){
	
	});
	
</script>
<div class="row">
					<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
						<h1 class="page-title txt-color-blueDark"><i class="fa-fw fa fa-desktop"></i> Configure os impostos para os clientes</h1>
					</div>
</div>

<div class="alert alert-warning" role="alert">
		<b>*Nessa listagem só aparecem os clientes que não possuem nenhum imposto configurado.</b><br><br>
		<b>*Marque o grupo dos impostos e na sequência marque os clientes que trabalharão com os impostos selecionados</b>
</div>
<div class="panel panel-default">
  <div class="panel-heading" id="titulo_imposto">Lista de Impostos</div>
		   
		  <form action="#" method="post" id="configurar_impostos" onsubmit="return cadastro()">
		  
		  <div class="panel-body" id="lista_impostos">	
		  
			<table class="table table-bordered">
				<thead>
				<tr>
					<th></th>
					<th>Imposto</th>
					<th>Código Receita</th>
				</tr>
				</thead>
				<tbody>
			<?php
				$sql="SELECT * FROM IMPOSTO ORDER BY ID ";
				$IMP = new QUERY($DATABASE,$sql);
				while ($IMP->NEXT()){
			?>
					<tr>
						<td><input type="checkbox" name="imposto[]"  value="<?php echo $IMP->BYNAME("ID")?>"></td>
						<td><?php echo $IMP->BYNAME("TITULO"); ?></td>
						<td><?php echo $IMP->BYNAME("CODIGO_RECEITA"); ?></td>
					</tr>	
			<?php
				}
			?>
				</tbody>
			</table>
		</div>		
		<script>
			$(document).ready(function(){
				$("#marcar_todos").click(function(){
					$(".clientes").each(function(){
						this.checked = true;
					});
					return false;
				});
				
				$("#desmarcar_todos").click(function(){
					$(".clientes").each(function(){
						this.checked = false;
					});
					return false;
				});
			});
		</script>
		<div class="panel-body" id="lista_clientes">	
		   <a href='#'  id="marcar_todos" class="btn btn-primary btn-sm" style='margin-top:10px;'>MARCAR TODOS</a>	
		   <a href='#' id="desmarcar_todos" class="btn btn-primary btn-sm" style='margin-top:10px;'>DESMARCAR TODOS</a>
		   <br>
		   <br>
 		 	<table class="table table-bordered">
				<thead>
				<tr>
					<th></th>
					<th>Código</th>
					<th>Nome</th>
					<th>Documento</th>
				</tr>
				</thead>
				<tbody>
			<?php
				$sql="SELECT * FROM CLIENTE WHERE IMPORTAR_DADOS='1' ORDER BY ID  ";
				$CLI = new QUERY($DATABASE,$sql);
				while ($CLI->NEXT()){
					$sql="SELECT * FROM CLIENTE_IMPOSTO WHERE CLIENTEID =".$CLI->BYNAME("ID")."";
					$CONSULTA = new QUERY($DATABASE,$sql);
					if (!$CONSULTA->NEXT()){
			?>
					<tr>
						<td><input type="checkbox" name="cliente[]" class="clientes" value="<?php echo $CLI->BYNAME("ID")?>"></td>
						<td><?php echo $CLI->BYNAME("CODIGO"); ?></td>
						<td><?php echo $CLI->BYNAME("NOME"); ?></td>
						<td><?php echo $CLI->BYNAME("CNPJ_CPF"); ?></td>
					</tr>	
			<?php
					}
					$CONSULTA->FREE();
				}
			?>
				</tbody>
			</table>
			<center><input value="Configurar impostos no Net Contábil" class="btn btn-primary btn-sm"  type="submit"></center>
			</form>
		</div>
		
		
		
		<div class="modal fade" id="alerta" data-backdrop="static" data-keyboard="false">
		  <div class="modal-dialog">
			<div class="modal-content">
			  <div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-label="Fechar"><span aria-hidden="true">&times;</span></button>
				<h4 class="modal-title">Consistência</h4>
			  </div>
			  <div class="modal-body" id="modal_formulario">
				
			  </div>
			  <div class="modal-footer">
				<button type="button" class="btn btn-default" data-dismiss="modal">Fechar</button>
			  </div>
			</div><!-- /.modal-content -->
		  </div><!-- /.modal-dialog -->
		</div><!-- /.modal -->
		
	</div>
<?php 	
include("includes/bottom_comum.php"); 
?>