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

	<!-- DITL Oltenita -->
	<screen id="account" type="numeric" title="Cod client">
		<fields>
			<text-field id="id1" keyboard="Digital" max-len="13" title="CNP / CIF">
				<validator type="regex">
					<rules>
<!--						<rule regex="(^[0-9]{13}$)|(^[0-9]{2,9}$)"/>-->
						<rule regex="^[0-9]{1,13}"/>
					</rules>
				</validator>
				<help>
					<![CDATA[<html>]]>
				</help>
			</text-field>
		</fields>
		<actions>
			<action type="Next" title="Inainte">
				<set key="sum1" value="1"/>
				<set key="service_name" value="DITL_Oltenita"/>
				<online-request type="default" function="get_taxes" params="id1,service_name">
					<actions>
						<goto-action type="success" target="select_bills"/>
						<action type="error">
							<dialog type="Info" title="Eroare" message="Lista taxelor este inaccesibila momentan" 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="#taxes"/>
		<actions>
			<action type="Next" title="Next">
				<sum key="summ" result-key="ssum" input-data="#taxes" filter="selected=1"/>
        		<text-format-table key="ids" template="${id3}," input-data="#taxes" default-value="0" filter="selected=1"/>
				<text-format-table key="priors" template="${prioritate}," input-data="#taxes" default-value="0" filter="selected=1"/>
				<text-format-table key="ibans" template="${iban}," input-data="#taxes" 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,prioritate,iban"/>
						<set key="selected" value="1" value-title="1"/>
						<pack type="data" key="#selected" elements="selected,editable,summ,allow-change-state,id3,name,prioritate,iban"/>
						<clear keys="#selected,selected,editable,summ,allow-change-state,id3,name,prioritate,iban"/>
						<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="Nu">
											<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"/>
		<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>
