<html lang="es">
<?php
	require 'conexion.php';
	
	$id_oc = $_GET['id_oc'];
    
    // seleciona todos os registros da base com inner join cliente
    
    $sql = "SELECT 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 WHERE ordem_corte.id_oc = '$id_oc'" ;
	$resultado = $mysqli->query($sql);
	$row = $resultado->fetch_array(MYSQLI_ASSOC);
    
    require_once('functions.php');
	include(HEADER_TEMPLATE);
?>

			<div class="row">
				<h3 style="text-align:center">Editando dados do PEDIDO</h3>
			</div>
			
   			<form method="POST" action="pedido_update.php" autocomplete="off">
				
				<input type="hidden" id="id" name="id" value="<?php echo $row['id']; ?>" />
                <input type="hidden" id="type" name="type" value="O" />
                <input type="hidden" id="ativo" name="ativo" value="1" />
                <input type="hidden" id="nr_company" name="nr_company" value="<?php echo $row['nr_company']; ?>" />
                
                <div class="row">

                    <div class="form-group col-md-2">
                        <label for="dtcadastro">Data de Cadastro</label>
                        <input type="date" class="form-control" name="dtcadastro" id="dtcadastro" value="<?php echo $row['dtcadastro'] ?>" readonly="readonly">
                    </div>
                    
                    <div class="form-group col-md-2">
                        <label for="id_piloto">LACRE</label>
                        <input type="number" class="form-control" id="id_piloto" name="id_piloto" value="<?php echo $row['id_piloto'] ?>" readonly="readonly">
                    </div>

                    <div class="form-group col-md-2">
                        <label for="nr_pedido">Nr Pedido</label>
                        <input type="number" class="form-control" id="nr_pedido" name="nr_pedido" value="<?php echo $row['nr_pedido'] ?>" required autofocus >
                    </div>
                    
                    <div class="form-group col-md-2">
                        <label for="revista">Revista</label>
                        <input type="text" class="form-control" id="revista" name="revista" value="<?php echo $row['revista'] ?>" required>
                    </div>

                    <div class="form-group col-md-2">
                            <label for="pop_name">Cliente</label>
                            <input type="text" class="form-control" name="popular_name" id="popular_name" value="<?php echo $row3['popular_name']; ?>" readonly="readonly" data-toggle="tooltip" data-placement="top" title="Cliente selecionado no Piloto">
                    </div>
                    
                    <?php if ($row['id_piloto'] == 0) : ?>              
                        <div class="form-group col-md-2">
                            <label for="nr_company">Altera cliente</label>
                            <select class="form-control" id="nr_company" name="nr_company">
                                <option value="<?php echo $row['nr_company']; ?>">muda cliente</option>
                                <?php
                                 $resultado_clientes2=$mysqli->query($query_clientes);
                                 while($row2 = $resultado_clientes2->fetch_assoc()) { ?>
                                    <option value="<?php echo $row2['id']; ?>"><?php echo $row2['popular_name']; ?></option>
                                <?php } ?>
                            </select>
                        </div>
                    <?php endif ?>    

                </div>

                <div class="row">
                   
                    <div class="form-group col-md-3">
                        <label for="referencia">Referência</label>
                        <input type="text" class="form-control" id="referencia" name="referencia" value="<?php echo $row['referencia'] ?>" required style='text-transform:uppercase'>
                    </div>

                    <div class="form-group col-md-3">
                        <label for="descricao">Descrição</label>
                        <input type="text" class="form-control" id="descricao" name="descricao" value="<?php echo $row['descricao'] ?>" required style='text-transform:uppercase'>
                    </div>

                    <div class="form-group col-md-2">
                      <label for="model">Modelo</label>
                      
                      <?php if ($row['id_piloto'] == 0) : ?>   
                        <input type="text" class="form-control" id="model" name="model" placeholder="Model" value="<?php echo $row['modelo']; ?>" style='text-transform:uppercase'>                      
                      <?php else : ?>  
                        <input type="text" class="form-control" id="model" name="model" placeholder="Model" value="<?php echo $row['modelo']; ?>" readonly="readonly" data-toggle="tooltip" data-placement="top" title="Modelo informado no Piloto">                      
                      <?php endif ?> 
                      
                    </div>

                    <div class="form-group col-md-2">
                      <label for="modelagem">Modelagem</label>
                      
                      <?php if ($row['id_piloto'] == 0) : ?>   
                        <input type="text" class="form-control" id="modelagem" name="modelagem" placeholder="Modelagem" value="<?php echo $row['modelagem']; ?>" style='text-transform:uppercase'>                      
                      <?php else : ?>  
                        <input type="text" class="form-control" id="modelagem" name="modelagem" placeholder="Modelagem" value="<?php echo $row['modelagem']; ?>" readonly="readonly" data-toggle="tooltip" data-placement="top" title="Modelagem informada no Piloto">                      
                      <?php endif ?>
                      
                    </div>

                    <div class="form-group col-md-2">
                        <label for="tecido">Tecido</label>
                        <input type="text" class="form-control" id="tecido" name="tecido" placeholder="tecido" style='text-transform:uppercase' required>
                    </div>
                </div>

                <div class="row">
                    <div class="form-group col-md-2">
                        <label for="data_pre">Data Pré</label>
                        <input type="date" class="form-control" id="data_pre" name="data_pre" value="<?php echo $row['data_pre'] ?>" required>
                    </div>                        
                
                    <div class="form-group col-md-2">
                      <label for="dtpedido">Data do Pedido</label>
                        <input type="date" class="form-control" id="data_pedido" name="data_pedido" value="<?php echo $row['data_pedido'] ?>" >                          
                    </div>
                    
                    <div class="form-group col-md-2">
                      <label for="dtentrega">Data da Entrega</label>
                        <input type="date" class="form-control" id="data_entrega" name="data_entrega" value="<?php echo $row['data_entrega'] ?>">                          
                    </div>
                    
                    <div class="form-group col-md-2">
                        <label for="qtd">Quantidade</label>
                        <input type="number" class="form-control" id="quantidade" name="quantidade" value="<?php echo $row['quantidade'] ?>" required>
                    </div>
                
                </div>
                
                <div class="row">
                
                    <div class="form-group col-sm-12 control-label">
                        <label for="obs">Observações do PEDIDO</label>
                        <div class="">
                            <textarea name="obs" class="form-control" rows="4" style='text-transform:uppercase'><?php echo $row['obs']?> </textarea>
                        </div>
                    </div>
                    

                </div>
                
                <div class="row">                
                    <div class="form-group">
                        <div class="col-xs-6 col-xs-offset-3 col-sm-4 col-sm-offset-0">
                            <a href="pedido_index.php" class="btn btn-primary">Voltar</a>
                            <button type="submit" class="btn btn-primary">Gravar Registro</button>
                        </div>
                    </div>
                </div>
            </form>
		</div>
    <?php include(FOOTER_TEMPLATE); ?>        
