<?php 
	$this->load->view('productos/producto_nav');
?>
<ul class="list-group">
	<li class="list-group-item">
		<h2><?php echo $producto['nombre']; ?></h2>
		<?php /*
		<ul class="nav nav-pills alt-pills float-right mini-labels">
			<form method="get">
				<li class="nav-item float-left mr-3">
					<label>Canal de Venta</label>
					<select name ="id_canal" class="form-control filtro-id-canal" onchange="this.form.submit()">
					<?php
					echo '<option value="0">Todos</option>';
					foreach ($canales as $k => $v) {
						$selected = '';
						if (!empty($_GET['id_canal'])) {
							if ($_GET['id_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 ="id_transportista" class="form-control filtro-id-transportista" onchange="this.form.submit()">
						<?php
							echo '<option value="0">Todos</option>';
							foreach ($transportistas_disponibles as $k => $v) {
								$selected = '';
								if (!empty($_GET['id_transportista'])) {
									if ($_GET['id_transportista'] == $k) {
										$selected =' selected="selected"';
									}
								}
								echo '<option value="' . $k . '"' . $selected . '>' . $v . '</option>';
							}
						?>
					</select>
				</li>
			</form>
		</ul>
		*/ ?>
	</li>
	<li class="list-group-item">
		<div class="table-responsive">
			<h4>Compras
				<?php /*
				<span class="badge badge-pill badge-danger tt" title="Total Invertido"><?php echo clp($producto['total_gastado']); ?></span>
				<span class="badge badge-pill badge-primary tt" title="Compras"><?php echo count($producto['compras']); ?></span>
				<span class="badge badge-pill badge-info tt" title="Unidades Compradas"><?php echo $producto['comprados']; ?></span>
				*/ ?>
			</h4>
			<table class="table table-striped">
				<thead>
					<tr>
						<th class="text-center">ID</th>
						<th>Proveedor</th>
						<th class="text-center">Fecha</th>
						<th class="text-center">Tipo Documento</th>
						<th class="text-center">Cantidad</th>
						<th class="text-center">Costo Bruto</th>
						<th class="text-center">Costo Bruto Total</th>
						<th class="text-center">Acciones</th>
					</tr>
				</thead>
				<tbody>
					<?php
					foreach($compras as $c) {
						?>
						<tr>
							<td class="text-center">
								<span class="badge badge-pill badge-primary">
									<?php echo $c['folio']; ?>
								</span>
							</td>
							<td>
								<a href="/proveedores/view/<?php echo $c['id_proveedor']; ?>"><?php echo $proveedores[$c['id_proveedor']] ?? 'Sin Definir'; ?></a>
							</td>
							<td class="text-center">
								<span class="badge badge-pill badge-primary tt" title="Fecha de recepción"><?php echo fecha($c['fecha_recepcion']); ?></span>
							</td>
							<td class="text-center">
								<span class="badge badge-pill badge-primary tt" title="Tipo de compra"><?php echo $tipos_compras[$c['id_tipo_compra']]; ?></span>
							</td>
							<td class="text-center">
								<span class="badge badge-pill badge-primary tt" title="Cantidad comprada"><?php echo $c['cantidad']; ?></span>
							</td>
							<td class="text-center">
								<span class="badge badge-pill badge-primary tt" title="Costo bruto">
									<?php 
									$factor = ($c['descuenta_iva']) ? 1.19 : 1;
									echo clp($c['costo_neto'] * $factor); ?>
								</span>
							</td>
							<td class="text-center">
								<span class="badge badge-pill badge-primary tt" title="Costo total">
									<?php echo clp($c['costo_total'] * $factor); ?>
								</span>
							</td>
							<td class="text-center">
								<button type="button" class="btn btn-primary btn-xs" data-toggle="modal" data-target="#modalCompra" data-id="<?php echo $c['id_compra']; ?>">
									<i class="fas fa-pencil-alt"></i>
								</button>
							</td>
						</tr>
					<?php
					}
					?>
				</tbody>
			</table>
		</div>
		<div class="row paginacion">
			<div class="info col-12 col-md-6">
				<?php echo $paginacion['info']; ?>
			</div>
			<div class="col-12 col-md-6">
				<?php echo $paginacion['links']; ?>
			</div>
		</div>
	</li>
</ul>

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