<ul class="list-group">
	<li class="list-group-item header-right">
		<div class="col-12">
			<ul class="nav nav-pills alt-pills float-right mini-labels">
				<form method="get">
					<li class="nav-item float-left mr-3">
						<label>Estado Boleta</label>
						<select name ="emision" class="form-control select-emision" onchange="this.form.submit()">
						<?php
						$estadosBoletas = ['-1' => 'Todos', 0 => 'Pendiente', 1 => 'Emitida'];
						foreach ($estadosBoletas as $k => $v) {
							$selected = '';
							if ($emision == $k) {
								$selected =' selected="selected"';
							}
							echo '<option value="' . $k . '"' . $selected . '>' . $v . '</option>';
						}
						?>
						</select>
					</li>
					<li class="nav-item float-left mr-3">
						<label>Tipo Documento</label>
						<select name ="tipo-documento" class="form-control select-tipo-documento" onchange="this.form.submit()">
						<?php
						echo '<option value="">Todos</option>';
						foreach ($tipos_documentos as $k => $v) {
							if (in_array($k, [1, 5, 7, 8, 9, 11, 12])) {
								$selected = '';
								if (!empty($_GET['tipo-documento'])) {
									if ($_GET['tipo-documento'] == $k) {
										$selected =' selected="selected"';
									}
								}
								echo '<option value="' . $k . '"' . $selected . '>' . $v . '</option>';
							}
						}
						?>
						</select>
					</li>
					<li class="nav-item float-left mr-3">
						<label>Canal de Venta</label>
						<select name ="canal" class="form-control select-canal" onchange="this.form.submit()">
						<?php
						echo '<option value="0">Todos</option>';
						foreach ($canales as $k => $v) {
							$selected = '';
							if (!empty($_GET['canal'])) {
								if ($_GET['canal'] == $k) {
									$selected =' selected="selected"';
								}
							}
							echo '<option value="' . $k . '"' . $selected . '>' . $v . '</option>';
						}
						?>
						</select>
					</li>
					<li class="nav-item float-left mr-3">
						<label>Transportista</label>
						<select name ="transportista" class="form-control select-transportista" onchange="this.form.submit()">
							<?php
								echo '<option value="0">Todos</option>';
								foreach ($transportistas_disponibles as $k => $v) {
									$selected = '';
									if (!empty($_GET['transportista'])) {
										if ($_GET['transportista'] == $k) {
											$selected =' selected="selected"';
										}
									}
									echo '<option value="' . $k . '"' . $selected . '>' . $v . '</option>';
								}
							?>
						</select>
					</li>
					<li class="nav-item float-left mr-3">
						<label>Periodo</label>
						<select name ="periodo" class="form-control select-periodo" onchange="this.form.submit()">
						<?php
						if (in_array($a, ['tienda_cite_italia', 'tienda_italia_1601', 'tienda_los_dominicos', 'tienda_drugstore', 'feria'])) {
							$selected = '';
							if (!empty($_GET['periodo'])) {
								$selected = $_GET['periodo'] == 'hoy' ?  'selected="selected"' : '';
							}
							echo '<option value="hoy"' . $selected . '>Hoy</option>';
							if (!empty($_GET['periodo'])) {
								$selected = $_GET['periodo'] == 'semana' ?  'selected="selected"' : '';
							}
							echo '<option value="semana"' . $selected . '>Semana Actual</option>';
						}
						foreach ($meses_ventas as $k => $v) {
							$selected = '';
							if (!empty($_GET['periodo'])) {
								if ($_GET['periodo'] == $v) {
									$selected =' selected="selected"';
								}
							}
							echo '<option value="' . $v . '"' . $selected . '>' . mtt($v) . '</option>';
						}
						?>
						</select>
					</li>
				</form>
			</ul>
		</div>
	</li>
	<li class="list-group-item text-right">
		<form action="<?php echo site_url('ventas/exportar_boletas_csv'); ?>" method="post" class="mb-0">
			<input type="hidden" name="emision" value="<?php echo isset($_GET['emision']) ? $_GET['emision'] : ''; ?>">
			<input type="hidden" name="periodo" value="<?php echo isset($_GET['periodo']) ? $_GET['periodo'] : ''; ?>">
			<input type="hidden" name="canal" value="<?php echo isset($_GET['canal']) ? $_GET['canal'] : ''; ?>">
			<input type="hidden" name="tipo-documento" value="<?php echo isset($_GET['tipo-documento']) ? $_GET['tipo-documento'] : ''; ?>">
			<input type="hidden" name="transportista" value="<?php echo isset($_GET['transportista']) ? $_GET['transportista'] : ''; ?>">
			<button type="submit" class="btn btn-success">Descargar CSV</button>
		</form>
	</li>
<?php
//$data['clientes'] = $clientes;
if(!empty($ventas)) {
	?>
	<li class="list-group-item">
		<div class="row">
			<div class="col-sm-6">
				<h4 class="mes clickable">
					<?php echo mtt($periodo);?>
					<span class="badge badge-pill badge-primary tt" title="Cantidad de ventas encontradas"><?php echo clp($ventas['cantidad']); ?></span> 
					<span class="badge badge-pill badge-success tt" title="Monto total encontrado"><?php echo clp($ventas['monto']); ?></span>
				</h4>
			</div>
			<div class="col-sm-6 text-right">
				<h5>
					<span class="badge badge-pill badge-danger tt" title="Cantidad Pendiente"><?php echo $ventas['sin_boleta'];?></span>
					<span class="badge badge-pill badge-danger tt" title="Total Pendiente"><?php echo clp($ventas['total_sin_boleta']);?></span>

					<span class="badge badge-pill badge-info tt" title="Cantidad"><?php echo $ventas['boletas'];?></span>
					<span class="badge badge-pill badge-success tt" title="Total Ventas"><?php echo clp($ventas['total_boletas']); ?></span>
				</h5>
			</div>
		</div>
		<?php
			if (!empty($ventas['ventas'])) {
				foreach($ventas['ventas'] as $v) {
					?>
					<div>
						<?php
							$data['v'] = $v;
							$data['boletas'] = true;
							$this->load->view('ventas/single', $data);
						?>
					</div>
					<?php
				}
			}
			else {
				echo 'Aún no existen ventas para emitir boletas';
			}
		?>
	</li>
	<?php
}
else {
	?>
	<li class="list-group-item">No hay ventas pendientes</li>
	<?php
}
?>
</ul>

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