{% set purchaseOrder = purchaseOrderBreakdown.purchaseOrder %}
{% set supplier = purchaseOrder.supplier %}
<pdf>
    <dynamic-page page-size="a4">
        <placeholders>
            <header>
                <div height="77" border.type="top+right+bottom+left">
                    <table>
                        <tr>
                            <td border.type="none" width="100px" height="80px"><img ignore-error="true" src="{{ pdf_image('RxConnexionBundle:../frontend/img/logo.jpg') }}" style="height:100px;width:100px;position:absolute" /></td>
                            <td border.type="none" height="80px" padding-right="10">
                                <h3 margin-left='10px' margin-bottom='1' padding='0'>Live Events</h3>
                                <p margin-left='10px' padding='0'>Philiipines</p>
                                <p margin-left='10px' padding='0'></p>
                                <p margin-left='10px' padding='0' padding-top="5">Tel No.: (XXX) XXX-XXX * Fax No.: (XX)-XXXXXXX</p>
                            </td>
                            <td border.type="none" width="250px">
                                <h2>PURCHASE ORDER</h2>
                                <table>
                                    <tr>
                                        <td border.type="none" width="50">P.O. #</td>
                                        <td border.type="none" font-style="bold">{{ purchaseOrderBreakdown.poNo }}</td>
                                    </tr>
                                    <tr>
                                        <td border.type="none">P.O. Date</td>
                                        <td border.type="none" font-style="bold">{{ purchaseOrderBreakdown.poDateAsLongString }}</td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                </div>
            </header>
            <footer>
                <div height="170">
                    <table width="100%" font-size="7">
                        <tr font-style="italic">
                            <td width="20%" padding="2">Prepared By:</td>
                            <td padding="2">Checked / Noted By:</td>
                            <td width="20%" padding="2">Approved By:</td>
                            <td width="20%" padding="2">With Our Conformity</td>
                        </tr>
                        <tr>
                            <td padding="5" text-align="center">
                                <div style="height:75px;">
                                    {% set userWhoSent = purchaseOrder.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 padding="5" text-align="center">
                                <table width="100%">
                                    <tr>
                                        <td border.type="none">
                                            <div style="height:75px;">
                                                {% set isAppByRommel = purchaseOrder.isApprovedByStatusAndUserFullName(constant('STATUS_PENDING_FIN_OFF_SIG_FOR_PO', purchaseOrder), 'Rommel Ocampo') %}
                                                {% set isAppByAna = purchaseOrder.isApprovedByStatusAndUserFullName(constant('STATUS_PENDING_FIN_OFF_SIG_FOR_PO', purchaseOrder), '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">
                                            <div style="height:75px;">
                                                {% set isAppByMsWie = purchaseOrder.isApprovedByStatusAndUserFullName(constant('STATUS_PENDING_OPE_DIV_MAN_SIG_FOR_PO', purchaseOrder), 'Wilma Pineda') %}
                                                {% set isAppByRommel = purchaseOrder.isApprovedByStatusAndUserFullName(constant('STATUS_PENDING_OPE_DIV_MAN_SIG_FOR_PO', purchaseOrder), 'Rommel Ocampo') %}
                                                {% if isAppByMsWie %}
                                                    <img ignore-error="true" src="{{ pdf_image('RxConnexionBundle:../approval/signatures/MsWie.png') }}" style="height:70px;margin-left:40px;" />
                                                {% elseif isAppByRommel %}
                                                    <img ignore-error="true" src="{{ pdf_image('RxConnexionBundle:../approval/signatures/Rommel.png') }}" style="height:60px;margin-top:10px;" />
                                                {% endif %}
                                            </div>
                                            <div>{{ isAppByRommel ? 'ROMMEL OCAMPO' : 'WILMA P. PINEDA' }}</div>
                                            <div border.type="top" margin-top="3" padding-top="3">Operation Div. Manager</div>
                                        </td>#}
                                    </tr>
                                </table>
                            </td>
                            <td padding="5" text-align="center">
                                <div style="height:75px;">
                                    {% set isAppByEngr = purchaseOrder.isApprovedByStatusAndUserFullName(constant('STATUS_PENDING_FINAL_ADMIN_APP_FOR_PO', purchaseOrder), 'Edwin Reyes') %}
                                    {% set isAppByIsrael = purchaseOrder.isApprovedByStatusAndUserFullName(constant('STATUS_PENDING_FINAL_ADMIN_APP_FOR_PO', purchaseOrder), '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>
                            <td padding="5" text-align="center">
                                <div style="height:75px;"></div>
                                <div>{{ supplier.description }}</div>
                                <div border.type="top" margin-top="3" padding-top="3">Supplier Name</div>
                            </td>
                        </tr>
                        <tr>
                            <td colspan="4" padding-left="10" padding-right="10" padding-bottom="15">
                                <p font-style="bold">NOTE: No payment will be made unless accompanied by this P.O. and not valid with erasure.</p>
                                <table width="100%">
                                    <tr>
                                        <td width="75" border.type="none">Date Printed:</td>
                                        <td width="100" border.type="none">{{ 'now'|date('m/d/Y') }}</td>
                                        <td border.type="none"><page-info format="page %s of %s" /></td>
                                    </tr>
                                </table>
                            </td>
                        </tr>
                    </table>
                    {#<div margin-bottom='20px' width='200px' float="left" margin-right="25px">
                        {% if purchaseOrderBreakdown.purchaseorder.status in ['Pending Final Admin Approval For PO', 'Pending Finance Officer Signature For PO', 'Pending Operations Division Manager Signature For PO', 'Approved', 'Sent', 'Received' ] %}
                            <img ignore-error="true" src="{{ pdf_image('RxConnexionBundle:../approval/signatures/Julius.png') }}" style="height:50px;width:200px;position:absolute;" />
                        {% else %}
                            <img ignore-error="true" src="" style="height:50px;width:200px;position:absolute;" />
                        {% endif %}
                        <div text-align='center' border.type='none' padding='5px'>Julius Torres</div>
                        <div text-align='center' border.type='top'  padding='5px'>Prepared By</div>
                    </div>
                    <div margin-bottom='20px' width='200px' float="left" margin-right="25px">
                        {% if purchaseOrderBreakdown.purchaseorder.status in ['Pending Final Admin Approval For PO', 'Approved', 'Sent', 'Received' ] %}
                            <img ignore-error="true" src="{{ pdf_image('RxConnexionBundle:../approval/signatures/Rommel.png') }}" style="height:50px;width:200px;position:absolute;" />
                        {% else %}
                            <img ignore-error="true" src="" style="height:50px;width:200px;position:absolute;" />
                        {% endif %}
                        <div text-align='center' border.type='none' padding='5px'>Rommel Ocampo</div>
                        <div text-align='center' border.type='top' padding='5px'>Checked By</div>
                    </div>
                    <div margin-bottom='20px' width='200px' float="left">
                        {% if purchaseOrderBreakdown.purchaseorder.status in ['Pending Final Admin Approval For PO', 'Pending Finance Officer Signature For PO','Approved', 'Sent', 'Received' ] %}
                            <img ignore-error="true" src="{{ pdf_image('RxConnexionBundle:../approval/signatures/MsWie.png') }}" style="height:50px;width:200px;position:absolute;" />
                        {% else %}
                        <img ignore-error="true" src="" style="height:50px;width:200px;position:absolute;" />
                        {% endif %}
                        <div text-align='center' border.type='none' padding='5px'>Wilma Pineda</div>
                        <div text-align='center' border.type='top' padding='5px'>Approved By</div>
                    </div>#}
                </div>
            </footer>
        </placeholders>
        <table width="100%" margin-top="5">
            <tr>
                <td>
                    <table width="100%">
                        <tr>
                            <td width="60" border.type="right" padding="5">VENDOR</td>
                            <td border.type="none" padding="5" font-style="bold">{{ supplier.description }}</td>
                        </tr>
                        <tr>
                            <td border.type="right" padding="5">ADDRESS</td>
                            <td border.type="none" padding="5">{{ supplier.address }}</td>
                        </tr>
                        <tr>
                            <td border.type="right" padding="5">CODE</td>
                            <td border.type="none" padding="5">{{ supplier.code }}</td>
                        </tr>
                    </table>
                </td>
                <td width="100" padding="10">
                    Terms
                    <br/>
                    <br/>
                    {% if purchaseOrder.paymentMode == 'Term' %}
                        {{ purchaseOrder.term ~ ' days' }}
                    {% else %}
                        {{ purchaseOrder.paymentMode }}
                    {% endif %}
                </td>
                <td width="150" padding="10">Terms</td>
            </tr>
        </table>
        <table margin-top="5">
            <tr font-style="bold">
                <td padding="5" width="75">Item Code</td>
                <td padding="5">Item Description</td>
                <td padding="5" width="40">Unit</td>
                <td text-align="right" padding="5" width="40">Qty</td>
                <td text-align="right" padding="5" width="100">Unit Price</td>
                <td text-align="right" padding="5" width="100">Amount</td>
            </tr>
            {% set totalAmount = 0 %}
            {% for item in purchaseOrderBreakdown.purchaseorderbreakdownitems %}
                {% set itm = item.purchaseorderitem.materialrequisitionitem.item %}
                {% set price = item.purchaseorderitem.price %}
                {% set amount = item.quantity * price %}
                {% set totalAmount = totalAmount + amount %}
                <tr>
                    <td border.type="left" padding="2">{{ itm.code }}</td>
                    <td border.type="none" padding="2">{{ itm.description }}</td>
                    <td border.type="none" padding="2">{{ itm.itemunit.description|default('') }}</td>
                    <td border.type="none" padding="2" text-align="right">{{ item.quantity|number_format(0, '.', ',') }}</td>
                    {% if loop.first %}
                        <td border.type="none">
                            <table width="100%">
                                <tr>
                                    <td border.type="none" padding="2" text-align="center" width="35">{{ purchaseOrder.currency.code|default('') }}</td>
                                    <td border.type="none" padding="2" text-align="right">{{ price|number_format(2, '.', ',') }}</td>
                                </tr>
                            </table>
                        </td>
                        <td border.type="none">
                            <table width="100%">
                                <tr>
                                    <td border.type="none" padding="2" text-align="center" width="35">{{ purchaseOrder.currency.code|default('') }}</td>
                                    <td border.type="right" padding="2" text-align="right">{{ amount|number_format(2, '.', ',') }}</td>
                                </tr>
                            </table>
                        </td>
                    {% else %}
                        <td border.type="none" padding="2" text-align="right">{{ price|number_format(2, '.', ',') }}</td>
                        <td border.type="right" padding="2" text-align="right">{{ amount|number_format(2, '.', ',') }}</td>
                    {% endif %}
                </tr>
                {% if loop.last %}
                    <tr>
                        <td border.type="left+right" padding="5" text-align="center" colspan="6">* * * Nothing Follows * * *</td>
                    </tr>
                {% endif %}
            {% endfor %}
            {% set itemCtr = purchaseOrderBreakdown.purchaseorderbreakdownitems.count %}
            {% if itemCtr < 29 %}
                {% for i in itemCtr..29 %}
                    <tr>
                        <td colspan="6" border.type="left+right">
                            <br/>
                            <br/>
                        </td>
                    </tr>
                {% endfor %}
            {% endif %}
            <tr>
                <td colspan="2" border.type="top+bottom+left" padding="5">
                    REMARKS: {{ purchaseOrder.materialRequisition.purpose.description|default('') }} <br/>
                    {{ purchaseOrder.materialRequisition.specificPurpose }}
                </td>
                <td colspan="4" border.type="top+right+bottom" padding="5" font-style="bold">
                    <table width="100%">
                        <tr>
                            <td width="120" border.type="none" text-align="right">TOTAL AMOUNT:</td>
                            <td width="30" border.type="none" text-align="right">{{ purchaseOrder.currency.code|default('') }}</td>
                            <td border.type="none" text-align="right">{{ totalAmount|number_format(2, '.', ',') }}</td>
                        </tr>
                        <tr>
                            <td border.type="none" padding-top="5" text-align="right">LESS: DISCOUNT:</td>
                            <td border.type="none" padding-top="5"></td>
                            <td border.type="none" padding-top="5" text-align="right">0.00</td>
                        </tr>
                        <tr>
                            <td border.type="none" padding-top="5" text-align="right">NET AMOUNT:</td>
                            <td border.type="none" padding-top="5" text-align="right">{{ purchaseOrder.currency.code|default('') }}</td>
                            <td border.type="none" padding-top="5" text-align="right">{{ totalAmount|number_format(2, '.', ',') }}</td>
                        </tr>
                    </table>
                </td>
            </tr>
        </table>
    </dynamic-page>
</pdf>