<?php echo $header; ?><?php echo $column_left; ?>
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="pull-right">
        <button  onclick="$('#print_form').submit();" id="button-invoice"   data-toggle="tooltip" class="btn btn-info"><i class="fa fa-print"></i></button>
      </div>
      <h1><?php echo $text_list_head; ?></h1>
      <ul class="breadcrumb">
        <?php foreach ($breadcrumbs as $breadcrumb) { ?>
        <li><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a></li>
        <?php } ?>
      </ul>
    </div>
  </div>
  <div class="container-fluid">
    <div class="panel panel-default">
      <div class="panel-heading">
        <h3 class="panel-title"><i class="fa fa-bar-chart"></i> <?php echo $text_list_head; ?></h3>
      </div>
      <div class="panel-body">
        <div class="well">
          <div class="row">
            <div class="col-sm-6">
              <div class="form-group">
                <label class="control-label" for="input-date-start"><?php echo $entry_date_start; ?></label>
                <div class="input-group date">
                  <input type="text" name="filter_date_start" value="<?php echo $filter_date_start; ?>" placeholder="<?php echo $entry_date_start; ?>" data-date-format="YYYY-MM-DD" id="input-date-start" class="form-control" />
                  <span class="input-group-btn">
                  <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
                  </span></div>
              </div>
              <div class="form-group">
                <label class="control-label" for="input-date-end"><?php echo $entry_date_end; ?></label>
                <div class="input-group date">
                  <input type="text" name="filter_date_end" value="<?php echo $filter_date_end; ?>" placeholder="<?php echo $entry_date_end; ?>" data-date-format="YYYY-MM-DD" id="input-date-end" class="form-control" />
                  <span class="input-group-btn">
                  <button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button>
                  </span></div>
              </div>
            </div>
            <div class="col-sm-6">
              <div class="form-group">
                <label class="control-label" for="input-status"><?php echo $entry_status; ?></label>
                <select name="filter_order_status_id" id="input-status" class="form-control">
                  <option value="0"><?php echo $text_all_status; ?></option>
                  <?php foreach ($order_statuses as $order_status) { ?>
                  <?php if ( $order_status['order_status_id'] == $filter_order_status_id ) { ?>
                  <option value="<?php echo $order_status['order_status_id']; ?>" selected="selected"><?php echo $order_status['name']; ?></option>
                  <?php } else { ?>
                  <option value="<?php echo $order_status['order_status_id']; ?>"><?php echo $order_status['name']; ?></option>
                  <?php } ?>
                  <?php } ?>
                </select>
              </div>
              <button type="button" id="button-filter" class="btn btn-primary pull-right"><i class="fa fa-filter"></i> <?php echo $button_filter; ?></button>
            </div>
          </div>
        </div>
        <div class="table-responsive">
          <form action="<?php echo $invoice; ?>" method="post" target="_blank" id="print_form">
          <table class="table table-bordered">
            <thead>
              <tr>
                <td><?php echo $text_customer_info; ?></td>
                <td><?php echo $text_product_name; ?></td>
                <td><?php echo $text_booking_date; ?></td>
                <td><?php echo $text_price; ?></td>
                <td><?php echo $text_quantity; ?></td>
                <td><?php echo $text_total; ?></td>
                <?php foreach($payment_methods as $payment_method){ ?>
                  <td><?php echo $payment_method; ?></td>
                <?php } ?>
              </tr>
            </thead>
              <?php foreach($orders as $order){ ?>
              <tr>
                <td rowspan="<?php echo max(count($order['products']),1);?>">
                  <?php echo $order['firstname']; ?><br>
                  <?php echo $order['sername']; ?><br>
                  <?php echo $order['phone']; ?><br>
                  <?php echo $order['mail']; ?><br>
                  <?php echo $order['date_start']; ?><br>
                  <?php echo $order['date_end']; ?><br>
                </td>
                <?php $firt=true;
                  foreach($order['products'] as $product){
                    if (!$firt){ ?><tr><?php } else { $firt=false; } ?>
                  <td><?php echo $product['name']; ?>
                    <?php if($product['options']) { ?>
                    <p><?php echo $product['options']; ?></p>
                    <?php } ?>
                  </td>
                  <td><?php echo $product['booking_date'];?></td>
                  <td><?php echo (int)$product['price'];?></td>
                <td><?php echo (int)$product['quantity'];?></td>
                  <td><?php echo (int)$product['total'];?></td>
                  <?php foreach($payment_methods as $payment_method){ ?>
                    <td><?php if(isset($product['payments'][$payment_method])){
                        echo $product['payments'][$payment_method];} ?>
                    </td>
                  <?php } ?>
                </tr>
              <?php }
              if (count($order['products'])==0){?>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <td></td>
                <?php foreach($payment_methods as $payment_method){ ?>
                <td></td>
                <?php } ?>
              </tr>
              <?php } ?>
              <?php } ?>
            </tbody>
          </table>
          </form>
        </div>
      </div>
    </div>
  </div>

  <script type="text/javascript"><!--
$('#button-filter').on('click', function() {
	url = 'index.php?route=report/sale_shipping&token=<?php echo $token; ?>';
	
	var filter_date_start = $('input[name=\'filter_date_start\']').val();
	
	if (filter_date_start) {
		url += '&filter_date_start=' + encodeURIComponent(filter_date_start);
	}

	var filter_date_end = $('input[name=\'filter_date_end\']').val();
	
	if (filter_date_end) {
		url += '&filter_date_end=' + encodeURIComponent(filter_date_end);
	}
		
	var filter_group = $('select[name=\'filter_group\']').val();
	
	if (filter_group) {
		url += '&filter_group=' + encodeURIComponent(filter_group);
	}
	
	var filter_order_status_id = $('select[name=\'filter_order_status_id\']').val();
	
	if (filter_order_status_id >= 0) {
		url += '&filter_order_status_id=' + encodeURIComponent(filter_order_status_id);
	}	

	location = url;
});
//--></script> 
  <script type="text/javascript"><!--
$('.date').datetimepicker({
	pickTime: false
});
//--></script></div>
<?php echo $footer; ?>