<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="aportes_patronales_pila" language="groovy" pageWidth="612" pageHeight="792" orientation="Landscape" columnWidth="572" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
	<property name="ireport.zoom" value="1.7715610000000093"/>
	<property name="ireport.x" value="30"/>
	<property name="ireport.y" value="0"/>
	<parameter name="id_periodo_filtro" class="java.lang.String">
		<defaultValueExpression><![CDATA[]]></defaultValueExpression>
	</parameter>
	<parameter name="comando" class="java.lang.String">
		<defaultValueExpression><![CDATA[]]></defaultValueExpression>
	</parameter>
	<parameter name="whereClasePlanta" class="java.lang.String">
		<defaultValueExpression><![CDATA[" "]]></defaultValueExpression>
	</parameter>
	<parameter name="desc_clase" class="java.lang.String"/>
	<queryString>
		<![CDATA[select
count(distinct tab0.num_doc) as cantidad,
count(clafon.codigo) as cantidad_clafon,
tab0.id_periodo,tab0.id_clase_fondo,
clafon.codigo as codigo_clafon,
clafon.descripcion,
clafon.codigo || ' - ' || clafon.descripcion as completo_clafon,
tab0.id_mae_fondos,
tab0.codigo, tab0.fondo,
tab0.num_doc_mae
,sum( nvl( tab0.APORTE_FUNC_PENSION ,0) ) APORTE_FUNC_PENSION
,sum( nvl( tab0.APORTE_PATRONO_PENSION ,0) ) APORTE_PATRONO_PENSION
,sum( nvl( tab0.TOTAL_PENSION ,0) ) TOTAL_PENSION
,sum( nvl( tab0.APORTE_FUNC_SALUD ,0) ) APORTE_FUNC_SALUD
,sum( nvl( tab0.APORTE_PATRONO_SALUD ,0) ) APORTE_PATRONO_SALUD
,sum( nvl( tab0.TOTAL_SALUD ,0) ) TOTAL_SALUD
,sum( nvl( tab0.UPC_ADICIO ,0) ) UPC_ADICIO
,sum( nvl( tab0.APORTE_PATRONO_ARP ,0) ) APORTE_PATRONO_ARP
,sum( nvl( tab0.TOTAL_ARP ,0) ) TOTAL_ARP
,sum( nvl( tab0.PARAFISCALES ,0) ) PARAFISCALES
,sum( nvl( tab0.TOTAL_EMPLEADO ,0) ) TOTAL_EMPLEADO
,sum( nvl( tab0.TOTAL_APORTES ,0) ) TOTAL_APORTES,
(select distinct periodo.periodo from no_liquida_v periodo where periodo.id_periodo = tab0.id_periodo) AS PERIODO,
(select distinct periodo.tipper from no_liquida_v periodo where periodo.id_periodo = tab0.id_periodo) AS TIPPER,
sum( nvl( tab0.APORTE_PATRONO_PENSION ,0) ) + sum( nvl( tab0.APORTE_PATRONO_SALUD ,0) ) + sum( nvl( tab0.APORTE_PATRONO_ARP ,0) ) + sum( nvl( tab0.PARAFISCALES ,0) ) total

    FROM(

    SELECT
    tab3.id_periodo,tab3.id_clase_fondo,
    tab3.id_mae_fondos,
    tab3.codigo,tab3.fondo,
    tab3.num_doc,
    tab3.num_doc_mae,
    tab3.APORTE_FUNC_PENSION,
    tab3.APORTE_PATRONO_PENSION,
    tab3.TOTAL_PENSION,
    tab3.APORTE_FUNC_SALUD,
    tab3.APORTE_PATRONO_SALUD,
    tab3.TOTAL_SALUD,
    tab3.UPC_ADICIO,
    tab3.APORTE_PATRONO_ARP,
    tab3.TOTAL_ARP,
    tab3.PARAFISCALES,
    ( nvl( APORTE_FUNC_PENSION ,0)  +  nvl( APORTE_FUNC_SALUD ,0) ) AS TOTAL_EMPLEADO,
    ( nvl( tab3.TOTAL_PENSION ,0)  +  nvl( tab3.TOTAL_SALUD ,0)  +  nvl( tab3.TOTAL_ARP ,0) +  nvl( tab3.PARAFISCALES ,0) ) AS TOTAL_APORTES

        FROM(

        select
        tab1.id_periodo as id_periodo,
        tab1.id_clase_fondo,
        tab2.id_mae_fondos,
        tab2.codigo as codigo,
        tab1.num_doc,
        tab2.num_doc as num_doc_mae,
        tab2.razon_social AS FONDO,
        case when tab1.id_clase_fondo =1 then tab1.aporte_func
        when tab1.id_clase_fondo = 2 then 0
        when tab1.id_clase_fondo = 3 then 0
        else 0 end AS APORTE_FUNC_PENSION,
        case when tab1.id_clase_fondo =1 then tab1.aporte_patrono + tab1.aporte_patrono_licnorem
        when tab1.id_clase_fondo = 2 then 0
        when tab1.id_clase_fondo = 3 then 0
        else 0 end AS APORTE_PATRONO_PENSION,
        case when tab1.id_clase_fondo =1 then tab1.aporte_patrono+tab1.aporte_func + tab1.aporte_patrono_licnorem
        when tab1.id_clase_fondo = 2 then 0
        when tab1.id_clase_fondo = 3 then 0
        else 0 end AS TOTAL_PENSION,

        case when tab1.id_clase_fondo =1 then 0
        when tab1.id_clase_fondo = 2 then tab1.aporte_func
        when tab1.id_clase_fondo = 3 then 0
        else 0 end AS APORTE_FUNC_SALUD,
        case when tab1.id_clase_fondo =1 then 0
        when tab1.id_clase_fondo = 2 then tab1.aporte_patrono + tab1.aporte_patrono_licnorem
        when tab1.id_clase_fondo = 3 then 0
        else 0 end AS APORTE_PATRONO_SALUD,
        case when tab1.id_clase_fondo =1 then 0
        when tab1.id_clase_fondo = 2 then tab1.aporte_patrono+tab1.aporte_func+tab1.upc_adicio + tab1.aporte_patrono_licnorem
        when tab1.id_clase_fondo = 3 then 0
        else 0 end AS TOTAL_SALUD,

        case when tab1.id_clase_fondo =1 then 0
        when tab1.id_clase_fondo = 2 then tab1.upc_adicio
        when tab1.id_clase_fondo = 3 then 0
        else 0 end AS UPC_ADICIO,

        case when tab1.id_clase_fondo =1 then 0
        when tab1.id_clase_fondo = 2 then 0
        when tab1.id_clase_fondo = 3 then tab1.aporte_patrono
        else 0 end AS APORTE_PATRONO_ARP,

        case when tab1.id_clase_fondo =1 then 0
        when tab1.id_clase_fondo = 2 then 0
        when tab1.id_clase_fondo = 3 then tab1.aporte_patrono
        else 0 end AS TOTAL_ARP,

        case when tab1.id_clase_fondo =1 then 0
        when tab1.id_clase_fondo = 2 then 0
        when tab1.id_clase_fondo = 3 then 0
        else tab1.aporte_patrono end AS PARAFISCALES


        from no_liquida_aporte tab1

        left join no_mae_fondos tab2 ON tab2.id_mae_fondos = tab1.id_mae_fondos

        left join (

           select nom.*,
           case when tab.num_doc is not null then 1 else 0 end as pago
           from no_nombramiento_v nom

           left join (select distinct
           pago.id_tipo_doc,
           pago.num_doc
           from no_pago_func pago
           where
           (select fecha_fin from no_periodo where id_periodo = $P{id_periodo_filtro}) between pago.fecha_activacion and nvl(pago.fecha_terminacion, (select fecha_fin from no_periodo where id_periodo = $P{id_periodo_filtro}))
           )tab
           on tab.id_tipo_doc = nom.id_tipo_doc and tab.num_doc = nom.num_doc

        )tab0
        on tab0.id_tipo_doc = tab1.id_tipo_doc and tab0.num_doc = tab1.num_doc

        --Se toman solo aportes tipo A - 20140825

        where
        tab1.tipo_planilla = 'A'
        $P!{whereClasePlanta}

    )tab3

)tab0

join no_clase_fondo clafon
on tab0.id_clase_fondo = clafon.id_clase_fondo

where tab0.id_periodo = $P{id_periodo_filtro}
--$whereClaseFondo $whereMaestroFondos

group by tab0.id_periodo,
tab0.id_clase_fondo, clafon.codigo,
clafon.descripcion,
tab0.id_mae_fondos,
tab0.num_doc_mae,
tab0.codigo, tab0.fondo

ORDER BY clafon.codigo, tab0.CODIGO]]>
	</queryString>
	<field name="CANTIDAD" class="java.math.BigDecimal"/>
	<field name="CANTIDAD_CLAFON" class="java.math.BigDecimal"/>
	<field name="ID_PERIODO" class="java.math.BigDecimal"/>
	<field name="ID_CLASE_FONDO" class="java.math.BigDecimal"/>
	<field name="CODIGO_CLAFON" class="java.lang.String"/>
	<field name="DESCRIPCION" class="java.lang.String"/>
	<field name="COMPLETO_CLAFON" class="java.lang.String"/>
	<field name="ID_MAE_FONDOS" class="java.math.BigDecimal"/>
	<field name="CODIGO" class="java.lang.String"/>
	<field name="FONDO" class="java.lang.String"/>
	<field name="NUM_DOC_MAE" class="java.math.BigDecimal"/>
	<field name="APORTE_FUNC_PENSION" class="java.math.BigDecimal"/>
	<field name="APORTE_PATRONO_PENSION" class="java.math.BigDecimal"/>
	<field name="TOTAL_PENSION" class="java.math.BigDecimal"/>
	<field name="APORTE_FUNC_SALUD" class="java.math.BigDecimal"/>
	<field name="APORTE_PATRONO_SALUD" class="java.math.BigDecimal"/>
	<field name="TOTAL_SALUD" class="java.math.BigDecimal"/>
	<field name="UPC_ADICIO" class="java.math.BigDecimal"/>
	<field name="APORTE_PATRONO_ARP" class="java.math.BigDecimal"/>
	<field name="TOTAL_ARP" class="java.math.BigDecimal"/>
	<field name="PARAFISCALES" class="java.math.BigDecimal"/>
	<field name="TOTAL_EMPLEADO" class="java.math.BigDecimal"/>
	<field name="TOTAL_APORTES" class="java.math.BigDecimal"/>
	<field name="PERIODO" class="java.lang.String"/>
	<field name="TIPPER" class="java.lang.String"/>
	<field name="TOTAL" class="java.math.BigDecimal"/>
	<variable name="suma1" class="java.math.BigDecimal" calculation="Sum">
		<variableExpression><![CDATA[$F{APORTE_FUNC_PENSION}]]></variableExpression>
	</variable>
	<variable name="suma2" class="java.math.BigDecimal" calculation="Sum">
		<variableExpression><![CDATA[$F{APORTE_PATRONO_PENSION}]]></variableExpression>
	</variable>
	<variable name="suma3" class="java.math.BigDecimal" calculation="Sum">
		<variableExpression><![CDATA[$F{TOTAL_PENSION}]]></variableExpression>
	</variable>
	<variable name="suma4" class="java.math.BigDecimal" calculation="Sum">
		<variableExpression><![CDATA[$F{APORTE_FUNC_SALUD}]]></variableExpression>
	</variable>
	<variable name="suma5" class="java.math.BigDecimal" calculation="Sum">
		<variableExpression><![CDATA[$F{APORTE_PATRONO_SALUD}]]></variableExpression>
	</variable>
	<variable name="suma6" class="java.math.BigDecimal" calculation="Sum">
		<variableExpression><![CDATA[$F{UPC_ADICIO}]]></variableExpression>
	</variable>
	<variable name="suma7" class="java.math.BigDecimal" calculation="Sum">
		<variableExpression><![CDATA[$F{TOTAL_SALUD}]]></variableExpression>
	</variable>
	<variable name="suma8" class="java.math.BigDecimal" calculation="Sum">
		<variableExpression><![CDATA[$F{TOTAL_ARP}]]></variableExpression>
	</variable>
	<variable name="suma9_total" class="java.math.BigDecimal" calculation="Sum">
		<variableExpression><![CDATA[$F{TOTAL}]]></variableExpression>
	</variable>
	<background>
		<band splitType="Stretch"/>
	</background>
	<title>
		<band height="60" splitType="Stretch">
			<staticText>
				<reportElement x="140" y="0" width="300" height="40"/>
				<textElement textAlignment="Center" verticalAlignment="Bottom" markup="none">
					<font fontName="SansSerif" size="12" isBold="true"/>
				</textElement>
				<text><![CDATA[Sistema General de Nómina
Aportes Patronales - PILA]]></text>
			</staticText>
			<image>
				<reportElement x="0" y="10" width="140" height="40"/>
				<imageExpression class="java.lang.String"><![CDATA["repo:LogoEmpresa003.jpg"]]></imageExpression>
			</image>
			<staticText>
				<reportElement mode="Opaque" x="440" y="28" width="115" height="12" forecolor="#000000" backcolor="#FFFFFF"/>
				<textElement textAlignment="Right" verticalAlignment="Middle" rotation="None" markup="none">
					<font fontName="SansSerif" size="8" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
				</textElement>
				<text><![CDATA[Fecha de Impresión:]]></text>
			</staticText>
			<textField pattern="dd-MMM-yyyy   hh:mm aaa">
				<reportElement x="440" y="40" width="115" height="12"/>
				<box rightPadding="3"/>
				<textElement textAlignment="Right" verticalAlignment="Middle">
					<font size="8"/>
				</textElement>
				<textFieldExpression class="java.util.Date"><![CDATA[new java.util.Date()]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="140" y="40" width="300" height="20"/>
				<textElement textAlignment="Center" verticalAlignment="Middle">
					<font size="12" isBold="true"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{TIPPER}+" "+$F{PERIODO}]]></textFieldExpression>
			</textField>
		</band>
	</title>
	<pageHeader>
		<band height="14" splitType="Stretch"/>
	</pageHeader>
	<columnHeader>
		<band height="12" splitType="Stretch">
			<staticText>
				<reportElement mode="Opaque" x="40" y="0" width="100" height="12" forecolor="#000000" backcolor="#88C2F9"/>
				<box>
					<pen lineWidth="0.75"/>
					<topPen lineWidth="0.75"/>
					<leftPen lineWidth="0.75"/>
					<bottomPen lineWidth="0.75"/>
					<rightPen lineWidth="0.75"/>
				</box>
				<textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
					<font fontName="SansSerif" size="8" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
				</textElement>
				<text><![CDATA[NIT Fondo]]></text>
			</staticText>
			<staticText>
				<reportElement mode="Opaque" x="140" y="0" width="300" height="12" forecolor="#000000" backcolor="#88C2F9"/>
				<box>
					<pen lineWidth="0.75"/>
					<topPen lineWidth="0.75"/>
					<leftPen lineWidth="0.75"/>
					<bottomPen lineWidth="0.75"/>
					<rightPen lineWidth="0.75"/>
				</box>
				<textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
					<font fontName="SansSerif" size="8" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
				</textElement>
				<text><![CDATA[Nombre Tercero]]></text>
			</staticText>
			<staticText>
				<reportElement mode="Opaque" x="440" y="0" width="115" height="12" forecolor="#000000" backcolor="#88C2F9"/>
				<box>
					<pen lineWidth="0.75"/>
					<topPen lineWidth="0.75"/>
					<leftPen lineWidth="0.75"/>
					<bottomPen lineWidth="0.75"/>
					<rightPen lineWidth="0.75"/>
				</box>
				<textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
					<font fontName="SansSerif" size="8" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
				</textElement>
				<text><![CDATA[Valor Aporte Patronal]]></text>
			</staticText>
		</band>
	</columnHeader>
	<detail>
		<band height="13" splitType="Stretch">
			<textField pattern="" isBlankWhenNull="false">
				<reportElement mode="Transparent" x="140" y="0" width="300" height="13" forecolor="#000000" backcolor="#FFFFFF"/>
				<box leftPadding="2">
					<pen lineWidth="0.75"/>
					<topPen lineWidth="0.75"/>
					<leftPen lineWidth="0.75"/>
					<bottomPen lineWidth="0.75"/>
					<rightPen lineWidth="0.75"/>
				</box>
				<textElement textAlignment="Left" verticalAlignment="Middle" rotation="None" markup="none">
					<font fontName="SansSerif" size="6" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{FONDO}]]></textFieldExpression>
			</textField>
			<textField pattern="#,##0.00;(#,##0.00)" isBlankWhenNull="false">
				<reportElement mode="Transparent" x="440" y="0" width="115" height="13" forecolor="#000000" backcolor="#FFFFFF"/>
				<box rightPadding="2">
					<pen lineWidth="0.75"/>
					<topPen lineWidth="0.75"/>
					<leftPen lineWidth="0.75"/>
					<bottomPen lineWidth="0.75"/>
					<rightPen lineWidth="0.75"/>
				</box>
				<textElement textAlignment="Right" verticalAlignment="Middle" rotation="None" markup="none">
					<font fontName="SansSerif" size="6" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
				</textElement>
				<textFieldExpression class="java.math.BigDecimal"><![CDATA[$F{TOTAL}]]></textFieldExpression>
			</textField>
			<textField pattern="" isBlankWhenNull="false">
				<reportElement mode="Transparent" x="40" y="0" width="100" height="13" forecolor="#000000" backcolor="#FFFFFF"/>
				<box rightPadding="0">
					<pen lineWidth="0.75"/>
					<topPen lineWidth="0.75"/>
					<leftPen lineWidth="0.75"/>
					<bottomPen lineWidth="0.75"/>
					<rightPen lineWidth="0.75"/>
				</box>
				<textElement textAlignment="Center" verticalAlignment="Middle" rotation="None" markup="none">
					<font fontName="SansSerif" size="6" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{NUM_DOC_MAE}]]></textFieldExpression>
			</textField>
		</band>
	</detail>
	<columnFooter>
		<band height="15" splitType="Stretch"/>
	</columnFooter>
	<pageFooter>
		<band height="25" splitType="Stretch">
			<textField>
				<reportElement mode="Opaque" x="215" y="12" width="87" height="12" forecolor="#575757" backcolor="#FFFFFF"/>
				<textElement textAlignment="Right" verticalAlignment="Middle" rotation="None" markup="none">
					<font fontName="SansSerif" size="6" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA["Página "+$V{PAGE_NUMBER}+" de "]]></textFieldExpression>
			</textField>
			<textField evaluationTime="Report" pattern="" isBlankWhenNull="false">
				<reportElement mode="Opaque" x="302" y="12" width="57" height="12" forecolor="#575757" backcolor="#FFFFFF"/>
				<box leftPadding="2"/>
				<textElement verticalAlignment="Middle" rotation="None" markup="none">
					<font fontName="SansSerif" size="6" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
			</textField>
			<staticText>
				<reportElement mode="Opaque" x="215" y="0" width="144" height="12" forecolor="#575757"/>
				<textElement textAlignment="Center" verticalAlignment="Middle">
					<font size="6"/>
				</textElement>
				<text><![CDATA[Websafi - Nómina]]></text>
			</staticText>
		</band>
	</pageFooter>
	<summary>
		<band height="107" splitType="Stretch">
			<subreport>
				<reportElement stretchType="RelativeToBandHeight" x="19" y="29" width="196" height="64"/>
				<subreportParameter name="comando">
					<subreportParameterExpression><![CDATA[$P{comando}]]></subreportParameterExpression>
				</subreportParameter>
				<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
				<subreportExpression class="java.lang.String"><![CDATA["repo:firmas1.jrxml"]]></subreportExpression>
			</subreport>
			<subreport>
				<reportElement x="242" y="29" width="200" height="64"/>
				<subreportParameter name="comando">
					<subreportParameterExpression><![CDATA[$P{comando}]]></subreportParameterExpression>
				</subreportParameter>
				<connectionExpression><![CDATA[$P{REPORT_CONNECTION}]]></connectionExpression>
				<subreportExpression class="java.lang.String"><![CDATA["repo:firma2.jrxml"]]></subreportExpression>
			</subreport>
			<textField pattern="" isBlankWhenNull="true">
				<reportElement mode="Opaque" x="40" y="0" width="400" height="9" forecolor="#000000" backcolor="#C0C4CA"/>
				<box leftPadding="2">
					<pen lineWidth="0.75"/>
					<topPen lineWidth="0.75"/>
					<leftPen lineWidth="0.75"/>
					<bottomPen lineWidth="0.75"/>
					<rightPen lineWidth="0.75"/>
				</box>
				<textElement verticalAlignment="Middle" rotation="None" markup="none">
					<font fontName="SansSerif" size="6" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA["Total"]]></textFieldExpression>
			</textField>
			<textField pattern="#,##0.00;(#,##0.00)" isBlankWhenNull="true">
				<reportElement mode="Opaque" x="440" y="0" width="115" height="9" forecolor="#000000" backcolor="#C0C4CA"/>
				<box rightPadding="2">
					<pen lineWidth="0.75"/>
					<topPen lineWidth="0.75"/>
					<leftPen lineWidth="0.75"/>
					<bottomPen lineWidth="0.75"/>
					<rightPen lineWidth="0.75"/>
				</box>
				<textElement textAlignment="Right" verticalAlignment="Middle" rotation="None" markup="none">
					<font fontName="SansSerif" size="6" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
				</textElement>
				<textFieldExpression class="java.math.BigDecimal"><![CDATA[$V{suma9_total}]]></textFieldExpression>
			</textField>
		</band>
	</summary>
	<noData>
		<band height="20">
			<staticText>
				<reportElement x="0" y="0" width="572" height="20"/>
				<textElement textAlignment="Center" verticalAlignment="Middle">
					<font isBold="true"/>
				</textElement>
				<text><![CDATA[No hay objetos a mostrar.]]></text>
			</staticText>
		</band>
	</noData>
</jasperReport>
