package ordentrabajoServlet;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Locale;
import java.util.ResourceBundle;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import m05bClasses.m05bComun;
import m05bClasses.m05bConexion;
import m05bClasses.m05bConstantes;
import m05bClasses.m05bConstantesInformes;
import m05bClasses.m05bDescrip;
import m05bClasses.m05bFileLog;
import m05bClasses.m05bInformes;

import org.apache.fop.apps.Driver;
import org.apache.fop.apps.FOPException;
import org.xml.sax.InputSource;


public class m05bImpOTServlet extends javax.servlet.http.HttpServlet
{
		 java.sql.Connection conn=null;
    	 m05bFileLog miLog = new m05bFileLog(); 
    	 m05bComun miComun = new m05bComun();
		 m05bConexion miConex = new m05bConexion();
		 m05bInformes miInforme = new m05bInformes();
		 m05bDescrip miDescrip = new m05bDescrip();
		 
		String sLinea;
        File foFileDir ;
        File tmpFoFile ;
		FileOutputStream tmpFoFileStream ;
		 


   public static final String FO_REQUEST_PARAM = "fo";
//    Logger log = null;

   public void doPost(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
   {
 	   try{
		      doGet(request, response);
		    }catch (Exception e){
		      miLog.addTraza(e);
		    }
   }

   public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException
   {
      performTask(request, response);
   }

   public void performTask(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws ServletException
   {
   	   String sSqlOrdenes="", sSqlReparaciones="", sSqlPiezas="";
	   PreparedStatement pstmtOT = null, pstmtRep = null, pstmtPie = null;
	   ResultSet rsOT = null, rsRep = null, rsPie = null;
       String sOrden="", sFEntrada="", sHEntrada="", sEmpleado="", sConductor="", sTelefono="",
       			sMatricula="", sMarca="", sModelo="", sRango="", sDepartamento="",
       			sKmEntrada="", sCodTaller="", sDescTaller="", sKmSalida="", sRepEfectuar="",
       			sNumFactura="",sFSalida="", sHSalida="", sImporte="", sGarantia="",sFGarantia="", sHGarantia="";
       String sCodigo="", sConcepto="", sOperario="", sTiempo="", sImpRep="";
       String sReferencia="", sCantidad="", sDenominacion="", sPrecio="", sImpPie="";
       double dNumero=0.0;
       String Vehiculo [];
	   Vehiculo = new String [3];
	   int cont=0;
	   boolean bVacio=false;  // Para sacar las filas en blanco en reparaciones y piezas


      try {
      	 HttpSession session = request.getSession(true);
      	 
     	/*Iker. idioma*/
			Locale idiomaLocal = (Locale)session.getAttribute("Local");
	
			ResourceBundle res =  (ResourceBundle)session.getAttribute("resTit");
			String idiomaSes = ((idiomaLocal.getLanguage()==null)?"es":idiomaLocal.getLanguage());	
			String campoTexto="C";
			String formatoFecha="dd-mm-yyyy";
			if(!idiomaSes.equals("es")){
				campoTexto="E";
				formatoFecha="yyyy-mm-dd";
				
			}
		 conn = miConex.getConnection();
     	 String persona = (String) session.getAttribute("persona");
     	 
      	 // Obtencion de parametros
         sOrden=request.getParameter("Codigo")==null?"":request.getParameter("Codigo");
         miLog.addTraza(persona, "Imp OT Servlet", "Orden: " + sOrden, m05bConstantes.LOG_NIVEL_BAJO);

		 //Datos Orden de Trabajo
		 if (!(sOrden.equals("")))  {
				 sSqlOrdenes=" select " + "to_char(" + m05bConstantes.COL_20_FENTRADA + ",'"+formatoFecha+"')" +
				 	 		", to_char(" + m05bConstantes.COL_20_FENTRADA + ",'hh24:mi')" +
				 	 		", " + m05bConstantes.COL_07_NOMBRE + 
				 	 		", " + m05bConstantes.COL_20_CONDUCTOR + 
				 	 		", " + m05bConstantes.COL_20_TELEF + 
				 	 		", " + m05bConstantes.COL_20_DESDPTO + 
				 	 		", " + m05bConstantes.COL_20_MATRICULA + 
				 	 		", " + m05bConstantes.COL_20_KM_ENTRADA + 
				 	 		", " + m05bConstantes.COL_20_CODTALLER + 
				 	 		", " + m05bConstantes.COL_20_KM_SALIDA + 
				 	 		", " + m05bConstantes.COL_20_DESCRIP + 
				 	 		", " + m05bConstantes.COL_20_FACTURA +
				 	 		", " + m05bConstantes.COL_20_GARANTIA + 
				 	 		", " + "to_char(" + m05bConstantes.COL_20_FSALIDA + ",'"+formatoFecha+"')" +
				 	 		", to_char(" + m05bConstantes.COL_20_FSALIDA + ",'hh24:mi')" +
				 	 		", " + "to_char(" + m05bConstantes.COL_20_GARANTIA + ",'"+formatoFecha+"')" +
				 	 		", to_char(" + m05bConstantes.COL_20_GARANTIA + ",'hh24:mi')" +
				 	 		", " + m05bConstantes.COL_20_IMPORTE + 
							" from " + m05bConstantes.TAB_EMPTALLER + ", " + m05bConstantes.TAB_ORDENESTRAB +
							" where " + m05bConstantes.COL_20_CODIGO + " = " + sOrden +
							" and " + m05bConstantes.COL_07_CODIGO + " = " + m05bConstantes.COL_20_PERSONA ;
				 	 miLog.addTraza(m05bConstantes.LOG_NO_USER , m05bConstantes.LOG_NO_SRC, "sSqlOrdenes: " + sSqlOrdenes, m05bConstantes.LOG_NIVEL_BAJO);
					 pstmtOT = conn.prepareStatement(sSqlOrdenes);
					 rsOT = pstmtOT.executeQuery();
		 } else {
		 	 	 bVacio=true;
		 }
		 
         //String foParam = request.getParameter(FO_REQUEST_PARAM);
     /*    String sFoFileDir = "/datos/m05b/tmp/";
         File foFileDir = new File(sFoFileDir);
         File tmpFoFile = File.createTempFile("m05b", "Fo", foFileDir);


         FileOutputStream tmpFoFileStream = new FileOutputStream(tmpFoFile);*/
         tmpFoFileStream=miInforme.fncAbrirFicheroTemporal();

         String sLinea;
         sLinea = "<?xml version=\"1.0\" encoding=\"windows-1252\"?>\n";
         tmpFoFileStream.write(sLinea.getBytes());
         
         sLinea = "<fo:root xmlns:fo=\"http://www.w3.org/1999/XSL/Format\">\n";
         tmpFoFileStream.write(sLinea.getBytes());
		 // LAYOUT DEL LISTADO 
	         sLinea = "<fo:layout-master-set>\n";
	         tmpFoFileStream.write(sLinea.getBytes());
		           sLinea = "	<fo:simple-page-master master-name=\"general\"  page-height=\"29.5cm\" page-width=\"21cm\" margin-top=\"1cm\" margin-bottom=\"0.5cm\" margin-left=\"2.5cm\" margin-right=\"2.5cm\">\n";
			       tmpFoFileStream.write(sLinea.getBytes());
			         sLinea = "		<fo:region-before extent=\"1cm\"/>\n";
			         tmpFoFileStream.write(sLinea.getBytes());
			         sLinea = "		<fo:region-body  margin-top=\"1cm\" margin-bottom=\"0.7cm\" />\n";
			         tmpFoFileStream.write(sLinea.getBytes());
			         sLinea = "		<fo:region-after  extent=\"1cm\"/>\n";
			         tmpFoFileStream.write(sLinea.getBytes());
			         sLinea = "		<fo:region-start extent=\"0cm\"/>\n";
			         tmpFoFileStream.write(sLinea.getBytes());
			         sLinea = "		<fo:region-end extent=\"0cm\"/>\n";
			         tmpFoFileStream.write(sLinea.getBytes());
			         
		            sLinea = "	</fo:simple-page-master>\n";
		          tmpFoFileStream.write(sLinea.getBytes());
		          
	         sLinea = "</fo:layout-master-set>\n";
	         tmpFoFileStream.write(sLinea.getBytes());
		 // PAGE-SEQUENCE DEL LISTADO 
	         sLinea = "<fo:page-sequence master-reference=\"general\">\n";
	         tmpFoFileStream.write(sLinea.getBytes());
	         
//REGION BEFORE
        	sLinea = "		<fo:static-content flow-name=\"xsl-region-before\" >\n";
        	tmpFoFileStream.write(sLinea.getBytes());
		           // --------------    CABECERA DEL LISTADO    --------------
                        //Cabecera 1
		            sLinea = "      <fo:block text-align=\"end\">\n";
		            tmpFoFileStream.write(sLinea.getBytes());
		            sLinea = "      </fo:block>\n";
		            tmpFoFileStream.write(sLinea.getBytes());
                    sLinea = "      <fo:block font-weight=\"bold\"  text-align=\"center\">\n "+res.getString("infOT.titulo")+" </fo:block>\n";
			        tmpFoFileStream.write(sLinea.getBytes());
        	sLinea = " 		</fo:static-content>\n"; 
        	tmpFoFileStream.write(sLinea.getBytes());
            //PIE DE PAGINA
		 miInforme.fncGenerarPiePagina(tmpFoFileStream, m05bConstantesInformes.DIR_VERTICAL,campoTexto,res.getString("pagina")); 
         miLog.addTraza(m05bConstantes.LOG_NO_USER, m05bConstantes.LOG_NO_SRC, "Antes body", m05bConstantes.LOG_NIVEL_BAJO);
		    
			//BODY
		         sLinea = "	<fo:flow flow-name=\"xsl-region-body\">\n";
		         tmpFoFileStream.write(sLinea.getBytes());

      	         // --------------    DETALLE DEL LISTADO    --------------
		   		 if ( (!(sOrden.equals(""))) && rsOT.next() ) {
		   		 	 
	       	    			sFEntrada= rsOT.getString(1)==null ? "":rsOT.getString(1);
	       	    			sHEntrada= rsOT.getString(2)==null ? "":rsOT.getString(2);
	       	    			sEmpleado = rsOT.getString(3)==null ? "":rsOT.getString(3);
	       	    			sConductor = rsOT.getString(4)==null ? "":rsOT.getString(4);
	       	    			sTelefono = rsOT.getString(5)==null ? "":rsOT.getString(5);
                            sDepartamento = rsOT.getString(6)==null ? "":rsOT.getString(6);
	       	    			sMatricula = rsOT.getString(7)==null ? "":rsOT.getString(7);
	       	    			//sKmEntrada = rsOT.getString(8)==null ? "":rsOT.getString(8);
		   		    	    String dNumeroS="";
							dNumeroS= (rsOT.getString(8)==null)?"0":rsOT.getString(8);
		   		    	    sKmEntrada = miComun.formatearDblMiles(new Double(dNumeroS).doubleValue());
		   		    	    sKmEntrada = sKmEntrada.equals("0") ? "":sKmEntrada;
		   		    	    sKmEntrada = sKmEntrada.replaceAll(",",".");  
	       	    			sCodTaller = rsOT.getString(9)==null ? "":rsOT.getString(9);
	       	    			//sKmSalida = rsOT.getString(10)==null ? "":rsOT.getString(10);
	       	    			dNumeroS= (rsOT.getString(10)==null)?"0":rsOT.getString(10);
		   		    	    sKmSalida = miComun.formatearDblMiles(new Double(dNumeroS).doubleValue());
		   		    	    miLog.addTraza(persona, "Imp OT Servlet", "sKmSalida: " + sKmSalida, m05bConstantes.LOG_NIVEL_BAJO);
		   		    	    sKmSalida = sKmSalida.equals("0") ? "":sKmSalida;
		   		    	    sKmSalida = sKmSalida.replaceAll(",",".");  
							   
							sRepEfectuar = rsOT.getString(11)==null ? "":rsOT.getString(11);
							sNumFactura = rsOT.getString(12)==null ? "":rsOT.getString(12);
							sGarantia = rsOT.getString(13)==null ? "":rsOT.getString(13);
							sFSalida= rsOT.getString(14)==null ? "":rsOT.getString(14);
	       	    			sHSalida= rsOT.getString(15)==null ? "":rsOT.getString(15);
	       	    			sFGarantia= rsOT.getString(16)==null ? "":rsOT.getString(16);
	       	    			sHGarantia= rsOT.getString(17)==null ? "":rsOT.getString(17);
	       	    			sImporte= rsOT.getString(18)==null ? "":rsOT.getString(18);
	       	    		    dNumero= rsOT.getDouble(18);
	       	    		    sImporte = miComun.formatearDblMilesDec(dNumero);
	       	    		    sImporte = sImporte.equals("0,00") ? "":sImporte;
	       	    			// Datos del vehiculo
						    Vehiculo= miDescrip.getPropVehiculo(sMatricula);
						    sMarca=Vehiculo[2];
						    sModelo=Vehiculo[0];
						    sRango=Vehiculo[5];
							sDescTaller = miDescrip.getDetalle(m05bConstantes.TAB_TALLER, m05bConstantes.COL_30_CODIGO, 
										m05bConstantes.COL_30_DESCRIP, sCodTaller);
 	     		 }
         // Datos OT
         		sLinea= "        <fo:table space-after=\"8pt\">\n";
            	tmpFoFileStream.write(sLinea.getBytes());
           		sLinea = "	    <fo:table-column column-width=\"162mm\"/>\n";
            	tmpFoFileStream.write(sLinea.getBytes());
		         sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			     tmpFoFileStream.write(sLinea.getBytes());
			     sLinea = "	    <fo:table-row >\n";
			     tmpFoFileStream.write(sLinea.getBytes());
                 sLinea = "	    <fo:table-cell  border-width=\"1pt\"  border-style=\"solid\" >\n";
				 tmpFoFileStream.write(sLinea.getBytes());
				 sLinea = "      <fo:block text-align=\"right\" padding-left=\"0.5mm\">\n ";
				 tmpFoFileStream.write(sLinea.getBytes());
			     
			    // Linea 1
		           		sLinea= "        <fo:table space-after=\"8pt\" space-before=\"8pt\">\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"140mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
				            	//  Etiqueta Nº Orden
				            	   sLinea = "	    <fo:table-cell border-width=\"0\" padding-top=\"0.2mm\" padding-right=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block font-weight=\"bold\" line-height=\"15pt\"  text-align=\"right\" >\n  "+res.getString("infOT.col1")+"   </fo:block>";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
				            	//  Nº orden
				            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\"  border-style=\"solid\" padding-top=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block text-align=\"right\">\n<![CDATA["+sOrden+"]]></fo:block>\n";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			 	        sLinea = "	    </fo:table-body>\n";
			            tmpFoFileStream.write(sLinea.getBytes());
			           sLinea= "       </fo:table>\n";
					   tmpFoFileStream.write(sLinea.getBytes());

			    // Linea 2 Fecha Entrada / Abierta por
		           		sLinea= "        <fo:table space-after=\"8pt\">\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"80mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		               		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
	   		                    sLinea = "	    <fo:table-row >\n";
				            	tmpFoFileStream.write(sLinea.getBytes());
				            	  // Etiqueta Entrada 
				            	  sLinea = "	    <fo:table-cell border-width=\"0\">\n";
				            	  tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block font-weight=\"bold\" line-height=\"15pt\"  text-align=\"left\" padding-top=\"0.2mm\">\n"+res.getString("infOT.col2")+"  </fo:block>";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	  sLinea = "	    </fo:table-cell>\n";
				            	  tmpFoFileStream.write(sLinea.getBytes());
				            	  // F. Entrada
				            	  sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\">\n";
				            	  tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block text-align=\"right\" padding-top=\"0.2mm\">\n <![CDATA["+ sFEntrada +"]]></fo:block>\n";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	  sLinea = "	    </fo:table-cell>\n";
				            	  tmpFoFileStream.write(sLinea.getBytes());
				            	//  H. Entrada
				            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block text-align=\"right\">\n<![CDATA["+ sHEntrada +"]]></fo:block>\n";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
	    	            		  // Etiqueta Abierta
	                    		   sLinea = "	    <fo:table-cell   border-width=\"0\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
				      			      sLinea = "      <fo:block font-weight=\"bold\" text-align=\"center\" padding-top=\"0.2mm\">\n "+res.getString("infOT.col3")+"   </fo:block>\n";
				            	      tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
				            	  // Detalle Abierta
				            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\"  border-style=\"solid\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								      sLinea = "      <fo:block  text-align=\"left\" padding-top=\"0.2mm\">\n<![CDATA["+sEmpleado+"]]></fo:block>\n";
								      tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
			                    sLinea = "	    </fo:table-row >\n";
				            	tmpFoFileStream.write(sLinea.getBytes());
			 	        sLinea = "	    </fo:table-body>\n";
			            tmpFoFileStream.write(sLinea.getBytes());
			           sLinea= "       </fo:table>\n";
					   tmpFoFileStream.write(sLinea.getBytes());
			    // Linea 3
		           		sLinea= "        <fo:table space-after=\"8pt\">\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"30mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"15mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"15mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"60mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
   		                    sLinea = "	    <fo:table-row >\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            	  // Etiqueta Conductor 
			            	  sLinea = "	    <fo:table-cell border-width=\"0\">\n";
			            	  tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block font-weight=\"bold\" line-height=\"15pt\"  text-align=\"left\" padding-top=\"0.2mm\">\n "+res.getString("infOT.col4")+"   </fo:block>";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	  sLinea = "	    </fo:table-cell>\n";
			            	  tmpFoFileStream.write(sLinea.getBytes());
			            	  // Conductor
			            	  sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\">\n";
			            	  tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block  text-align=\"left\" padding-top=\"0.2mm\">\n <![CDATA["+ sConductor +"]]></fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	  sLinea = "	    </fo:table-cell>\n";
			            	  tmpFoFileStream.write(sLinea.getBytes());
			            	//  Etiqueta Telefono
			            	   sLinea = "	    <fo:table-cell border-width=\"0\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block font-weight=\"bold\" text-align=\"center\">\n "+res.getString("infOT.col5")+"   </fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	//  Telefono
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block  text-align=\"center\">\n<![CDATA["+ sTelefono + "]]></fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
    	            		   // Etiqueta Departamento
                    		   sLinea = "	    <fo:table-cell  >\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			      			      sLinea = "      <fo:block font-weight=\"bold\" text-align=\"center\" padding-top=\"0.2mm\">\n"+res.getString("infOT.col6")+"   </fo:block>\n";
			            	      tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	   // Detalle Departamento
			            	   sLinea = "	    <fo:table-cell  border-width=\"0.1pt\" border-style=\"solid\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							      sLinea = "      <fo:block  text-align=\"left\" padding-top=\"0.2mm\">\n<![CDATA["+sDepartamento+"]]></fo:block>\n";
							      tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
  			                sLinea = "	    </fo:table-row>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			 	        sLinea = "	    </fo:table-body>\n";
			            tmpFoFileStream.write(sLinea.getBytes());
			           sLinea= "       </fo:table>\n";
					   tmpFoFileStream.write(sLinea.getBytes());
			    // Linea 4
		           		sLinea= "        <fo:table space-after=\"8pt\">\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"30mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"30mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"10mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"5mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"25mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
   		                    sLinea = "	    <fo:table-row >\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            	  // Etiqueta Matricula 
			            	  sLinea = "	    <fo:table-cell border-width=\"0\">\n";
			            	  tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block font-weight=\"bold\" text-align=\"left\" padding-top=\"0.2mm\">\n "+res.getString("infOT.col7")+" </fo:block>";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	  sLinea = "	    </fo:table-cell>\n";
			            	  tmpFoFileStream.write(sLinea.getBytes());
			            	  // Matricula
			            	  sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\">\n";
			            	  tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block  text-align=\"left\" padding-top=\"0.2mm\">\n<![CDATA[ "+ sMatricula +"]]></fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	  sLinea = "	    </fo:table-cell>\n";
			            	  tmpFoFileStream.write(sLinea.getBytes());
			            	//  Marca
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block text-align=\"left\">\n<![CDATA["+ sMarca +"]]></fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	//  Modelo
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block text-align=\"left\">\n"+ sModelo +" </fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
    	            		   // Rango
                    		   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			      			      sLinea = "      <fo:block  text-align=\"left\" padding-top=\"0.2mm\">\n<![CDATA["+ sRango + "]]></fo:block>\n";
			            	      tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
    	            		  // Vacio
			            	   sLinea = "	    <fo:table-cell border-width=\"0\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							      sLinea = "      <fo:block font-weight=\"bold\" text-align=\"center\" padding-top=\"0.2mm\">\n</fo:block>\n";
							      tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	   
			            	   // Etiqueta Km. Entrada
			            	   sLinea = "	    <fo:table-cell border-width=\"0\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							      sLinea = "      <fo:block font-weight=\"bold\" line-height=\"15pt\"  text-align=\"left\" padding-top=\"0.2mm\">\n"+res.getString("infOT.col8")+" </fo:block>\n";
							      tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	//  Km. Entrada
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block  text-align=\"right\">\n <![CDATA[" + sKmEntrada + "]]></fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
  			                sLinea = "	    </fo:table-row>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			 	        sLinea = "	    </fo:table-body>\n";
			            tmpFoFileStream.write(sLinea.getBytes());
			           sLinea= "       </fo:table>\n";
					   tmpFoFileStream.write(sLinea.getBytes());
			    // Linea 5
		           		sLinea= "        <fo:table space-after=\"8pt\">\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"70mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"5mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"25mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
   		                    sLinea = "	    <fo:table-row >\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            	  // Etiqueta Taller 
			            	  sLinea = "	    <fo:table-cell border-width=\"0\">\n";
			            	  tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block font-weight=\"bold\" text-align=\"left\" padding-top=\"0.2mm\">\n "+res.getString("infOT.col9")+" </fo:block>";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	  sLinea = "	    </fo:table-cell>\n";
			            	  tmpFoFileStream.write(sLinea.getBytes());
			            	  // Codigo de Taller
			            	  sLinea = "	    <fo:table-cell  border-width=\"0.1pt\" border-style=\"solid\">\n";
			            	  tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block  text-align=\"center\" padding-top=\"0.2mm\">\n <![CDATA["+ sCodTaller +"]]></fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	  sLinea = "	    </fo:table-cell>\n";
			            	  tmpFoFileStream.write(sLinea.getBytes());
			            	//  Descripcion de Taller
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block text-align=\"left\"  >\n<![CDATA[ "+ sDescTaller +"]]></fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	//  Blanco
			            	   sLinea = "	    <fo:table-cell border-width=\"0\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block font-weight=\"bold\" text-align=\"center\">\n </fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	   // Detalle Km.Salida
			            	   sLinea = "	    <fo:table-cell border-width=\"0\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							      sLinea = "      <fo:block font-weight=\"bold\" line-height=\"15pt\" text-align=\"left\" padding-top=\"0.2mm\">\n"+res.getString("infOT.col10")+" </fo:block>\n";
							      tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	//  Km. Salida
			            	   sLinea = "	    <fo:table-cell  border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block   text-align=\"right\"  >\n<![CDATA["+sKmSalida+"]]></fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
  			                sLinea = "	    </fo:table-row>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			 	        sLinea = "	    </fo:table-body>\n";
			            tmpFoFileStream.write(sLinea.getBytes());
			           sLinea= "       </fo:table>\n";
					   tmpFoFileStream.write(sLinea.getBytes());
					   
					   
			           sLinea= "       </fo:block>\n";
					   tmpFoFileStream.write(sLinea.getBytes());
				     sLinea = "	    </fo:table-cell>\n";
				     tmpFoFileStream.write(sLinea.getBytes());
			         sLinea = "	    </fo:table-row >\n";
			         tmpFoFileStream.write(sLinea.getBytes());
			 	    sLinea = "	    </fo:table-body>\n";
			        tmpFoFileStream.write(sLinea.getBytes());
			       sLinea= "       </fo:table>\n";
				tmpFoFileStream.write(sLinea.getBytes());
         miLog.addTraza(m05bConstantes.LOG_NO_USER, m05bConstantes.LOG_NO_SRC, "Antes reparaciones a efectuar", m05bConstantes.LOG_NIVEL_BAJO);
					   
         // Reparaciones a Efectuar
         	// Rep. a Efectuar     Titulo
		           		sLinea= "        <fo:table space-before=\"8pt\">\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"54mm\"/>\n";
    		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"54mm\"/>\n";
		            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"54mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
				            	// 
				            	   sLinea = "	    <fo:table-cell border-width=\"0\" padding-top=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block text-align=\"right\">\n  </fo:block>\n";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block font-weight=\"bold\" line-height=\"15pt\"  text-align=\"center\">\n "+res.getString("infOT.titulo2")+"  </fo:block>\n";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    <fo:table-cell border-width=\"0\" padding-top=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block text-align=\"right\">\n </fo:block>\n";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
				            	   
			            		sLinea = "	    </fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			 	        sLinea = "	    </fo:table-body>\n";
			            tmpFoFileStream.write(sLinea.getBytes());
			           sLinea= "       </fo:table>\n";
					   tmpFoFileStream.write(sLinea.getBytes());
		           		sLinea= "        <fo:table space-after=\"8pt\">\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"162mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
        		            sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
				            	//  Campo Reparacionees a efectuar
				            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\" padding-bottom=\"12mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block text-align=\"left\">\n<![CDATA["+ sRepEfectuar.toUpperCase()+"]]></fo:block>\n";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
				                sLinea = "	    </fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			 	        sLinea = "	    </fo:table-body>\n";
			            tmpFoFileStream.write(sLinea.getBytes());
			           sLinea= "       </fo:table>\n";
					   tmpFoFileStream.write(sLinea.getBytes());

         miLog.addTraza(m05bConstantes.LOG_NO_USER, m05bConstantes.LOG_NO_SRC, "Antes reparaciones efectuadas", m05bConstantes.LOG_NIVEL_BAJO);
					   
         // Reparaciones Efectuadas
		 if (!(sOrden.equals("")))  {
				 sSqlReparaciones =" select " + m05bConstantes.COL_19_CODIGO + 
				 	 		", " + m05bConstantes.COL_19_CONCEPTO + 
				 	 		", " + m05bConstantes.COL_07_NOMBRE + 
				 	 		", " + m05bConstantes.COL_19_TIEMPO + 
				 	 		", " + m05bConstantes.COL_19_IMPORTE + 
							" from " + m05bConstantes.TAB_EMPTALLER + ", " + m05bConstantes.TAB_ORDEREPAR +
							" where " + m05bConstantes.COL_19_COD_ORD + " = " + sOrden +
							" and " + m05bConstantes.COL_07_CODIGO + " = " + m05bConstantes.COL_19_EMPLEADO ;
				 
				 
				 miLog.addTraza(persona, "m05b - ImpOT:  ", "sSqlReparaciones: " + sSqlReparaciones, m05bConstantes.LOG_NIVEL_BAJO);

				 pstmtRep = conn.prepareStatement(sSqlReparaciones);
				 rsRep = pstmtRep.executeQuery();
         }	 
         	// Rep. Efectuadas Titulo
		           		sLinea= "        <fo:table space-before=\"8pt\">\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"54mm\"/>\n";
    		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"54mm\"/>\n";
		            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"54mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
				            	//  Etiqueta Reparaciones Efectuadas
				            	   sLinea = "	    <fo:table-cell border-width=\"0\" padding-top=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block text-align=\"right\">\n  </fo:block>\n";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block font-weight=\"bold\" line-height=\"15pt\"  text-align=\"center\">\n "+res.getString("infOT.titulo3")+"  </fo:block>\n";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    <fo:table-cell border-width=\"0\" padding-top=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block text-align=\"right\">\n </fo:block>\n";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
				            	   
			            		sLinea = "	    </fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			 	        sLinea = "	    </fo:table-body>\n";
			            tmpFoFileStream.write(sLinea.getBytes());
			           sLinea= "       </fo:table>\n";
					   tmpFoFileStream.write(sLinea.getBytes());
         
		           		sLinea= "        <fo:table space-after=\"8pt\">\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"10mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
 		                    sLinea = "	    <fo:table-column column-width=\"86mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            	sLinea = "	    <fo:table-column column-width=\"37mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
 		                    sLinea = "	    <fo:table-column column-width=\"11mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            	sLinea = "	    <fo:table-column column-width=\"18mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		                    sLinea = "	    <fo:table-header font-family=\"Helvetica\" font-size=\"8pt\" >\n";
			                tmpFoFileStream.write(sLinea.getBytes());
			                // Cabecera Tabla
		            		sLinea = "	    <fo:table-row >\n";
		            		tmpFoFileStream.write(sLinea.getBytes());
			  		        //  Etiqueta Cod.
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block font-weight=\"bold\" line-height=\"15pt\"  text-align=\"center\"  >\n " + res.getString("infOT.col11")  + "</fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
		            	    //  Etiqueta Concepto
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block font-weight=\"bold\" line-height=\"15pt\"  text-align=\"center\"  >\n " + res.getString("infOT.col12") + "</fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	//  Etiqueta Operario
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block font-weight=\"bold\" line-height=\"15pt\"  text-align=\"center\"  >\n " + res.getString("infOT.col13") + "</fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	//  Etiqueta Tiempo
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block font-weight=\"bold\" line-height=\"15pt\"  text-align=\"center\"  >\n " + res.getString("infOT.col14")+ "</fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	//  Etiqueta Importe
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block font-weight=\"bold\" line-height=\"15pt\"  text-align=\"center\"  >\n " + res.getString("infOT.col15") + "</fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	sLinea = "	    </fo:table-row >\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            	sLinea = "	    </fo:table-header>\n";
		            	   tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            	
         miLog.addTraza(m05bConstantes.LOG_NO_USER, m05bConstantes.LOG_NO_SRC, "Antes while reparaciones", m05bConstantes.LOG_NIVEL_BAJO);
			            	
		   		 while (cont<9)  {
		   		 	 
		   		 	if ((bVacio==false) && rsRep.next())  {
	       	    			sCodigo = rsRep.getString(1)==null ? "":rsRep.getString(1);
	       	    			sConcepto = rsRep.getString(2)==null ? "":rsRep.getString(2);
	       	    			sOperario = rsRep.getString(3)==null ? "":rsRep.getString(3);
	       	    			sTiempo = rsRep.getString(4)==null ? "":rsRep.getString(4);
		   		    	    dNumero= rsRep.getDouble(5);
		   		    	    sImpRep = miComun.formatearDblMilesDec(dNumero);
		   		    	    sImpRep = sImpRep.equals("0,00") ? "":sImpRep;
							//sImpRep = miComun.formatearDblMilesDec(rsRep.getDouble(5));
					
		            		sLinea = "	    <fo:table-row>\n";
			        } else {
							bVacio= true;
	       	    			sCodigo = "Libre"; sConcepto = ""; sOperario = ""; sTiempo = ""; sImpRep = "";
		            		sLinea = "	    <fo:table-row color=\"white\" >\n";
			        }
		            		tmpFoFileStream.write(sLinea.getBytes());
			  		        //  Detalle Cod.
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block text-align=\"center\" line-height=\"15pt\" >\n <![CDATA[" + sCodigo + "]]></fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
		            	    //  Detalle Concepto
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block   text-align=\"center\" line-height=\"15pt\" >\n<![CDATA[" + sConcepto + "]]></fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	//  Detalle Operario
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block   text-align=\"center\" line-height=\"15pt\">\n <![CDATA[" + sOperario + "]]></fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	//  Detalle Tiempo
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block   text-align=\"center\" line-height=\"15pt\" >\n <![CDATA[" + sTiempo + "]]></fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	//  Detalle Importe
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block   text-align=\"center\" line-height=\"15pt\" >\n <![CDATA[" + sImpRep + "]]></fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	sLinea = "	    </fo:table-row >\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            	++cont;
			     } // Fin detalle reparaciones
			 	        sLinea = "	    </fo:table-body>\n";
			            tmpFoFileStream.write(sLinea.getBytes());			            								            		
			           sLinea= "       </fo:table>\n";
					   tmpFoFileStream.write(sLinea.getBytes());
			// Cerrar sql
				if (rsRep != null)
					rsRep.close();
				if (pstmtRep != null)
					pstmtRep.close();
				
         miLog.addTraza(m05bConstantes.LOG_NO_USER, m05bConstantes.LOG_NO_SRC, "Antes piezas", m05bConstantes.LOG_NIVEL_BAJO);
				
         // Materiales empleados
         cont=0;
		 if (!(sOrden.equals("")))  {
				 sSqlPiezas =" select " + m05bConstantes.COL_23_PIE + 
				 	 		", " + m05bConstantes.COL_23_CANTIDAD + 
				 	 		", NVL(" + (campoTexto=="C"?"":campoTexto)+m05bConstantes.COL_22_DESCRIPCION +
				 	 		","+m05bConstantes.COL_22_DESCRIPCION +")"+
				 	 		", " + m05bConstantes.COL_23_PRECIO + 
				 	 		", " + m05bConstantes.COL_23_TOTAL + 
							" from " +m05bConstantes.TAB_PIEZAS+","+ m05bConstantes.TAB_PIEZAREP +
							" where " + m05bConstantes.COL_23_ORDEN + " = " + sOrden
							+" AND "+m05bConstantes.COL_22_CODIGO+" ="+m05bConstantes.COL_23_PIE;
				 
				 
//					sql.append("SELECT ").append(campoTexto+m05bConstantes.COL_22_DESCRIPCION).append(",");
//					sql.append(m05bConstantes.COL_23_PIE).append(",");
//					sql.append(m05bConstantes.COL_23_DESCRIP).append(",").append(m05bConstantes.COL_23_CANTIDAD);
//					sql.append(",").append(m05bConstantes.COL_23_PRECIO).append(",").append(m05bConstantes.COL_23_TOTAL);
//					sql.append(" FROM ").append(m05bConstantes.TAB_PIEZAS).append(", ").append(m05bConstantes.TAB_PIEZAREP);
//					sql.append(" WHERE ").append(m05bConstantes.COL_23_ORDEN);
//					sql.append("='").append(nOrden).append("' AND ").append(m05bConstantes.COL_23_CODIGO);
//					sql.append("='").append(codigo).append("'");
//					sql.append(" AND ").append(m05bConstantes.COL_22_CODIGO).append(" = ").append(m05bConstantes.COL_23_PIE);
//				 
				 
				 
				 
				 miLog.addTraza(m05bConstantes.LOG_NO_USER, m05bConstantes.LOG_NO_SRC, "sSqlPiezas: " + sSqlPiezas, m05bConstantes.LOG_NIVEL_BAJO);

				 pstmtPie = conn.prepareStatement(sSqlPiezas);
				 rsPie = pstmtPie.executeQuery();
         }
         // Materiales Empleados Titulo
		           		sLinea= "        <fo:table space-before=\"8pt\">\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"54mm\"/>\n";
    		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"54mm\"/>\n";
		            		tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"54mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
				            	//  Cabecera de Tabla
				            	   sLinea = "	    <fo:table-cell border-width=\"0\" padding-top=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block text-align=\"right\">\n  </fo:block>\n";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block font-weight=\"bold\" line-height=\"15pt\"  text-align=\"center\">\n "+res.getString("infOT.titulo3")+"  </fo:block>\n";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    <fo:table-cell border-width=\"0\" padding-top=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block text-align=\"right\">\n </fo:block>\n";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
				            	   
			            		sLinea = "	    </fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			 	        sLinea = "	    </fo:table-body>\n";
			            tmpFoFileStream.write(sLinea.getBytes());
			           sLinea= "       </fo:table>\n";
					   tmpFoFileStream.write(sLinea.getBytes());
         
		           		sLinea= "        <fo:table space-after=\"8pt\">\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
 		                    sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            	sLinea = "	    <fo:table-column column-width=\"82mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
 		                    sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            	sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		                    sLinea = "	    <fo:table-header font-family=\"Helvetica\" font-size=\"8pt\" >\n";
			                tmpFoFileStream.write(sLinea.getBytes());
			                // Primera Linea
		            		sLinea = "	    <fo:table-row >\n";
		            		tmpFoFileStream.write(sLinea.getBytes());
			  		        //  Referencia.
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block font-weight=\"bold\" line-height=\"15pt\"  text-align=\"center\"  >\n " + res.getString("infOT.col16")+ "</fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
		            	    //  Cant.
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block font-weight=\"bold\" line-height=\"15pt\"  text-align=\"center\"  >\n " + res.getString("infOT.col17") + "</fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	//  Denominación
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block font-weight=\"bold\" line-height=\"15pt\"  text-align=\"center\"  >\n " + res.getString("infOT.col18") + "</fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	//  Precio/u
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block font-weight=\"bold\" line-height=\"15pt\"  text-align=\"center\"  >\n " + res.getString("infOT.col19") + "</fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	//  Importe
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block font-weight=\"bold\" line-height=\"15pt\"  text-align=\"center\"  >\n " + res.getString("infOT.col20")+ "</fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	sLinea = "	    </fo:table-row >\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            	sLinea = "	    </fo:table-header>\n";
		            	   tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            	
         miLog.addTraza(m05bConstantes.LOG_NO_USER, m05bConstantes.LOG_NO_SRC, "Antes while piezas", m05bConstantes.LOG_NIVEL_BAJO);
		 if (!(sOrden.equals("")))  {			 	
			     bVacio = false;
	     } else {	    	 	
			     bVacio = true;
	     }
		   		 while (cont<9)  {
		   			miLog.addTraza(m05bConstantes.LOG_NO_USER, m05bConstantes.LOG_NO_SRC, "***cont***: " + cont, m05bConstantes.LOG_NIVEL_BAJO);
		   		 	if ((bVacio==false) && rsPie.next())  {		   		 
	       	    			sReferencia = rsPie.getString(1)==null ? "":rsPie.getString(1);
	       	    			sCantidad = rsPie.getString(2)==null ? "":rsPie.getString(2);
	       	    			sDenominacion = rsPie.getString(3)==null ? "":rsPie.getString(3);
							sPrecio = miComun.formatearDblMilesDec(rsPie.getDouble(4));													
							//sImpPie = miComun.formatearDblMilesDec(rsPie.getDouble(5));
							//Agurtzane Feb12: error listado materiales
		   		    	    //dNumero= rsRep.getDouble(5);
							dNumero= rsPie.getDouble(5);
		   		    	    //Fin Agurtzane Feb12: error listado materiales
		   		    	    sImpPie = miComun.formatearDblMilesDec(dNumero);
		   		    	    sImpPie = sImpPie.equals("0,00") ? "":sImpPie;
			           		sLinea = "	    <fo:table-row >\n";
			        }  else {
			        	    bVacio=true;
	       	    			sReferencia = "Libre"; sCantidad = " "; sDenominacion = " "; sPrecio = " "; sImpPie = " ";
		            		sLinea = "	    <fo:table-row color=\"white\" >\n";
			        }
		            		tmpFoFileStream.write(sLinea.getBytes());
			  		        //  Detalle Referencia
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block   text-align=\"center\"  line-height=\"15pt\">\n " + sReferencia + "</fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
		            	    //  Detalle Cant.
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block   text-align=\"center\"  line-height=\"15pt\">\n " + sCantidad + "</fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	// Detalle Denominacion
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block  text-align=\"center\" line-height=\"15pt\" >\n " + sDenominacion + "</fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	// Detalle Precio/u.
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block   text-align=\"center\" line-height=\"15pt\" >\n " + sPrecio + "</fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	// Detalle Importe
			            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\" border-style=\"solid\" padding-top=\"0.2mm\">\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
							     sLinea = "      <fo:block  text-align=\"center\"  line-height=\"15pt\">\n " + sImpPie + "</fo:block>\n";
							     tmpFoFileStream.write(sLinea.getBytes());
			            	   sLinea = "	    </fo:table-cell>\n";
			            	   tmpFoFileStream.write(sLinea.getBytes());
			            	sLinea = "	    </fo:table-row >\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            	++cont;
			     }    // Fin detalle Piezas
			 	        sLinea = "	    </fo:table-body>\n";
			            tmpFoFileStream.write(sLinea.getBytes());			            								            		
			           sLinea= "       </fo:table>\n";
					   tmpFoFileStream.write(sLinea.getBytes());
			// Cerrar sql
				if (rsPie != null)
					rsPie.close();
				if (pstmtPie != null)
					pstmtPie.close();
					   
         miLog.addTraza(m05bConstantes.LOG_NO_USER, m05bConstantes.LOG_NO_SRC, "Antes datos factura", m05bConstantes.LOG_NIVEL_BAJO);
					   
               // Datos Factura
			    // Linea 1 Nº Factura
		           		sLinea= "        <fo:table space-after=\"8pt\">\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"122mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
				            	//  Etiqueta Nº Factura
				            	   sLinea = "	    <fo:table-cell border-width=\"0\" padding-top=\"0.2mm\" padding-right=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block font-weight=\"bold\" line-height=\"15pt\"  text-align=\"left\" >\n "+res.getString("infOT.col21")+"  </fo:block>";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
				            	//  Factura
				            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\"  border-style=\"solid\" padding-top=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block text-align=\"right\" line-height=\"15pt\">\n"+sNumFactura+"</fo:block>\n";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
		            	       //  Etiqueta Fecha y firma del empleado
				            	   sLinea = "	    <fo:table-cell border-width=\"0\" padding-top=\"0.2mm\" padding-right=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block font-weight=\"bold\" text-align=\"right\" >\n"+res.getString("infOT.col22")+"  </fo:block>";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    </fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			 	        sLinea = "	    </fo:table-body>\n";
			            tmpFoFileStream.write(sLinea.getBytes());
			           sLinea= "       </fo:table>\n";
					   tmpFoFileStream.write(sLinea.getBytes());
			    // Linea 2 Garantía
		           		sLinea= "        <fo:table space-after=\"8pt\">\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		        		sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
	            		sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
	            		sLinea = "	    <fo:table-column column-width=\"10mm\"/>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
	            		sLinea = "	    <fo:table-column column-width=\"112mm\"/>\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
	            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
				            	//  Etiqueta Garantía
				            	   sLinea = "	    <fo:table-cell border-width=\"0\" padding-top=\"0.2mm\" padding-right=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block font-weight=\"bold\" line-height=\"15pt\"  text-align=\"left\" >\n "+res.getString("infOT.col23")+" </fo:block>";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
					            	//  Fecha
				            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\"  border-style=\"solid\" padding-top=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block text-align=\"right\" line-height=\"15pt\">\n"+sFGarantia+"</fo:block>\n";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
		            	       //  Hora
				            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\"  border-style=\"solid\" padding-top=\"0.2mm\" padding-right=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block text-align=\"right\" line-height=\"15pt\">\n"+sHGarantia+"</fo:block>\n";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
		            	       //  Blanco
				            	   sLinea = "	    <fo:table-cell border-width=\"0\" padding-top=\"0.2mm\" padding-right=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block font-weight=\"bold\" text-align=\"right\" >\n </fo:block>";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());				            	   
			            		sLinea = "	    </fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			 	        sLinea = "	    </fo:table-body>\n";
			            tmpFoFileStream.write(sLinea.getBytes());			            								            		
			           sLinea= "       </fo:table>\n";
					   tmpFoFileStream.write(sLinea.getBytes());
			    // Linea 3 Fecha Salida
		           		sLinea= "        <fo:table space-after=\"8pt\">\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"20mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"10mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"112mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
				            	//  Etiqueta Fecha Salida
				            	   sLinea = "	    <fo:table-cell border-width=\"0\" padding-top=\"0.2mm\" padding-right=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block font-weight=\"bold\" line-height=\"15pt\"  text-align=\"left\" >\n"+res.getString("infOT.col24")+"  </fo:block>";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
				            	//  Fecha
				            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\"  border-style=\"solid\" padding-top=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block text-align=\"right\" line-height=\"15pt\">\n"+sFSalida+"</fo:block>\n";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
		            	       //  Hora
				            	   sLinea = "	    <fo:table-cell border-width=\"0.1pt\"  border-style=\"solid\" padding-top=\"0.2mm\" padding-right=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block text-align=\"right\" line-height=\"15pt\">\n"+sHSalida+"</fo:block>\n";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
				            	//  Blanco
				            	   sLinea = "	    <fo:table-cell border-width=\"0\" padding-top=\"0.2mm\" padding-right=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block font-weight=\"bold\" text-align=\"right\" >\n </fo:block>";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			 	        sLinea = "	    </fo:table-body>\n";
			            tmpFoFileStream.write(sLinea.getBytes());
			           sLinea= "       </fo:table>\n";
					   tmpFoFileStream.write(sLinea.getBytes());

			    // Linea 4 Importe Iva
		           		sLinea= "        <fo:table space-after=\"8pt\">\n";
		            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"70mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"45mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-column column-width=\"45mm\"/>\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
		            		sLinea = "	    <fo:table-body font-family=\"Helvetica\" font-size=\"8pt\">\n";
			            	tmpFoFileStream.write(sLinea.getBytes());
			            		sLinea = "	    <fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
				            	//  Blanco
				            	   sLinea = "	    <fo:table-cell border-width=\"0\" padding-top=\"0.2mm\" padding-right=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block font-weight=\"bold\" text-align=\"right\" >\n </fo:block>";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());

				            	//  Etiqueta Importe (IVA incluido)
				            	   sLinea = "	    <fo:table-cell padding-top=\"0.7mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block font-weight=\"bold\"  line-height=\"15pt\" border-width=\"0\" text-align=\"right\">\n"+res.getString("infOT.col25")+"</fo:block>\n";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
		            	       //  Importe
				            	   sLinea = "	    <fo:table-cell  border-width=\"0.8pt\"  border-style=\"solid\"  padding-top=\"0.2mm\" padding-right=\"0.2mm\">\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
								     sLinea = "      <fo:block text-align=\"right\" line-height=\"15pt\">\n"+sImporte+"</fo:block>\n";
								     tmpFoFileStream.write(sLinea.getBytes());
				            	   sLinea = "	    </fo:table-cell>\n";
				            	   tmpFoFileStream.write(sLinea.getBytes());
			
			            		sLinea = "	    </fo:table-row >\n";
			            		tmpFoFileStream.write(sLinea.getBytes());
			 	        sLinea = "	    </fo:table-body>\n";
			            tmpFoFileStream.write(sLinea.getBytes());			            								            		
			           sLinea= "       </fo:table>\n";
					   tmpFoFileStream.write(sLinea.getBytes());

		         sLinea = "      </fo:flow>\n";
                 tmpFoFileStream.write(sLinea.getBytes());
                 
         	 sLinea = "   </fo:page-sequence>\n";
             tmpFoFileStream.write(sLinea.getBytes());
             
         sLinea = "</fo:root>\n";
         tmpFoFileStream.write(sLinea.getBytes());
         

         tmpFoFileStream.close();

         //generarPDFdesdeFO(sFoFileDir + tmpFoFile.getName(),sFoFileDir,response);
         miInforme.generarPDFdesdeFO(response);
         
         //FileInputStream file = new FileInputStream(sFoFileDir + tmpFoFile.getName());

         //renderFO(new InputSource(file), response);

         //tmpFoFile.delete();

         //response.flushBuffer();


      } catch (Exception ex) {
      		try {
				response.sendRedirect("m05bError.jsp");
			} catch (IOException e) {
				// TODO Auto-generated catch block
				miLog.addTraza(e);
			}
      } finally{
	   	    try {
				if (rsPie != null)
					rsPie.close();
				if (pstmtPie != null)
					pstmtPie.close();
				if (rsRep != null)
					rsRep.close();
				if (pstmtRep != null)
					pstmtRep.close();
				if (rsOT != null)
					rsOT.close();
				if (pstmtOT != null)
					pstmtOT.close();
				if (conn != null)
					conn.close();
			} catch (SQLException e2) {
				try {
					response.sendRedirect("m05bError.jsp");
				} catch (IOException e) {
					// TODO Auto-generated catch block
					miLog.addTraza(e);
				}
	  		}
	   }
    }  // Fin funcion performTask

    /**
     * rendersOT an FO inputsource into a PDF file which is rendered
     * directly to the response object's OutputStream
     */
    public void renderFO(InputSource foFile, HttpServletResponse response) throws ServletException
    {
        try
        {
            ByteArrayOutputStream out = new ByteArrayOutputStream();

	    	response.reset();
            OutputStream oOut=response.getOutputStream();
            BufferedOutputStream bOut=new BufferedOutputStream(oOut);
            Driver driver = new Driver(foFile, out);
            driver.setRenderer(Driver.RENDER_PDF);
            driver.run();

            response.setContentLength(out.size());
	    response.setContentType("application/pdf");


            bOut.write(out.toByteArray());
	    out.close();
	    bOut.flush();
            bOut.close();
//	    response.flushBuffer();
        }
        catch (Exception ex)
        {
            throw new ServletException(ex);
        }
    }
public void generarPDFdesdeFO(String ficheroFO, String rutaPDF, HttpServletResponse response) throws FOPException {
        try {

            Driver driver = new Driver();

            driver.setRenderer(Driver.RENDER_PDF);

            //Si no existe el directrio lo crea
            File f = new File(rutaPDF);

            if (!f.exists()) {

                f.mkdir();
            }
            //Cargar los datos del .FO
            FileInputStream file = new FileInputStream(ficheroFO);

            BufferedInputStream bfile=new BufferedInputStream(file);

            driver.setInputSource(new InputSource(bfile));


            //Crear un temporal que va a ser el .pdf
            String sPdfFileDir = rutaPDF;
            File   pdfFileDir = new File(sPdfFileDir);
            File   tmpPdfFile = File.createTempFile("m05b", ".pdf", pdfFileDir);


            FileOutputStream fileout = new FileOutputStream(tmpPdfFile);

            BufferedOutputStream bfileout=new BufferedOutputStream(fileout);

            driver.setOutputStream(bfileout);

            driver.run();


 

            bfile.close();

            bfileout.close();
            //Longitus del Fichero PDF.
            Long longitud = new Long(tmpPdfFile.length());
            String sLongitud=""+ longitud;
            int iLongitud=Integer.parseInt(sLongitud);

            response.setContentLength((int)iLongitud);
	        response.setContentType("application/pdf");
	        
            byte[] fileBytes = new byte[longitud.intValue()];
            FileInputStream fisficheroPdf = new FileInputStream(tmpPdfFile);
            fisficheroPdf.read(fileBytes);
            ServletOutputStream os = response.getOutputStream();
            ((OutputStream)os).write(fileBytes);
            ((OutputStream)os).flush();
            ((OutputStream)os).close();

            // BORRAR EL FICHERO FO

            File fichero = new File(ficheroFO);

            boolean borrado = fichero.delete();
            boolean borrado2 = tmpPdfFile.delete();

        } catch (Exception e) {

            //System.out.println("EXCEPCION !!! : Error pasando de FO a PDF: " + e);

        }

    }
}