<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE jasperReport
        PUBLIC "-//JasperReports//DTD Report Design//EN"
        "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd">

<jasperReport name="PatientBill" pageWidth="600" pageHeight="400">
	<style name="Normal" 
		isDefault="true" 
		fontSize="10" 
		pdfFontName="data/jasper/times.ttf"
		pdfEncoding="Cp1251"
		isPdfEmbedded="false" />
	<style name="Arial_Bold"
		isDefault="false"
		fontName="Arial"
		isBold="true"
		isItalic="false"
		isUnderline="false"
		isStrikeThrough="false"
		isPdfEmbedded="false"
	/>
	<style name="pHeader" style="Normal" isBold="true" fontSize="10" />
	<style name="pHeader1" style="Normal" isBold="true" fontSize="18" />
	<style name="pHeader2" style="Normal" isBold="true" fontSize="10" forecolor="#AA0000" />
	<style name="Procedure" style="Normal" fontSize="9" />
	
	<parameter name="patient_name" class="java.lang.String"/>
	<parameter name="patient_adres" class="java.lang.String"/>
	<parameter name="visit_number" class="java.lang.Long"/>
	<parameter name="date_curent" class="java.lang.String"/>
	<parameter name="language" class="java.lang.Integer"/>	
	<parameter name="tax" class="java.lang.Integer"/>
	<parameter name="sum_word" class="java.lang.String"/>
	<parameter name="signature" class="java.awt.Image"/>
	<parameter name="clinic_name" class="java.lang.String"/>
	<parameter name="clinic_address" class="java.lang.String"/>
	<parameter name="clinic_phone" class="java.lang.String"/>
	<parameter name="clinic_fax" class="java.lang.String"/>
	<parameter name="clinic_reg_nr" class="java.lang.String"/>                 
	
	<queryString><![CDATA[
		SELECT 1 as s,
			sl_visits.name AS proc_name,
			sum(visit_procedures.proc_count) AS proc_count,
			sl_visits.price AS price_kassa,
			sl_visits.price AS price_clinic,
			sl_visits.price*sum(visit_procedures.proc_count)  AS proc_summ
		FROM
			sl_visits
		Inner Join sl_procedures ON sl_visits.proc_code = sl_procedures.kod
		Inner Join visit_procedures ON visit_procedures.p_code = sl_procedures.id
		WHERE
			sl_visits.doctor_id =  '2' AND
			sl_visits.data_out IS NULL  AND
			visit_procedures.visit_id =  $P{visit_number}
		GROUP BY
			sl_visits.proc_code
		]]>
	</queryString>
  
	<field name="s" class="java.lang.Integer" />
	<field name="proc_name" class="java.lang.String"/>
	<field name="proc_count" class="java.lang.Integer" />
	<field name="price_kassa" class="java.lang.Double" />
	<field name="price_clinic" class="java.lang.Double" />
	<field name="proc_summ" class="java.lang.Double" />
	
	<variable name="summ" class="java.lang.Double" resetType="Column" calculation="Sum">
		<variableExpression><![CDATA[$F{proc_summ}]]></variableExpression>
	</variable>
	<variable name="nnn" class="java.lang.Integer" resetType="Column" calculation="Count">
		<variableExpression><![CDATA[($V{nnn} != null)?($V{nnn}):(new Integer(0))]]></variableExpression>
	</variable>
	
	<group name="TotalSums" isReprintHeaderOnEachPage="true">
		<groupExpression><![CDATA[$F{s}]]></groupExpression>
		<groupFooter>
		<band height="15">
			<rectangle>
				<reportElement x="-15" y="0" width="400" height="15" backcolor="#333333"/>
				<graphicElement/>
			</rectangle>
			<staticText>
				<reportElement mode="Opaque" x="15" y="0" width="140" height="15" forecolor="#ffffff" backcolor="#333333" />
				<textElement>
					<font isBold="true"/>
				</textElement>
				<text><![CDATA[Kokku:]]></text>
			</staticText>
			<textField pattern="0.00">
				<reportElement mode="Opaque" x="320" y="0" width="50" height="15" forecolor="#ffffff" backcolor="#333333" />
				<textElement textAlignment="Right">
					<font isBold="true"/>
				</textElement>
				<textFieldExpression class="java.lang.Double"><![CDATA[$V{summ}]]></textFieldExpression>
			</textField>
		</band>
		</groupFooter>
	</group>
	
	<title>
		<band height="60">
			<textField>
				<reportElement x="-10" y="-20" width="200" height="32" style="pHeader1"/>
						<textFieldExpression>
							<![CDATA["A.L. Medical AS"]]>
						</textFieldExpression>
			</textField>
			<textField>
				<reportElement x="-10" y="10" width="100" height="20" />
						<textFieldExpression>
							<![CDATA["Klient:"]]>
						</textFieldExpression>
			</textField>
			<textField>
				<reportElement x="20" y="10" width="100" height="20" style="pHeader"/>
						<textFieldExpression>
							<![CDATA[$P{patient_name}]]>
						</textFieldExpression>
			</textField>
			<textField>
				<reportElement x="20" y="22" width="100" height="20" />
						<textFieldExpression>
							<![CDATA[$P{patient_adres}]]>
						</textFieldExpression>
			</textField>
			<textField>
				<reportElement x="290" y="-10" width="60" height="20" style="pHeader"/>
				<textElement textAlignment="Right" />
						<textFieldExpression>
							<![CDATA["Arve nr.:"]]>
						</textFieldExpression>
			</textField>
			<textField>
				<reportElement x="355" y="-10" width="40" height="20" style="pHeader"/>
						<textFieldExpression>
							<![CDATA[""+$P{visit_number}]]>
						</textFieldExpression>
			</textField>
			<textField>
				<reportElement x="290" y="5" width="60" height="20" />
				<textElement textAlignment="Right" />
						<textFieldExpression>
							<![CDATA["Kuupäev:"]]>
						</textFieldExpression>
			</textField>
			<textField>
				<reportElement x="355" y="7" width="60" height="20" style="Procedure"/>
						<textFieldExpression>
							<![CDATA[$P{date_curent}]]>
						</textFieldExpression>
			</textField>
			<textField>
				<reportElement x="290" y="20" width="60" height="20" />
				<textElement textAlignment="Right" />
						<textFieldExpression>
							<![CDATA["Maksepäev:"]]>
						</textFieldExpression>
			</textField>
			<textField>
				<reportElement x="270" y="35" width="80" height="15" />
				<textElement textAlignment="Right" />
						<textFieldExpression>
							<![CDATA["Viivis % päevas:"]]>
						</textFieldExpression>
			</textField>
			<textField>
				<reportElement x="360" y="35" width="40" height="15" />
						<textFieldExpression>
							<![CDATA[$P{tax}+" %"]]>
						</textFieldExpression>
			</textField>
		</band>
	</title>

	<pageHeader>
		<band height="21">
			<staticText>
				<reportElement x="-10" y="1" width="400" height="15" style="pHeader"/>
				<text><![CDATA[Nr                        Service                                       KM%  Kogus         Hind      Summa    Summa+KM]]></text>
			</staticText>
			<line>
				<reportElement x="-15" y="20" width="400" height="1"/>
				<graphicElement/>
			</line>
		</band>
	</pageHeader>
	<detail>
		<band height="12">
			<textField>
				<reportElement x="-5" y="0" width="50" height="12" style="Procedure"/>
				<textFieldExpression class="java.lang.Integer">
					<![CDATA[$V{nnn}]]>
				</textFieldExpression>
			</textField>
			<textField>
				<reportElement x="15" y="0" width="200" height="12" style="Procedure"/>
				<textFieldExpression class="java.lang.String">
					<![CDATA[$F{proc_name}]]>
				</textFieldExpression>
			</textField>
			<textField>
				<reportElement x="210" y="0" width="20" height="12" style="Procedure"/>
				<textElement textAlignment="Right" />
				<textFieldExpression class="java.lang.Integer">
					<![CDATA[$P{tax}]]>
				</textFieldExpression>
			</textField>
			<textField>
				<reportElement x="240" y="0" width="20" height="12" style="Procedure"/>
				<textElement textAlignment="Right" />
				<textFieldExpression class="java.lang.Integer">
					<![CDATA[$F{proc_count}]]>
				</textFieldExpression>
			</textField>
			<textField pattern="0.00">
				<reportElement x="270" y="0" width="50" height="12" style="Procedure"/>
				<textElement textAlignment="Right" />
				<textFieldExpression class="java.lang.Double">
					<![CDATA[$F{price_clinic}]]>
				</textFieldExpression>
			</textField>
			<textField pattern="0.00">
				<reportElement x="320" y="0" width="50" height="12" style="Procedure"/>
				<textElement textAlignment="Right" />
				<textFieldExpression class="java.lang.Double">
					<![CDATA[$F{proc_summ}]]>
				</textFieldExpression>
			</textField>
		</band>
	</detail>
	<pageFooter>
		<band height="47">
			<line>
				<reportElement x="-15" y="0" width="400" height="1"/>
				<graphicElement/>
			</line>
			<textField>
				<reportElement x="-10" y="1" width="100" height="13" style="pHeader"/>
				<textFieldExpression>
					<![CDATA[$P{clinic_name}]]>
				</textFieldExpression>
			</textField>
			<textField>
				<reportElement x="-10" y="13" width="100" height="34"/>
				<textFieldExpression>
					<![CDATA[$P{clinic_address}]]>
				</textFieldExpression>
			</textField>
			
			<textField>
				<reportElement x="120" y="1" width="100" height="12" style="Procedure"/>
				<textFieldExpression>
					<![CDATA["Telefon: +"+$P{clinic_phone}]]>
				</textFieldExpression>
			</textField>
			<textField>
				<reportElement x="120" y="13" width="100" height="12" style="Procedure"/>
				<textFieldExpression>
					<![CDATA["Faks:     +"+$P{clinic_fax}]]>
				</textFieldExpression>
			</textField>
			<textField>
				<reportElement x="120" y="35" width="100" height="12" style="Procedure"/>
				<textFieldExpression>
					<![CDATA["Reg.nr:  "+$P{clinic_reg_nr}]]>
				</textFieldExpression>
			</textField>
			
			<staticText>
				<reportElement x="200" y="1" width="180" height="13"/>
				<textElement textAlignment="Right">
					<font size="9"/>
				</textElement>
				<text><![CDATA[A/a 221026381854]]></text>
			</staticText>
			<staticText>
				<reportElement x="200" y="13" width="180" height="12"/>
				<textElement textAlignment="Right">
					<font size="9"/>
				</textElement>
				<text><![CDATA[Hansapank 767]]></text>
			</staticText>
			<staticText>
				<reportElement x="200" y="24" width="180" height="12"/>
				<textElement textAlignment="Right">
					<font size="9"/>
				</textElement>
				<text><![CDATA[SWIFT kood: HABAEE2X]]></text>
			</staticText>
			<staticText>
				<reportElement x="200" y="35" width="180" height="12"/>
				<textElement textAlignment="Right">
					<font size="9"/>
				</textElement>
				<text><![CDATA[VAT/KMKR nr. EE100869497]]></text>
			</staticText>
			
		</band>
	</pageFooter>

	<summary>
		<band height="75">
			<textField>
				<reportElement x="0" y="10" width="100" height="15" />
				<textFieldExpression>
					<![CDATA["Summa sõnadega:"]]>
				</textFieldExpression>
			</textField>
			<textField>
				<reportElement x="95" y="10" width="300" height="15" />
				<textFieldExpression>
					<![CDATA[$P{sum_word}]]>
				</textFieldExpression>
			</textField>
			<textField>
				<reportElement x="0" y="25" width="100" height="15" />
				<textFieldExpression>
					<![CDATA["Allkiri:"]]>
				</textFieldExpression>
			</textField>
			<image>
				<reportElement x="100" y="25" width="100" height="50"/>
				<graphicElement/>
				<imageExpression class="java.awt.Image"><![CDATA[$P{signature}]]></imageExpression>
			</image>
		</band>
	</summary>
</jasperReport>