Approva richieste
This commit is contained in:
@@ -4,7 +4,7 @@ public class Dipendente {
|
|||||||
private String codiceFiscale;
|
private String codiceFiscale;
|
||||||
private String nome;
|
private String nome;
|
||||||
private String cognome;
|
private String cognome;
|
||||||
private int giorniFerieResidui = 0;
|
private int giorniFerieResidui = GIORNI_FERIE_TOTALI;
|
||||||
public static final int GIORNI_FERIE_TOTALI = 35;
|
public static final int GIORNI_FERIE_TOTALI = 35;
|
||||||
|
|
||||||
public Dipendente(String codiceFiscale, String nome, String cognome) {
|
public Dipendente(String codiceFiscale, String nome, String cognome) {
|
||||||
@@ -25,9 +25,11 @@ public class Dipendente {
|
|||||||
return cognome;
|
return cognome;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGiorniFerieResidui(int giorniFerieResidui) {
|
public void updateGiorniFerieResidui(int giorniFerie) {
|
||||||
this.giorniFerieResidui = giorniFerieResidui;
|
this.giorniFerieResidui -= giorniFerie;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getGiorniFerieResidui() {
|
||||||
|
return giorniFerieResidui;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.InputMismatchException;
|
import java.util.InputMismatchException;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@@ -63,7 +65,7 @@ public class GestioneFerie {
|
|||||||
pausa();
|
pausa();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
|
approvaRichiesteFerie(dipendenti, richieste);
|
||||||
pausa();
|
pausa();
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
@@ -101,19 +103,18 @@ public class GestioneFerie {
|
|||||||
error = false;
|
error = false;
|
||||||
|
|
||||||
System.out.print("Inserire il nome del dipendente: ");
|
System.out.print("Inserire il nome del dipendente: ");
|
||||||
nome = sc.nextLine().trim().toLowerCase();
|
nome = sc.nextLine().trim().toLowerCase();
|
||||||
|
|
||||||
System.out.print("Inserire il cognome del dipendente: ");
|
System.out.print("Inserire il cognome del dipendente: ");
|
||||||
cognome = sc.nextLine().trim().toLowerCase();
|
cognome = sc.nextLine().trim().toLowerCase();
|
||||||
|
|
||||||
codiceFiscale = codiceFiscale();
|
codiceFiscale = codiceFiscale();
|
||||||
|
|
||||||
|
if (dipendenteExists(nome, cognome, codiceFiscale, dipendenti)) {
|
||||||
if (dipendenteExists(nome, cognome, codiceFiscale, dipendenti)) {
|
System.out.println("Il dipendente è già stato inserito.");
|
||||||
System.out.println("Il dipendente è già stato inserito.");
|
pausa();
|
||||||
pausa();
|
error = true;
|
||||||
error = true;
|
}
|
||||||
}
|
|
||||||
} while (error);
|
} while (error);
|
||||||
dipendenti.add(new Dipendente(codiceFiscale, nome, cognome));
|
dipendenti.add(new Dipendente(codiceFiscale, nome, cognome));
|
||||||
}
|
}
|
||||||
@@ -138,12 +139,13 @@ public class GestioneFerie {
|
|||||||
return codiceFiscale;
|
return codiceFiscale;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean dipendenteExists(String nome, String cognome, String codiceFiscale,
|
private static boolean dipendenteExists(String nome, String cognome, String codiceFiscale,
|
||||||
ArrayList<Dipendente> dipendenti) {
|
ArrayList<Dipendente> dipendenti) {
|
||||||
boolean dipendenteExists = false;
|
boolean dipendenteExists = false;
|
||||||
|
|
||||||
for (Dipendente dipendente : dipendenti) {
|
for (Dipendente dipendente : dipendenti) {
|
||||||
if (dipendente.getNome().equals(nome) && dipendente.getCognome().equals(cognome) && dipendente.getCodiceFiscale().equals(codiceFiscale)) {
|
if (dipendente.getNome().equals(nome) && dipendente.getCognome().equals(cognome)
|
||||||
|
&& dipendente.getCodiceFiscale().equals(codiceFiscale)) {
|
||||||
dipendenteExists = true;
|
dipendenteExists = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -168,6 +170,7 @@ public class GestioneFerie {
|
|||||||
String codiceFiscale;
|
String codiceFiscale;
|
||||||
String richiestaExists;
|
String richiestaExists;
|
||||||
boolean error;
|
boolean error;
|
||||||
|
int giorniDiFerie;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
error = false;
|
error = false;
|
||||||
@@ -187,21 +190,28 @@ public class GestioneFerie {
|
|||||||
pausa();
|
pausa();
|
||||||
error = true;
|
error = true;
|
||||||
} else {
|
} else {
|
||||||
richiestaExists = richiestaExists(codiceFiscale, inizio, fine, richieste);
|
giorniDiFerie = (int) (fine.getTimeInMillis() / (24 * 60 * 60 * 1000)
|
||||||
|
- inizio.getTimeInMillis() / (24 * 60 * 60 * 1000));
|
||||||
if (!richiestaExists.isEmpty()) {
|
if (getDipendente(codiceFiscale, dipendenti).getGiorniFerieResidui() - giorniDiFerie < 0) {
|
||||||
System.out.println(richiestaExists);
|
System.out.println("Il periodo di ferie supera la durata di feire massima per dipendente di " + Dipendente.GIORNI_FERIE_TOTALI + ".");
|
||||||
pausa();
|
pausa();
|
||||||
error = true;
|
error = true;
|
||||||
|
} else {
|
||||||
|
richiestaExists = richiestaExists(codiceFiscale, inizio, fine, richieste);
|
||||||
|
|
||||||
|
if (!richiestaExists.isEmpty()) {
|
||||||
|
System.out.println(richiestaExists);
|
||||||
|
pausa();
|
||||||
|
error = true;
|
||||||
|
} else {
|
||||||
|
getDipendente(codiceFiscale, dipendenti).updateGiorniFerieResidui(giorniDiFerie);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (error);
|
} while (error);
|
||||||
|
|
||||||
richieste.add(new Richiesta_Ferie(codiceFiscale, inizio, fine));
|
richieste.add(new Richiesta_Ferie(codiceFiscale, inizio, fine));
|
||||||
|
|
||||||
getDipendente(codiceFiscale, dipendenti).setGiorniFerieResidui((int) (fine.getTimeInMillis() / (24 * 60 * 60 * 1000)
|
|
||||||
- inizio.getTimeInMillis() / (24 * 60 * 60 * 1000)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Dipendente getDipendente(String codiceFiscale, ArrayList<Dipendente> dipendenti) {
|
private static Dipendente getDipendente(String codiceFiscale, ArrayList<Dipendente> dipendenti) {
|
||||||
@@ -213,18 +223,46 @@ getDipendente(codiceFiscale, dipendenti).setGiorniFerieResidui((int) (fine.getTi
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Dipendente getDipendente(String nome, String cognome, String codiceFiscale, ArrayList<Dipendente> dipendenti) {
|
private static Dipendente getDipendente(ArrayList<Dipendente> dipendenti) {
|
||||||
for (Dipendente dipendente : dipendenti) {
|
String nome;
|
||||||
if (dipendente.getNome().equals(nome) && dipendente.getCognome().equals(cognome) && dipendente.getCodiceFiscale().equals(codiceFiscale)) {
|
String cognome;
|
||||||
return dipendente;
|
String codiceFiscale;
|
||||||
|
boolean error;
|
||||||
|
|
||||||
|
do {
|
||||||
|
error = false;
|
||||||
|
|
||||||
|
System.out.print("Inserire il nome del dipendente: ");
|
||||||
|
nome = sc.nextLine().trim().toLowerCase();
|
||||||
|
|
||||||
|
System.out.print("Inserire il cognome del dipendente: ");
|
||||||
|
cognome = sc.nextLine().trim().toLowerCase();
|
||||||
|
|
||||||
|
codiceFiscale = codiceFiscale();
|
||||||
|
|
||||||
|
if (!dipendenteExists(nome, cognome, codiceFiscale, dipendenti)) {
|
||||||
|
System.out.println("Il dipendente inserito non esiste.");
|
||||||
|
pausa();
|
||||||
|
error = true;
|
||||||
|
} else {
|
||||||
|
for (Dipendente dipendente : dipendenti) {
|
||||||
|
if (dipendente.getNome().equals(nome) && dipendente.getCognome().equals(cognome)
|
||||||
|
&& dipendente.getCodiceFiscale().equals(codiceFiscale)) {
|
||||||
|
return dipendente;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
} while (error);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isPeriodoValido(Calendar inizio, Calendar fine) {
|
private static boolean isPeriodoValido(Calendar inizio, Calendar fine) {
|
||||||
return inizio.before(fine) && inizio.after(new Date()) && fine.getTimeInMillis() / (24 * 60 * 60 * 1000) >= 1 && (int) (fine.getTimeInMillis() / (24 * 60 * 60 * 1000)
|
return inizio.before(fine) && inizio.after(new Date()) && fine.getTimeInMillis() / (24 * 60 * 60 * 1000) >= 1
|
||||||
- inizio.getTimeInMillis() / (24 * 60 * 60 * 1000)) <= Dipendente.GIORNI_FERIE_TOTALI; // da millisecondi a giorni
|
&& (int) (fine.getTimeInMillis() / (24 * 60 * 60 * 1000)
|
||||||
|
- inizio.getTimeInMillis() / (24 * 60 * 60 * 1000)) <= Dipendente.GIORNI_FERIE_TOTALI; // da
|
||||||
|
// millisecondi
|
||||||
|
// a
|
||||||
|
// giorni
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String richiestaExists(String codiceFiscale, Calendar inizio, Calendar fine,
|
private static String richiestaExists(String codiceFiscale, Calendar inizio, Calendar fine,
|
||||||
@@ -273,4 +311,73 @@ getDipendente(codiceFiscale, dipendenti).setGiorniFerieResidui((int) (fine.getTi
|
|||||||
|
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static LinkedList<Richiesta_Ferie> getRichiesteFerie(String codiceFiscale,
|
||||||
|
ArrayList<Richiesta_Ferie> richieste) {
|
||||||
|
LinkedList<Richiesta_Ferie> ferieRichieste = new LinkedList<>();
|
||||||
|
for (Richiesta_Ferie richiesta : richieste) {
|
||||||
|
if (richiesta.getCodiceFiscale().equals(codiceFiscale)) {
|
||||||
|
ferieRichieste.add(richiesta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ferieRichieste;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void approvaRichiesteFerie(ArrayList<Dipendente> dipendenti, ArrayList<Richiesta_Ferie> richieste) {
|
||||||
|
Dipendente daApprovare;
|
||||||
|
LinkedList<Richiesta_Ferie> ferieRichieste;
|
||||||
|
|
||||||
|
daApprovare = getDipendente(dipendenti);
|
||||||
|
ferieRichieste = getRichiesteFerie(daApprovare.getCodiceFiscale(), richieste);
|
||||||
|
|
||||||
|
if (ferieRichieste.isEmpty()) {
|
||||||
|
System.out.println("Questo dipendente non ha ancora richiesto nessun periodo di ferie.");
|
||||||
|
} else {
|
||||||
|
System.out.println("Richieste:");
|
||||||
|
for (Richiesta_Ferie richiesta : ferieRichieste) {
|
||||||
|
System.out.println(richiesta.toString());
|
||||||
|
if (richiesta.getStato().equals(statiApprovazione.IN_ATTESA)) {
|
||||||
|
approvaRichiestaFerie(richiesta);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void approvaRichiestaFerie(Richiesta_Ferie richiesta) {
|
||||||
|
int scelta = -1;
|
||||||
|
do {
|
||||||
|
System.out.println("Che operazione eseguire?");
|
||||||
|
System.out.println("1. Approvare");
|
||||||
|
System.out.println("2. Ignorare");
|
||||||
|
System.out.println("3. Rifiutare");
|
||||||
|
System.out.print("Scelta: ");
|
||||||
|
System.out.print("Opzione: ");
|
||||||
|
|
||||||
|
try {
|
||||||
|
scelta = sc.nextInt();
|
||||||
|
sc.nextLine();
|
||||||
|
|
||||||
|
switch (scelta) {
|
||||||
|
case 1:
|
||||||
|
richiesta.approva();
|
||||||
|
System.out.println("Richiesta approvata.");
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
System.out.println("Richiesta ignorata.");
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
richiesta.rifiuta();
|
||||||
|
System.out.println("Richiesta rifiutata.");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.out.println(ERRORE_GENERICO);
|
||||||
|
pausa();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} catch (InputMismatchException _) {
|
||||||
|
System.out.println(ERRORE_GENERICO);
|
||||||
|
pausa();
|
||||||
|
}
|
||||||
|
} while (scelta != 1 && scelta != 2 && scelta != 3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package gestioneferie;
|
package gestioneferie;
|
||||||
|
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
|
||||||
public class Richiesta_Ferie {
|
public class Richiesta_Ferie {
|
||||||
@@ -42,4 +43,19 @@ public class Richiesta_Ferie {
|
|||||||
return giorniFerie;
|
return giorniFerie;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void approva() {
|
||||||
|
stato = statiApprovazione.APPROVATA;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void rifiuta() {
|
||||||
|
stato = statiApprovazione.RIFIUTATA;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
SimpleDateFormat sdf = new SimpleDateFormat(GestioneFerie.FORMATO_DATA);
|
||||||
|
return "Codice fiscale: " + codiceFiscale + "\nInizio ferie: " + sdf.format(inizio.getTime()) + "\nFine ferie: "
|
||||||
|
+ sdf.format(fine.getTime()) + "\nTotale giorni di ferie: " + giorniFerie + "\nStato approvazione: "
|
||||||
|
+ stato;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user