<?php 
	require_once("vendor/autoload.php");
	
	    @$msg = $_GET['msg'];

	$pedidos = new \App\Models\Pedidos();

	// $_SESSION['id_loja'] = 2119;
	$getLoj   = $pedidos->getLojaALL($_SESSION['id_loja']);
	$getAllPedidos   = $pedidos->getAllPedidosLoja($getLoj[0]['id']);
	?>
<style>
  .bd-placeholder-img {
	font-size: 1.125rem;
	text-anchor: middle;
	-webkit-user-select: none;
	-moz-user-select: none;
	-ms-user-select: none;
	user-select: none;
  }
  @media (min-width: 768px) {
	.bd-placeholder-img-lg {
	  font-size: 3.5rem;
	}
  }
  .list-group-horizontal{-ms-flex-direction: row;flex-direction: row;}
  .list-group-item{ padding: .4rem 0rem; }
  .list-group-item a{ padding: .75rem 1.25rem; } 
  .disabled {cursor: not-allowed;}
  .table-hover tbody tr:hover {
		background-color: rgba(0,0,0,.075) !important;
  }
  		.table td, .table th {
			font-size: 11px !important;
		    height: auto !important;
		}
		.btn {
			padding: .1rem 1.8rem !important;
			font-size: 12px !important;
		}
		.form-control {
			font-size: 12px;
			border-color: #ebedf2;
			padding: 2px 5px;
			height: inherit!important;
		}
</style>
<!-- MOVE O CURSO DO MENU -->
<script> window.onload = function(e){ $('.nav-item').removeClass('active'); $('#pedido').addClass('active'); } </script>
<!-- MOVE O CURSO DO MENU -->
<div class="page-inner">
	<div class="page-header">
		
		<h4 class="page-title">
			Meus Pedidos
		</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="#">Pedidos</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-12">
			
			<div class="card">
				<div class="card-body">
				
					<div class="table-responsive">
						<table id="example2" class="table table-bordered table-head-bg-default">
							<thead>
							 <?php  if($_SESSION['id_type'] == 3){ ?>
								<tr>
									<th></th>
									<th>Código</th>
									<th>Data</th>
									<th style="text-align: center;width: 80px;">Status</th>
									<th>Pedido</th>
									<th>NF</th>
								</tr>
							 <?php  }else{ ?>
								<tr>
									<th></th>
									<th>Código</th>
									<th>Data</th>
									<th>Usuário</th>
									<th>Operador</th>
									<th style="text-align: center;width: 80px;">Status</th>
									<th>Pedido</th>
									<th>NF</th>
								</tr>
							 
							 <?php  }?>
							</thead>
							<tbody>
								<?php
								function mscolor($st1){
									switch($st1){
										case 'CONCLUIDO':
											echo "background-color: #cfd3f7;";
											break;
										case 'EXPORTADO':
											echo "background-color: #b9ffd4;";
											break;
										case 'PENDENTE':
											echo "background-color: #fbb1b1;";	
											break;
										case 'SEPARAÇÃO':
											echo "background-color: #ffd892;";
											break;
										default:
											echo "background-color: #fff;";
											break;
									}
								}
								
								
									$contador = 1;
									if(!empty($getAllPedidos)){
										foreach ($getAllPedidos as $key => $lista) {
											
										 if($_SESSION['id_type'] != 3){	
								?>
								<tr style="font-weight: bold;color: #000;height: 40px; <?php echo mscolor($lista['status']); ; ?>">
									<td><input type='checkbox' class='checkclass' id='two<?= $lista['id'];?>' onchange="libDisabled3('<?= $lista['status'];?>', '<?= $lista['id'];?>');"  name='checks2[]' value='two<?= $lista['id'];?>'/></td>
									<td><?= $lista['id'];?></td>
									<td><?= date("d/m/Y H:i:s", strtotime($lista['data']));?></td>
									<td><?php echo $pedidos->getUser($lista['usuario']); ?></td>
									<td><?php echo $pedidos->getUserOP($lista['gerador']); ?></td>									
									<td><?= $lista['status'];?></td>
									<?php 
										$response = $pedidos->getSFOPED($lista['id']);
										$nome = "";
										$nf   = "";
										if(!empty($response)){
											foreach ($response as $key => $l) {
												$nome .= $l['sofcon_pedido'].",";
												$nf   .= $l['sofcon_nf'].",";
											}
										}else{
											$nome = "0";
											$nf = "0";
										}
									?>
									<td><?= $nome ;?></td>
									<td><?= $nf   ;?></td>
								</tr>
								<?php 
								
								}else{
								?>
								<tr style="font-weight: bold;color: #000;height: 40px; <?php echo mscolor($lista['status']); ; ?>">
									<td><input type='checkbox' class='checkclass' id='two<?= $lista['id'];?>' onchange="libDisabled3('<?= $lista['status'];?>', '<?= $lista['id'];?>');"  name='checks2[]' value='two<?= $lista['id'];?>'/></td>
									<td><?= $lista['id'];?></td>
									<td><?= date("d/m/Y H:i:s", strtotime($lista['data']));?></td>
									<td><?= $lista['status'];?></td>
									<?php 
										$response = $pedidos->getSFOPED($lista['id']);
										$nome = "";
										$nf   = "";
										if(!empty($response)){
											foreach ($response as $key => $l) {
												$nome .= $l['sofcon_pedido'].",";
												$nf   .= $l['sofcon_nf'].",";
											}
										}else{
											$nome = "0";
											$nf = "0";
										}
									?>
									<td><?= $nome ;?></td>
									<td><?= $nf   ;?></td>
								</tr>
								
									
								<?php 
								}
										$contador++;
										
										
										
										}
								
								}
								
								
								?>
								
								
								
							</tbody>
						</table>
					</div>
					
				</div>
			</div>
			
		</div>
	</div>
	
	<div class="row">
		<div class="col-lg-12">
			<div class="table-responsive">
				<div style="overflow-x:auto;" id="ts" >
					<table id="example" class="table table-bordered table-hover" style="background:#FFF; margin:0 !important;width: 100%;">
						<thead  class="thead-dark">
							<tr>
								<th></th>
								<th style="text-align:center;">COD</th>
								<th style="text-align:center;">REF</th>
								<th style="text-align:center;">DESCRIÇÂO</th>
								<th style="text-align:center;">SUGESTÂO</th>
								<th style="text-align:center;">SEPARADO</th>
								<th style="text-align:center;">DEPOSITO</th>
							</tr>
						</thead>
						<tbody id="ResultX"></tbody>
						<tfoot class="text-center">
							<tr>
							  <td colspan="7" ><span id="meupedidoid" ></span></td>
							</tr>
						</tfoot>
					</table>
				</div>
			</div>
		</div>
	</div>
	
</div>
	<style>
	    .bootstrap-select.form-control {
			border: 1px solid #90939a;
		}
	</style>

<!-- 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 .= "					'order': [[ 1, 'desc' ]],";
		$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_',";
		$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 .= "				let msg = localStorage.getItem('msg');";
		$jspage .= "				if(msg == 'ativa'){";
		$jspage .= "					func(localStorage.getItem('status'),localStorage.getItem('texto'));";
		$jspage .= "				}";
		$jspage .= "			});";
		$jspage .= "		</script>";
		
?>

