Controllo dati
This commit is contained in:
@@ -11,5 +11,18 @@ public class Dipendente {
|
||||
this.codiceFiscale = codiceFiscale;
|
||||
this.nome = nome;
|
||||
this.cognome = cognome;
|
||||
}
|
||||
}
|
||||
|
||||
public String getCodiceFiscale() {
|
||||
return codiceFiscale;
|
||||
}
|
||||
|
||||
public String getNome() {
|
||||
return nome;
|
||||
}
|
||||
|
||||
public String getCognome() {
|
||||
return cognome;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,8 @@ import java.util.InputMismatchException;
|
||||
import java.util.Scanner;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import gestioneferie.Richiesta_Ferie.statiApprovazione;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Verde
|
||||
@@ -55,7 +57,7 @@ public class GestioneFerie {
|
||||
pausa();
|
||||
break;
|
||||
case 2:
|
||||
richiediFerie(richieste);
|
||||
richiediFerie(richieste, dipendenti);
|
||||
System.out.println("Richiesta di ferie aggiunta con successo.");
|
||||
System.out.println("La richiesta è attualmente in attesa di approvazione.");
|
||||
pausa();
|
||||
@@ -93,8 +95,12 @@ public class GestioneFerie {
|
||||
String nome;
|
||||
String cognome;
|
||||
String codiceFiscale;
|
||||
boolean error;
|
||||
|
||||
System.out.print("Inserire il nome del dipendente: ");
|
||||
do {
|
||||
error = false;
|
||||
|
||||
System.out.print("Inserire il nome del dipendente: ");
|
||||
nome = sc.nextLine().trim().toLowerCase();
|
||||
|
||||
System.out.print("Inserire il cognome del dipendente: ");
|
||||
@@ -102,6 +108,13 @@ public class GestioneFerie {
|
||||
|
||||
codiceFiscale = codiceFiscale();
|
||||
|
||||
|
||||
if (dipendenteExists(nome, cognome, codiceFiscale, dipendenti)) {
|
||||
System.out.println("Il dipendente è già stato inserito.");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
} while (error);
|
||||
dipendenti.add(new Dipendente(codiceFiscale, nome, cognome));
|
||||
}
|
||||
|
||||
@@ -125,17 +138,99 @@ public class GestioneFerie {
|
||||
return codiceFiscale;
|
||||
}
|
||||
|
||||
private static void richiediFerie(ArrayList<Richiesta_Ferie> richieste) {
|
||||
private static boolean dipendenteExists(String nome, String cognome, String codiceFiscale,
|
||||
ArrayList<Dipendente> dipendenti) {
|
||||
boolean dipendenteExists = false;
|
||||
|
||||
for (Dipendente dipendente : dipendenti) {
|
||||
if (dipendente.getNome().equals(nome) && dipendente.getCognome().equals(cognome) && dipendente.getCodiceFiscale().equals(codiceFiscale)) {
|
||||
dipendenteExists = true;
|
||||
}
|
||||
}
|
||||
return dipendenteExists;
|
||||
}
|
||||
|
||||
private static boolean codiceFiscaleExists(String codiceFiscale,
|
||||
ArrayList<Dipendente> dipendenti) {
|
||||
boolean codiceFiscaleExists = false;
|
||||
|
||||
for (Dipendente dipendente : dipendenti) {
|
||||
if (dipendente.getCodiceFiscale().equals(codiceFiscale)) {
|
||||
codiceFiscaleExists = true;
|
||||
}
|
||||
}
|
||||
return codiceFiscaleExists;
|
||||
}
|
||||
|
||||
private static void richiediFerie(ArrayList<Richiesta_Ferie> richieste, ArrayList<Dipendente> dipendenti) {
|
||||
Calendar inizio = Calendar.getInstance();
|
||||
Calendar fine = Calendar.getInstance();
|
||||
String codiceFiscale = codiceFiscale();
|
||||
String codiceFiscale;
|
||||
String richiestaExists;
|
||||
boolean error;
|
||||
|
||||
inizio.setTime(data("dell'inizio delle ferie"));
|
||||
fine.setTime(data("della fine delle ferie"));
|
||||
do {
|
||||
error = false;
|
||||
|
||||
codiceFiscale = codiceFiscale();
|
||||
|
||||
if (!codiceFiscaleExists(codiceFiscale, dipendenti)) {
|
||||
System.out.println("Il codice fiscale selezionato non è valido.");
|
||||
pausa();
|
||||
error = true;
|
||||
} else {
|
||||
inizio.setTime(data("dell'inizio delle ferie"));
|
||||
fine.setTime(data("della fine delle ferie"));
|
||||
|
||||
if (isPeriodoValido(inizio, fine)) {
|
||||
System.out.println("Il periodo di ferie selezionato non è valido.");
|
||||
pausa();
|
||||
error = true;
|
||||
} else {
|
||||
richiestaExists = richiestaExists(codiceFiscale, inizio, fine, richieste);
|
||||
|
||||
if (!richiestaExists.isEmpty()) {
|
||||
System.out.println(richiestaExists);
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
} while (error);
|
||||
|
||||
richieste.add(new Richiesta_Ferie(codiceFiscale, inizio, fine));
|
||||
}
|
||||
|
||||
private static boolean isPeriodoValido(Calendar inizio, Calendar fine) {
|
||||
return inizio.before(fine) && inizio.after(new Date()) && fine.getTimeInMillis() / (24 * 60 * 60 * 1000) >= 1; // da millisecondi a giorni
|
||||
}
|
||||
|
||||
private static String richiestaExists(String codiceFiscale, Calendar inizio, Calendar fine,
|
||||
ArrayList<Richiesta_Ferie> richieste) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(FORMATO_DATA);
|
||||
|
||||
for (Richiesta_Ferie richiesta : richieste) {
|
||||
if (sdf.format(richiesta.getInizio().getTime()).equals(sdf.format(inizio.getTime()))
|
||||
&& sdf.format(richiesta.getFine().getTime()).equals(sdf.format(fine.getTime()))) {
|
||||
if (codiceFiscale.equals(richiesta.getCodiceFiscale())) {
|
||||
switch (richiesta.getStato()) {
|
||||
case statiApprovazione.RIFIUTATA:
|
||||
return "Non è possibile rifare una richiesta di ferie per un periodo già rifiutato";
|
||||
case statiApprovazione.APPROVATA:
|
||||
return "Non è possibile rifare una richiesta di ferie per un periodo già approvato";
|
||||
case statiApprovazione.IN_ATTESA:
|
||||
return "Questo dipendente ha già richiesto delle ferie in questo periodo";
|
||||
default:
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
return "Un altro dipendente ha già richiesto delle ferie in questo periodo";
|
||||
}
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private static Date data(String diCheCosa) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat(FORMATO_DATA);
|
||||
boolean error;
|
||||
|
||||
@@ -20,4 +20,20 @@ public class Richiesta_Ferie {
|
||||
this.inizio = inizio;
|
||||
this.fine = fine;
|
||||
}
|
||||
|
||||
public String getCodiceFiscale() {
|
||||
return codiceFiscale;
|
||||
}
|
||||
|
||||
public Calendar getInizio() {
|
||||
return inizio;
|
||||
}
|
||||
|
||||
public Calendar getFine() {
|
||||
return fine;
|
||||
}
|
||||
public statiApprovazione getStato() {
|
||||
return stato;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user