<?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="RelatorioTrechoVendido" pageWidth="595" pageHeight="842" whenNoDataType="NoDataSection" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="41ab2d20-dc50-4e37-b78d-20e600a984d4">
	<property name="ireport.zoom" value="1.5"/>
	<property name="ireport.x" value="0"/>
	<property name="ireport.y" value="118"/>
	<parameter name="DATA_INICIO" class="java.sql.Timestamp"/>
	<parameter name="DATA_FINAL" class="java.sql.Timestamp"/>
	<parameter name="NOMBEMPRESA" class="java.lang.String">
		<parameterDescription><![CDATA[]]></parameterDescription>
		<defaultValueExpression><![CDATA[]]></defaultValueExpression>
	</parameter>
	<parameter name="NOW" class="java.util.Date"/>
	<parameter name="NOMBEMPRESA_SEARCH" class="java.lang.String"/>
	<parameter name="PUNTOVENTA_ID" class="java.lang.String"/>
	<parameter name="PUNTOVENTA" class="java.lang.String"/>
	<queryString>
		<![CDATA[SELECT
    origem.DESCPARADA                 AS ORIGEM,
    destino.DESCPARADA                AS DESTINO,
    TO_CHAR(cor.FECHORSALIDA ,'HH24:MI') AS FECHORSALIDA,
    e.NOMBEMPRESA                     AS NOMBEMPRESA,
  SUM (CASE
            WHEN c.motivocancelacion_id is null
	then 1
	else -1
	end *
	c.PRECIOPAGADO)              AS SOMA,
    COUNT(
        CASE
            WHEN c.PRECIOPAGADO = 0
             OR c.PRECIOPAGADO IS NULL AND c.motivocancelacion_id  is null
            THEN 1
            ELSE NULL
        END) AS LIVRE,
    COUNT(
        CASE
            WHEN c.PRECIOPAGADO <> 0 AND c.motivocancelacion_id  is null
            THEN 1
            ELSE NULL
        END) AS VENDA
FROM
    CAJA c
LEFT JOIN PARADA origem
ON
    (
        c.ORIGEN_ID = origem.PARADA_ID
    )
LEFT JOIN PARADA destino
ON
    (
        c.DESTINO_ID = destino.PARADA_ID
    )
LEFT JOIN CORRIDA cor
ON
    (
        c.CORRIDA_ID = cor.CORRIDA_ID
    AND c.FECCORRIDA = cor.FECCORRIDA
    )

LEFT JOIN MARCA m
ON
    (
        m.marca_id = c.marca_id
    )
LEFT JOIN EMPRESA e
ON
    (
        e.EMPRESA_ID = m.empresa_id
    )
WHERE
    c.FECHORVENTA BETWEEN $P{DATA_INICIO} AND $P{DATA_FINAL}

    AND ((c.PUNTOVENTA_ID IN ( $P!{PUNTOVENTA_ID} )) OR ($P{PUNTOVENTA_ID} = '-1'))

    AND e.NOMBEMPRESA LIKE $P{NOMBEMPRESA_SEARCH}
    AND c.INDREIMPRESION = 0
GROUP BY
    origem.DESCPARADA ,
    destino.DESCPARADA ,
    TO_CHAR(cor.FECHORSALIDA,'HH24:MI'),
    e.NOMBEMPRESA
ORDER BY
    origem.DESCPARADA,
    destino.DESCPARADA,
    TO_CHAR(cor.FECHORSALIDA,'HH24:MI')]]>
	</queryString>
	<field name="ORIGEM" class="java.lang.String"/>
	<field name="DESTINO" class="java.lang.String"/>
	<field name="FECHORSALIDA" class="java.lang.String"/>
	<field name="NOMBEMPRESA" class="java.lang.String"/>
	<field name="SOMA" class="java.math.BigDecimal"/>
	<field name="LIVRE" class="java.math.BigDecimal"/>
	<field name="VENDA" class="java.math.BigDecimal"/>
	<variable name="SOMA_TRECHO" class="java.math.BigDecimal" resetType="Group" resetGroup="ORIGEM_DESTINO" calculation="Sum">
		<variableExpression><![CDATA[$F{SOMA}]]></variableExpression>
	</variable>
	<variable name="VENDA_1" class="java.math.BigDecimal" resetType="Group" resetGroup="ORIGEM_DESTINO" calculation="Sum">
		<variableExpression><![CDATA[$F{VENDA}]]></variableExpression>
	</variable>
	<variable name="LIVRE_1" class="java.math.BigDecimal" resetType="Group" resetGroup="ORIGEM_DESTINO" calculation="Sum">
		<variableExpression><![CDATA[$F{LIVRE}]]></variableExpression>
	</variable>
	<variable name="TOTAL_V_L" class="java.math.BigDecimal" calculation="Sum">
		<variableExpression><![CDATA[($V{VENDA_1}.add($V{LIVRE_1}))]]></variableExpression>
		<initialValueExpression><![CDATA[BigDecimal.ZERO]]></initialValueExpression>
	</variable>
	<variable name="VENDA_2" class="java.math.BigDecimal" calculation="Sum">
		<variableExpression><![CDATA[$F{VENDA}]]></variableExpression>
	</variable>
	<variable name="LIVRE_2" class="java.math.BigDecimal" calculation="Sum">
		<variableExpression><![CDATA[$F{LIVRE}]]></variableExpression>
	</variable>
	<variable name="SOMA_1" class="java.math.BigDecimal" calculation="Sum">
		<variableExpression><![CDATA[$F{SOMA}]]></variableExpression>
	</variable>
	<group name="ORIGEM_DESTINO">
		<groupExpression><![CDATA[$F{ORIGEM} + $F{DESTINO}]]></groupExpression>
		<groupHeader>
			<band height="22">
				<textField>
					<reportElement uuid="f69c0e2b-192d-4e29-89a2-cc946586e4fb" x="0" y="1" width="346" height="20"/>
					<textElement>
						<font size="7"/>
					</textElement>
					<textFieldExpression><![CDATA[$F{ORIGEM} + "  " + $R{msg.a}  + "  " + $F{DESTINO}]]></textFieldExpression>
				</textField>
				<line>
					<reportElement uuid="2722767b-42a9-43f4-8530-a3843acd50f5" x="0" y="21" width="555" height="1"/>
				</line>
				<line>
					<reportElement uuid="86c9cbad-4985-468c-94b3-df769598cbfc" x="0" y="0" width="555" height="1"/>
				</line>
				<textField isStretchWithOverflow="true" evaluationTime="Group" evaluationGroup="ORIGEM_DESTINO" pattern="¤ #,##0.00">
					<reportElement uuid="179fee07-d42f-496e-b230-845f93d8c8f0" x="503" y="1" width="52" height="18"/>
					<textElement textAlignment="Right">
						<font size="7"/>
					</textElement>
					<textFieldExpression><![CDATA[$V{SOMA_TRECHO}]]></textFieldExpression>
				</textField>
				<textField isStretchWithOverflow="true" evaluationTime="Group" evaluationGroup="ORIGEM_DESTINO">
					<reportElement uuid="a322f9ad-954c-465c-9b40-ac3cab4dc79b" x="379" y="2" width="36" height="18"/>
					<textElement textAlignment="Center">
						<font size="7"/>
					</textElement>
					<textFieldExpression><![CDATA[$V{VENDA_1}]]></textFieldExpression>
				</textField>
				<textField isStretchWithOverflow="true" evaluationTime="Group" evaluationGroup="ORIGEM_DESTINO">
					<reportElement uuid="5d465455-d176-491c-85d6-32c9253ee154" x="415" y="0" width="35" height="20"/>
					<textElement textAlignment="Center">
						<font size="7"/>
					</textElement>
					<textFieldExpression><![CDATA[$V{LIVRE_1}]]></textFieldExpression>
				</textField>
				<textField isStretchWithOverflow="true" evaluationTime="Group" evaluationGroup="ORIGEM_DESTINO">
					<reportElement uuid="01f963e8-3bec-4337-b9a5-b268e1a542e1" x="450" y="0" width="53" height="18"/>
					<textElement textAlignment="Center">
						<font size="7"/>
					</textElement>
					<textFieldExpression><![CDATA[$V{LIVRE_1}.add( $V{VENDA_1} )]]></textFieldExpression>
				</textField>
			</band>
		</groupHeader>
		<groupFooter>
			<band/>
		</groupFooter>
	</group>
	<background>
		<band splitType="Stretch"/>
	</background>
	<title>
		<band height="1" splitType="Stretch"/>
	</title>
	<pageHeader>
		<band height="81" splitType="Stretch">
			<textField>
				<reportElement uuid="ba15f24b-d005-454d-a657-77e4026eb86d" x="0" y="20" width="243" height="20"/>
				<textElement/>
				<textFieldExpression><![CDATA[$R{header.titulo.relatorio}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement uuid="51c70ea8-b2da-4205-987b-440e2fd92472" x="0" y="40" width="57" height="20"/>
				<textElement/>
				<textFieldExpression><![CDATA[$R{header.periodo}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement uuid="e937012b-ba35-4470-a65d-721239415cfb" x="0" y="60" width="85" height="20"/>
				<textElement/>
				<textFieldExpression><![CDATA[$R{header.filtro.agencia}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement uuid="cb97e1df-8fd7-4be9-a133-3847faca4a55" x="0" y="0" width="243" height="20"/>
				<textElement>
					<font size="12" isBold="true"/>
				</textElement>
				<textFieldExpression><![CDATA[$P{NOMBEMPRESA}]]></textFieldExpression>
			</textField>
			<textField pattern="dd/MM/yyyy">
				<reportElement uuid="82c899d6-0520-4713-87c1-9547f112e0a6" x="57" y="40" width="57" height="20"/>
				<textElement/>
				<textFieldExpression><![CDATA[$P{DATA_INICIO}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement uuid="0edcc027-d655-4f86-a3a4-7ef42dc76c79" x="114" y="40" width="13" height="20"/>
				<textElement/>
				<textFieldExpression><![CDATA[$R{msg.a}]]></textFieldExpression>
			</textField>
			<textField pattern="dd/MM/yyyy">
				<reportElement uuid="845264f4-fe59-4244-9ba3-a379ed2554af" x="127" y="40" width="62" height="20"/>
				<textElement/>
				<textFieldExpression><![CDATA[$P{DATA_FINAL}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement uuid="55501b9a-fd9a-463d-ae0d-cb8c15a6139f" x="538" y="20" width="17" height="20"/>
				<textElement/>
				<textFieldExpression><![CDATA[$V{PAGE_NUMBER}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement uuid="8d99edae-4a10-4091-bb1a-bc5fc4ef1b78" x="499" y="20" width="39" height="20"/>
				<textElement/>
				<textFieldExpression><![CDATA[$R{header.pagina}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement uuid="0f57ef57-d7b2-414c-84e5-73b8936474e3" x="395" y="0" width="55" height="20"/>
				<textElement/>
				<textFieldExpression><![CDATA[$R{header.data.hora}]]></textFieldExpression>
			</textField>
			<textField pattern="dd/MM/yyyy HH:mm:ss">
				<reportElement uuid="54dce584-fcac-4ea6-8c53-5fffbd0fc369" x="450" y="0" width="105" height="20"/>
				<textElement/>
				<textFieldExpression><![CDATA[$P{NOW}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement uuid="9656fe00-431b-4746-a82d-729b99b3aa27" x="85" y="61" width="470" height="19"/>
				<textElement/>
				<textFieldExpression><![CDATA[$P{PUNTOVENTA}]]></textFieldExpression>
			</textField>
			<line>
				<reportElement uuid="c0b4cb22-4607-4f4e-a6e3-c1c819f28efe" x="0" y="60" width="555" height="1"/>
			</line>
		</band>
	</pageHeader>
	<columnHeader>
		<band height="20" splitType="Stretch">
			<textField>
				<reportElement uuid="27c1f448-0728-42af-a89b-84443846c281" x="0" y="0" width="346" height="20"/>
				<textElement/>
				<textFieldExpression><![CDATA[$R{group.trecho}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement uuid="d86c76ce-f705-45e7-8cdb-a11b626bcb83" x="346" y="0" width="33" height="20"/>
				<textElement>
					<font size="7"/>
				</textElement>
				<textFieldExpression><![CDATA[$R{group.horario}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement uuid="69a8660b-6a02-443a-bfd8-c04a1fdafe01" x="415" y="0" width="35" height="20"/>
				<textElement textAlignment="Center">
					<font size="7"/>
				</textElement>
				<textFieldExpression><![CDATA[$R{group.poltronas.livres}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement uuid="aa808a36-04ce-4f33-8cca-17782c004628" x="450" y="0" width="53" height="20"/>
				<textElement textAlignment="Center">
					<font size="7"/>
				</textElement>
				<textFieldExpression><![CDATA[$R{group.total}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement uuid="48b8257c-bf68-4b1e-9b6b-b51fecd0d6d0" x="503" y="0" width="52" height="20"/>
				<textElement textAlignment="Right">
					<font size="7"/>
				</textElement>
				<textFieldExpression><![CDATA[$R{group.valor.total}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement uuid="889f0cb9-8418-42b0-83b8-a30794a7541f" x="379" y="0" width="36" height="20"/>
				<textElement>
					<font size="7"/>
				</textElement>
				<textFieldExpression><![CDATA[$R{group.venda}]]></textFieldExpression>
			</textField>
			<line>
				<reportElement uuid="07c2d42d-0861-42f7-bda2-8157b5120f87" x="0" y="-1" width="555" height="1"/>
			</line>
		</band>
	</columnHeader>
	<detail>
		<band height="21" splitType="Stretch">
			<textField isStretchWithOverflow="true" pattern="¤ #,##0.00">
				<reportElement uuid="b27e9c29-cf89-41db-a94b-799c969ef1e1" x="503" y="0" width="52" height="20"/>
				<textElement textAlignment="Right">
					<font size="7"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{SOMA}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true">
				<reportElement uuid="2b9b18b3-59d0-443c-9171-b5f43febb878" x="379" y="0" width="36" height="20"/>
				<textElement textAlignment="Center">
					<font size="7"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{VENDA}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true">
				<reportElement uuid="5834225d-51b1-4929-b692-c9b61910587e" x="415" y="1" width="35" height="19"/>
				<textElement textAlignment="Center">
					<font size="7"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{LIVRE}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true">
				<reportElement uuid="e9915cd8-dd51-4e7b-8115-200c0222e843" x="450" y="1" width="53" height="19"/>
				<textElement textAlignment="Center">
					<font size="7"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{VENDA}.add( $F{LIVRE} )]]></textFieldExpression>
			</textField>
			<textField pattern="HH:mm" isBlankWhenNull="true">
				<reportElement uuid="3875c823-7570-4b5b-aaf1-98d6d68d268c" x="346" y="1" width="33" height="19"/>
				<textElement>
					<font size="7"/>
				</textElement>
				<textFieldExpression><![CDATA[$F{FECHORSALIDA}]]></textFieldExpression>
			</textField>
		</band>
	</detail>
	<columnFooter>
		<band splitType="Stretch"/>
	</columnFooter>
	<pageFooter>
		<band splitType="Stretch"/>
	</pageFooter>
	<summary>
		<band height="20" splitType="Stretch">
			<textField>
				<reportElement uuid="398bcb75-d1a6-459d-ae52-94e90ceed079" x="379" y="0" width="36" height="20"/>
				<textElement textAlignment="Center" verticalAlignment="Middle">
					<font size="7" isBold="true"/>
				</textElement>
				<textFieldExpression><![CDATA[$V{VENDA_2}]]></textFieldExpression>
			</textField>
			<textField>
				<reportElement uuid="92505b57-456e-477a-b456-10f7499c7c76" x="415" y="0" width="35" height="20"/>
				<textElement textAlignment="Center" verticalAlignment="Middle">
					<font size="7" isBold="true"/>
				</textElement>
				<textFieldExpression><![CDATA[$V{LIVRE_2}]]></textFieldExpression>
			</textField>
			<textField pattern="¤ #,##0.00">
				<reportElement uuid="ca0102b6-c0eb-40a9-a9b7-d30798839138" x="503" y="0" width="52" height="20"/>
				<textElement textAlignment="Right" verticalAlignment="Middle">
					<font size="7" isBold="true"/>
				</textElement>
				<textFieldExpression><![CDATA[$V{SOMA_1}]]></textFieldExpression>
			</textField>
			<textField isStretchWithOverflow="true" evaluationTime="Group" evaluationGroup="ORIGEM_DESTINO">
				<reportElement uuid="12f2bdb9-c2cc-48bf-b5fe-23bd584acf4d" x="450" y="2" width="53" height="18"/>
				<textElement textAlignment="Center" verticalAlignment="Middle">
					<font size="7" isBold="true"/>
				</textElement>
				<textFieldExpression><![CDATA[$V{LIVRE_2}.add( $V{VENDA_2} )]]></textFieldExpression>
			</textField>
			<line>
				<reportElement uuid="c36faceb-fd36-4f57-86b1-113129160cce" x="0" y="-1" width="555" height="2"/>
			</line>
			<textField>
				<reportElement uuid="626a1346-a1f9-411e-bb5f-4e37804dffaa" x="0" y="1" width="97" height="19"/>
				<textElement>
					<font size="8" isBold="true"/>
				</textElement>
				<textFieldExpression><![CDATA[$R{summary.total}]]></textFieldExpression>
			</textField>
		</band>
	</summary>
	<noData>
		<band height="21">
			<textField>
				<reportElement uuid="637f94f0-fe53-4a50-934e-58f2312a96a4" x="0" y="0" width="555" height="20"/>
				<textElement markup="none">
					<font size="11" isBold="true"/>
				</textElement>
				<textFieldExpression><![CDATA[$R{msg.noData}]]></textFieldExpression>
			</textField>
		</band>
	</noData>
</jasperReport>
