<vn>
<vn-group>
	<vn-param id="ticket-id"/>
	<vn-hash-param key="ticket" param="ticket-id"/>
	<db-form id="ticket">
		<db-model property="model" id="ticket-data">
			<custom>
				SELECT t.id, date, a.Agencia, note, p.name province,
				zip_code, city, c.name, consignee, invoice, delivery
					FROM ticket_view t
					JOIN address_view c ON t.address_id = c.id
					JOIN vn2008.Agencias a ON t.agency_id = a.Id_Agencia
					JOIN vn2008.province p ON c.province_id = p.province_id
						WHERE t.id = #ticket
			</custom>
			<sql-batch property="batch">
				<custom>
					<item name="ticket" param="ticket-id"/>
				</custom>
			</sql-batch>
		</db-model>
	</db-form>
</vn-group>
<div id="title">
	<h1><t>OrderDetail</t></h1>
</div>
<div id="actions" class="action-bar">
	<htk-bar-button
		icon="print"
		tip="_Print delivery note"
		on-click="onPrintClick"/>
</div>
<div id="form" class="ticket">
	<div class="box">
		<div class="head">
			<div>
				<p class="important ticket-id">
					<htk-text column="id" form="ticket"/>
				</p>
				<p>
					<htk-text form="ticket" column="delivery" format="%A, %e of %B %Y"/>
				</p>
			</div>
			<div>
				<p>
					<t>Delivery</t> <htk-text form="ticket" column="Agencia"/>
				</p>
				<p>
					<htk-text form="ticket" column="consignee"/>
				</p>
				<p>
					<htk-text form="ticket" column="name"/>
				</p>
				<p>
					<htk-text form="ticket" column="zip_code"/> 
					<htk-text form="ticket" column="city"/> 
					(<htk-text form="ticket" column="province"/>)
				</p>
			</div>
			<div>
				<p class="important total">
					<t>Total</t> 
					<htk-text format="%.2d€">
						<db-calc-sum property="param" func="subtotal" model="movements"/>
					</htk-text>
				</p>
			</div>
		</div>
		<htk-repeater form-id="iter" renderer="repeaterFunc">
			<db-model property="model" id="movements">
				<custom>
					SELECT m.item_id, amount, concept, Categoria, Medida, Tallos, Color,
					Abreviatura, IF(fixed != FALSE, price, NULL) price, fixed, discount
						FROM ticket_row_view m
						INNER JOIN vn2008.Articles a
							ON m.item_id = a.Id_Article AND ticket_id = #ticket 
						LEFT JOIN vn2008.Origen o
							ON a.id_origen = o.id
							ORDER BY concept
				</custom>
				<sql-batch property="batch">
					<custom>
						<item name="ticket" param="ticket-id"/>
					</custom>
				</sql-batch>
			</db-model>
			<custom>
				<div class="line">
					<p class="concept">
						<htk-text form="iter" column="concept"/> 
						<htk-text form="iter" column="Medida"/> 
						<htk-text form="iter" column="Categoria"/>
					</p>
					<p class="amount">
						<htk-text form="iter" column="amount"/> x
						<htk-text form="iter" column="price" format="%.2d€"/>
					</p>
					<p class="subtotal">
						<htk-text id="subtotal" format="%.2d€"/>
					</p>
					<div class="clear"/>
				</div>
			</custom>
		</htk-repeater>
	</div>
</div>
</vn>
