<ul class="list-group">
  <li class="list-group-item">
    <div class="row">
      <div class="col-6">
        <button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#modalCompra" data-id="0"><i class="fas fa-plus"></i> Agregar</h4>
      </div>
      <div class="col-6">
        <h4 class="total-compras text-right"><?php echo '[' . clp($totales['total'][$tipo_compra]) . ']'; ?></h4>
      </div>
    </div>
    <h4 class="mt-4"><?php echo $title; ?></h4>
	<ul class="nav nav-pills alt-pills float-right mini-labels">
		<form method="get">
			<li class="nav-item float-left mr-3">
				<label>Periodo</label>
					<select name ="periodo" class="form-control select-periodo" onchange="this.form.submit()">
					<?php
						$selected = '';
						foreach ($meses_compras as $k => $c) {
							$selected = '';
							if (!empty($_GET['periodo'])) {
								if ($_GET['periodo'] == $c) {
									$selected =' selected="selected"';
								}
							}
							echo '<option value="' . $c . '"' . $selected . '>' . mtt($c) . '</option>';
						}
					?>
					</select>
			</li>
		</form>
	</ul>
</li>
  
<?php
if(!empty($compras)) {
  $current_mes = 0;
  foreach($compras as $c) {
    if ($current_mes != $c['mes']) {
      if ($current_mes != 0) {
        echo '</div></li>';
      }
      $current_mes = $c['mes'];
      echo '<li class="list-group-item"><h4 class="mes">' . mtt($c['mes']) . ' [' . $totales[$current_mes][$tipo_compra]['cantidad'] . ': ' . clp($totales[$current_mes][$tipo_compra]['total']) . ']</h4>';
      echo '<div>';
    }
    $data['c'] = $c;
    $this->load->view('compras/single', $data);
  }
  echo '</div></li>';
}
else {
  ?>
  <li>A&uacute;n no hay compras</li>
  <?php
}
echo '</ul>';
?>

<?php $this->load->view('compras/modal'); ?>
<script src="<?php echo js('compras.js'); ?>"></script>