<?xml version="1.0" encoding="UTF-8"?>
<scenario begin="select_category">

	<!-- Select category -->
	<screen id="select_category" type="selector/image" title="Alege categoria">
		<fields>
			<selector-field id="category" title="Categorii autoturisme">
				<items type="static">
					<item value="1" title="TBI Bank" image="tbi_bank.png"/>
					<item value="2" title="TBI Money" image="tbi_money.png"/>
				</items>
			</selector-field>
		</fields>
		<actions>
			<action type="Next" title="Inainte">
				<goto target="online_request"/>
			</action>
			<action type="Prev" title="Inapoi">
				<goto target="exit"/>
			</action>
			<action type="Exit" title="Pagina principala">
				<goto target="exit"/>
			</action>
		</actions>
	</screen>

	<screen type="void" decor="button" title="" id="online_request">
		<fields/>
		<actions>
			<action type="Next" title="Verifica lista prodiselor">
				<if condition="is-not-null id1">
					<then>
						<dialog type="Info" title="Info" message="Verificam: {0}" timeout="10" default="okay" mess-params="service_">
							<actions>
								<action type="okay" title="OK"/>
							</actions>
						</dialog>
						<set key="bills" value="0"/>
						<load from="point.city" key="trm_location"/>
<!--						<set key="id1" value="0"/>-->
<!--						<modify src-key="id1" t-key-title="^(.*)$" t-key-value="^(.*)$" v-key="barcode"/>-->
						<online-request type="default" function="get_bills" params="id1,bills">
							<actions>
								<action type="success">
									<if condition="code == 0">
										<then>
											<goto target="select_bill"/>
										</then>
										<else>
											<dialog type="Info" title="Eroare" message="Eroare: {0}" timeout="10" default="okay" mess-params="exception">
												<actions>
													<action type="okay" title="OK">
														<cancel/>
													</action>
												</actions>
											</dialog>
										</else>
									</if>
								</action>
								<action type="error">
									<dialog type="Info" title="Eroare" message="A intervenit o eroare, va rugam sa incercati din nou" timeout="10" default="okay">
										<actions>
											<action type="okay" title="OK">
												<goto target="account"/>
											</action>
										</actions>
									</dialog>
								</action>
							</actions>
						</online-request>
					</then>
					<else>
						<goto target="account"/>
					</else>
				</if>
			</action>
			<goto-action type="Inapoi" title="Inapoi" target="previous"/>
			<goto-action type="Pagina principala" title="Pagina principala" target="exit"/>
		</actions>
	</screen>

		<!-- TBI Credit-->
		<screen id="account" type="numeric" title="Introduceti codul de client">
			<fields>
				<text-field id="id1" keyboard="Digital" max-len="99" message="Introduceti codul de client sau scanati codul de bare" title="Cod client">
					<validator type="regex">
						<rules>
							<rule regex="^[0-9]+$"/>
<!--							<rule regex="^[1-8]([0-9]{2})(0[1-9]|1[012])([123]0|[012][1-9]|31)(0[1-9]|[1234][0-9]|5[012])[0-9]{4}$"/>-->
						</rules>
					</validator>
					<help>
						<![CDATA[<html>Scanati codul de bare sau introduceti datele manual.]]>
					</help>
				</text-field>
			</fields>
			<barcode-scanner>
				<barcode-parser type="regex" >
					<rules validate="^.*$">
						<rule key="id1" title="Cod" regex="^(.*)$" is-bind="true"/>
					</rules>
				</barcode-parser>
			</barcode-scanner>
			<actions>
				<action type="Next" title="Inainte">
					<goto target="online"/>
				</action>
				<action type="Prev" title="Inapoi">
					<goto target="select_category"/>
				</action>
				<action type="Exit" title="Acasa">
					<goto target="exit"/>
				</action>
			</actions>
		</screen>

	<screen id="online" type="void" title="Lista facturi">
		<fields/>
		<actions>
			<action type="Next" title="Inainte">
				<set key="bills" value="0"/>
				<load from="point.city" key="trm_location"/>
				<online-request type="default" function="get_bills" params="id1,bills">
					<actions>
						<action type="success">
							<if condition="code == 0">
								<then>
									<goto target="select_bill"/>
								</then>
								<else>
									<dialog type="Info" title="Eroare" message="Eroare: {0}" timeout="10" default="okay" mess-params="exception">
										<actions>
											<action type="okay" title="OK">
												<cancel/>
											</action>
										</actions>
									</dialog>
								</else>
							</if>
						</action>
						<action type="error">
							<dialog type="Info" title="Eroare" message="A intervenit o eroare, va rugam sa incercati din nou" timeout="10" default="okay">
								<actions>
									<action type="okay" title="OK">
										<cancel/>
									</action>
								</actions>
							</dialog>
						</action>
					</actions>
				</online-request>
			</action>
			<action type="Prev" title="Inapoi">
				<goto target="account"/>
			</action>
			<action type="Exit" title="Pagina principala">
				<goto target="exit"/>
			</action>
		</actions>
	</screen>

		<!-- Select product -->
		<screen id="select_bill" type="table" title="Alege factura">
			<fields>
				<table-field id="tf" title="Tabel" read-only="false">
					<columns>
						<column key="ContractNumber" title="Contract" width="0.4"/>
						<column key="NextInstallmentDate" title="Data" width="0.3"/>
						<column key="MinimumPaymentAmount" title="Suma" width="0.3"/>
					</columns>
					<items type="data" key="#bills"/>
				</table-field>
			</fields>
			<actions>
				<action type="Next" title="Inainte">
<!--					<set key="summ" value="1"/>-->
<!--					<modify src-key="price" t-key-title="^(.*)$" v-key-title="Pret" />-->
<!--					<modify src-key="product" t-key-title="^(.*)$" v-key-title="Produs" />-->
					<!--<modify src-key="productName" t-key-title="^(.*)$" v-key-title="Produs" />
					<set key="id1" value="#productName#"/>
					<modify src-key="id1" t-key-title="^(.*)$" v-key-title="Produs" t-key-value="^(.*)$" v-key-value="productName"  />-->
					<goto target="confirm"/>
				</action>
				<action type="Prev" title="Inapoi">
					<goto target="account"/>
				</action>
				<action type="Exit" title="Pagina principala">
					<goto target="exit"/>
				</action>
			</actions>
		</screen>

	<!-- Confirm -->
	<screen id="confirm" type="confirm" title="Confirmare">
		<fields list="ContractNumber,NextInstallmentDate,MinimumPaymentAmount"/>
		<actions>
			<action type="Next" title="Achita">
<!--				<set-sum from="summ" type="units"/>-->
<!--				<set-sum from="MinimumPaymentAmount" type="units"/>-->
				<goto target="pay"/>
			</action>
			<action type="Prev" title="Inapoi">
				<goto target="online"/>
			</action>
			<action type="Exit" title="Acasa">
				<goto target="exit"/>
			</action>
		</actions>
	</screen>
</scenario>
