<?xml version="1.0"?>

<report name="cash-report" pdf-renderer="Tagesabschluss.xsl">
	<title>Tagesabschluss</title>

	<report-parameter name="TENANT" type="integer" hidden="true">
		<preset>@TENANT_NO</preset>
	</report-parameter>
	<report-parameter name="COMPANY" type="integer" hidden="true">
		<preset>@COMPANY_NO</preset>
	</report-parameter>
	<report-parameter name="DATE" type="date" label="Von Datum:">
		<preset>@TODAY</preset>
		<input type="datepicker" />
	</report-parameter>
	<report-parameter name="BUSINESSUNIT" type="integer">
		<label>Filiale:</label>
		<input type="selectlist">
			<source type="dataset" name="businessunits">
			</source>
		</input>
	</report-parameter>

	<report-result report-dataset="businessunits">
	</report-result>
	<report-result report-dataset="drawers">
	</report-result>

		<report-result report-dataset="firstNote">
	</report-result>
		<report-result report-dataset="lastNote">
	</report-result>

	<report-result report-dataset="simple_accounts">
	</report-result>

	
	
<report-transaction report-nm="pos_payment_statistics" report-transaction="de.timeglobe.pos.reporting.PosPaymentStatistics">
	</report-transaction>
	<report-result report-dataset="departmentCurrency">
	</report-result>

    <report-dataset name="departmentCurrency">
		<sql>
			select * from currencies c join departments d on c.tenant_no = d.tenant_no AND c.currency_cd = d.currency_cd  where d.tenant_no=@TENANT_NO and d.company_no=@COMPANY_NO and d.department_no =@DEPARTMENT_NO 
		</sql>
	</report-dataset>
	<report-dataset name="businessunits">
		<sql>
			select * from businessunits where tenant_no=@TENANT_NO and company_no=@COMPANY_NO and department_no=@DEPARTMENT_NO and businessunit_no=@BUSINESSUNIT_NO
		</sql>
	</report-dataset>


	<report-dataset name="simple_accounts">
		<sql>
			select * from simple_accounts where tenant_no=@TENANT_NO and company_no=@COMPANY_NO AND department_no=@DEPARTMENT_NO
		</sql>
	</report-dataset>

	<report-dataset name="drawers">
		<sql>
			select * from pos_drawers d
			where d.tenant_no=@TENANT_NO and d.pos_cd=@POS_CD
		</sql>
	</report-dataset>

		
		
	
	
	<report-dataset name="firstNote">
		<sql>
			select
			h.sales_inv_cd sales_inv_cd
			from sales_invs h
			where h.sales_inv_ts in (select min(sales_inv_ts) from sales_invs where tenant_no=@TENANT_NO and pos_cd=@POS_CD and cast (sales_inv_ts as DATE) = cast (@DATE as DATE))
		</sql>
	</report-dataset>
	
	<report-dataset name="lastNote">
		<sql>
			select
			h.sales_inv_cd sales_inv_cd
			from sales_invs h
			where h.sales_inv_ts in (select max(sales_inv_ts) from sales_invs where tenant_no=@TENANT_NO and pos_cd=@POS_CD and cast (sales_inv_ts as DATE) = cast (@DATE as DATE))
		</sql>
	</report-dataset>
	

	
	

</report>
