<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>
                {%- if ',' in item.menu_item_id|string() %}
                <ScreenCell>{{ item.menu_item_id }}</ScreenCell>
                {%- else %}
                <ItemNumber>{{ item.menu_item_id }}</ItemNumber>
                {%- endif %}
                <Quantity>{{ item.quantity }}</Quantity>
                {%- if item.price %}
                <Price>{{ cents_to_dollars(item.price) }}</Price>
                {%- endif %}
            </ItemDetail>
                {%- for modifier in item.modifiers %}
                <ItemDetail>
                    {%- if ',' in modifier.modifier_id|string() %}
                    <ScreenCell>{{ modifier.modifier_id }}</ScreenCell>
                    {%- else %}
                    <ItemNumber>{{ modifier.modifier_id }}</ItemNumber>
                    {%- endif %}
                    <Quantity>{{ modifier.quantity }}</Quantity>
                </ItemDetail>
                {%- endfor %}
                {%- for discount in item.discounts %}
                    {%- if discount.is_true_open_discount %}
                        {%- if discount.type == 'dollar' %}
                        <OpenDollarDiscItem>
                            {%- if '-' in discount.menu_item_id|string() %}
                            <ScreenCell>{{ discount.menu_item_id.replace('-', ',') }}</ScreenCell>
                            {%- else %}
                            <ItemNumber>{{ discount.menu_item_id }}</ItemNumber>
                            {%- endif %}
                            <OpenDollarDiscAmt>{{ discount.value }}</OpenDollarDiscAmt>
                        </OpenDollarDiscItem>
                        {%- else %}
                        <OpenPercentDiscItem>
                            {%- if '-' in discount.menu_item_id|string() %}
                            <ScreenCell>{{ discount.menu_item_id.replace('-', ',') }}</ScreenCell>
                            {%- else %}
                            <ItemNumber>{{ discount.menu_item_id }}</ItemNumber>
                            {%- endif %}
                            <OpenPercentDiscPct>{{ discount.value }}</OpenPercentDiscPct>
                        </OpenPercentDiscItem>
                        {%- endif %}
                    {%- else %}
                    <ItemDetail>
                        {%- if discount.menu_item_id %}
                            {%- if '-' in discount.menu_item_id|string() %}
                            <ScreenCell>{{ discount.menu_item_id.replace('-', ',') }}</ScreenCell>
                            {%- else %}
                            <ItemNumber>{{ discount.menu_item_id }}</ItemNumber>
                            {%- endif %}
                        {%- elif '-' in discount.id|string() %}
                            <ScreenCell>{{ discount.id.replace('-', ',') }}</ScreenCell>
                        {%- else %}
                            <ItemNumber>{{ discount.id }}</ItemNumber>
                        {%- endif %}
                        {%- 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>
                        {%- if '-' in discount.menu_item_id|string() %}
                        <ScreenCell>{{ discount.menu_item_id.replace('-', ',') }}</ScreenCell>
                        {%- else %}
                        <ItemNumber>{{ discount.menu_item_id }}</ItemNumber>
                        {%- endif %}
                        <OpenDollarDiscAmt>{{ discount.value }}</OpenDollarDiscAmt>
                    </OpenDollarDiscItem>
                    {%- else %}
                    <OpenPercentDiscItem>
                        {%- if '-' in discount.menu_item_id|string() %}
                        <ScreenCell>{{ discount.menu_item_id.replace('-', ',') }}</ScreenCell>
                        {%- else %}
                        <ItemNumber>{{ discount.menu_item_id }}</ItemNumber>
                        {%- endif %}
                        <OpenPercentDiscPct>{{ discount.value }}</OpenPercentDiscPct>
                    </OpenPercentDiscItem>
                    {%- endif %}
                {%- else %}
                <ItemDetail>
                    {%- if '-' in discount.menu_item_id|string() %}
                    <ScreenCell>{{ discount.menu_item_id.replace('-', ',') }}</ScreenCell>
                    {%- else %}
                    <ItemNumber>{{ discount.menu_item_id }}</ItemNumber>
                    {%- endif %}
                    <Quantity>{{ discount.quantity or 1 }}</Quantity>
                    {%- if discount.value %}
                    <Price>{{ discount.value }}</Price>
                    {%- endif %}
                </ItemDetail>
                {%- endif %}
            {%- endfor %}
        </Check>
    </NewOrder>
</Orders>