Días festivos
This commit is contained in:
@@ -10,12 +10,14 @@ $user = unserialize($_SESSION['user']);
|
|||||||
$ruta = "../";
|
$ruta = "../";
|
||||||
require_once "../include/bd_pdo.php";
|
require_once "../include/bd_pdo.php";
|
||||||
global $pdo;
|
global $pdo;
|
||||||
print_r($_POST);
|
//print_r($_POST);
|
||||||
if ($_POST['periodo'] == 0) {
|
if (!isset($_POST['periodo']) || count($_POST["periodo"])==0) {
|
||||||
$periodo = null;
|
//header("Location: ../días_festivos.php?error=1");
|
||||||
} else {
|
echo "Error no hay periodo";
|
||||||
$periodo = $_POST['periodo'];
|
exit();
|
||||||
}
|
}
|
||||||
|
$periodo = $_POST['periodo'];
|
||||||
|
|
||||||
if (isset($_POST['rango'])) {
|
if (isset($_POST['rango'])) {
|
||||||
$diaInicio = new DateTime(date("Y-m-d", strtotime(str_replace("/", "-", $_POST['diaFestivo']))));
|
$diaInicio = new DateTime(date("Y-m-d", strtotime(str_replace("/", "-", $_POST['diaFestivo']))));
|
||||||
$diaFin = new DateTime(date("Y-m-d", strtotime(str_replace("/", "-", $_POST['diaFestivoFin']))));
|
$diaFin = new DateTime(date("Y-m-d", strtotime(str_replace("/", "-", $_POST['diaFestivoFin']))));
|
||||||
|
|||||||
@@ -13,10 +13,28 @@ if ($user->acceso === null && !$user->admin){
|
|||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
$fs_dias_festivos = $db->query("SELECT d.diasfestivos_id, d.diasfestivos_dia , p.periodo_id , p.periodo_nombre, extract(dow from diasfestivos_dia) AS dia_id from diasfestivos d
|
|
||||||
join periodo p on p.periodo_id = any (d.periodos_id)
|
|
||||||
order by d.diasfestivos_dia DESC");
|
|
||||||
|
|
||||||
|
$periodo_rs = $db->querySingle('SELECT periodo_fecha_inicio, periodo_fecha_fin FROM periodo WHERE periodo_id = :periodo_id', [':periodo_id' => $user->periodo_id]);
|
||||||
|
|
||||||
|
|
||||||
|
if(isset($_POST["fecha_ini"]) && $_POST["fecha_ini"]!=""){
|
||||||
|
$fecha_ini_obj = DateTime::createFromFormat('d/m/Y', $_POST["fecha_ini"]);
|
||||||
|
}else{
|
||||||
|
$fecha_ini_obj = DateTime::createFromFormat('Y-m-d', $periodo_rs["periodo_fecha_inicio"]);
|
||||||
|
}
|
||||||
|
if(isset($_POST["fecha_fin"]) && $_POST["fecha_fin"]!=""){
|
||||||
|
$fecha_fin_obj = DateTime::createFromFormat('d/m/Y', $_POST["fecha_fin"]);
|
||||||
|
}else{
|
||||||
|
$fecha_fin_obj = DateTime::createFromFormat('Y-m-d', $periodo_rs["periodo_fecha_fin"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$fecha_ini = $fecha_ini_obj->format('d/m/Y');
|
||||||
|
$fecha_fin = $fecha_fin_obj->format('d/m/Y');
|
||||||
|
unset($periodo_rs);
|
||||||
|
|
||||||
|
$fs_dias_festivos = $db->query("SELECT d.diasfestivos_id, d.diasfestivos_dia , p.periodo_id , p.periodo_nombre, extract(dow from diasfestivos_dia) AS dia_id from diasfestivos d
|
||||||
|
join periodo p on p.periodo_id = any (d.periodos_id) where diasfestivos_dia between :ini and :fin
|
||||||
|
order by d.diasfestivos_dia DESC", [":ini"=> $fecha_ini_obj->format('Y-m-d'), ":fin"=>$fecha_fin_obj->format('Y-m-d')]);
|
||||||
|
|
||||||
|
|
||||||
$dias_arr = array();
|
$dias_arr = array();
|
||||||
@@ -31,8 +49,11 @@ foreach ($fs_dias_festivos as $dia){
|
|||||||
}
|
}
|
||||||
|
|
||||||
$dias_nombres=array("Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado");
|
$dias_nombres=array("Domingo", "Lunes", "Martes", "Miércoles", "Jueves", "Viernes", "Sábado");
|
||||||
|
|
||||||
$write = true;
|
$write = true;
|
||||||
|
|
||||||
|
$fs_periodos = $db->query("SELECT periodo_id, periodo_nombre, periodo_fecha_inicio, periodo_fecha_fin FROM periodo WHERE CURRENT_DATE < periodo_fecha_fin order by id_periodo_sgu");
|
||||||
|
|
||||||
|
|
||||||
?>
|
?>
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
@@ -79,7 +100,7 @@ $write = true;
|
|||||||
</div>
|
</div>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
<div id="message"></div>
|
<div id="message"></div>
|
||||||
<form action="dias_festivos.php" method="post" class="">
|
<form action="días_festivos.php" method="post" class="">
|
||||||
<div class="form-box">
|
<div class="form-box">
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
<label for="filter_fecha_ini" class="col-4 col-form-label">Fecha inicial</label>
|
<label for="filter_fecha_ini" class="col-4 col-form-label">Fecha inicial</label>
|
||||||
@@ -188,7 +209,7 @@ $write = true;
|
|||||||
<input id="diaFestivo" name="diaFestivo" type="text" class="form-control date-picker" placeholder="dd/mm/aaaa" maxlength="10" required="required" readonly="">
|
<input id="diaFestivo" name="diaFestivo" type="text" class="form-control date-picker" placeholder="dd/mm/aaaa" maxlength="10" required="required" readonly="">
|
||||||
</div>
|
</div>
|
||||||
<div class="col-1 diaFestivoRango">
|
<div class="col-1 diaFestivoRango">
|
||||||
<span class="ing-menos"></span>
|
<span class="ing-menos pt-2"></span>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-4 diaFestivoRango" id="diaFestivoRango">
|
<div class="col-4 diaFestivoRango" id="diaFestivoRango">
|
||||||
<input id="diaFestivoFin" name="diaFestivoFin" type="text" class="form-control date-picker" placeholder="dd/mm/aaaa" maxlength="10" required="required" readonly="">
|
<input id="diaFestivoFin" name="diaFestivoFin" type="text" class="form-control date-picker" placeholder="dd/mm/aaaa" maxlength="10" required="required" readonly="">
|
||||||
@@ -198,14 +219,19 @@ $write = true;
|
|||||||
|
|
||||||
<div class="form-group row" id="periodos">
|
<div class="form-group row" id="periodos">
|
||||||
<label for="periodos" class="col-3 col-form-label">Periodos</label>
|
<label for="periodos" class="col-3 col-form-label">Periodos</label>
|
||||||
<div class="col-7">
|
<div class="col-9" style="overflow-y:auto; overflow-x:none; max-height:220px; font-size:80%">
|
||||||
<select multiple="multiple" size="4" class="form-control">
|
<?php
|
||||||
|
foreach($fs_periodos as $per){
|
||||||
|
?>
|
||||||
|
<div class="form-check form-check-inline" data-fechaini = "<?php echo $per["periodo_fecha_inicio"];?>" data-fechafin = "<?php echo $per["periodo_fecha_fin"];?>">
|
||||||
|
<input class="form-check-input radio-lg " type="checkbox" id="check<?php echo $per["periodo_id"]?>" name="periodo[]" value="<?php echo $per["periodo_id"]?>">
|
||||||
|
<label for="check<?php echo $per["periodo_id"]?>" class="col-form-label"><?php echo $per["periodo_nombre"]?></label>
|
||||||
|
</div>
|
||||||
|
<?php
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
</div>
|
||||||
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div class="col-2">
|
|
||||||
<button class="btn btn-outline-primary"><span class="ing-mas"></span></button>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group row">
|
<div class="form-group row">
|
||||||
@@ -225,7 +251,7 @@ $write = true;
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="modal fade" id="modal_confirm" tabindex="-1" role="dialog" aria-labelledby="modal" aria-hidden="true">
|
<div class="modal fade" id="modal_confirm" tabindex="-1" role="dialog" aria-labelledby="modal_confirm" aria-hidden="true">
|
||||||
<div class="modal-dialog modal-dialog-centered" role="document">
|
<div class="modal-dialog modal-dialog-centered" role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
@@ -254,6 +280,13 @@ $write = true;
|
|||||||
require_once 'js/messages.php';
|
require_once 'js/messages.php';
|
||||||
?>
|
?>
|
||||||
<script>
|
<script>
|
||||||
|
$(document).on( "click", ".btn-reset", function(event){
|
||||||
|
var forma = $(this).parents("form");
|
||||||
|
forma.find("input[type=text]").val("");
|
||||||
|
forma.submit();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
$(document).ready(function(){
|
$(document).ready(function(){
|
||||||
$('.diaFestivoRango').hide();
|
$('.diaFestivoRango').hide();
|
||||||
});
|
});
|
||||||
@@ -299,19 +332,39 @@ $write = true;
|
|||||||
triggerMessage("No se encontraron días festivos", "Error");
|
triggerMessage("No se encontraron días festivos", "Error");
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
|
||||||
|
function actualizaPeriodos(fechaOriginal){
|
||||||
|
var partesFecha = fechaOriginal.split('/');
|
||||||
|
var fechaFestivo = partesFecha[2]+"-"+partesFecha[1]+"-"+partesFecha[0];
|
||||||
|
|
||||||
|
$.each($('#periodos .form-check'), function(){
|
||||||
|
if(fechaFestivo>= $(this).data("fechaini") && fechaFestivo<= $(this).data("fechafin")){
|
||||||
|
$(this).show();
|
||||||
|
}else{
|
||||||
|
$(this).find("input").prop("checked", false);
|
||||||
|
$(this).hide();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//Cambio de fecha valida periodos activos para esa fecha
|
||||||
|
$('#modal .date-picker').change(function(){
|
||||||
|
actualizaPeriodos($(this).val());
|
||||||
|
});
|
||||||
$('#modal').on('show.bs.modal', function (event){
|
$('#modal').on('show.bs.modal', function (event){
|
||||||
var button = $(event.relatedTarget);
|
var button = $(event.relatedTarget);
|
||||||
var tipo = button.data('tipo');
|
var tipo = button.data('tipo');
|
||||||
var modal = $(this);
|
var modal = $(this);
|
||||||
|
$("#formaModal .text-danger").removeClass("text-danger");
|
||||||
|
$("#diaFestivoFin").removeClass("is-invalid");
|
||||||
if(tipo==1){//agregar
|
if(tipo==1){//agregar
|
||||||
$('#modalLabel').html("Agregar Día Festivo");
|
$('#modalLabel').html("Agregar Día Festivo");
|
||||||
$('#submitBtn').data('tipo', 1);
|
$('#submitBtn').data('tipo', 1);
|
||||||
$('#diaFestivo').datepicker("setDate", today);
|
$('#diaFestivo').datepicker("setDate", today);
|
||||||
$('#diaFestivoFin').datepicker("setDate", today);
|
$('#diaFestivoFin').datepicker("setDate", today);
|
||||||
setDatalistFirst("#periodo");
|
|
||||||
$('#rangoDiv').show();
|
$('#rangoDiv').show();
|
||||||
$('#dia').removeClass('col-9');
|
$('#dia').removeClass('col-9');
|
||||||
$('#dia').addClass('col-4');
|
$('#dia').addClass('col-4');
|
||||||
|
actualizaPeriodos($("#diaFestivo").val());
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$('#modalLabel').html("Editar Día Festivo");
|
$('#modalLabel').html("Editar Día Festivo");
|
||||||
@@ -329,11 +382,7 @@ $write = true;
|
|||||||
success:function(result){
|
success:function(result){
|
||||||
console.log(result);
|
console.log(result);
|
||||||
$('#id').val(result['diasfestivos_id']);
|
$('#id').val(result['diasfestivos_id']);
|
||||||
if(!result['periodo_id']){
|
|
||||||
setDatalist('#periodo', 0);
|
|
||||||
}else{
|
|
||||||
setDatalist('#periodo', result['periodo_id']);
|
|
||||||
}
|
|
||||||
var date = new Date(result['diasfestivos_dia']);
|
var date = new Date(result['diasfestivos_dia']);
|
||||||
date.setDate(date.getDate() + 1);
|
date.setDate(date.getDate() + 1);
|
||||||
$('#diaFestivo').datepicker("setDate", date);
|
$('#diaFestivo').datepicker("setDate", date);
|
||||||
@@ -345,6 +394,8 @@ $write = true;
|
|||||||
|
|
||||||
function valida_campos(){
|
function valida_campos(){
|
||||||
var error=false;
|
var error=false;
|
||||||
|
$("#modal .text-danger").removeClass("text-danger");
|
||||||
|
$("#diaFestivoFin").removeClass("is-invalid");
|
||||||
if($("#diaFestivo").val()==""){
|
if($("#diaFestivo").val()==""){
|
||||||
$("#diaFestivo").addClass("is-invalid");
|
$("#diaFestivo").addClass("is-invalid");
|
||||||
error=true;
|
error=true;
|
||||||
@@ -360,6 +411,10 @@ $write = true;
|
|||||||
$('#diaFestivoFin').addClass("is-invalid");
|
$('#diaFestivoFin').addClass("is-invalid");
|
||||||
error=true;
|
error=true;
|
||||||
}
|
}
|
||||||
|
if($("#modal .form-check-input:checked").length<=0){
|
||||||
|
$("#modal .form-check-input").siblings().addClass("text-danger");
|
||||||
|
error=true;
|
||||||
|
}
|
||||||
if(error){
|
if(error){
|
||||||
return false;
|
return false;
|
||||||
}else{
|
}else{
|
||||||
|
|||||||
Reference in New Issue
Block a user