{%- import "macros.jinja2" as macros %}
<Orders>
    <ResubmitOrder>
        <Function>{{ function_value }}</Function>
        <ErrorLevel>2</ErrorLevel>
        <CheckNumber>{{ check_number }}</CheckNumber>
        {%- if sub_check_number %}
        <SubCheckNumber>{{sub_check_number}}</SubCheckNumber>
        {%- endif %}
        <Check>
            <CheckHeader>
                <TableNumber>{{ table_number }}</TableNumber>
                <CostCenter>{{ revenue_center }}</CostCenter>
                <ServerNumber>{{ server_number }}</ServerNumber>
                <NumberInParty>{{ number_in_party }}</NumberInParty>
                {%- if terminal_number %}
                <TerminalNumber>{{ terminal_number }}</TerminalNumber>
                {%- endif %}
                {%- if user_info %}
                <Account>
                    <AccountNumber>{{ user_info.account_number or '' }}</AccountNumber>
                    <LastName>{{ user_info.last_name|e or '' }}</LastName>
                    <FirstName>{{ user_info.first_name|e or '' }}</FirstName>
                    <MiddleInitial>{{ user_info.middle_initial|e or '' }}</MiddleInitial>
                </Account>
                {%- endif %}
                {%- if fire_time %}
                <AdvanceOrderDate>{{ fire_date }}</AdvanceOrderDate>
                <AdvanceOrderTime>{{ fire_time }}</AdvanceOrderTime>
                {%- endif %}
            </CheckHeader>
            {%- if ticket_name and ticket_name_item and ticket_name_modifier %}
            <ItemDetail>
                {{ macros.id_node(ticket_name_item) }}
                <Quantity>1</Quantity>
                <ItemName>NAME</ItemName>
            </ItemDetail>
            <ItemDetail>
                {{ macros.id_node(ticket_name_modifier) }}
                <Quantity>1</Quantity>
                <ItemName>NAME</ItemName>
                <Memo>{{ ticket_name|e }}</Memo>
            </ItemDetail>
            {%- endif %}
            {%- for item in items %}
            <ItemDetail>
                {{ macros.id_node(item.ordering_id) }}
                <Quantity>{{ item.quantity or 1 }}</Quantity>
                {%- if item.price_per_unit %}
                <Price>{{ item.price_per_unit }}</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 %}
                </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 %}
            {%- 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>
    </ResubmitOrder>
</Orders>