<?php
/**
 * Vendas - Vendas e PDV
 *
 */
if (!defined("_VALID_PHP"))
	die('Acesso direto a esta classe não é permitido.');
if (!$usuario->is_Todos())
	redirect_to("login.php");
?>
<?php switch (Filter::$acao):
	case "novavenda":
		$id_unico = $_SESSION['id_unico'] . '_' . $_SESSION['uid'] . '_' . date("YmdHis");
		?>
		<style>
			#cpf_cnpj_modal {
				width: 100%;
				padding: 8px;
			}
			#sugestoes {
				position: absolute;
				border: 1px solid #ccc;
				background-color: #fff;
				max-height: 150px;
				overflow-y: auto;
				width: calc(100% - 16px);
				margin-top: 4px;
				box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
				z-index: 1000;
				display: none;
			}
			.sugestao {
				padding: 8px;
				cursor: pointer;
				font-size: 14px;
			}
			.sugestao:hover {
				background-color: #f0f0f0;
			}
		</style>
		<script type="text/javascript">
			$(document).ready(function () {
				$('#cod_barras').focus().select();
				
				$(document).on('keydown', function(e) {
					var code = e.which || e.keyCode;
					// --- BLOQUEIO DO F5 ---
					if (code === 116) {
						e.preventDefault();
            			e.stopPropagation();
						return false;
					}

					/*
					if (code === 117 || code === 118 || code === 119 || code === 121) {
						podeSair = true;
					}
					*/

				});
			});
			async function buscarCpfCnpj() {
				let cpfcnpj = document.querySelector("#cpf_cnpj_modal").value
				cpfcnpj = cpfcnpj.replace(/[./-]/g, '')
				if (cpfcnpj.length > 0) {
					const response = await fetch(`./webservices/buscarcpfcnpj.php?query=${cpfcnpj}`, {
						method: "GET",
						headers: {
							"Content-Type": "application/json"
						}
					})
					if (!response.ok) throw new Error("Erro na consulta")
					const data = await response.json()
					mostrarSugestoes(data)
				}
			}
			function mostrarSugestoes(data) {
				const sugestoes = document.getElementById('sugestoes')
				sugestoes.innerHTML = ''
				if (data.length > 0) {
					sugestoes.style.display = 'block'
					data.forEach(cliente => {
						const div = document.createElement('div')
						div.className = 'sugestao'
						div.innerHTML = `
							${cliente.nome}</br><b>
							${cliente.cpf_cnpj}</b></br>
							${cliente.telefone}</br>
							${cliente.celular}</br>
							${cliente.endereco}</br> _________________________________`
						div.onclick = () => preencherCamposCliente(cliente)
						sugestoes.appendChild(div)
					})
				}
			}
			async function preencherCamposCliente(cliente) {
				document.getElementById('sugestoes').style.display = 'none'
				const nome = document.getElementById("cadastro")
				const cpfCnpj = document.getElementById("cpf_cnpj_modal")
				const celular = document.getElementById("celular")
				nome.value = cliente.nome
				cpfCnpj.value = cliente.cpf_cnpj
				celular.value = cliente.celular
				if (cliente.status == 1) {
					validaStatus(cliente)
				}
				$('.selecionado').removeClass("ocultar");
				$('.selecionado').addClass("mostrar");
				const data = await clienteCrediario(cliente.cpf_cnpj.replace(/[./-]/g, ''))
				if (data[0].crediarioSistema && data[0].crediario > 0) {
					$('.btncrediario').removeClass("ocultar");
					$('.btncrediario').addClass("mostrar");
					$('.devendo').removeClass("ocultar");
					$('.devendo').addClass("mostrar devendo");
				} else {
					$('.btncrediario').removeClass("mostrar");
					$('.btncrediario').addClass("ocultar");
					$('.devendo').removeClass("mostrar ");
					$('.devendo').addClass("ocultar");
				}
				let id_cadastro = cliente.id_cadastro
				$('#id_cadastro').val(id_cadastro);
				$('#id_cadastro_form').val(id_cadastro);
				clienteExistente(id_cadastro)
			}
			function validaStatus(cliente) {
				const nome = document.getElementById("cadastro")
				const cpfCnpj = document.getElementById("cpf_cnpj_modal")
				const celular = document.getElementById("celular")
				if (confirm("Cliente está desativado, deseja reativa-lo")) {
					return reativarCadastro(cliente.id_cadastro)
				}
				nome.value = ''
				cpfCnpj.value = ''
				celular.value = ''
			}
			async function reativarCadastro(id) {
				const response = await fetch(`./webservices/reativarcadastropdv.php?id_cadastro=${id}`, {
					method: "POST",
					headers: {
						"Content-Type": "application/json"
					}
				})
				if (!response.ok) {
					throw new Error("Erro na consulta")
				}
			}
			async function clienteCrediario(cpfcnpj) {
				const response = await fetch(`./webservices/listar_cadastro.php?query=${cpfcnpj}`, {
					method: "GET",
					headers: {
						"Content-Type": "application/json"
					}
				})
				if (!response.ok) throw new Error("Erro na consulta")
				const data = await response.json()
				return data
			}
			document.addEventListener("click", (event) => {
				if (!event.target.closest("#cpf_cnpj_modal")) {
					document.getElementById("sugestoes").style.display = "none";
				}
			})
		</script>
		<?php if (empty($id_unico) || strlen($id_unico)<31): ?>
			<script type="text/javascript">
				$(document).ready(function () {
					$('#modal_aviso_id_unico').modal();
					$('#modal_aviso_id_unico').on('hide.bs.modal', function (event) {
						location.href = "login.php";
					});
				});
			</script>
			<div class="modal fade" id="modal_aviso_id_unico" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true">
				<div class="">
					<div class="modal-dialog" role="document">
						<div class="modal-content">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal" aria-label="Close">
									<span aria-hidden="true">&times;</span>
								</button>
								<h4 class="modal-title" id=""><strong>AVISO IMPORTANTE</strong></h5>
							</div>
							<div class="modal-body">
								<div class="row">
									<div class="col-md-12">
										<div class="alert alert-warning">
											<h4 class="block"><?php echo lang('VENDA_FALHA_TITULO'); ?></h4>
											<h5><?php echo lang('VENDA_FALHA_DESCRICAO'); ?></h5>
											<h5><?php echo "[$id_unico]"; ?></h5>
										</div>
									</div>
								</div>
							</div>
							<div class="modal-footer">
								<button type="button" class="btn default" data-dismiss="modal"><?php echo lang('SAIR'); ?></button>
							</div>
						</div>
					</div>
				</div>
			</div>
		<?php endif; ?>
		<?php if ($faturamento->verificaCaixa($usuario->uid) == 0): ?>
			<script type="text/javascript">
				$(document).ready(function () {
					$('#modal_aviso_caixa').modal();
				});
			</script>
			<div class="modal fade" id="modal_aviso_caixa" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true">
				<div class="">
					<div class="modal-dialog" role="document">
						<div class="modal-content">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal" aria-label="Close">
									<span aria-hidden="true">&times;</span>
								</button>
								<h4 class="modal-title" id=""><strong>AVISO</strong></h5>
							</div>
							<div class="modal-body">
								<div class="row">
									<div class="col-md-12">
										<div class="alert alert-warning">
											<h4 class="block"><?php echo lang('CAIXA_VENDA_AVISO'); ?></h4>
											<h5><?php echo lang('CAIXA_VENDA_AVISO_DESCRICAO'); ?></h5>
										</div>
									</div>
								</div>
							</div>
							<div class="modal-footer">
								<a href="index.php?do=caixa&acao=adicionar"
									class="btn btn-warning"><?php echo lang('ABRIR_CAIXA'); ?></a>
								<button type="button" class="btn default" data-dismiss="modal"><?php echo lang('SAIR'); ?></button>
							</div>
						</div>
					</div>
				</div>
			</div>
		<?php endif; ?>
		<div class="page-container" style="overflow: hidden; width: 100%">
			<form action="" autocomplete="off" method="post" class="horizontal-form" name="admin_form" id="admin_form">
				<div class="page-content">
					<div class="" style="height: 450px; margin: 20px;"> <!-- container -->
						<div class="portlet-body form">
							<div class="col-md-12">
								<div class="dados_cliente ocultar">
									<div>
										<span id="cliente_novo" class="label label-danger ocultar">Novo</span>
										<span id="cliente_existente" class="label label-success ocultar">Existente</span>
										<span id="cliente_devendo"
											class="label label-danger devendo ocultar"><?php echo lang('CLIENTE_DEVENDO'); ?></span>
										<div id="resposta_cliente"></div>
										<div id="resposta_celular"></div>
									</div>
								</div>
								<div class="row">
									<div class="form-group col-md-2">
										<label class="control-label"><?php echo lang('TABELA_PRECO'); ?></label>
										<div class="">
											<select class="form-control input-sm" id="id_tabela_venda" name="id_tabela">
												<?php
												$retorno_row = $produto->getTabelaNivel($usuario->nivel);
												if ($retorno_row):
													foreach ($retorno_row as $srow):
														?>
														<option value="<?php echo $srow->id; ?>"
															desconto="<?php echo $srow->desconto; ?>"><?php echo $srow->tabela; ?>
														</option>
														<?php
													endforeach;
													unset($srow);
												endif;
												?>
											</select>
										</div>
									</div>
									<div class="form-group col-md-4">
										<label class="control-label"><?php echo lang('CODIGO_DE_BARRAS'); ?></label>
										<div class="">
											<div class="input-group">
												<input type="text" class="form-control barcode input-sm" id="" name="cod_barras"
													autofocus placeholder="Código de barras">
												<span class="input-group-addon"><?php echo lang('TECLE_ENTER'); ?></span>
											</div>
											<small class="help-block"><?php echo lang('ATALHO_F2') ?></small>
										</div>
									</div>
									<div class="form-group col-md-3">
										<label class="control-label">
											<?php echo lang('VENDEDOR'); ?>
										</label>
										<div>
											<select class="select2me form-control input-sm" name="id_vendedor" id="id_vendedor"
												data-placeholder="<?php echo lang('SELECIONE_VENDEDOR'); ?>">
												<option value=""></option>
												<?php
												$retorno_row = $usuario->getVendedor();
												if ($retorno_row):
													foreach ($retorno_row as $srow):
														?>
														<option value="<?php echo $srow->id; ?>" <?php if ($srow->id == $usuario->uid)
															   echo 'selected="selected"'; ?>><?php echo strtoupper($srow->usuario); ?>
														</option>
														<?php
													endforeach;
													unset($srow);
												endif;
												?>
											</select>
										</div>
										<small class="help-block" style="color: #f00; font-size: 11px">* Obrigatório se for um
											orçamento.</small>
									</div>
									<div class="form-group col-md-3">
										<label class="control-label"><?php echo lang('PRAZO_ENTREGA'); ?></label>
										<div>
											<input type="text" class="form-control input-sm data calendario"
												name="prazo_entrega" id="prazo_entrega">
											<small class="help-block"><?php echo lang('AVISO_ROMANEIO'); ?></small>
										</div>
									</div>
								</div>
							</div>
							<div class="tabelas_pagamento_produto">
								<div class="col-md-8" id="tabela_produto_novavenda">
									<div class="row">
										<div class="col-md-12">
											<div class="table-scrollable table-scrollable-borderless"
												style=" height: 310px; overflow-y: scroll; border-radius: 5px">
												<table class="table table-hover table-advance">
													<thead>
														<tr style="
													position: sticky;
													top: 0;
													opacity: 0.95;
												">
															<th width="200px"><?php echo lang('PRODUTO'); ?></th>
															<th width="30px"><?php echo lang('UNIDADE'); ?></th>
															<th width="50px"><?php echo lang('ESTOQUE'); ?></th>
															<th width="50px"><?php echo lang('QUANTIDADE'); ?></th>
															<th width="70px"><?php echo lang('VALOR'); ?></th>
															<th width="70px"><?php echo lang('TOTAL'); ?></th>
															<th width="90px"><?php echo lang('ACOES'); ?></th>
														</tr>
													</thead>
													<tbody id="tabela_produtos"></tbody>
												</table>
											</div>
										</div>
									</div>
								</div>
								<div class="col-md-4" id="tabela_pagamento_novavenda">
									<div class="row">
										<div class="col-md-12">
											<div class="table-scrollable table-scrollable-borderless"
												style="height: 310px; overflow-y: scroll;border-radius: 5px">
												<table class="table table-hover table-advance-green">
													<thead>
														<tr style="
													position: sticky;
													top: 0;
													opacity: 0.95;
												">
															<th width="20%"><?php echo lang('PAGAMENTO'); ?></th>
															<th width="10%"><?php echo lang('PARCELAS'); ?></th>
															<th width="20%"><?php echo lang('VALOR_PAGO'); ?></th>
															<th width="5%"><?php echo lang('ACOES'); ?></th>
														</tr>
													</thead>
													<tbody id="tabela_pagamentos"></tbody>
												</table>
											</div>
										</div>
									</div>
								</div>
							</div>
						</div>
					</div>
				</div>
				<div id="foorter-buttons">
					<div class="row" id="row_footer_buttons">
						<div class="col-md-3" style="width: 145px;">
							<button type="button" class="btn yellow-saffron modal_adicionar_produto" data-toggle="modal"
								data-target="#modal_produtos">
								<i class="fa fa-plus-square">&nbsp;</i>
								<?php echo lang('PRODUTOS'); ?> (F1)
							</button>
						</div>
						<div class="col-md-3" style="width: 190px;">
							<button type="button" class="btn red-thunderbird" data-toggle="modal" data-target="#modal_cliente">
								<i class="fa fa-plus-square">&nbsp;</i>
								<?php echo lang('CLIENTE_ADICIONAR'); ?> (F3)
							</button>
						</div>
						<div class="col-md-3" style="width: 155px;">
							<button type="button" class="btn blue-soft modal_adicionar_pagamento" data-toggle="modal"
								data-target="#modal_pagamentos">
								<i class="fa fa-usd">&nbsp;</i>
								<?php echo lang('PAGAMENTO_TITULO'); ?> (F4)
							</button>
						</div>
						<div class="col-md-3" style="width: 140px;">
							<button type="button" class="btn btn-submit green-seagreen btn_finalizar">
								<i class="fa fa-check-square-o">&nbsp;</i>
								<?php echo lang('FINALIZAR'); ?> (F6)
							</button>
						</div>
						<?php if ($usuario->is_nfc() && $core->tipo_sistema != 2): ?>
							<div class="col-md-3" style="width: 185px;">
								<a href="javascript:void(0)" class="btn purple btnvenda_nfc">
									<i class="fa fa-check-square-o">&nbsp;</i>
									<?php echo lang('FINALIZAR_COM_NFC'); ?> (F7)
								</a>
							</div>
						<?php endif; ?>
						<?php if ($usuario->is_VendaAberto() && $core->tipo_sistema != 1): ?>
							<div class="col-md-3" style="width: 130px;">
								<button type="button" class="btn btn-protect btnsalvar <?php echo $core->primeira_cor; ?>">
									<i class="fa fa-save">&nbsp;</i>
									<?php echo lang('SALVAR'); ?> (F8)
								</button>
							</div>
						<?php endif; ?>
						<?php if ($usuario->is_Orcamento() && $core->tipo_sistema != 1): ?>
							<div class="col-md-4" style="width: 165px;">
								<button type="button" class="btn btn-protect btn-salvar-orcamento"
									style="color: #fff; background-color: #d63384 ;">
									<i class="fa fa-save">&nbsp;</i>
									<?php echo lang('SALVAR_ORCAMENTO'); ?>
								</button>
							</div>
						<?php endif; ?>
						<div class="col-md-3" style="width: 150px;">
							<button type="button" class="btn btn-protect yellow-casablanca btncrediario ocultar">
								<i class="fa fa-money">&nbsp;</i>
								<?php echo lang('FINALIZAR_FICHA'); ?> (F10)
							</button>
						</div>
					</div>
				</div>
				<input type="hidden" name="valor" id="valor">
				<input type="hidden" name="id_cadastro" id="id_cadastro_form">
				<input type="hidden" name="cpf_cnpj" id="cpf_cnpj_form">
				<input type="hidden" name="cadastro" id="cadastro_form">
				<input type="hidden" name="celular" id="celular_form">
				<input type="hidden" name="observacao" id="observacao_form">
				<input type="hidden" name="data_boleto" id="data_boleto" class="form-control data calendario">
				<input type="hidden" name="valor_desconto" id="valor_desconto_rapida" class="form-control moeda">
				<input type="hidden" name="descporcentagem" id="valor_desconto_porcentagem" class="form-control desconto">
				<input type="hidden" name="valor_acrescimo" id="valor_acrescimo_rapida" class="form-control moeda">
				<input type="hidden" id="valor_pago" class="form-control moeda valor_pago_venda">
				<input type="hidden" id="parcelas" class="form-control inteiro">
				<input type="hidden" id="modal_cancelar_produto_venda"
					value="<?php echo $core->modal_cancelar_produto_venda; ?>">
				<input type="hidden" id="modal_alterar_valor_produto_venda"
					value="<?php echo $core->modal_alterar_valor_produto_venda; ?>">
				<input type="hidden" id="case-novavenda" value="<?php echo Filter::$acao ?>" />
				<input type="hidden" name="id_unico" id="id_unico" value="<?php echo $id_unico; ?>" />
				<?php echo $core->doForm("processarNovaVenda"); ?>
		</div>
		</form>
		<div class="modal fade" id="modal_cliente" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true">
			<div class="">
				<div class="modal-dialog" role="document">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-label="Close">
								<span aria-hidden="true">&times;</span>
							</button>
							<h4 class="modal-title" id=""><strong><?php echo lang('CLIENTE_ADICIONAR') ?></strong></h5>
						</div>
						<div class="modal-body">
							<div class="form-group">
								<span class="help-block pull-right"><?php echo lang('ATALHO_ENTER') ?></span>
								<label class="control-label"><?php echo lang('CLIENTE'); ?>:</label>
								<div>
									<input name="id_cadastro" id="id_cadastro" type="hidden" />
									<input name="cpf_cnpj" id="cpf_cnpj" type="hidden" />
									<input type="text" autocomplete="off" class="form-control caps listar_cliente pular"
										name="cadastro" id="cadastro" placeholder="Digite aqui o nome ou razão social">
								</div>
								<div class="row selecionado ocultar">
									<div class="form-group">
										<div class="col-md-9">
											<span class="label label-success label-sm"><?php echo lang('SELECIONADO'); ?></span>
										</div>
									</div>
								</div>
								<div class="row devendo ocultar">
									<div class="form-group">
										<div class="col-md-9">
											<span
												class="label label-danger label-sm"><?php echo lang('CLIENTE_DEVENDO'); ?></span>
										</div>
									</div>
								</div>
							</div>
							<div class="form-group">
								<label class="control-label"><?php echo lang('CPF_CNPJ'); ?>:</label>
								<div>
									<input type="text" autocomplete="off" class="form-control cpf_cnpj pular"
										id="cpf_cnpj_modal" name="cpf_cnpj" placeholder="Digite aqui o CPF ou CNPJ">
									<div id="sugestoes"></div>
								</div>
							</div>
							<div class="form-group">
								<label class="control-label"><?php echo lang('CELULAR'); ?>:</label>
								<div>
									<input type="text" autocomplete="off" class="form-control celular pular" id="celular"
										name="celular">
								</div>
							</div>
							<div class="form-group">
								<label class="control-label"><?php echo lang('OBSERVACAO'); ?>:</label>
								<div>
									<textarea class="form-control caps pular" name="observacao" id="observacao_modal"
										maxlength="250"></textarea>
								</div>
							</div>
						</div>
						<div class="modal-footer">
							<button type="button" onclick="buscarCpfCnpj()"
								class="btn salvar_cliente_modal <?php echo $core->primeira_cor; ?>"><?php echo lang('SALVAR'); ?></button>
							<button type="button" class="btn default sair_cliente_modal"
								data-dismiss="modal"><?php echo lang('SAIR'); ?></button>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="modal fade" id="modal_produtos" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true">
			<div class="vertical-alignment-helper" style="min-width:90%;">
				<div class="modal-dialog vertical-align-center modal-dialog modal-lg" role="document">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-label="Close">
								<span aria-hidden="true">&times;</span>
							</button>
							<h4 class="modal-title" id=""><strong><?php echo lang('PRODUTOS') ?></strong></h5>
						</div>
						<div class="modal-body">
							<div class=row>
								<div class="col-md-12">
									<div class="form-group">
										<div class="col-md-6">
											<div id="showProductInput"></div>
										</div>
										<div class="col-md-3">
											<div id="showQuantidadeInput"></div>
										</div>
										<div class="col-md-3">
											<div id="showPriceProductInput"></div>
										</div>
									</div>
								</div>
							</div>
							<div id="showProduct"></div>
						</div>
						<div class="modal-footer">
							<span class="help-block pull-left">Aperte "ESC" para sair.</span>
							<button type="button" class="btn default" data-dismiss="modal"><?php echo lang('SAIR'); ?></button>
						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="modal fade" id="modal_pagamentos" tabindex="-1" role="dialog" aria-labelledby="" aria-hidden="true">
			<div class="vertical-alignment-helper">
				<div class="modal-dialog vertical-align-center" role="document">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal" aria-label="Close">
								<span aria-hidden="true">&times;</span>
							</button>
							<h4 class="modal-title" id=""><strong><?php echo lang('TIPO_PAGAMENTO') ?></strong></h5>
						</div>
						<div class="modal-body">
							<select name="tipopagamento" id="tipopagamento" multiple class="form-control selectPayment"
								style=" height: 200px; margin-top: 10px; " autofocus>
								<?php
								$retorno_row = $faturamento->getTipoPagamento();
								if ($retorno_row):
									foreach ($retorno_row as $srow):
										?>
										<option class="todos_pagamentos" value="<?php echo $srow->id; ?>"
											avista="<?php echo $srow->avista; ?>" id_categoria="<?php echo $srow->id_categoria; ?>"
											<?php echo ($srow->id == 1) ? 'selected' : '' ?>>
											<?php echo $srow->tipo; ?>
										</option>
										<?php
									endforeach;
									unset($srow);
								endif;
								?>
							</select>
							<span class="help-block" style="margin-bottom:40px">
								<?php echo lang('ATALHO_MODALPAG_ALT_F'); ?>
								&emsp;&emsp;&emsp;
								<?php echo lang('INFORMACAO_FORMA_PAGAMENTO'); ?>
							</span>
							<div class="row valores_pagamento mostrar">
								<div class="col-md-4">
									<div class="input-group">
										<span class="input-group-addon">%</span>
										<input type="text" class="form-control desconto" name="descporcentagem"
											id="valor_desconto_porcentagem_modal" placeholder="Desconto" data-prefix="%">
									</div>
									<span class="help-block"><?php echo lang('ATALHO_MODALPAG_ALT_S'); ?></span>
								</div>
								<div class="col-md-4">
									<div class="input-group">
										<span class="input-group-addon">R$</span>
										<input type="text" class="form-control moeda" name="valor_desconto"
											id="valor_desconto_modal" placeholder="Desconto">
									</div>
									<span class="help-block"><?php echo lang('ATALHO_MODALPAG_ALT_D'); ?></span>
								</div>
								<div class="col-md-4">
									<div class="input-group">
										<span class="input-group-addon">R$</span>
										<input type="text" class="form-control moeda" name="valor_acrescimo"
											id="valor_acrescimo_modal" placeholder="Acrescimo (frete, taxas, etc)">
									</div>
									<span class="help-block"><?php echo lang('ATALHO_MODALPAG_ALT_A'); ?></span>
								</div>
								<div class="col-md-4">
									<input autocomplete="off" type="text" class="form-control inteiro" name=""
										id="parcelas_modal" placeholder="Parcelas">
									<span class="help-block"><?php echo lang('ATALHO_MODALPAG_ALT_P'); ?></span>
								</div>
								<div class="col-md-4">
									<div class="input-group">
										<span class="input-group-addon">R$</span>
										<input type="text" class="form-control moeda valor_pago_venda" name="valor_pago_modal"
											id="valor_pago_modal" placeholder="Valor a pagar">
										<input name="valor_pagar_modal_pgto" id="valor_pagar_modal_pgto" type="hidden" />
									</div>
									<span class="help-block"><?php echo lang('ATALHO_MODALPAG_ALT_V'); ?></span>
								</div>
								<div class="col-md-4">
									<input type="text" class="form-control data calendario" name="data_boleto"
										id="data_boleto_modal"
										value="<?php echo date('d/m/Y', strtotime(date("Y-m-d") . ' + 2 days')); ?>">
									<span id="span_data_boleto_modal"
										class="help-block"><?php echo lang('PRIMEIRA_PARCELA_BOLETO'); ?></span>
								</div>
							</div>
							<!-- <hr style="margin: 20px 0;"> -->
						</div>
						<div class="modal-footer">
							<button type="button" class="btn default pull-left"
								data-dismiss="modal"><?php echo lang('SAIR'); ?></button>
							<div class="infos-modal valores_pagamento mostrar">
								<button type="button"
									class="btn btn-primary adicionar_pagamento_pdv"><?= lang('PAGAMENTO_ADICIONAR'); ?></button>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
		<?php if ($core->modal_cancelar_produto_venda): ?>
			<div class="modal fade" id="modal_cancelamento_produto" tabindex="-1" role="dialog" aria-labelledby=""
				aria-hidden="true">
				<div class="vertical-alignment-helper">
					<div class="modal-dialog vertical-align-center" role="document">
						<div class="modal-content">
							<div class="modal-header" style="background-color: #f3565d; color: #67001A;">
								<button type="button" class="close" data-dismiss="modal" aria-label="Close">
									<span aria-hidden="true">&times;</span>
								</button>
								<h4 class="modal-title" id=""><strong><?php echo lang('CANCELAMENTO_PRODUTO') ?></strong></h5>
							</div>
							<form autocomplete="off">
								<div class="modal-body">
									<div class="alert alert-danger">
										<h4><?php echo lang('ATENCAO'); ?></h4>
										<h5><?php echo lang('AVISO_CANCELAMENTO_PRODUTO'); ?></h5>
									</div>
									<div class="row">
										<div class="form-group">
											<label class="col-md-2 control-label"><?php echo lang('PIN'); ?></label>
											<div class="col-md-10">
												<div class="input-group">
													<input type="password" class="form-control" name="pinUserCancel"
														id="pinUserCancel" autocomplete="off">
													<span class="input-group-addon"><?php echo lang('TECLE_ENTER') ?></span>
												</div>
												<small class="hidden info-pin-incorreto" style="color: #f00; font-weight: bold">O
													PIN está incorreto.</small>
											</div>
										</div>
									</div>
								</div>
								<div class="modal-footer">
									<button type="button" class="pull-left btn default"
										data-dismiss="modal"><?php echo lang('SAIR'); ?></button>
									<button type="button" class="btn btn-danger btn-form-cancelamento"
										style="color: #67001A"><?php echo lang('CANCELAR_CONFIRMAR'); ?></button>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		<?php endif; ?>
		<?php if ($core->modal_alterar_valor_produto_venda): ?>
			<div class="modal fade" id="modal_alterar_valorvenda_por_pin" tabindex="-1" role="dialog" aria-labelledby=""
				aria-hidden="true">
				<div class="vertical-alignment-helper">
					<div class="modal-dialog vertical-align-center" role="document">
						<div class="modal-content">
							<div class="modal-header" style="background-color: #EECB00; color: #675800;">
								<button type="button" class="close" data-dismiss="modal" aria-label="Close">
									<span aria-hidden="true">&times;</span>
								</button>
								<h4 class="modal-title" id=""><strong><?php echo lang('ORCAMENTO_VALOR_PRODUTO_MUDAR') ?></strong>
									</h5>
							</div>
							<form autocomplete="off">
								<div class="modal-body">
									<div class="alert alert-warning">
										<h4><?php echo lang('ATENCAO'); ?></h4>
										<h5><?php echo lang('AVISO_ALTERACAO_VALOR_PRODUTO'); ?></h5>
									</div>
									<div class="row">
										<div class="form-group">
											<label class="col-md-2 control-label"><?php echo lang('PIN'); ?></label>
											<div class="col-md-10">
												<div class="input-group">
													<input type="password" class="form-control" name="pinUserAlter"
														id="pinUserAlter" autocomplete="off">
													<span class="input-group-addon"><?php echo lang('TECLE_ENTER') ?></span>
												</div>
												<small class="hidden info-pin-incorreto" style="color: #f00; font-weight: bold">O
													PIN está incorreto.</small>
											</div>
										</div>
									</div>
								</div>
								<div class="modal-footer">
									<button type="button" class="pull-left btn default"
										data-dismiss="modal"><?php echo lang('SAIR'); ?></button>
									<button type="button" class="btn btn-form-alterar-valorvenda"
										style="background-color: #EECB00; color: #675800;"><?php echo lang('ALTERACAO_CONFIRMAR'); ?></button>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		<?php endif; ?>
		</div>
		<?php break; ?>
	<?php
	default: ?>
		<div class="imagem-fundo">
			<img src="assets/img/logo.png" border="0">
		</div>
		<?php break; ?>
<?php endswitch; ?>
<?php if (isset($_GET["id_venda"])):
	$id_venda = get('id_venda');
	?>
	<script>
		function getStatus() {
			if (!window.Notification) {
				return "unsupported";
			}
			return window.Notification.permission;
		}
		// get permission Promise
		function getPermission() {
			return new Promise((resolve, reject) => {
				Notification.requestPermission(status => {
					var status = getStatus();
					if (status == 'granted') {
						resolve();
					} else {
						reject(status);
					}
				});
			});
		};
		getPermission()
			.then(function () {
				var n = new Notification("Venda realizada", {
					body: "Código da venda: <?php print $id_venda; ?>\nFAVOR DIRIGIR AO CAIXA \nPARA FINALIZAR A VENDA!"
				});
			}).catch(function (status) {
				console.log('Had no permission!');
			});
	</script>
<?php endif; ?>