<?php $__env->startSection('titulo', 'Reportes'); ?>

<?php $__env->startSection('css'); ?>
	<?php echo Html::style('css/jquery.datetimepicker.min.css'); ?>

	<style type="text/css">
		.form-group div {
			margin-top: 2px;
		}
	</style>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('botonera'); ?>
	<li class="form-group">
		<a href="<?php echo URL::to('admin'); ?>" class="btn btn-warning btn-right">Salir</a>
	</li>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('content'); ?>
	<?php echo $__env->make('alerts.request', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>
	<div class="row">
		
		<?php if(isset($formulario)): ?>
			<?php echo Form::model($formulario, ['class' => 'form-horizontal', 'url' => '/reportes', 'method' => 'POST']); ?>

		<?php else: ?>
			<?php echo Form::open(['class' => 'form-horizontal', 'url' => '/reportes', 'method' => 'POST']); ?>

		<?php endif; ?>
		
			<div class="form-group form-group-sm">
		
				<div class="col-sm-7">

					<?php echo Form::label('tipo', 'Tipo', ['class' => 'col-sm-2 control-label']); ?>

					<div class="col-sm-4">
						<?php echo Form::select('tipo', ['Inscripción', 'Seguimiento'], null, ['class' => 'form-control']); ?>

					</div>
					
					<?php if(isset($formulario)): ?>
						<div id="seccion-cantidad">
							<?php echo Form::label('cantidad', 'Cantidad', ['class' => 'col-sm-2 control-label']); ?>

							<div class="col-sm-4">
								<?php echo Form::text('cantidad', null, ['class' => 'form-control', 'readonly']); ?>

							</div>
						</div>
					<?php else: ?>
						<div class="clearfix"></div>
					<?php endif; ?>

					<?php echo Form::label('programa_id', 'Programa', ['class' => 'col-sm-2 control-label']); ?>

					<div class="col-sm-10">
						<?php echo Form::select('programa_id', $programas, null, ['class' => 'form-control']); ?>

					</div>

				</div>

				<div class="col-sm-3">

					<?php echo Form::label('desde', 'Desde', ['class' => 'col-sm-4 control-label']); ?>

					<div class="col-sm-8">
							<?php echo Form::text('desde', isset($fechaActual) ? $fechaActual : null, ['class' => 'form-control']); ?>

					</div>

					<?php echo Form::label('hasta', 'Hasta', ['class' => 'col-sm-4 control-label']); ?>

					<div class="col-sm-8">
						<?php echo Form::text('hasta', isset($fechaActual) ? $fechaActual : null, ['class' => 'form-control']); ?>

					</div>

				</div>

				<div class="col-sm-2">
					<div class="col-sm-12">
						<?php echo Form::submit('Buscar', ['class' => 'btn btn-primary btn-sm']); ?>

					</div>
					<?php if(isset($registros) && count($registros)): ?>
						<div class="col-sm-12">
							<?php echo link_to_action('ReportesController@mostrarPdfReporte',
								$title = 'Imprimir reporte',
								$parameters = [
									$formulario['tipo'],
									$formulario['programa_id'],
									$formulario['fecha_inicio'],
									$formulario['fecha_fin']
								],
								$attributes = ['id' => 'btn-imprimir-reporte', 'class' => 'btn btn-success btn-sm', 'target' => '_blank', 'mehtod' => 'POST']); ?>

						</div>
					<?php endif; ?>
				</div>

			</div>

		<?php echo Form::close(); ?>


		<?php if(isset($registros) && count($registros)): ?>
			<table class="table table-bordered table-condensed table-hover">
				<thead>
					<?php if($formulario['tipo'] == 0): ?>
						<th>Estado</th>
					<?php endif; ?>
					<th>Fecha / Hora (24h)</th>
					<?php if(isset($registros[0]->programa)): ?>
						<th>Programa</th>
					<?php endif; ?>
					<th>Documento</th>
					<th>Paciente</th>
					<th>Operaciones</th>
				</thead>
				<tbody>
					<?php foreach($registros as $registro): ?>
						<?php if($formulario['tipo'] == 0): ?>
							<?php if($registro->deleted_at): ?>
								<tr class="bg-danger">
									<td>Inactiva</td>
							<?php else: ?>
								<tr>
									<td>Activa</td>
							<?php endif; ?>
						<?php endif; ?>
							<td><?php echo e("$registro->fecha $registro->hora"); ?></td>
							<?php if(isset($registro->programa)): ?>
								<td><?php echo e($registro->programa); ?></td>
							<?php endif; ?>
							<td><?php echo e($registro->documento); ?></td>
							<td><?php echo e($registro->paciente_nombre); ?></td>
							<td>
								<?php if($formulario['tipo'] == 1): ?>
									<?php echo link_to('/mostrar-pdf/'.$registro->programaId.'/'.$registro->id, 
										$title = 'Imprimir',
										$attributes = ['class' => 'btn btn-success btn-xs', 'target' => '_blank']); ?>

								<?php else: ?>
									<?php echo link_to('/mostrar-pdf-inscripcion/'.$registro->id, 
										$title = 'Imprimir',
										$attributes = ['class' => 'btn btn-success btn-xs', 'target' => '_blank']); ?>

								<?php endif; ?>
							</td>
						</tr>
					<?php endforeach; ?>
				</tbody>
			</table>
		<?php endif; ?>


	</div>
<?php $__env->stopSection(); ?>

<?php $__env->startSection('scripts'); ?>
	<?php echo Html::script('js/jquery.datetimepicker.full.js'); ?>

	<script type="text/javascript">

		// Date picker
		$('#desde, #hasta').datetimepicker({
			timepicker:false,
			format:'d M Y'
		});

		$(document).ready(function(){
			<?php echo $__env->make('componentes.script-mostrar-modal-request', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>

			// Limpiar resultados al cambiar un select
			$('select, input[type=text]').change(function(){
				$('.table, #btn-imprimir-reporte').remove();
				$('#seccion-cantidad').html('').addClass('clearfix');
			});
		});
		

	</script>
<?php $__env->stopSection(); ?>
<?php echo $__env->make('layouts.admin-bloqueo-vista', array_except(get_defined_vars(), array('__data', '__path')))->render(); ?>