<?php

$a = $this->router->method;
$c = [
	's' => '', // tienda
	'fe' => '', // feria
	'b' => '', // Boletas
	'p' => '', // Preparación
	'r' => '', // Retiros
	'e' => '', // Enviados
	'ee' => '', // En espera
	'f' => '', // Facturas
	't' => '', // Transportistas
	//'i' => '', // Index / Ventas
	'u' => '', // Utilidades
];
$c[$a] = 'active';

$ua = !empty($ua) ? $ua : '';

// Utilidades
if ($a == 'u') {
	$u = [
		'b' => '', // Balance
		'g' => '', // Gráficos
		'e' => '', // Etiquetas
		'ch' => '', //Checklist
		'en' => '', // Envios
		'm' => '', // Mensual
	];
	$u[$ua] = 'active';
}
?>
<div class="row">
	<div class="col-12 col-xl-5">
		<?php
		if (empty($c['u'])) {
		?>
			<ul class="nav nav-pills alt-pills">
				<?php if (!in_array($a, ['tienda_cite_italia', 'tienda_italia_1601', 'tienda_los_dominicos','tienda_drugstore', 'feria'])) { ?>
				<li class="nav-item mr-2 mb-1">
					<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#modalVenta" data-id="0" data-channel="1">
						<i class="fas fa-plus"></i> Agregar
					</button>
				</li>
				<?php } ?>
				<?php if (in_array($a, ['tienda_cite_italia'])) { ?>
				<li class="nav-item mr-2 mb-1">
					<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#modalVenta" data-id="0" data-channel="2">
						<i class="fas fa-plus"></i> Venta Cité Italia
					</button>
				</li>
				<?php } ?>
				<?php if (in_array($a, ['tienda_italia_1601'])) {
					if ((isset($_SESSION['usuario']['id_canal']) && $_SESSION['usuario']['id_canal'] == 7) || $_SESSION['usuario']['admin'] == 1) {
					?>
					<li class="nav-item mr-2 mb-1">
						<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#modalVenta" data-id="0" data-channel="7">
							<i class="fas fa-plus"></i> Venta Italia 1601
						</button>
					</li>
				<?php } 
				} ?>
				<?php if (in_array($a, ['tienda_los_dominicos'])) { 
					if ((isset($_SESSION['usuario']['id_canal']) && $_SESSION['usuario']['id_canal'] == 8) || $_SESSION['usuario']['admin'] == 1) {
					?>
				<li class="nav-item mr-2 mb-1">
					<button type="button" class="btn btn-sm"  style="color: #CDDE00; background-color: #000000;" data-toggle="modal" data-target="#modalVenta" data-id="0" data-channel="8">
						<i class="fas fa-plus"></i> Venta Los Dominicos
					</button>
				</li>
				<?php } 
				} ?>
				<?php if (in_array($a, ['tienda_drugstore'])) { 
					if ((isset($_SESSION['usuario']['id_canal']) && $_SESSION['usuario']['id_canal'] == 12) || $_SESSION['usuario']['admin'] == 1) {
					?>
				<li class="nav-item mr-2 mb-1">
					<button type="button" class="btn btn-sm"  style="color: #FFFFFF; background-color: #ffca00;" data-toggle="modal" data-target="#modalVenta" data-id="0" data-channel="12">
						<i class="fas fa-plus"></i> Venta Drugstore
					</button>
				</li>
				<?php } 
				} ?>
				<?php if (!in_array($a, ['tienda_cite_italia', 'tienda_italia_1601', 'tienda_los_dominicos', 'tienda_drugstore', 'feria', 'index'])) { ?>
				<li class="nav-item mr-2 mb-1">
					<button type="button" class="btn btn-warning btn-sm" data-toggle="modal" data-target="#modalVenta" data-id="0" data-channel="3">
						<i class="fas fa-plus"></i> Market Place
					</button>
				</li>
				<?php } ?>
				<?php if (in_array($a, ['feria'])) {
					if ((isset($_SESSION['usuario']['id_canal']) && $_SESSION['usuario']['id_canal'] == 4) || $_SESSION['usuario']['admin'] == 1) {
					?>
				<li class="nav-item mr-2 mb-1">
					<button type="button" class="btn btn-success btn-sm" data-toggle="modal" data-target="#modalVenta" data-id="0" data-channel="4">
						<i class="fas fa-plus"></i> Venta Feria
					</button>
				</li>
				<?php } 
				} ?>
				<?php if (in_array($a, ['index'])) { ?>
				<li class="nav-item mr-2 mb-1">
					<button type="button" class="btn btn-primary btn-sm" data-toggle="modal" data-target="#modalVenta" data-id="0" data-channel="6">
						<i class="fas fa-plus"></i> Nota Crédito
					</button>
				</li>
				<?php } ?>
			</ul>
		<?php
		}
		?>
	</div>
	<?php
	if ($a != 't') {
	?>
		<div class="col-12 col-xl-7">
			<ul class="nav nav-pills alt-pills float-right mini-labels">
				<form method="get">
					<?php
					if (in_array($a, ['boletas'])) {
					?>
						<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>
					<?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, ['boletas'])) {
						?>
							<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>
						<?php
					}

					// Si el canal que estamos viendo tiene puntos de venta permite filtrar por punto de venta
					if (!empty($idCanal) && !empty($canales_puntos_ventas['puntos_ventas'][$idCanal])) {
						if (count($canales_puntos_ventas['puntos_ventas'][$idCanal]) > 1) {
							$puntosVentas = $canales_puntos_ventas['puntos_ventas'][$idCanal];
							?>
							<li class="nav-item float-left mr-3">
							<label>Punto Venta</label>
								<select name ="punto_venta" class="form-control filtros-select-punto-venta" onchange="this.form.submit()">
								<?php
								echo '<option value="">Todos</option>';
								foreach ($puntosVentas as $k => $v) {
									$selected = '';
									if (!empty($_GET['punto_venta'])) {
										if ($_GET['punto_venta'] == $k) {
											$selected =' selected="selected"';
										}
									}
									echo '<option value="' . $k . '"' . $selected . '>' . $v . '</option>';
								}
								?>
								</select>
							</li>
						<?php
						}
					}

					if (in_array($a, ['tienda_cite_italia', 'tienda_italia_1601', 'tienda_los_dominicos', 'tienda_drugstore','feria', 'boletas', 'facturas', 'balance', 'mensual', 'envios', 'tipo_documento'])) {
					?>
						<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>
					<?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 ($encargados 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
					}
					/*
					if (in_array($a, ['index'])) {
					?>
						<li class="nav-item float-left mr-3">
						<label>Tipo</label>
							<select name ="tipo" class="form-control select-tipo" onchange="this.form.submit()">
							<?php
							$tipos = [0 => 'Todos', 2 => 'Factura', 3 => 'Nota de Crédito', 4 => 'Merma', 6 => 'Abono'];
							foreach ($tipos as $k => $v) {
								$selected = '';
								if (!empty($_GET['tipo'])) {
									if ($_GET['tipo'] == $k) {
										$selected =' selected="selected"';
									}
								}
								echo '<option value="' . $k . '"' . $selected . '>' . $v . '</option>';
							}
							?>
							</select>
						</li>
					<?php
					}*/
					?>
				</form>
			</ul>
		</div>
	<?php
	}
	?>
</div>