<?php 
function naturaleza($campo){
    if ($campo==1)
         $campo= "DEBE";
    else
        $campo="HABER";
    return $campo;
}
function titulo($campo){
    if ($campo==1)
         $campo= "TITULO";
    else
        $campo="MOVIMIENTO";
    return $campo;
}
function sino($campo){
    if ($campo==true)
         $campo= "SI";
    else
        $campo="NO";
    return $campo;
}
function muestraNivel($nivel) {
        
        switch ($nivel) {
            case 1:
                $nivel='Rubro';
                break;
            case 2:
                $nivel='Grupo';
                break;
            case 3:
                $nivel='Cuenta';
                break;
            case 4:
                $nivel='Primera Subcuenta';
                break;
            case 5:
                $nivel='Segunda Subcuenta';
                break;
            case 6:
                $nivel='Tercera Subcuenta';
                break;
             default :
                $nivel='Auxiliar';
                break;       
        }
        return $nivel;
        
    }

 $id= Yii::app()->user->id;
 $modelousuario= CrugeUserI::model()->findByPk($id);
 $usuario=$modelousuario->nombres.' '.$modelousuario->apellidos;
   

$pdf = Yii::createComponent('application.extensions.mpdf60.mpdf');
$dataProvider = $_SESSION['datos_filtrados']->getData();
//echo "<pre>";print_r($dataProvider);exit;
$html.='<link rel="stylesheet" type="text/css" href="'.Yii::app()->request->baseUrl.'/css/pdf.css" />
<table class="detail-view" repeat_header="1" cellpadding="1" cellspacing="1"
width="100%" border="0">
<thead>
<tr >
<th  width="10%">Código cuenta</th>
<th  width="65%">Descripción</th>
<th  width="5%">Naturaleza</th>
<th class="principal" width="5%">Grupo Contable</th>
<th  width="5%">Tipo</th>
<th  width="5%">Nivel</th>
<th class="principal" width="5%">Sudeca</th>
</tr></thead>

';
$i=0;
$val=count($dataProvider);
while($i<$val){
   
   if ($dataProvider[$i]["nivel"]==1){     
   $color="azul";  
   }else if ($dataProvider[$i]["nivel"]==2){
   $color="verde";  
   }else if ($dataProvider[$i]["nivel"]==3){
   $color="naranja";  
   }else if ($dataProvider[$i]["nivel"]==4){
        if ($dataProvider[$i]["titulo_mov"]==1)
            $color="vinotinto";  
        else
        $color="white";  
   }else if ($dataProvider[$i]["nivel"]==5){
        if ($dataProvider[$i]["titulo_mov"]==1)
                $color="negrita";  
        else
            $color="white";   
   }else if ($dataProvider[$i]["nivel"]==6){
         if ($dataProvider[$i]["titulo_mov"]==1)
            $color="gris";  
         else
            $color="white";  
   }else {
   $color="white";  
   }
$html.='
<tbody  >    
<tr>
<td  class='.$color.'>'.$dataProvider[$i]["codigo_cuenta"].'</td>
<td  class='.$color.'>'.$dataProvider[$i]["descripcion"].'</td>
<td  class='.$color.'>'.naturaleza($dataProvider[$i]["naturaleza"]).'</td>
<td  class='.$color.'>'.$dataProvider[$i]["Grupo"]["descripcion"].'</td>
<td  class='.$color.'>'.titulo($dataProvider[$i]["titulo_mov"]).'</td>
<td  class='.$color.'>'.muestraNivel($dataProvider[$i]["nivel"]).'</td>
<td  class='.$color.'>'.sino($dataProvider[$i]["sudeca"]).'</td>
';
$html.='</tr></tbody>';
$i++;
}
$html.='</table>';
//echo $html; exit;
$date= date("d-m-Y");
$mpdf=new mPDF('win-1252','LETTER-L','','',9,9,24,10,5,5);
$header=$header.'<p align="right" style="font-size:11px;">'.$pag.'</p><p align="center" style="font-family:Arial"><b>'.Empresa::RazonSocial().'<BR>
     RIF '.Empresa::Rif().'<br>
  <h5 style="text-align:center">Plan de cuentas contables emitido por la Superintendencia de Cajas de Ahorro</h5></p>
   
    ';
$mpdf->SetHTMLHeader($header);
$mpdf->SetFooter('Generado por: '. $usuario.' {DATE j/m/Y}|Página {PAGENO}/{nbpg}|Saica');
$mpdf->WriteHTML($html);
$mpdf->Output('Plan_cuentas_'.$date.'.pdf','D');
exit; ?>