<?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="no_ana_planta_personal_ocupada" language="groovy" pageWidth="572" pageHeight="752" columnWidth="555" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0">
	<property name="ireport.zoom" value="1.2100000000000009"/>
	<property name="ireport.x" value="0"/>
	<property name="ireport.y" value="0"/>
	<parameter name="id_periodo" class="java.math.BigDecimal">
		<defaultValueExpression><![CDATA[]]></defaultValueExpression>
	</parameter>
	<queryString>
		<![CDATA[select

nivel.*,
cant.descripcion as desc_nivel,
nvl(cant.cantidad,0) as cantidad,
nvl(cant.porcentaje,0) as porcentaje

from rh_pn_jerarquia nivel

left join(

    select
    tab.id_pn_jer,
    tab.descripcion,
    tab.nivel,
    count(tab.id_dp) as cantidad,
    round( count(tab.id_dp) * 100 / tab.n_cargos ) as porcentaje
    from(

        select
        pla.id_planta,
        pla.n_cargos,
        est.*,
        dat.fecha_nace,
        rhdp.codigo as codigo_cargo,
        apden.id_den_emp,
        apden.id_nat_em,
        apden.empl_norma,
        pncom.id_com_esc,
        pncom.codigo,
        pncom.grado,
        pncom.denominacion,
        nivel.nivel,
        nivel.descripcion,
        nivel.id_pn_jer

        from no_estado_func_v est

        join no_periodo_v per
        on per.id_periodo = est.periodo

        join NO_DATOS_FUNCIONARIO_V dat
        on est.id_tipo_doc = dat.id_tipo_doc and est.num_doc = dat.num_doc

        left join no_nombramiento_v nom
        on nom.id_tipo_doc = est.id_tipo_doc and nom.num_doc = est.num_doc

        join rh_dp rhdp
        on rhdp.id_dp = est.id_dp

        join rh_ap_den_emp apden
        on apden.id_den_emp = rhdp.id_den_emp

        left join rh_ap_planta pla
        on pla.id_planta = apden.id_planta_p

        join rh_pn_componente_escala pncom
        on pncom.id_com_esc = apden.id_comp_es

        join rh_pn_jerarquia nivel
        on nivel.nivel = pncom.id_nivel_jerarquico

        where
        est.periodo = $P{id_periodo}
        and (
            nom.estado = 1
            or
            (
              nom.estado = 0
              and nom.fecha_termina > per.fecha_fin
            )
        )

    )tab

    group by
    tab.id_pn_jer,
    tab.descripcion,
    tab.nivel,
    tab.n_cargos

)cant
on cant.nivel = nivel.nivel

order by
nivel.id_pn_jer]]>
	</queryString>
	<field name="NIVEL" class="java.math.BigDecimal"/>
	<field name="DESCRIPCION" class="java.lang.String"/>
	<field name="ID_PN_JER" class="java.math.BigDecimal"/>
	<field name="ADJUNTO" class="java.lang.String"/>
	<field name="DESC_NIVEL" class="java.lang.String"/>
	<field name="CANTIDAD" class="java.math.BigDecimal"/>
	<field name="PORCENTAJE" class="java.math.BigDecimal"/>
	<variable name="cantidad" class="java.math.BigDecimal" calculation="Sum">
		<variableExpression><![CDATA[$F{CANTIDAD}]]></variableExpression>
	</variable>
	<variable name="porcentaje" class="java.math.BigDecimal" calculation="Sum">
		<variableExpression><![CDATA[$F{PORCENTAJE}]]></variableExpression>
	</variable>
	<columnHeader>
		<band height="38" splitType="Stretch">
			<staticText>
				<reportElement x="0" y="0" width="572" height="20"/>
				<textElement textAlignment="Center" verticalAlignment="Middle">
					<font size="8" isBold="true"/>
				</textElement>
				<text><![CDATA[DISTRIBUCIÓN PLANTA OCUPADA]]></text>
			</staticText>
			<staticText>
				<reportElement mode="Opaque" x="341" y="26" width="80" height="12" forecolor="#000000" backcolor="#AED6FB"/>
				<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[Porcentaje]]></text>
			</staticText>
			<staticText>
				<reportElement mode="Opaque" x="141" y="26" width="100" height="12" forecolor="#000000" backcolor="#AED6FB"/>
				<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[Nivel]]></text>
			</staticText>
			<staticText>
				<reportElement mode="Opaque" x="241" y="26" width="100" height="12" forecolor="#000000" backcolor="#AED6FB"/>
				<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[Cantidad]]></text>
			</staticText>
		</band>
	</columnHeader>
	<detail>
		<band height="10" splitType="Stretch">
			<textField>
				<reportElement x="141" y="0" width="100" height="10"/>
				<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>
					<font size="8"/>
				</textElement>
				<textFieldExpression class="java.lang.String"><![CDATA[$F{DESCRIPCION}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="341" y="0" width="80" 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">
					<font size="8"/>
				</textElement>
				<textFieldExpression class="java.math.BigDecimal"><![CDATA[$F{PORCENTAJE}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement x="241" y="0" width="100" 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">
					<font size="8"/>
				</textElement>
				<textFieldExpression class="java.math.BigDecimal"><![CDATA[$F{CANTIDAD}]]></textFieldExpression>
			</textField>
		</band>
	</detail>
	<columnFooter>
		<band height="11" splitType="Stretch"/>
	</columnFooter>
	<summary>
		<band height="195" splitType="Stretch">
			<pie3DChart>
				<chart>
					<reportElement x="14" y="25" width="541" height="161"/>
					<chartTitle/>
					<chartSubtitle/>
					<chartLegend/>
				</chart>
				<pieDataset>
					<keyExpression><![CDATA[$F{DESCRIPCION}]]></keyExpression>
					<valueExpression><![CDATA[$F{PORCENTAJE}]]></valueExpression>
					<labelExpression><![CDATA[$F{DESCRIPCION} + " " + $F{PORCENTAJE} + "%"]]></labelExpression>
				</pieDataset>
				<pie3DPlot>
					<plot/>
					<itemLabel color="#000000" backgroundColor="#FFFFFF"/>
				</pie3DPlot>
			</pie3DChart>
			<staticText>
				<reportElement mode="Opaque" x="141" y="0" width="100" height="10" forecolor="#000000" backcolor="#CFCFCF"/>
				<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="8" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" pdfEncoding="Cp1252" isPdfEmbedded="false"/>
				</textElement>
				<text><![CDATA[Total]]></text>
			</staticText>
			<textField>
				<reportElement mode="Opaque" x="341" y="0" width="80" height="10" backcolor="#CFCFCF"/>
				<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">
					<font size="8"/>
				</textElement>
				<textFieldExpression class="java.math.BigDecimal"><![CDATA[$V{porcentaje}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement mode="Opaque" x="241" y="0" width="100" height="10" backcolor="#CFCFCF"/>
				<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">
					<font size="8"/>
				</textElement>
				<textFieldExpression class="java.math.BigDecimal"><![CDATA[$V{cantidad}]]></textFieldExpression>
			</textField>
		</band>
	</summary>
</jasperReport>
