<?php    
        $data = $data['data'];                   
        
        $pdf = new PDF();
        $pdf->AddPage('P','');
        
        $empresaRepo = new CompanyRepository();
        $empresaData = $empresaRepo->getById(1);
        
        $login = new Login();
        
        $pdf->SetFont('Arial','B','11');     
        $pdf->Cell(190, 5, $empresaData['name'], '0', 1, 'C'); //<== margin left   
        $pdf->Cell(190, 5, strtoupper($this->_getTranslation($this->getTituloReporte())), '0', 1, 'C'); //<== margin left   
        $pdf->Cell(190, 5, "SUCURSAL: ". $login->getStoreName(), '0', 1, 'C'); //<== margin left   
        $pdf->Cell(190, 5, "FECHA: ".date('m/d/Y'), '0', 1, 'C'); //<== margin left   
        
        $i = 1;
        $j = 1;  
        $k = 1;
        $yForComments = $pdf->GetY();
        
        foreach($data as $areaName => $detalles){
            $y = $pdf->GetY();
            $x = $pdf->GetX();
            
            $showSizeName = null;
            $widthTitleArea = 90;
            //if(strtolower($areaName) == 'pasteleria'){$showSizeName = true;$widthTitleArea +=30;}
                         
            $pdf->SetFont('Arial','B','8');             
            $pdf->SetFillColor(245,245,245); 
            $pdf->Cell($widthTitleArea, 5, $areaName, 'B', 1, 'L');
            $pdf->SetX($x);
            $pdf->Cell(65, 5, "Producto", 'B', 0, 'L');
            //if($showSizeName){$pdf->Cell(30, 5, utf8_decode("Tamaño"), 'B', 0, 'L');}
            $pdf->Cell(25, 5, "Existencias", 'B', 1, 'R');           
              
            $fila = 2;
            $pdf->SetFont('Arial','','8');            
            foreach($detalles as $detalle){      
                if ($fila%2==0){$backgroundcolor = true;}
                else{$backgroundcolor = null;}     
                /*
                $pdf->Cell(60, 5, utf8_decode($detalle['description']), '0', 0, 'L',$backgroundcolor);
                //if($showSizeName){$pdf->Cell(30, 5, utf8_decode($detalle['sizeName']), '0', 0, 'L',$backgroundcolor);}
                $pdf->Cell(25, 5, "", '0', 1, 'R',$backgroundcolor);
                */
                $fila++;
                
                
                /*TITULOS PARA SEGUNDA COLUMNA*/
                if($j > 30){
                    $j = 1;                
                    $yForComments = $pdf->GetY();
                    $pdf->SetY($y);
                    $pdf->SetFont('Arial','B','8');
                    $pdf->Cell(98, 7, "", '', 0, 'L');/*Margin left*/
                    $pdf->Cell(90, 7, $areaName, 'B', 1, 'L');
                    
                    $pdf->Cell(98, 7, "", '', 0, 'L');/*Margin left*/
                    $pdf->Cell(5, 7, "#", 'B', 0, 'L');
                    $pdf->Cell(60, 7, "Producto", 'B', 0, 'L');
                    $pdf->Cell(25, 7, "Existencias", 'B', 1, 'R');              
                }
                
                /* SEGUNDA COLUMNA */
                if($k > 30){
                    $pdf->SetFont('Arial','','8');
                    $pdf->Cell(98, 7, "", '', 0, 'L');/*Margin left*/    
                    $x = $pdf->GetX();                
                    $pdf->Cell(5, 5, $i, 'B', 0, 'C',$backgroundcolor);
                    $pdf->Cell(60, 5, utf8_decode($detalle['description']), 'B', 0, 'L',$backgroundcolor);
                    $pdf->Cell(25, 5, "", 'B', 1, 'R',$backgroundcolor);

                /* PRIMER COLUMNA */
                }else{                          
                    $pdf->SetFont('Arial','','8');
                    $pdf->Cell(5, 5, $i, 'B', 0, 'C',$backgroundcolor);
                    $pdf->Cell(60, 5, utf8_decode($detalle['description']), 'B', 0, 'L',$backgroundcolor);
                    $pdf->Cell(25, 5, "", 'B', 1, 'R',$backgroundcolor);
                    $yForComments = $pdf->GetY();                    
                }            
                $i++;
                $j++;
                $k++;   
            }         
            
            $pdf->ln(5);
            $pdf->SetX($x);
        }
        
        $pdf->SetY($yForComments);
        $pdf->Ln(5);    
        $pdf->Cell(190, 6, "Notas de inventario", 'B', 1, 'L');  
        $pdf->Cell(190, 30, "", '0', 1, 'L'); 
        
        $pdf->Ln(30);
        $pdf->Cell(65, 6, "", '', 0, 'C'); 
        $pdf->Cell(65, 6, "", 'B', 1, 'C'); 
        $pdf->Cell(190, 6, "Realizado por", '', 1, 'C');     
        
        if($this->saveFile == true){    
            $pdf->Output($this->getTempFolder()."/".$this->getNombreArchivo().".pdf","F");
        }else{
            $pdf->Output();
        }
        
        
        
       

    

