{{ header }}{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
	  <div class="pull-right">
        <button type="submit" id="button-shipping" form="form-order" formaction="{{ shipping }}" formtarget="_blank" data-toggle="tooltip" title="{{ button_shipping_print }}" class="btn btn-info"><i class="fa fa-truck"></i></button>
        <button type="submit" id="button-invoice" form="form-order" formaction="{{ invoice }}" formtarget="_blank" data-toggle="tooltip" title="{{ button_invoice_print }}" class="btn btn-info"><i class="fa fa-print"></i></button>
        <a href="{{ add }}" data-toggle="tooltip" title="{{ button_add }}" class="btn btn-primary"><i class="fa fa-plus"></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 %}
    {% if success %}
	  <div class="alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i> {{ success }}
		<button type="button" class="close" data-dismiss="alert">&times;</button>
	  </div>
    {% endif %}
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-list"></i> {{ text_list }}</h3>
      </div>
      <div class="panel-body">
        <div class="maxy-backdrop"></div>
	    <div class="messages-body"></div>
        <form method="post" action="" enctype="multipart/form-data" id="form-order">
          <div class="table-responsive">
            <table class="table table-bordered table-hover">
              <thead>
                <tr class="table-pagination">
				  <td colspan="9">
					<div class="pull-left">{{ pagination }}</div>
					{% if pagination %}
					  <div class="pull-right pagination-text">{{ results }}</div>
					  {% else %}
					  <div class="pull-right">{{ results }}</div>
					{% endif %}
				  </td>
				</tr>
				<tr>
                  <td style="width: 1px;" class="text-center"><input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);" /></td>
                  <td class="text-center" style="width: 90px; min-width: 90px;">{% if sort == 'o.order_id' %} <a href="{{ sort_order }}" class="{{ order|lower }}">{{ column_order_id }}</a> {% else %} <a href="{{ sort_order }}">{{ column_order_id }}</a> {% endif %}</td>
                  <td class="text-left">{% if sort == 'customer' %} <a href="{{ sort_customer }}" class="{{ order|lower }}">{{ column_customer }}</a> {% else %} <a href="{{ sort_customer }}">{{ column_customer }}</a> {% endif %}</td>
				  <td class="text-left">{% if sort == 'o.payment_method' %} <a href="{{ sort_payment_method }}" class="{{ order|lower }}">{{ column_payment }}</a> {% else %} <a href="{{ sort_payment_method }}">{{ column_payment }}</a> {% endif %}</td>
                  <td class="text-center" style="width: 150px; min-width: 150px;">{% if sort == 'order_status' %} <a href="{{ sort_status }}" class="{{ order|lower }}">{{ column_status }}</a> {% else %} <a href="{{ sort_status }}">{{ column_status }}</a> {% endif %}</td>
                  <td class="text-center" style="width: 100px; min-width: 100px;">{% if sort == 'o.total' %} <a href="{{ sort_total }}" class="{{ order|lower }}">{{ column_total }}</a> {% else %} <a href="{{ sort_total }}">{{ column_total }}</a> {% endif %}</td>
                  <td class="text-center" style="width: 130px; min-width: 130px;">{% if sort == 'o.date_added' %} <a href="{{ sort_date_added }}" class="{{ order|lower }}">{{ column_date_added }}</a> {% else %} <a href="{{ sort_date_added }}">{{ column_date_added }}</a> {% endif %}</td>
                  <td class="text-center" style="width: 130px; min-width: 130px;">{% if sort == 'o.date_modified' %} <a href="{{ sort_date_modified }}" class="{{ order|lower }}">{{ column_date_modified }}</a> {% else %} <a href="{{ sort_date_modified }}">{{ column_date_modified }}</a> {% endif %}</td>
                  <td class="text-center" style="width: 140px; min-width: 140px;">{{ column_action }}</td>
				</tr>
				<tr class="table-filter">
				  <td></td>
				  <td class="text-right"><input type="text" name="filter_order_id" value="{{ filter_order_id }}" class="form-control text-right" /></td>
				  <td class="text-left"><input type="text" name="filter_customer" value="{{ filter_customer }}" class="form-control" /></td>
				  <td><input type="text" class="form-control" disabled="disabled" /></td>
				  <td class="text-center">
				    <select name="filter_order_status_id" onchange="filter();" class="form-control">
                      <option value=""></option>
					  {% if filter_order_status_id == '0' %}
					    <option value="0" selected="selected">{{ text_missing }}</option>
					    {% else %}
					    <option value="0">{{ text_missing }}</option>
					  {% endif %}
					  {% for order_status in order_statuses %}
					    {% if order_status.order_status_id == filter_order_status_id %}
						  <option value="{{ order_status.order_status_id }}" selected="selected">{{ order_status.name }}</option>
						  {% else %}
						  <option value="{{ order_status.order_status_id }}">{{ order_status.name }}</option>
					    {% endif %}
					  {% endfor %}
                    </select>
				  </td>
				  <td class="text-center"><input type="text" name="filter_total" value="{{ filter_total }}" class="form-control" /></td>
				  <td class="text-right">
				    <div class="input-group date">
					  <input type="text" name="filter_date_added" value="{{ filter_date_added }}" data-date-format="YYYY-MM-DD" class="form-control" />
					  <span class="input-group-btn">
					  <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
					  </span>
					</div>
				  </td>
				  <td class="text-right">
				    <div class="input-group date">
					  <input type="text" name="filter_date_modified" value="{{ filter_date_modified }}" data-date-format="YYYY-MM-DD" class="form-control" />
					  <span class="input-group-btn">
					  <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
					  </span>
					</div>
				  </td>
				  <td class="text-center"><button type="button" onclick="filter();" class="btn btn-info btn-sm"><i class="fa fa-search"></i> {{ button_filter }}</button></td>
				</tr>
              </thead>
              <tbody>
                {% if orders %}
                  {% for order in orders %}
					<tr>
					  <td class="text-center">
					    {% if order.order_id in selected %}
						  <input type="checkbox" name="selected[]" value="{{ order.order_id }}" checked="checked" />
						  {% else %}
						  <input type="checkbox" name="selected[]" value="{{ order.order_id }}" />
						{% endif %}
						<input type="hidden" name="shipping_code[]" value="{{ order.shipping_code }}" />
					  </td>
					  <td class="text-right">{{ order.order_id }}</td>
					  <td class="text-left">{{ order.customer }}</td>
					  <td class="text-left">{{ order.payment_method }}</td>
					  <td class="text-center">{{ order.order_status }}</td>
					  <td class="text-center">{{ order.total }}</td>
					  <td class="text-center">{{ order.date_added }}</td>
					  <td class="text-center">{{ order.date_modified }}</td>
					  <td class="text-center">
						<a href="{{ order.view }}" data-toggle="tooltip" title="{{ button_view }}" class="btn btn-info btn-sm"><i class="fa fa-eye fa-fw"></i></a>
						<a href="{{ order.edit }}" data-toggle="tooltip" title="{{ button_edit }}" class="btn btn-primary btn-sm"><i class="fa fa-pencil fa-fw"></i></a>
						<a href="{{ order.order_id }}" id="button-delete{{order.order_id }}" data-toggle="tooltip" title="{{ button_delete }}" class="btn btn-danger btn-sm"><i class="fa fa-trash-o fa-fw"></i></a>
					  </td>
					</tr>
                  {% endfor %}
                  {% else %}
                  <tr>
                    <td class="text-center" colspan="9">{{ text_no_results }}</td>
                  </tr>
                {% endif %}
              </tbody>
			  <tfoot>
			    <tr>
                  <td class="text-center"><input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);" /></td>
                  <td class="text-right">{% if sort == 'o.order_id' %} <a href="{{ sort_order }}" class="{{ order|lower }}">{{ column_order_id }}</a> {% else %} <a href="{{ sort_order }}">{{ column_order_id }}</a> {% endif %}</td>
                  <td class="text-left">{% if sort == 'customer' %} <a href="{{ sort_customer }}" class="{{ order|lower }}">{{ column_customer }}</a> {% else %} <a href="{{ sort_customer }}">{{ column_customer }}</a> {% endif %}</td>
				  <td class="text-left">{% if sort == 'o.payment_method' %} <a href="{{ sort_payment_method }}" class="{{ order|lower }}">{{ column_payment }}</a> {% else %} <a href="{{ sort_payment_method }}">{{ column_payment }}</a> {% endif %}</td>
                  <td class="text-center">{% if sort == 'order_status' %} <a href="{{ sort_status }}" class="{{ order|lower }}">{{ column_status }}</a> {% else %} <a href="{{ sort_status }}">{{ column_status }}</a> {% endif %}</td>
                  <td class="text-center">{% if sort == 'o.total' %} <a href="{{ sort_total }}" class="{{ order|lower }}">{{ column_total }}</a> {% else %} <a href="{{ sort_total }}">{{ column_total }}</a> {% endif %}</td>
                  <td class="text-center">{% if sort == 'o.date_added' %} <a href="{{ sort_date_added }}" class="{{ order|lower }}">{{ column_date_added }}</a> {% else %} <a href="{{ sort_date_added }}">{{ column_date_added }}</a> {% endif %}</td>
                  <td class="text-center">{% if sort == 'o.date_modified' %} <a href="{{ sort_date_modified }}" class="{{ order|lower }}">{{ column_date_modified }}</a> {% else %} <a href="{{ sort_date_modified }}">{{ column_date_modified }}</a> {% endif %}</td>
                  <td class="text-center">{{ column_action }}</td>
				</tr>
				<tr class="table-pagination">
				  <td colspan="9">
					<div class="pull-left">{{ pagination }}</div>
					{% if pagination %}
					  <div class="pull-right pagination-text">{{ results }}</div>
					  {% else %}
					  <div class="pull-right">{{ results }}</div>
					{% endif %}
				  </td>
				</tr>
			  </tfoot>
            </table>
          </div>
        </form>
      </div>
    </div>
  </div>
  <script type="text/javascript"><!--
function filter() {
	url = 'index.php?route=editors/order&user_token={{ user_token }}';

	var filter_order_id = $('input[name=\'filter_order_id\']').val();

	if (filter_order_id) {
		url += '&filter_order_id=' + encodeURIComponent(filter_order_id);
	}

	var filter_customer = $('input[name=\'filter_customer\']').val();

	if (filter_customer) {
		url += '&filter_customer=' + encodeURIComponent(filter_customer);
	}

	var filter_order_status_id = $('select[name=\'filter_order_status_id\']').val();

	if (filter_order_status_id !== '') {
		url += '&filter_order_status_id=' + encodeURIComponent(filter_order_status_id);
	}

	var filter_total = $('input[name=\'filter_total\']').val();

	if (filter_total) {
		url += '&filter_total=' + encodeURIComponent(filter_total);
	}

	var filter_date_added = $('input[name=\'filter_date_added\']').val();

	if (filter_date_added) {
		url += '&filter_date_added=' + encodeURIComponent(filter_date_added);
	}

	var filter_date_modified = $('input[name=\'filter_date_modified\']').val();

	if (filter_date_modified) {
		url += '&filter_date_modified=' + encodeURIComponent(filter_date_modified);
	}

	location = url;
}
//--></script> 
  <script type="text/javascript"><!--
$('input[name=\'filter_customer\']').autocomplete({
	'source': function(request, response) {
		$.ajax({
			url: 'index.php?route=editors/customer/autocomplete&user_token={{ user_token }}&filter_name=' +  encodeURIComponent(request),
			dataType: 'json',
			success: function(json) {
				response($.map(json, function(item) {
					return {
						label: item['name'],
						value: item['customer_id']
					}
				}));
			}
		});
	},
	'select': function(item) {
		$('input[name=\'filter_customer\']').val(item['label']);
	}
});
//--></script> 
  <script type="text/javascript"><!--
$('input[name^=\'selected\']').on('change', function() {
	$('#button-shipping, #button-invoice').prop('disabled', true);

	var selected = $('input[name^=\'selected\']:checked');

	if (selected.length) {
		$('#button-invoice').prop('disabled', false);
	}

	for (i = 0; i < selected.length; i++) {
		if ($(selected[i]).parent().find('input[name^=\'shipping_code\']').val()) {
			$('#button-shipping').prop('disabled', false);

			break;
		}
	}
});

$('#button-shipping, #button-invoice').prop('disabled', true);

$('input[name^=\'selected\']:first').trigger('change');

// IE and Edge fix!
$('#button-shipping, #button-invoice').on('click', function(e) {
	$('#form-order').attr('action', this.getAttribute('formAction'));
});

$('#form-order a[id^=\'button-delete\']').on('click', function(e) {
	e.preventDefault();
	
	var element = this;
	
	if (confirm('{{ text_confirm }}')) {
		$.ajax({
			url: '{{ catalog }}index.php?route=api/order/delete&api_token={{ api_token }}&store_id={{ store_id }}&order_id=' + $(element).attr('href'),
			dataType: 'json',
			success: function(json) {
				$('.alert-dismissible').remove();
	
				if (json['error']) {
					$('#content > .container-fluid').prepend('<div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> ' + json['error'] + ' <button type="button" class="close" data-dismiss="alert">&times;</button></div>');
				}
	
				if (json['success']) {
					location = '{{ delete }}';
				}
			},
			error: function(xhr, ajaxOptions, thrownError) {
				alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
			}
		});
	}
});
//--></script> 
  <script src="view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.js" type="text/javascript"></script>
  <link href="view/javascript/jquery/datetimepicker/bootstrap-datetimepicker.min.css" type="text/css" rel="stylesheet" media="screen" />
  <script type="text/javascript"><!--
$('.date').datetimepicker({
	language: '{{ datepicker }}',
	pickTime: false
});
//--></script></div>
{{ footer }} 