Inserimento ordinazione completo
This commit is contained in:
@@ -60,12 +60,7 @@ public class FatturaScontrini {
|
|||||||
pausa();
|
pausa();
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
if (ordinazione != null) {
|
ordinazione = placeOrdinazione(ordinazione);
|
||||||
pagare(ordinazione);
|
|
||||||
} else {
|
|
||||||
System.out.println(
|
|
||||||
"Errore: è necessario effettuare un'ordinazione prima di procedere al pagamento.");
|
|
||||||
}
|
|
||||||
pausa();
|
pausa();
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
@@ -144,15 +139,20 @@ public class FatturaScontrini {
|
|||||||
ritorno.add(ordine);
|
ritorno.add(ordine);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
System.out.println(ordinazioneToString(ritorno));
|
||||||
|
|
||||||
do {
|
do {
|
||||||
error = false;
|
error = false;
|
||||||
System.out.print("Inserire un altra ordinazione? [S/N] ");
|
System.out.print("Modificare l'ordinazione? [S/N] "); // TODO: feedback UX
|
||||||
scelta = sc.nextLine().trim().toLowerCase();
|
scelta = sc.nextLine().trim().toLowerCase();
|
||||||
switch (scelta) {
|
switch (scelta) {
|
||||||
case "s":
|
case "s":
|
||||||
|
ritorno = cancellaInOrdinazione(ritorno);
|
||||||
exit = false;
|
exit = false;
|
||||||
break;
|
break;
|
||||||
case "n":
|
case "n":
|
||||||
|
System.out.println("Stampa dello scontrino. . .");
|
||||||
|
pagare(ritorno);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
System.out.println(ERRORE_DEFAULT);
|
System.out.println(ERRORE_DEFAULT);
|
||||||
@@ -286,8 +286,120 @@ public class FatturaScontrini {
|
|||||||
return ritorno;
|
return ritorno;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static String ordinazioneToString(ArrayList<int[]> ordinazione) {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
String[][] menu = tabellaNomePrezzo();
|
||||||
|
double totale = 0;
|
||||||
|
|
||||||
|
// Larghezze colonne
|
||||||
|
int larghezzaNome = 50;
|
||||||
|
int larghezzaPrezzoQuantita = 10;
|
||||||
|
String formattatoreLarghezzaNome = "%-" + larghezzaNome + "s";
|
||||||
|
String formattatoreLarghezzaPrezzoQuantita = "%-" + larghezzaPrezzoQuantita + "s";
|
||||||
|
|
||||||
|
// Intestazione tabella
|
||||||
|
sb.append(String.format(formattatoreLarghezzaNome, "Nome"));
|
||||||
|
sb.append(String.format(formattatoreLarghezzaPrezzoQuantita, "Prezzo"));
|
||||||
|
sb.append(String.format(formattatoreLarghezzaPrezzoQuantita, "Quantità"));
|
||||||
|
sb.append("\n");
|
||||||
|
|
||||||
|
for (int i = 0; i < ordinazione.size(); i++) {
|
||||||
|
sb.append(String.format(formattatoreLarghezzaNome, menu[0][ordinazione.get(i)[0]].trim()));// nome
|
||||||
|
sb.append(String.format(formattatoreLarghezzaPrezzoQuantita, menu[1][ordinazione.get(i)[0]].trim()));// prezzo
|
||||||
|
sb.append(String.format(formattatoreLarghezzaPrezzoQuantita, Integer.toString(ordinazione.get(i)[1])));// quantità
|
||||||
|
sb.append("\n");
|
||||||
|
totale += Double.parseDouble(menu[1][ordinazione.get(i)[0]].replace("€", "").trim())
|
||||||
|
* ordinazione.get(i)[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
sb.append("\nTotale: " + totale);
|
||||||
|
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
static String[][] tabellaNomePrezzo() {
|
||||||
|
String[][] ritorno = new String[2][getMenuSize()];
|
||||||
|
try (BufferedReader br = new BufferedReader(new FileReader(PATH_MENU))) {
|
||||||
|
String riga = br.readLine();
|
||||||
|
|
||||||
|
for (int i = 0; i < getMenuSize(); i++) {
|
||||||
|
ritorno[0][i] = riga.split(":")[0];
|
||||||
|
ritorno[1][i] = riga.split(":")[1].trim();
|
||||||
|
riga = br.readLine();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
System.out.println(ERRORE_FILE + e.getMessage());
|
||||||
|
}
|
||||||
|
return ritorno;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ArrayList<int[]> cancellaInOrdinazione(ArrayList<int[]> ordinazione) {
|
||||||
|
String scelta;
|
||||||
|
boolean error;
|
||||||
|
|
||||||
|
do {
|
||||||
|
error = false;
|
||||||
|
System.out.print("Eliminare un ordinazione? [S/N] ");
|
||||||
|
scelta = sc.nextLine().trim().toLowerCase();
|
||||||
|
switch (scelta) {
|
||||||
|
case "s":
|
||||||
|
ordinazione = cancellaOrdine(ordinazione);
|
||||||
|
System.out.println("Ordine cancellato con successo.");
|
||||||
|
pausa();
|
||||||
|
break;
|
||||||
|
case "n":
|
||||||
|
System.out.println("Nessuna ordinazione è stata cancellata.");
|
||||||
|
pausa();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.out.println(ERRORE_DEFAULT);
|
||||||
|
pausa();
|
||||||
|
error = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} while (error);
|
||||||
|
|
||||||
|
return ordinazione;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ArrayList<int[]> cancellaOrdine(ArrayList<int[]> ordinazione) {
|
||||||
|
int scelta = -1;
|
||||||
|
String[][] menu = tabellaNomePrezzo();
|
||||||
|
boolean error;
|
||||||
|
|
||||||
|
do {
|
||||||
|
error = false;
|
||||||
|
|
||||||
|
System.out.println("Quale opzione eliminare tra le seguenti?");
|
||||||
|
for (int i = 0; i < ordinazione.size(); i++) {
|
||||||
|
System.out.println(i + ". " + menu[0][ordinazione.get(i)[0]].trim() + ": "
|
||||||
|
+ menu[1][ordinazione.get(i)[0]].trim());
|
||||||
|
}
|
||||||
|
System.out.print("Scelta: ");
|
||||||
|
|
||||||
|
try {
|
||||||
|
scelta = sc.nextInt();
|
||||||
|
sc.nextLine();
|
||||||
|
|
||||||
|
if (scelta < 0 || scelta >= getMenuSize()) {
|
||||||
|
System.out.println(ERRORE_DEFAULT);
|
||||||
|
pausa();
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
} catch (InputMismatchException _) {
|
||||||
|
System.out.println(ERRORE_DEFAULT);
|
||||||
|
pausa();
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
} while (error);
|
||||||
|
|
||||||
|
ordinazione.remove(scelta);
|
||||||
|
|
||||||
|
return ordinazione;
|
||||||
|
}
|
||||||
|
|
||||||
static void pagare(ArrayList<int[]> ordinazione) {
|
static void pagare(ArrayList<int[]> ordinazione) {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd_HH_mm");
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd_HH_mm_ss");
|
||||||
Date now = new Date();
|
Date now = new Date();
|
||||||
String contenutoScontrino;
|
String contenutoScontrino;
|
||||||
|
|
||||||
@@ -314,52 +426,6 @@ public class FatturaScontrini {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static String ordinazioneToString(ArrayList<int[]> ordinazione) {
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
String[][] menu = tabellaNomePrezzo();
|
|
||||||
double totale = 0;
|
|
||||||
|
|
||||||
// Larghezze colonne
|
|
||||||
int larghezzaNome = 50;
|
|
||||||
int larghezzaPrezzoQuantita = 10;
|
|
||||||
String formattatoreLarghezzaNome = "%-" + larghezzaNome + "s";
|
|
||||||
String formattatoreLarghezzaPrezzoQuantita = "%-" + larghezzaPrezzoQuantita + "s";
|
|
||||||
|
|
||||||
// Intestazione tabella
|
|
||||||
sb.append(String.format(formattatoreLarghezzaNome, "Nome"));
|
|
||||||
sb.append(String.format(formattatoreLarghezzaPrezzoQuantita, "Prezzo"));
|
|
||||||
sb.append(String.format(formattatoreLarghezzaPrezzoQuantita, "Quantità"));
|
|
||||||
sb.append("\n");
|
|
||||||
|
|
||||||
for (int i = 0; i < ordinazione.size(); i++) {
|
|
||||||
sb.append(String.format(formattatoreLarghezzaNome, menu[0][ordinazione.get(i)[0]].trim()));// nome
|
|
||||||
sb.append(String.format(formattatoreLarghezzaPrezzoQuantita, menu[1][ordinazione.get(i)[0]].trim()));// prezzo
|
|
||||||
sb.append(String.format(formattatoreLarghezzaPrezzoQuantita, Integer.toString(ordinazione.get(i)[1])));// quantità
|
|
||||||
sb.append("\n");
|
|
||||||
totale += Double.parseDouble(menu[1][ordinazione.get(i)[0]].replaceFirst(",", ".")) * ordinazione.get(i)[1];
|
|
||||||
}
|
|
||||||
|
|
||||||
sb.append("\nTotale: " + totale);
|
|
||||||
|
|
||||||
return sb.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
static String[][] tabellaNomePrezzo() {
|
|
||||||
String[][] ritorno = new String[2][getMenuSize()];
|
|
||||||
try (BufferedReader br = new BufferedReader(new FileReader(PATH_MENU))) {
|
|
||||||
String riga = br.readLine();
|
|
||||||
|
|
||||||
for (int i = 0; i < getMenuSize(); i++) {
|
|
||||||
ritorno[0][i] = riga.split(":")[0];
|
|
||||||
ritorno[1][i] = riga.split(":")[1].trim();
|
|
||||||
riga = br.readLine();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
System.out.println(ERRORE_FILE + e.getMessage());
|
|
||||||
}
|
|
||||||
return ritorno;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void fattura() {
|
static void fattura() {
|
||||||
boolean error;
|
boolean error;
|
||||||
String formatoDataInserimento = "dd/MM/yyyy";
|
String formatoDataInserimento = "dd/MM/yyyy";
|
||||||
@@ -388,9 +454,9 @@ public class FatturaScontrini {
|
|||||||
|
|
||||||
if (listaScontrini.isEmpty()) {
|
if (listaScontrini.isEmpty()) {
|
||||||
System.out.println("Errore: non sono stati trovati scontrini per la data inserita.");
|
System.out.println("Errore: non sono stati trovati scontrini per la data inserita.");
|
||||||
}
|
} else {
|
||||||
else{
|
stampaFattura(new Fattura(listaScontrini.size(), calcolaTotaleScontrini(listaScontrini)),
|
||||||
stampaFattura(new Fattura(listaScontrini.size(), calcolaTotaleScontrini(listaScontrini)), sdf.format(dataRicerca));
|
sdf.format(dataRicerca));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user