<?php
    session_start();
	ob_start();

	$id_users = isset($_SESSION['id_users']) ? $_SESSION['id_users']: "";	
	$nome_user = isset($_SESSION['nome']) ? $_SESSION['nome']: "";	
	$email_users = isset($_SESSION['email']) ? $_SESSION['email']: "";	
	$pass_users = isset($_SESSION['pass']) ? $_SESSION['pass']: "";	
	$logado = isset($_SESSION['logado']) ? $_SESSION['logado']: "N";	

	if ($logado == "N" && $id_users == ""){	    
		echo  "<script type='text/javascript'>
					location.href='login.php'
				</script>";	
		exit();
	}

	require 'conexion.php';
	require_once('functions.php');

    $sql = "SELECT producao.id_producao, producao.producao_fim, ordem_corte.*, pedidos.*, companies.popular_name FROM ordem_corte INNER JOIN pedidos ON pedidos.id = ordem_corte.id_pedido INNER JOIN companies ON pedidos.nr_company = companies.id INNER JOIN producao ON ordem_corte.id_oc = producao.id_oc AND ordem_corte.enviado_producao > '1' GROUP BY ordem_corte.id_oc";

    include(HEADER_TEMPLATE);

?>
 

			<div class="container-fluid">

				<table class="table table-hover" id="mitabla">
					<thead>
						<tr>
							<th>Prod</th>
							<th>O.C.</th>
							<th>Pedido</th>
							<th>Cliente</th>
							<th>Referência</th>
							<th>Modelagem</th>
							<th>Modelo</th>
							<th>Nr.Pedido</th>
							<th></th>
							<th></th>
						</tr>
					</thead>
					
					<tbody>
                            <?php 
                            $resultado = $mysqli->query($sql);
                            while($row = $resultado->fetch_array(MYSQLI_ASSOC)) { ?>
                                <tr>
                                    <td><?php echo $row['id_producao']; ?></td>
                                    <td><?php echo $row['id_oc']; ?></td>									
                                    <td><?php echo $row['id_pedido']; ?></td>
                                    <td><?php echo $row['popular_name']; ?></td>
                                    <td><?php echo $row['referencia']; ?></td>
                                    <td><?php echo $row['modelagem']; ?></td>
                                    <td><?php echo $row['modelo']; ?></td>
                                    <td><?php echo $row['nr_pedido']; ?></td>
									
									<td><a href="pdf_oc_producao.php?id=<?php echo $row['id_pedido']; ?>" target="_blank" <span class="glyphicon glyphicon-print"></span></a></td>

                                    <?php if ($row['producao_fim'] == '0000-00-00 00:00:00') : ?>
											<td><a href="grade_estatisticas.php?id=<?php echo $row['id_oc']; ?>" data-toggle="tooltip" data-placement="top" title="Estatísticas"><button type="button" class="btn btn-xs btn-warning" >em Produção</button></a></td>
                                       <?php else : ?>
											<td><a href="grade_estatisticas.php?id=<?php echo $row['id_oc']; ?>"><button type="button" class="btn btn-xs btn-success" >Concluído!</button></a></td>
                                    <?php endif ?>
                                    
                                </tr>
                            <?php } ?>

                    </tbody>
				</table>

			</div>
    <?php include(FOOTER_TEMPLATE); ?>      