<?php
	require 'conexion.php';
	
	$id_grade = $_GET['id_grade'];
    
    // seleciona todos os registros da base com id_grade igual ao do post que veio do formulario
	$sql = "SELECT * FROM grade WHERE id_grade = '$id_grade'";
	$resultado = $mysqli->query($sql);

	$row = $resultado->fetch_array(MYSQLI_ASSOC);
    //print_r($row);
    //$temp = echo '<pre>', $sql, '<br />';
    
    require_once('functions.php');
	include(HEADER_TEMPLATE);
?>
<script> 
function soma() 
{
    
formPedido.subtotal.value = (formPedido.tda.value*1) + (formPedido.tqa.value*1) + (formPedido.tsa.value*1) + (formPedido.toa.value*1) + (formPedido.qua.value*1) + (formPedido.qda.value*1) + (formPedido.qqa.value*1) + (formPedido.qsa.value*1) + (formPedido.qoa.value*1) + (formPedido.cia.value*1) + (formPedido.cda.value*1)

}
</script>
<script> 
function porcent() 
{

formPedido.tda.value = Math.round((formPedido.tda.value*1) + ((formPedido.tda.value*1) * (formPedido.ajuste.value*1) /100 ))
formPedido.tqa.value = Math.round((formPedido.tqa.value*1) + ((formPedido.tqa.value*1) * (formPedido.ajuste.value*1) /100 ))
formPedido.tsa.value = Math.round((formPedido.tsa.value*1) + ((formPedido.tsa.value*1) * (formPedido.ajuste.value*1) /100 ))
formPedido.toa.value = Math.round((formPedido.toa.value*1) + ((formPedido.toa.value*1) * (formPedido.ajuste.value*1) /100 ))
formPedido.qua.value = Math.round((formPedido.qua.value*1) + ((formPedido.qua.value*1) * (formPedido.ajuste.value*1) /100 ))
formPedido.qda.value = Math.round((formPedido.qda.value*1) + ((formPedido.qda.value*1) * (formPedido.ajuste.value*1) /100 ))
formPedido.qqa.value = Math.round((formPedido.qqa.value*1) + ((formPedido.qqa.value*1) * (formPedido.ajuste.value*1) /100 ))
formPedido.qsa.value = Math.round((formPedido.qsa.value*1) + ((formPedido.qsa.value*1) * (formPedido.ajuste.value*1) /100 ))
formPedido.qoa.value = Math.round((formPedido.qoa.value*1) + ((formPedido.qoa.value*1) * (formPedido.ajuste.value*1) /100 ))
formPedido.cia.value = Math.round((formPedido.cia.value*1) + ((formPedido.cia.value*1) * (formPedido.ajuste.value*1) /100 ))
formPedido.cda.value = Math.round((formPedido.cda.value*1) + ((formPedido.cda.value*1) * (formPedido.ajuste.value*1) /100 ))

formPedido.subtotal.value = (formPedido.tda.value*1) + (formPedido.tqa.value*1) + (formPedido.tsa.value*1) + (formPedido.toa.value*1) + (formPedido.qua.value*1) + (formPedido.qda.value*1) + (formPedido.qqa.value*1) + (formPedido.qsa.value*1) + (formPedido.qoa.value*1) + (formPedido.cia.value*1) + (formPedido.cda.value*1)

}
</script>
			<div class="row">
				<h3 style="text-align:center">Edição de Grade de Ordem de Corte</h3>
			</div>
			
   			<form border="2" name="formPedido" method="POST" action="grade_grava.php" autocomplete="off">
				
				<input type="hidden" id="id_gradez" name="id_gradez" value="<?php echo $row['id_grade']; ?>" />
				<input type="hidden" id="id_pedidoz" name="id_pedidoz" value="<?php echo $row['id_pedido']; ?>" />
                <input type="hidden" id="ativo" name="ativo" value="1" />
                <input type="hidden" id="ajuste" name="ajuste" value="0" />
                <input type="hidden" id="dir" name="dir" value="4" />
                
                <hr>

                <div class="row">
                
                    <div class="form-group col-sm-1">
                        <label for="id_p'">Pedido</label>
                        <input type="text" class="form-control" id="id_pedido" name="id_pedido" value="<?php echo $row['id_pedido'] ?>" readonly="readonly">
                    </div>
                    
                    <div class="form-group col-sm-1">
                        <label for="id_g'">grade</label>
                        <input type="text" class="form-control" id="id_grade" name="id_grade" value="<?php echo $row['id_grade'] ?>" readonly="readonly">
                    </div>

                    <div class="form-group col-sm-2">
                        <label for="tit'">Fechamento grade</label>
                        <input type="text" class="form-control" id="titulo" name="titulo" value="<?php echo $row['titulo'] ?>" readonly="readonly">
                    </div>

                    <div class="form-group col-sm-7">
                        <label for="obs_grade">Obs:</label>
                        <input type="text" class="form-control" id="obs_grade" name="obs_grade" value="<?php echo $row['obs_grade'] ?>" style='text-transform:uppercase'>
                    </div>
                    
                </div>

                <div class="row">
                    <div class="form-group col-sm-1">
                        <label for="tda">32</label>
                        <input type="text" class="form-control" id="tda" name="tda" value="<?php echo $row['tda'] ?>" onBlur="soma();" style="min-width:60px;">
                    </div>
                    <div class="form-group col-sm-1">
                        <label for="tqa">34</label>
                        <input type="text" class="form-control" id="tqa" name="tqa" value="<?php echo $row['tqa'] ?>" onBlur="soma();" style="min-width:60px;">
                    </div>
                    <div class="form-group col-sm-1">
                        <label for="tsa">36</label>
                        <input type="text" class="form-control" id="tsa" name="tsa" value="<?php echo $row['tsa'] ?>" onBlur="soma();" style="min-width:60px;">
                    </div>
                    <div class="form-group col-sm-1">
                        <label for="toa">38</label>
                        <input type="text" class="form-control" id="toa" name="toa" value="<?php echo $row['toa'] ?>" onBlur="soma();" style="min-width:60px;">
                    </div>
                    <div class="form-group col-sm-1">
                        <label for="qua">40</label>
                        <input type="text" class="form-control" id="qua" name="qua" value="<?php echo $row['qua'] ?>" onBlur="soma();" style="min-width:60px;">
                    </div>
                    <div class="form-group col-sm-1">
                        <label for="qda">42</label>
                        <input type="text" class="form-control" id="qda" name="qda" value="<?php echo $row['qda'] ?>" onBlur="soma();" style="min-width:60px;">
                    </div>
                    <div class="form-group col-sm-1">
                        <label for="qqa">44</label>
                        <input type="text" class="form-control" id="qqa" name="qqa" value="<?php echo $row['qqa'] ?>"onBlur="soma();" style="min-width:60px;">
                    </div>
                    <div class="form-group col-sm-1">
                        <label for="qsa">46</label>
                        <input type="text" class="form-control" id="qsa" name="qsa" value="<?php echo $row['qsa'] ?>"onBlur="soma();" style="min-width:60px;"> 
                    </div>
                    <div class="form-group col-sm-1">
                        <label for="qoa">48</label>
                        <input type="text" class="form-control" id="qoa" name="qoa" value="<?php echo $row['qoa'] ?>" onBlur="soma();" style="min-width:60px;">
                    </div>
                    <div class="form-group col-sm-1">
                        <label for="cia">50</label>
                        <input type="text" class="form-control" id="cia" name="cia" value="<?php echo $row['cia'] ?>" onBlur="soma();" style="min-width:60px;">
                    </div>
                    <div class="form-group col-sm-1">
                        <label for="cda">52</label>
                        <input type="text" class="form-control" id="cda" name="cda" value="<?php echo $row['cda'] ?>" onBlur="soma();" style="min-width:60px;">
                    </div>
                    <div class="form-group col-sm-1">
                        <label for="subtotal">Subtotal</label>
                        <input type="text" class="form-control" id="subtotal" name="subtotal" value="<?php echo $row['subtotal'] ?>" readonly="readonly">
                    </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="fim_view.php?id=<?php echo $row['id_pedido'] ?>" class="btn btn-info">Voltar</a>
                            <button type="submit" class="btn btn-danger">GRAVA GRADE</button>
                        </div>
                    </div>
                </div>

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