{% extends '@RxConnexion/Admin/content.html.twig' %}
{% block content %}
    {% set materialRequisition = canvass.materialRequisition %}
    <div class="row max-width-initial">
        <div class="small-12 columns">
            <nav aria-label="You are here:" role="navigation">
                <ul class="breadcrumbs">
                    <li><a href="{{ path('material_requisition_canvass') }}">Supplier Canvassing List</a></li>
                    <li>
                        <span class="show-for-sr">Current: </span> Details
                    </li>
                </ul>
            </nav>
            <div class="content-detail-container">
                <div class="row max-width-initial">
                    <div class="large-4 columns">
                        <div class="page-detail-header">Canvassing Details</div>
                        <div class="page-detail">Canvass No.: <span>{{ canvass.canvassno }}</span></div>
                        {#<div class="page-detail">Assigned To: <span>Julius Torres, Archie Cabalo</span></div>#}
                        {#<div class="page-detail">Status: <span>{{ canvass.status }}</span></div>#}
                        {#{% if canvass.status != 'Approved' %}#}
                            {#<div class="page-detail">Approver(s): <span>{{ statusApproval.approvalUsers|default('')|raw }}</span></div>#}
                        {#{% endif %}#}
                    </div>
                    <div class="large-4 columns">
                        <div class="page-detail-header">Purchase Request Details</div>
                        <div class="page-detail">Control No.: <span>{{ materialRequisition.materialrequisitionno|default('N/A') }}</span></div>
                        <div class="page-detail">Request Date: <span>{{ materialRequisition.requestdateasstring|default('N/A') }}</span></div>
                        <div class="page-detail">Branch: <span>{{ materialRequisition.healthFacility.description|default('N/A') }}</span></div>
                        {#<div class="page-detail">Department: <span>{{ materialRequisition.department.description }}</span></div>#}
                        <div class="page-detail">Requested By: <span>{{ materialRequisition.accountUser.fullname|default('N/A') }}</span></div>
                    </div>
                    <div class="large-4 columns">
                        <div class="page-detail-header">&nbsp;</div>
                        <div class="page-detail">Purpose: <span>{{ materialRequisition.purpose.description|default('N/A') }}</span></div>
                        {#<div class="page-detail">Specific Purpose: <span>{{ materialRequisition.specificpurpose }}</span></div>#}
                        <div class="page-detail">Notes: <span>{{ materialRequisition.note }}</span></div>
                    </div>
                </div>
            </div>
            <div class="content-container has-loading">
                <div class="content-container-content hide">
                    <div class="text-right button-container">
                        {# {% if canvass.status == 'Supplier Canvassing' and (userData.type == 'Super Admin' or 'Admin Canvass Print Blank PO' in userData.accesses) %}
                             <a href="javascript:void(0)" class="button small secondary" style="margin: 0 0 10px 10px;" data-open="print-blank-po-modal">Print Blank PO</a>
                         {% endif %}#}
                        {% if userData.type == 'Super Admin' or 'Admin Canvass Print Quotation' in userData.accesses %}
                            <a href="{{ path('material_requisition_canvass_print_quotation', {canvass_id: canvass.idEncoded}) }}" class="button small secondary" style="margin: 0 0 10px 10px;">Print Abstract of Quotation</a>
                        {% endif %}
                        {% if canvass.status == 'Supplier Canvassing' and (userData.type == 'Super Admin' or 'Admin Canvass Send' in userData.accesses) %}
                            <a href="javascript:void(0)" class="button small" id="href-canvassItemSupplier-send" data-open="send-ask-modal" style="margin: 0 0 10px 10px;">Send</a>
                        {% endif %}
                        {#{% if canvass.status == 'Supplier Canvassing' and (userData.type == 'Super Admin' or 'Admin Canvass Add Quantity' in userData.accesses) %}
                            <a href="javascript:void(0)" class="button small success" id="href-canvass-add-quantity"  style="margin: 0 0 10px 10px;">Add Quantity</a>
                        {% endif %}#}
                        {% if canvass.isvoidable and (userData.type == 'Super Admin' or 'Admin Canvass Void' in userData.accesses) %}
                            <a href="javascript:void(0)" class="button small alert" id="href-canvass-void"  style="margin: 0 0 10px 10px;">Void</a>
                        {% endif %}
                        {% if canvass.status == 'Supplier Canvassing' and canvass.materialrequisition.iscancellable and (userData.type == 'Super Admin' or 'Admin Canvass Cancel' in userData.accesses) %}
                            <a href="javascript:void(0)" class="button small alert" id="href-canvass-cancel"  style="margin: 0 0 10px 10px;">Cancel</a>
                        {% endif %}
                    </div>
                    <ul class="tabs custom-tabs" data-tabs id="tabs-1">
                        <li class="tabs-title is-active"><a href="#panel-1-item" aria-selected="true">Items</a></li>
                        {#<li class="tabs-title"><a href="#panel-1-approval" aria-selected="false">Approval</a></li>#}
                        {#{% if (canvass.status == 'Approved' or canvass.status == 'Voided') and (userData.type == 'Super Admin' or 'Admin Purchase Order' in userData.accesses) %}#}
                        {% if userData.type == 'Super Admin' or 'Admin Purchase Order' in userData.accesses %}
                            <li class="tabs-title"><a href="#panel-1-purchase-order" aria-selected="false">Purchase Order</a></li>
                        {% endif %}
                    </ul>
                    <div class="tabs-content custom-tabs-content" data-tabs-content="tabs-1">
                        <div class="tabs-panel is-active" id="panel-1-item">
                            {#<div class="row">
                                <div class="large-6 columns right">
                                    <label>Category</label>
                                    <input type="text" id="item_category_description" name="item_category_description">
                                    <input type="hidden" id="item_category_id" name="item_category_id">
                                </div>
                            </div>#}
                            <table class="display responsive" id="canvassItem-datalist" width="100%">
                                <thead>
                                <tr>
                                    <th>Item</th>
                                    <th>Required Qty</th>
                                    <th>Voided Qty</th>
                                    {#<th>Added Qty</th>#}
                                    <th>Canvassed Qty</th>
                                    <th>Supplier(s)</th>
                                    <th>Selected Supplier(s)</th>
                                    <th>Action</th>
                                </tr>
                                </thead>
                                <tbody>
                                </tbody>
                            </table>
                        </div>
                        {#<div class="tabs-panel" id="panel-1-approval">#}
                            {#{% if canvass.canApproveByUser(userData) %}#}
                            {#{% if canApproveByUser %}#}
                                {#<form method="POST" action="{{ path('material_requisition_canvass_status_approval') }}">#}
                                    {#<input type="hidden" name="canvass_id" value="{{ canvass_id }}" />#}
                                    {#<input type="hidden" class="form-action" name="action" />#}
                                    {#<div class="row max-width-initial">#}
                                        {#<div class="small-12 columns">#}
                                            {#<label>Notes</label>#}
                                            {#<textarea name="notes" placeholder="Enter your notes here"></textarea>#}
                                        {#</div>#}
                                        {#<div class="small-12 columns">#}
                                            {#<div class="button-container">#}
                                                {#<button type="submit" class="button ask-continue no-margin-bottom" name="action" value="approve"#}
                                                        {#data-message="Are you sure you want to approve this request?"#}
                                                {#>Approve</button>#}
                                                {#<button type="submit" class="button alert ask-continue no-margin-bottom" name="action" value="reject"#}
                                                        {#data-message="Are you sure you want to reject this request?"#}
                                                {#>Reject</button>#}
                                            {#</div>#}
                                        {#</div>#}
                                    {#</div>#}
                                {#</form>#}
                                {#<hr class="max-width-initial">#}
                            {#{% endif %}#}
                            {#<h5>History</h5>#}
                            {#<table class="display response" id="canvassStatusHistory-datalist" width="100%">#}
                                {#<thead>#}
                                {#<tr>#}
                                    {#<th>Date / Time</th>#}
                                    {#<th>Status</th>#}
                                    {#<th>Approval</th>#}
                                    {#<th>User</th>#}
                                    {#<th>Notes</th>#}
                                {#</tr>#}
                                {#</thead>#}
                                {#<tbody>#}
                                {#{% for ctr in canvass.approvalbatchno..0 %}#}
                                    {#{% for canvassStatus in canvass.canvassstatuses %}#}
                                        {#{% if canvassStatus.batchno == ctr and (canvassStatus.approvaldescription == 'Approved' or canvassStatus.approvaldescription == 'Rejected') %}#}
                                            {#<tr>#}
                                                {#<td>{{ canvassStatus.updatedat|date('m/d/Y h:i:s A') }}</td>#}
                                                {#<td>{{ canvassStatus.status }}</td>#}
                                                {#<td>{{ canvassStatus.approvaldescription }}</td>#}
                                                {#<td>{{ canvassStatus.user.fullname }} - {{ canvassStatus.user.type }}</td>#}
                                                {#<td>{{ canvassStatus.note }}</td>#}
                                            {#</tr>#}
                                        {#{% endif %}#}
                                    {#{% endfor %}#}
                                {#{% endfor %}#}
                                {#</tbody>#}
                            {#</table>#}
                        {#</div>#}
                        {#{% if (canvass.status == 'Approved' or canvass.status == 'Voided') and (userData.type == 'Super Admin' or 'Admin Purchase Order' in userData.accesses) %}#}
                        {% if userData.type == 'Super Admin' or 'Admin Purchase Order' in userData.accesses %}
                            <div class="tabs-panel" id="panel-1-purchase-order">
                                <table class="display response" id="purchaseOrder-datalist" width="100%">
                                    <thead>
                                    <tr>
                                        {#<th>Batch No.</th>#}
                                        <th>Supplier</th>
                                        <th>Currency</th>
                                        <th>Payment Mode</th>
                                        <th>Term</th>
                                        <th>W/Tax Rate</th>
                                        <th>Status</th>
                                        <th>No. of Items</th>
                                        <th>Action</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    {% for purchaseOrder in canvass.purchaseorders %}
                                        <tr>
                                            {#<td>{{ purchaseOrder.batchno }}</td>#}
                                            <td>{{ purchaseOrder.supplier.description }}</td>
                                            <td>{{ purchaseOrder.currency.code|default('') }}</td>
                                            <td>{{ purchaseOrder.paymentMode }}</td>
                                            <td>{{ purchaseOrder.term }}</td>
                                            <td>{{ purchaseOrder.withholdingTaxRate.descriptionAndRate|default('') }}</td>
                                            <td>{{ purchaseOrder.status }}</td>
                                            <td>{{ purchaseOrder.purchaseorderitems|length }}</td>
                                            <td>
                                                <a class="action-button-style" href="{{ path('material_requisition_purchase_order_view', {purchaseOrder_id: purchaseOrder.idencoded}) }}">View</a>
                                            </td>
                                        </tr>
                                    {% endfor %}
                                    </tbody>
                                </table>
                                <br/>
                                {#<h5 class="subheader">Approval History</h5>#}
                                {#<table class="display response" id="purchaseOrderStatusHistory-datalist" width="100%">#}
                                    {#<thead>#}
                                    {#<tr>#}
                                        {#<th>Batch No.</th>#}
                                        {#<th>Date / Time</th>#}
                                        {#<th>Status</th>#}
                                        {#<th>Approval</th>#}
                                        {#<th>User</th>#}
                                        {#<th>Notes</th>#}
                                    {#</tr>#}
                                    {#</thead>#}
                                    {#<tbody>#}
                                    {#{% for purchaseOrder in canvass.purchaseOrders %}#}
                                        {#{% for ctr in purchaseOrder.approvalbatchno..0 %}#}
                                            {#{% for purchaseOrderStatus in purchaseOrder.purchaseorderstatuses %}#}
                                                {#{% if purchaseOrderStatus.batchno == ctr and (purchaseOrderStatus.approvaldescription == 'Approved' or purchaseOrderStatus.approvaldescription == 'Rejected') %}#}
                                                    {#<tr>#}
                                                        {#<td>{{ purchaseOrder.batchNo }}</td>#}
                                                        {#<td>{{ purchaseOrderStatus.updatedat|date('m/d/Y h:i:s A') }}</td>#}
                                                        {#<td>{{ purchaseOrderStatus.status }}</td>#}
                                                        {#<td>{{ purchaseOrderStatus.approvaldescription }}</td>#}
                                                        {#<td>{{ purchaseOrderStatus.user.fullname }} - {{ purchaseOrderStatus.user.type }}</td>#}
                                                        {#<td>{{ purchaseOrderStatus.note }}</td>#}
                                                    {#</tr>#}
                                                {#{% endif %}#}
                                            {#{% endfor %}#}
                                        {#{% endfor %}#}
                                    {#{% endfor %}#}
                                    {#</tbody>#}
                                {#</table>#}
                            </div>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="reveal large" id="modal" data-reveal data-close-on-esc="false" data-close-on-click="false">
        <div id="modal-content"></div>
        <button class="close-button" data-close aria-label="Close modal" type="button">
            <span aria-hidden="true">&times;</span>
        </button>
    </div>
    <div class="reveal large" id="modal-large" data-reveal data-close-on-esc="false" data-close-on-click="false">
        <div id="modal-content-large"></div>
        <button class="close-button" data-close aria-label="Close modal" type="button">
            <span aria-hidden="true">&times;</span>
        </button>
    </div>
    {#<div class="reveal large" id="modal-add-supplier-form" data-reveal>
        <h5 id="modal-title-add-supplier-form"></h5>
        <table class="display responsive" id="addSupplierForm-datalist" width="100%">
            <thead>
            <tr>
                <th>Supplier Name</th>
                <th>Mobile No.</th>
                <th>Phone No.</th>
                <th>Email</th>
                <th>Currency</th>
                <th>Price</th>
                <th>Notes</th>
                <th>Action</th>
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
        <button class="close-button" data-close aria-label="Close modal" type="button">
            <span aria-hidden="true">&times;</span>
        </button>
        <input type="hidden" id="addSupplierForm-canvassItem-id" />
    </div>#}
    <div class="reveal small" id="send-ask-modal" data-reveal data-close-on-esc="false" data-close-on-click="false">
        <h4>Are you sure you want to continue?</h4>
        <hr class="max-width-initial">
        <div class="button-container text-right">
            <a href="javascript:void(0);" id="btn-send-ask-modal-continue" data-action="" class="button">&nbsp;&nbsp;Yes&nbsp;&nbsp;</a>
            <a href="javascript:void(0);" class="button secondary no-margin-right" data-close>Cancel</a>
        </div>
        <button class="close-button" data-close aria-label="Close modal" type="button">
            <span aria-hidden="true">&times;</span>
        </button>
    </div>
    {#<div class="reveal small" id="print-blank-po-modal" data-reveal>
        <h4>Where do you want to print?</h4>
        <hr class="max-width-initial">
        <div class="button-container text-right">
            <a data-close href="{{ path('material_requisition_canvass_print_blank_po', {canvass_id: canvass.idencoded}) }}" class="button alert"><i class="fa fa-file-pdf-o"></i> Soft Copy</a>
            <a data-close href="javascript:alert('Coming soon...');" class="button secondary no-margin-right"><i class="fa fa-print"></i> Printer</a>
        </div>
        <button class="close-button" data-close aria-label="Close modal" type="button">
            <span aria-hidden="true">&times;</span>
        </button>
    </div>#}
    {% include '@RxConnexion/Admin/js.html.twig' %}
    <script language="javascript">
        //<![CDATA[
        canvass_view.settings.canvass_id = '{{ canvass_id }}';
        canvass_view.settings.sendUrl = '{{ path('material_requisition_canvass_send') }}';
        // canvass_view.settings.addQuantityUrl = '{{ path('material_requisition_canvass_add_quantity') }}';
        // canvass_view.settings.addQuantityActionUrl = '{{ path('material_requisition_canvass_add_quantity_action') }}';
        canvass_view.settings.voidUrl = '{{ path('material_requisition_canvass_void') }}';
        canvass_view.settings.voidActionUrl = '{{ path('material_requisition_canvass_void_action') }}';
        canvass_view.settings.cancelUrl = '{{ path('material_requisition_canvass_cancel') }}';
        canvass_view.settings.ajaxUrl = '{{ path('material_requisition_canvass_item_ajax_list') }}';
        // canvass_view.settings.canvassItemSupplierForm_url = '{{ path('material_requisition_canvass_item_supplier_form') }}';
        // canvass_view.settings.canvassItemSupplierFormAction_url = '{{ path('material_requisition_canvass_item_supplier_do_add') }}';
        canvass_view.settings.canvassItemSupplierFormMultiple_url = '{{ path('material_requisition_canvass_item_supplier_form_multiple') }}';
        canvass_view.settings.canvassItemSupplierDoAdd_url = '{{ path('material_requisition_canvass_item_supplier_do_add') }}';
        canvass_view.settings.canvassItemSupplierSelect_url = '{{ path('material_requisition_canvass_item_supplier_select') }}';
        canvass_view.settings.canvassItemSupplierSelectAction_url = '{{ path('material_requisition_canvass_item_supplier_select_action') }}';
        canvass_view.settings.canvassItemSupplierDetails_url = '{{ path('material_requisition_canvass_item_supplier_details') }}';
        canvass_view.settings.canvassItemSupplierRemove_url = '{{ path('material_requisition_canvass_item_supplier_remove') }}';
        // canvass_view.settings.supplier_autocomplete_url = '{{ path('supplier_autocomplete2') }}';
        canvass_view.settings.supplier_ajaxUrl = '{{ path('supplier_ajax_list_for_canvassing') }}';
        // canvass_view.settings.item_category_autocomplete_url = '{{ path('item_category_autocomplete') }}';
        jQ(document).ready(canvass_view.init);
        //]]>
    </script>
{% endblock %}