<?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="th_sugestao_compra" language="groovy" pageWidth="595" pageHeight="842" whenNoDataType="NoDataSection" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="0ce52e53-f265-4609-b706-04890bcb4e91">
	<property name="ireport.zoom" value="1.9487171000000014"/>
	<property name="ireport.x" value="0"/>
	<property name="ireport.y" value="0"/>
	<style name="Linhas-Zebra" backcolor="#F5F7FA" hAlign="Left" vAlign="Middle" isBlankWhenNull="true" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false">
		<box topPadding="1" leftPadding="2" bottomPadding="1" rightPadding="2">
			<topPen lineWidth="0.5" lineColor="#D4D7DD"/>
			<leftPen lineWidth="0.5" lineColor="#D4D7DD"/>
			<bottomPen lineWidth="0.5" lineColor="#D4D7DD"/>
			<rightPen lineWidth="0.5" lineColor="#D4D7DD"/>
		</box>
		<conditionalStyle>
			<conditionExpression><![CDATA[new Boolean( $V{REPORT_COUNT}.intValue() % 2 == 0)]]></conditionExpression>
			<style mode="Opaque" backcolor="#F3F5FA"/>
		</conditionalStyle>
	</style>
	<style name="Título" hAlign="Left" vAlign="Middle" isBlankWhenNull="true" fontSize="10" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" isPdfEmbedded="false">
		<box topPadding="1" bottomPadding="1"/>
	</style>
	<style name="Filtros" hAlign="Left" vAlign="Middle" isBlankWhenNull="false" fontSize="7" isBold="false" isItalic="true" isUnderline="false" isStrikeThrough="false">
		<box topPadding="2" bottomPadding="5">
			<bottomPen lineWidth="0.75"/>
		</box>
	</style>
	<style name="Data/Hora" hAlign="Right" vAlign="Middle" isBlankWhenNull="false" fontSize="8" isBold="false" isItalic="false" isUnderline="false" isStrikeThrough="false">
		<box topPadding="1" bottomPadding="1">
			<bottomPen lineWidth="0.0"/>
		</box>
	</style>
	<style name="Apr-Clean" fill="Solid" hAlign="Center" vAlign="Middle" markup="none" isBlankWhenNull="true" fontSize="7" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" isPdfEmbedded="false">
		<box topPadding="1" leftPadding="2" bottomPadding="1" rightPadding="2">
			<pen lineWidth="0.0"/>
			<topPen lineWidth="0.5" lineColor="#000000"/>
			<leftPen lineWidth="0.0" lineStyle="Dashed"/>
			<bottomPen lineWidth="0.5" lineColor="#000000"/>
			<rightPen lineWidth="0.0" lineStyle="Dashed"/>
		</box>
	</style>
	<style name="Apr-Duplo" fill="Solid" hAlign="Center" vAlign="Middle" markup="none" isBlankWhenNull="true" fontSize="7" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" isPdfEmbedded="false">
		<box topPadding="1" leftPadding="2" bottomPadding="1" rightPadding="2">
			<pen lineWidth="0.0"/>
			<topPen lineWidth="0.5" lineColor="#000000"/>
			<leftPen lineWidth="0.5" lineColor="#000000"/>
			<bottomPen lineWidth="0.5" lineColor="#000000"/>
			<rightPen lineWidth="0.5" lineColor="#000000"/>
		</box>
	</style>
	<style name="Grupo1" hAlign="Left" vAlign="Middle" isBlankWhenNull="true" fontSize="9" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" isPdfEmbedded="false">
		<box topPadding="9" bottomPadding="3"/>
	</style>
	<style name="Totalizador" hAlign="Left" vAlign="Middle" isBlankWhenNull="false" fontSize="7" isBold="true" isItalic="false" isUnderline="false" isStrikeThrough="false" isPdfEmbedded="false">
		<box topPadding="0" leftPadding="1" bottomPadding="0" rightPadding="1">
			<pen lineWidth="0.5"/>
			<topPen lineWidth="0.5" lineColor="#D4D7DD"/>
			<leftPen lineWidth="0.5" lineColor="#D4D7DD"/>
			<bottomPen lineWidth="0.5" lineColor="#D4D7DD"/>
			<rightPen lineWidth="0.5" lineColor="#D4D7DD"/>
		</box>
	</style>
	<style name="Versão" hAlign="Left" vAlign="Middle" isBlankWhenNull="false" fontSize="7" isBold="true" isItalic="true" isUnderline="false" isStrikeThrough="false" isPdfEmbedded="false">
		<box topPadding="0" bottomPadding="1">
			<pen lineWidth="0.0"/>
			<topPen lineWidth="0.75" lineColor="#000000"/>
			<leftPen lineWidth="0.0"/>
			<bottomPen lineWidth="0.0"/>
			<rightPen lineWidth="0.0"/>
		</box>
	</style>
	<parameter name="P_EMP" class="java.lang.String">
		<defaultValueExpression><![CDATA["0"]]></defaultValueExpression>
	</parameter>
	<parameter name="P_USU" class="java.lang.String">
		<defaultValueExpression><![CDATA["0"]]></defaultValueExpression>
	</parameter>
	<parameter name="P_FORN" class="java.lang.String">
		<defaultValueExpression><![CDATA["0"]]></defaultValueExpression>
	</parameter>
	<parameter name="P_DEPP" class="java.lang.String">
		<defaultValueExpression><![CDATA["0"]]></defaultValueExpression>
	</parameter>
	<parameter name="P_SECP" class="java.lang.String">
		<defaultValueExpression><![CDATA["0"]]></defaultValueExpression>
	</parameter>
	<parameter name="P_CAT" class="java.lang.String">
		<defaultValueExpression><![CDATA["0"]]></defaultValueExpression>
	</parameter>
	<parameter name="P_SCAT" class="java.lang.String">
		<defaultValueExpression><![CDATA["0"]]></defaultValueExpression>
	</parameter>
	<parameter name="P_MARCA" class="java.lang.String">
		<defaultValueExpression><![CDATA["0"]]></defaultValueExpression>
	</parameter>
	<parameter name="P_FAM" class="java.lang.String">
		<defaultValueExpression><![CDATA["0"]]></defaultValueExpression>
	</parameter>
	<parameter name="P_PRO" class="java.lang.String">
		<defaultValueExpression><![CDATA["0"]]></defaultValueExpression>
	</parameter>
	<parameter name="P_APP" class="java.lang.String">
		<defaultValueExpression><![CDATA["0"]]></defaultValueExpression>
	</parameter>
	<parameter name="P_CONDICAO" class="java.lang.Integer">
		<defaultValueExpression><![CDATA[1]]></defaultValueExpression>
	</parameter>
	<parameter name="P_EMBALAGEM" class="java.lang.Integer">
		<defaultValueExpression><![CDATA[1]]></defaultValueExpression>
	</parameter>
	<queryString>
		<![CDATA[-- SUGESTAO DE COMPRA - versao proposta 26.10.21
-- Somente leitura. Nao altera tabelas ou views.
-- PREMISSAS PARA HOMOLOGACAO:
-- 1. est_qtpontoped e est_qtpedmin sao cadastrados na escala de P_EMBALAGEM=0.
--    Para comparar com saldos brutos da view, multiplicar por fpemult.
-- 2. est_qtmin, saldos, giro e compras pendentes ja estao na escala bruta da view.
-- 3. Ciclo atrasado: hoje > ultima entrada + frequencia, sem tolerancia adicional.
-- 4. Entrada valida: entre hoje - 4 meses e hoje (janela movel).
-- 5. Sem entrada valida ou frequencia: fallback ORIGINAL, nao dias ate fim do mes.
-- 6. Sugestao do periodo usa dias desde a entrada; e simulacao, nao soma a principal.
-- 7. Agrupamento por empresa/fornecedor evita escolher IDs arbitrarios com MAX.
-- 8. Pedido minimo e ponto de pedido usam MAX por grupo, nao soma de parametros.
-- 9. ROUND preserva a politica antiga; nao implementa lote multiplo nem CEIL.
WITH parametros AS (
    SELECT
        COALESCE(CAST($P{P_EMP} AS varchar), '') AS p_emp,
        COALESCE(CAST($P{P_FORN} AS varchar), '') AS p_forn,
        COALESCE(CAST($P{P_DEPP} AS varchar), '') AS p_depp,
        COALESCE(CAST($P{P_SECP} AS varchar), '') AS p_secp,
        COALESCE(CAST($P{P_CAT} AS varchar), '') AS p_cat,
        COALESCE(CAST($P{P_SCAT} AS varchar), '') AS p_scat,
        COALESCE(CAST($P{P_MARCA} AS varchar), '') AS p_marca,
        COALESCE(CAST($P{P_FAM} AS varchar), '') AS p_fam,
        COALESCE(CAST($P{P_PRO} AS varchar), '') AS p_pro,
        COALESCE(CAST($P{P_APP} AS varchar), '') AS p_app,
        COALESCE(CAST($P{P_USU} AS varchar), '') AS p_usu,
        COALESCE(NULLIF(CAST($P{P_EMBALAGEM} AS varchar), '')::integer, 0) AS embalagem_opcao,
        COALESCE(NULLIF(CAST($P{P_CONDICAO} AS varchar), '')::integer, 0) AS condicao
),
-- Compra recente e usada somente como fallback de exibicao/quantidade da entrada.
ultimas_compras AS (
    SELECT DISTINCT ON (com_emp_cod, com_forn_cod, com_pro_cod)
        com_emp_cod, com_forn_cod, com_pro_cod, com_nf_dtlan, com_qt
    FROM sd.vw_compra CROSS JOIN parametros p
    WHERE com_opnf_tipo = 'CO'
      AND com_nf_dtemi >= date_trunc('month', current_date) - interval '4 months'
      AND com_nf_dtemi < current_date + interval '1 day'
      AND (p.p_emp = '' OR CAST(com_emp_cod AS varchar) = p.p_emp)
      AND (p.p_forn = '' OR CAST(com_forn_cod AS varchar) = p.p_forn)
      AND (p.p_depp = '' OR CAST(com_depp_cod AS varchar) = p.p_depp)
      AND (p.p_secp = '' OR CAST(com_secp_cod AS varchar) = p.p_secp)
      AND (p.p_cat = '' OR CAST(com_cat_cod AS varchar) = p.p_cat)
      AND (p.p_scat = '' OR CAST(com_scat_cod AS varchar) = p.p_scat)
      AND (p.p_marca = '' OR CAST(com_marcas_cod AS varchar) = p.p_marca)
      AND (p.p_fam = '' OR CAST(com_fam_cod AS varchar) = p.p_fam)
      AND (p.p_pro = '' OR CAST(com_pro_cod AS varchar) = p.p_pro)
      AND (p.p_app = '' OR CAST(com_app_cod AS varchar) = p.p_app)
    ORDER BY com_emp_cod, com_forn_cod, com_pro_cod, com_nf_dtlan DESC NULLS LAST
),
-- Historico nao calcula o giro: o giro continua vindo de sd.vw_est.
ultven AS (
    SELECT fat_emp_cod, fat_forn_cod, fat_pro_cod,
        SUM(CASE WHEN fat_nf_dtemi >= date_trunc('month', current_date) - interval '3 months'
                  AND fat_nf_dtemi < date_trunc('month', current_date) - interval '2 months' THEN fat_qtmult ELSE 0 END) AS qtant3,
        SUM(CASE WHEN fat_nf_dtemi >= date_trunc('month', current_date) - interval '2 months'
                  AND fat_nf_dtemi < date_trunc('month', current_date) - interval '1 month' THEN fat_qtmult ELSE 0 END) AS qtant2,
        SUM(CASE WHEN fat_nf_dtemi >= date_trunc('month', current_date) - interval '1 month'
                  AND fat_nf_dtemi < date_trunc('month', current_date) THEN fat_qtmult ELSE 0 END) AS qtant1,
        SUM(CASE WHEN fat_nf_dtemi >= date_trunc('month', current_date)
                  AND fat_nf_dtemi < current_date + interval '1 day' THEN fat_qtmult ELSE 0 END) AS qtatual
    FROM sd.vw_fat CROSS JOIN parametros p
    WHERE fat_nf_sta <> 'EX' AND fat_opnftipo_cod IN ('VE', 'VI', 'VV')
      AND fat_nf_dtemi >= date_trunc('month', current_date) - interval '4 months'
      AND fat_nf_dtemi < current_date + interval '1 day'
      AND (p.p_emp = '' OR CAST(fat_emp_cod AS varchar) = p.p_emp)
      AND (p.p_forn = '' OR CAST(fat_forn_cod AS varchar) = p.p_forn)
      AND (p.p_depp = '' OR CAST(fat_depp_cod AS varchar) = p.p_depp)
      AND (p.p_secp = '' OR CAST(fat_secp_cod AS varchar) = p.p_secp)
      AND (p.p_cat = '' OR CAST(fat_cat_cod AS varchar) = p.p_cat)
      AND (p.p_scat = '' OR CAST(fat_scat_cod AS varchar) = p.p_scat)
      AND (p.p_marca = '' OR CAST(fat_marcas_cod AS varchar) = p.p_marca)
      AND (p.p_fam = '' OR CAST(fat_fam_cod AS varchar) = p.p_fam)
      AND (p.p_pro = '' OR CAST(fat_pro_cod AS varchar) = p.p_pro)
      AND (p.p_app = '' OR CAST(fat_app_cod AS varchar) = p.p_app)
    GROUP BY fat_emp_cod, fat_forn_cod, fat_pro_cod
),
estoque AS (
    SELECT est_emp_cod, est_forn_cod, est_pro_cod, est_pro_des, est_uve_des, est_uve_un, est_pro_ref,
        MAX(est_dtultentr)::date AS dt_entrada,
        SUM(est_qtultentr)::numeric AS qt_entrada,
        SUM(est_custocompra)::numeric AS custo,
        COALESCE(SUM(est_qt), 0)::numeric AS saldo,
        COALESCE(SUM(est_qtdisp), 0)::numeric AS disponivel,
        COALESCE(SUM(est_qtcompra), 0)::numeric AS chegar,
        COALESCE(SUM(est_girodia), 0)::numeric AS giro,
        COALESCE(SUM(est_qtmin), 0)::numeric AS minimo_cadastrado,
        COALESCE(MAX(est_qtpontoped), 0)::numeric AS pp_cadastro,
        COALESCE(MAX(est_qtpedmin), 0)::numeric AS pedido_minimo,
        SUM(est_duracao) AS est_duracao, SUM(est_duracaodisp) AS est_duracaodisp
    FROM sd.vw_est CROSS JOIN parametros p
    WHERE est_foralinha = 'N'
      AND (p.p_emp = '' OR CAST(est_emp_cod AS varchar) = p.p_emp)
      AND (p.p_forn = '' OR CAST(est_forn_cod AS varchar) = p.p_forn)
      AND (p.p_depp = '' OR CAST(est_depp_cod AS varchar) = p.p_depp)
      AND (p.p_secp = '' OR CAST(est_secp_cod AS varchar) = p.p_secp)
      AND (p.p_cat = '' OR CAST(est_cat_cod AS varchar) = p.p_cat)
      AND (p.p_scat = '' OR CAST(est_scat_cod AS varchar) = p.p_scat)
      AND (p.p_marca = '' OR CAST(est_marcas_cod AS varchar) = p.p_marca)
      AND (p.p_fam = '' OR CAST(est_fam_cod AS varchar) = p.p_fam)
      AND (p.p_pro = '' OR CAST(est_pro_cod AS varchar) = p.p_pro)
      AND (p.p_app = '' OR CAST(est_app_cod AS varchar) = p.p_app)
    GROUP BY est_emp_cod, est_forn_cod, est_pro_cod, est_pro_des, est_uve_des, est_uve_un, est_pro_ref
),
-- Mantem todos os registros fpe. Nao escolhe embalagem arbitraria com DISTINCT ON.
base AS (
    SELECT e.*, fpe.fpetipo, COALESCE(fpe.fpemult, 1)::numeric AS mult,
        fpe.fpeqtmaster AS est_qtmaster,
        GREATEST(COALESCE(f.for_freq_compra, 0), 0) AS freq,
        GREATEST(COALESCE(f.forpze, 0), 0)::numeric AS prazo,
        GREATEST(COALESCE(f.formargsegest, 0), 0)::numeric AS margem,
        c.com_nf_dtlan AS dt_compra,
        COALESCE(e.qt_entrada, c.com_qt)::numeric AS ultima_quantidade,
        COALESCE(v.qtant3, 0)::numeric AS venda3, COALESCE(v.qtant2, 0)::numeric AS venda2,
        COALESCE(v.qtant1, 0)::numeric AS venda1, COALESCE(v.qtatual, 0)::numeric AS venda_atual
    FROM estoque e
    LEFT JOIN fpe ON fpe.fpeempparcod = e.est_emp_cod
                AND fpe.fpeforparcod = e.est_forn_cod AND fpe.fpeprocod = e.est_pro_cod
    LEFT JOIN forn f ON f.forparcod = COALESCE(fpe.fpeforparcod, e.est_forn_cod)
    LEFT JOIN ultimas_compras c ON c.com_emp_cod = e.est_emp_cod
        AND c.com_forn_cod = e.est_forn_cod AND c.com_pro_cod = e.est_pro_cod
    LEFT JOIN ultven v ON v.fat_emp_cod = e.est_emp_cod
        AND v.fat_forn_cod = e.est_forn_cod AND v.fat_pro_cod = e.est_pro_cod
),
referencias AS (
    SELECT b.*,
        (freq > 0 AND dt_entrada BETWEEN (current_date - interval '4 months')::date AND current_date) AS ciclo_valido,
        CASE WHEN freq > 0 AND dt_entrada IS NOT NULL THEN dt_entrada + freq END AS proxima_referencia,
        CASE WHEN dt_entrada IS NOT NULL THEN current_date - dt_entrada END AS dias_decorridos,
        -- O minimo estimado legado fica separado do minimo usado no PP virtual.
        CASE WHEN minimo_cadastrado > 0 THEN minimo_cadastrado ELSE prazo * giro END AS minimo_legado,
        -- PP virtual usa minimo CADASTRADO para nao contar prazo duas vezes.
        CASE WHEN pp_cadastro > 0 THEN pp_cadastro * mult
             ELSE giro * (prazo + margem) + GREATEST(minimo_cadastrado, 0) END AS pp_interno,
        CASE WHEN pp_cadastro > 0 THEN 'CADASTRADO' ELSE 'VIRTUAL' END AS origem_pp,
        GREATEST(pedido_minimo, 0) * mult AS pedmin_interno
    FROM base b
),
alvos AS (
    SELECT r.*,
        CASE WHEN freq <= 0 THEN 'SEM FREQUENCIA'
             WHEN dt_entrada IS NULL THEN 'SEM DATA DE ENTRADA'
             WHEN dt_entrada > current_date THEN 'DATA FUTURA'
             WHEN NOT ciclo_valido THEN 'ENTRADA FORA DOS 4 MESES'
             WHEN current_date > proxima_referencia THEN 'ATRASADO'
             WHEN current_date = proxima_referencia THEN 'VENCE HOJE'
             ELSE 'EM DIA' END AS situacao_ciclo,
        CASE WHEN ciclo_valido THEN GREATEST(current_date - proxima_referencia, 0) END AS dias_atraso,
        -- Estoque ideal legado e preservado como coluna de conferencia.
        minimo_legado + margem * giro AS ideal_legado,
        CASE WHEN ciclo_valido THEN giro * freq + minimo_legado
             ELSE minimo_legado + margem * giro END AS alvo_ciclo,
        CASE WHEN ciclo_valido AND current_date > proxima_referencia
             THEN giro * dias_decorridos + minimo_legado END AS alvo_periodo
    FROM referencias r
),
necessidades AS (
    SELECT a.*,
        alvo_ciclo - disponivel - chegar AS necessidade_ciclo,
        alvo_periodo - disponivel - chegar AS necessidade_periodo,
        (disponivel + chegar <= pp_interno) AS compra_autorizada
    FROM alvos a
),
sugestoes AS (
    SELECT n.*,
        -- Minimo nao cria compra se necessidade for zero ou negativa.
        CASE WHEN NOT compra_autorizada OR necessidade_ciclo <= 0 THEN 0::numeric
             ELSE GREATEST(necessidade_ciclo, pedmin_interno) END AS sugestao_ciclo,
        CASE WHEN necessidade_periodo IS NULL THEN NULL::numeric
             WHEN NOT compra_autorizada OR necessidade_periodo <= 0 THEN 0::numeric
             ELSE GREATEST(necessidade_periodo, pedmin_interno) END AS sugestao_periodo,
        GREATEST(-necessidade_ciclo, 0) AS excesso_ciclo,
        CASE WHEN NOT compra_autorizada THEN 'ACIMA DO PONTO DE PEDIDO'
             WHEN necessidade_ciclo <= 0 THEN 'SEM NECESSIDADE LIQUIDA'
             WHEN pedmin_interno > necessidade_ciclo THEN 'PEDIDO MINIMO APLICADO'
             ELSE 'NECESSIDADE DO CICLO' END AS motivo_sugestao
    FROM necessidades n
),
-- Conversao centralizada; preserva os sentidos de quantidade/custo da SQL original.
exibicao AS (
    SELECT s.*, p.embalagem_opcao, p.condicao,
        CASE WHEN p.embalagem_opcao = 1 THEN 1::numeric ELSE mult END AS divisor,
        ROUND(CASE WHEN p.embalagem_opcao = 1 THEN custo ELSE custo * mult END, 4) AS custo_exibido
    FROM sugestoes s CROSS JOIN parametros p
),
cabecalho AS (
    SELECT 'Sugestão de Compra'::text AS relatorio,
        to_char(now(), 'dd/mm/yyyy HH24:MI') || ' (' ||
          COALESCE((SELECT usulogin FROM usu WHERE CAST(usufunparcod AS varchar) = p.p_usu), '...') || ')' AS dtimpr,
        'th_sugestao_compra v26.10.26 - proposta para homologacao'::text AS versao,
        '[Empresa: ' || COALESCE((SELECT parfan FROM par WHERE CAST(parcod AS varchar) = p.p_emp), 'TODAS') || ']'
        || ', [Fornecedor: ' || COALESCE((SELECT parfan FROM par WHERE CAST(parcod AS varchar) = p.p_forn), 'TODOS') || ']'
        || CASE WHEN p.p_depp <> '' THEN ', [Departamento: ' || p.p_depp || ']' ELSE '' END
        || CASE WHEN p.p_secp <> '' THEN ', [Secao: ' || p.p_secp || ']' ELSE '' END
        || CASE WHEN p.p_cat <> '' THEN ', [Categoria: ' || p.p_cat || ']' ELSE '' END
        || CASE WHEN p.p_scat <> '' THEN ', [Subcategoria: ' || p.p_scat || ']' ELSE '' END
        || CASE WHEN p.p_marca <> '' THEN ', [Marca: ' || p.p_marca || ']' ELSE '' END
        || CASE WHEN p.p_fam <> '' THEN ', [Familia: ' || p.p_fam || ']' ELSE '' END
        || CASE WHEN p.p_pro <> '' THEN ', [Produto: ' || p.p_pro || ']' ELSE '' END
        || CASE WHEN p.p_app <> '' THEN ', [Aplicacao: ' || p.p_app || ']' ELSE '' END
        || CASE WHEN p.embalagem_opcao = 1 THEN ', [Embalagem Alternativa]' ELSE ', [Embalagem Principal]' END AS filtro
    FROM parametros p
)
SELECT
    c.relatorio, c.dtimpr, c.versao, c.filtro,
    x.est_emp_cod, x.est_forn_cod, x.fpetipo,
    x.est_pro_cod, x.est_pro_des || ' (Cód: ' || x.est_pro_cod || ')' AS est_pro_des,
    ROUND(x.mult) || 'X' || x.est_uve_des AS embalagem,
    COALESCE(x.dt_entrada, x.dt_compra::date) AS est_dtultentr,
    x.dt_entrada AS dt_referencia_ciclo,
    ROUND(x.custo_exibido * ROUND(x.sugestao_ciclo / x.divisor), 3) AS total_est_custocompra,
    ROUND(x.ultima_quantidade / x.divisor) AS est_qtultentr,
    x.custo_exibido AS est_custocompra,
    to_char(date_trunc('month', current_date) - interval '3 months', 'TMMon') AS des_mes_ant3,
    ROUND(x.venda3 / x.divisor) AS qtant3,
    to_char(date_trunc('month', current_date) - interval '2 months', 'TMMon') AS des_mes_ant2,
    ROUND(x.venda2 / x.divisor) AS qtant2,
    to_char(date_trunc('month', current_date) - interval '1 month', 'TMMon') AS des_mes_ant1,
    ROUND(x.venda1 / x.divisor) AS qtant1,
    to_char(current_date, 'TMMon') AS des_mes_atual,
    ROUND(x.venda_atual / x.divisor) AS qtatual,
    ROUND(x.saldo / x.divisor) AS est_qt,
    ROUND(x.disponivel / x.divisor) AS est_qtdisp,
    ROUND(x.giro / x.divisor, 4) AS est_girodia,
    ROUND(x.giro * 30 / x.divisor, 4) AS est_giromes,
    x.est_duracao, x.est_duracaodisp,
    ROUND(x.minimo_legado / x.divisor) AS qtestmin,
    CASE WHEN x.minimo_cadastrado > 0 THEN 'CADASTRADO' ELSE 'ESTIMADO LEGADO' END AS origem_minimo,
    ROUND(x.ideal_legado / x.divisor) AS qtideal,
    ROUND(x.alvo_ciclo / x.divisor, 3) AS estoque_alvo_ciclo,
    x.freq AS freq_compra,
    CASE WHEN x.ciclo_valido THEN x.freq END AS dias_cobertura,
    x.dias_decorridos, x.proxima_referencia, x.dias_atraso, x.situacao_ciclo,
    CASE WHEN x.ciclo_valido THEN 'FREQUENCIA' ELSE 'FORMULA ORIGINAL' END AS regra_calculo,
    x.prazo AS prazo_entrega, x.margem AS margem_entrega,
    ROUND(x.pp_interno / x.divisor, 3) AS est_qtpontoped,
    x.origem_pp,
    ROUND(x.pedmin_interno / x.divisor, 3) AS est_qtpedmin,
    -- Necessidades exibidas na MESMA escala dos saldos e sugestoes.
    ROUND(x.necessidade_ciclo / x.divisor, 3) AS necessidade_bruta,
    ROUND(x.necessidade_periodo / x.divisor, 3) AS necessidade_periodo,
    ROUND(x.sugestao_ciclo / x.divisor) AS qtsug,
    ROUND(x.sugestao_periodo / x.divisor) AS qtsug_periodo,
    ROUND(x.excesso_ciclo / x.divisor) AS qtexesso,
    x.motivo_sugestao,
    ROUND(x.custo_exibido * ROUND(x.sugestao_periodo / x.divisor), 3) AS total_periodo,
    x.est_qtmaster, ROUND(x.chegar / x.divisor, 1) AS est_qtchegar, x.est_pro_ref
FROM exibicao x CROSS JOIN cabecalho c
WHERE x.condicao NOT IN (2, 3)
   OR (x.condicao = 2 AND (ROUND(x.sugestao_ciclo / x.divisor) > 0 OR ROUND(x.sugestao_periodo / x.divisor) > 0))
   OR (x.condicao = 3 AND ROUND(x.excesso_ciclo / x.divisor) > 0)
ORDER BY x.est_pro_des, x.est_emp_cod, x.est_forn_cod, x.fpetipo;]]>
	</queryString>
	<field name="relatorio" class="java.lang.String"/>
	<field name="dtimpr" class="java.lang.String"/>
	<field name="versao" class="java.lang.String"/>
	<field name="filtro" class="java.lang.String"/>
	<field name="est_emp_cod" class="java.lang.Integer"/>
	<field name="est_forn_cod" class="java.lang.Integer"/>
	<field name="fpetipo" class="java.lang.String"/>
	<field name="est_pro_cod" class="java.lang.Integer"/>
	<field name="est_pro_des" class="java.lang.String"/>
	<field name="embalagem" class="java.lang.String"/>
	<field name="est_dtultentr" class="java.sql.Date"/>
	<field name="dt_referencia_ciclo" class="java.sql.Date"/>
	<field name="total_est_custocompra" class="java.math.BigDecimal"/>
	<field name="est_qtultentr" class="java.math.BigDecimal"/>
	<field name="est_custocompra" class="java.math.BigDecimal"/>
	<field name="des_mes_ant3" class="java.lang.String"/>
	<field name="qtant3" class="java.math.BigDecimal"/>
	<field name="des_mes_ant2" class="java.lang.String"/>
	<field name="qtant2" class="java.math.BigDecimal"/>
	<field name="des_mes_ant1" class="java.lang.String"/>
	<field name="qtant1" class="java.math.BigDecimal"/>
	<field name="des_mes_atual" class="java.lang.String"/>
	<field name="qtatual" class="java.math.BigDecimal"/>
	<field name="est_qt" class="java.math.BigDecimal"/>
	<field name="est_qtdisp" class="java.math.BigDecimal"/>
	<field name="est_girodia" class="java.math.BigDecimal"/>
	<field name="est_giromes" class="java.math.BigDecimal"/>
	<field name="est_duracao" class="java.math.BigDecimal"/>
	<field name="est_duracaodisp" class="java.math.BigDecimal"/>
	<field name="qtestmin" class="java.math.BigDecimal"/>
	<field name="origem_minimo" class="java.lang.String"/>
	<field name="qtideal" class="java.math.BigDecimal"/>
	<field name="estoque_alvo_ciclo" class="java.math.BigDecimal"/>
	<field name="freq_compra" class="java.lang.Integer"/>
	<field name="dias_cobertura" class="java.lang.Integer"/>
	<field name="dias_decorridos" class="java.lang.Integer"/>
	<field name="proxima_referencia" class="java.sql.Date"/>
	<field name="dias_atraso" class="java.lang.Integer"/>
	<field name="situacao_ciclo" class="java.lang.String"/>
	<field name="regra_calculo" class="java.lang.String"/>
	<field name="prazo_entrega" class="java.math.BigDecimal"/>
	<field name="margem_entrega" class="java.math.BigDecimal"/>
	<field name="est_qtpontoped" class="java.math.BigDecimal"/>
	<field name="origem_pp" class="java.lang.String"/>
	<field name="est_qtpedmin" class="java.math.BigDecimal"/>
	<field name="necessidade_bruta" class="java.math.BigDecimal"/>
	<field name="necessidade_periodo" class="java.math.BigDecimal"/>
	<field name="qtsug" class="java.math.BigDecimal"/>
	<field name="qtsug_periodo" class="java.math.BigDecimal"/>
	<field name="qtexesso" class="java.math.BigDecimal"/>
	<field name="motivo_sugestao" class="java.lang.String"/>
	<field name="total_periodo" class="java.math.BigDecimal"/>
	<field name="est_qtmaster" class="java.lang.Integer"/>
	<field name="est_qtchegar" class="java.math.BigDecimal"/>
	<field name="est_pro_ref" class="java.lang.String"/>
	<variable name="est_pro_cod_1" class="java.lang.Integer" calculation="DistinctCount">
		<variableExpression><![CDATA[$F{est_pro_cod}]]></variableExpression>
	</variable>
	<variable name="total_est_custocompra_1" class="java.math.BigDecimal" calculation="Sum">
		<variableExpression><![CDATA[$F{total_est_custocompra}]]></variableExpression>
	</variable>
	<background>
		<band splitType="Stretch"/>
	</background>
	<pageHeader>
		<band height="80" splitType="Stretch">
			<textField>
				<reportElement style="Data/Hora" x="374" y="0" width="180" height="16" uuid="0ddc2e72-ea76-4a75-a5de-7529b458f035"/>
				<box leftPadding="3" rightPadding="2"/>
				<textElement textAlignment="Right" verticalAlignment="Middle">
					<font size="11"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{dtimpr}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement style="Título" x="0" y="0" width="374" height="16" uuid="214c640c-8c6f-426e-bb48-caf4e655ae03"/>
				<box leftPadding="1" rightPadding="1"/>
				<textElement verticalAlignment="Middle">
					<font size="11" isBold="true"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{relatorio}]]></textFieldExpression>
			</textField>
			<staticText>
				<reportElement x="0" y="35" width="554" height="45" uuid="9c2c8eca-6901-4133-8097-cb262a56cba9"/>
				<textElement verticalAlignment="Middle" markup="html">
					<font size="6" isItalic="true"/>
				</textElement>
				<text><![CDATA[* Estoque mínimo: valor cadastrado; se não informado, Prazo de entrega × Giro diário.
* Ponto de pedido: valor cadastrado; se não informado, Giro diário × (Prazo + Margem de entrega) + Mínimo cadastrado.
* Sugestão de compra: (Giro diário × Frequência) + Mínimo − Disponível − A chegar, respeitando o ponto de pedido e o pedido mínimo.
* Duração do estoque: Estoque atual ÷ Giro diário, em dias.
* Pedido mínimo: menor quantidade de uma compra necessária; não gera compra sem necessidade.]]></text>
			</staticText>
			<textField isStretchWithOverflow="true">
				<reportElement style="Filtros" stretchType="RelativeToBandHeight" x="0" y="16" width="554" height="15" uuid="c7231fd2-5106-495d-9631-2c9cd05244fd"/>
				<box leftPadding="1" rightPadding="1"/>
				<textElement verticalAlignment="Middle" markup="html">
					<font size="6"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{filtro}]]></textFieldExpression>
			</textField>
		</band>
	</pageHeader>
	<columnHeader>
		<band height="21" splitType="Stretch">
			<staticText>
				<reportElement style="Apr-Duplo" x="168" y="10" width="45" height="11" uuid="37aa4b80-508a-4fd8-ae93-e224e04a24b7"/>
				<textElement verticalAlignment="Middle">
					<font size="6"/>
				</textElement>
				<text><![CDATA[Data]]></text>
			</staticText>
			<staticText>
				<reportElement style="Apr-Duplo" x="245" y="10" width="46" height="11" uuid="751dacf0-0f9a-48bd-a563-66cf79d8a32b"/>
				<textElement verticalAlignment="Middle">
					<font size="6"/>
				</textElement>
				<text><![CDATA[Custo Compra]]></text>
			</staticText>
			<staticText>
				<reportElement style="Apr-Duplo" x="213" y="10" width="32" height="11" uuid="9042db23-aa79-4ce6-b23b-066e8bfb25dc"/>
				<textElement verticalAlignment="Middle">
					<font size="6"/>
				</textElement>
				<text><![CDATA[Qtde]]></text>
			</staticText>
			<staticText>
				<reportElement style="Apr-Duplo" x="0" y="0" width="140" height="21" uuid="ac4f511f-54ff-4784-afea-f635cdff1725"/>
				<textElement verticalAlignment="Middle">
					<font size="6"/>
				</textElement>
				<text><![CDATA[Produto]]></text>
			</staticText>
			<staticText>
				<reportElement style="Apr-Duplo" x="401" y="0" width="29" height="21" uuid="109b8200-fd27-4eac-8ee8-fe26615955ba"/>
				<textElement verticalAlignment="Middle" markup="html">
					<font size="6"/>
				</textElement>
				<text><![CDATA[Duração Estoque]]></text>
			</staticText>
			<staticText>
				<reportElement style="Apr-Duplo" x="345" y="0" width="29" height="21" uuid="ff669b33-601f-4b5b-89d8-b890f811eaaa"/>
				<textElement verticalAlignment="Middle">
					<font size="6"/>
				</textElement>
				<text><![CDATA[Estoque]]></text>
			</staticText>
			<staticText>
				<reportElement style="Apr-Duplo" x="374" y="0" width="27" height="21" uuid="d9d1ca6d-7c96-48fa-8a1c-f71ebb9b4f88"/>
				<box topPadding="1" leftPadding="2" bottomPadding="1" rightPadding="2">
					<rightPen lineWidth="0.5"/>
				</box>
				<textElement verticalAlignment="Middle">
					<font size="6"/>
				</textElement>
				<text><![CDATA[Qt. Chegar]]></text>
			</staticText>
			<staticText>
				<reportElement style="Apr-Duplo" x="488" y="0" width="32" height="21" uuid="c1a53e63-c334-46a4-b5ae-ffe73815dc19"/>
				<box topPadding="1" leftPadding="2" bottomPadding="1" rightPadding="2">
					<rightPen lineWidth="0.0"/>
				</box>
				<textElement verticalAlignment="Middle">
					<font size="6"/>
				</textElement>
				<text><![CDATA[Sugestão]]></text>
			</staticText>
			<staticText>
				<reportElement style="Apr-Duplo" x="316" y="0" width="29" height="21" uuid="aed8ecdc-b503-4a83-a1e8-ec5ae35c0f33"/>
				<textElement verticalAlignment="Middle" markup="html">
					<font size="6"/>
				</textElement>
				<text><![CDATA[Estoque Mínimo]]></text>
			</staticText>
			<staticText>
				<reportElement style="Apr-Duplo" x="291" y="10" width="25" height="11" uuid="6dbf8c8e-12cf-413b-be28-a7d644b1cf9e"/>
				<box topPadding="1" leftPadding="2" bottomPadding="1" rightPadding="2">
					<rightPen lineWidth="0.5"/>
				</box>
				<textElement verticalAlignment="Middle">
					<font size="6"/>
				</textElement>
				<text><![CDATA[Dias]]></text>
			</staticText>
			<staticText>
				<reportElement style="Apr-Duplo" x="140" y="0" width="28" height="21" uuid="941384c0-ebf8-4b68-884c-775779e2287c"/>
				<textElement verticalAlignment="Middle">
					<font size="6"/>
				</textElement>
				<text><![CDATA[Emb]]></text>
			</staticText>
			<staticText>
				<reportElement style="Apr-Duplo" x="520" y="0" width="34" height="21" uuid="6486347d-d790-449d-a046-9f135121c953"/>
				<textElement textAlignment="Center" verticalAlignment="Middle" markup="html">
					<font size="6" isBold="true" isItalic="true"/>
				</textElement>
				<text><![CDATA[Valor Total R$]]></text>
			</staticText>
			<staticText>
				<reportElement style="Apr-Duplo" x="430" y="0" width="29" height="21" uuid="83a763ce-12ba-4f23-a48a-ce92e05f1a98"/>
				<textElement verticalAlignment="Middle" markup="html">
					<font size="6"/>
				</textElement>
				<text><![CDATA[Pt. de pedido]]></text>
			</staticText>
			<staticText>
				<reportElement style="Apr-Duplo" x="459" y="0" width="29" height="21" uuid="c6328d19-f19b-4a25-8c0b-ad2c834f3ce6"/>
				<textElement verticalAlignment="Middle" markup="html">
					<font size="6"/>
				</textElement>
				<text><![CDATA[Ped. mínimo]]></text>
			</staticText>
			<staticText>
				<reportElement style="Apr-Duplo" x="168" y="0" width="148" height="10" uuid="18b82db4-a45e-408f-8c8e-71910cd8fc70"/>
				<textElement verticalAlignment="Middle">
					<font size="6"/>
				</textElement>
				<text><![CDATA[Últ.Compra]]></text>
			</staticText>
		</band>
	</columnHeader>
	<detail>
		<band height="11" splitType="Prevent">
			<textField isStretchWithOverflow="true" isBlankWhenNull="true">
				<reportElement style="Linhas-Zebra" stretchType="RelativeToBandHeight" x="0" y="0" width="140" height="11" isPrintWhenDetailOverflows="true" uuid="b90f6ab7-f7bb-4521-bb2a-101f3a559b8f"/>
				<textElement textAlignment="Left" verticalAlignment="Middle" markup="none">
					<font size="6"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{est_pro_des}]]></textFieldExpression>
			</textField>
			<textField pattern="#,##0.00" isBlankWhenNull="true">
				<reportElement style="Linhas-Zebra" stretchType="RelativeToBandHeight" x="245" y="0" width="46" height="11" isPrintWhenDetailOverflows="true" uuid="949f8108-7570-4c57-8c24-205c07312ffa"/>
				<textElement textAlignment="Right" verticalAlignment="Middle" markup="none">
					<font size="6"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{est_custocompra}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" pattern="d/M/yyyy" isBlankWhenNull="true">
				<reportElement style="Linhas-Zebra" stretchType="RelativeToBandHeight" x="168" y="0" width="45" height="11" isPrintWhenDetailOverflows="true" uuid="ac71343a-0656-4d50-be2b-483a52dc1f35"/>
				<textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
					<font size="6"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{est_dtultentr}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" pattern="#,##0" isBlankWhenNull="true">
				<reportElement style="Linhas-Zebra" stretchType="RelativeToBandHeight" x="213" y="0" width="32" height="11" isPrintWhenDetailOverflows="true" uuid="df5f6d8e-dbc1-4f35-878a-0df5b9762fbc"/>
				<textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
					<font size="6"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{est_qtultentr}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" pattern="#,##0" isBlankWhenNull="true">
				<reportElement style="Linhas-Zebra" stretchType="RelativeToBandHeight" x="401" y="0" width="29" height="11" isPrintWhenDetailOverflows="true" uuid="d6bdff0d-3a5e-421c-aad3-8a83a12f44b2"/>
				<textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
					<font size="6"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{est_duracaodisp}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" pattern="#,##0" isBlankWhenNull="true">
				<reportElement style="Linhas-Zebra" stretchType="RelativeToBandHeight" x="345" y="0" width="29" height="11" isPrintWhenDetailOverflows="true" uuid="97e3d7be-9d25-4c2f-8fc4-013736e2a656"/>
				<textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
					<font size="6"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{est_qtdisp}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" pattern="#,##0" isBlankWhenNull="true">
				<reportElement style="Linhas-Zebra" stretchType="RelativeToBandHeight" x="291" y="0" width="25" height="11" isPrintWhenDetailOverflows="true" uuid="399ad97e-d0f1-485a-b773-a6bd015bf921"/>
				<textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
					<font size="6"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{dias_decorridos}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" pattern="#,##0" isBlankWhenNull="true">
				<reportElement style="Linhas-Zebra" stretchType="RelativeToBandHeight" x="488" y="0" width="32" height="11" isPrintWhenDetailOverflows="true" uuid="451dfe04-2a37-442b-86eb-b27ff8b0f8c3"/>
				<textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
					<font size="6" isBold="true"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{qtsug}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" pattern="#,##0" isBlankWhenNull="true">
				<reportElement style="Linhas-Zebra" stretchType="RelativeToBandHeight" x="316" y="0" width="29" height="11" isPrintWhenDetailOverflows="true" uuid="f2e1c9c0-3ac5-4c98-8c58-40e6f6effaa2"/>
				<textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
					<font size="6"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{qtestmin}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" pattern="#,##0" isBlankWhenNull="true">
				<reportElement style="Linhas-Zebra" stretchType="RelativeToBandHeight" x="374" y="0" width="27" height="11" isPrintWhenDetailOverflows="true" uuid="80378648-3111-4709-a653-75087cdcb0b9"/>
				<textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
					<font size="6"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{est_qtchegar}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" isBlankWhenNull="true">
				<reportElement style="Linhas-Zebra" stretchType="RelativeToBandHeight" x="140" y="0" width="28" height="11" isPrintWhenDetailOverflows="true" uuid="df2fd976-80bd-4401-b770-25fd58b04ad9"/>
				<textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
					<font size="6"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{embalagem}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" pattern="#,##0.00" isBlankWhenNull="true">
				<reportElement style="Linhas-Zebra" stretchType="RelativeToBandHeight" x="520" y="0" width="34" height="11" isPrintWhenDetailOverflows="true" uuid="b8802135-3e43-4ce0-a4d6-ba522699bfb0"/>
				<textElement textAlignment="Right" verticalAlignment="Middle" markup="none">
					<font size="6" isBold="true"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{total_est_custocompra}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" pattern="#,##0" isBlankWhenNull="true">
				<reportElement style="Linhas-Zebra" stretchType="RelativeToBandHeight" x="430" y="0" width="29" height="11" isPrintWhenDetailOverflows="true" uuid="c63fe126-24d3-4a40-b0c1-c94ec5586a93"/>
				<textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
					<font size="6"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{est_qtpontoped}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" pattern="#,##0" isBlankWhenNull="true">
				<reportElement style="Linhas-Zebra" stretchType="RelativeToBandHeight" x="459" y="0" width="29" height="11" isPrintWhenDetailOverflows="true" uuid="10b0b29c-de6f-4f64-89e7-44c07553eb52"/>
				<textElement textAlignment="Center" verticalAlignment="Middle" markup="none">
					<font size="6"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{est_qtpedmin}]]></textFieldExpression>
			</textField>
		</band>
	</detail>
	<pageFooter>
		<band height="20" splitType="Stretch">
			<textField>
				<reportElement style="Versão" x="436" y="5" width="61" height="12" uuid="76b5a34f-9804-43fb-b036-b6fc7d1ed908"/>
				<box leftPadding="3" rightPadding="2"/>
				<textElement textAlignment="Right">
					<font size="6"/>
				</textElement>
				<textFieldExpression><![CDATA["Página "+$V{PAGE_NUMBER}+" de"]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement style="Versão" x="0" y="5" width="436" height="12" uuid="8cd40148-70ae-4d77-8c97-2f7bb2ef5ed5"/>
				<box leftPadding="3" rightPadding="2"/>
				<textElement verticalAlignment="Middle">
					<font size="6" isItalic="true"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{versao}]]></textFieldExpression>
			</textField>
			<textField evaluationTime="Report">
				<reportElement style="Versão" x="497" y="5" width="58" height="12" uuid="78ae06e4-703b-463f-8f73-f384c75f09be"/>
				<box leftPadding="3" rightPadding="2"/>
				<textElement>
					<font size="6"/>
				</textElement>
				<textFieldExpression><![CDATA[" " + $V{PAGE_NUMBER}]]></textFieldExpression>
			</textField>
		</band>
	</pageFooter>
	<summary>
		<band height="23" splitType="Stretch">
			<textField>
				<reportElement style="Totalizador" x="0" y="5" width="520" height="12" uuid="fe414ebc-b5ec-45ee-ba75-bbbe56c993bb"/>
				<textElement textAlignment="Left" verticalAlignment="Middle" markup="none">
					<font size="6" isBold="true"/>
				</textElement>
				<textFieldExpression><![CDATA["Número de registros: "+$V{est_pro_cod_1}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" pattern="#,##0.00" isBlankWhenNull="true">
				<reportElement style="Totalizador" stretchType="RelativeToBandHeight" x="520" y="5" width="34" height="12" isPrintWhenDetailOverflows="true" uuid="c770a0f5-9930-4461-bb03-8611032c84eb"/>
				<textElement textAlignment="Right" verticalAlignment="Middle" markup="none">
					<font size="5"/>
				</textElement>
				<textFieldExpression><![CDATA[$V{total_est_custocompra_1}]]></textFieldExpression>
			</textField>
		</band>
	</summary>
	<noData>
		<band height="50">
			<staticText>
				<reportElement x="42" y="0" width="478" height="50" uuid="938739a9-5161-40d8-870f-762584691d7a"/>
				<textElement textAlignment="Center">
					<font size="14" isBold="true"/>
				</textElement>
				<text><![CDATA[Este relatório não possui informações referente aos filtros informados. Tente usar outros filtros.]]></text>
			</staticText>
		</band>
	</noData>
</jasperReport>
