<vn>
<vn-group>
	<vn-lot id="lot"/>
	<db-form id="order" on-ready="onOrderReady">
		<db-model property="model" result-index="1">
			CALL basket_get_vat ();
			SELECT o.id, o.date_send sendDate, o.note, o.company_id company, 
				ag.description agency, v.code method, 
				ad.consignee, ad.zip_code zipCode, ad.city, ad.name address, 
				t.*, c.credit, clientGetDebt() debt
				FROM basket o
					JOIN vn2008.Agencias ag ON ag.Id_Agencia = o.agency_id 
					LEFT JOIN address_view ad ON ad.id = o.address_id 
					JOIN vn2008.Vistas v ON v.vista_id = o.delivery_method_id
					JOIN customer_view c
					JOIN (
						SELECT
							IFNULL(SUM(tax_base), 0) taxBase,
							IFNULL(SUM(vat + surcharge), 0) vat
							FROM t_order_vat
					) t;
			DROP TEMPORARY TABLE t_order_vat;
		</db-model>
	</db-form>
	<db-query id="confirm-query" on-ready="onConfirm">
		CALL basket_confirm ()
	</db-query>
</vn-group>
<h1 id="title">
	_Order summary
</h1>
<div id="main" class="confirm">
	<div class="summary form card">
		<div>
			<div class="delivery">
				<p>
					_Delivery at 
					<htk-text format="%D" lot="order" name="sendDate"/>
				</p>
				<p>
					<span id="method">_Agency</span> {{order.agency}}
				</p>
			</div>
			<div id="address" class="address">
				<p>
					{{order.consignee}}
				</p>
				<p>
					{{order.address}}
				</p>
				<p>
					{{order.zipCode}}, {{order.city}}
				</p>
			</div>
		</div>
	</div>
	<div class="payment form card">
		<div>
			<table class="debt-info">
				<tbody>
					<tr>
						<td>
							_Previous balance
						</td>
						<td class="currency">
							<htk-text format="%.2d€" lot="order" name="debt"/>
						</td>
					</tr>
					<tr>
						<td>
							_Order total
						</td>
						<td class="currency">
							<htk-text format="%.2d€" lot="order" name="taxBase"/>
						</td>
					</tr>
					<tr>
						<td>
							_Order VAT
						</td>
						<td class="currency">
							<htk-text format="%.2d€" lot="order" name="vat"/>
						</td>
					</tr>
					<tr class="total-debt sum-total">
						<td>
							_Total debt
						</td>
						<td class="currency">
							<htk-text format="%.2d€" lot="lot" name="totalDebt"/>
						</td>
					</tr>
					<tr id="credit-info" class="credit-info">
						<td>
							_Credit
						</td>
						<td class="currency">
							<htk-text format="%.2d€" lot="order" name="credit"/>
						</td>
					</tr>
					<tr id="exceeded-info" class="exceeded-info sum-total">
						<td>
							_Exceeded credit
						</td>
						<td class="currency">
							<htk-text format="%.2d€" lot="lot" name="exceededCredit"/>
						</td>
					</tr>
				</tbody>
			</table>
		</div>
		<div id="amount-selector" class="amount-selector">
			<h2>
				_Amount to pay
			</h2>
			<div class="radio">
				<htk-radio-group
					id="pay-amount"
					lot="lot"
					name="payAmount"/>
				<div>
					<htk-radio radio-group="pay-amount" value="ALL"/>
					<label>
						_Total debt, 
						<htk-text format="%.2d€" lot="lot" name="totalDebt"/>
					</label>
				</div>
				<div>
					<htk-radio radio-group="pay-amount" value="EXCEEDED"/>
					<label>
						_Exceeded credit, 
						<htk-text format="%.2d€" lot="lot" name="exceededCredit"/>
					</label>
				</div>
			</div>
		</div>
		<div>
			<h2>
				_Pay method
			</h2>
			<div class="pay-methods radio">
				<htk-radio-group
					lot="lot"
					id="pay-method"
					name="payMethod"
					on-changed="onPayMethodChange"/>
				<div id="balance-method">
					<htk-radio id="r-balance" radio-group="pay-method" value="BALANCE"/>
					<label for="r-balance">_Use my balance</label>
					<div class="pay-info">
						_You have a favorable balance.
					</div>
				</div>
				<div id="credit-method">
					<htk-radio id="r-credit" radio-group="pay-method" value="CREDIT"/>
					<label for="r-credit">_Use my credit</label>
					<div class="pay-info">
						_You have a favorable credit.
					</div>
				</div>
				<div id="card-method">
					<htk-radio id="r-card" radio-group="pay-method" value="CARD"/>
					<label for="r-card">_Credit card</label>
					<div class="pay-info">
						_You will be redirected to the payment.
					</div>
				</div>
				<div id="transfer-method">
					<htk-radio id="r-transfer" radio-group="pay-method" value="TRANSFER"/>
					<label for="r-transfer">_Bank Transfer</label>
					<div class="pay-info">
						_Make a transfer to one account.
						<htk-repeater>
							<db-model property="model">
								SELECT description, iban, entity_id, office, dc, number
									FROM vn2008.account_customer c
							</db-model>
							<custom>
								<div class="transfer-account">
									<p>
										{{description}}
									</p>
									<p>
										{{iban}} 
										<htk-text lot="iter" name="entity_id" format="%.4d"/> 
										{{office}} {{dc}} {{number}}
									</p>
								</div>
							</custom>
						</htk-repeater>
					</div>
				</div>
				<div id="later-method">
					<htk-radio id="r-later" radio-group="pay-method" value="LATER"/>
					<label for="r-later">_Pay later</label>
				</div>
			</div>
		</div>
		<div class="button-bar">
			<button on-click="onModifyClick" id="modify" class="thin modify-order">
				_Modify
			</button>
			<button on-click="onConfirmClick" id="confirm" class="thin confirm-order">
				_Confirm
			</button>
			<div class="clear"/>
		</div>
	</div>
</div>
<htk-dialog
	id="success-dialog"
	icon="ok"
	message="_Order confirmed successfully"
	buttons="ACCEPT"
	on-response="onDialogResponse"/>
</vn>
