<?xml version="1.0"?>

<report name="cash-report" pdf-renderer="StockNoteDetail.xsl">
	<title>PurchaseNoteList</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-transaction report-nm="stock_note_detail" report-transaction="net.spa.pos.transactions.LoadJSStockNote">
	</report-transaction>
	<report-result report-dataset="businessunits">
	</report-result>

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

	<report-result report-dataset="itemPruchasePrices">
	</report-result>
<!-- 	<report-result report-dataset="itemPruchasePricesDraft">
	</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="stockRevisionTypes">
		<sql>
			select stock_revision_type_no ID, stock_revision_type_nm from stock_revision_types where tenant_no=@TENANT_NO and company_no=@COMPANY_NO and department_no=@DEPARTMENT_NO 
		</sql>
	</report-dataset>

<report-dataset name="itemPruchasePrices">
	<sql>
SELECT item_cd, item_net_price 
 FROM purchase_item_prices 
WHERE tenant_no = @TENANT_NO  
  and company_no = @COMPANY_NO 
  and department_no  = @DEPARTMENT_NO 
  and stock_no = (SELECT stock_no from stock_dlns WHERE tenant_no = @TENANT_NO  
                     and company_no = @COMPANY_NO 
                     and department_no  = @DEPARTMENT_NO 
                     and stock_dln_id = cast(@NOTE_ID as INTEGER)
                   )
  and   price_ts &lt;= (SELECT stock_dln_ts from stock_dlns WHERE tenant_no = @TENANT_NO  
                     and company_no = @COMPANY_NO 
                     and department_no  = @DEPARTMENT_NO
                     and stock_dln_id = cast(@NOTE_ID as INTEGER)
                   )  
 order by price_ts DESC 
	</sql>
	</report-dataset>


<report-dataset name="itemPruchasePricesDraft">
	<sql>
SELECT item_cd, item_net_price 
 FROM purchase_item_prices 
WHERE tenant_no = @TENANT_NO  
  and company_no = @COMPANY_NO 
  and department_no  = @DEPARTMENT_NO 
  and stock_no = (SELECT stock_no from d_stock_dlns WHERE tenant_no = @TENANT_NO  
                     and company_no = @COMPANY_NO 
                     and department_no  = @DEPARTMENT_NO 
                     and stock_dln_id = cast(@NOTE_ID as INTEGER)
                   )
  and   price_ts &lt;= (SELECT stock_dln_ts from d_stock_dlns WHERE tenant_no = @TENANT_NO  
                     and company_no = @COMPANY_NO 
                     and department_no  = @DEPARTMENT_NO
                     and stock_dln_id = cast(@NOTE_ID as INTEGER)
                   )  
 order by price_ts DESC 
	</sql>
	</report-dataset>

</report>

