Skip to content

Commit

Permalink
Spendenbescheinigung Liste Export als PDF und CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
Johann Maierhofer committed Dec 9, 2024
1 parent a7ccd91 commit 18f7908
Show file tree
Hide file tree
Showing 5 changed files with 318 additions and 2 deletions.
116 changes: 116 additions & 0 deletions src/de/jost_net/JVerein/gui/control/SpendenbescheinigungControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@

import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.FileDialog;
import org.eclipse.swt.widgets.Listener;

import de.jost_net.JVerein.Einstellungen;
Expand All @@ -48,7 +50,10 @@
import de.jost_net.JVerein.gui.menu.SpendenbescheinigungMenu;
import de.jost_net.JVerein.gui.parts.BuchungListTablePart;
import de.jost_net.JVerein.gui.view.SpendenbescheinigungMailView;
import de.jost_net.JVerein.io.FileViewer;
import de.jost_net.JVerein.io.MailSender;
import de.jost_net.JVerein.io.SpendenbescheinigungExportCSV;
import de.jost_net.JVerein.io.SpendenbescheinigungExportPDF;
import de.jost_net.JVerein.keys.Adressblatt;
import de.jost_net.JVerein.keys.Ausgabeart;
import de.jost_net.JVerein.keys.FormularArt;
Expand Down Expand Up @@ -133,6 +138,9 @@ public class SpendenbescheinigungControl extends DruckMailControl

private String sql = "";

final static String ExportPDF = "PDF";

final static String ExportCSV = "CSV";

public SpendenbescheinigungControl(AbstractView view)
{
Expand Down Expand Up @@ -935,5 +943,113 @@ public boolean isInterrupted()
};
Application.getController().start(t);
}

public Button getPDFExportButton()
{
Button b = new Button("PDF", new Action()
{

@Override
public void handleAction(Object context) throws ApplicationException
{
starteExport(ExportPDF);
}
}, null, false, "file-pdf.png");
// button
return b;
}

public Button getCSVExportButton()
{
Button b = new Button("CSV", new Action()
{
@Override
public void handleAction(Object context) throws ApplicationException
{
starteExport(ExportCSV);
}
}, null, false, "xsd.png");
// button
return b;
}

private void starteExport(String type) throws ApplicationException
{
try
{
FileDialog fd = new FileDialog(GUI.getShell(), SWT.SAVE);
fd.setText("Ausgabedatei wählen.");
String path = settings.getString("lastdir",
System.getProperty("user.home"));
if (path != null && path.length() > 0)
{
fd.setFilterPath(path);
}
fd.setFileName(new Dateiname("spendenbescheinigungen", "",
Einstellungen.getEinstellung().getDateinamenmuster(), type).get());

final String s = fd.open();

if (s == null || s.length() == 0)
{
return;
}

final File file = new File(s);
settings.setAttribute("lastdir", file.getParent());
ArrayList<Spendenbescheinigung> spbList = getSpendenbescheinigungen();
ausgabe(type, file, spbList);
}
catch (RemoteException e)
{
throw new ApplicationException(
String.format("Fehler beim Aufbau des Reports: %s", e.getMessage()));
}
}

private void ausgabe(final String type, final File file,
final ArrayList<Spendenbescheinigung> spbList)
{
BackgroundTask t = new BackgroundTask()
{
@Override
public void run(ProgressMonitor monitor) throws ApplicationException
{
try
{
switch (type)
{
case ExportCSV:
new SpendenbescheinigungExportCSV(file, spbList);
break;
case ExportPDF:
new SpendenbescheinigungExportPDF(file, spbList);
break;
}
GUI.getCurrentView().reload();
}
catch (Exception e)
{
Logger.error("Fehler", e);
GUI.getStatusBar().setErrorText(e.getMessage());
throw new ApplicationException(e);
}
FileViewer.show(file);
}

@Override
public void interrupt()
{
//
}

@Override
public boolean isInterrupted()
{
return false;
}
};
Application.getController().start(t);
}

}
4 changes: 2 additions & 2 deletions src/de/jost_net/JVerein/gui/control/ZusatzbetragControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,9 @@ public void run(ProgressMonitor monitor) throws ApplicationException
BaseColor.LIGHT_GRAY);
reporter.addHeaderColumn("Startdatum", Element.ALIGN_LEFT, 30,
BaseColor.LIGHT_GRAY);
reporter.addHeaderColumn("nächste Fälligkeit", Element.ALIGN_LEFT, 30,
reporter.addHeaderColumn("Nächste Fälligkeit", Element.ALIGN_LEFT, 30,
BaseColor.LIGHT_GRAY);
reporter.addHeaderColumn("letzte Ausführung", Element.ALIGN_LEFT, 30,
reporter.addHeaderColumn("Letzte Ausführung", Element.ALIGN_LEFT, 30,
BaseColor.LIGHT_GRAY);
reporter.addHeaderColumn("Intervall", Element.ALIGN_LEFT, 30,
BaseColor.LIGHT_GRAY);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public void bind() throws Exception
ButtonArea buttons = new ButtonArea();
buttons.addButton("Hilfe", new DokumentationAction(),
DokumentationUtil.SPENDENBESCHEINIGUNG, false, "question-circle.png");
buttons.addButton(control.getCSVExportButton());
buttons.addButton(control.getPDFExportButton());
buttons.addButton("Neu (Sachspende)", new SpendenbescheinigungAction(Spendenart.SACHSPENDE), null,
false, "document-new.png");
buttons.addButton("Neu (automatisch)",
Expand Down
110 changes: 110 additions & 0 deletions src/de/jost_net/JVerein/io/SpendenbescheinigungExportCSV.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/**********************************************************************
* Copyright (c) by Heiner Jostkleigrewe
* This program is free software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not,
* see <http://www.gnu.org/licenses/>.
*
* [email protected]
* www.jverein.de
**********************************************************************/
package de.jost_net.JVerein.io;

import java.io.File;
import java.io.FileWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import org.supercsv.cellprocessor.ConvertNullTo;
import org.supercsv.cellprocessor.FmtNumber;
import org.supercsv.cellprocessor.ift.CellProcessor;
import org.supercsv.io.CsvMapWriter;
import org.supercsv.io.ICsvMapWriter;
import org.supercsv.prefs.CsvPreference;

import de.jost_net.JVerein.Einstellungen;
import de.jost_net.JVerein.rmi.Spendenbescheinigung;
import de.willuhn.jameica.gui.GUI;
import de.willuhn.logging.Logger;
import de.willuhn.util.ApplicationException;

public class SpendenbescheinigungExportCSV
{

private static CellProcessor[] getProcessors()
{
final CellProcessor[] processors = new CellProcessor[] {
new ConvertNullTo(""), new ConvertNullTo(""),
new ConvertNullTo("", new FmtNumber(Einstellungen.DECIMALFORMAT)), // Betrag
new ConvertNullTo(""), new ConvertNullTo(""), new ConvertNullTo(""),
new ConvertNullTo(""), new ConvertNullTo(""), new ConvertNullTo(""),
new ConvertNullTo(""), };

return processors;
}

public SpendenbescheinigungExportCSV(final File file,
final ArrayList<Spendenbescheinigung> spbList) throws ApplicationException
{
ICsvMapWriter writer = null;
try
{
writer = new CsvMapWriter(new FileWriter(file),
CsvPreference.EXCEL_NORTH_EUROPE_PREFERENCE);
final CellProcessor[] processors = getProcessors();
Map<String, Object> csvzeile = new HashMap<>();

// Header
String[] header = { "Bescheinigungsdatum", "Spendedatum", "Betrag",
"Zeile 1", "Zeile 2", "Zeile 3", "Zeile 4", "Zeile 5", "Zeile 6",
"Zeile 7" };
writer.writeHeader(header);

// Einträge
for (Spendenbescheinigung spb : spbList)
{
csvzeile.put(header[0], spb.getBescheinigungsdatum());
csvzeile.put(header[1], spb.getSpendedatum());
csvzeile.put(header[2], (Double) spb.getBetrag());
csvzeile.put(header[3], spb.getZeile1());
csvzeile.put(header[4], spb.getZeile2());
csvzeile.put(header[5], spb.getZeile3());
csvzeile.put(header[6], spb.getZeile4());
csvzeile.put(header[7], spb.getZeile5());
csvzeile.put(header[8], spb.getZeile6());
csvzeile.put(header[9], spb.getZeile7());
writer.write(csvzeile, header, processors);
}

GUI.getStatusBar().setSuccessText("Ausgabe fertig");
writer.close();
}
catch (Exception e)
{
Logger.error("Error while creating report", e);
throw new ApplicationException("Fehler", e);
}
finally
{
if (writer != null)
{
try
{
writer.close();
}
catch (Exception e)
{
Logger.error("Error while creating report", e);
throw new ApplicationException("Fehler", e);
}
}
}
}
}
88 changes: 88 additions & 0 deletions src/de/jost_net/JVerein/io/SpendenbescheinigungExportPDF.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
/**********************************************************************
* Copyright (c) by Heiner Jostkleigrewe
* This program is free software: you can redistribute it and/or modify it under the terms of the
* GNU General Public License as published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
* the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with this program. If not,
* see <http://www.gnu.org/licenses/>.
*
* [email protected]
* www.jverein.de
**********************************************************************/
package de.jost_net.JVerein.io;

import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;

import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Element;

import de.jost_net.JVerein.rmi.Spendenbescheinigung;
import de.willuhn.jameica.gui.GUI;
import de.willuhn.logging.Logger;
import de.willuhn.util.ApplicationException;

public class SpendenbescheinigungExportPDF
{

public SpendenbescheinigungExportPDF(final File file,
final ArrayList<Spendenbescheinigung> spbList)
throws ApplicationException
{
try
{
FileOutputStream fos = new FileOutputStream(file);
Reporter reporter = new Reporter(fos, "Spendenbescheinigungen", "",
spbList.size());
reporter.addHeaderColumn("Bescheinigungsdatum", Element.ALIGN_LEFT, 10,
BaseColor.LIGHT_GRAY);
reporter.addHeaderColumn("Spendedatum", Element.ALIGN_LEFT, 10,
BaseColor.LIGHT_GRAY);
reporter.addHeaderColumn("Betrag", Element.ALIGN_RIGHT, 10,
BaseColor.LIGHT_GRAY);
reporter.addHeaderColumn("Zeile 1", Element.ALIGN_LEFT, 10,
BaseColor.LIGHT_GRAY);
reporter.addHeaderColumn("Zeile 2", Element.ALIGN_LEFT, 10,
BaseColor.LIGHT_GRAY);
reporter.addHeaderColumn("Zeile 3", Element.ALIGN_LEFT, 10,
BaseColor.LIGHT_GRAY);
reporter.addHeaderColumn("Zeile 4", Element.ALIGN_LEFT, 10,
BaseColor.LIGHT_GRAY);
reporter.addHeaderColumn("Zeile 5", Element.ALIGN_LEFT, 10,
BaseColor.LIGHT_GRAY);
reporter.addHeaderColumn("Zeile 5", Element.ALIGN_LEFT, 10,
BaseColor.LIGHT_GRAY);
reporter.addHeaderColumn("Zeile 7", Element.ALIGN_LEFT, 10,
BaseColor.LIGHT_GRAY);
reporter.createHeader();
for (Spendenbescheinigung spb : spbList)
{
reporter.addColumn(spb.getBescheinigungsdatum(), Element.ALIGN_LEFT);
reporter.addColumn(spb.getSpendedatum(), Element.ALIGN_LEFT);
reporter.addColumn(spb.getBetrag());
reporter.addColumn(spb.getZeile1(), Element.ALIGN_LEFT);
reporter.addColumn(spb.getZeile2(), Element.ALIGN_LEFT);
reporter.addColumn(spb.getZeile3(), Element.ALIGN_LEFT);
reporter.addColumn(spb.getZeile4(), Element.ALIGN_LEFT);
reporter.addColumn(spb.getZeile5(), Element.ALIGN_LEFT);
reporter.addColumn(spb.getZeile6(), Element.ALIGN_LEFT);
reporter.addColumn(spb.getZeile7(), Element.ALIGN_LEFT);
}
reporter.closeTable();
reporter.close();
fos.close();
GUI.getStatusBar().setSuccessText("Ausgabe fertig.");
}
catch (Exception e)
{
Logger.error("error while creating report", e);
throw new ApplicationException("Fehler", e);
}
}
}

0 comments on commit 18f7908

Please sign in to comment.