<?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;
	
	$route = $_GET['route'];
	//print_r ($route);
	if (($route) == 'prod_on') {
		$route = "prod_on";
	} else {
		$route = "oc_on";
	}
    $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 = 'RISCOS'";
    $resultadoOc = $mysqli->query($sqlOc);
    $row = $resultadoOc->fetch_array(MYSQLI_ASSOC);

?>
            <h4 style="text-align:center">Grade Cortada - RISCOS</h4>
            <table class="table table-striped table-condensed table-bordered">
                <thead>
                  <tr bgcolor="#c1c1c1">
                    <th><h5 style="text-align:center">Setor</h5></th>
                    <th><h5 style="text-align:center">Obs</h5></th>
                    <th><h5 style="text-align:center">%</h5></th>                            
                    <th><h5 style="text-align:center">32</h5></th>
                    <th><h5 style="text-align:center">34</h5></th>
                    <th><h5 style="text-align:center">36</h5></th>
                    <th><h5 style="text-align:center">38</h5></th>
                    <th><h5 style="text-align:center">40</h5></th>
                    <th><h5 style="text-align:center">42</h5></th>
                    <th><h5 style="text-align:center">44</h5></th>
                    <th><h5 style="text-align:center">46</h5></th>
                    <th><h5 style="text-align:center">48</h5></th>
                    <th><h5 style="text-align:center">50</h5></th>
                    <th><h5 style="text-align:center">52</h5></th>
                    <th><h5 style="text-align:center">Subtotal</h5></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 style="width:80px;"><?php echo $row['titulo'] ?></td>
                            <td style="width:158px;"><?php echo $row['obs_grade'] ?></td>
                            <td><?php echo $row['ajuste'] ?></td>
                            <td><h5 style="text-align:center"><?php echo $row['tda'] ?></h5> </td>
                                <?php $tdat += $row['tda']; ?>

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

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

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

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

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

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

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

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

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

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

							<td><h5 style="text-align:center"><?php echo $row['subtotal'] ?></h5> </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']; ?>&route=riscos"> <span class="glyphicon glyphicon-plus-sign"></a></td>
							<?php }	?>
                                
                        </tr>
                    <?php } ?>
                </tbody>
                
                
                <tr>
                
                    <td>
                        <?php if (($route) == 'oc_on') { ?>
                            <a></a>
                        <?php }	else {?>
                            <a href="producao_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 Risco</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" size ="2" width="1" maxlength="3" style="text-align:center;" id="tdat" name="tdat" value="<?php echo $tdat ?>" readonly="readonly" disabled style="min-width:55px;">
                    </td>
                    <td align='center'>
                        <input type="text" size ="2" width="1" maxlength="3" style="text-align:center;" id="tqat" name="tqat" value="<?php echo $tqat ?>" readonly="readonly" disabled style="min-width:55px;">
                    </td>
                    <td align='center'>
                        <input type="text" size ="2" width="1" maxlength="3" style="text-align:center;" id="tsat" name="tsat" value="<?php echo $tsat ?>" readonly="readonly" disabled style="min-width:55px;">
                    </td>
                    <td align='center'>
                        <input type="text" size ="2" width="1" maxlength="3" style="text-align:center;" id="toat" name="toat" value="<?php echo $toat ?>" readonly="readonly" disabled style="min-width:55px;">
                    </td>
                    <td align='center'>
                        <input type="text" size ="2" width="1" maxlength="3" style="text-align:center;" id="quat" name="quat" value="<?php echo $quat ?>" readonly="readonly" disabled style="min-width:55px;">
                    </td>
                    <td align='center'>
                        <input type="text" size ="2" width="1" maxlength="3" style="text-align:center;" id="qdat" name="qdat" value="<?php echo $qdat ?>" readonly="readonly" disabled style="min-width:55px;">
                    </td>
                    <td align='center'>
                        <input type="text" size ="2" width="1" maxlength="3" style="text-align:center;" id="qqat" name="qqat" value="<?php echo $qqat ?>" readonly="readonly" disabled style="min-width:55px;">
                    </td>
                    <td align='center'>
                        <input type="text" size ="2" width="1" maxlength="3" style="text-align:center;" id="qsat" name="qsat" value="<?php echo $qsat ?>" readonly="readonly" disabled style="min-width:55px;"> 
                    </td>
                    <td align='center'>
                        <input type="text" size ="2" width="1" maxlength="3" style="text-align:center;" id="qoat" name="qoat" value="<?php echo $qoat ?>" readonly="readonly" disabled style="min-width:55px;">
                    </td>
                    <td align='center'>
                        <input type="text" size ="2" width="1" maxlength="3" style="text-align:center;" id="ciat" name="ciat" value="<?php echo $ciat ?>" readonly="readonly" disabled style="min-width:55px;">
                    </td>
                    <td align='center'>
                        <input type="text" size ="2" width="1" maxlength="3" style="text-align:center;" id="cdat" name="cdat" value="<?php echo $cdat ?>" readonly="readonly" disabled style="min-width:55px;">
                    </td>
                    <td align='center'>
                        <input type="text" size ="2" width="1" maxlength="3" style="text-align:center;" id="totalg" name="totalg" value="<?php echo $totalg ?>" readonly="readonly" disabled style="min-width:60px;">
                    </td>
                </tr>
            </table>