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

	<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="Plata catre operatorul: {0}" timeout="10" default="okay" mess-params="service_">
							<actions>
								<action type="okay" title="OK"/>
							</actions>
						</dialog>
						<!--						<set key="id1" value="0"/>-->
						<!-- <modify src-key="id1" t-key-title="^(.*)$" t-key-value="^(.*)$" v-key="barcode"/>-->
						<online-request type="default" function="adv-check" params="id1">
							<actions>
								<action type="success">
									<if condition="code == 0">
										<then>
											<goto target="confirm"/>
										</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>
					</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>

	<screen id="account" type="group" title="Introduceti codul de client">
		<fields>
			<text-field id="id1" keyboard="any:[en,symb]:upper:true" max-len="99" title="Cod client">
				<validator type="regex">
					<rules>
						<rule regex="^.{1,6}/[0-9]{1,2}/[0-9]{1,6}$"/>
					</rules>
				</validator>
				<help>
					<![CDATA[<html>Introduceti referinta unica (ex.: SRF/2/15673) sau scanati codul de bare]]>
				</help>
			</text-field>
		</fields>
		<barcode-scanner show-error="true" on-success="next">
			<barcode-parser type="regex">
				<rules validate="^.*$">
					<rule key="id1" title="Codul de client" regex="^[a-zA-Z0-9]{15,25}$" is-bind="true"/>
					<rule key="barcode" title="Barcode" regex="^.*$" is-bind="true"/>
				</rules>
			</barcode-parser>
		</barcode-scanner>
		<actions>
			<action type="Next">
				<if condition="is-not-null barcode">
					<then>
						<online-request type="default" function="adv-check" params="id1">
							<actions>
								<action type="success">
									<if condition="code == 0">
										<then>
											<goto target="confirm"/>
										</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>
					</then>
					<else>
						<goto target="cnp"/>
					</else>
				</if>
			</action>
			<action type="Prev">
				<goto target="exit"/>
			</action>
			<action type="Exit">
				<goto target="exit"/>
			</action>
		</actions>
	</screen>

	<screen id="cnp" type="numeric" title="Introduceti CNP">
		<fields>
			<text-field id="cnp" keyboard="Digital" max-len="99" message="Introduceti CNP-ul" title="CNP">
				<validator type="regex">
					<rules>
						<rule regex="^[1-9]([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>
			</text-field>
		</fields>
		<actions>
			<action type="Next">
				<goto target="telefon"/>
			</action>
			<action type="Prev">
				<goto target="account"/>
			</action>
			<action type="Exit">
				<goto target="exit"/>
			</action>
		</actions>
	</screen>

	<!-- KRUK -->
	<screen id="telefon" type="numeric" title="Telefon">
		<fields>
			<text-field id="telefon" keyboard="Digital" max-len="99" message="Introduceti numarul de telefon" title="Telefon">
				<validator type="regex">
					<rules>
						<rule regex="^07[0-9]{8}$"/>
					</rules>
				</validator>
			</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">
				<online-request type="default" function="adv-check" params="id1,cnp,telefon">
					<actions>
						<action type="success">
							<if condition="code == 0">
								<then>
									<goto target="confirm"/>
								</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="previous"/>
			</action>
			<action type="Exit" title="Pagina principala">
				<goto target="exit"/>
			</action>
		</actions>
	</screen>

	<!-- Confirm -->
	<screen id="confirm" type="confirm" title="Confirmare">
		<fields list="client"/>
		<actions>
			<action type="Next" title="Achita">
				<goto target="pay"/>
			</action>
			<action type="Prev" title="Inapoi">
				<goto target="account"/>
			</action>
			<action type="Exit" title="Acasa">
				<goto target="exit"/>
			</action>
		</actions>
	</screen>
</scenario>
