<?xml version="1.0" encoding="UTF-8"?>
<scenario begin="LoadInfo">
    
    <!-- Load Info Page
    ID: 99 / 1099 - Apa Nova Bucuresti
    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 client
    - Sa continta doar cifre;
    - Sa permita continuarea doar la indeplinirea celor 8 cifre;
    -->
    <screen id="StepOne" type="numeric" title="Introduceti codul de client">
        <fields>
            <text-field id="id1" keyboard="Digital" max-len="8" title="Codul de client">
                <validator type="regex">
                    <rules>
                        <rule regex="^\d{8}$"/>
                    </rules>
                </validator>
                <help>
                    <![CDATA[<html><img src="$terminal_home/resources/info/specimen_factura.png"/>]]>
                </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 client" regex="^(\d{8})" is-bind="true"/>
                    <rule key="id2" title="Numarul de factura" regex="ANB(\d{7,9})" is-bind="true"/>
                    <rule key="date" title="Data emiterii" regex="ANB\d{7,9}([0-9]{6})" is-bind="true"/>
                    <rule key="sum" title="Total factura" regex="(0|[1-9][0-9]{0,6})$" 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 date">
                <then>
                    <modify src-key="id2" t-value="^(.*)$" t-value-title="^(.*)$" v-value="$1" v-value-title="ANB $1"/>
                    <modify src-key="date" t-value-title="^(\d{2})(\d{2})(\d{2})$" v-value-title="$1.$2.20$3"/>
                    <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 continta prefixul ANB;
    - Sa fie lungimea maxima 12 impreuna cu prefixul;
    - Sa fie numarul de factura pana in 9 cifre;
    - Sa permita continuarea daca se ajunge la 7 cifre;
    -->
    <screen id="StepTwo" type="numeric" title="Introduceti numarul de factura">
        <fields>
            <text-field id="id2" keyboard="Digital" prefix="ANB" max-len="12" title="Numarul de factura">
                <validator type="regex">
                    <rules>
                        <rule regex="^ANB(\d{7,9})$"/>
                    </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">
                <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="^\d{10}$"/>
                    </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">
                <goto target="ConfirmPage"/>
            </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="id1,id2,id3,date,sum"/>
        <actions>
          <action type="Next" title="Achita">
            <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>
