<Orders>
    {%- if user_info %}
    <AccountMaintenance>
        <AccountDetail>
            <AccountNumber>{{ user_info.account_number or '' }}</AccountNumber>
            <LastName>{{ user_info.last_name or '' }}</LastName>
            <FirstName>{{ user_info.first_name or '' }}</FirstName>
            <MiddleInitial>{{ user_info.middle_initial or '' }}</MiddleInitial>
            {%- if user_info.address %}
            <Address1>{{ user_info.address.street1 or '' }}</Address1>
            <Address2>{{ user_info.address.street2 or '' }}</Address2>
            <Address3>{{ user_info.address.street3 or '' }}</Address3>
            <City>{{ user_info.address.city or '' }}</City>
            <State>{{ user_info.address.state or '' }}</State>
            <Zip>{{ user_info.address.zip or '' }}</Zip>
            {%- endif %}
            <Phone>{{ user_info.phone or '' }}</Phone>
            <PhoneExt>{{ user_info.phone_ext or '' }}</PhoneExt>
        </AccountDetail>
    </AccountMaintenance>
    {%- endif %}
    <NewOrder>
        <Function>{{ function_value }}</Function>
        <ErrorLevel>2</ErrorLevel>
        <ReferenceNumber>{{ reference_number }}</ReferenceNumber>
        <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 or '' }}</LastName>
                    <FirstName>{{ user_info.first_name or '' }}</FirstName>
                    <MiddleInitial>{{ user_info.middle_initial or '' }}</MiddleInitial>
                </Account>
                {%- endif %}
                {%- if fire_time %}
                <AdvanceOrderDate>{{ fire_date }}</AdvanceOrderDate>
                <AdvanceOrderTime>{{ fire_time }}</AdvanceOrderTime>
                {%- endif %}
            </CheckHeader>
            {%- if ticket_name and ticket_name_data_set %}
            <ItemDetail>
                <ScreenCell>{{ ticket_name_item_screen_cell_id }}</ScreenCell>
                <Quantity>1</Quantity>
                <ItemName>NAME</ItemName>
            </ItemDetail>
            <ItemDetail>
                {%- if ticket_name_modifier_screen_cell_id -%}
                <ScreenCell>{{ ticket_name_modifier_screen_cell_id }}</ScreenCell>
                {%- else %}
                <ItemNumber>{{ ticket_name_modifier_inv_id }}</ItemNumber>
                {%- endif %}
                <Quantity>1</Quantity>
                <ItemName>NAME</ItemName>
                <Memo>{{ ticket_name }}</Memo>
            </ItemDetail>
            {%- endif %}
            {%- for item in items %}
            <ItemDetail>
                {%- if '-' in item.menu_item_id|string() %}
                <ScreenCell>{{ item.menu_item_id.replace('-', ',') }}</ScreenCell>
                {%- else %}
                <ItemNumber>{{ item.menu_item_id }}</ItemNumber>
                {%- endif %}
                <Quantity>{{ item.quantity or 1 }}</Quantity>
                {%- if item.price_per_unit %}
                <Price>{{ item.price_per_unit }}</Price>
                {%- endif %}
            </ItemDetail>
            {%- if item.comment %}
                <ItemDetail>
                    {%- if '-' in comment_id|string() -%}
                    <ScreenCell>{{ comment_id.replace('-', ',') }}</ScreenCell>
                    {%- else %}
                    <ItemNumber>{{ comment_id }}</ItemNumber>
                    {%- endif %}
                    <Memo>{{ item.comment[0:23] + '_' }}</Memo>
                </ItemDetail>
            {%- endif %}
            {%- for modifier in item.modifiers %}
                <ItemDetail>
                    {%- if '-' in modifier.modifier_id|string() %}
                    <ScreenCell>{{ modifier.modifier_id.replace('-', ',') }}</ScreenCell>
                    {%- else %}
                    <ItemNumber>{{ modifier.modifier_id }}</ItemNumber>
                    {%- endif %}
                    <Quantity>{{ modifier.quantity }}</Quantity>
                    {%- if modifier.memo_comment %}
                    <Memo>{{ modifier.memo_comment[0:24] }}</Memo>
                    {%- elif modifier.item_comment %}
                    <Memo>{{ modifier.item_comment[0:23] + '_' }}</Memo>
                    {%- endif %}
                </ItemDetail>
                {%- if modifier.comment %}
                <ItemDetail>
                    {%- if '-' in comment_id|string() %}
                    <ScreenCell>{{ comment_id.replace('-', ',') }}</ScreenCell>
                    {%- else %}
                    <ItemNumber>{{ comment_id }}</ItemNumber>
                    {%- endif %}
                    <Memo>{{ modifier.comment[0:23] + '_' }}</Memo>
                </ItemDetail>
                {%- endif %}
            {%- 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 %}
                {%- if not discount.is_true_open_discount %}
                    {%- if discount.comment %}
                    <ItemDetail>
                        {%- if '-' in comment_id|string() %}
                        <ScreenCell>{{ comment_id.replace('-', ',') }}</ScreenCell>
                        {%- else %}
                        <ItemNumber>{{ comment_id }}</ItemNumber>
                        {%- endif %}
                        <Memo>{{ discount.comment[0:23] + '_' }}</Memo>
                    </ItemDetail>
                    {%- endif %}
                {%- 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 %}
                {%- if not discount.is_true_open_discount %}
                    {%- if discount.comment %}
                        <ItemDetail>
                            {%- if '-' in comment_id|string() -%}
                            <ScreenCell>{{ comment_id.replace('-', ',') }}</ScreenCell>
                            {%- else %}
                            <ItemNumber>{{ comment_id }}</ItemNumber>
                            {%- endif %}
                            <Memo>{{ discount.comment[0:23] + '_' }}</Memo>
                        </ItemDetail>
                    {%- endif %}
                    {%- for modifier in discount.modifiers %}
                        <ItemDetail>
                            {%- if '-' in modifier.modifier_id|string() %}
                            <ScreenCell>{{ modifier.modifier_id.replace('-', ',') }}</ScreenCell>
                            {%- else %}
                            <ItemNumber>{{ modifier.modifier_id }}</ItemNumber>
                            {%- endif %}
                            <Quantity>{{ modifier.quantity }}</Quantity>
                            {%- if modifier.memo_comment %}
                            <Memo>{{ modifier.memo_comment[0:24] }}</Memo>
                            {%- elif modifier.item_comment %}
                            <Memo>{{ modifier.item_comment[0:23] + '_' }}</Memo>
                            {%- endif %}
                        </ItemDetail>
                        {%- if modifier.comment %}
                        <ItemDetail>
                            {%- if '-' in comment_id|string() %}
                            <ScreenCell>{{ comment_id.replace('-', ',') }}</ScreenCell>
                            {%- else %}
                            <ItemNumber>{{ comment_id }}</ItemNumber>
                            {%- endif %}
                            <Memo>{{ modifier.comment[0:23] + '_' }}</Memo>
                        </ItemDetail>
                        {%- endif %}
                    {%- endfor %}
                {%- endif %}
            {%- endfor %}
        </Check>
            {%- for payment in payments %}
            <CreditCardAuth>
                <CardNumber>{{ payment.masked_card_number or payment.card_number }}</CardNumber>
                <ExpirationDate>{{ payment.expiration_date }}</ExpirationDate>
                <ReferenceNumber>{{ payment.reference_number }}</ReferenceNumber>
                <ApprovalCode>{{ payment.approval_code }}</ApprovalCode>
                <Amount>{{ payment.converted_payment }}</Amount>
                {%- if payment.gift_card_balance %}
                <GCRemainingBalance>{{ payment.gift_card_balance }}</GCRemainingBalance>
                {%- endif %}
                {%- if payment.type == '3rd_party' %}
                <DebitProcessing>Y</DebitProcessing>
                {%- endif %}
                <Gratuity>{{ payment.converted_tip }}</Gratuity>
                <SlipCopies>{{ slip_copies }}</SlipCopies>
                <Debit>N</Debit>
                {%- if payment.full_name %}
                <CardholderName>{{ payment.full_name }}</CardholderName>
                {%- endif %}
            </CreditCardAuth>
            {%- endfor %}
    </NewOrder>
</Orders>