{{ header }}{{ column_left }}
<div id="content">
    <div class="page-header">
        <div class="container-fluid">
            <div class="pull-right">
{#                <button type="submit" form="form-shipping" data-toggle="tooltip" title="{{ button_save }}" class="btn btn-primary"><i class="fa fa-save"></i></button>#}
                <a href="{{ goToOrders }}" data-toggle="tooltip" title="Go to Order list" class="btn btn-default"><i class="fa fa-reply"></i></a></div>
            <h1>{{ heading_title }}</h1>
            <ul class="breadcrumb">
                {% for breadcrumb in breadcrumbs %}
                    <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
                {% endfor %}
            </ul>
        </div>
    </div>
    <div class="container-fluid">
        {% if error_warning %}
            <div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> {{ error_warning }}
                <button type="button" class="close" data-dismiss="alert">&times;</button>
            </div>
        {% endif %}
        <div class="row">
            <div class="col-sm-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title"><i class="fa fa-filter"></i> {{ text_filter }}</h3>
                    </div>
                    <div class="panel-body">
                        <div class="form-group col-sm-3">
                            <label class="control-label">{{ text_shipment_number }}</label>
                            <input type="text" class="form-control" value="{{ filter_idInpost }}" id="filter_idInpost" name="filter_idInpost" placeholder="{{ text_shipment_number }}">
                        </div>
                        <div class="form-group col-sm-3">
                            <label class="control-label">{{ text_reference }}</label>
                            <input type="text" class="form-control" value="{{ filter_reference }}" id="filter_reference" name="filter_reference" placeholder="{{ text_reference }}">
                        </div>
                        <div class="form-group col-sm-3">
                            <label class="control-label">{{ text_service }}</label>
                            <select name="filter_service" id="filter_service" class="form-control">
                                <option value="">--- {{ text_none }} ---</option>
                                {% for service in services %}
                                <option value="{{ service.service }}" {{ service.service == filter_service ? 'selected="selected"' : '' }}>{{ apiServices[service.service].description }}</option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="form-group col-sm-3">
                            <label class="control-label">{{ entry_shipping_method }}</label>
{#                            <input type="text" class="form-control" value="{{ filter_sending_method }}" id="filter_sending_method" name="filter_sending_method" placeholder="Sending Method">#}
                            <select name="filter_sending_method" id="filter_sending_method" class="form-control">
                                <option value="">--- {{ text_none }} ---</option>
                                {% for sending_method in sendingMethods %}
                                    <option value="{{ sending_method.sending_method }}" {{ sending_method.sending_method == filter_sending_method ? 'selected="selected"' : '' }}>{{ apiShippingMethods[sending_method.sending_method].description }}</option>
                                {% endfor %}
                            </select>
                        </div>
                        <div class="form-group col-sm-3">
                            <label class="control-label">{{ text_created_at }}</label>
                            <input type="text" class="form-control" value="{{ filter_created_at }}" id="filter_created_at" name="filter_created_at" placeholder="{{ text_created_at }}">
                        </div>
                        <div class="form-group col-sm-3">
                            <label class="control-label">{{ text_label_printed }}</label>
{#                            <input type="text" class="form-control" value="{{ filter_labelPrinted }}" id="filter_labelPrinted" name="filter_labelPrinted" placeholder="Label Printed">#}
                            <select name="filter_labelPrinted" id="filter_labelPrinted" class="form-control">
                                <option value="">--- {{ text_none }} ---</option>
                                <option value="1" {{ filter_labelPrinted == '1' ? 'selected="selected"' : '' }}>{{ text_no }}</option>
                                <option value="2" {{ filter_labelPrinted == '2' ? 'selected="selected"' : '' }}>{{ text_yes }}</option>
                            </select>
                        </div>
                        <div class="form-group col-sm-3">
                            <label class="control-label">{{ text_dispatched }}</label>
{#                            <input type="text" class="form-control" value="{{ filter_dispatched }}" id="filter_dispatched" name="filter_dispatched" placeholder="Dispatched">#}
                            <select name="filter_dispatched" id="filter_dispatched" class="form-control">
                                <option value="">--- {{ text_none }} ---</option>
                                <option value="1" {{ filter_dispatched == '1' ? 'selected="selected"' : '' }}>{{ text_no }}</option>
                                <option value="2" {{ filter_dispatched == '2' ? 'selected="selected"' : '' }}>{{ text_yes }}</option>
                            </select>
                        </div>
                    </div>

                    <div class="panel-footer">
                        <div class="row">
                            <div class="col-sm-12 text-right">
                                <button type="button" class="btn btn-primary" id="button-filter"><i class="fa fa-filter"></i>
                                    {{ text_filter }}</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-body">
                <div class="row">
                    <div class="col-sm-12">
                        <div class="dropdown">
                            <button class="btn btn-default dropdown-toggle" type="button" id="inpostBulkActions" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
                                {{ text_bulk_actions }}
                                <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu" aria-labelledby="inpostBulkActions">
                                <li><a href="#" class="select-all"><i class="fa fa-check-square"></i>{{ text_select_all }}</a></li>
                                <li><a href="#" class="unselect-all"><i class="fa fa-square">{{ text_unselect_all }}</i></a></li>
                                <li role="separator" class="divider"></li>
{#                                <li><a href="#" class="bulk-generate-link" id="inpost-shipments">Create Shipment</a></li>#}
                                <li><a href="#" class="bulk-generate-link" id="inpost-labels">{{ text_print_labels }}</a></li>
                                <li><a href="#" class="bulk-generate-link" id="inpost-returns">{{ text_print_return_labels }}</a></li>
                                <li><a href="#" class="bulk-generate-link" id="inpost-create-dispatch">{{ text_create_dispatch_orders }}</a></li>
                                <li><a href="#" class="bulk-generate-link" id="inpost-print-dispatch">{{ text_print_dispatch_labels }}</a></li>
                            </ul>
                        </div>
                    </div>
                </div>
                <br>
                <table class="table table-bordered table-responsive shipments-table">
                    <thead>
                        <tr>
                            <td></td>
                            <td><a href="{{ sort_filter_idInpost }}" {% if sort == 'idInpost' %} class="{{ order|lower }}" {% endif %}>{{ text_shipment_number }}</a></td>
                            <td><a href="{{ sort_filter_reference }}" {% if sort == 'reference' %} class="{{ order|lower }}" {% endif %}>{{ text_reference }}</a></td>
                            <td><a href="{{ sort_filter_price }}" {% if sort == 'price' %} class="{{ order|lower }}" {% endif %}>{{ text_price }}</a></td>
                            <td>{{ text_service }}</td>
                            <td>{{ entry_shipping_method }}</td>
                            <td>{{ entry_shipping_phone }}</td>
                            <td><a href="{{ sort_filter_email }}" {% if sort == 'email' %} class="{{ order|lower }}" {% endif %}>{{ entry_shipping_email }}</a></td>
                            <td><a href="{{ sort_filter_created_at }}" {% if sort == 'created_at' %} class="{{ order|lower }}" {% endif %}>{{ text_created_at }}</a></td>
                            <td><a href="{{ sort_filter_labelPrinted }}" {% if sort == 'labelPrinted' %} class="{{ order|lower }}" {% endif %}>{{ text_label_printed }}</a></td>
                            <td><a href="{{ sort_filter_dispatched }}" {% if sort == 'dispatched' %} class="{{ order|lower }}" {% endif %}>{{ text_dispatched }}</a></td>
                            <td>Actions</td>
                        </tr>
                    </thead>
                    <tbody>
                    {% for shipment in shipments %}
                        <tr data-id="{{ shipment.id_shipment }}">
                            <td>
                                <div class="checkbox">
                                    <label>
                                        <input type="checkbox" value="{{ shipment.id_shipment }}" />
                                    </label>
                                </div>
                            </td>
                            <td>{{ shipment.tracking_number ? shipment.tracking_number : '---' }}</td>
                            <td>{{ shipment.reference }}</td>
                            <td>--</td>
                            <td>{{ apiServices[shipment.service]['description'] }}</td>
                            <td>{{ apiShippingMethods[shipment.sending_method]['description'] }}</td>
                            <td>{{ phone ? phone : shipment.orderInfo.telephone }}</td>
                            <td>{{ email ? email : shipment.orderInfo.email }}</td>
                            <td>{{ shipment.created_at }}</td>
                            <td><i class="fa fa-{{ shipment.labelPrinted ? 'check' : 'times' }}"></i></td>
                            <td><i class="fa fa-{{ shipment.dispatched ? 'check' : 'times' }}"></i></td>
                            <td>
                                <button class="btn btn-sm btn-warning view-order" data-order="{{ shipment.reference }}">{{ text_view_order }}</button>
                                <button class="btn btn-sm btn-info print-label">{{ text_print_label }}</button>
                                <button class="btn btn-sm btn-danger return-shipment">{{ text_return }}</button>
                                {% if shipment.createDispatchOrder %}<button class="btn btn-sm btn-primary create-dispatch-order">{{ text_dispatch_order }}</button>{% endif %}
                                {% if shipment.printDispatchOrder %}<button class="btn btn-sm btn-info print-dispatch-order">{{ text_print_dispatch_label }}</button>{% endif %}
                            </td>
                        </tr>
                    {% endfor %}
                    </tbody>
                </table>
                <div class="row">
                    <div class="col-sm-6 text-left">{{ pagination }}</div>
                    <div class="col-sm-6 text-right">{{ results }}</div>
                </div>
                <input type="hidden" id="userToken" value="{{ userToken }}">
                <input type="hidden" id="returnsUrl" value="{{ returnsUrl }}">
            </div>
        </div>
    </div>
</div>
<script>
    $(document).on('click', '#button-filter', function() {
        url = '';
        var filter_idInpost = $('input[name=\'filter_idInpost\']').val();
        if (filter_idInpost) {
            url += '&filter_idInpost=' + encodeURIComponent(filter_idInpost);
        }

        var filter_reference = $('input[name=\'filter_reference\']').val();
        if (filter_reference) {
            url += '&filter_reference=' + encodeURIComponent(filter_reference);
        }

        var filter_service = $('select[name=\'filter_service\']').val();
        if (filter_service) {
            url += '&filter_service=' + encodeURIComponent(filter_service);
        }

        var filter_sending_method = $('select[name=\'filter_sending_method\']').val();
        if (filter_sending_method) {
            url += '&filter_sending_method=' + encodeURIComponent(filter_sending_method);
        }

        var filter_created_at = $('input[name=\'filter_created_at\']').val();
        if (filter_created_at) {
            url += '&filter_created_at=' + encodeURIComponent(filter_created_at);
        }

        var filter_labelPrinted = $('select[name=\'filter_labelPrinted\']').val();
        if (filter_labelPrinted) {
            url += '&filter_labelPrinted=' + encodeURIComponent(filter_labelPrinted);
        }

        var filter_dispatched = $('select[name=\'filter_dispatched\']').val();
        if (filter_dispatched) {
            url += '&filter_dispatched=' + encodeURIComponent(filter_dispatched);
        }

        location = 'index.php?route=extension/shipping/inpost_shipping/shipmentsList&user_token={{ userToken }}' + url;
    });
</script>
{{ footer }}