<?php
	$tdat = 0;
	$tqat = 0;
	$tsat = 0;
	$toat = 0;
	$quat = 0;
	$qdat = 0;
	$qqat = 0;
	$qsat = 0;
	$qoat = 0;
	$ciat = 0;
	$cdat = 0;
	$totalg = 0;

    $sqlOc = "SELECT ordem_corte.*, companies.popular_name, grade.*, pedidos.id, pedidos.modelo, pedidos.modelagem, pedidos.nr_company, pedidos.id_piloto, pedidos.revista, pedidos.dtcadastro, pedidos.data_pre, pedidos.data_pedido,pedidos.data_entrega,pedidos.nr_pedido, pedidos.referencia, pedidos.descricao, pedidos.descricao, pedidos.quantidade, pedidos.tecido, pedidos.dt_baixado, pedidos.obs AS obsPed, pedidos.ativo FROM grade RIGHT OUTER JOIN pedidos ON pedidos.id = grade.id_pedido LEFT JOIN companies on companies.id = pedidos.nr_company INNER JOIN ordem_corte ON ordem_corte.id_pedido = pedidos.id WHERE pedidos.id = '$id' AND grade.dir <> '4' AND grade.titulo ='FORRO' ";
    $resultadoOc = $mysqli->query($sqlOc);
    $row = $resultadoOc->fetch_array(MYSQLI_ASSOC);
?>
            <h4 style="text-align:center">Grade Cortada - FORRO</h4>
            <table class="table table-condensed  table-bordered">
                <thead>
                  <tr>
                    <th><h4 style="text-align:center">Setor</h4></th>
                    <th><h4 style="text-align:center">Obs</h4></th>
                    <th><h5 style="text-align:center">%</h5></th>                            
                    <th><h3 style="text-align:center">32</h3></th>
                    <th><h3 style="text-align:center">34</h3></th>
                    <th><h3 style="text-align:center">36</h3></th>
                    <th><h3 style="text-align:center">38</h3></th>
                    <th><h3 style="text-align:center">40</h3></th>
                    <th><h3 style="text-align:center">42</h3></th>
                    <th><h3 style="text-align:center">44</h3></th>
                    <th><h3 style="text-align:center">46</h3></th>
                    <th><h3 style="text-align:center">48</h3></th>
                    <th><h3 style="text-align:center">50</h3></th>
                    <th><h3 style="text-align:center">52</h3></th>
                    <th><h3 style="text-align:center">Subtotal</h3></th>
                  </tr>
                </thead>

                <tbody>
                    <?php 
                    $resultadoOc = $mysqli->query($sqlOc);
                    while($row = $resultadoOc->fetch_array(MYSQLI_ASSOC)) { ?>
                        
                        <input type="hidden" id="id_grade" name="id_grade" value="<?php echo $row['id_grade']; ?>" />
                        <input type="hidden" id="id" name="id" value="<?php echo $row['id']; ?>" />

                        
                        <tr>
                            <td><?php echo $row['titulo'] ?></td>
                            <td><?php echo $row['obs_grade'] ?></td>
                            <td><?php echo $row['ajuste'] ?></td>

                            <td align="center"><?php echo $row['tda'] ?></td>
                                <?php $tdat += $row['tda']; ?>

                            <td align="center"><?php echo $row['tqa'] ?></td>
                                <?php $tqat += $row['tqa'];?>

                            <td align="center"><?php echo $row['tsa'] ?></td>
                                <?php $tsat += $row['tsa'];?> 

                            <td align="center"><?php echo $row['toa'] ?></td>
                                <?php $toat += $row['toa'];?> 

                            <td align="center"><?php echo $row['qua'] ?></td>
                                <?php $quat += $row['qua'];?> 

                            <td align="center"><?php echo $row['qda'] ?></td>
                                <?php $qdat += $row['qda'];?> 

                            <td align="center"><?php echo $row['qqa'] ?></td>
                                <?php $qqat += $row['qqa'];?> 

                            <td align="center"><?php echo $row['qsa'] ?></td>
                                <?php $qsat += $row['qsa'];?> 

                            <td align="center"><?php echo $row['qoa'] ?></td>
                                <?php $qoat += $row['qoa'];?> 

                            <td align="center"><?php echo $row['cia'] ?></td>
                                <?php $ciat += $row['cia'];?> 

                            <td align="center"><?php echo $row['cda'] ?></td>
                                <?php $cdat += $row['cda'];?> 

                            <td align="center"><?php echo $row['subtotal'] ?></td>
                                <?php $totalg += $row['subtotal']; ?>

                            <?php if (($route) == 'oc_on') { ?>
								<td> <a href="grade_edita_linha_oc.php?id_grade=<?php echo $row['id_grade']; ?>&id=<?php echo $row['id']; ?>"> <span class="glyphicon glyphicon-plus-sign"></a></td>
							<?php }	?>

								
                        </tr>
                    <?php } ?>
                </tbody>
                
                
                <tr>
                <td>
					<?php if (($route) == 'oc_on') { ?>
						<a href="oc_index.php" class="btn btn-info">Retornar</a>
					<?php }	else {?>
						<a href="oc_index.php" class="btn btn-default">Retornar</a>
					<?php }	?>
                </td>

                    <td>
                        <?php   $resultadoOc = $mysqli->query($sqlOc);
                                $row = $resultadoOc->fetch_array(MYSQLI_ASSOC);?>
                        <?php if (($route) == 'oc_on') { ?>
							<a href="grade_adiciona_oc.php?id=<?php echo $id; ?>&route=riscos" class="btn btn-primary">Adiciona linha Grade Cortada</a>
						<?php }	else {?>
							<a href="" class="btn btn-default" disabled>Grade em Produção</a>
						<?php }	?>

                    </td>
                    <td>
                    </td>                    
                    <td align="center">
                        <input type="text" class="form-control" id="tdat" name="tdat" value="<?php echo $tdat ?>" readonly="readonly" style="min-width:55px;">
                    </td>
                    <td>
                        <input type="text" class="form-control" id="tqat" name="tqat" value="<?php echo $tqat ?>" readonly="readonly" disabled style="min-width:55px;">
                    </td>
                    <td>
                        <input type="text" class="form-control" id="tsat" name="tsat" value="<?php echo $tsat ?>" readonly="readonly" style="min-width:55px;">
                    </td>
                    <td>
                        <input type="text" class="form-control" id="toat" name="toat" value="<?php echo $toat ?>" readonly="readonly" style="min-width:55px;">
                    </td>
                    <td>
                        <input type="text" class="form-control" id="quat" name="quat" value="<?php echo $quat ?>" readonly="readonly" style="min-width:55px;">
                    </td>
                    <td>
                        <input type="text" class="form-control" id="qdat" name="qdat" value="<?php echo $qdat ?>" readonly="readonly" style="min-width:55px;">
                    </td>
                    <td>
                        <input type="text" class="form-control" id="qqat" name="qqat" value="<?php echo $qqat ?>" readonly="readonly" style="min-width:55px;">
                    </td>
                    <td>
                        <input type="text" class="form-control" id="qsat" name="qsat" value="<?php echo $qsat ?>" readonly="readonly" style="min-width:55px;"> 
                    </td>
                    <td>
                        <input type="text" class="form-control" id="qoat" name="qoat" value="<?php echo $qoat ?>" readonly="readonly" style="min-width:55px;">
                    </td>
                    <td>
                        <input type="text" class="form-control" id="ciat" name="ciat" value="<?php echo $ciat ?>" readonly="readonly" style="min-width:55px;">
                    </td>
                    <td>
                        <input type="text" class="form-control" id="cdat" name="cdat" value="<?php echo $cdat ?>" readonly="readonly" style="min-width:55px;">
                    </td>
                    <td>
                        <input type="text" align="middle" class="form-control" id="totalg" name="totalg" value="<?php echo $totalg ?>" readonly="readonly" style="min-width:60px;">
                    </td>
                </tr>
            </table>