forked from jverein/jverein
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spendenbescheinigung Liste Export als PDF und CSV
- Loading branch information
Johann Maierhofer
committed
Dec 9, 2024
1 parent
a7ccd91
commit 18f7908
Showing
5 changed files
with
318 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
src/de/jost_net/JVerein/io/SpendenbescheinigungExportCSV.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
88
src/de/jost_net/JVerein/io/SpendenbescheinigungExportPDF.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |