<?php
error_reporting(0);
ini_set(“display_errors”, 0);
include "protege_professor.php";

function converterdata($dateSql)
{
	$ano = substr($dateSql, 6);
	$mes = substr($dateSql, 3, -5);
	$dia = substr($dateSql, 0, -8);
	return $ano . "-" . $mes . "-" . $dia;
}

function forma_pagamento($id)
{
	include "conexao.php";
	$query_amigo = "SELECT * FROM forma_pagamento where idforma_pagamento = $id";
	$executa_query = mysqli_query($db, $query_amigo);

	while ($buscar_amigo = mysqli_fetch_assoc($executa_query)) {
		$descricao           = $buscar_amigo["descricao"];
	}
	return $descricao;
}

function retorna_dados_cliente($id, $idvenda, $tipo_venda)
{

	if ($tipo_venda == 2) {
		$inner = "INNER JOIN venda ON venda.idvenda = parcelas.venda_idvenda
		INNER JOIN lote ON venda.lote_idlote = lote.idlote
		INNER JOIN produto ON venda.produto_idproduto = produto.idproduto
		INNER JOIN empreendimento ON produto.empreendimento_idempreendimento = empreendimento.idempreendimento 
		INNER JOIN empreendimento_cadastro ON empreendimento.empreendimento_cadastro_id = empreendimento_cadastro.idempreendimento_cadastro";
		$tabela_inner = "venda.cliente_idcliente";
		$juros_hr = "0200";
	}
	if ($tipo_venda == 3) {
		$inner = "INNER JOIN contrato_pagar ON contrato_pagar.idcontrato_pagar = parcelas.venda_idvenda

		INNER JOIN empreendimento ON contrato_pagar.empreendimento_id = empreendimento.idempreendimento 
		INNER JOIN empreendimento_cadastro ON empreendimento.empreendimento_cadastro_id = empreendimento_cadastro.idempreendimento_cadastro";
		$tabela_inner = "contrato_pagar.fornecedor_idfornecedor";
		$juros_hr  = "0200";
	}
	if ($tipo_venda == 1) {
		$inner = "INNER JOIN locacao ON locacao.idlocacao = parcelas.venda_idvenda INNER JOIN imovel ON locacao.imovel_idimovel = imovel.idimovel";
		$tabela_inner = "locacao.cliente_idcliente";
		$juros_hr = "1000";
	}
	if ($tipo_venda == 4) {
		$inner = "INNER JOIN contrato_receber ON contrato_receber.idcontrato_receber = parcelas.venda_idvenda

		INNER JOIN empreendimento ON contrato_receber.empreendimento_id = empreendimento.idempreendimento 
		INNER JOIN empreendimento_cadastro ON empreendimento.empreendimento_cadastro_id = empreendimento_cadastro.idempreendimento_cadastro";

		$tabela_inner = "contrato_receber.cliente_idcliente";
		$juros_hr  = "0200";
	}

	$wes_hoje = date("dmy");
	include "conexao.php";
	$query_amigo323 = "SELECT * FROM parcelas " . $inner . "  

	INNER JOIN cliente ON " . $tabela_inner . " = cliente.idcliente
	WHERE idparcelas = $id";

    // echo $query_amigo323; die();

	$executa_query323 = mysqli_query($db, $query_amigo323) or die("Erro ao listar dados cliente");


	while ($buscar_amigo323 = mysqli_fetch_assoc($executa_query323)) { //--verifica se são amigos
		$idcliente                  = $buscar_amigo323["idcliente"];
		$nome_cli                   = $buscar_amigo323["nome_cli"];
		$descricao_empreendimento   = $buscar_amigo323["descricao_empreendimento"];
		$quadra                     = $buscar_amigo323["quadra"];
		$lote                       = $buscar_amigo323["lote"];



		if ($tipo_venda == 1) {
			$endereco      = $buscar_amigo323["endereco"];
			$numero        = $buscar_amigo323["numero"];
			$cep           = $buscar_amigo323["cep"];
			$complemento   = $buscar_amigo323["complemento_endereco"];
		}
	}


	$dados["nome_cli"]                 = $nome_cli;
	$dados["descricao_empreendimento"] = $descricao_empreendimento;
	$dados["quadra"]                   = $quadra;
	$dados["lote"]                     = $lote;
	$dados["idcliente"]                = $idcliente;

	if ($tipo_venda == 1) {
		$dados["endereco"]                 = $endereco;
		$dados["numero"]                   = $numero;
		$dados["cep"]                      = $cep;
		$dados["complemento"]              = $complemento;
	}


	return $dados;
}

function gravar($texto, $nome)
{
	//Variável arquivo armazena o nome e extensão do arquivo.

	$path = "../etiquetas.ibsystem.com.br/etiqueta/vendor/proner/phppimaco/templates/" . $nome . ".json";
	//Variável $fp armazena a conexão com o arquivo e o tipo de ação.
	$fp = fopen($path, "w+");

	//Escreve no arquivo aberto.
	fwrite($fp, $texto);

	//Fecha o arquivo.
	fclose($fp);
}

if (isset($_POST['valida_layout']) && $_POST['valida_layout'] == 1) {

	//var_dump($_POST);
	//echo '<br><br>';

	$page;
	$tag;
	$dados['page'] = array();

	$page['font-size']  = $_POST['fonte'];
	$page['orientation'] = 'P';
	$page['columns'] = $_POST['col'];
	$page['unit'] = 'mm';
	$page['size'][] = $_POST['alt_pagina'];
	$page['size'][] = $_POST['larg_pagina'];
	$page['margin-top'] = $_POST['margin-top'];
	$page['margin-left'] = $_POST['margin-left'];
	$page['margin-right'] = $_POST['margin-right'];
	$page['margin-bottom'] = $_POST['margin-bottom'];
	$page['margin-header'] = '0';
	$page['margin-footer'] = '0';

	array_push($dados['page'], $page);

	$tag['width'] = $_POST['larg_etiqueta'];
	$tag['height'] = $_POST['alt_etiqueta'];
	$tag['border'] = '0';
	$tag['margin-left'] = $_POST['margin-etiqueta'];

	//var_dump($tag);
	//echo '<br><br>';

	array_push($dados['tag'], $tag);

	$texto =  json_encode($dados);

	gravar($texto, $_POST['nome_modelo']);
}

?>

<!DOCTYPE html>
<!--[if IE 8]> <html lang="en" class="ie8"> <![endif]-->
<!--[if !IE]><!-->
<html>
<!--<![endif]-->

<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8">
	

	<title>Immobile | Business</title>
	<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport" />
	<meta content="" name="description" />
	<meta content="" name="author" />

	<!-- ================== BEGIN BASE CSS STYLE ================== -->
	<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400,600,700" rel="stylesheet">
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/jquery-ui/themes/base/minified/jquery-ui.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap/css/bootstrap.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/css/animate.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/css/style.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/css/style-responsive.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/css/theme/default.css" rel="stylesheet" id="theme" />

	<link href="https://immobilebusiness.com.br/admin/assets/plugins/select2/dist/css/select2.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/css/multiple-select.css" rel="stylesheet" />

	<!-- ================== END BASE CSS STYLE ================== -->

	<!-- ================== BEGIN PAGE LEVEL STYLE ================== -->
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/media/css/dataTables.bootstrap.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/extensions/Buttons/css/buttons.bootstrap.min.css" rel="stylesheet" />
	<link href="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/extensions/Responsive/css/responsive.bootstrap.min.css" rel="stylesheet" />
	<!-- ================== END PAGE LEVEL STYLE ================== -->

	<!-- ================== BEGIN BASE JS ================== -->
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/pace/pace.min.js"></script>
	<!-- ================== END BASE JS ================== -->
</head>

<body>


	<!-- begin #page-loader -->
	<div id="page-loader" class="fade in"><span class="spinner"></span></div>
	<!-- end #page-loader -->

	<!-- begin #page-container -->
	<div id="page-container" class="page-container fade page-sidebar-fixed page-header-fixed">
		<!-- begin #header -->
		<?php include "topo.php";

		function verifica_permissao($grupo_id, $empreendimento_id)
		{

			include "conexao.php";
			$query = "SELECT * FROM grupo_empreendimento WHERE grupo_id = '$grupo_id' AND empreendimento_id = '$empreendimento_id'";
			$executa_query = mysqli_query($db, $query);

			while ($busca_query = mysqli_fetch_assoc($executa_query)) {

				$idgrupo_empreendimento = $busca_query['idgrupo_empreendimento'];
			}

			return $idgrupo_empreendimento;
		}


		?>

		<!-- begin #content -->
		<div id="content" class="content">
			<!-- begin breadcrumb -->

			<!-- end breadcrumb -->
			<!-- begin page-header -->
			<h1 class="page-header">Etiquetas</h1>
			<!-- end page-header -->

			<div class="row">
				<div class="col-md-12">
					<div class="panel panel-inverse">
						<div class="panel-heading">
							<h4 class="panel-title">Informe o Período</h4>
						</div>
						<div class="panel-body">
							<form class="form-vertical form-bordered" name="myForm" method="GET" action="etiqueta.php" id="form_etiqueta">
								<div class="row">
									<div class="form-group">
										<input type="hidden" name="valida_form" value="1">
										<label class="col-md-2 control-label">Cliente</label>
										<div class="col-md-4">
											<div class="input-group">
												<select class="default-select2 form-control" name="cliente_idcliente" required="">
													<option value="Todos">Todos</option>
													<?php

													include "conexao.php";

													$query_amigo = "SELECT * FROM cliente
    													INNER JOIN cliente_tipo ON cliente_tipo.idcliente = cliente.idcliente
    													WHERE idtipo = 1 order by nome_cli Asc";

													$executa_query = mysqli_query($db, $query_amigo) or die("Erro ao listar empreendimento");
													while ($buscar_amigo = mysqli_fetch_assoc($executa_query)) { //--verifica se são amigos

														$idcliente             = $buscar_amigo["idcliente"];
														$nome_cli              = $buscar_amigo["nome_cli"];
														$cpf_cli               = $buscar_amigo["cpf_cli"];

													?>
														<option value="<?php echo "$idcliente" ?>"> <?php echo "$nome_cli " . "CPF: " . "$cpf_cli" ?> </option>
													<?php } ?>
												</select>
											</div>
										</div>
									</div>

									<div class="form-group">
										<label class="col-md-2 control-label">Empreendimento</label>
										<div class="col-md-4">
											<div class="input-group">
												<select class="default-select2 form-control" name="empreendimento_id" id="os">
													<?php if ($idgrupo_acesso != 14) { ?>
														<option value="Todos">Todos</option>
													<?php } ?>
													<?php

													include "conexao.php";

													$query_amigo = "SELECT * FROM empreendimento 
																		INNER JOIN empreendimento_cadastro on empreendimento.empreendimento_cadastro_id = empreendimento_cadastro.idempreendimento_cadastro
																		order by descricao_empreendimento Asc";

													$executa_query = mysqli_query($db, $query_amigo) or die("Erro ao listar empreendimento");
													while ($buscar_amigo = mysqli_fetch_assoc($executa_query)) { //--verifica se são amigos

														$idempreendimento_cadastro             = $buscar_amigo["idempreendimento"];
														$descricao_empreendimento              = $buscar_amigo["descricao_empreendimento"];


														$verifica_permissao = verifica_permissao($idgrupo_acesso, $idempreendimento_cadastro);
														





													?>
															<option value="<?php echo $idempreendimento_cadastro ?>"> <?php echo $descricao_empreendimento ?> </option>
													<?php 
													} ?>

												</select>
											</div>
										</div>
									</div>
								</div>

								<div class="row">
									<!-- Inicio quadra / lote -->
									<div class="form-group">
										<label class="col-md-2 control-label">Quadra</label>
										<div class="col-md-4">
											<div>
												<select name="idquadra" id="quadra" class="form-control">
												</select>
											</div>
										</div>
									</div>

									<div class="form-group">
										<label class="col-md-2 control-label">Lote</label>
										<div class="col-md-4">
											<div>
												<select name="idlote" id="lote" class="form-control">
												</select>
											</div>
										</div>
									</div>
								</div>

								<div class="row">
									<div class="form-group">
										<label class="col-md-2 control-label">Modelo de Layout</label>
										<div class="col-md-4">
											<div>
												<select name="modelo_layout" id="layout" class="form-control" required="">
													<?php

													$ch = curl_init("http://etiquetas.ibsystem.com.br/lista_etiqueta.php");
													curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
													$etiquetas = curl_exec($ch);
													curl_close($ch);
													fclose($fp);

													$modelos = json_decode($etiquetas);
													var_dump($modelos);

													foreach ($modelos as $key => $value) {
														if ($value != '.' && $value != '..') {
															$name = explode('.', $value);
															if ($name[0] == 'A4254') {
													?>
																<option value="<?php echo "$value" ?>" selected><?php echo "$name[0]" ?></option>
															<?php
															} else {
															?>
																<option value="<?php echo "$value" ?>"><?php echo "$name[0]" ?></option>
													<?php
															}
														}
													}
													?>
												</select>
											</div>
										</div>
									</div>
								</div>

								<div class="row" style="margin-top: 10px!important;">
									<div class="col-md-6">
										<input type="submit" class="btn btn-sm btn-success" value="Consultar" />
										<a href="#" class="btn btn-info btn-sm" id="cad_layout">Cadastrar Modelo de etiquetas</a>
									</div>
								</div>
							</form>

							<div class="pre-scrollable" style="padding: 0px!important;">
								<table class="table table-bordered table-responsive-md table-striped text-center" style="margin-top: 20px!important;">
									<colgroup>
										<col width="15%">
										</col>
										<col width="10%">
										</col>
										<col width="15%">
										</col>
										<col width="5%">
										</col>
										<col width="10%">
										</col>
										<col width="5%">
										</col>
										<col width="10%">
										</col>
										<col width="5%">
										</col>
										<col width="5%">
										</col>
										<col width="10%">
										</col>
										<col width="10%">
										</col>
										<col width="10%">
										</col>
									</colgroup>
									<tbody id="myTable">
										<tr align="center" id="semConteudo">
											<td colspan="5">Sem conteudo !</td>
										</tr>
										<tr class="hidden">
											<td></td>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
											<td></td>
										</tr>
									</tbody>
								</table>
							</div>
						</div>
						<div class="panel-footer">
							<button class="btn btn-success btn-sm hidden" id="gerar_etiqueta">Gerar Etiquetas</button>
						</div>
					</div>
				</div>
			</div>
			<!-- end #content -->
		</div>

		<button href="#modal-dialog" data-toggle="modal" data-target="#modal-dialog" class="hidden" id="dialog"></button>
		<div id="modal-dialog" class="modal fade" role="dialog">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header" id="dialog-header">
						<button type="button" class="close" data-dismiss="modal" id="close">&times;</button>
						<h4 class="modal-title" align="center" id="salvar">Baixar Etiquetas!</h4>
					</div>
					<div class="modal-body" id="dialog-body" align="center">
						<a href="https://etiquetas.ibsystem.com.br/etiqueta/etiquetas.pdf" class="btn btn-success">Baixar</a>
					</div>
					<div class="modal-footer" id="dialog-footer">
						<button type="button" class="btn btn-defaut" data-dismiss="modal">Fechar</button>
					</div>
				</div>
			</div>
		</div>

		<button href="#modal-dialog" data-toggle="modal" data-target="#modal-dialog" class="hidden" id="dialog">alo</button>
		<div id="modal-dialog" class="modal fade" role="dialog">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header" id="dialog-header">
						<button type="button" class="close" data-dismiss="modal" id="close">&times;</button>
					</div>
					<div class="modal-body" id="dialog-body" align="center">
						<h4 class="modal-title" align="center" id="salvar">Salvo com sucesso!</h4>
					</div>
					<div class="modal-footer" id="dialog-footer">
						<button type="button" class="btn btn-defaut" data-dismiss="modal">Fechar</button>
					</div>
				</div>
			</div>
		</div>

		<button href="#modal_form_layout" data-toggle="modal" data-target="#modal_form_layout" class="hidden" id="form_layout">alo</button>
		<div id="modal_form_layout" class="modal fade" role="dialog">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header" id="dialog-header">
						<button type="button" class="close" data-dismiss="modal" id="close">&times;</button>
						<h3 class="modal-title">Cadastrar Layout de Etiqueta</h3>
					</div>
					<div class="modal-body" id="dialog-body" align="center">
						<form name="form_layout" method="POST" action="etiqueta.php">
							<div class="row">
								<div class="form-group col-md-12">
									<label class="control-label">Nome do modelo</label>
									<input type="text" name="nome_modelo" class="form-control" required>
								</div>
							</div>
							<div class="row">
								<div class="form-group col-md-6">
									<input type="hidden" name="valida_layout" value="1">
									<label class="control-label">Fonte</label>
									<input type="text" name="fonte" class="form-control" required>
								</div>

								<div class="form-group col-md-6">
									<label class="control-label">Colunas</label>
									<input type="text" name="col" class="form-control" required>
								</div>
							</div>

							<div class="row">
								<div class="form-group col-md-6">
									<label class="control-label">Altura Pagina mm*</label>
									<input type="text" name="alt_pagina" class="form-control" required>
								</div>

								<div class="form-group col-md-6">
									<label class="control-label">Largura Pagina mm*</label>
									<input type="text" name="larg_pagina" class="form-control" required>
								</div>
							</div>

							<div class="row">
								<div class="form-group col-md-3">
									<label class="control-label">Margin-top mm*</label>
									<input type="text" name="margin-top" class="form-control" required>
								</div>

								<div class="form-group col-md-3">
									<label class="control-label">Margin-bottom mm*</label>
									<input type="text" name="margin-bottom" class="form-control" required>
								</div>

								<div class="form-group col-md-3">
									<label class="control-label">Margin-left mm*</label>
									<input type="text" name="margin-left" class="form-control" required>
								</div>

								<div class="form-group col-md-3">
									<label class="control-label">Margin-rigth mm*</label>
									<input type="text" name="margin-rigth" class="form-control" required>
								</div>
							</div>

							<div class="row">
								<div class="form-group col-md-4">
									<label class="control-label">Altura etiqueta mm*</label>
									<input type="text" name="alt_etiqueta" class="form-control" required>
								</div>

								<div class="form-group col-md-4">
									<label class="control-label">Largura Etiqueta mm*</label>
									<input type="text" name="larg_etiqueta" class="form-control" required>
								</div>

								<div class="form-group col-md-4">
									<label class="control-label">Margin-left Etiqueta mm*</label>
									<input type="text" name="margin-etiqueta" class="form-control" required>
								</div>
							</div>

							<div class="row">
								<button class="btn btn-success btn-sm" type="submit">Enviar</button>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>


		<!-- begin scroll to top btn -->
		<a href="javascript:;" class="btn btn-icon btn-circle btn-success btn-scroll-to-top fade" data-click="scroll-top"><i class="fa fa-angle-up"></i></a>

		<!-- end scroll to top btn -->
	</div>
	<!-- ================== BEGIN BASE JS ================== -->
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/jquery/jquery-1.9.1.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/jquery/jquery-migrate-1.1.0.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/jquery-ui/ui/minified/jquery-ui.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap/js/bootstrap.min.js"></script>
	<!--[if lt IE 9]>
		    <script src="https://immobilebusiness.com.br/admin/assets/crossbrowserjs/html5shiv.js"></script>
		    <script src="https://immobilebusiness.com.br/admin/assets/crossbrowserjs/respond.min.js"></script>
		    <script src="https://immobilebusiness.com.br/admin/assets/crossbrowserjs/excanvas.min.js"></script>
		<![endif]-->
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/slimscroll/jquery.slimscroll.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/jquery-cookie/jquery.cookie.js"></script>
	<!-- ================== END BASE JS ================== -->
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/ionRangeSlider/js/ion-rangeSlider/ion.rangeSlider.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-colorpicker/js/bootstrap-colorpicker.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/masked-input/masked-input.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-timepicker/js/bootstrap-timepicker.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/password-indicator/js/password-indicator.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-combobox/js/bootstrap-combobox.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-select/bootstrap-select.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-tagsinput/bootstrap-tagsinput.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-tagsinput/bootstrap-tagsinput-typeahead.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/jquery-tag-it/js/tag-it.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-daterangepicker/moment.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-daterangepicker/daterangepicker.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/select2/dist/js/select2.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/bootstrap-eonasdan-datetimepicker/build/js/bootstrap-datetimepicker.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/js/form-plugins.demo.min.js"></script>
	<!-- ================== BEGIN PAGE LEVEL JS ================== -->
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/media/js/jquery.dataTables.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/media/js/dataTables.bootstrap.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/extensions/Buttons/js/dataTables.buttons.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/extensions/Buttons/js/buttons.bootstrap.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/extensions/Buttons/js/buttons.flash.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/extensions/Buttons/js/jszip.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/extensions/Buttons/js/pdfmake.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/extensions/Buttons/js/vfs_fonts.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/extensions/Buttons/js/buttons.html5.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/extensions/Buttons/js/buttons.print.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/plugins/DataTables/extensions/Responsive/js/dataTables.responsive.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/js/table-manage-buttons.demo.min.js"></script>
	<script src="https://immobilebusiness.com.br/admin/assets/js/apps.min.js"></script>
	<!-- ================== END PAGE LEVEL JS ================== -->


	<script src="produtos_pagar.js"></script>
	<script src="lote_pagar.js"></script>

	<script>
		$(document).ready(function() {
			App.init();
			TableManageButtons.init();
			FormPlugins.init();

			<?php
			if (isset($_GET["confirma_etiqueta"])) {
			?>
				$("button#dialog").click();

			<?php
			}
			?>


			$('#form_etiqueta').on("submit", function(event) {
				event.preventDefault();

				$.ajax({
					url: 'grava_etiqueta.php',
					method: 'POST',
					data: $('#form_etiqueta').serialize(),
					dataType: 'json',
					success: dados => {

						console.log(dados);
						$('button.hidden').removeClass('hidden');
						$('tr#semConteudo').detach();

						for (var i = 0; i < dados.length; i++) {
							for (var j = 0; j < dados[i].length; j++) {
								$('tr.hidden').find('td').eq(j).text(dados[i][j]);
							}

							var linha = $('tr.hidden').clone().removeClass('hidden');
							$('tbody#myTable').append(linha);

							$('tr:last-child').find('td').eq(11).append("<button class='btn btn-danger btn-sm' id='remove'>Remover</button>");

						}
					},
					error: erro => {
						console.log(0);
					}
				});
			});

			//Função para rempver linha
			$(document).on('click', '#remove', function() {
				$(this).parents('tr').detach();
			});


			$('button#gerar_etiqueta').click(function() {
				var dados = [];
				var dado = [];

				var modelo = $('select#layout').val();

				$('tr:not(.hidden)').each(function(i) {
					$(this).find('td:not(td:last-child)').each(function(j) {
						dado.push($(this).text());
					})

					dados.push(dado);
					dado = [];
				});

				$.ajax({
					url: 'https://etiquetas.ibsystem.com.br/etiqueta/etiqueta_rbl.php',
					method: 'POST',
					data: {
						dados: dados,
						modelo: modelo
					},
					success: dados => {
						window.open("https://etiquetas.ibsystem.com.br/etiqueta/etiquetas.pdf", "_blank");
					},
					error: erro => {
						console.log(0)
					}
				});
			});

			$('#cad_layout').click(function() {
				$('#form_layout').click();
			});

		});
	</script>
</body>

</html>