<?php 
    @$msg = $_GET['msg'];
	require_once __DIR__ . '/../../constantes.php';
	require_once("vendor/autoload.php");
	
	$config = new \App\Models\Config();

	$getConfig   = $config->getConfig();
	$getDesconto = $config->getDesconto();
	$getDescontoProduto = $config->getDescontoProduto();
	
	$pedidos = new \App\Models\Pedidos();

	$getAllPedidos   = $pedidos->getAllPedidos('', '');
	
?>
<style>

  .table-hover tbody tr:hover {
		background-color: rgba(0,0,0,.075) !important;
  }
  		.table td, .table th {
			font-size: 11px !important;
		    height: auto !important;
		}
		.bs-placeholder{border: 1px solid #ccc;}
</style>
<!-- MOVE O CURSO DO MENU -->
<script> window.onload = function(e){ $('.nav-item').removeClass('active'); $('#config').addClass('active'); } </script>
<!-- MOVE O CURSO DO MENU -->
<div class="page-inner">
	<div class="page-header">
		<h4 class="page-title">Configurações</h4>
		<ul class="breadcrumbs">
			<li class="nav-home">
				<a href="#">
					<i class="flaticon-home"></i>
				</a>
			</li>
			<li class="separator">
				<i class="flaticon-right-arrow"></i>
			</li>
			<li class="nav-item">
				<a href="#">Configurações</a>
			</li>
		</ul>
	</div>
	<div class="row">
		<div class="col-md-12">
			<?php include './inc/alerts.php';?>
		</div>
	</div>
	<div class="row">
		<div class="col-md-6">
			<div class="card" style="padding: 20px" >
			
				<form method="post" id="configfor" enctype="multipart/form-data" >
					<div class="caixa_form">
						<div class="row">
							<div class="col-md-6">
								 <div class="form-group">
									<input type="hidden" name="cod" value="4">
									<input type="hidden" name="id" value="<?= $getConfig[0]["id"]; ?>">
									<label for="min_estoque">Qtd. Min Estoque Matriz <sup style="color: #db0606;" >*</sup></label>
									<input class="form-control" value="<?= $getConfig[0]["min_estoque"]; ?>" required id="min_estoque" name="min_estoque" type="text">
								  </div>
							</div>
							<div class="col-md-6">
								  <div class="form-group">
									<label for="cod_desconto">Cód. Vencimento</label>
									<input type="text" value="<?= $getConfig[0]["cod_desconto"]; ?>" class="form-control" required id="cod_desconto" name="cod_desconto">
								  </div>
							</div>
						</div>
						<div class="row">
							<div class="col-md-12">
								  <div class="form-group">
									<label for="caminho">Caminho Arquivo Importação</label>
									<input type="text" value="<?= $getConfig[0]["caminho"]; ?>" class="form-control" required id="caminho" name="caminho">
								  </div>
							</div>
						</div>
						<div class="row">
							<div class="col-md-12">
								  <div class="form-group">
									<label for="max_itens">Qtd. Itens Pedido{MAX: 299}</label>
									<input type="number" value="<?= $getConfig[0]["max_itens"]; ?>" class="form-control" required id="max_itens" name="max_itens" min="1" max="299">
								  </div>
							</div>
						</div>
						<div class="row">
							<div class="col-md-4">
								 <div class="form-group">
									<label for="data_analise_ini">Data inicial analise <sup style="color: #db0606;" >*</sup></label>
									<input class="form-control" value="<?= $getConfig[0]["data_analise_ini"]; ?>" required id="data_analise_ini" name="data_analise_ini" type="text">
								  </div>
							</div>
							<div class="col-md-4">
								  <div class="form-group">
									<label for="data_analise_fim">Data fim analise</label>
									<input type="text" value="<?= $getConfig[0]["data_analise_fim"]; ?>" class="form-control" required id="data_analise_fim" name="data_analise_fim">
								  </div>
							</div>
							<div class="col-md-4">
								  <div class="form-group">
									<label for="data_sug_dias">Sug.Dias</label>
									<input type="text" value="<?= $getConfig[0]["sug"]; ?>" class="form-control" required id="data_sug_dias" name="data_sug_dias">
								  </div>
							</div>							
						</div>
						
						
						<div class="row">
							<div class="col-md-12">
								  <div class="form-group">
									<button type="button" onclick="ChamadaPadrao('configfor','btn_modalEdt','span_modalEdt','main?view=config');return false;" class="btn btn-success btn-block" name="BTN_NEW" id="btn_modalEdt"> Salvar <span id="span_modalEdt"></span></button>
								  </div>
							</div>
						</div>						  
					</div>
			    </form>
				
			</div>
		</div>
		<div class="col-md-6">
			<div class="card" style="padding: 20px; max-height: 365px; min-height: 365px; position: relative;overflow:auto;" >
				<h3>Descontos por grupos</h3>
				<a href="javascript:void(0);" data-toggle="modal" data-target="#modalStatus" class="btn btn-info btn-sm" >Alterar descontos por grupo</a>

				<table id="example" class="table table-bordered table-hover text-center" style="background:#FFF; margin:0 !important;width: 100%; height: 200px; overflow:auto; position:relative;">
					<thead  class="thead-dark">	
					  <tr>
						<th>Grupo</th>
						<th>Desconto</th>
					  </tr>
					</thead>
					<tbody>
					<?php
						$contador = 1;
						if(!empty($getDesconto)){
							foreach ($getDesconto as $key => $lista) {
					?>
					  <tr style="display: table-block;" >
						<td><?= $lista['group_id']." - ".$lista['label'];?></td>
						<td><?= $lista['desconto'];?></td>
					  </tr>
					<?php $contador++;}}?>
					  
					  
				    </tbody>
				</table>
			
			
			</div>
		</div>
	</div>
	<div class="row">
		<div class="col-md-12">
			<div class="card" style="padding: 20px; max-height: 365px; min-height: 365px; position: relative;overflow:auto;">
				<h3>Descontos por produtos</h3>
				<a href="javascript:void(0);" data-toggle="modal" data-target="#modalStatus2" class="btn btn-info btn-sm" >Alterar descontos por produtos</a>
				<table id="example2" class="table table-bordered table-hover text-center" style="background:#FFF; margin:0 !important;width: 100%; overflow:auto; position:relative;">
					<thead  class="thead-dark">	
					  <tr>
						<th>Produto</th>
						<th>Desconto</th>
						<th></th>
					  </tr>
					</thead>
					<tbody>
					<?php
						$contador = 1;
						if(!empty($getDescontoProduto)){
							foreach ($getDescontoProduto as $key => $lista) {
					?>
					  <tr style="display: table-block;" >
						<td><?= $lista['product_id'];?></td>
						<td><?= $lista['desconto'];?></td>
						<td>
							<button type="button" class="btn btn-icon btn-round btn-danger btn-sm" id="btt-ex" data-toggle="modal" data-target="#modalDelet" style="cursor: pointer;" onclick="excluir_padrao('uni_descontos_prod', '<?= $lista['id'];?>')" data-toggle2="tooltip" data-placement="top" title="Deletar" ><i class="fas fa-times"></i></button>										
						</td>
					  </tr>
					<?php $contador++;}}?>
					  
					  
				    </tbody>
				</table>
			
			
			</div>
		</div>
	</div>	
	<div class="row">
		<div class="col-md-12">
		
			<div class="page-header">
				<h4 class="page-title"><i class="fa fa-exclamation-triangle"></i> Configurações Avançadas</h4>
				<ul class="breadcrumbs">
					<li class="nav-home">
						<a href="#">
							<i class="fa fa-desktop"></i>
						</a>
					</li>
					<li class="separator">
						<i class="flaticon-right-arrow"></i>
					</li>
					<li class="nav-item">
						<a href="#">Area do Desonvolvedor</a>
					</li>
				</ul>
			</div>
			<div class="card" style="padding: 20px; max-height: 365px; min-height: 365px; position: relative;overflow:auto;">
				<h3><i class="fa fa-arrow-right"></i> Status de Pedidos</h3>
					<div class="row">
						<div class="col-md-4">
							<label>Pedido</label>
							<select name="pedidox" id="pedidox" class="form-control selectpicker" data-live-search="true" >
								<option value="" disabled selected>::- SELECIONE - ::</option>
								<?php
									foreach($getAllPedidos as $key => $lista) {
								?>
								<option value="<?= $lista['id'];?>"><?= $lista['id'];?></option>
								<?php }?>
							</select>
						</div>
						<div class="col-md-4">
							<label>Status</label>
							<select name="st" id="st" class="form-control" >
								<option value="" disabled selected>::- SELECIONE - ::</option>
								<option value="PENDENTE">PENDENTE</option>
								<option value="SEPARAÇÃO">SEPARAÇÃO</option>
								<option value="CONCLUIDO">CONCLUIDO</option>
								<option value="EXPORTADO">EXPORTADO</option>
							</select>
						</div>
						<div class="col-md-4">
							<label><br></label>
							<button type="button" onclick="Up_manual();" class="btn btn-secondary btn-sm" style="display: flex;">Alterar</button>
						</div>
					</div>
						
				<br>
				<h3><i class="fa fa-arrow-right"></i>  Exclusão de Pedido</h3>
			</div>	
		
		</div>
	</div>		
</div>

    <div class="modal fade" id="modalStatus" tabindex="-1" role="dialog" aria-labelledby="modalEdtdms" aria-hidden="true">
		 <div class="modal-dialog modal-lg">
			  <div class="modal-content">
				  <div class="modal-header">
					<h5 class="modal-title" id="modalEdtdms">Descontos por Grupos</h5>
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					  <span aria-hidden="true">&times;</span>
					</button>
				  </div>
				  <div class="modal-body">
				  		<form  method="post" id="configfor1" enctype="multipart/form-data" >
							<div class="row">
								<div class="col-md-12">
									<div class="form-group">
										<label>Grupo</label>
								      	<input type="hidden" name="cod" value="5">
										<select name="groupid[]" id="groupid"  class="form-control selectpicker" data-live-search="true" multiple>
											  <?php
													foreach($getDesconto as $key => $lista) {
												?>
												<option value="<?= $lista['id'];?>"><?= $lista['group_id']." - ".$lista['label'];?></option>
												<?php }?>
										</select>
									
									</div>
							
								</div>
							</div>
							<div class="row">
								<div class="col-md-12">
									<div class="form-group">
										<label>Desconto</label>
										<input class="form-control" type="text" name="desconto" id="desconto" value="0" />
									</div>
								</div>
							</div>
							<div class="row">
								<div class="col-md-12">
									<button class="btn btn-success" type="button" onclick="ChamadaPadrao('configfor1','btn_modalEdt1','span_modalEdt1','main?view=config');return false;" name="BTN_SALVAR" id="btn_modalEdt1" >Salvar <span id="span_modalEdt1"></span></button>
								</div>
							</div>
								
							
						</form>
				  
				  
				  </div>
			  </div>
		 </div>
    </div>
	
	    <div class="modal fade" id="modalStatus2" tabindex="-1" role="dialog" aria-labelledby="modalEdtdms" aria-hidden="true">
		 <div class="modal-dialog modal-lg">
			  <div class="modal-content">
				  <div class="modal-header">
					<h5 class="modal-title" id="modalEdtdms">Descontos por Produtos</h5>
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
					  <span aria-hidden="true">&times;</span>
					</button>
				  </div>
				  <div class="modal-body">
				  		<form  method="post" id="configfor2" enctype="multipart/form-data" >
							<div class="row">
								<div class="col-md-12">
									<div class="form-group">
										<label>Produtos</label>
								      	<input type="hidden" name="cod" value="6">
										<input class="form-control" type="text" name="produtoid" id="produtoid" value="" />
									</div>
								</div>
							</div>
							<div class="row">
								<div class="col-md-12">
									<div class="form-group">
										<label>Desconto</label>
										<input class="form-control" type="text" name="desconto" id="desconto" value="0" />
									</div>
								</div>
							</div>
							<div class="row">
								<div class="col-md-12">
									<button class="btn btn-success" type="button" onclick="ChamadaPadrao('configfor2','btn_modalEdt2','span_modalEdt2','main?view=config');return false;" name="BTN_SALVAR" id="btn_modalEdt2" >Salvar <span id="span_modalEdt2"></span></button>
								</div>
							</div>
						</form>
				  
				  </div>
			  </div>
		 </div>
    </div>
	
<!-- inclusao do footer -->

<?php 

		$jspage  = "<script src='utils/js/acoes_analise_pedidos.js'></script>";
		$jspage .= "<script src='./assets/js/dataTables.buttons.min.js'></script>";
		$jspage .= "<script src='./assets/js/jszip.min.js'></script>";
		$jspage .= "<script src='./assets/js/pdfmake.min.js'></script>";
		$jspage .= "<script src='./assets/js/vfs_fonts.js'></script>";
		$jspage .= "<script src='./assets/js/buttons.html5.min.js'></script>";
		$jspage .= "<script>";
		$jspage .= "	$(document).ready(function() {";
		$jspage .= "				$(\"[data-toggle2='tooltip']\").tooltip();";
		$jspage .= "				$(\"#example2\").DataTable( {";
		$jspage .= "					'pageLength': 50,";
		$jspage .= "					'pagingType': 'full_numbers',";
		$jspage .= "					'language': {";
		$jspage .= "						'lengthMenu': 'Exibição _MENU_ registros por página',";
		$jspage .= "						'zeroRecords': 'Nada encontrado - desculpe',";
		$jspage .= "						'info': 'Mostrando página _PAGE_ de _PAGES_ | _TOTAL_ Pedidos',";
		$jspage .= "						'infoEmpty': 'Não há registros acessível',";
		$jspage .= "						'infoFiltered': '(filtrado de _MAX_ total registros)',";
		$jspage .= "							'sSearch':       	'Procurar',";
		$jspage .= "						'sEmptyTable': 'Nenhum dado disponível na tabela', ";
		$jspage .= "						'sLoadingRecords':'Carregando...',";
		$jspage .= "						'sProcessing':'Aguarde...', ";
		$jspage .= "						'sZeroRecords':'Nenhuma entrada.', ";
		$jspage .= "					'oPaginate': {";
		$jspage .= "							'sFirst':    	'Primeira',";
		$jspage .= "							'sPrevious': 	'Voltar',";
		$jspage .= "							'sNext':     	'Próximo',";
		$jspage .= "							'sLast':     	'Último'";
		$jspage .= "						}";
		$jspage .= "					}";
		$jspage .= "				} );";
		$jspage .= "			});";
		$jspage .= "		</script>";
		
?>


$ff = "<script>
				/*$(function() {
					
					$.ajax({
						url: 'backend/config/processos/processos2.php',
						type: 'POST',
						data: {POST_paramentro: 'prod'},
						dataType: 'json',  
						error: function(jqXHR, textStatus, errorThrown){
							console.log('jqXHR:'+jqXHR);
							console.log('textStatus:'+textStatus);
							console.log('errorThrown:'+errorThrown);
						},
						success: function(retorno){
							let httml = '';
							
							for(let x = 0; x < retorno.length; x++ ){
								 httml += \"<option value='\"+retorno[x].trim()+\"'>\"+retorno[x].trim()+\"</option>\";
							}
							
							$('#produtoid').html(httml);
							$('#produtoid').selectpicker();

						}
					}); 
				});*/
				</script>";
?>

