{%- import "macros.jinja2" as macros %}
<Orders>
   <UpdateOrder>
       <Function>{{ function_value }}</Function>
       <ErrorLevel>2</ErrorLevel>
       <ReferenceNumber>{{ reference_number }}</ReferenceNumber>
       <CheckNumber>{{ ticket_number }}</CheckNumber>
       {%- if sub_ticket_number %}
       <SubCheckNumber>{{sub_ticket_number}}</SubCheckNumber>
       {%- endif %}
       <Check>
           <CheckHeader>
               {%- if terminal_number %}
               <TerminalNumber>{{ terminal_number }}</TerminalNumber>
               {%- endif %}
           </CheckHeader>
            {%- for discount in discounts %}
                {%- if discount.is_true_open_discount %}
                    {%- if discount.type == 'dollar' %}
                    <OpenDollarDiscItem>
                        {{ macros.id_node(discount.ordering_id) }}
                        <OpenDollarDiscAmt>{{ discount.value }}</OpenDollarDiscAmt>
                    </OpenDollarDiscItem>
                    {%- else %}
                    <OpenPercentDiscItem>
                        {{ macros.id_node(discount.ordering_id) }}
                        <OpenPercentDiscPct>{{ discount.value }}</OpenPercentDiscPct>
                    </OpenPercentDiscItem>
                    {%- endif %}
                {%- else %}
                <ItemDetail>
                    {{ macros.id_node(discount.ordering_id) }}
                    <Quantity>{{ discount.quantity or 1 }}</Quantity>
                    {%- if discount.value %}
                    <Price>{{ discount.value }}</Price>
                    {%- endif %}
                </ItemDetail>
                {%- endif %}
                {%- if not discount.is_true_open_discount %}
                    {%- for modifier in discount.modifiers %}
                        <ItemDetail>
                            {{ macros.id_node(modifier.ordering_id) }}
                            <Quantity>{{ modifier.quantity }}</Quantity>
                            {%- if modifier.item_comment %}
                            <Memo>{{ modifier.item_comment|e }}</Memo>
                            {%- endif %}
                        </ItemDetail>
                        {%- if modifier.comment %}
                        <ItemDetail>
                            {{ macros.id_node(comment_id) }}
                            <Memo>{{ modifier.comment|e }}</Memo>
                        </ItemDetail>
                        {%- endif %}
                    {%- endfor %}
                {%- endif %}
           {%- endfor %}
       </Check>
   </UpdateOrder>
</Orders>
