<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="ISO-8859-1" indent="yes" omit-xml-declaration="yes" standalone="yes" media-type="text/html"/>
<xsl:decimal-format name="chile" decimal-separator="," grouping-separator="." NaN="" zero-digit="0"/>
<xsl:template match="/">
<html>
<head>
<title>Visualizador de Facturas Electronicas</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
<style>
    .tdTitulo{
        color:#000080;
        font-size:13pt;
        height:20px;
        width:30mm;
    }
    .tdTotal{
        color:#000080;
        font-size:15pt;
        height:20px;
        width:40mm;
        font-weight:bold;
    }
    .tdTotalValor{
        font-size:15pt;
        height:20px;
        width:70mm;
        font-weight:bold;
    }
    .tdValorDer{
        font-size:15pt;
        text-align:right;
        height:20px;
        width:30mm;
    }
    .tdValorIzq{
        font-size:15pt;
        text-align:left;
        height:20px;
        width:180mm;
    }
    .tdHeadTablaDetalle{
        color:#000080;
        font-size:13pt;
        height:20px;
        text-align:center;
        font-weight:bold;
    }
    .tdBodyTablaDetalle{
        font-size:14pt;
        height:20px;
        padding-right:1mm;
        padding-left:1mm;
    }
    .txtDer{text-align:right;}
    .txtIzq{text-align:left;}
    .txtCen{text-align:center;}
</style>
</head>
<body background='../imagenes/factura.jpg' style="font-family : Arial;background-repeat:no-repeat;align:center;width:215.9mm;height:279.4mm;position:absolute;border:1px solid ;top:0px;" >

<xsl:for-each select="DTE/Documento">

<div align="center" style="margin-top:0px:width:205mm;">

         
    <table>
        <tr>
            <td width="359"><img src="../imagenes/factura_los_olivos.png" alt="factura" width="359" style="height:35mm;"/></td>
        <td width="285" style="">
                <table>
                    <tr>
                        <td style="width:70mm;height:30mm;margin-right:10mm;border:1mm solid red; font-family:Arial;font-size:12pt;font-weight:bold;color:red;text-align:center;line-height:35mm;">
                            <p style="">
                        RUT.: <xsl:value-of select='concat(format-number(number(substring-before(Encabezado/Emisor/RUTEmisor,"-")),"##.###.###","chile"),"-",substring-after(Encabezado/Emisor/RUTEmisor,"-"))'/>
                        </p>
                        <br/>
                        <p>
                        <xsl:choose>
                  <xsl:when test="Encabezado/IdDoc/TipoDTE[. = 33]">FACTURA ELECTRÓNICA</xsl:when>
                 <xsl:when test="Encabezado/IdDoc/TipoDTE[. = 34]">FACTURA NO AFECTA O EXENTA ELECTRÓNICA</xsl:when>
                  <xsl:when test="Encabezado/IdDoc/TipoDTE[. = 43]">LIQUIDACION FACTURA ELECTRÓNICA</xsl:when>
                              <xsl:when test="Encabezado/IdDoc/TipoDTE[. = 46]">FACTURA DE COMPRA ELECTRÓNICA</xsl:when>
                              <xsl:when test="Encabezado/IdDoc/TipoDTE[. = 52]">GUIA DE DESPACHO ELECTRÓNICA</xsl:when>
                              <xsl:when test="Encabezado/IdDoc/TipoDTE[. = 61]">NOTA DE CREDITO ELECTRÓNICA</xsl:when>
                               <xsl:when test="Encabezado/IdDoc/TipoDTE[. = 56]">NOTA DE DEBITO ELECTRÓNICA</xsl:when>
                               <xsl:when test="Encabezado/IdDoc/TipoDTE[. = 39]">BOLETA ELECTRÓNICA</xsl:when>
                              <xsl:otherwise>OTRO DOCUMENTO</xsl:otherwise>
                        </xsl:choose>
                        </p>
                        
                        <br/>
                        Nº <xsl:value-of select="Encabezado/IdDoc/Folio"/>                        </td>
                    </tr>
                    <tr>
                        <td style="width:70mm;float:right;margin-right:10mm;margin-top:2mm;font-family:Arial;font-size:12pt;font-weight:bold;color:red;text-align:center;">
                            <div >
                                S.I.I. QUILLOTA                            </div>                        </td>
                    </tr>
                </table>            </td>
        </tr>
    </table>
         
<table width="1176" border="0" style="font-family:Arial;width:200mm;margin-right:5mm;">
  <tr>
    <td width="100%">
      <table border="0" width="100%" cellpadding="0" height="137" style="font-family:Arial;">
        <tr>
          <td style="color:#000080;font-size:11pt;height:20px;width:35mm;"></td>
          <td class="tdValorIzq"></td>
          <td style="color:#000080;font-size:13pt;height:20px;width:35mm;">Fecha Emisi&#243;n:</td>
          <td class="tdValorDer"><xsl:value-of select='concat(substring(Encabezado/IdDoc/FchEmis,9,2),"-",substring(Encabezado/IdDoc/FchEmis,6,2),"-",substring(Encabezado/IdDoc/FchEmis,1,4))'/></td>
        </tr>
        <tr>
          <td style="color:#000080;font-size:13pt;height:20px;width:35mm;">Se&#241;or(es):</td>
          <td class="tdValorIzq" ><xsl:value-of select="Encabezado/Receptor/RznSocRecep"/></td>
          <td style="color:#000080;font-size:13pt;height:20px;width:35mm;">RUT.:</td>
          <td class="tdValorDer"><xsl:value-of select='concat(format-number(number(substring-before(Encabezado/Receptor/RUTRecep,"-")),"##.###.###","chile"),"-",substring-after(Encabezado/Receptor/RUTRecep,"-"))'/></td>
        </tr>
        <tr>
          <td style="color:#000080;font-size:13pt;height:20px;width:35mm;">Direcci&#243;n:</td>
          <td class="tdValorIzq" colspan="3"><xsl:value-of select="Encabezado/Receptor/DirRecep"/></td>
        </tr>
        <tr>
          <td style="color:#000080;font-size:13pt;height:20px;width:35mm;">Giro:</td>
          <td class="tdValorIzq"><xsl:value-of select="Encabezado/Receptor/GiroRecep"/></td>
           <td style="color:#000080;font-size:13pt;height:20px;width:25mm;">Vendedor</td>
           <td class="tdValorDer"><xsl:value-of select="Encabezado/Emisor/CdgVendedor"/></td>
        </tr>
        <tr>
          <td style="color:#000080;font-size:13pt;height:20px;width:35mm;">Comuna:</td>
          <td class="tdValorIzq"><xsl:value-of select="Encabezado/Receptor/CmnaRecep"/></td>
          <td style="color:#000080;font-size:13pt;height:20px;width:35mm;">Fecha Venc:</td>
          <td class="tdValorDer"><xsl:value-of select='concat(substring(Encabezado/IdDoc/FchVenc,9,2),"-",substring(Encabezado/IdDoc/FchVenc,6,2),"-",substring(Encabezado/IdDoc/FchVenc,1,4))'/></td>
        </tr>
        
        <tr>
          <td class="tdTitulo">Ciudad:</td>
          <td class="tdValorIzq"><xsl:value-of select="Encabezado/Receptor/CiudadRecep"/></td>
          <td class="tdTitulo">Forma Pago:</td>
          <td class="tdValorDer">
		<xsl:choose>
		      <xsl:when test="Encabezado/IdDoc/FmaPago[. = 1]">Efectivo</xsl:when>
		      <xsl:when test="Encabezado/IdDoc/FmaPago[. = 2]">Crédito</xsl:when>
  		</xsl:choose>          
          </td>
        </tr>
          <xsl:for-each select="Encabezado/Transporte">
         <tr>
          <td class="tdTitulo">Patente:</td>
          <td class="tdValorIzq"> <xsl:value-of select="Patente"/>  Rut: <xsl:value-of select="RUTTrans"/></td>
          <td> </td>
		 </tr>
        </xsl:for-each>
      </table>
    </td>
  </tr>
    <tr>
   <td>
    <hr/>
   </td>
  </tr>
  <tr>
    <td width="100%">

<!--selecciona el tipo de detalle a mostrar con/sin descuentos -->
    
<xsl:choose>        
   <xsl:when test="Detalle/DescuentoMonto">
      <table border="0" width="100%" cellpadding="0" cellspacing="0" style="padding-left:1mm;padding-right:1mm;">
        <tr>
          <td width="128" class="tdHeadTablaDetalle" style="width:10mm;">Item</td>
          <td width="124" class="tdHeadTablaDetalle" style="width:10mm;">Codigo</td>
          <td width="383" class="tdHeadTablaDetalle txtIzq" style="width:80mm;">Detalle</td>
          <td width="102" class="tdHeadTablaDetalle" style="width:10mm;">Cantidad</td>
          <td width="101" class="tdHeadTablaDetalle" style="width:10mm;">Valor Unitario</td>
          <td width="198" class="tdHeadTablaDetalle" style="width:10mm;">Dscto</td>
          <td width="112" class="tdHeadTablaDetalle txtDer" style="width:10mm;">Total</td>
        </tr>
                   <tr>
		   <td colspan="7">
		    <hr/>
		   </td>
		  </tr>
     	<xsl:for-each select="Detalle">
     
	        <tr>
	          <td class="tdBodyTablaDetalle txtCen"><xsl:value-of select="NroLinDet"/></td>
	          <td class="tdBodyTablaDetalle txtIzq"><xsl:value-of select="CdgItem/VlrCodigo"/></td>
	          <td class="tdBodyTablaDetalle txtIzq"><xsl:value-of select="NmbItem"/>
	          	<xsl:choose>        
   				<xsl:when test="DscItem">
   					<br/><xsl:value-of select="DscItem"/>
   				</xsl:when>
   			</xsl:choose>
	          
	          </td>
	          <td class="tdBodyTablaDetalle txtDer"><xsl:value-of select="format-number(QtyItem,'###.###.###.###,######', 'chile')"/></td>
	          <td class="tdBodyTablaDetalle txtDer"><xsl:value-of select="format-number(PrcItem,'$ ###.###.###.###,######', 'chile')"/></td>
	          <td class="tdBodyTablaDetalle txtDer"><xsl:value-of select="format-number(DescuentoMonto,'$ ###.###.###.###,######', 'chile')"/></td>
	          <td class="tdBodyTablaDetalle txtDer"><xsl:value-of select="format-number(MontoItem,'$ ###.###.###.###,######', 'chile')"/></td>
	        </tr>
      
     	</xsl:for-each>
     	 </table>
     </xsl:when>
     <xsl:otherwise> 
            
            <table width="1241" border="0" cellpadding="0" cellspacing="0" style="padding-left:1mm;padding-right:1mm;width:200mm;">
	        <tr>
                    <td width="113" class="tdHeadTablaDetalle" style="width:30mm;">Item</td>
                    <td width="189" class="tdHeadTablaDetalle" style="width:50mm;">Codigo</td>
                    <td width="416" class="tdHeadTablaDetalle txtIzq" style="width:110mm;">Detalle</td>
                    <td width="151" class="tdHeadTablaDetalle" style="width:40mm;">Cantidad</td>
                    <td width="151" class="tdHeadTablaDetalle" style="width:40mm;">Valor Unitario</td>
                    <td width="221" class="tdHeadTablaDetalle txtDer" style="width:45mm;">Total</td>
	        </tr>
                  <tr>
		   <td colspan="6">
		    <hr/>
		   </td>
		  </tr>
     		<xsl:for-each select="Detalle">
     
	        <tr>
	          
	          <td  class="tdBodyTablaDetalle txtCen"><xsl:value-of select="NroLinDet"/></td>
	          <td class="tdBodyTablaDetalle txtIzq"><xsl:value-of select="CdgItem/VlrCodigo"/></td>
	          <td  class="tdBodyTablaDetalle txtIzq"><xsl:value-of select="NmbItem"/>
	          	<xsl:choose>        
   				<xsl:when test="DscItem">
   					<br/><xsl:value-of select="DscItem"/>
   				</xsl:when>
   			</xsl:choose>	          
	          
	          </td>
	          <td  class="tdBodyTablaDetalle txtDer"><xsl:value-of select="format-number(QtyItem,'###.###.###.###,######', 'chile')"/></td>
	          <td class="tdBodyTablaDetalle txtDer"><xsl:value-of select="format-number(PrcItem,'$ ###.###.###.###,######', 'chile')"/></td>
	          <td class="tdBodyTablaDetalle txtDer"><xsl:value-of select="format-number(MontoItem,'$ ###.###.###.###,######', 'chile')"/></td>
	          
	        </tr>
  
     		</xsl:for-each>
        </table>
     </xsl:otherwise>
</xsl:choose>      
    </td>
  </tr>

<!--********descuentos y recargos globales*********-->

  <tr>
   <td width="100%">
       <table border="0" width="100%" cellpadding="0" cellspacing="0" style="padding-left:1mm;padding-right:1mm;width:200mm;">
	<xsl:for-each select="DscRcgGlobal">
	        <tr>
	            <td width="25%"><font size="8"></font></td>
	          <td width="50%"><font size="8">Descuento Global</font></td>
	         
	          <td width="15%" align="right"><font size="8"><xsl:value-of select="ValorDR"/></font></td>
               <td width="10%" align="left"><font size="8"><xsl:value-of select="TpoValor"/></font></td>
	        </tr>
  
  	</xsl:for-each>
       </table>

   </td>
  </tr>  
  
  <tr>
   <td>
    <hr/>
   </td>
  </tr>
  
<!--  REFERENCIAS DEL DTE-->

	<xsl:choose>        
	   <xsl:when test="Referencia/TpoDocRef">
	   <tr>
   	    <td>
	      <table border="0" cellpadding="0" cellspacing="0" style="padding-left:1mm;padding-right:1mm;width:200mm;">
	        <tr><td colspan="6" align="center" style="width:230mm;font-size:14pt;font-weight:bold;height:30px;">REFERENCIAS</td></tr>
	        <tr>
	          <td  class="tdHeadTablaDetalle" style="width:30mm;">Lin</td>
	          <td class="tdHeadTablaDetalle" style="width:40mm;">Doc</td>
	          <td class="tdHeadTablaDetalle" style="width:40mm;">Folio</td>
	          <td class="tdHeadTablaDetalle" style="width:40mm;">Fecha</td>
	          <td class="tdHeadTablaDetalle txtIzq" style="width:110mm;">Motivo</td>
	          <td class="tdHeadTablaDetalle txtDer" style="width:40mm;">Corr.Factura</td>
	          
	        </tr>
	                   <tr>
			   <td colspan="6">
			    <hr/>
			   </td>
			  </tr>
	     	<xsl:for-each select="Referencia">
	     
		        <tr>
		          <td class="tdBodyTablaDetalle txtCen"><xsl:value-of select="NroLinRef"/></td>
		          <td class="tdBodyTablaDetalle txtIzq"><xsl:value-of select="TpoDocRef"/></td>
		          <td class="tdBodyTablaDetalle txtIzq"><xsl:value-of select="FolioRef"/></td>
		          <td class="tdBodyTablaDetalle txtDer"><xsl:value-of select="FchRef"/></td>
		          <td class="tdBodyTablaDetalle txtIzq"><xsl:value-of select="RazonRef"/></td>
		          <td class="tdBodyTablaDetalle txtDer"><xsl:value-of select="CorrFact"/></td>
		        </tr>
	      
	     	</xsl:for-each>
	     	 </table>
	     </td>
   	    </tr>
   	      <tr>
		 <td>
		   <hr/>
		 </td>
	      </tr>
	     </xsl:when>  
  	</xsl:choose>  
  

<!-- FIN REFERENCIAS DEL DTE-->  
  
  
  
  <tr>
    <td width="100%">
      <table border="0" width="100%" cellspacing="0">
        <tr>
          <td width="125" align="center"></td>
          <td width="106"></td>
          <td width="914" align="right" valign="top">
	          <table >
		          <tr>
		          	<td width="50%" class="tdTotal">Neto:</td>
		          	<td width="50%" align="right" class="tdTotalValor"><xsl:value-of select="format-number(Encabezado/Totales/MntNeto,'$ ###.###.###.###,######', 'chile')"/>
		          	<!--<xsl:number select="Encabezado/Totales/MntNeto"/>--></td>
		          </tr>
		          <tr>
		          	<td width="50%" class="tdTotal">IVA <xsl:value-of select='format-number(Encabezado/Totales/TasaIVA,"###.##")'/>%:</td>
		          	<td width="50%" align="right" class="tdTotalValor"><xsl:value-of select="format-number(Encabezado/Totales/IVA,'$ ###.###.###.###,######', 'chile')"/></td>
		          </tr>
		        <xsl:choose> 
                
                
 			<xsl:when test="Encabezado/Totales/MntExe">
 				<tr>
			          <td width="50%" class="tdTotal">Monto Exento</td>
			          <td width="50%" align="right" class="tdTotalValor"><xsl:value-of select="format-number(Encabezado/Totales/MntExe,'$ ###.###.###.###,######', 'chile')"/></td>
			        </tr>	
 			</xsl:when>
 			</xsl:choose>
            
 <!--IVA RETENIDOS -->
  <xsl:choose> 
 			<xsl:when test="Encabezado/Totales/ImptoReten/TipoImp">
 				<tr>
			          <td width="50%" class="tdTotal">IVA Retenido <xsl:value-of select='format-number(Encabezado/Totales/ImptoReten/TasaImp,"###.##")'/>%:</td>
			          <td width="50%" align="right" class="tdTotalValor"><xsl:value-of select="format-number(Encabezado/Totales/ImptoReten/MontoImp,'$ ###.###.###.###,######', 'chile')"/></td>
			        </tr>	
 			</xsl:when>
 			</xsl:choose>
            
<!--COMISIONES     -->
   <xsl:choose> 
 			<xsl:when test="Encabezado/Totales/Comisiones/ValComNeto">
 				<tr>
			          <td width="50%" class="tdTotal">Comision  <xsl:value-of select='format-number(Comisiones/TasaComision,"###.##")'/>%:</td>
			          <td width="50%" align="right" class="tdTotalValor"><xsl:value-of select="format-number(Encabezado/Totales/Comisiones/ValComNeto,'$ ###.###.###.###,######', 'chile')"/></td>
			        </tr>	
 			</xsl:when>
 	</xsl:choose>  
     <xsl:choose> 
 			<xsl:when test="Encabezado/Totales/Comisiones/ValComIVA">
 				<tr>
			          <td width="50%" class="tdTotal">IVA Comision: </td>
			          <td width="50%" align="right" class="tdTotalValor"><xsl:value-of select="format-number(Encabezado/Totales/Comisiones/ValComIVA,'$ ###.###.###.###,######', 'chile')"/></td>
			        </tr>	
 			</xsl:when>
 	</xsl:choose> 
            
			<!--IMPUESTOS ADICIONALES 
			    
		<xsl:for-each select="Encabezado/Totales/ImptoReten/TipoImp">
			        <tr>
			          <td width="50%">
		  			<xsl:choose>
	 <xsl:when test=".[. = 18]"><font size="3" color="#000080"><b>IVA Ant.(Carne)</b></font></xsl:when>
	 
          <xsl:when test=".[. = 32]"><font size="3" color="#000080"><b>Impuesto Retenido 8%</b></font></xsl:when>
          <xsl:when test=".[. = 321]"><font size="3" color="#000080"><b>Impuesto Retenido 19%</b></font></xsl:when>
					      <xsl:otherwise>IMPTO. xxx</xsl:otherwise>
		  		        </xsl:choose>
			          
			          </td>
			          <td width="50%" align="right"><xsl:value-of select="../MontoImp"/></td>
			        </tr>
			</xsl:for-each>-->
			        <tr>
			          <td width="50%" class="tdTotal">Total:</td>
			          <td width="50%" align="right" class="tdTotalValor"><xsl:value-of select='format-number(Encabezado/Totales/MntTotal,"$ ###.###.###.###,######","chile")'/></td>
			        </tr>	

<!--Campos Opcionales-->
			<xsl:choose> 
 			<xsl:when test="Encabezado/Totales/SaldoAnterior">
 				<tr>
			          <td width="50%" class="tdTotal">Saldo Anterior</td>
			          <td width="50%" align="right" class="tdTotalValor"><xsl:value-of select="Encabezado/Totales/SaldoAnterior"/></td>
			        </tr>	
       				<tr>
			          <td width="50%" class="tdTotal">Total a Pagar</td>
			          <td width="50%" align="right" class="tdTotalValor"><xsl:value-of select="Encabezado/Totales/VlrPagar"/></td>
			        </tr>	
 			</xsl:when>
 			</xsl:choose>

	          </table>
          </td>
       </tr>
      </table>
    </td>
  </tr>
</table>
<br/>
<br/>

<!-- FIN TOTALES -->
<table height="38" width="100%" border="0">
    <TR><TD>
	<table height="35" border="0">
        <tr>
        	<td width="278"> <img src="timbre_1.png" width="300" height="100"/></td>
        </tr>
		<tr>
		  <td align="center"><font face="Times New Roman, Times, serif" size="-4"><p>Timbre Electronico SII</p></font></td>				
		</tr>
		<tr>4
		  <td align="center">
		    <p><font size="-4" face="Times New Roman, Times, serif">Resolucion N° 80 del 22-08-2014</font></p>
		  </td>		  		
		</tr>
		<tr>
		  <td align="center"><font face="Times New Roman, Times, serif" size="-4"><p>Verifique documento : www.sii.cl</p></font></td>		  		
		</tr>
    </table> 
    </TD>
     <td>
    		<table height="35" border="0" width="*" align="right">
			<tr>
				<td><img src="../imagenes/acuse_recibo.png" width="336" height="166" border="0"/></td>
			</tr>
     	</table>
    </td>
    </TR>
    
    <tr>
     <td></td>
   
   
        <xsl:choose>                  
                  <xsl:when test="Encabezado/IdDoc/TipoDTE[. = 52]"><td style="width:70mm;float:right;margin-right:10mm;margin-top:2mm;font-family:Arial;font-size:12pt;font-weight:bold;color:red;text-align:right;"> CEDIBLE CON SU FACTURA </td></xsl:when>
                  <xsl:otherwise><td style="width:70mm;float:right;margin-right:10mm;margin-top:2mm;font-family:Arial;font-size:12pt;font-weight:bold;color:red;text-align:right;">CEDIBLE</td></xsl:otherwise>
                      </xsl:choose>
  
   
   
    </tr>
    
    </table>

</div>

</xsl:for-each>

</body>
</html>
</xsl:template>


</xsl:stylesheet>