Approva richieste
This commit is contained in:
@@ -4,7 +4,7 @@ public class Dipendente {
|
||||
private String codiceFiscale;
|
||||
private String nome;
|
||||
private String cognome;
|
||||
private int giorniFerieResidui = 0;
|
||||
private int giorniFerieResidui = GIORNI_FERIE_TOTALI;
|
||||
public static final int GIORNI_FERIE_TOTALI = 35;
|
||||
|
||||
public Dipendente(String codiceFiscale, String nome, String cognome) {
|
||||
@@ -25,9 +25,11 @@ public class Dipendente {
|
||||
return cognome;
|
||||
}
|
||||
|
||||
public void setGiorniFerieResidui(int giorniFerieResidui) {
|
||||
this.giorniFerieResidui = giorniFerieResidui;
|
||||
public void updateGiorniFerieResidui(int giorniFerie) {
|
||||
this.giorniFerieResidui -= giorniFerie;
|
||||
}
|
||||
|
||||
|
||||
public int getGiorniFerieResidui() {
|
||||
return giorniFerieResidui;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.InputMismatchException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Scanner;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@@ -63,7 +65,7 @@ public class GestioneFerie {
|
||||
pausa();
|
||||
break;
|
||||
case 3:
|
||||
|
||||
approvaRichiesteFerie(dipendenti, richieste);
|
||||
pausa();
|
||||
break;
|
||||
case 4:
|
||||
@@ -101,19 +103,18 @@ public class GestioneFerie {
|
||||
error = false;
|
||||
|
||||
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: ");
|
||||
cognome = sc.nextLine().trim().toLowerCase();
|
||||
System.out.print("Inserire il cognome del dipendente: ");
|
||||
cognome = sc.nextLine().trim().toLowerCase();
|
||||
|
||||
codiceFiscale = codiceFiscale();
|
||||
codiceFiscale = codiceFiscale();
|
||||
|
||||
|
||||
if (dipendenteExists(nome, cognome, codiceFiscale, dipendenti)) {
|
||||
System.out.println("Il dipendente è già stato inserito.");
|
||||
pausa();
|
||||
error = true;
|
||||
}
|
||||
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));
|
||||
}
|
||||
@@ -138,12 +139,13 @@ public class GestioneFerie {
|
||||
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) {
|
||||
boolean dipendenteExists = false;
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -168,6 +170,7 @@ public class GestioneFerie {
|
||||
String codiceFiscale;
|
||||
String richiestaExists;
|
||||
boolean error;
|
||||
int giorniDiFerie;
|
||||
|
||||
do {
|
||||
error = false;
|
||||
@@ -187,21 +190,28 @@ public class GestioneFerie {
|
||||
pausa();
|
||||
error = true;
|
||||
} else {
|
||||
richiestaExists = richiestaExists(codiceFiscale, inizio, fine, richieste);
|
||||
|
||||
if (!richiestaExists.isEmpty()) {
|
||||
System.out.println(richiestaExists);
|
||||
giorniDiFerie = (int) (fine.getTimeInMillis() / (24 * 60 * 60 * 1000)
|
||||
- inizio.getTimeInMillis() / (24 * 60 * 60 * 1000));
|
||||
if (getDipendente(codiceFiscale, dipendenti).getGiorniFerieResidui() - giorniDiFerie < 0) {
|
||||
System.out.println("Il periodo di ferie supera la durata di feire massima per dipendente di " + Dipendente.GIORNI_FERIE_TOTALI + ".");
|
||||
pausa();
|
||||
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);
|
||||
|
||||
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) {
|
||||
@@ -213,18 +223,46 @@ getDipendente(codiceFiscale, dipendenti).setGiorniFerieResidui((int) (fine.getTi
|
||||
return null;
|
||||
}
|
||||
|
||||
private static Dipendente getDipendente(String nome, String cognome, String codiceFiscale, ArrayList<Dipendente> dipendenti) {
|
||||
for (Dipendente dipendente : dipendenti) {
|
||||
if (dipendente.getNome().equals(nome) && dipendente.getCognome().equals(cognome) && dipendente.getCodiceFiscale().equals(codiceFiscale)) {
|
||||
return dipendente;
|
||||
private static Dipendente getDipendente(ArrayList<Dipendente> dipendenti) {
|
||||
String nome;
|
||||
String cognome;
|
||||
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;
|
||||
}
|
||||
|
||||
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)
|
||||
- inizio.getTimeInMillis() / (24 * 60 * 60 * 1000)) <= Dipendente.GIORNI_FERIE_TOTALI; // da millisecondi a giorni
|
||||
return inizio.before(fine) && inizio.after(new Date()) && fine.getTimeInMillis() / (24 * 60 * 60 * 1000) >= 1
|
||||
&& (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,
|
||||
@@ -273,4 +311,73 @@ getDipendente(codiceFiscale, dipendenti).setGiorniFerieResidui((int) (fine.getTi
|
||||
|
||||
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;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
|
||||
public class Richiesta_Ferie {
|
||||
@@ -42,4 +43,19 @@ public class Richiesta_Ferie {
|
||||
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