<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
    <soap:Body>
        <AddToExistingCheckEx xmlns="http://micros-hosting.com/EGateway/">
            <vendorCode />
            <pGuestCheck>
                {%- if fire_date_time is not none %}
                <CheckDateToFire>{{ fire_date_time }}</CheckDateToFire>
                {%- endif %}
                {%- if check_status_bits is not none %}
                <CheckStatusBits>{{ check_status_bits }}</CheckStatusBits>
                {%- endif %}
                <CheckEmployeeObjectNum>{{ employee_num }}</CheckEmployeeObjectNum>
                <CheckGuestCount>{{ guest_count }}</CheckGuestCount>
                {%- if name is not none %}
                <CheckID>{{ check_name }}</CheckID>
                {%- endif %}
                <CheckNum>{{ check_num }}</CheckNum>
                <CheckOrderType>{{ order_type }}</CheckOrderType>
                <CheckRevenueCenterID>{{ revenue_center }}</CheckRevenueCenterID>
                <CheckSeq>{{ check_seq }}</CheckSeq>
                {%- if table_number is not none %}
                <CheckTableObjectNum>{{ table_number }}</CheckTableObjectNum>
                {%- endif %}
            </pGuestCheck>
            <ppMenuItems>
                {%- if items is not none %}
                {%- for item in items %}
                <SimphonyPosApi_MenuItem>
                    {%- if item.modifiers %}
                    <Condiments>
                        {%- for modifier in item.modifiers %}
                        <SimphonyPosApi_MenuItemDefinition>
                            <ItemDiscount>
                                <DiscObjectNum>0</DiscObjectNum>
                            </ItemDiscount>
                            {% set mod_obj_num = modifier.menu_modifier.id.split('-')[0] %}
                            <MiObjectNum>{{ mod_obj_num }}</MiObjectNum>
                            {%- if modifier.comment is not none %}
                            <MiReference>{{ modifier.comment }}</MiReference>
                            {%- endif %}
                            <MiWeight />
                            <MiMenuLevel>{{ modifier.main_level }}</MiMenuLevel>
                            <MiSubLevel>{{ modifier.sub_level }}</MiSubLevel>
                            {%- if modifier.price_per_unit is not none %}
                            <MiOverridePrice>{{ cents_to_dollars(modifier.price_per_unit) }}</MiOverridePrice>
                            {%- endif %}
                        </SimphonyPosApi_MenuItemDefinition>
                        {%- endfor %}
                    </Condiments>
                    {%- endif %}
                    <MenuItem>
                        {%- for item_discount in item.discounts %}
                        <ItemDiscount>
                            <DiscAmountOrPercent>{{ get_micros_discount_price(item_discount) }}</DiscAmountOrPercent>
                            <DiscObjectNum>{{ item_discount.discount.id }}</DiscObjectNum>
                            {%- if item_discount.comment is not none %}
                            <DiscReference>{{ item_discount.comment }}</DiscReference>
                            {%- endif %}
                        </ItemDiscount>
                        {%- endfor %}
                        {% set mi_obj_num = item.menu_item.id.split('-')[0] %}
                        <MiObjectNum>{{ mi_obj_num }}</MiObjectNum>
                        {%- if item.comment is not none %}
                        <MiReference>{{ item.comment }}</MiReference>
                        {%- endif %}
                        <MiWeight />
                        <MiMenuLevel>{{ item.main_level }}</MiMenuLevel>
                        <MiSubLevel>{{ item.sub_level }}</MiSubLevel>
                        <MiPriveLevel>0</MiPriveLevel>
                        {%- if item.price_per_unit is not none %}
                        <MiOverridePrice>{{ cents_to_dollars(item.price_per_unit) }}</MiOverridePrice>
                        {%- endif %}
                    </MenuItem>
                </SimphonyPosApi_MenuItem>
                {%- endfor %}
                {%- endif %}
            </ppMenuItems>
            <ppComboMeals />
            {%- if service_charge is not none %}
            <pServiceChg>
                <SvcChgObjectNum>{{ service_charge.service_charge.id }}</SvcChgObjectNum>
                <SvcChgAmountOrPercent>{{ get_micros_service_charge_price(service_charge) }}</SvcChgAmountOrPercent>
                {%- if service_charge.comment is not none %}
                <SvcChgReference>{{ service_charge.comment }}</SvcChgReference>
                {%- endif %}
            </pServiceChg>
            {%- endif %}
            {%- if ticket_discount is not none %}
            <pSubTotalDiscount>
                <DiscObjectNum>{{ ticket_discount.discount.id }}</DiscObjectNum>
                <DiscAmountOrPercent>{{ get_micros_discount_price(ticket_discount) }}</DiscAmountOrPercent>
                {%- if ticket_discount.comment is not none %}
                <DiscReference>{{ ticket_discount.comment }}</DiscReference>
                {%- endif %}
            </pSubTotalDiscount>
            {%- endif %}
            <pTmedDetail>
                {%- if payment is not none %}
                <TmedEPayment>
                    <AccountDataSource>SOURCE_UNDEFINED</AccountDataSource>
                    <AccountType>ACCOUNT_TYPE_UNDEFINED</AccountType>
                    <ExpirationDate>0001-01-01T00:00:00</ExpirationDate>
                    <IssueNumber>0</IssueNumber>
                    <PaymentCommand>NO_E_PAYMENT</PaymentCommand>
                    <StartDate>0001-01-01T00:00:00</StartDate>
                    <TipAmount>{{ cents_to_dollars(payment['tip']) }}</TipAmount>
                </TmedEPayment>
                <TmedObjectNum>{{ payment['tender_type'].pos_id }}</TmedObjectNum>
                <TmedPartialPayment>{{ cents_to_dollars(payment['amount']) }}</TmedPartialPayment>
                {%- if payment['comment'] is not none %}
                <TmedReference>{{ payment['comment'] }}</TmedReference>
                {%- endif %}
                {%- else %}
                <TmedEPayment></TmedEPayment>
                <TmedObjectNum>{{ save_check_tender }}</TmedObjectNum>
                {%- endif %}
            </pTmedDetail>
        </AddToExistingCheckEx>
    </soap:Body>
</soap:Envelope>