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

    <!-- Load Info Page
    ID: 213 / 1213 - E-ON Asist Complet
    Smith & Smith
    -->
    <screen type="Void" id="LoadInfo">
        <actions>
            <action type="Next">
                <set key="#file" value="file://smith.html" />
                <goto target="InfoPage"/>
            </action>
        </actions>
    </screen>

    <!-- Info -->
    <screen id="InfoPage" type="info" title="Informare">
        <field key="#file" />
        <actions>
            <action type="Next">
                <goto target="StepOne"/>
            </action>
            <action type="Prev">
                <goto target="previous"/>
            </action>
            <action type="Exit">
                <goto target="exit"/>
            </action>
        </actions>
    </screen>


    <!-- Codul de incasare
    - Sa contina doar cifre;
    - Sa permita continuarea doar la indeplinirea celor 10 cifre;
    -->
    <screen id="StepOne" type="numeric" title="Introduceti codul de incasare">
        <fields>
            <text-field id="id1" keyboard="Digital" max-len="10" title="Codul de incasare">
                <validator type="regex">
                    <rules>
                        <rule regex="^\d{10}$"/>
                    </rules>
                </validator>
                <help>
                    <![CDATA[<html>Completati cele 10 cifre ale codului de incasare (prima cifra este 2 sau 9).]]>
                    <![CDATA[<html><br/>Optiuni disponibile:<br/>1. Introducere manuala a datelor.<br/>2. Scanare a codului de bare.]]>
                </help>
            </text-field>
        </fields>
        <!-- Parse BarCode -->
        <barcode-scanner show-error="true" on-success="next">
            <barcode-parser type="regex">
                <rules validate="^.*$">
                    <rule key="id1" title="Codul de incasare" regex="^(\d{10})\d{29}$" is-bind="true"/>
                    <rule key="id2" title="Numarul de factura" regex="^\d{12}(?:00(\d{12})|0(\d{13})|(\d{14}))\d{13}$" is-bind="true"/>
                    <rule key="sum" title="Total factura" regex="(0|[1-9][0-9]{0,6})$" is-bind="true"/>
                    <rule key="region" title="Regiune" regex="^\d{10}(\d{2})" is-bind="true"/>
                    <rule key="barcode" title="Barcode" regex="^.*$" is-bind="true"/>
                </rules>
            </barcode-parser>
        </barcode-scanner>
        <actions>
            <action type="Next">
                <!-- Make Barcode variables readable -->
                <if condition="is-not-null id2">
                    <then>
                        <switch value="region">
                            <case value="22">
                                <set key="region" key-title="Cont colector" value="22" value-title="E.ON Energie Romania"/>
                            </case>
                            <case value="33">
                                <set key="region" key-title="Cont colector" value="33" value-title="E.ON Energie Romania clienti KAM"/>
                            </case>
                            <case value="44">
                                <set key="region" key-title="Cont colector" value="44" value-title="E.ON Gaz Distributie"/>
                            </case>
                            <case value="55">
                                <set key="region" key-title="Cont colector" value="55" value-title="E.ON Moldova Distributie"/>
                            </case>
                            <case value="77">
                                <set key="region" key-title="Cont colector" value="77" value-title="SEA Complet"/>
                            </case>
                            <default/>
                        </switch>
                        <modify src-key="sum" t-value="^(\d{1,4}?)(\d{2})$" t-value-title="^(\d{1,4}?)(\d{2})$" v-value="$1.$2" v-value-title="$1.$2 LEI"/>
                        <goto target="PhoneNumber"/>
                    </then>
                    <else>
                        <goto target="StepTwo"/>
                    </else>
                </if>
            </action>
            <action type="Prev">
                <goto target="InfoPage"/>
            </action>
            <action type="Exit">
                <goto target="exit"/>
            </action>
        </actions>
    </screen>

    <!-- Numarul de factura
    - Sa contina doar cifre;
    - Sa fie lungimea maxima 14, E-ON mai are doua zero-uri libere;
    - Sa permita continuarea doar la indeplinirea celor 12 cifre, numarul curent de cifre folosit;
    -->
    <screen id="StepTwo" type="numeric" title="Introduceti numarul de factura">
        <fields>
            <text-field id="id2" keyboard="Digital" max-len="14" title="Numarul de factura">
                <validator type="regex">
                    <rules>
                        <rule regex="^(\d{11,14})$"/>
                    </rules>
                </validator>
                <help>

                    <![CDATA[<html>Introduceti numarul facturii pe care doriti sa o achitati.]]>
                </help>
            </text-field>
        </fields>
        <actions>
            <action type="Next">
                <goto target="PhoneNumber"/>
            </action>
            <action type="Prev">
                <goto target="StepOne"/>
            </action>
            <action type="Exit">
                <goto target="exit"/>
            </action>
        </actions>
    </screen>

    <!-- Numarul de telefon
    - Sa contina prefixul 07, doar retea mobila;
    - Sa fie lungimea maxima 10 impreuna cu prefixul;
    - Sa permita continuarea doar la indeplinirea celor 10 cifre;
    -->
    <screen id="PhoneNumber" type="numeric" title="Introduceti numarul de telefon">
        <fields>
            <text-field id="id3" keyboard="Digital" max-len="10" title="Numarul de telefon">
                <validator type="regex">
                    <rules>
                        <rule regex="^07(\d{8}$)"/>
                    </rules>
                </validator>
                <formatter type="regex">
                    <rules default="**** *** ***"/>
                </formatter>
                <help>
                    <![CDATA[<html>Prin continuarea tranzactiei va dati acordul pentru plata unui comision de <b>3 RON</b> pentru procesarea acestei plati;]]>
                </help>
            </text-field>
        </fields>
        <actions>
            <action type="Next">
                <set key="service_name" value="EONasistC"/>
                <online-request type="default" function="check_request" params="id1,id2,id3,service_name">
                    <actions>
                        <action type="success">
                            <if condition="code == 0">
                                <then>
                                    <goto target="ConfirmPage"/>
                                </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">
                <goto target="StepTwo"/>
            </action>
            <action type="Exit">
                <goto target="exit"/>
            </action>
        </actions>
    </screen>

    <!-- Confirm -->
    <screen id="ConfirmPage" type="confirm" title="Verificati corectitudinea datelor introduse">
        <fields list="region,id1,id2,id3,sum"/>
        <actions>
            <action type="Next" title="Achita">
                <clear keys="#file"/>
                <dialog type="Info" title="Info" message="Sunteti de acord cu prelucrarea datelor cu caracter personal in scopuri de marketing?" timeout="10" default="cancel" mess-params="name">
                    <actions>
                        <action type="okay" title="Da">
                            <set key="gdpr" value="1"/>
                            <goto target="pay"/>
                        </action>
                        <action type="cancel" title="Nu">
                            <set key="gdpr" value="0"/>
                            <goto target="pay"/>
                        </action>
                    </actions>
                </dialog>
            </action>
            <action type="Prev" title="Inapoi">
                <goto target="StepOne"/>
            </action>
            <action type="Exit" title="Acasa">
                <goto target="exit"/>
            </action>
        </actions>
    </screen>
</scenario>
