<?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');
	include(HEADER_TEMPLATE); 
    
	//$id_pedido = $_GET['id'];
	$id = $_GET['id'];

    // seleciona todos os registros da base com inner join cliente
    //$sql = "SELECT companies.popular_name, pedidos.*, pedidos.obs AS obsPed FROM pedidos INNER JOIN companies on companies.id = pedidos.nr_company LEFT JOIN grade ON grade.id_pedido = pedidos.id WHERE pedidos.id = '$id'";
    $sql = "SELECT pilotos.lacre, companies.popular_name, pedidos.*, pedidos.obs AS obsPed FROM pedidos LEFT JOIN pilotos on pilotos.id_pedido = pedidos.id INNER JOIN companies on companies.id = pedidos.nr_company LEFT JOIN grade ON grade.id_pedido = pedidos.id WHERE pedidos.id = '$id'";
    
    $resultado = $mysqli->query($sql);
    $row = $resultado->fetch_array(MYSQLI_ASSOC);
?>


			<form name="gradePedido" method="POST" action="grade_update_pedido.php" autocomplete="off" onload="soma()">

                <input type="hidden" id="ativo" name="ativo" value="1" />
                <input type="hidden" id="id_pedido" name="id_pedido" value="<?php echo $id_pedido; ?>" />
                <input type="hidden" id="dir" name="dir" value="1" />
                <input type="hidden" id="obs_grade" name="obs_grade" value="" />
               
                <div class="container">  
                <table id="gradecabeca" class="table table-striped table-condensed table-bordered">  
                    <thead>  
                        <tr style="background-color: #67aded" align="center">  
                            <td><span style='font-weight:bold;'>Altera Grade - PEDIDO: <?php echo $id; ?></span></td>  
                        </tr>  
                    </thead>  
                </table>
                
                <a href="#collapse1" data-toggle="collapse">detalhes do Pedido</a>
                <div id="collapse1" class="collapse">
                    <div class="row">    
                        <div class="form-group col-md-2">
                            <label for="dtcadastro">Cadastro Pedido</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-1">
                            <label for="idpiloto">Lacre</label>
                            <input type="text" class="form-control" name="id_piloto" id="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="text" class="form-control" id="nr_pedido" name="nr_pedido" value="<?php echo $row['nr_pedido'] ?>" readonly="readonly">
                        </div>
                        
                        <div class="form-group col-md-1">
                            <label for="revista">Revista</label>
                            <input type="text" class="form-control" id="revista" name="revista" value="<?php echo $row['revista'] ?>" readonly="readonly">
                        </div>

                        <div class="form-group col-md-3">
                            <label for="popular_name">Cliente</label> 
                            <input type="text" class="form-control" id="popular_name" name="popular_name" value="<?php echo $row['popular_name'] ?>" readonly="readonly">
                        </div>
                        <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'] ?>" readonly="readonly">
                        </div>
                        
                    </div>
                    <div class="row">
                          
                        <div class="form-group col-md-3">
                            <label for="modelo">Modelo</label>
                            <input type="text" class="form-control" id="modelo" name="modelo" value="<?php echo $row['modelo'] ?>" readonly="readonly">
                        </div>

                        <div class="form-group col-md-3">
                            <label for="modelagem">Modelagem</label>
                            <input type="text" class="form-control" id="modelagem" name="modelagem" value="<?php echo $row['modelagem'] ?>" readonly="readonly">
                        </div>

                        <div class="form-group col-md-4">
                            <label for="tecido">Tecido</label>
                            <input type="text" class="form-control" id="tecido" name="tecido" value="<?php echo $row['tecido'] ?>" readonly="readonly">
                        </div>

                        <div class="form-group col-md-2">
                            <label for="tecido">Largura</label>
                            <input type="text" class="form-control" id="tecido" name="tamanho" value="<?php echo $row['tamanho'] ?>" readonly="readonly">
                        </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'] ?>" readonly="readonly">
                            </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'] ?>" readonly="readonly">                          
                            </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'] ?>" readonly="readonly">                          
                            </div>
                                 
                            <div class="form-group col-sm-6 control-label">
                                <label for="obs">Observações do PEDIDO</label>
                                <div class="">
                                    <textarea name="obs" class="form-control" rows="1" readonly="readonly" ><?php echo $row['obsPed']?></textarea>
                                </div>
                            </div>
                    </div>
                    
                        <div>
                            <a href="pedido_modificar.php?id=<?php echo $row['id']; ?>" class="btn btn-primary">Altera dados do pedido</a>
                        </div>
                        <br>
                </div>
                    <?php
                    $sql = "SELECT grade.*, companies.popular_name, pedidos.*, pedidos.obs AS obsPed FROM pedidos INNER JOIN companies on companies.id = pedidos.nr_company LEFT JOIN grade ON grade.id_pedido = pedidos.id WHERE grade.id_pedido = '$id' and grade.dir = '1'";
                    $resultado = $mysqli->query($sql);
                    $row = $resultado->fetch_array(MYSQLI_ASSOC);
                    ?>     
                    
                    <input type="hidden" id="ativo" name="ativo" value="1" />
                    <input type="hidden" id="id" name="id" value="<?php echo $id; ?>" />
                    <input type="hidden" id="dir" name="dir" value="1" />
                    <input type="hidden" id="obs_grade" name="obs_grade" value="" />

                    <div class="table-responsive">  
                        <table id="gradePedidoz" class="table table-striped table-condensed table-bordered">  
                            <thead>  
                                <tr style="background-color: #d3d3d3" align="center">  
                                    <td width="10%">NOME</td>  
                                    <td>32</td>  
                                    <td>34</td>  
                                    <td>36</td>  
                                    <td>38</td>  
                                    <td>40</td>  
                                    <td>42</td>  
                                    <td>44</td>  
                                    <td>46</td>  
                                    <td>48</td>  
                                    <td>50</td>  
                                    <td>52</td>  
                                    <td>SUBTOTAL</td>  
                                </tr>  
                            </thead>  

                            <form name="gradePedido" method="POST" action="grade_update.php" autocomplete="off">
                            
                               <tr align="center" style="font-weight:bold">  
                                   <td width="10%">
                                   
                                        <input type="text" size ="15" width="1" maxlength="15" id="tituloc1" name="tituloc1" value="<?php echo $row['tituloc1'] ?>" style='text-transform:uppercase' autofocus>  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4"  style="text-align:center;" id="tdc1" name="tdc1" value="<?php echo $row['tdc1'] > 0 ? $row['tdc1'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma()">  
                                   </td>  
                                   <td> 
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="tqc1" name="tqc1" value="<?php echo $row['tqc1'] > 0 ? $row['tqc1'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="tsc1" name="tsc1" value="<?php echo $row['tsc1'] > 0 ? $row['tsc1'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="toc1" name="toc1" value="<?php echo $row['toc1'] > 0 ? $row['toc1'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="quc1" name="quc1" value="<?php echo $row['quc1'] > 0 ? $row['quc1'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="qdc1" name="qdc1" value="<?php echo $row['qdc1'] > 0 ? $row['qdc1'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="qqc1" name="qqc1" value="<?php echo $row['qqc1'] > 0 ? $row['qqc1'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="qsc1" name="qsc1" value="<?php echo $row['qsc1'] > 0 ? $row['qsc1'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="qoc1" name="qoc1" value="<?php echo $row['qoc1'] > 0 ? $row['qoc1'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="cic1" name="cic1" value="<?php echo $row['cic1'] > 0 ? $row['cic1'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="cdc1" name="cdc1" value="<?php echo $row['cdc1'] > 0 ? $row['cdc1'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="subtotalc1" name="subtotalc1" readonly="readonly">  
                                   </td>     
                               </tr>  
                               <tr align="center" style="font-weight:bold">  
                                   <td width="10%">
                                        <input type="text" size ="15" width="1" maxlength="15" style='text-transform:uppercase' value="<?php echo $row['tituloc2'] ?>" id="tituloc2" name="tituloc2">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4"  style="text-align:center;" id="tdc2" name="tdc2" value="<?php echo $row['tdc2'] > 0 ? $row['tdc2'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma()">  
                                   </td>  
                                   <td> 
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="tqc2" name="tqc2" value="<?php echo $row['tqc2'] > 0 ? $row['tqc2'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="tsc2" name="tsc2" value="<?php echo $row['tsc2'] > 0 ? $row['tsc2'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="toc2" name="toc2" value="<?php echo $row['toc2'] > 0 ? $row['toc2'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="quc2" name="quc2" value="<?php echo $row['quc2'] > 0 ? $row['quc2'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="qdc2" name="qdc2" value="<?php echo $row['qdc2'] > 0 ? $row['qdc2'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="qqc2" name="qqc2" value="<?php echo $row['qqc2'] > 0 ? $row['qqc2'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="qsc2" name="qsc2" value="<?php echo $row['qsc2'] > 0 ? $row['qsc2'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="qoc2" name="qoc2" value="<?php echo $row['qoc2'] > 0 ? $row['qoc2'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="cic2" name="cic2" value="<?php echo $row['cic2'] > 0 ? $row['cic2'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="cdc2" name="cdc2" value="<?php echo $row['cdc2'] > 0 ? $row['cdc2'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="subtotalc2" name="subtotalc2" readonly="readonly">  
                                   </td>     
                               </tr>  
                               <tr align="center" style="font-weight:bold">  
                                   <td width="10%">
                                        <input type="text" size ="15" width="1" maxlength="15" style='text-transform:uppercase' value="<?php echo $row['tituloc3'] ?>" id="tituloc3" name="tituloc3">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4"  style="text-align:center;" id="tdc3" name="tdc3" value="<?php echo $row['tdc3'] > 0 ? $row['tdc3'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma()">  
                                   </td>  
                                   <td> 
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="tqc3" name="tqc3" value="<?php echo $row['tqc3'] > 0 ? $row['tqc3'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="tsc3" name="tsc3" value="<?php echo $row['tsc3'] > 0 ? $row['tsc3'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="toc3" name="toc3" value="<?php echo $row['toc3'] > 0 ? $row['toc3'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="quc3" name="quc3" value="<?php echo $row['quc3'] > 0 ? $row['quc3'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="qdc3" name="qdc3" value="<?php echo $row['qdc3'] > 0 ? $row['qdc3'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="qqc3" name="qqc3" value="<?php echo $row['qqc3'] > 0 ? $row['qqc3'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="qsc3" name="qsc3" value="<?php echo $row['qsc3'] > 0 ? $row['qsc3'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="qoc3" name="qoc3" value="<?php echo $row['qoc3'] > 0 ? $row['qoc3'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="cic3" name="cic3" value="<?php echo $row['cic3'] > 0 ? $row['cic3'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="cdc3" name="cdc3" value="<?php echo $row['cdc3'] > 0 ? $row['cdc3'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="subtotalc3" name="subtotalc3" readonly="readonly">  
                                   </td>     
                               </tr>  
								<tr align="center" style="font-weight:bold">  
                                   <td width="10%">
                                        <input type="text" size ="15" width="1" maxlength="15" style='text-transform:uppercase' value="<?php echo $row['tituloc4'] ?>" id="tituloc4" name="tituloc4">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4"  style="text-align:center;" id="tdc4" name="tdc4" value="<?php echo $row['tdc4'] > 0 ? $row['tdc4'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma()">  
                                   </td>  
                                   <td> 
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="tqc4" name="tqc4" value="<?php echo $row['tqc4'] > 0 ? $row['tqc4'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="tsc4" name="tsc4" value="<?php echo $row['tsc4'] > 0 ? $row['tsc4'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="toc4" name="toc4" value="<?php echo $row['toc4'] > 0 ? $row['toc4'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="quc4" name="quc4" value="<?php echo $row['quc4'] > 0 ? $row['quc4'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="qdc4" name="qdc4" value="<?php echo $row['qdc4'] > 0 ? $row['qdc4'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="qqc4" name="qqc4" value="<?php echo $row['qqc4'] > 0 ? $row['qqc4'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="qsc4" name="qsc4" value="<?php echo $row['qsc4'] > 0 ? $row['qsc4'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="qoc4" name="qoc4" value="<?php echo $row['qoc4'] > 0 ? $row['qoc4'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="cic4" name="cic4" value="<?php echo $row['cic4'] > 0 ? $row['cic4'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="cdc4" name="cdc4" value="<?php echo $row['cdc4'] > 0 ? $row['cdc4'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="subtotalc4" name="subtotalc4" readonly="readonly">  
                                   </td>     
                               </tr>  
                               <tr align="center" style="font-weight:bold">  
                                   <td width="10%">
                                        <input type="text" size ="15" width="1" maxlength="15" style='text-transform:uppercase' value="<?php echo $row['tituloc5'] ?>" id="tituloc5" name="tituloc5">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4"  style="text-align:center;" id="tdc5" name="tdc5" value="<?php echo $row['tdc5'] > 0 ? $row['tdc5'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma()">  
                                   </td>  
                                   <td> 
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="tqc5" name="tqc5" value="<?php echo $row['tqc5'] > 0 ? $row['tqc5'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="tsc5" name="tsc5" value="<?php echo $row['tsc5'] > 0 ? $row['tsc5'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="toc5" name="toc5" value="<?php echo $row['toc5'] > 0 ? $row['toc5'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="quc5" name="quc5" value="<?php echo $row['quc5'] > 0 ? $row['quc5'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="qdc5" name="qdc5" value="<?php echo $row['qdc5'] > 0 ? $row['qdc5'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="qqc5" name="qqc5" value="<?php echo $row['qqc5'] > 0 ? $row['qqc5'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="qsc5" name="qsc5" value="<?php echo $row['qsc5'] > 0 ? $row['qsc5'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="qoc5" name="qoc5" value="<?php echo $row['qoc5'] > 0 ? $row['qoc5'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="cic5" name="cic5" value="<?php echo $row['cic5'] > 0 ? $row['cic5'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="cdc5" name="cdc5" value="<?php echo $row['cdc5'] > 0 ? $row['cdc5'] : '';  ?>" onkeypress='return SomenteNumero(event)' onBlur="soma();">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4" style="text-align:center;" id="subtotalc5" name="subtotalc5" readonly="readonly">  
                                   </td>     
                               </tr>  
                                                              
                               <tr align="center" style="background-color: #d3d3d3">  
                                   <td width="10%">
                                    Soma Futura
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4"  style="text-align:center;" id="somatdc" name="somatdc" readonly="readonly">  
                                   </td>  
                                   <td> 
                                        <input type="text" size ="4" width="1" maxlength="4"  style="text-align:center;" id="somatqc" name="somatqc" readonly="readonly">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4"  style="text-align:center;" id="somatsc" name="somatsc" readonly="readonly">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4"  style="text-align:center;" id="somatoc" name="somatoc" readonly="readonly">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4"  style="text-align:center;" id="somaquc" name="somaquc" readonly="readonly">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4"  style="text-align:center;" id="somaqdc" name="somaqdc" readonly="readonly">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4"  style="text-align:center;" id="somaqqc" name="somaqqc" readonly="readonly">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4"  style="text-align:center;" id="somaqsc" name="somaqsc" readonly="readonly">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4"  style="text-align:center;" id="somaqoc" name="somaqoc" readonly="readonly">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4"  style="text-align:center;" id="somacic" name="somacic" readonly="readonly">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4"  style="text-align:center;" id="somacdc" name="somacdc" readonly="readonly">  
                                   </td>  
                                   <td>  
                                        <input type="text" size ="4" width="1" maxlength="4"  style="text-align:center;" id="somageralc" name="somageralc" readonly="readonly">  
                                   </td>     
                               </tr>  
                                   
                                   
                            </form>
                        </table>
                    </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-danger">ATUALIZA GRADE</button>
                                </div>
                            </div>
                        </div>

                </div>            
            </form>  

<script type="text/javascript">
window.onload = function()
{
   soma();
}
</script>   

<script language='JavaScript'>
function soma() 
{
gradePedido.subtotalc1.value = (gradePedido.tdc1.value*1) + (gradePedido.tqc1.value*1) + (gradePedido.tsc1.value*1) + (gradePedido.toc1.value*1) + (gradePedido.quc1.value*1) + (gradePedido.qdc1.value*1) + (gradePedido.qqc1.value*1) + (gradePedido.qsc1.value*1) + (gradePedido.qoc1.value*1) + (gradePedido.cic1.value*1) + (gradePedido.cdc1.value*1)
gradePedido.subtotalc2.value = (gradePedido.tdc2.value*1) + (gradePedido.tqc2.value*1) + (gradePedido.tsc2.value*1) + (gradePedido.toc2.value*1) + (gradePedido.quc2.value*1) + (gradePedido.qdc2.value*1) + (gradePedido.qqc2.value*1) + (gradePedido.qsc2.value*1) + (gradePedido.qoc2.value*1) + (gradePedido.cic2.value*1) + (gradePedido.cdc2.value*1)
gradePedido.subtotalc3.value = (gradePedido.tdc3.value*1) + (gradePedido.tqc3.value*1) + (gradePedido.tsc3.value*1) + (gradePedido.toc3.value*1) + (gradePedido.quc3.value*1) + (gradePedido.qdc3.value*1) + (gradePedido.qqc3.value*1) + (gradePedido.qsc3.value*1) + (gradePedido.qoc3.value*1) + (gradePedido.cic3.value*1) + (gradePedido.cdc3.value*1)
gradePedido.subtotalc4.value = (gradePedido.tdc4.value*1) + (gradePedido.tqc4.value*1) + (gradePedido.tsc4.value*1) + (gradePedido.toc4.value*1) + (gradePedido.quc4.value*1) + (gradePedido.qdc4.value*1) + (gradePedido.qqc4.value*1) + (gradePedido.qsc4.value*1) + (gradePedido.qoc4.value*1) + (gradePedido.cic4.value*1) + (gradePedido.cdc4.value*1)
gradePedido.subtotalc5.value = (gradePedido.tdc5.value*1) + (gradePedido.tqc5.value*1) + (gradePedido.tsc5.value*1) + (gradePedido.toc5.value*1) + (gradePedido.quc5.value*1) + (gradePedido.qdc5.value*1) + (gradePedido.qqc5.value*1) + (gradePedido.qsc5.value*1) + (gradePedido.qoc5.value*1) + (gradePedido.cic5.value*1) + (gradePedido.cdc5.value*1)

gradePedido.somatdc.value = (gradePedido.tdc1.value*1) + (gradePedido.tdc2.value*1) + (gradePedido.tdc3.value*1) + (gradePedido.tdc4.value*1) + (gradePedido.tdc5.value*1)
gradePedido.somatqc.value = (gradePedido.tqc1.value*1) + (gradePedido.tqc2.value*1) + (gradePedido.tqc3.value*1) + (gradePedido.tqc4.value*1) + (gradePedido.tqc5.value*1)
gradePedido.somatsc.value = (gradePedido.tsc1.value*1) + (gradePedido.tsc2.value*1) + (gradePedido.tsc3.value*1) + (gradePedido.tsc4.value*1) + (gradePedido.tsc5.value*1)
gradePedido.somatoc.value = (gradePedido.toc1.value*1) + (gradePedido.toc2.value*1) + (gradePedido.toc3.value*1) + (gradePedido.toc4.value*1) + (gradePedido.toc5.value*1)
gradePedido.somaquc.value = (gradePedido.quc1.value*1) + (gradePedido.quc2.value*1) + (gradePedido.quc3.value*1) + (gradePedido.quc4.value*1) + (gradePedido.quc5.value*1)
gradePedido.somaqdc.value = (gradePedido.qdc1.value*1) + (gradePedido.qdc2.value*1) + (gradePedido.qdc3.value*1) + (gradePedido.qdc4.value*1) + (gradePedido.qdc5.value*1)
gradePedido.somaqqc.value = (gradePedido.qqc1.value*1) + (gradePedido.qqc2.value*1) + (gradePedido.qqc3.value*1) + (gradePedido.qqc4.value*1) + (gradePedido.qqc5.value*1)
gradePedido.somaqsc.value = (gradePedido.qsc1.value*1) + (gradePedido.qsc2.value*1) + (gradePedido.qsc3.value*1) + (gradePedido.qsc4.value*1) + (gradePedido.qsc5.value*1)
gradePedido.somaqoc.value = (gradePedido.qoc1.value*1) + (gradePedido.qoc2.value*1) + (gradePedido.qoc3.value*1) + (gradePedido.qoc4.value*1) + (gradePedido.qoc5.value*1)
gradePedido.somacic.value = (gradePedido.cic1.value*1) + (gradePedido.cic2.value*1) + (gradePedido.cic3.value*1) + (gradePedido.cic4.value*1) + (gradePedido.cic5.value*1)
gradePedido.somacdc.value = (gradePedido.cdc1.value*1) + (gradePedido.cdc2.value*1) + (gradePedido.cdc3.value*1) + (gradePedido.cdc4.value*1) + (gradePedido.cdc5.value*1)

gradePedido.somageralc.value = 
(gradePedido.somatdc.value*1) + (gradePedido.somatqc.value*1) + (gradePedido.somatsc.value*1) + (gradePedido.somatoc.value*1) + 
(gradePedido.somaquc.value*1) + (gradePedido.somaqdc.value*1) + (gradePedido.somaqqc.value*1) + (gradePedido.somaqsc.value*1) + 
(gradePedido.somaqoc.value*1) + (gradePedido.somacic.value*1) + (gradePedido.somacdc.value*1)
}

</script>

<script language='JavaScript'>
function SomenteNumero(e){
    var tecla=(window.event)?event.keyCode:e.which;   
    if((tecla>47 && tecla<58)) return true;
    else{
    	if (tecla==8 || tecla==0) return true;
	else  return false;
    }
}
</script>

<?php include(FOOTER_TEMPLATE); ?>
