<?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="re_inf_recur_pend_giro" language="groovy" pageWidth="900" pageHeight="612" orientation="Landscape" whenNoDataType="NoDataSection" columnWidth="860" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20">
	<property name="ireport.zoom" value="1.2100000000000026"/>
	<property name="ireport.x" value="21"/>
	<property name="ireport.y" value="0"/>
	<parameter name="id_anhos" class="java.math.BigDecimal">
		<defaultValueExpression><![CDATA[]]></defaultValueExpression>
	</parameter>
	<parameter name="id_meses" class="java.math.BigDecimal">
		<defaultValueExpression><![CDATA[]]></defaultValueExpression>
	</parameter>
	<parameter name="whereDepartamento" class="java.lang.String">
		<defaultValueExpression><![CDATA[" "]]></defaultValueExpression>
	</parameter>
	<parameter name="whereMinero" class="java.lang.String">
		<defaultValueExpression><![CDATA[" "]]></defaultValueExpression>
	</parameter>
	<parameter name="whereAutorizado" class="java.lang.String">
		<defaultValueExpression><![CDATA[" "]]></defaultValueExpression>
	</parameter>
	<queryString>
		<![CDATA[select
tab0.*
from(

    select
    tab0.coddepto,
    tab0.desdepto,
    tab0.id_mae_ter_obldet as id_mae_ter,
    tab0.num_doc_ter_obldet,
    tab0.razon_soc_obldet,
    tab0.dv_obldet,
    tab0.autorizado,
    tab0.fecha_doc,
    sum(nvl(tab0.valor_girar,0)) as valor_girar,
    tab0.id_bn_achdis,
    tab0.banco,
    tab0.num_cuenta
    from(
        SELECT

        ter.coddepto,
        dep.desdepto,
        ter.codmun,
        tab.*,
        bene.id_bene_autoriza,
        bene.secuencia as secuencia_bene,
        nvl(bene.autorizado,1) as autorizado,
        bene.fecha_doc,
        achdis.id_bn as id_bn_achdis,
        achdis.num_cuenta,
        bn.descripcion as banco

        from re_distri_obl_obldet tab

        left join (
          SELECT
           aut.*,
           ROW_NUMBER() OVER (
            PARTITION BY aut.id_mae_ter
            ORDER BY aut.id_mae_ter, aut.secuencia desc
           ) AS rn
          from re_bene_autoriza aut
        )bene
        on bene.id_mae_ter = tab.id_mae_ter_obldet
        and bene.rn = 1

        LEFT JOIN re_terceros ter
        ON ter.id_mae_ter = tab.id_mae_ter_obldet

        LEFT JOIN departamentos dep
        ON dep.coddepto = ter.coddepto

        /*left join ts_reg_ach_distri achdis
        on tab.id_mae_ter_obldet = achdis.id_tercero*/
        left join (
          SELECT
           aut.*,
           ROW_NUMBER() OVER (
            PARTITION BY aut.id_tercero
            ORDER BY aut.id_tercero, aut.id_reg_ach_distri desc
           ) AS rn
          from ts_reg_ach_distri aut
          join ts_reg_ach ach
          on aut.id_reg_ach = ach.id_reg_ach
          where
          ach.aplica_regalias = 1
        )achdis
        on achdis.id_tercero = tab.id_mae_ter_obldet
        and achdis.rn = 1

        left join ts_bn bn
        on bn.id_bn = achdis.id_bn

        where
        tab.fecha_crea <= last_day(to_date( $P{id_anhos}||'-'||$P{id_meses}||'-01' , 'yyyy-mm-dd'))
        and tab.estado_obl = 1
        and tab.pago = 0
        and tab.es_transfer = 0
        and tab.valor_girar != 0

    )tab0

    group by
    tab0.coddepto,
    tab0.desdepto,
    tab0.id_mae_ter_obldet,
    tab0.num_doc_ter_obldet,
    tab0.razon_soc_obldet,
    tab0.dv_obldet,
    tab0.autorizado,
    tab0.fecha_doc,
    tab0.id_bn_achdis,
    tab0.banco,
    tab0.num_cuenta

)tab0

where
1 = 1
$P!{whereDepartamento}
$P!{whereMinero}
$P!{whereAutorizado}

order by
tab0.desdepto, tab0.num_doc_ter_obldet]]>
	</queryString>
	<field name="CODDEPTO" class="java.lang.String"/>
	<field name="DESDEPTO" class="java.lang.String"/>
	<field name="ID_MAE_TER" class="java.math.BigDecimal"/>
	<field name="NUM_DOC_TER_OBLDET" class="java.lang.String"/>
	<field name="RAZON_SOC_OBLDET" class="java.lang.String"/>
	<field name="DV_OBLDET" class="java.math.BigDecimal"/>
	<field name="AUTORIZADO" class="java.math.BigDecimal"/>
	<field name="FECHA_DOC" class="java.sql.Timestamp"/>
	<field name="VALOR_GIRAR" class="java.math.BigDecimal"/>
	<field name="ID_BN_ACHDIS" class="java.math.BigDecimal"/>
	<field name="BANCO" class="java.lang.String"/>
	<field name="NUM_CUENTA" class="java.lang.String"/>
	<background>
		<band splitType="Stretch"/>
	</background>
	<title>
		<band height="60" splitType="Stretch">
			<textField pattern="dd-MM-yyyy   hh:mm aaa">
				<reportElement mode="Opaque" x="760" y="40" width="100" height="12" forecolor="#000000" backcolor="#FFFFFF"/>
				<textElement textAlignment="Right" verticalAlignment="Middle" rotation="None" markup="none">
					<font fontName="SansSerif" size="8" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
				</textElement>
				<textFieldExpression class="java.util.Date"><![CDATA[new java.util.Date()]]></textFieldExpression>
			</textField>
			<staticText>
				<reportElement x="240" y="0" width="410" height="40"/>
				<textElement textAlignment="Center" verticalAlignment="Bottom" markup="none">
					<font fontName="SansSerif" size="12" isBold="true"/>
				</textElement>
				<text><![CDATA[Sistema de Distribución de Regalías
Informe de Recursos Pendientes de Giro]]></text>
			</staticText>
			<image>
				<reportElement x="0" y="12" width="140" height="40"/>
				<imageExpression class="java.lang.String"><![CDATA["repo:LogoEmpresa003.jpg"]]></imageExpression>
			</image>
			<staticText>
				<reportElement mode="Opaque" x="760" y="28" width="100" 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>
				<reportElement x="240" y="40" width="410" height="20"/>
				<textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
					<font fontName="SansSerif" size="12" isBold="true"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA["Periodo: " + $P{id_meses} + " - "+ $P{id_anhos}]]></textFieldExpression>
			</textField>
		</band>
	</title>
	<pageHeader>
		<band height="9" splitType="Stretch"/>
	</pageHeader>
	<columnHeader>
		<band height="36" splitType="Stretch">
			<staticText>
				<reportElement mode="Opaque" x="0" y="16" width="60" height="20" 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[Cod. Depto.]]></text>
			</staticText>
			<staticText>
				<reportElement mode="Opaque" x="240" y="16" width="140" height="20" 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[Beneficiario]]></text>
			</staticText>
			<staticText>
				<reportElement mode="Opaque" x="60" y="16" width="100" height="20" 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[Departamento]]></text>
			</staticText>
			<staticText>
				<reportElement mode="Opaque" x="160" y="16" width="80" height="20" 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[Documento]]></text>
			</staticText>
			<staticText>
				<reportElement mode="Opaque" x="380" y="16" width="60" height="20" 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[Estado]]></text>
			</staticText>
			<staticText>
				<reportElement mode="Opaque" x="650" y="16" width="110" height="20" 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[Banco]]></text>
			</staticText>
			<staticText>
				<reportElement mode="Opaque" x="760" y="16" width="100" height="20" 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[No. Cuenta]]></text>
			</staticText>
			<staticText>
				<reportElement mode="Opaque" x="440" y="16" width="120" height="20" 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[Fecha Autorización/Suspención]]></text>
			</staticText>
			<staticText>
				<reportElement mode="Opaque" x="560" y="16" width="90" height="20" 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[Saldo]]></text>
			</staticText>
		</band>
	</columnHeader>
	<detail>
		<band height="10" splitType="Stretch">
			<textField isStretchWithOverflow="true" isBlankWhenNull="true">
				<reportElement x="240" y="0" width="140" height="10"/>
				<box leftPadding="3">
					<pen lineWidth="0.75"/>
					<topPen lineWidth="0.75"/>
					<leftPen lineWidth="0.75"/>
					<bottomPen lineWidth="0.75"/>
					<rightPen lineWidth="0.75"/>
				</box>
				<textElement verticalAlignment="Middle">
					<font size="6"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{RAZON_SOC_OBLDET}]]></textFieldExpression>
			</textField>
			<textField isBlankWhenNull="true">
				<reportElement stretchType="RelativeToTallestObject" x="0" y="0" width="60" height="10"/>
				<box leftPadding="0" 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">
					<font size="6"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{CODDEPTO}]]></textFieldExpression>
			</textField>
			<textField isBlankWhenNull="true">
				<reportElement stretchType="RelativeToTallestObject" x="60" y="0" width="100" height="10"/>
				<box leftPadding="2" rightPadding="0">
					<pen lineWidth="0.75"/>
					<topPen lineWidth="0.75"/>
					<leftPen lineWidth="0.75"/>
					<bottomPen lineWidth="0.75"/>
					<rightPen lineWidth="0.75"/>
				</box>
				<textElement verticalAlignment="Middle">
					<font size="6"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{DESDEPTO}]]></textFieldExpression>
			</textField>
			<textField isBlankWhenNull="true">
				<reportElement stretchType="RelativeToTallestObject" x="160" y="0" width="80" height="10"/>
				<box leftPadding="0" rightPadding="1">
					<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">
					<font size="6"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{NUM_DOC_TER_OBLDET}]]></textFieldExpression>
			</textField>
			<textField isBlankWhenNull="true">
				<reportElement stretchType="RelativeToTallestObject" x="380" y="0" width="60" height="10"/>
				<box leftPadding="0" 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="Center" verticalAlignment="Middle">
					<font size="6"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[( $F{AUTORIZADO}.intValue() == 1
    ? "Autorizado"
    : "Suspendido"
)]]></textFieldExpression>
			</textField>
			<textField isBlankWhenNull="true">
				<reportElement stretchType="RelativeToTallestObject" x="760" y="0" width="100" height="10"/>
				<box leftPadding="3">
					<pen lineWidth="0.75"/>
					<topPen lineWidth="0.75"/>
					<leftPen lineWidth="0.75"/>
					<bottomPen lineWidth="0.75"/>
					<rightPen lineWidth="0.75"/>
				</box>
				<textElement verticalAlignment="Middle">
					<font size="6"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{NUM_CUENTA}]]></textFieldExpression>
			</textField>
			<textField isBlankWhenNull="true">
				<reportElement stretchType="RelativeToTallestObject" x="650" y="0" width="110" height="10"/>
				<box leftPadding="3">
					<pen lineWidth="0.75"/>
					<topPen lineWidth="0.75"/>
					<leftPen lineWidth="0.75"/>
					<bottomPen lineWidth="0.75"/>
					<rightPen lineWidth="0.75"/>
				</box>
				<textElement verticalAlignment="Middle">
					<font size="6"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{BANCO}]]></textFieldExpression>
			</textField>
			<textField pattern="dd/MM/yyyy" isBlankWhenNull="true">
				<reportElement stretchType="RelativeToTallestObject" x="440" y="0" width="120" height="10"/>
				<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">
					<font size="6"/>
				</textElement>
				<textFieldExpression class="java.util.Date"><![CDATA[$F{FECHA_DOC}]]></textFieldExpression>
			</textField>
			<textField pattern="#,##0.00" isBlankWhenNull="true">
				<reportElement stretchType="RelativeToTallestObject" x="560" y="0" width="90" height="10"/>
				<box leftPadding="0" 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">
					<font size="6"/>
				</textElement>
				<textFieldExpression class="java.math.BigDecimal"><![CDATA[$F{VALOR_GIRAR}]]></textFieldExpression>
			</textField>
		</band>
	</detail>
	<columnFooter>
		<band height="12" splitType="Stretch"/>
	</columnFooter>
	<pageFooter>
		<band height="24" splitType="Stretch">
			<textField>
				<reportElement mode="Opaque" x="401" y="12" width="89" 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="491" y="12" width="60" height="12" forecolor="#575757" backcolor="#FFFFFF"/>
				<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="401" y="0" width="150" height="12" forecolor="#575757"/>
				<textElement textAlignment="Center" verticalAlignment="Middle">
					<font size="6"/>
				</textElement>
				<text><![CDATA[Websafi - Regalias]]></text>
			</staticText>
		</band>
	</pageFooter>
	<summary>
		<band height="14" splitType="Stretch"/>
	</summary>
	<noData>
		<band height="20">
			<staticText>
				<reportElement x="0" y="0" width="860" height="20"/>
				<textElement textAlignment="Center" verticalAlignment="Middle">
					<font isBold="true"/>
				</textElement>
				<text><![CDATA[No hay objetos a mostrar.]]></text>
			</staticText>
		</band>
	</noData>
</jasperReport>
