<?php include_once('../../config.php') ?>
<?php
$hostname = gethostbyaddr($_SERVER['REMOTE_ADDR']);
?>


<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<title>Sisplan Web | Agrupamento de Venda</title>
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="plugins/fontawesome-free/css/all.min.css?versao=3.243.6.1">
	<link rel="stylesheet" href="https://code.ionicframework.com/ionicons/2.0.1/css/ionicons.min.css">
	<link rel="stylesheet" href="dist/css/adminlte.min.css?versao=3.243.6.1">
	<link rel="stylesheet" href="plugins/overlayScrollbars/css/OverlayScrollbars.min.css?versao=3.243.6.1">
	<link href='https://fonts.googleapis.com/css?family=Roboto:400,300,500,600,700,400italic' rel='stylesheet' type='text/css'>
	<link rel="stylesheet" href="dist/css/custom.css?versao=3.243.6.1">
	<link rel="shortcut icon" href="<?php echo BASE_URI; ?>/favicon.ico">
	<script src="plugins/moment/moment.min.js?versao=3.243.6.1"></script>
	<link rel="stylesheet" href="dist/css/sisplan.css?versao=3.243.6.1">
	<link rel="stylesheet" type="text/css" href="dist/css/dataTables.bootstrap4.min.css?versao=3.243.6.1" />
	<link rel="stylesheet" href="plugins/icheck-bootstrap/icheck-bootstrap.min.css?versao=3.243.6.1">
	<link rel="shortcut icon" href="favicon.ico">
	<link rel="stylesheet" type="text/css" href="dist/css/driver.min.css?versao=3.243.6.1" />
	<link rel="stylesheet" href="dist/css/jquery-ui.css?versao=3.243.6.1">
	<link rel="stylesheet" href="plugins/toastr/toastr.min.css">

</head>

<body class="hold-transition sidebar-mini layout-fixed">
	<div class="wrapper">
		<div class="content-wrapper">
			<div class="content-header">
				<div class="container-fluid">
					<div class="row mb-1">
						<div class="col-sm-6 flex">
							<h1 class="m-0 text-dark">Agrupamento de Venda</h1>
							<button class="btn btn-info btn-sm ml-2" id="tutorial">
								<i class="fas fa-question-circle"></i>
							</button>
							<!-- <div class="col-sm-2 col-2">
								<button id="btnLojaPrincipal" class="btn btn-danger btn-sisp" title="Voltar para o loja principal">Loja Principal</button>
							</div> -->
						</div>

						<div class="col-sm-6">
						</div>
					</div>
				</div>
			</div>

			<section class="content">
				<div class="card">
					<div class="card-body">
						<div class="container-fluid p-12" id="divFiltros">
							<div class="row">
								<div class="form-group col-sm-3">
									<label data-error="wrong" class="labelGeral" data-success="right" for="txtCliente">Cliente</label>
									<div class="input-group">
										<input type="text" placeholder="Cliente" class="input-default focus form-control validate" id="txtCliente" name="txtCliente">
										<div class="input-group-append">
											<button class="btn bg-danger" id="btnCliente" name="btnCliente" data-button="absolute" type="button">
												<i class="m-0 p-0 fas fa-search"></i>
											</button>
											<button class="btn bg-danger" id="btnACliente" type="button">
												<i class="m-0 p-0 fas fa-trash"></i>
											</button>
										</div>
									</div>
								</div>

								<div class="form-group col-sm-3">
									<label data-error="wrong" class="labelGeral" data-success="right" for="txtCaixa">Caixa</label>
									<div class="input-group">
										<input type="text" class="input-default focus form-control validate" id="txtCaixa" name="txtCaixa" placeholder="Caixa">
										<div class="input-group-append">
											<button class="btn bg-danger" id="btnCaixa" name="btnCaixa" data-button="absolute" type="button">
												<i class="m-0 p-0 fas fa-search"></i>
											</button>
											<button class="btn bg-danger" id="btnLimpaCaixa" type="button">
												<i class="m-0 p-0 fas fa-trash"></i>
											</button>
										</div>
									</div>
								</div>

								<div class="form-group col-sm-3">
									<label data-error="wrong" class="labelGeral" data-success="right" for="dtInicio">Data Inicio/ Data Fim:</label>
									<div class="input-group">
										<input type="date" max="2500-12-31" class="input-default focus form-control validate" id="dtInicio" name="dtInicio">
										<input type="date" max="2500-12-31" class="input-default focus form-control validate" id="dtFim" name="dtFim">
									</div>
								</div>

								<div class="form-group col-sm-3">
									<label data-error="wrong" data-success="right" for="txtTipoVendaFiltro">Tipo de Venda:</label>
									<div class="input-group">
										<input type="text" data-selecionado="false" class="input-default focus form-control validate" id="txtTipoVendaFiltro" name="txtTipoVendaFiltro" class="form-control" placeholder="Tipo de Venda">
										<div class="input-group-append">
											<button class="btn bg-danger" id="btnPesquisaTipoVenda" name="btnPesquisaTipoVenda" data-button="absolute" type="button"><i class="m-0 p-0 fas fa-search"></i></button>
											<button class="btn bg-danger" id="btnLimpaTipoVenda" type="button"><i class="m-0 p-0 fas fa-trash"></i></button>
										</div>
									</div>
								</div>
								<div class="col-sm-9"></div>
								<div class="col-sm-3 d-flex">
									<button id="btnConsultar" class='btn btn-success btn-sisp mr-1' type='button'><i class="fas fa-search"></i> Consultar</button>
									<button id="btnImprimir" class='btn btn-danger btn-sisp' type='button'><i class="fas fa-print"></i> Imprimir</button>
								</div>
							</div>

						</div>

						<div class="row">
							<div class="col-sm-12 icheck-primary d-inline pb-2 ml-2 justify-content-between" style="margin-right: 15px; height:30px;">
								<input class="form-check-input" type="checkbox" id="check_todos" value="option1">
								<label class="form-check-label" for="check_todos">Selecionar Todos</label>
							</div>
						</div>

						<div class="row">
							<div class="col-sm-12 table-responsive" id="divTabela">
								<table id="tabelaVendas" class="table table-responsive-sm table-select table-hover" width="100%">
									<thead>
										<th>SEL</th>
										<th>CODVEN</th>
										<th>CODCLI</th>
										<th>NOME</th>
										<th>VALOR</th>
										<th>VALOR RESTANTE</th>
										<th>QUANTIDADE</th>
										<th>QUANT. DEVOLVIDA</th>
										<th>QUANT. RESTANTE</th>
										<th>TIPO VENDA</th>
										<th>DESC TIPO VENDA</th>
									</thead>
									<tbody>
									</tbody>
								</table>
							</div>
							<div class="col-sm-12 d-flex justify-content-between">
								<button id="btnDevolver" title="Faça a devolução por esse botão quando o cliente quiser devolver itens porém sem dar por finalizado o(s) consignado(s), dessa forma será criado apenas uma venda de devolução com os itens devolvidos, podendo finalizar o(s) consignado(s) posteriormente através do botão Conferir." class="btn botoesMenu btn-secondary">Devolver Parcial</button>
								<div class="btn-group flex-wrap btn-group-justified btn-group-sm" role="group" aria-label="Basic example" id="divTotais">
									<div class="ml-2">
										<label data-error="wrong" class="labelGeral" data-success="right" for="txtTotalQuantSelec">
											Quant.
											Selecionada</label>
										<input style="max-width: 130px;" readonly type="text" class="input-default focus form-control validate" value='0' id="txtTotalQuantSelec" name="txtTotalQuantSelec">
									</div>
									<div class="ml-2">
										<label data-error="wrong" class="labelGeral" data-success="right" for="txtTotalQuantRestante">
											Quant. Restante</label>
										<input style="max-width: 130px;" readonly type="text" class="input-default focus form-control validate" value='0' id="txtTotalQuantRestante" name="txtTotalQuantRestante">
									</div>
									<div class="ml-2">
										<label data-error="wrong" class="labelGeral" data-success="right" for="txtTotalValorSelec">
											Valor Selecionado</label>
										<input style="max-width: 130px;" readonly type="text" class="input-default focus form-control validate" value='0' id="txtTotalValorSelec" name="txtTotalValorSelec">
									</div>
									<div class="ml-2">
										<label data-error="wrong" class="labelGeral" data-success="right" for="txtTotalValorRestante">
											Valor Restante</label>
										<input style="max-width: 130px;" readonly type="text" class="input-default focus form-control validate" value='0' id="txtTotalValorRestante" name="txtTotalValorRestante">
									</div>
									<div class="ml-2">
										<label data-error="wrong" class="labelGeral" data-success="right" for="txtTotalDevolucao">
											Devolução</label>
										<input style="max-width: 130px;" readonly type="text" class="input-default focus form-control validate" value='0' id="txtTotalDevolucao" name="txtTotalDevolucao">
									</div>
								</div>
								<button id="btnConferir" title="Utilize esse botão quando quiser finalizar o(s) consignado(s), tendo a opção de devolver itens que o cliente não ficou e gerar uma nova venda com apenas os itens que o cliente ficou." class="btn botoesMenu btn-danger btn-sisp">Conferir</button>
							</div>
						</div>
					</div>
				</div>
		</div>
		</section>
	</div>
	<aside class="control-sidebar control-sidebar-dark">
	</aside>
	<?php
	include_once('../../footer.php');
	?>
	</div>

	<div id="modalDevolucao" class="modal" tabindex="-1" role="dialog">
		<div class="modal-dialog modal-xl" role="document">
			<div class="modal-content" id="modalBody">
				<div class="modal-header">
					<h4 class="modal-title">Devolução Parcial</h4>

					<label for="btn-iniciar-epc" style="margin-left: 10px"></label>
					<div class="divRFID d-none">
						<button type="button" class="btn btn-icon-normal btn-danger d-flex align-items-center justify-content-center" style="border-radius: 4px!important; text-align: center;" id="btn-iniciar-epc" name="btn-iniciar-epc" data-button="absolute" title="Iniciar RFID, Atalho (Alt + 1)">
							<i class="fas fa-play"></i>
						</button>
					</div>
					<label for="btn-parar-epc" style="margin-left: 5px"></label>
					<div class="divRFID d-none">
						<button type="button" class="btn btn-icon-normal btn-danger d-flex align-items-center justify-content-center" style="border-radius: 4px!important;" id="btn-parar-epc" name="btn-parar-epc" data-button="absolute" title="Parar RFID, Atalho (Alt + 2)">
							<i class="fas fa-pause"></i>
						</button>
					</div>

					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
				</div>
				<div class="modal-body">
					<div class="row">
						<div class="col-6">
							<label data-error="wrong" data-success="right" for="txtVendasDev">Vendas </label>
							<div class="input-group">
								<input type="text" class="input-default focus form-control" id="txtVendasDev" name="txtVendasDev" readonly>
							</div>
						</div>
						<div class="col-6">
							<label style="margin-top:0.5rem!important;margin-bottom:0!important;display: flex; text-align: center; justify-content: space-between" for="txtBarraDev">Barra Devolução
								<i title='desativar som bipagem' style="font-size: 20px" id="somAtivoDev" class="fas fa-volume-up somAtivo d-none"></i>
								<i title='ativar som bipagem' style="font-size: 20px" id="somInativoDev" class="fas fa-volume-mute somInativo"></i>
							</label>
							<div class="input-group">
								<input type="text" class="input-default focus form-control" id="txtBarraDev" name="txtBarraDev">
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-sm-12">
							<table id="tabelaDevolucao" class="table table-responsive-sm table-select table-hover" width="100%">
								<thead>
								</thead>
								<tbody>
								</tbody>
							</table>
						</div>
					</div>
				</div>
				<div class="modal-footer" style="justify-content: space-between;">
					<div class="col-md-2" style="margin-top: 12px; padding-right: auto;">
						<div class="flex">
							<span class="info-box-icon"><i class="fas fa-box-open text-white" style="font-size: 25px; margin-right: 5px; margin-top: 5px;"></i></span>
							<div class="info-box-content ">
								<input type="number" name="txtTotalDevolvido" id="txtTotalDevolvido" class="form-control" data-bs-toggle="tooltip" title="Quantidade total de peças devolvidas" readonly>
							</div>
						</div>
					</div>
					<div class="col-md-2" style="margin-top: 12px; right: 300px;">
						<div class="flex">
							<i class="fas fa-dollar-sign" style="font-size: 25px; margin-right: 5px; margin-top: 5px;"></i>
							<div class="info-box-content ">
								<input type="number" name="txtValorTotalDevolvido" id="txtValorTotalDevolvido" class="form-control" data-bs-toggle="tooltip" title="Valor total de peças devolvidas" readonly>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-sm-12 d-flex justify-content-end">
							<button id="btnConfirmarDev" class="btn btn-danger btn-sisp">Confirmar</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<div id="modalConferencia" class="modal" tabindex="-1" role="dialog">
		<div class="modal-dialog modal-xl" role="document">
			<div class="modal-content" id="modalBody">
				<div class="modal-header">
					<h4 class="modal-title">Conferência     <input type="checkbox" id="checkConsig"> <label for="checkConsig" style="font-size: 65%;">Criar consignado com itens conferidos</label>    </h4>
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
				</div>
				<div class="modal-body">
					<div class="row">
						<div class="col-6">
							<label data-error="wrong" data-success="right" for="txtVendas">Vendas </label>
							<div class="input-group">
								<input type="text" class="input-default focus form-control" id="txtVendas" name="txtVendas" readonly>
							</div>
						</div>
						<div class="col-6">
							<label style="margin-top:0.5rem!important;margin-bottom:0!important;display: flex; text-align: center; justify-content: space-between" for="txtBarra">Barra Conferência
								<i title='desativar som bipagem' style="font-size: 20px" id="somAtivoBarra" class="fas fa-volume-up somAtivo d-none"></i>
								<i title='ativar som bipagem' style="font-size: 20px" id="somInativoBarra" class="fas fa-volume-mute somInativo"></i>
							</label>
							<div class="input-group">
								<input type="text" class="input-default focus form-control" id="txtBarra" name="txtBarra">
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-sm-12">
							<table id="tabelaItens" class="table table-sm table-select table-hover" width="100%">
								<thead>
								</thead>
								<tbody>
								</tbody>
							</table>
						</div>
					</div>
				</div>
				<div class="modal-footer" style="justify-content: space-between;">
					<div class="col-md-2" style="margin-top: 12px; padding-right: auto;">
						<div class="flex">
							<span class="info-box-icon"><i class="fas fa-box-open text-white" style="font-size: 25px; margin-right: 5px; margin-top: 5px;"></i></span>
							<div class="info-box-content ">
								<input type="number" name="txtTotalConferido" id="txtTotalConferido" class="form-control" data-bs-toggle="tooltip" title="Quantidade total de peças bipadas" readonly>
							</div>
						</div>
					</div>
					<div class="col-md-2" style="margin-top: 12px; right: 300px;">
						<div class="flex">
							<i class="fas fa-dollar-sign" style="font-size: 25px; margin-right: 5px; margin-top: 5px;"></i>
							<div class="info-box-content ">
								<input type="number" name="txtValorTotalConferido" id="txtValorTotalConferido" class="form-control" data-bs-toggle="tooltip" title="Valor total de peças bipadas" readonly>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-sm-12 d-flex justify-content-end">
							<button id="btnConfirmarConf" class="btn btn-danger btn-sisp">Confirmar</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<div id="modalAgrupaVendas" class="modal" tabindex="-1" role="dialog">
		<div class="modal-dialog modal-xl" role="document">
			<div class="modal-content" id="modalBody">
				<div class="modal-header">
					<h4 class="modal-title">Conferência     </h4>
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
				</div>
				<div class="modal-body">
					<div class="row">
						<div class="col-6">
							<label data-error="wrong" data-success="right" for="txtAgrupaVendas">Vendas </label>
							<div class="input-group">
								<input type="text" class="input-default focus form-control" id="txtAgrupaVendas" name="txtAgrupaVendas" readonly>
							</div>
						</div>
					</div>
					<div class="row">
						<div class="col-sm-12">
							<table id="tabelaItensAgrupaVendas" class="table table-sm table-select table-hover" width="100%">
								<thead>
								</thead>
								<tbody>
								</tbody>
							</table>
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<div class="row">
						<div class="col-sm-12">
							<button id="btnConfirmarAgrupaVendas" class="btn btn-danger btn-sisp">Confirmar</button>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>

	<script src="plugins/jquery/jquery.min.js?versao=3.243.6.1"></script>
	<script src="plugins/jquery-ui/jquery-ui.min.js?versao=3.243.6.1"></script>
	<script>
		if ($('[type="date"]').prop('type') != 'date') {
			$('[type="date"]').datepicker();
		}
		$.widget.bridge('uibutton', $.ui.button);
	</script>

	<!-- Bootstrap 4 -->
	<script src="plugins/bootstrap/js/bootstrap.bundle.min.js?versao=3.243.6.1"></script>
	<script src="dist/js/sisplan.js?versao=3.243.6.1"></script>
	<script type="text/javascript" src="utils/funcoes.js?versao=3.243.6.1"></script>
	<script src="dist/js/adminlte.min.js?versao=3.243.6.1"></script>
	<script type="text/javascript" src="dist/js/jquery.dataTables.min.js?versao=3.243.6.1"></script>
	<script type="text/javascript" src="dist/js/loadingoverlay.min.js?versao=3.243.6.1"></script>
	<script type="text/javascript" src="dist/js/dataTables.bootstrap4.min.js?versao=3.243.6.1"></script>
	<script src="dist/js/jquery.maskMoney.min.js?versao=3.243.6.1"></script>
	<script src="dist/js/dataTables.keyTable.js?versao=3.243.6.1"></script>
	<script src="utils/cookies.js?versao=3.243.6.1"></script>
	<script src="dist/js/requisicoes.js?versao=3.243.6.1"></script>
	<!-- SweetAlert2 -->
	<script type="text/javascript" src="<?php echo BASE_URI; ?>/dist/js/sum().js?versao=3.243.6.1"></script>
	<script src="plugins/sweetalert2/sweetalert2.min.js?versao=3.243.6.1"></script>
	<script src="plugins/toastr/toastr.min.js?versao=3.243.6.1"></script>
	<script src="dist/js/driver.min.js?versao=3.243.6.1"></script>
	<script type="text/javascript" src="config.js?versao=3.243.6.1"></script>
	<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-scrollTo/2.1.3/jquery.scrollTo.min.js"></script>
	<script>
		$(document).ready(async function () {
			if (getCookie('usuario') == "") {
				window.location.href = `${BASE_URI}/login`;
				return;
			}

			let usuario = getCookie('usuario');
			let empresa = getCookie('empresa');

			ipInterno = IP_INTERNO;
			ipExterno = IP_EXTERNO;
			basicAuth = BASIC_AUTH;

			const temAcesso = await temAcessoTela('AGRUPAMENTO_VENDA');
			if (!temAcesso.resultado) {
				toastrAcesso(temAcesso, BASE_URI);
				return;
			}

			sArquivo = `${BASE_URI}/pages/agrupamento_consig/agrupamento_consig.js?versao=3.243.6.1`;
			insereJavaScriptPagina(sArquivo);

		});
	</script>
</body>

</html>