<?php
	require_once '../cron/class.db.php'; //LOCAL
	// require_once 'cron/class.db.php'; // PRODUCTION
	$usuario = (isset($_GET['usuario']) && $_GET['usuario'] != '') ? $_GET['usuario'] :0;
	$anyo = (isset($_GET['anyo']) && $_GET['anyo'] != '') ? $_GET['anyo'] : '';
	$mes = (isset($_GET['month']) && $_GET['month'] != '') ? $_GET['month'] : '';
	$boat = (isset($_GET['boat']) && $_GET['boat'] != '') ? $_GET['boat'] : 0;
 	$admin = (isset($_GET['admin']) && $_GET['admin'] > 0) ? 1 : 0;
	$parcial = (isset($_GET['parcial']) && $_GET['parcial'] != '') ? 1 : 0;



	if ($usuario > 0 && $boat > 0) {

		if ($parcial == 1) {

			DataBase::getInstancia();

			$min_date =  strtotime(date('Y-m-d'));

			if ($anyo != '' && $mes != ''){
                $mes -= 1;
			    $min_date =  strtotime($anyo.'-'.$mes.'-'.date('d'));
			}


			for ( $i = 0; $i < 3; $i++){
                $reservations_in_holidays = [];
				$consumidos = [];
				$mesI = date('m',$min_date);
				$anyoI = date('Y',$min_date);

				// Credito del mes
				$sql = 'SELECT * FROM credit_register WHERE customer_id = '.$usuario.' AND boat_id = '.$boat.' AND date_year = '.$anyoI.' AND date_month = '.$mesI;

				// echo $sql;

				$resultados = DataBase::execute_query($sql,'S');


				$sql2 = ('SELECT month(date_start) as date_month, weekday(date_start) as dia, year(date_start) as date_year, schedule_id, status_id, count(1) as contador
									FROM reservations
									WHERE customer_id = '.$usuario.
									' AND boat_id = '.$boat.
									' AND year(date_start) = '.$anyoI.
									' AND month(date_start) = '.$mesI.
									' AND status_id IN (1,2,4)'.
									' AND id NOT IN (select bookings24h.reservation_id FROM bookings24h)
										AND date_start NOT IN (select festives.date FROM festives WHERE deleted_at IS NULL)
										GROUP BY date_month, dia, date_year,schedule_id, status_id
										ORDER BY date_month ASC');
				$resultados2 = DataBase::execute_query($sql2,'S');


				foreach ( $resultados2 as $res ) {
				   if ($res['status_id'] != 3){
						if ( $res['dia'] == 5 || ( $res['dia'] == 4 && ($res['schedule_id'] == 2 || $res['schedule_id'] == 4) ) || ( $res['dia'] == 6 && ($res['schedule_id'] == 1 || $res['schedule_id'] == 3) ) ){
							if ($res['schedule_id'] == 1 || $res['schedule_id'] == 3 ){
                                isset($consumidos[$res['date_month']]['FS']['morning']) ? $consumidos[$res['date_month']]['FS']['morning'] += intval($res['contador'], 10) : $consumidos[$res['date_month']] = ['FS'=>['morning' => 1]];
							} else {
                                isset($consumidos[$res['date_month']]['FS']['morning']) ? $consumidos[$res['date_month']]['FS']['afternoon'] += intval($res['contador'], 10) : $consumidos[$res['date_month']] = ['FS'=>['afternoon' => 1]];
                            }
						}else{
							if ($res['schedule_id'] == 1 || $res['schedule_id'] == 3 ){
                                isset($consumidos[$res['date_month']]['L']['morning']) ? $consumidos[$res['date_month']]['L']['morning'] += intval($res['contador'], 10) : $consumidos[$res['date_month']] = ['L'=>['morning' => 1]];

                            }else{
                                isset($consumidos[$res['date_month']]['L']['morning']) ? $consumidos[$res['date_month']]['L']['morning'] += intval($res['contador'], 10) : $consumidos[$res['date_month']] = ['L'=>['morning' => 1]];
                            }
						}
				   }
				}


				$current_month = date('m');
				$current_year = date('Y');


				$sql = 'SELECT * FROM festives WHERE year(date) = '.$anyo. ' and month(date) = '.$mesI.' AND deleted_at IS NULL';
				$holidays = DataBase::execute_query($sql,'S');

				if(count($holidays) > 0){
					$text_where_in = '';

					foreach ($holidays as $key => $value) {
						$text_where_in =  $text_where_in.' "'.$value['date'].'",';
					}


					$text_where_in = rtrim($text_where_in, ',');

					$text_where_in = '( '.$text_where_in.' )';

					$sql = 'SELECT * FROM reservations WHERE customer_id = '.$usuario.
								 ' AND boat_id =  '.$boat.
								 ' AND status_id in (1,2,4) AND date_start IN '.$text_where_in.
								 ' AND id NOT IN (select bookings24h.reservation_id FROM bookings24h)';


					$reservations_in_holidays = DataBase::execute_query($sql,'S');
				}

				foreach ($reservations_in_holidays as $key => $value) {
					$number_of_month = (int)$mesI;

					if($value['schedule_id'] == "1" || $value['schedule_id'] == "3" ){
						isset($consumidos[$number_of_month]['FS']['morning']) ? $consumidos[$number_of_month]['FS']['morning'] += 1 : $consumidos[$number_of_month] = ['FS'=>['morning' => 1]];//array_push($consumidos[$number_of_month], ['FS' => ['morning' => 1]]);
					}else {
						isset($consumidos[$number_of_month]['FS']['afternoon']) ?  $consumidos[$number_of_month]['FS']['afternoon'] += 1 : $consumidos[$number_of_month] = ['FS' => ['afternoon' => 1]];
					}
				}


				$current_date = strtotime('01-'.$current_month.'-'.$current_year);

				foreach ($resultados as $item){
					$item_date = strtotime('01-'.$item['date_month'].'-'.$item['date_year']);

					$checkIsInPass = ($current_date < $item_date ? true: false);

					$checkIsFuture = ($item['date_month'] >= $current_month && $item['date_year'] == $current_year) || ($item['date_year'] > $current_year);

					$meses = array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre');
					$resto1 = (isset($consumidos[$item['date_month']]['L']['morning'])) ? max(0, intval($item['morning']) - intval($consumidos[$item['date_month']]['L']['morning']))  : $item['morning'];
					$resto2 = (isset($consumidos[$item['date_month']]['L']['afternoon'])) ? max(0, intval($item['afternoon']) - intval($consumidos[$item['date_month']]['L']['afternoon'])) : $item['afternoon'];
					$resto3 = (isset($consumidos[$item['date_month']]['FS']['morning'])) ? max(0, intval($item['festivo_morning']) - intval($consumidos[$item['date_month']]['FS']['morning'])) : $item['festivo_morning'];
					$resto4 = (isset($consumidos[$item['date_month']]['FS']['afternoon'])) ? max(0, intval($item['festivo_afternoon']) - intval($consumidos[$item['date_month']]['FS']['afternoon'])) : $item['festivo_afternoon'];

					$permitenSiguiente = array(1,2,4,5,7,8,9,10,11,12);
					$permitenAnterior = array(1,2,3,4,5,6,7,8,10,11,12);

					$next1 = (in_array($item['date_month'], $permitenSiguiente ) && $resto1 > 0 && $checkIsFuture) ? '<div style="width:32%;display:inline-block;"><a href="#" class="btn btn-flat changeCredito" onclick="cambiar(\'N_L_D_'.$item['date_year'].'_'.$item['date_month'].'_'.$boat.'\')"><i class="fa fa-arrow-circle-o-right"></i></a></div>' : '<div style="width:32%;display:inline-block;">&nbsp;</div>';

					$next2 = (in_array($item['date_month'], $permitenSiguiente ) && $resto2 > 0 && $checkIsFuture) ? '<div style="width:32%;display:inline-block;"><a href="#" class="btn btn-flat changeCredito" onclick="cambiar(\'N_L_N_'.$item['date_year'].'_'.$item['date_month'].'_'.$boat.'\')"><i class="fa fa-arrow-circle-o-right"></i></a></div>' : '<div style="width:32%;display:inline-block;">&nbsp;</div>';

					$next3 = (in_array($item['date_month'], $permitenSiguiente ) && $resto3 > 0 && $checkIsFuture) ? '<div style="width:32%;display:inline-block;"><a href="#" class="btn btn-flat changeCredito" onclick="cambiar(\'N_FS_D_'.$item['date_year'].'_'.$item['date_month'].'_'.$boat.'\')"><i class="fa fa-arrow-circle-o-right"></i></a></div>' : '<div style="width:32%;display:inline-block;">&nbsp;</div>';

					$next4 = (in_array($item['date_month'], $permitenSiguiente ) && $resto4 > 0 && $checkIsFuture) ? '<div style="width:32%;display:inline-block;"><a href="#" class="btn btn-flat changeCredito" onclick="cambiar(\'N_FS_N_'.$item['date_year'].'_'.$item['date_month'].'_'.$boat.'\')"><i class="fa fa-arrow-circle-o-right"></i></a></div>' : '<div style="width:32%;display:inline-block;">&nbsp;</div>';

					$previous1 = (in_array($item['date_month'], $permitenAnterior ) && $resto1 > 0 && $i > 0 && $checkIsInPass) ? '<div style="width:32%;display:inline-block;"><a href="#" class="btn btn-flat changeCredito" onclick="cambiar(\'P_L_D_'.$item['date_year'].'_'.$item['date_month'].'_'.$boat.'\')"><i class="fa fa-arrow-circle-o-left"></i></a></div>' : '<div style="width:32%;display:inline-block;">&nbsp;</div>';

					$previous2 = (in_array($item['date_month'], $permitenAnterior ) && $resto2 > 0 && $i > 0 && $checkIsInPass) ? '<div style="width:32%;display:inline-block;"><a href="#" class="btn btn-flat changeCredito" onclick="cambiar(\'P_L_N_'.$item['date_year'].'_'.$item['date_month'].'_'.$boat.'\')"><i class="fa fa-arrow-circle-o-left"></i></a></div>' : '<div style="width:32%;display:inline-block;">&nbsp;</div>';

					$previous3 = (in_array($item['date_month'], $permitenAnterior ) && $resto3 > 0 && $i > 0 && $checkIsInPass) ? '<div style="width:32%;display:inline-block;"><a href="#" class="btn btn-flat changeCredito" onclick="cambiar(\'P_FS_D_'.$item['date_year'].'_'.$item['date_month'].'_'.$boat.'\')"><i class="fa fa-arrow-circle-o-left"></i></a></div>' : '<div style="width:32%;display:inline-block;">&nbsp;</div>';

					$previous4 = (in_array($item['date_month'], $permitenAnterior ) && $resto4 > 0 && $i > 0 && $checkIsInPass) ? '<div style="width:32%;display:inline-block;"><a href="#" class="btn btn-flat changeCredito" onclick="cambiar(\'P_FS_N_'.$item['date_year'].'_'.$item['date_month'].'_'.$boat.'\')"><i class="fa fa-arrow-circle-o-left"></i></a></div>' : '<div style="width:32%;display:inline-block;">&nbsp;</div>';

					$disa = ( $admin ) ? '' : 'disabled="disabled"';

					echo '
					<div class="col-md-4 estamos-en-public2">
						<div class="box">
							<div class="box-header with-border">
							  <h3 class="box-title text-center">'.$meses[($item['date_month'])-1].'-'.$item['date_year'].'</h3>
							</div>
							<div class="box-body">
								<div style="border:2px solid #605ca8">
								   <div style="padding:3px;">
									  '.$previous1.'<div style="width:32%;display:inline-block; text-align:center"><i class="fa fa-sun-o" style="margin-top:5px;margin-bottom:5px;"></i><span style="margin-left:5px;width:25px;text-align:center;display: inline-block;font-size: 17px;">'.$resto1.'</span><input type="text" '.$disa.' name="L_D_'.$item['date_year'].'_'.$item['date_month'].'" id="L_D_'.$item['date_year'].'_'.$item['date_month'].'" value="'.$resto1.'" style="margin-left:5px;width:25px;text-align:center;display:none"/></div>'.$next1.'
								  </div>
								  <div style="padding:3px;">
									  '.$previous2.'<div style="width:32%;display:inline-block; text-align:center"><i class="fa fa-moon-o" style="margin-top:5px;margin-bottom:5px;"></i><span style="margin-left:5px;width:25px;text-align:center;display: inline-block;font-size: 17px;">'.$resto2.'</span><input type="text" '.$disa.' name="L_N_'.$item['date_year'].'_'.$item['date_month'].'" id="L_N_'.$item['date_year'].'_'.$item['date_month'].'" value="'.$resto2.'" style="margin-left:5px;width:25px;text-align:center;display:none"/></div>'.$next2.'
								  </div>
								</div>
								<div style="border:2px solid #ff851b; margin-top:5px;">
								  <div style="padding:3px;">
									  '.$previous3.'<div style="width:32%;display:inline-block; text-align:center"><i class="fa fa-sun-o" style="margin-top:5px;margin-bottom:5px;"></i><span style="margin-left:5px;width:25px;text-align:center;display: inline-block;font-size: 17px;">'.$resto3.'</span><input type="text" '.$disa.' name="FS_D_'.$item['date_year'].'_'.$item['date_month'].'" id="FS_D_'.$item['date_year'].'_'.$item['date_month'].'" value="'.$resto3.'" style="margin-left:5px;width:25px;text-align:center;display:none"/></div>'.$next3.'
								  </div>
								  <div style="padding:3px;">
									  '.$previous4.'<div style="width:32%;display:inline-block; text-align:center"><i class="fa fa-moon-o" style="margin-top:5px;margin-bottom:5px;"></i><span style="margin-left:5px;width:25px;text-align:center;display: inline-block;font-size: 17px;">'.$resto4.'</span><input type="text" '.$disa.' name="FS_N_'.$item['date_year'].'_'.$item['date_month'].'" id="FS_N_'.$item['date_year'].'_'.$item['date_month'].'" value="'.$resto4.'" style="margin-left:5px;width:25px;text-align:center;display:none"/></div>'.$next4.'
								  </div>
								</div>

							</div>
						</div>
					</div>';
				}
				$min_date = strtotime('first day of next month', $min_date);

				// $min_date = strtotime( '+26 DAY', $min_date);
			}


		} else {

			// VISTA ADMIN

            if ($admin)
                echo '<form method="post" id="saveCredits">';

            DataBase::getInstancia();

            $min_date =  strtotime(date('Y-m-d'));
            for ( $i = 0; $i < 12; $i++){

                $mesI = date('m',$min_date);
                $anyoI = date('Y',$min_date);

                // Credito del mes
                $sql = 'SELECT * FROM credit_register WHERE customer_id = '.$usuario.' AND boat_id = '.$boat.' AND date_year = '.$anyoI.' AND date_month = '.$mesI;
                $resultados = DataBase::execute_query($sql,'S');

                // Créditos consumidos del mes
								$sql2 = ('SELECT month(date_start) as date_month, weekday(date_start) as dia, year(date_start) as date_year, schedule_id, status_id, count(1) as contador
													FROM reservations
													WHERE customer_id = '.$usuario.
													' AND boat_id = '.$boat.
													' AND year(date_start) = '.$anyoI.
													' AND month(date_start) = '.$mesI.
													' AND status_id IN (1,2,4)'.
													' AND id NOT IN (select bookings24h.reservation_id FROM bookings24h)
														AND date_start NOT IN (select festives.date FROM festives WHERE deleted_at IS NULL)
														GROUP BY date_month, dia, date_year,schedule_id, status_id
														ORDER BY date_month ASC');


								$resultados2 = DataBase::execute_query($sql2,'S');

                foreach ( $resultados2 as $res ) {
                    if ($res['status_id'] == 1 || $res['status_id'] == 2 || $res['status_id'] == 4){
                        if ( $res['dia'] == 5 || ( $res['dia'] == 4 && ($res['schedule_id'] == 2 || $res['schedule_id'] == 4) ) || ( $res['dia'] == 6 && ($res['schedule_id'] == 1 || $res['schedule_id'] == 3) ) ){
                            if ($res['schedule_id'] == 1 || $res['schedule_id'] == 3 ){
                                $consumidos[$res['date_month']]['FS']['morning']  += intval($res['contador'], 10);
                            }else{
                                $consumidos[$res['date_month']]['FS']['afternoon']  += intval($res['contador'], 10);
                            }
                        }else{
                            if ($res['schedule_id'] == 1 || $res['schedule_id'] == 3 ){
                                $consumidos[$res['date_month']]['L']['morning']  += intval($res['contador'], 10);
                            }else{
                                $consumidos[$res['date_month']]['L']['afternoon']  += intval($res['contador'], 10);
                            }
                        }
                    }
                }


								//COUNT HOLIDAYS ON CALENDAR
								$sql = 'SELECT * FROM festives WHERE year(date) >= '.$anyoI. ' and month(date) >= '.$mesI.' AND deleted_at IS NULL';
								$holidays = DataBase::execute_query($sql,'S');

								if(count($holidays) > 0){
									$text_where_in = '';

									foreach ($holidays as $key => $value) {
										$text_where_in =  $text_where_in.' "'.$value['date'].'",';
									}


									$text_where_in = rtrim($text_where_in, ',');

									$text_where_in = '( '.$text_where_in.' )';

									$sql = 'SELECT * FROM reservations WHERE customer_id = '.$usuario.
												 ' AND boat_id =  '.$boat.
												 ' AND status_id in (1,2,4) AND date_start IN '.$text_where_in.
												 ' AND id NOT IN (select bookings24h.reservation_id FROM bookings24h)';


									$reservations_in_holidays = DataBase::execute_query($sql,'S');
								}


								foreach ($reservations_in_holidays as $key => $value) {
									$number_of_month = str_replace('0', '',  $mesI);

									if($value['schedule_id'] == "1" || $value['schedule_id'] == "3" ){

										if($consumidos[$number_of_month]['FS']['morning']){
											$consumidos[$number_of_month]['FS']['morning'] = $consumidos[$number_of_month]['FS']['morning'] + 1;
										}else{
											$consumidos[$number_of_month]['FS']['morning'] = 1;
										}

									}else {

										if($consumidos[$number_of_month]['FS']['afternoon']){
											$consumidos[$number_of_month]['FS']['afternoon'] = $consumidos[$number_of_month]['FS']['afternoon'] + 1;
										}else{
											$consumidos[$number_of_month]['FS']['afternoon'] = 1;
										}
									}
								}


                foreach ($resultados as $item){

                    $meses = array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre');

										$resto1 = (isset($consumidos[$item['date_month']]['L']['morning'])) ? max(0, intval($item['morning']) - intval($consumidos[$item['date_month']]['L']['morning']))  : $item['morning'];
										$resto2 = (isset($consumidos[$item['date_month']]['L']['afternoon'])) ? max(0, intval($item['afternoon']) - intval($consumidos[$item['date_month']]['L']['afternoon'])) : $item['afternoon'];
										$resto3 = (isset($consumidos[$item['date_month']]['FS']['morning'])) ? max(0, intval($item['festivo_morning']) - intval($consumidos[$item['date_month']]['FS']['morning'])) : $item['festivo_morning'];
										$resto4 = (isset($consumidos[$item['date_month']]['FS']['afternoon'])) ? max(0, intval($item['festivo_afternoon']) - intval($consumidos[$item['date_month']]['FS']['afternoon'])) : $item['festivo_afternoon'];


                    $permitenSiguiente = array(1,2,4,5,7,8,9,10,11,12);
                    $permitenAnterior = array(1,2,3,4,5,6,7,8,10,11,12);

                    $next1 = (in_array($item['date_month'], $permitenSiguiente ) && $resto1 > 0) ? '<div style="width:32%;display:inline-block;"><a href="#" class="btn btn-flat changeCredito" onclick="cambiar(\'N_L_D_'.$item['date_year'].'_'.$item['date_month'].'_'.$boat.'\')"><i class="fa fa-arrow-circle-o-right"></i></a></div>' : '<div style="width:32%;display:inline-block;">&nbsp;</div>';

                    $next2 = (in_array($item['date_month'], $permitenSiguiente ) && $resto2 > 0) ? '<div style="width:32%;display:inline-block;"><a href="#" class="btn btn-flat changeCredito" onclick="cambiar(\'N_L_N_'.$item['date_year'].'_'.$item['date_month'].'_'.$boat.'\')"><i class="fa fa-arrow-circle-o-right"></i></a></div>' : '<div style="width:32%;display:inline-block;">&nbsp;</div>';

                    $next3 = (in_array($item['date_month'], $permitenSiguiente ) && $resto3 > 0) ? '<div style="width:32%;display:inline-block;"><a href="#" class="btn btn-flat changeCredito" onclick="cambiar(\'N_FS_D_'.$item['date_year'].'_'.$item['date_month'].'_'.$boat.'\')"><i class="fa fa-arrow-circle-o-right"></i></a></div>' : '<div style="width:32%;display:inline-block;">&nbsp;</div>';

                    $next4 = (in_array($item['date_month'], $permitenSiguiente ) && $resto4 > 0) ? '<div style="width:32%;display:inline-block;"><a href="#" class="btn btn-flat changeCredito" onclick="cambiar(\'N_FS_N_'.$item['date_year'].'_'.$item['date_month'].'_'.$boat.'\')"><i class="fa fa-arrow-circle-o-right"></i></a></div>' : '<div style="width:32%;display:inline-block;">&nbsp;</div>';

                    $previous1 = (in_array($item['date_month'], $permitenAnterior ) && $resto1 > 0 && $i > 0) ? '<div style="width:32%;display:inline-block;"><a href="#" class="btn btn-flat changeCredito" onclick="cambiar(\'P_L_D_'.$item['date_year'].'_'.$item['date_month'].'_'.$boat.'\')"><i class="fa fa-arrow-circle-o-left"></i></a></div>' : '<div style="width:32%;display:inline-block;">&nbsp;</div>';

                    $previous2 = (in_array($item['date_month'], $permitenAnterior ) && $resto2 > 0 && $i > 0) ? '<div style="width:32%;display:inline-block;"><a href="#" class="btn btn-flat changeCredito" onclick="cambiar(\'P_L_N_'.$item['date_year'].'_'.$item['date_month'].'_'.$boat.'\')"><i class="fa fa-arrow-circle-o-left"></i></a></div>' : '<div style="width:32%;display:inline-block;">&nbsp;</div>';

                    $previous3 = (in_array($item['date_month'], $permitenAnterior ) && $resto3 > 0 && $i > 0) ? '<div style="width:32%;display:inline-block;"><a href="#" class="btn btn-flat changeCredito" onclick="cambiar(\'P_FS_D_'.$item['date_year'].'_'.$item['date_month'].'_'.$boat.'\')"><i class="fa fa-arrow-circle-o-left"></i></a></div>' : '<div style="width:32%;display:inline-block;">&nbsp;</div>';

                    $previous4 = (in_array($item['date_month'], $permitenAnterior ) && $resto4 > 0 && $i > 0) ? '<div style="width:32%;display:inline-block;"><a href="#" class="btn btn-flat changeCredito" onclick="cambiar(\'P_FS_N_'.$item['date_year'].'_'.$item['date_month'].'_'.$boat.'\')"><i class="fa fa-arrow-circle-o-left"></i></a></div>' : '<div style="width:32%;display:inline-block;">&nbsp;</div>';

                    $disa = ( $admin ) ? '' : 'disabled="disabled"';

                    echo '
											<div class="col-md-3 estamos-en-public">
												<div class="box">
													<div class="box-header with-border">
													  <h3 class="box-title text-center">'.$meses[($item['date_month'])-1].'-'.$item['date_year'].'</h3>
													</div>
													<div class="box-body">
														<div style="border:2px solid #605ca8">
														   <div style="padding:3px;">
															  '.$previous1.'<div style="width:32%;display:inline-block;"><i class="fa fa-sun-o"></i><input type="text" '.$disa.' name="L_D_'.$item['date_year'].'_'.$item['date_month'].'" id="L_D_'.$item['date_year'].'_'.$item['date_month'].'" value="'.$resto1.'" style="margin-left:5px;width:25px;text-align:center;"/></div>'.$next1.'
														  </div>
														  <div style="padding:3px;">
															  '.$previous2.'<div style="width:32%;display:inline-block;"><i class="fa fa-moon-o"></i><input type="text" '.$disa.' name="L_N_'.$item['date_year'].'_'.$item['date_month'].'" id="L_N_'.$item['date_year'].'_'.$item['date_month'].'" value="'.$resto2.'" style="margin-left:5px;width:25px;text-align:center;"/></div>'.$next2.'
														  </div>
														</div>
														<div style="border:2px solid #ff851b; margin-top:5px;">
														  <div style="padding:3px;">
															  '.$previous3.'<div style="width:32%;display:inline-block;"><i class="fa fa-sun-o"></i><input type="text" '.$disa.' name="FS_D_'.$item['date_year'].'_'.$item['date_month'].'" id="FS_D_'.$item['date_year'].'_'.$item['date_month'].'" value="'.$resto3.'" style="margin-left:5px;width:25px;text-align:center;"/></div>'.$next3.'
														  </div>
														  <div style="padding:3px;">
															  '.$previous4.'<div style="width:32%;display:inline-block;"><i class="fa fa-moon-o"></i><input type="text" '.$disa.' name="FS_N_'.$item['date_year'].'_'.$item['date_month'].'" id="FS_N_'.$item['date_year'].'_'.$item['date_month'].'" value="'.$resto4.'" style="margin-left:5px;width:25px;text-align:center;"/></div>'.$next4.'
														  </div>
														</div>

													</div>
												</div>
											</div>';
                }


								$min_date = strtotime('first day of next month', $min_date);

                //$min_date = strtotime( '+28 DAY', $min_date);
            }

            if ($admin)
                echo '<div class="col-md-12"><input name="user" value="'.$usuario.'" type="hidden"/><a class="btn btn-default btn-flat" id="saveButton">Guardar</a></div></form>';

        }

	}else{
			echo '<div class="callout callout-danger">Lo sentimos, su usuario no tiene permisos para la configuración de créditos.</div>';
	}

?>
