<ul class="list-group">
	<li class="list-group-item header-right">
		<div class="row">
			<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>Vendedor</label>
							<select name ="vendedor" class="form-control select-vendedor" onchange="this.form.submit()">
							<?php
							foreach ($encargados as $k => $v) {
								$selected = '';
								if ($vendedor == $k) {
									$selected =' selected="selected"';
								}
								echo '<option value="' . $k . '"' . $selected . '>' . $v . '</option>';
							}
							?>
							</select>
						</li>
						<li class="nav-item float-left mr-3">
							<label>Inicio</label>
							<input type="date" name ="inicio" class="form-control input-inicio" onchange="this.form.submit()" value="<?php echo $inicio; ?>"/>
							
						</li>
						<li class="nav-item float-left mr-3">
							<label>Fin</label>
							<input type="date" name ="fin" class="form-control input-fin" onchange="this.form.submit()" value="<?php echo $fin; ?>"/>
						</li>
						<?php
/*
						if (in_array($a, ['boletas', 'preparacion'])) {
						?>
							<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>
						<?php
						}
						if (in_array($a, ['tienda', 'feria', 'boletas', 'facturas', 'balance', 'mensual'])) {
						?>
							<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 ($a == 'tienda') {
									$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>
						<?php
						}
						//if (in_array($a, ['p','r','e','ee'])) {
						if (in_array($a, ['preparacion', 'retiros', 'enviados', 'en_espera'])) {
						?>
							<li class="nav-item float-left mr-3">
								<?php // Select de Transportistas ?>
								<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">
								<?php // Select de Usuario asignado ?>
								<label>Usuario Asignado</label>
								<select name ="asignado" class="form-control select-asignado" onchange="this.form.submit()">
									<?php
									$selected ='';
									if (!isset($_GET['asignado'])) {
										$selected ='selected="selected"';
									}
									echo '<option value="-1" ' . $selected . '>Todos</option>';

									$selected ='';
									if (isset($_GET['asignado']) && $_GET['asignado'] == 0) {
										$selected ='selected="selected"';
									}
									echo '<option value="0"' . $selected . '>Sin Asignar</option>';
									foreach ($usuarios as $k => $v) {
										$selected = '';
										if (!empty($_GET['asignado'])) {
											if ($_GET['asignado'] == $k) {
												$selected =' selected="selected"';
											}
										}
										echo '<option value="' . $k . '"' . $selected . '>' . $v . '</option>';
									}
									?>
								</select>
							</li>
							<?php
							if ($a == 'ee') {
								$fields['fecha'] = 'Fecha de llegada';
							}
							if ($a == 'e') {
								$fields['fecha_envio'] = 'Fecha de envío';
							}
							$fields['id_transportista'] = 'Transportista';
							$fields['cliente'] = 'Alfabeticamente';
							$fields['fecha_venta'] = 'Fecha de venta';

							$orden = $_GET['orden'] ?? '';
							?>
							<li class="nav-item float-left">
								<label>Ordenar por:</label>
								<select name ="orden" class="form-control select-orden" onchange="this.form.submit()">
									<?php
										if (in_array($a, ['enviados'])) {
											echo '<option value="fecha_envio">Fecha de envío</option>';
										}
										foreach ($fields as $f => $v) {
											$s ='';
											if ($f == $orden) {
												$s ='selected="selected"';
											}
											echo '<option value="' . $f . '" ' . $s . '>' . $v . '</option>';
										}
									?>
								</select>
							</li>
						<?php
						}
						*/
						?>
					</form>
				</ul>
			</div>
		</div>
	</li>
<?php
$data['clientes'] = $clientes;
if(!empty($ventas)) {
	?>
	<li class="list-group-item">
		<div class="row">
			<div class="col-12">
				<h4 class="mes">
					<?php echo $encargados[$vendedor]; ?>
					<span class="badge badge-pill badge-primary tt" title="Cantidad de Ventas"><?php echo $cantidad; ?></span>
					<span class="badge badge-pill badge-success tt" title="Total Vendido"><?php echo clp($total); ?></span>
				</h4>
			</div>
		</div>
		<?php
			foreach($ventas as $v) {
				?>
				<div>
					<?php
						$data['v'] = $v;
						$data['boletas'] = true;
						$this->load->view('ventas/single', $data);
					?>
				</div>
				<?php
			}
		?>
	</li>
	<?php
}
else {
	?>
	<li class="list-group-item">No hay ventas</li>
	<?php
}
?>
</ul>

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