Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature alte Buchungen löschen #225

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
98 changes: 98 additions & 0 deletions src/de/jost_net/JVerein/gui/action/BuchungenDeleteAction.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/**********************************************************************
* 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/>.
*
* heiner@jverein.de
* www.jverein.de
**********************************************************************/
package de.jost_net.JVerein.gui.action;

import java.util.Date;

import de.jost_net.JVerein.rmi.Buchung;
import de.jost_net.JVerein.Einstellungen;
import de.jost_net.JVerein.Messaging.BuchungMessage;
import de.jost_net.JVerein.gui.dialogs.BuchungenDeleteDialog;
import de.willuhn.datasource.rmi.DBIterator;
import de.willuhn.jameica.gui.Action;
import de.willuhn.jameica.gui.GUI;
import de.willuhn.jameica.system.Application;
import de.willuhn.jameica.system.OperationCanceledException;
import de.willuhn.logging.Logger;
import de.willuhn.util.ApplicationException;

/**
* Loeschen einer Buchung.
*/
public class BuchungenDeleteAction implements Action
{

@Override
public void handleAction(Object context) throws ApplicationException
{

try
{
BuchungenDeleteDialog d = new BuchungenDeleteDialog(BuchungenDeleteDialog.POSITION_CENTER);
Date choice = (Date) d.open();
if (choice == null)
{
return;
}

DBIterator<Buchung> it = Einstellungen.getDBService()
.createList(Buchung.class);
it.addFilter("datum < ?", choice);
int count = 0;
Buchung b = null;
while (it.hasNext())
{
b = it.next();
try
{
if (d.getLoeschen() && (b.getMitgliedskonto() != null))
{
b.getMitgliedskonto().delete();
}
}
catch (Exception e)
{
// Das kann passieren wenn der Sollbuchung mehrere Buchungen
// zugeordnet waren. Dann existiert die Sollbuchung nicht mehr
// bei den weiteren Buchungen da das Query vorher erfolgt ist
}
b.delete();
count++;
}
if (count > 0)
{
GUI.getStatusBar().setSuccessText(String.format(
"%d Buchung" + (count != 1 ? "en" : "") + " gel�scht.", count));
}
else
{
GUI.getStatusBar().setErrorText("Keine Buchung gel�scht");
}
Application.getMessagingFactory().sendMessage(new BuchungMessage(b));
}
catch (OperationCanceledException oce)
{
throw oce;
}
catch (Exception e)
{
String fehler = "Fehler beim L�schen von Buchungen.";
GUI.getStatusBar().setErrorText(fehler);
Logger.error(fehler, e);
}
}
}
138 changes: 138 additions & 0 deletions src/de/jost_net/JVerein/gui/dialogs/BuchungenDeleteDialog.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
/**********************************************************************
* 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/>.
*
* heiner@jverein.de
* www.jverein.de
**********************************************************************/
package de.jost_net.JVerein.gui.dialogs;

import java.util.Calendar;
import java.util.Date;

import org.eclipse.swt.widgets.Composite;

import de.willuhn.jameica.gui.Action;
import de.willuhn.jameica.gui.dialogs.AbstractDialog;
import de.willuhn.jameica.gui.input.CheckboxInput;
import de.willuhn.jameica.gui.input.DateInput;
import de.willuhn.jameica.gui.parts.ButtonArea;
import de.willuhn.jameica.gui.util.Container;
import de.willuhn.jameica.gui.util.LabelGroup;
import de.willuhn.jameica.gui.util.SWTUtil;
import de.willuhn.jameica.gui.util.SimpleContainer;

/**
* Dialog zur Zuordnung einer Buchungsart.
*/
public class BuchungenDeleteDialog extends AbstractDialog<Date>
{

private DateInput dateInput = null;

private CheckboxInput sollbuchungenloeschen = null;

private Date date = null;

private Boolean loeschen = true;

private String text = "Diese Aktion l�scht alle Buchungen vor dem "
+ "selektierten Datum."
+ "\nSollbuchungen k�nnen mit gel�scht werden damit "
+ "\nkeine offenen Buchungen im Mitgliedskonto bleiben."
+ "\nDie Buchungen k�nnen nicht wieder hergestellt werden!"
+ "\nBitte Aufbewahrungsfristen beachten!";

/**
* @param position
*/
public BuchungenDeleteDialog(int position)
{
super(position);
setTitle("Alte Buchungen l�schen");
setPanelText("Alte Buchungen l�schen?");
setSideImage(SWTUtil.getImage("dialog-warning-large.png"));
}

@Override
protected void paint(Composite parent) throws Exception
{
Container container = new SimpleContainer(parent);
container.addText(text,true);

LabelGroup group = new LabelGroup(parent, "");
group.addLabelPair("Buchungen l�schen �lter als", getDatumAuswahl());
group.addLabelPair("Zugeordnete Sollbuchungen l�schen", getSollbuchungenLoeschen());

ButtonArea buttons = new ButtonArea();
buttons.addButton("Ok", new Action()
{
@Override
public void handleAction(Object context)
{
date = (Date) getDatumAuswahl().getValue();
loeschen = (Boolean) getSollbuchungenLoeschen().getValue();
close();
}
}, null, true, "ok.png");

buttons.addButton("Abbrechen", new Action()
{
@Override
public void handleAction(Object context)
{
date = null;
close();
}
}, null, false, "process-stop.png");

buttons.paint(parent);
}

/**
* @see de.willuhn.jameica.gui.dialogs.AbstractDialog#getData()
*/
@Override
public Date getData() throws Exception
{
return date;
}

public Boolean getLoeschen()
{
return loeschen;
}

private DateInput getDatumAuswahl()
{
if (dateInput != null)
{
return dateInput;
}
Calendar cal = Calendar.getInstance();
cal.set(Calendar.YEAR, 2000);
cal.set(Calendar.MONTH, Calendar.JANUARY);
cal.set(Calendar.DAY_OF_MONTH, 1);
dateInput = new DateInput(new Date(cal.getTimeInMillis()));
return dateInput;
}

private CheckboxInput getSollbuchungenLoeschen()
{
if (sollbuchungenloeschen != null)
{
return sollbuchungenloeschen;
}
sollbuchungenloeschen = new CheckboxInput(true);
return sollbuchungenloeschen;
}
}
3 changes: 3 additions & 0 deletions src/de/jost_net/JVerein/gui/view/BuchungslisteView.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import de.jost_net.JVerein.gui.action.BuchungImportAction;
import de.jost_net.JVerein.gui.action.BuchungNeuAction;
import de.jost_net.JVerein.gui.action.BuchungenDeleteAction;
import de.jost_net.JVerein.gui.action.DokumentationAction;
import de.jost_net.JVerein.gui.control.BuchungsControl;
import de.jost_net.JVerein.gui.control.BuchungsHeaderControl;
Expand Down Expand Up @@ -112,6 +113,8 @@ public void handleAction(Object context) throws ApplicationException
ButtonArea buttons = new ButtonArea();
buttons.addButton("Hilfe", new DokumentationAction(),
DokumentationUtil.BUCHUNGEN, false, "question-circle.png");
buttons.addButton("Alte Buchungen l�schen...", new BuchungenDeleteAction(), null, false,
"user-trash-full.png");
buttons.addButton("Import", new BuchungImportAction(), null, false,
"file-import.png");
buttons.addButton(control.getStartCSVAuswertungButton());
Expand Down
2 changes: 1 addition & 1 deletion src/de/jost_net/JVerein/server/BuchungImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public String getPrimaryAttribute()
@Override
protected void deleteCheck() throws ApplicationException
{
insertCheck();
//insertCheck();
}

@Override
Expand Down
16 changes: 16 additions & 0 deletions src/de/jost_net/JVerein/server/DDLTool/AbstractDDLUpdate.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,5 +316,21 @@ public String dropTable(String table)
{
return "drop table " + table + ";\n";
}

public String dropForeignKey(String constraintname, String table)
{
switch (drv)
{
case H2:
{
return "ALTER TABLE " + table + " DROP CONSTRAINT " + constraintname + ";\n";
}
case MYSQL:
{
return "ALTER TABLE " + table + " DROP FOREIGN KEY " + constraintname + ";\n";
}
}
return "";
}

}
36 changes: 36 additions & 0 deletions src/de/jost_net/JVerein/server/DDLTool/Updates/Update0441.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**********************************************************************
* 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/>.
*
**********************************************************************/
package de.jost_net.JVerein.server.DDLTool.Updates;

import de.jost_net.JVerein.server.DDLTool.AbstractDDLUpdate;
import de.willuhn.util.ApplicationException;
import de.willuhn.util.ProgressMonitor;

import java.sql.Connection;

public class Update0441 extends AbstractDDLUpdate
{
public Update0441(String driver, ProgressMonitor monitor, Connection conn)
{
super(driver, monitor, conn);
}

@Override
public void run() throws ApplicationException
{
execute(dropForeignKey("fkbuchungdokument1", "buchungdokument"));
execute(createForeignKey("fkbuchungdokument1", "buchungdokument",
"referenz", "buchung", "id", "CASCADE", "NO ACTION"));
}
}