<?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" title="Cont"/>-->
						<set key="sum1" value="1"/>
						<!-- <modify src-key="id1" t-key-title="^(.*)$" t-key-value="^(.*)$" v-key="barcode"/>-->
						<online-request type="default" function="get_bills" params="id1">
							<actions>
								<action type="success">
									<if condition="code == 0">
										<then>
											<goto target="select_bills"/>
										</then>
										<else>
											<dialog type="Info" title="Info" message="Atentie: {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>

	<!-- e-bloc -->
	<screen id="account" type="group" title="Cod client">
		<fields>
			<text-field id="id1" keyboard="any:[en,symb]:upper:true" max-len="50" title="Cont">
				<validator type="regex">
					<rules>
						<rule regex="^.{1,50}$"/>
					</rules>
				</validator>
				<help>
					<![CDATA[<html>La acest terminal plata in contul Dvs. poate fi efectuata partial, integral sau in avans.<br/><br/>Diferenta dintre suma introdusa si suma totala de plata afisata va fi considerata plata in avans sau se va aloca in contul celei mai vechi datorii.]]>
				</help>
			</text-field>
		</fields>
		<actions>
			<action type="Next" title="Inainte">
				<set key="sum1" value="1"/>
				<online-request type="default" function="get_bills" params="id1">
					<actions>
						<action type="success">
							<if condition="code == 0">
								<then>
									<goto target="select_bills"/>
								</then>
								<else>
									<dialog type="Info" title="Eroare" message="Atentie: {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>

	<!-- Select bills -->
	<screen id="select_bills" type="communal" title="Facturi">
		<fields key="#services"/>
		<actions>
			<action type="Next" title="Next">
				<sum key="summ" result-key="ssum" input-data="#services" filter="selected=1"/>
        		<text-format-table key="ids" template="${id3}," input-data="#services" default-value="0" filter="selected=1"/>
				<text-format-table key="sums" template="${summ}," input-data="#services" default-value="0" filter="selected=1"/>
				<!-- <set-sum from="ssum" type="units"/> -->
				<clear keys="ssum"/>
				<goto target="confirm"/>
			</action>
			<action type="Prev" title="Prev">
				<goto target="account"/>
			</action>
			<action type="Exit" title="Exit">
				<goto target="exit"/>
			</action>
			<action type="Edit">
				<if condition="is-not-null #selected">
					<then>
						<unpack type="data" key="#selected" elements="editable,summ,allow-change-state,id3,name"/>
						<set key="selected" value="1" value-title="1"/>
						<pack type="data" key="#selected" elements="selected,editable,summ,allow-change-state,id3,name"/>
						<clear keys="#selected,selected,editable,summ,allow-change-state,id3,name"/>
						<goto target="select_bills"/>
					</then>
					<else>
						<if condition="is-not-null #removed">
							<then>
								<unpack type="data" key="#removed" elements="name"/>
								<dialog type="Info" title="Info" message="Doriti sa stergeti {0}?" timeout="10" default="cancel" mess-params="name">
									<actions>
										<action type="okay" title="Da">
											<set key="selected" value="0" value-title="0"/>
											<pack type="data" key="#removed" elements="selected,name"/>
											<clear keys="name,selected,#removed"/>
											<goto target="select_bills"/>
										</action>
										<action type="cancel" title="Cancel">
											<clear keys="#removed,name"/>
											<cancel/>
										</action>
									</actions>
								</dialog>
							</then>
						</if>
					</else>
				</if>
			</action>
		</actions>
	</screen>

	<!-- Confirm -->
	<screen id="confirm" type="confirm" title="Confirmare">
		<fields list="id1,id_client"/>
		<actions>
			<action type="Next" title="Achita">
				<!-- <set-sum from="sum1" type="units"/> -->
				<goto target="pay"/>
			</action>
			<action type="Prev" title="Inapoi">
				<goto target="select_bills"/>
			</action>
			<action type="Exit" title="Acasa">
				<goto target="exit"/>
			</action>
		</actions>
	</screen>
</scenario>
