Skip to content

Commit

Permalink
Formularfeld Zähler & Formularverknüpfungen (#72)
Browse files Browse the repository at this point in the history
* Formularfeld Zähler & Formularverknüpfungen

- Neues Formularfeld "zaehler" eingefügt
- Feld "zaehler" wird in Formularübersicht als "Fortlaufende Nr."
ausgegeben
- Bei Formularen vom Typ Rechnung und Mahnung wird die Fortlaufende Nr.
automatisch hochgezählt
- Formulare können verknüpft werden
- Bei verknüpften Formularen werden die zaehler gleichgesetzt und
untereinander aktualisiert
- Eine Vererbung der Verknüpfung ist nicht implementiert

* Fix: Show zaehler length in bills settings

---------

Co-authored-by: Alexander Dippe <[email protected]>
  • Loading branch information
dippeal and Alexander Dippe authored Dec 11, 2023
1 parent 9cf2f17 commit 1feeee8
Show file tree
Hide file tree
Showing 18 changed files with 452 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/de/jost_net/JVerein/Variable/AllgemeineVar.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public enum AllgemeineVar
TAGESDATUMTT("tagesdatumtt"), //
TAGESDATUMMM("tagesdatummm"), //
TAGESDATUMJJJJ("tagesdatumjjjj"), //
VORMONAT("vormonat"), VORJAHR("vorjahr"); //
VORMONAT("vormonat"), //
VORJAHR("vorjahr"), //
ZAEHLER("zaehler"); //

private String name;

Expand Down
3 changes: 3 additions & 0 deletions src/de/jost_net/JVerein/gui/action/FormularAnzeigeAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import de.jost_net.JVerein.Einstellungen;
import de.jost_net.JVerein.Variable.AllgemeineMap;
import de.jost_net.JVerein.Variable.AllgemeineVar;
import de.jost_net.JVerein.Variable.LastschriftMap;
import de.jost_net.JVerein.Variable.MitgliedMap;
import de.jost_net.JVerein.Variable.MitgliedskontoVar;
Expand Down Expand Up @@ -77,6 +78,8 @@ public void handleAction(Object context) throws ApplicationException
map = new LastschriftMap().getMap(ls, map);

map = new AllgemeineMap().getMap(map);
// Get current zaehler
map.put(AllgemeineVar.ZAEHLER.getName(), formular.getZaehler());
map.put(FormularfeldControl.EMPFAENGER,
"Herr\nDr. Willi Wichtig\nTestgasse 1\n12345 Testenhausen");
map.put(FormularfeldControl.BUCHUNGSDATUM, new Date());
Expand Down
44 changes: 44 additions & 0 deletions src/de/jost_net/JVerein/gui/action/FormularDeleteAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@

import java.rmi.RemoteException;

import de.jost_net.JVerein.Einstellungen;
import de.jost_net.JVerein.rmi.Formular;
import de.willuhn.jameica.gui.Action;
import de.willuhn.jameica.gui.GUI;
import de.willuhn.jameica.gui.dialogs.AbstractDialog;
import de.willuhn.jameica.gui.dialogs.SimpleDialog;
import de.willuhn.jameica.gui.dialogs.YesNoDialog;
import de.willuhn.jameica.gui.parts.TablePart;
import de.willuhn.logging.Logger;
Expand Down Expand Up @@ -52,6 +55,47 @@ public void handleAction(Object context) throws ApplicationException
return;
}

// Do not delete a form if it is linked by other forms
if (f.hasFormlinks())
{
SimpleDialog sd = new SimpleDialog(AbstractDialog.POSITION_CENTER);
sd.setTitle("Formularabhängigkeit");
sd.setText(String.format(
"Das Formular kann nicht gelöscht werden. Es ist noch mit %d Formular(en) verknüpft.",
f.getLinked().size()));
try
{
sd.open();
}
catch (Exception e)
{
Logger.error("Fehler", e);
}
return;
}
// Do not delete a form if it is linked to another
Integer formlink = f.getFormlink();
if (formlink > 0)
{
Formular fo = (Formular) Einstellungen.getDBService().createObject(
Formular.class, String.valueOf(formlink));

SimpleDialog sd = new SimpleDialog(AbstractDialog.POSITION_CENTER);
sd.setTitle("Formularabhängigkeit");
sd.setText(String.format(
"Das Formular kann nicht gelöscht werden. Es ist mit dem Formular \"%s\" verknüpft.",
fo.getBezeichnung()));
try
{
sd.open();
}
catch (Exception e)
{
Logger.error("Fehler", e);
}
return;
}

YesNoDialog d = new YesNoDialog(YesNoDialog.POSITION_CENTER);
d.setTitle("Formular löschen");
d.setText(("Wollen Sie dieses Formular wirklich löschen?"));
Expand Down
15 changes: 15 additions & 0 deletions src/de/jost_net/JVerein/gui/control/EinstellungControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ public class EinstellungControl extends AbstractControl

private TextInput rechnungtextbar;

private IntegerInput zaehlerlaenge;

private CheckboxInput externemitgliedsnummer;

private SelectInput arbeitsstundenmodel;
Expand Down Expand Up @@ -748,6 +750,16 @@ public TextInput getRechnungTextBar() throws RemoteException
return rechnungtextbar;
}

public IntegerInput getZaehlerLaenge() throws RemoteException
{
if (null == zaehlerlaenge)
{
zaehlerlaenge = new IntegerInput(
Einstellungen.getEinstellung().getZaehlerLaenge());
}
return zaehlerlaenge;
}

public CheckboxInput getExterneMitgliedsnummer() throws RemoteException
{
if (externemitgliedsnummer != null)
Expand Down Expand Up @@ -1914,6 +1926,9 @@ public void handleStoreRechnungen()
e.setRechnungTextUeberweisung((String) rechnungtextueberweisung
.getValue());
e.setRechnungTextBar((String) rechnungtextbar.getValue());
Integer length = (Integer) zaehlerlaenge.getValue();
e.setZaehlerLaenge(length);

e.store();
Einstellungen.setEinstellung(e);

Expand Down
98 changes: 97 additions & 1 deletion src/de/jost_net/JVerein/gui/control/FormularControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,25 @@
import java.io.FileNotFoundException;
import java.io.IOException;
import java.rmi.RemoteException;
import java.util.List;

import de.jost_net.JVerein.Einstellungen;
import de.jost_net.JVerein.gui.action.FormularAction;
import de.jost_net.JVerein.gui.formatter.FormularLinkFormatter;
import de.jost_net.JVerein.gui.formatter.FormularartFormatter;
import de.jost_net.JVerein.gui.input.FormularInput;
import de.jost_net.JVerein.gui.menu.FormularMenu;
import de.jost_net.JVerein.keys.FormularArt;
import de.jost_net.JVerein.rmi.Formular;
import de.jost_net.JVerein.server.FormularImpl;
import de.willuhn.datasource.rmi.DBIterator;
import de.willuhn.datasource.rmi.DBService;
import de.willuhn.jameica.gui.AbstractControl;
import de.willuhn.jameica.gui.AbstractView;
import de.willuhn.jameica.gui.GUI;
import de.willuhn.jameica.gui.Part;
import de.willuhn.jameica.gui.input.FileInput;
import de.willuhn.jameica.gui.input.IntegerInput;
import de.willuhn.jameica.gui.input.SelectInput;
import de.willuhn.jameica.gui.input.TextInput;
import de.willuhn.jameica.gui.parts.Column;
Expand All @@ -56,6 +61,10 @@ public class FormularControl extends AbstractControl

private Formular formular;

private IntegerInput zaehler;

private SelectInput formlink;

public FormularControl(AbstractView view)
{
super(view);
Expand Down Expand Up @@ -107,6 +116,76 @@ public FileInput getDatei()
return datei;
}

public IntegerInput getZaehler() throws RemoteException
{
if (zaehler != null)
{
return zaehler;
}
zaehler = new IntegerInput(getFormular().getZaehler());

// Deactivate the input field if form is linked to another form
if (getFormular().getFormlink() > 0)
{
zaehler.setEnabled(false);
}
return zaehler;
}

public SelectInput getFormlink() throws RemoteException
{
if (formlink != null)
{
return formlink;
}

Formular currentForm = getFormular();
Integer currentlyLinkedFormId = currentForm.getFormlink();
// Create select box
if (currentlyLinkedFormId != 0)
{
formlink = new FormularInput(null, currentlyLinkedFormId.toString());
}
else
{
formlink = new FormularInput(null);
}

// Remove current form from select list
if (currentForm.getID() != null)
{
@SuppressWarnings("unchecked")
List<SelectInput> list = formlink.getList();
int size = list.size();
for (int i=0;i<size;++i)
{
Object object = list.get(i);
if (object == null) continue;
// Cast to FormularImpl
FormularImpl formimpl = (FormularImpl) object;
// Remove current form object and stop comparing
if (Integer.valueOf(formimpl.getID()) == Integer.valueOf(currentForm.getID()))
{
list.remove(i);
formlink.setList(list);
break;
}
}
}

// Deactivate the select box if it has linked forms
if (currentForm.hasFormlinks())
{
formlink.setPleaseChoose("Verknüpft");
formlink.disable();
}
else
{
formlink.setPleaseChoose("Keine");
}
return formlink;
}

/**
* This method stores the project using the current values.
*/
Expand All @@ -119,7 +198,6 @@ public void handleStore()
FormularArt fa = (FormularArt) getArt().getValue();
f.setArt(fa);
String dat = (String) getDatei().getValue();

if (dat.length() > 0)
{
FileInputStream fis = new FileInputStream(dat);
Expand All @@ -128,6 +206,21 @@ public void handleStore()
fis.close();
f.setInhalt(b);
}

int newZaehler = (int) getZaehler().getValue();
f.setZaehler(newZaehler);
f.setZaehlerToFormlink(newZaehler);

Formular fl = (Formular) getFormlink().getValue();
if (fl != null)
{
f.setFormlink(Integer.valueOf(fl.getID()));
}
else
{
f.setFormlink(null);
}

f.store();
GUI.getStatusBar().setSuccessText("Formular gespeichert");
}
Expand Down Expand Up @@ -164,6 +257,9 @@ public Part getFormularList() throws RemoteException
formularList.addColumn("Bezeichnung", "bezeichnung");
formularList.addColumn("Art", "art", new FormularartFormatter(), false,
Column.ALIGN_LEFT);
formularList.addColumn("Fortlaufende Nr.", "zaehler");
formularList.addColumn("Verknüpft mit", "formlink",
new FormularLinkFormatter());
formularList.setRememberColWidths(true);
formularList.setContextMenu(new FormularMenu(this));
formularList.setRememberOrder(true);
Expand Down
2 changes: 2 additions & 0 deletions src/de/jost_net/JVerein/gui/control/FormularfeldControl.java
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ public class FormularfeldControl extends AbstractControl
public static final String AUSTRITT = "Austritt";

public static final String KUENDIGUNG = "Kündigung";

public static final String ZAEHLER = "Fortlaufende Nummer des Formulars";

public FormularfeldControl(AbstractView view, Formular formular)
{
Expand Down
55 changes: 55 additions & 0 deletions src/de/jost_net/JVerein/gui/formatter/FormularLinkFormatter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**********************************************************************
* 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.gui.formatter;

import java.rmi.RemoteException;

import de.jost_net.JVerein.Einstellungen;
import de.jost_net.JVerein.rmi.Formular;
import de.willuhn.jameica.gui.formatter.Formatter;
import de.willuhn.logging.Logger;

public class FormularLinkFormatter implements Formatter
{
@Override
public String format(Object o)
{
if (o == null)
{
return "";
}
if (o instanceof Long)
{
try
{
Formular f = (Formular) Einstellungen.getDBService()
.createObject(Formular.class, o.toString());
if (f == null)
{
return "Das Formular mit der ID " + o.toString() + " wurde gelöscht.";
}
return f.getBezeichnung();
}
catch (RemoteException e)
{
Logger.error("Fehler", e);
}
}

return "";
}
}
5 changes: 5 additions & 0 deletions src/de/jost_net/JVerein/gui/input/FormularInput.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ private static GenericIterator<Formular> init(FormularArt mahnung)
{
DBIterator<Formular> it = Einstellungen.getDBService()
.createList(Formular.class);
// Add filter only if needed
if (mahnung == null)
{
return it;
}
it.addFilter("art = ?", mahnung.getKey());
return it;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public void bind() throws Exception
cont.addLabelPair("Text Überweisung",
control.getRechnungTextUeberweisung());
cont.addLabelPair("Text Bar", control.getRechnungTextBar());
cont.addLabelPair("Zählerlänge", control.getZaehlerLaenge());

ButtonArea buttons = new ButtonArea();
buttons.addButton("Hilfe", new DokumentationAction(),
Expand Down
2 changes: 2 additions & 0 deletions src/de/jost_net/JVerein/gui/view/FormularDetailView.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public void bind() throws Exception
group.addLabelPair("Bezeichnung", control.getBezeichnung(true));
group.addLabelPair("Art", control.getArt());
group.addLabelPair("Datei", control.getDatei());
group.addLabelPair("Fortlaufende Nr.", control.getZaehler());
group.addLabelPair("Formularverknüpfung", control.getFormlink());

ButtonArea buttons = new ButtonArea();
buttons.addButton("Hilfe", new DokumentationAction(),
Expand Down
Loading

0 comments on commit 1feeee8

Please sign in to comment.