diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index fafc2b5..4bfdfa9 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -5,11 +5,19 @@
+
+
+
+
-
+
-
+
+
+
+
+
@@ -55,23 +63,32 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -84,12 +101,12 @@
+
- remove
error
arqueo
System.out.prin
@@ -119,6 +136,7 @@
System.out
this.comparator
Button
+ deposito
2018 Daniel Cortes
@@ -141,15 +159,11 @@
@@ -237,6 +255,7 @@
+
@@ -265,13 +284,14 @@
-
+
+
+
-
@@ -285,8 +305,11 @@
-
+
+
+
+
@@ -295,13 +318,24 @@
-
+
-
+
+
+
+
+
+
+
+
+
+
+
+
@@ -311,10 +345,6 @@
-
-
-
-
@@ -329,47 +359,39 @@
-
-
+
-
+
+
+
+
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
-
+
@@ -379,43 +401,15 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
-
-
-
+
+
@@ -526,20 +520,8 @@
-
-
- 1545420806001
-
-
-
- 1545420806001
-
-
- 1545694977931
-
-
-
- 1545694977931
+
+
1545699519326
@@ -870,11 +852,54 @@
1547848576090
-
+
+ 1547927728996
+
+
+
+ 1547927728997
+
+
+ 1547928164109
+
+
+
+ 1547928164109
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
+
@@ -887,11 +912,47 @@
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -921,41 +982,6 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
@@ -1014,8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+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -1805,10 +1807,10 @@
+
+
-
-
Programa Caja
@@ -1876,6 +1878,7 @@
+
diff --git a/caja.iml b/caja.iml
index 07b7473..ededa55 100644
--- a/caja.iml
+++ b/caja.iml
@@ -4,6 +4,7 @@
+
@@ -24,5 +25,17 @@
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/dist/caja.jar b/dist/caja.jar
deleted file mode 100644
index fb38b3d..0000000
Binary files a/dist/caja.jar and /dev/null differ
diff --git a/src/danielcortes/xyz/controllers/InformesController.java b/src/danielcortes/xyz/controllers/InformesController.java
index 7cfe5cb..b6e46b1 100644
--- a/src/danielcortes/xyz/controllers/InformesController.java
+++ b/src/danielcortes/xyz/controllers/InformesController.java
@@ -38,6 +38,10 @@ import javax.swing.filechooser.FileNameExtensionFilter;
import java.awt.*;
import java.io.File;
import java.io.IOException;
+import java.nio.file.FileAlreadyExistsException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
@@ -64,13 +68,13 @@ public class InformesController {
String formatedName = month.format(formatter);
String capitalized = StringUtils.toUpperCase(formatedName);
- File saveFile = askForFile("Libro " + capitalized);
+ Path saveFile = askForFile("Libro " + capitalized);
if (saveFile == null) {
return;
}
InformeLibroDeVentas informe = new InformeLibroDeVentas(month, saveFile);
- File generatedFile = informe.generarInforme();
+ Path generatedFile = informe.generarInforme();
this.showConfirmation(generatedFile);
}
@@ -89,13 +93,13 @@ public class InformesController {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM YYYY");
String formatedMonth = month.format(formatter);
- File saveFile = askForFile("Informe Egresos - " + tipoEgreso.getNombre() + " - " + StringUtils.toUpperCase(formatedMonth));
+ Path saveFile = askForFile("Informe Egresos - " + tipoEgreso.getNombre() + " - " + StringUtils.toUpperCase(formatedMonth));
if (saveFile == null) {
return;
}
InformeEgresos informe = new InformeEgresos(tipoEgreso.getId(), month, saveFile);
- File generatedFile = informe.generarInforme();
+ Path generatedFile = informe.generarInforme();
this.showConfirmation(generatedFile);
}
@@ -118,28 +122,58 @@ public class InformesController {
}
}
- private File askForFile(String suggestedName) {
+ private Path askForFile(String suggestedName) {
JFileChooser chooser = new JFileChooser();
chooser.setDialogType(JFileChooser.SAVE_DIALOG);
chooser.setSelectedFile(new File(suggestedName + ".xls"));
chooser.setFileFilter(new FileNameExtensionFilter("Excel 2007", "xls"));
if (chooser.showSaveDialog(this.view.getContentPanel()) == JFileChooser.APPROVE_OPTION) {
- String filename = chooser.getSelectedFile().getPath();
- if (!FileUtils.isValidPath(filename)) {
- JOptionPane.showMessageDialog(this.view.getContentPanel(),"El archivo seleccionado no es valido","Archivo no valido", JOptionPane.ERROR_MESSAGE);
- return null;
- } else if (!filename.endsWith(".xls")) {
- filename += ".xls";
+ String pathString = chooser.getSelectedFile().getPath();
+
+ if (!pathString.endsWith(".xls")) {
+ pathString = pathString + ".xls";
}
- return new File(filename);
+
+ Path path = Paths.get(pathString);
+
+
+ try {
+ Files.createFile(path);
+ } catch (FileAlreadyExistsException e) {
+ int response = JOptionPane.showConfirmDialog(
+ this.view.getContentPanel(),
+ "El archivo ya existe\n¿Desea sobreescribirlo?",
+ "Confirmacion",
+ JOptionPane.YES_NO_OPTION,
+ JOptionPane.WARNING_MESSAGE
+ );
+
+ if (response != 0) {
+ return null;
+ }
+
+ } catch (IOException e) {
+ e.printStackTrace();
+ JOptionPane.showMessageDialog(
+ this.view.getContentPanel(),
+ "No a sido posible crear el archivo",
+ "Error!",
+ JOptionPane.ERROR_MESSAGE
+ );
+
+ return null;
+ }
+
+ return path;
+
} else {
return null;
}
}
- private void showConfirmation(File file) {
+ private void showConfirmation(Path path) {
int result = JOptionPane.showConfirmDialog(
this.view.getContentPanel(),
"El informes se a generado\n" +
@@ -148,9 +182,10 @@ public class InformesController {
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE
);
+
if (result == 0) {
try {
- Desktop.getDesktop().open(file);
+ Desktop.getDesktop().open(path.toFile());
} catch (IOException e) {
e.printStackTrace();
}
diff --git a/src/danielcortes/xyz/informes/InformeEgresos.java b/src/danielcortes/xyz/informes/InformeEgresos.java
index 6c0ee44..e8c003b 100644
--- a/src/danielcortes/xyz/informes/InformeEgresos.java
+++ b/src/danielcortes/xyz/informes/InformeEgresos.java
@@ -38,6 +38,8 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
@@ -51,7 +53,7 @@ public class InformeEgresos {
};
private List informe;
- private File saveFile;
+ private Path saveFile;
//Filas donde se almacenaran los totales
private ArrayList totalRows;
@@ -68,7 +70,7 @@ public class InformeEgresos {
private CreationHelper createHelper;
private HashMap styles;
- public InformeEgresos(int tipoEgresoId, LocalDate date, File saveFile) {
+ public InformeEgresos(int tipoEgresoId, LocalDate date, Path saveFile) {
new SQLiteCajaDAO().createCajasForMonth(date);
this.informe = new SQLiteInformeEgresosContentDAO().getInformeEgresosFactuasMateriaPrima(date, tipoEgresoId);
this.saveFile = saveFile;
@@ -275,7 +277,7 @@ public class InformeEgresos {
return styles;
}
- public File generarInforme() {
+ public Path generarInforme() {
fillHeaders();
fillData();
fillTotales();
@@ -283,7 +285,7 @@ public class InformeEgresos {
setStyles();
addBorders();
- try (OutputStream fileOut = new FileOutputStream(this.saveFile)) {
+ try (OutputStream fileOut = Files.newOutputStream(this.saveFile)){
wb.write(fileOut);
return this.saveFile;
} catch (IOException e) {
diff --git a/src/danielcortes/xyz/informes/InformeLibroDeVentas.java b/src/danielcortes/xyz/informes/InformeLibroDeVentas.java
index 2d31386..deb373c 100644
--- a/src/danielcortes/xyz/informes/InformeLibroDeVentas.java
+++ b/src/danielcortes/xyz/informes/InformeLibroDeVentas.java
@@ -36,6 +36,8 @@ import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.nio.file.Files;
+import java.nio.file.Path;
import java.time.LocalDate;
import java.time.ZoneId;
import java.util.*;
@@ -67,14 +69,14 @@ public class InformeLibroDeVentas {
private ArrayList informe;
private int informeSize;
- private File saveFile;
+ private Path saveFile;
private Workbook wb;
private Sheet sheet;
private CreationHelper createHelper;
private HashMap styles;
- public InformeLibroDeVentas(LocalDate date, File saveFile) {
+ public InformeLibroDeVentas(LocalDate date, Path saveFile) {
new SQLiteCajaDAO().createCajasForMonth(date);
this.informe = new ArrayList<>(new SQLiteInformeLibroDeVentasContentDAO().getInformeMensual(date));
@@ -298,7 +300,7 @@ public class InformeLibroDeVentas {
}
}
- public File generarInforme() {
+ public Path generarInforme() {
sortInforme();
fillData();
fillHeaders();
@@ -308,7 +310,7 @@ public class InformeLibroDeVentas {
setStyles();
addBorders();
- try (OutputStream fileOut = new FileOutputStream(this.saveFile)) {
+ try (OutputStream fileOut = Files.newOutputStream(this.saveFile)) {
wb.write(fileOut);
return this.saveFile;
} catch (IOException e) {
diff --git a/src/danielcortes/xyz/utils/FileUtils.java b/src/danielcortes/xyz/utils/FileUtils.java
index a1ee472..d59dacc 100644
--- a/src/danielcortes/xyz/utils/FileUtils.java
+++ b/src/danielcortes/xyz/utils/FileUtils.java
@@ -24,15 +24,17 @@
package danielcortes.xyz.utils;
-import java.nio.file.InvalidPathException;
-import java.nio.file.Paths;
+import java.io.File;
+import java.io.IOException;
public class FileUtils {
public static boolean isValidPath(String path) {
+ File file = new File(path);
try {
- Paths.get(path);
- } catch (InvalidPathException | NullPointerException ex) {
- ex.printStackTrace();
+ //noinspection ResultOfMethodCallIgnored
+ file.getCanonicalPath();
+ } catch (IOException e) {
+ e.printStackTrace();
return false;
}
return true;