{%- import "macros.jinja2" as macros %}
<Orders>
    <NewOrder>
        <Function>2</Function>
        <ErrorLevel>1</ErrorLevel>
        <ReferenceNumber>{{ reference_number }}</ReferenceNumber>
        <Check>
            <CheckHeader>
                {%- if table_number %}
                <TableNumber>{{ table_number }}</TableNumber>
                {%- endif %}
                {%- if revenue_center %}
                <CostCenter>{{ revenue_center }}</CostCenter>
                {%- endif %}
                {%- if server_number %}
                <ServerNumber>{{ server_number }}</ServerNumber>
                {%- endif %}
                <NumberInParty>1</NumberInParty>
            </CheckHeader>
            {%- for item in items %}
            <ItemDetail>
                {{ macros.id_node(item.ordering_id) }}
                <Quantity>{{ item.quantity or 1 }}</Quantity>
                {%- if item.price %}
                <Price>{{ cents_to_dollars(item.price) }}</Price>
                {%- endif %}
            </ItemDetail>
                {%- for modifier in item.modifiers %}
                <ItemDetail>
                    {{ macros.id_node(modifier.ordering_id) }}
                    <Quantity>{{ modifier.quantity or 1 }}</Quantity>
                </ItemDetail>
                {%- 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>
                        {{ macros.id_node(discount.ordering_id) }}
                        {%- if discount.value %}
                        <Price>{{ discount.value }}</Price>
                        {%- endif %}
                    </ItemDetail>
                    {%- endif %}
                {%- 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 %}
            {%- endfor %}
        </Check>
    </NewOrder>
</Orders>