<vn>
<vn-group>
	<db-form id="ticket">
		<db-model property="model" id="ticket-data" conn="conn" batch="batch">
			<custom>
				SELECT t.id, date, a.Agencia, note, p.name province,
				zip_code, city, c.name, consignee, invoice
					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>
		</db-model>
	</db-form>
</vn-group>
<div id="report" class="sheet">
	<h2>
		<htk-text column="id" form="ticket"/>
	</h2>
	<div class="header">
		<p>
			<htk-text form="ticket" column="consignee"/>
		</p>
		<p>
			<htk-text form="ticket" column="date" format="%D"/>
		</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>
		<p>
			<t>Delivery</t> <htk-text form="ticket" column="Agencia"/>
		</p>
	</div>
	<htk-grid>
		<db-model property="model" id="movements" conn="conn" batch="batch">
			<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>
		</db-model>
		<htk-column-spin title="_Ref" column="item_id"/>
		<htk-column-spin title="_Amount" column="amount"/>
		<htk-column-text title="_Item" column="concept"/>
		<htk-column-text title="_S1" column="Medida"/>
		<htk-column-text title="_Cat" column="Categoria"/>
		<htk-column-spin title="_Price" column="price" unit="€" digits="2"/>
		<htk-column-spin title="_Subtotal" unit="€" digits="2" renderer="subtotalRenderer"/>
	</htk-grid>
	<p class="footer">
		<htk-text format="%.2d€">
			<db-calc-sum property="param" func="subtotal" model="movements"/>
		</htk-text>
	</p>
</div>
</vn>
