{% set mr = canvass.materialrequisition %}
<pdf>
    <dynamic-page page-size="letter-landscape">
        <h1 text-align="center" margin-bottom="0">ABSTRACT OF QUOTATION</h1>
        <h3 text-align="center" margin-top="0">{{ mr.materialRequisitionNo }}</h3>
        <table width="100%">
            <tr>
                <td width="40%" border.type="none">
                    <table width="100%">
                        <tr>
                            <td border.type="none" padding="1" width="40%">Date Requested:</td>
                            <td border.type="none" padding="1" font-style="bold">{{ mr.requestDateAsString }}</td>
                        </tr>
                        <tr>
                            <td border.type="none" padding="1">Branch:</td>
                            <td border.type="none" padding="1" font-style="bold">{{ mr.branch.description }}</td>
                        </tr>
                        <tr>
                            <td border.type="none" padding="1">Department:</td>
                            <td border.type="none" padding="1" font-style="bold">{{ mr.department.description }}</td>
                        </tr>
                    </table>
                </td>
                <td border.type="none">
                    <table width="100%">
                        <tr>
                            <td border.type="none" padding="1" width="30%">Requested By:</td>
                            <td border.type="none" padding="1" font-style="bold">{{ mr.user.fullName }}</td>
                        </tr>
                        <tr>
                            <td border.type="none" padding="1">Purpose:</td>
                            <td border.type="none" padding="1" font-style="bold">{{ mr.purpose.description }}</td>
                        </tr>
                        <tr>
                            <td border.type="none" padding="1">Specific Purpose:</td>
                            <td border.type="none" padding="1" font-style="bold">{{ mr.specificpurpose }}</td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
        <br/>
        <br/>
        <br/>
        <table width="100%" font-size="8">
            <tr> {# We needed this line as colspan is not working in the first row #}
                <td border.type="none"></td>
                <td border.type="none"></td>
                <td border.type="none"></td>
                {% for s in suppliers %}
                    <td border.type="none"></td>
                    <td border.type="none"></td>
                {% endfor %}
            </tr>
            <tr>
                <td colspan="3" border.type="none"></td>
                {% for s in suppliers %}
                <td background.color="#EEEEEE" colspan="2" padding="3" text-align="center">{{ s.desc }}</td>
                {% endfor %}
            </tr>
            <tr>
                <td padding="3" text-align="center" width="50">Qty</td>
                <td padding="3" text-align="center" width="50">Unit</td>
                <td padding="3" text-align="center">Particulars</td>
                {% for s in suppliers %}
                    <td background.color="#EEEEEE" colspan="2" padding="3" text-align="center">
                        {{ 'Term' == s.payMode ? s.payTerm ~ ' days' : s.payMode }}
                    </td>
                {% endfor %}
            </tr>
            <tr background.color="#CCCCCC">
                <td></td>
                <td></td>
                <td></td>
                {% for s in suppliers %}
                    <td padding="3" text-align="center">Unit Price</td>
                    <td padding="3" text-align="center">Total Price</td>
                {% endfor %}
            </tr>
            {% for ci in canvass.canvassItems %}
                {% set it = ci.materialRequisitionItem.item %}
                <tr>
                    <td text-align="center">{{ ci.quantityCanvassed|number_format }}</td>
                    <td text-align="center">{{ it.itemUnit.description|default('N/A') }}</td>
                    <td text-align="center">{{ it.description }}</td>
                    {% for s in suppliers %}
                        {% set up = 0 %}
                        {% set tp = 0 %}
                        {% for cis in ci.canvassItemSuppliers if cis.supplier.id == s.id %}
                            {% set up = cis.price %}
                            {% set tp = cis.price * ci.quantityCanvassed %}
                        {% endfor %}
                        {% if loop.parent.loop.first and s.currencyCode is not empty %}
                            <td>
                                <table width="100%">
                                    <tr>
                                        <td padding="3" border.type="none" text-align="center">{{ s.currencyCode }}</td>
                                        <td padding="3" border.type="none" text-align="right">{{ up > 0 ? up|number_format(2, '.', ',') : '-' }}</td>
                                    </tr>
                                </table>
                            </td>
                            <td>
                                <table width="100%">
                                    <tr>
                                        <td padding="3" border.type="none" text-align="center">{{ s.currencyCode }}</td>
                                        <td padding="3" border.type="none" text-align="right">{{ tp > 0 ? tp|number_format(2, '.', ',') : '-' }}</td>
                                    </tr>
                                </table>
                            </td>
                        {% else %}
                            <td padding="3" text-align="right">{{ up > 0 ? up|number_format(2, '.', ',') : '-' }}</td>
                            <td padding="3" text-align="right">{{ tp > 0 ? tp|number_format(2, '.', ',') : '-' }}</td>
                        {% endif %}
                    {% endfor %}
                </tr>
            {% endfor %}
            {% set itemCtr = canvass.canvassItems.count %}
            {% if itemCtr < 10 %}
                {% for i in itemCtr..9 %}
                    <tr>
                        <td></td>
                        <td></td>
                        <td></td>
                        {% for s in suppliers %}
                            <td padding="3" text-align="right">-</td>
                            <td padding="3" text-align="right">-</td>
                        {% endfor %}
                    </tr>
                {% endfor %}
            {% endif %}
            <tr>
                <td colspan="3" background.color="#CCCCCC"></td>
                {% for s in suppliers %}
                    <td padding="3" text-align="right"></td>
                    {% if s.currencyCode is not empty %}
                        <td>
                            <table width="100%">
                                <tr>
                                    <td padding="3" border.type="none" text-align="center">{{ s.currencyCode }}</td>
                                    <td padding="3" border.type="none" text-align="right" font-style="bold">{{ s.totalAmt|number_format(2, '.', ',') }}</td>
                                </tr>
                            </table>
                        </td>
                    {% else %}
                        <td padding="3" text-align="right" font-style="bold">{{ s.totalAmt|number_format(2, '.', ',') }}</td>
                    {% endif %}
                {% endfor %}
            </tr>
        </table>
        <br/>
        <br/>
        <br/>
        <table width="100%">
            <tr font-style="italic">
                <td padding="5" border.type="none">Prepared By:</td>
                <td width="15%" border.type="none"></td>
                <td padding="5" border.type="none">Checked By:</td>
                <td width="15%" border.type="none"></td>
                <td padding="5" border.type="none">Approved By:</td>
            </tr>
            <tr>
                <td border.type="none" padding="5">
                    <div style="height:75px;">
                        {% set userWhoSent = canvass.userWhoSent %}
                        {% set userWhoSentFullName = userWhoSent ? userWhoSent.fullNameToUpper : '' %}
                        {% if 'JULIUS TORRES' == userWhoSentFullName %}
                            <img ignore-error="true" src="{{ pdf_image('RxConnexionBundle:../approval/signatures/Julius.png') }}" style="height:60px;margin-left:25px;margin-top:10px;" />
                        {% elseif 'ARCHIE CABALO' == userWhoSentFullName %}
                            <img ignore-error="true" src="{{ pdf_image('RxConnexionBundle:../approval/signatures/Archie.png') }}" style="height:60px;margin-left: 25px;margin-top:10px;" />
                        {% endif %}
                    </div>
                    {#<div>{{ 'ARCHIE CABALO' == userWhoSentFullName ? 'ARCHIE CABALO' : 'JULIUS TORRES' }}</div>#}
                    <div border.type="top" margin-top="3" padding-top="3">Purchasing Officer</div>
                </td>
                <td border.type="none"></td>
                <td border.type="none" padding="5">
                    <div style="height:75px;">
                        {% set isAppByRommel = canvass.isApprovedByStatusAndUserFullName(constant('STATUS_PENDING_FIN_OFF_APP_FOR_PO', canvass), 'Rommel Ocampo') %}
                        {% set isAppByAna = canvass.isApprovedByStatusAndUserFullName(constant('STATUS_PENDING_FIN_OFF_APP_FOR_PO', canvass), 'Ana Khaira Macam') %}
                        {% if isAppByRommel %}
                            <img ignore-error="true" src="{{ pdf_image('RxConnexionBundle:../approval/signatures/Rommel.png') }}" style="height:60px;margin-top:10px;" />
                        {% elseif isAppByAna %}
                            <img ignore-error="true" src="{{ pdf_image('RxConnexionBundle:../approval/signatures/Ana.png') }}" style="height:70px;margin-left:40px;" />
                        {% endif %}
                    </div>
                    {#<div>{{ isAppByAna ? 'ANA KHAIRA MACAM' : 'ROMMEL OCAMPO' }}</div>#}
                    <div border.type="top" margin-top="3" padding-top="3">Officer</div>
                </td>
                <td border.type="none"></td>
                <td border.type="none" padding="5">
                    <div style="height:75px;">
                        {% set isAppByEngr = canvass.isApprovedByStatusAndUserFullName(constant('STATUS_PENDING_ADMIN_APP_FOR_PO', canvass), 'Edwin Reyes') %}
                        {% set isAppByIsrael = canvass.isApprovedByStatusAndUserFullName(constant('STATUS_PENDING_ADMIN_APP_FOR_PO', canvass), 'Israel Orquia') %}
                        {% if isAppByEngr %}
                            <img ignore-error="true" src="{{ pdf_image('RxConnexionBundle:../approval/signatures/Engr.png') }}" style="height:40px;margin-top:20px;" />
                        {% elseif isAppByIsrael %}
                            <img ignore-error="true" src="{{ pdf_image('RxConnexionBundle:../approval/signatures/Israel.png') }}" style="height:60px;" />
                        {% endif %}
                    </div>
                    {#<div>{{ isAppByIsrael ? 'ISRAEL ORAQUIA' : 'ENGR. EDWIN R. REYES' }}</div>#}
                    <div border.type="top" margin-top="3" padding-top="3">Approver</div>
                </td>
            </tr>
        </table>
    </dynamic-page>
</pdf>