<?xml version="1.0"?>

<report name="cash-report" pdf-renderer="Einrichtungsprotokoll.xsl">
	<title>Einrichtungsprotokoll</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="POSSESSIONID" type="integer"
		hidden="true">
		<preset>@POS_SESSION_ID</preset>
	</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="pointOfSale">
	</report-result>

	<report-result report-dataset="salesInvsAmount">
	</report-result>
	<report-result report-dataset="purchaseInvsAmount">
	</report-result>

	<report-result report-dataset="stockDlnAmount">
	</report-result>
	<report-result report-dataset="minSalesInvTs">
	</report-result>
	<report-result report-dataset="voucherAmount">
	</report-result>
	<report-result report-dataset="paymentAmount">
	</report-result>
<report-result report-dataset="drawers">
	</report-result>
	<report-result report-dataset="employees">
	</report-result>
	<report-result report-dataset="employeesAmount">
	</report-result>	
	<report-result report-dataset="simpleAccountsAmount">
	</report-result>	
	
	<report-result report-dataset="simpleAccounts">
	</report-result>
	<report-result report-dataset="countContacts">
	</report-result>
	<report-result report-dataset="countCustomers">
	</report-result>
	<report-result report-dataset="itemsServiceAmount">
	</report-result>

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

	<report-result report-dataset="taxes">
	</report-result>
<report-result report-dataset="stocks">
	</report-result> 
	
<report-result report-dataset="currencies">
	</report-result> 
	<report-result report-dataset="departmentCurrency">
	</report-result>	



	<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="pointOfSale">
		<sql>
			select * from points_of_sale where tenant_no=@TENANT_NO and
			 pos_cd=@POS_CD 
		</sql>
	</report-dataset>





<report-dataset name="minSalesInvTs">
		<sql>
			select case when min(sales_inv_ts) is null THEN min(sales_inv_ts) ELSE  {fn TIMESTAMPADD( SQL_TSI_DAY, -7, min(sales_inv_ts))} END minSalesInvTs
			  from sales_invs 
	         where tenant_no=@TENANT_NO 
	           and pos_cd=@POS_CD 
			 
		</sql>
	</report-dataset>


	<report-dataset name="salesInvsAmount">
		<sql>
			select count(sales_inv_id) cnt
			from sales_invs h
			where h.sales_inv_ts &lt; (select min(sales_inv_ts) 
			                          from sales_invs 
	                                 where tenant_no=@TENANT_NO 
	                                   and pos_cd=@POS_CD 
			                        )
			 and tenant_no=@TENANT_NO 
	         and pos_cd=@POS_CD 
		</sql>
	</report-dataset>


<report-dataset name="purchaseInvsAmount">
		<sql>
			select count(purchase_inv_id) cnt
			from purchase_invs h
			where h.purchase_inv_ts &lt; (select min(sales_inv_ts) 
			                          from sales_invs 
	                                 where tenant_no=@TENANT_NO 
	                                   and pos_cd=@POS_CD 
			                        )
			 and tenant_no=@TENANT_NO 
	         and pos_cd=@POS_CD 
		</sql>
	</report-dataset>

<report-dataset name="stockDlnAmount">
		<sql>
			select count(stock_dln_id) cnt
			from stock_dlns h
			where h.stock_dln_ts &lt; (select min(sales_inv_ts) 
			                          from sales_invs 
	                                 where tenant_no=@TENANT_NO 
	                                   and pos_cd=@POS_CD 
			                        )
			 and tenant_no=@TENANT_NO 
	         and pos_cd=@POS_CD 
		</sql>
	</report-dataset>
	
	
<report-dataset name="paymentAmount">
		<sql>
			select count(pos_payment_id) cnt
			from pos_payments h
			where h.payment_ts &lt; (select min(sales_inv_ts) 
			                          from sales_invs 
	                                 where tenant_no=@TENANT_NO 
	                                   and pos_cd=@POS_CD 
			                        )
			 and tenant_no=@TENANT_NO 
	         and pos_cd=@POS_CD 
		</sql>
	</report-dataset>	

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

	<report-dataset name="employees">
		<sql>
			select * from employees
			 
			 WHERE tenant_no=@TENANT_NO 
			  and company_no=@COMPANY_NO 
	         
		</sql>
	</report-dataset>	
		
		<report-dataset name="employeesAmount">
		<sql>
			select count(*) cnt from employees
			 
			 WHERE tenant_no=@TENANT_NO 
			  and company_no=@COMPANY_NO 
	         
		</sql>
	</report-dataset>	
		
	<report-dataset name="simpleAccounts">
		<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="simpleAccountsAmount">
		<sql>
			select count(*) cnt from simple_accounts 
			 
			 WHERE tenant_no=@TENANT_NO 
	         and company_no=@COMPANY_NO and department_no=@DEPARTMENT_NO
		</sql>
	</report-dataset>	
		
		<report-dataset name="itemsServiceAmount">
		<sql>
			select count(*) cnt from items
			 
			 WHERE tenant_no=@TENANT_NO 
	         and company_no=@COMPANY_NO and department_no=@DEPARTMENT_NO
	         and coalesce(stockable ,0 ) = 0
		</sql>
	</report-dataset>			
		
		
		<report-dataset name="itemsProductAmount">
		<sql>
			select count(*) cnt from items
			 
			 WHERE tenant_no=@TENANT_NO 
	         and company_no=@COMPANY_NO and department_no=@DEPARTMENT_NO
	         and coalesce(stockable ,0 ) = 1
		</sql>
	</report-dataset>		
		
		<report-dataset name="taxes">
		<sql>
			select * from taxes
			 
			 where tenant_no=@TENANT_NO 
	         and company_no=@COMPANY_NO 
		</sql>
	</report-dataset>		
		
		<report-dataset name="stocks">
		<sql>
			select * from stocks
			 
			 where tenant_no=@TENANT_NO 
	         and company_no=@COMPANY_NO 
	         and department_no=@DEPARTMENT_NO
		</sql>
	</report-dataset>		

		<report-dataset name="currencies">
		<sql>
			select * from currencies
			 
			 WHERE tenant_no=@TENANT_NO 
	       
		</sql>
	</report-dataset>	

  <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="countContacts">
		<sql>
			select count(*) cnt from contacts
			 
			 WHERE tenant_no=@TENANT_NO 
	       
		</sql>
	</report-dataset>	
	<report-dataset name="countCustomers">
		<sql>
			select count(cr.contact_no)  cnt
			  from customer_roles cr
			  join contacts c on c.tenant_no = cr.tenant_no and c.contact_no = cr.contact_no
			   WHERE cr.tenant_no=@TENANT_NO 
	           and cr.company_no=@COMPANY_NO
	       
		</sql>
	</report-dataset>			
	
	
		<report-dataset name="voucherAmount">
		<sql>
			select count(sales_voucher_id) cnt
			from sales_vouchers h
			where h.sales_voucher_ts &lt; (select min(sales_inv_ts) 
			                          from sales_invs 
	                                 where tenant_no=@TENANT_NO 
	                                   and pos_cd=@POS_CD 
			                        )
			 and tenant_no=@TENANT_NO 
	         and pos_cd=@POS_CD 
		</sql>
	</report-dataset>	
	
		
		
</report>
