{%- 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 %}
               {%- if menu %}
               {#- Increment the menu number prior to sending in XML.  According to POSitouch documentation, #}
               {#- "Menu numbers submitted should be increased by 1.  For instance, if a site wants menu #1 #}
               {#- to be applied, the Menu tag must have the value 2." #}
               <Menu>{{ menu|int + 1 }}</Menu>
               {%- endif %}
           </CheckHeader>
            {%- for item in items %}
            <ItemDetail>
                {{ macros.id_node(item.ordering_id) }}
                <Quantity>{{ item.quantity or 1 }}</Quantity>
                {%- if item.price %}
                <Price>{{ item.price }}</Price>
                {%- endif %}
            </ItemDetail>
            {%- for modifier in item.modifiers %}
                <ItemDetail>
                    {{ macros.id_node(modifier.ordering_id) }}
                    <Quantity>{{ modifier.quantity }}</Quantity>
                    {%- if modifier.memo_comment %}
                    <Memo>{{ modifier.memo_comment|e }}</Memo>
                    {%- elif modifier.item_comment %}
                    <Memo>{{ modifier.item_comment|e }}</Memo>
                    {%- endif %}
                    {%- if modifier.price %}
                    <Price>{{ modifier.price }}</Price>
                    {%- endif %}
                </ItemDetail>
                {%- if modifier.comment %}
                <ItemDetail>
                    {{ macros.id_node(comment_id) }}
                    <Memo>{{ modifier.comment|e }}</Memo>
                </ItemDetail>
                {%- endif %}
            {%- endfor %}
            {%- for discount in item.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>
                    {%- if discount.ordering_id %}
                        {{ macros.id_node(discount.ordering_id) }}
                    {%- else %}
                        {{ macros.id_node(discount.id) }}
                    {%- endif %}
                    {%- if discount.value %}
                    <Price>{{ discount.value }}</Price>
                    {%- endif %}
                </ItemDetail>
                {%- endif %}
                {%- if not discount.is_true_open_discount %}
                    {%- if discount.comment %}
                    <ItemDetail>
                        {{ macros.id_node(comment_id) }}
                        <Memo>{{ discount.comment|e }}</Memo>
                    </ItemDetail>
                    {%- endif %}
                {%- endif %}
                {%- for modifier in discount.modifiers %}
                {%- if modifier.item_comment %}
                <ItemDetail>
                    {{ macros.id_node(comment_id) }}
                    <Memo>{{ modifier.item_comment|e }}</Memo>
                </ItemDetail>
                {%- endif %}
                {%- endfor %}
            {%- endfor %}
            {%- endfor %}
       </Check>
   </UpdateOrder>
</Orders>
