
<?php
class Agro_View_Helper_PlanilhaClassificacaoFrutos extends Zend_View_Helper_Abstract {
    public function PlanilhaClassificacaoFrutos($Configuracoes, $Amostras = array(), $vlPercentPerdas = 0, $flDisable = false, $flReadonly = false) {
?>
    <script type="text/javascript">
        function enableClassificacaoFrutos() {
            $(".classificacao-frutos").removeAttr("disabled");
        }
        
        function disableClassificacaoFrutos() {
            $(".classificacao-frutos").attr("disabled", "disabled");
        }

    </script>
    <table width="100%" class="grid" style="border-collapse: ;">
        <thead>
            <tr>
            	<th></th>
                <th align="center">Amostra</th>
                <?for ($x = 1; $x <= $Configuracoes['nr_amostras']; $x++):?>
                <th align="center"><?=$x?></th>
                <?endfor?>
                <th>Total</th>
                <th>Total (%)</th>
            </tr>
        </thead>
        <tbody>
<?
        $TotaisFrutosAmostras = array();
        $nrTotalFrutos = 0;
        $vlDepreciacaoTotal = 0;
		$aux = 0;
		
        for ($x = 0; $x < count($Configuracoes['categorias']); $x++) {
            $Categoria1 = $Configuracoes['categorias'][$x];
            $CategoriasRestantes = array_slice($Configuracoes['categorias'], $x);
            foreach ($CategoriasRestantes as $Categoria2) {
                $vlTotalCategoria = 0;

				if($Categoria2['ds_nome_exibicao'] == 'Descarte'){
					$style = "border-bottom: 2px solid #009933;";
				}else{
					$style = '';
				}
				
				if($x == 0 && $Categoria2['ds_nome_exibicao'] == 'CAT 1'){
					$style .= "border-top: 2px solid #009933";
				}
?> 				
				
	            <tr>
					<th style="<?=$style?>"><?=$Categoria1['ds_nome_exibicao']?></th>               
                
                	<th style="<?=$style?>"><?=$Categoria2['ds_nome_exibicao']?></th>
<?
                for ($y = 1; $y <= $Configuracoes['nr_amostras']; $y++) {
                    $dsNomeCampo = $Configuracoes['ds_prefixo_com_dano'].$Categoria1['ds_nome_campo'].'_'.$Categoria2['ds_nome_campo'];
                    $vlValue = '';
                    if (array_key_exists($y, $Amostras)) {
                        if (array_key_exists($dsNomeCampo, $Amostras[$y])) {
                            $vlValue = $Amostras[$y][$dsNomeCampo];
                            $TotaisFrutosAmostras[$y] += $vlValue;
                            $vlTotalCategoria += $vlValue;
                            $nrTotalFrutos += $vlValue;
                        }
                    }
?>
                <td align="center" style="<?=$style?>">
                    <input type="text" name="<?=$dsNomeCampo?>[<?=$y?>]" id="<?=$dsNomeCampo.'_'.$y?>" class="integer classificacao-frutos" size="3" value="<?=$vlValue?>"<?if ($flDisable) echo ' disabled'?><?if ($flReadonly) echo ' readonly'?> />
                </td>
<?
                }
?>
                <td style="<?=$style?>"><?=$vlTotalCategoria?></td>
                <td style="<?=$style?>">
<?
                    $vlDepreciacao = $vlTotalCategoria * $Configuracoes['depreciacao'][$Categoria1['ds_nome_campo'].'_'.$Categoria2['ds_nome_campo']]; 
                    echo $vlDepreciacao;
                    $vlDepreciacaoTotal += $vlDepreciacao;
?>
                </td>
            </tr>
<?
            } 
        }
?>
            <tr>
            	<th></th>
                <th>Total</th>
                <?for ($x = 1; $x <= $Configuracoes['nr_amostras']; $x++):?>
                <td align="center">
                    <?if (array_key_exists($x, $TotaisFrutosAmostras)) echo $TotaisFrutosAmostras[$x]?>
                </td>
                <?endfor?>
                <td><?=$nrTotalFrutos?></td>
                <td><?=$vlDepreciacaoTotal?></td>
            </tr>
            <tr>
            	<th></th>
                <th colspan="<?=$Configuracoes['nr_amostras']?>"></th>
                <th>Total (%)</th>
                <th colspan="2"><?=$vlPercentPerdas?></th>
            </tr>
        </tbody>
    </table>
<?
    }
}