Last active
August 29, 2015 14:09
-
-
Save sangar82/9eb5feca23e6bbd403d6 to your computer and use it in GitHub Desktop.
Row search stats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="row"> | |
<div class="col-md-8"> </div> | |
<div class="col-md-4"> | |
<div class="form-inline" role="form" style="margin-bottom: 6px"> | |
<div class="form-group" > | |
<input id="date_fix" name="dates_dateselectradio" type="radio" value="fix" checked="checked"> | |
</div> | |
<div class="form-group"> | |
<select id="dateselect" name="dates_dateselect" class="form-control" size="1"> | |
<option value="hoy">Hoy</option> | |
<option value="ayer">Ayer</option> | |
<option value="esta_semana">Esta semana</option> | |
<option value="semana_pasada">Semana pasada</option> | |
<option value="este_mes">Este mes</option> | |
<option value="mes_pasado">El mes pasado</option> | |
<option value="ultimos" selected="">Ultimos 30 días</option> | |
</select> | |
</div> | |
</div> | |
<div class="form-inline" role="form"> | |
<div class="form-group"> | |
<input id="date_variable" name="dates_dateselectradio" type="radio" value="variable"> | |
</div> | |
<div class="form-group"> | |
<input id="fecha_inicio" name="dates_fecha_inicio" class="fecha_inicio form-control" type="text" maxlength="10" size="10" minlength="8" disabled="disabled" placeholder="{{trans('web.start_date')}}"> | |
</div> | |
<div class="form-group"> | |
<input id="fecha_fin" name="dates_fecha_fin" class="fecha_fin form-control" type="text" maxlength="10" size="10" minlength="8" disabled="disabled" placeholder="{{trans('web.end_date')}}"> | |
</div> | |
<button type="submit" class="btn btn-success">Buscar</button> | |
</div> | |
</div> | |
</div> | |
$(function() | |
{ | |
$(".fecha_inicio").datepicker( | |
{ | |
minDate: '-1Y', | |
maxDate: '+0D', | |
dateFormat: 'dd-mm-yy', | |
onClose: function( selectedDate ) { | |
$( ".fecha_fin" ).datepicker( "option", "minDate", selectedDate ); | |
} | |
} | |
); | |
$(".fecha_fin").datepicker( | |
{ | |
maxDate: '+0D', | |
dateFormat: 'dd-mm-yy', | |
onClose: function( selectedDate ) { | |
$( ".fecha_inicio" ).datepicker( "option", "maxDate", selectedDate ); | |
} | |
} | |
); | |
$("#date_fix").click(function () { | |
$("#dateselect").attr('disabled', false); | |
$("#fecha_inicio").attr('disabled', true); | |
$("#fecha_fin").attr('disabled', true); | |
}); | |
$("#date_variable").click(function () { | |
$("#fecha_inicio").attr('disabled', false); | |
$("#fecha_fin").attr('disabled', false); | |
$("#dateselect").attr('disabled', true); | |
}); | |
if ($("#date_fix").is(':checked')) | |
{ | |
$("#dateselect").attr('disabled', false); | |
$("#fecha_inicio").attr('disabled', true); | |
$("#fecha_fin").attr('disabled', true); | |
} | |
else | |
{ | |
$("#fecha_inicio").attr('disabled', false); | |
$("#fecha_fin").attr('disabled', false); | |
$("#dateselect").attr('disabled', true); | |
} | |
}); | |
/** | |
* Convierte un string recogido de un combo de fechas predefinidas y lo convierte en un array con dos indices 'start' i 'end' con las fechas seleccionadas | |
* | |
* @param string $dateselect Valor del combo de tipo de fecha predifinida | |
* @return array $days Retorna un array con indices 'start' y 'end' para construir las estadisticas | |
*/ | |
static function get_days_from_combobox_predifined_dates($dateselect) | |
{ | |
switch ($dateselect) | |
{ | |
case "hoy": | |
$start = date('Y-m-d'); | |
$end= date('Y-m-d'); | |
break; | |
case "ayer": | |
$start = date('Y-m-d', mktime( date("h"), date("i"), date("s"), date("m"), date("d")-1, date("Y") )); | |
$end = date('Y-m-d', mktime( date("h"), date("i"), date("s"), date("m"), date("d")-1, date("Y") )); | |
break; | |
case "esta_semana": | |
$start = date('Y-m-d', mktime( date("h"), date("i"), date("s"), date("m"), date("d")-date("w")+1, date("Y") )); | |
$end = date('Y-m-d', mktime( date("h"), date("i"), date("s"), date("m"), date("d") + ( 7 - date("w") ), date("Y") )); | |
break; | |
case "semana_pasada": | |
$start = date('Y-m-d', mktime( date("h"), date("i"), date("s"), date("m"), date("d")-date("w")+1-7, date("Y") )); | |
$end = date('Y-m-d', mktime( date("h"), date("i"), date("s"), date("m"), date("d") + ( 7 - date("w") )-7, date("Y") )); | |
break; | |
case "este_mes": | |
$start = date('Y-m-d', mktime( date("h"), date("i"), date("s"), date("m"), 1, date("Y") )); | |
$end = date('Y-m-t'); | |
break; | |
case "mes_pasado": | |
$start = date('Y-m-d', mktime( date("h"), date("i"), date("s"), date("m") -1 , 1, date("Y") )); | |
$end = date('Y-m-d', mktime( 0,0,0, date("m") - 1, date("t", mktime( 0,0,0,date("m")-1, date("d"), date("Y"))), date("Y") )); | |
break; | |
case "default": | |
case "ultimos": | |
$inici = date('Y-m-d'); | |
$start = Cutils::return_default_start_day($inici); | |
$end= date('Y-m-d'); | |
break; | |
} | |
$days = array('start' => $start, 'end' => $end); | |
return $days; | |
} | |
/** | |
* Metodo que recoge variables request y redirige si no existen | |
* | |
* @param string $dateselect Valor del combo de tipo de fecha predifinida | |
* @return array $days Retorna un array con indices 'start' y 'end' para construir las estadisticas | |
*/ | |
static function return_default_start_day( $dateend, $dias_a_restar = '30' ) | |
{ | |
$default = $dias_a_restar ;//days | |
list( $anyfi, $mesfi, $diafi ) = explode( '-', $dateend, 3 ); | |
$comprobadatafi = mktime(0,0,0, $mesfi, $diafi, $anyfi); | |
$data_mostrar_timestamp = mktime( 0, 0, 0, $mesfi, $diafi - $default, $anyfi ); | |
$data_mostrar = date( "Y-m-d", $data_mostrar_timestamp ); | |
return $data_mostrar; | |
} | |
static function convert_timestamp_to_string($timestamp){ | |
$date_format = date("d-m-Y", strtotime($timestamp)); | |
$time_format = date("H:i:s", strtotime($timestamp)); | |
return $date_format." a las ".$time_format ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment