<?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"/>-->
						<set key="service_name" value="EngieG"/>
						<set key="channel" value="RBN"/>
						<online-request type="default" function="adv-check" params="id1,service_name,channel">
							<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>

	<!-- Engie gaze -->
	<!-- Client code or barcode -->
	<screen id="account" type="numeric" title="Introduceti codul de client sau scanati codul de bare">
		<fields>
			<text-field id="id1" keyboard="Digital" max-len="99" message="Introduceti codul de client sau scanati codul de bare" title="Cod de client">
				<validator type="regex">
					<rules>
						<rule regex="(^[0-9]{12}$)|(^[0-9]{27}$)|(^[0-9]{33}$)"/>
					</rules>
				</validator>
				<help>
					<![CDATA[<html>Scanati codul de bare sau introduceti datele manual.]]>
				</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="^[0-9]{12,40}$" is-bind="true"/>
					<rule key="barcode" title="Barcode" regex="^.*$" is-bind="true"/>
				</rules>
			</barcode-parser>
		</barcode-scanner>
		<actions>
			<action type="Next" title="Inainte">
				<if condition="is-not-null barcode">
					<then>
						<set key="service_name" value="EngieG"/>
						<set key="channel" value="RBN"/>
						<online-request type="default" function="adv-check" params="id1,service_name,channel">
						<actions>
								<action type="success">
									<if condition="code == 0">
										<then>
											<goto target="confirm"/>
										</then>
										<else>
											<dialog type="Info" title="Eroare" message="{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="factura"/>
					</else>
				</if>
			</action>
			<action type="Prev" title="Inapoi">
				<goto target="previous"/>
			</action>
			<action type="Exit" title="Pagina principala">
				<goto target="exit"/>
			</action>
		</actions>
	</screen>

	<screen id="factura" type="numeric" title="Introduceti numarul facturii">
		<fields>
			<text-field id="factura" keyboard="Digital" max-len="99" message="Introduceti numarul de factura" title="Factura">
				<validator type="regex">
					<rules>
						<rule regex="(^[0-9]{11}$)"/>
					</rules>
				</validator>
			</text-field>
		</fields>
		<actions>
			<action type="Next" title="Inainte">
				<set key="service_name" value="EngieG"/>
				<set key="channel" value="RBN"/>
				<online-request type="default" function="adv-check" params="id1,factura,service_name,channel">
					<actions>
						<action type="success">
							<if condition="code == 0">
								<then>
									<goto target="confirm"/>
								</then>
								<else>
									<dialog type="Info" title="Eroare" message="{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>

	<!-- Confirm -->
	<screen id="confirm" type="confirm" title="Confirmare">
		<fields list="cod_client,factura,suma"/>
		<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>
