Sportstätte und Sportart ist flexibel

master
Markus Kreth 3 years ago
parent d28138c3fd
commit 799da42a9c
  1. 2
      .settings/org.eclipse.core.resources.prefs
  2. 27
      sql/create_sportart_sportstaette_mysql.sql
  3. 32
      sql/create_sportart_sportstaette_postgresql.sql
  4. 123
      sql/create_tables_mysql.sql
  5. 65
      src/main/java/de/kreth/invoice/data/InvoiceItem.java
  6. 12
      src/main/java/de/kreth/invoice/persistence/SportArtRepository.java
  7. 12
      src/main/java/de/kreth/invoice/persistence/SportstaetteRepository.java
  8. 17
      src/main/java/de/kreth/invoice/report/InvoiceReportSource.java
  9. 13
      src/main/java/de/kreth/invoice/views/View.java
  10. 3
      src/main/java/de/kreth/invoice/views/invoice/InvoiceDialog.java
  11. 136
      src/main/java/de/kreth/invoice/views/invoiceitem/InvoiceItemDialog.java
  12. 36
      src/main/java/de/kreth/invoice/views/invoiceitem/InvoiceItemOverviewComponent.java
  13. 24
      src/main/resources/reports/mtv_gross_buchholz.jrxml
  14. 24
      src/main/resources/reports/mtv_gross_buchholz_trainer.jrxml

@ -2,6 +2,8 @@ eclipse.preferences.version=1
encoding//src/main/generated=UTF-8
encoding//src/main/java=UTF-8
encoding//src/main/resources=UTF-8
encoding//src/main/resources/reports/mtv_gross_buchholz.jrxml=UTF-8
encoding//src/main/resources/reports/mtv_gross_buchholz_trainer.jrxml=UTF-8
encoding//src/packaging=UTF-8
encoding//src/test/java=UTF-8
encoding/<project>=UTF-8

@ -0,0 +1,27 @@
CREATE TABLE SPORTSTAETTE
(
id int NOT NULL AUTO_INCREMENT,
updated timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
created timestamp NOT NULL DEFAULT current_timestamp(),
name varchar(50),
user_id int NOT NULL,
PRIMARY KEY (id),
CONSTRAINT sportstaette_user_fk FOREIGN KEY (user_id) REFERENCES USERDATA(id) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE SPORTART
(
id int NOT NULL AUTO_INCREMENT,
updated timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
created timestamp NOT NULL DEFAULT current_timestamp(),
name varchar(50),
user_id int NOT NULL,
PRIMARY KEY (id),
CONSTRAINT sportart_user_fk FOREIGN KEY (user_id) REFERENCES USERDATA(id) ON DELETE CASCADE ON UPDATE CASCADE
);
ALTER TABLE invoice_item
ADD COLUMN sportart_id int(11) NULL;
ALTER TABLE invoice_item
ADD COLUMN sportstaette_id int(11) NULL;

@ -0,0 +1,32 @@
CREATE TABLE public.SPORTSTAETTE
(
id BIGSERIAL PRIMARY KEY,
updated timestamp without time zone,
created timestamp without time zone,
name character varying(50),
user_id bigint NOT NULL,
CONSTRAINT sportstaette_user_fk FOREIGN KEY (user_id) REFERENCES public.USERDATA(id)
);
CREATE TABLE public.SPORTART
(
id BIGSERIAL PRIMARY KEY,
updated timestamp without time zone,
created timestamp without time zone,
name character varying(50),
user_id bigint NOT NULL,
CONSTRAINT sportart_user_fk FOREIGN KEY (user_id) REFERENCES public.USERDATA(id)
);
ALTER TABLE public.invoice_item
ADD COLUMN sportart_id bigint NULL;
ALTER TABLE public.invoice_item
ADD COLUMN sportstaette_id bigint NULL;
ALTER TABLE IF EXISTS public.SPORTSTAETTE
OWNER TO trainer;
ALTER TABLE IF EXISTS public.SPORTART
OWNER TO trainer;

@ -0,0 +1,123 @@
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET NAMES utf8 */;
/*!50503 SET NAMES utf8mb4 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
CREATE DATABASE trainerinvoice;
USE trainerinvoice;
CREATE TABLE IF NOT EXISTS `adress` (
`USER_ID` int(11) NOT NULL,
`ADRESS_TYPE` varchar(31) NOT NULL,
`ADRESS1` varchar(255) DEFAULT NULL,
`ADRESS2` varchar(255) DEFAULT NULL,
`ZIP` varchar(45) DEFAULT NULL,
`CITY` varchar(155) DEFAULT NULL,
`UPDATED` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`CREATED` timestamp NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (`USER_ID`),
CONSTRAINT `one2one_adress_user` FOREIGN KEY (`USER_ID`) REFERENCES `USERDATA` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40000 ALTER TABLE `adress` DISABLE KEYS */;
/*!40000 ALTER TABLE `adress` ENABLE KEYS */;
CREATE TABLE IF NOT EXISTS `article` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`price` double NOT NULL,
`title` varchar(50) NOT NULL,
`description` varchar(255) DEFAULT NULL,
`user_id` int(11) NOT NULL,
`report_ressource` varchar(45) NOT NULL DEFAULT '/reports/mtv_gross_buchholz.jrxml',
`UPDATED` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`CREATED` timestamp NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (`id`),
KEY `fk_artivle_user` (`user_id`),
CONSTRAINT `fk_artivle_user` FOREIGN KEY (`user_id`) REFERENCES `USERDATA` (`id`) ON DELETE CASCADE ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=latin1;
/*!40000 ALTER TABLE `article` DISABLE KEYS */;
/*!40000 ALTER TABLE `article` ENABLE KEYS */;
CREATE TABLE IF NOT EXISTS `banking_connection` (
`USER_ID` int(11) NOT NULL,
`OWNER_TYPE` varchar(31) NOT NULL,
`bank_name` varchar(255) DEFAULT NULL,
`BIC` varchar(255) DEFAULT NULL,
`IBAN` varchar(255) DEFAULT NULL,
`UPDATED` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`CREATED` timestamp NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (`USER_ID`),
UNIQUE KEY `banking_connection_UNIQUE` (`USER_ID`,`OWNER_TYPE`,`IBAN`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40000 ALTER TABLE `banking_connection` DISABLE KEYS */;
/*!40000 ALTER TABLE `banking_connection` ENABLE KEYS */;
CREATE TABLE IF NOT EXISTS `invoice` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`invoicedate` datetime NOT NULL,
`invoiceid` varchar(150) NOT NULL,
`user_id` int(11) NOT NULL,
`signImagePath` varchar(255) DEFAULT NULL,
`UPDATED` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`CREATED` timestamp NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (`id`),
KEY `fk_invoice_1_idx` (`user_id`),
CONSTRAINT `fk_invoice_1` FOREIGN KEY (`user_id`) REFERENCES `USERDATA` (`id`) ON DELETE CASCADE ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=39 DEFAULT CHARSET=latin1;
/*!40000 ALTER TABLE `invoice` DISABLE KEYS */;
/*!40000 ALTER TABLE `invoice` ENABLE KEYS */;
CREATE TABLE IF NOT EXISTS `invoice_item` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`start_time` datetime NOT NULL,
`end_time` varchar(45) NOT NULL,
`article_id` int(11) NOT NULL,
`participants` varchar(15) DEFAULT NULL,
`sum_price` decimal(7,2) NOT NULL,
`rechnung_id` int(11) DEFAULT NULL,
`invoice_id` int(11) DEFAULT NULL,
`UPDATED` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`CREATED` timestamp NOT NULL DEFAULT current_timestamp(),
`title` varchar(100) NOT NULL,
`description` varchar(255) DEFAULT NULL,
`user_id` int(11) NOT NULL,
`pricePerHour` decimal(7,2) NOT NULL,
`report` varchar(255) DEFAULT NULL,
PRIMARY KEY (`id`),
KEY `fk_invoiceitem_article` (`article_id`),
CONSTRAINT `fk_invoiceitem_article` FOREIGN KEY (`article_id`) REFERENCES `article` (`id`) ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=318 DEFAULT CHARSET=latin1;
/*!40000 ALTER TABLE `invoice_item` DISABLE KEYS */;
/*!40000 ALTER TABLE `invoice_item` ENABLE KEYS */;
CREATE TABLE IF NOT EXISTS `USERDATA` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`login` varchar(45) NOT NULL,
`prename` varchar(45) NOT NULL,
`surname` varchar(45) NOT NULL,
`password` varchar(45) NOT NULL,
`principal_id` varchar(255) DEFAULT NULL,
`email` varchar(255) DEFAULT NULL,
`family_name` varchar(255) DEFAULT NULL,
`given_name` varchar(255) DEFAULT NULL,
`UPDATED` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
`CREATED` timestamp NOT NULL DEFAULT current_timestamp(),
PRIMARY KEY (`id`),
UNIQUE KEY `id_UNIQUE` (`id`),
UNIQUE KEY `login_UNIQUE` (`login`),
UNIQUE KEY `principalIdUnique` (`principal_id`)
) ENGINE=InnoDB AUTO_INCREMENT=21 DEFAULT CHARSET=latin1;
/*!40000 ALTER TABLE `USERDATA` DISABLE KEYS */;
/*!40000 ALTER TABLE `USERDATA` ENABLE KEYS */;
/*!40101 SET SQL_MODE=IFNULL(@OLD_SQL_MODE, '') */;
/*!40014 SET FOREIGN_KEY_CHECKS=IFNULL(@OLD_FOREIGN_KEY_CHECKS, 1) */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40111 SET SQL_NOTES=IFNULL(@OLD_SQL_NOTES, 1) */;

@ -6,6 +6,7 @@ import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.FormatStyle;
import java.time.temporal.ChronoUnit;
import java.util.Objects;
import javax.persistence.Column;
import javax.persistence.Entity;
@ -34,6 +35,14 @@ public class InvoiceItem extends BaseEntity {
@JoinColumn(name = "invoice_id", nullable = true, updatable = true)
private Invoice invoice;
@ManyToOne(optional = true)
@JoinColumn(name = "sportstaette_id", nullable = true, updatable = true)
private SportStaette sportStaette;
@ManyToOne(optional = true)
@JoinColumn(name = "sportart_id", nullable = true, updatable = true)
private SportArt sportArt;
@Column(name = "sum_price")
private BigDecimal sumPrice;
@ -81,6 +90,22 @@ public class InvoiceItem extends BaseEntity {
getSumPrice();
}
public SportStaette getSportStaette() {
return sportStaette;
}
public void setSportStaette(SportStaette sportStaette) {
this.sportStaette = sportStaette;
}
public SportArt getSportArt() {
return sportArt;
}
public void setSportArt(SportArt sportArt) {
this.sportArt = sportArt;
}
public BigDecimal getSumPrice() {
if (article == null || startTime == null || endTime == null) {
sumPrice = null;
@ -128,17 +153,16 @@ public class InvoiceItem extends BaseEntity {
@Override
public String toString() {
return "InvoiceItem [id=" + getId() + ", start=" + startTime + ", end="
+ endTime + ", article=" + article + "]";
return "InvoiceItem [id()=" + getId() + ", start=" + startTime + ", end=" + endTime
+ ", ort=" + sportStaette + ", Art=" + sportArt + ", article=" + article + "]";
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((article == null) ? 0 : article.hashCode());
result = prime * result + ((endTime == null) ? 0 : endTime.hashCode());
result = prime * result + ((startTime == null) ? 0 : endTime.hashCode());
int result = super.hashCode();
result = prime * result + Objects.hash(article, description, endTime, invoice, participants, pricePerHour,
sportArt, sportStaette, startTime, sumPrice);
return result;
}
@ -147,35 +171,18 @@ public class InvoiceItem extends BaseEntity {
if (this == obj) {
return true;
}
if (obj == null) {
if (!super.equals(obj)) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
InvoiceItem other = (InvoiceItem) obj;
if (article == null) {
if (other.article != null) {
return false;
}
} else if (!article.equals(other.article)) {
return false;
}
if (endTime == null) {
if (other.endTime != null) {
return false;
}
} else if (!endTime.equals(other.endTime)) {
return false;
}
if (startTime == null) {
if (other.startTime != null) {
return false;
}
} else if (!endTime.equals(other.endTime)) {
return false;
}
return true;
return Objects.equals(article, other.article) && Objects.equals(description, other.description)
&& Objects.equals(endTime, other.endTime) && Objects.equals(invoice, other.invoice)
&& Objects.equals(participants, other.participants) && Objects.equals(pricePerHour, other.pricePerHour)
&& Objects.equals(sportArt, other.sportArt) && Objects.equals(sportStaette, other.sportStaette)
&& Objects.equals(startTime, other.startTime) && Objects.equals(sumPrice, other.sumPrice);
}
}

@ -0,0 +1,12 @@
package de.kreth.invoice.persistence;
import java.util.List;
import org.springframework.data.repository.CrudRepository;
import de.kreth.invoice.data.SportArt;
public interface SportArtRepository extends CrudRepository<SportArt, Long> {
List<SportArt> findByUserId(long userId);
}

@ -0,0 +1,12 @@
package de.kreth.invoice.persistence;
import java.util.List;
import org.springframework.data.repository.CrudRepository;
import de.kreth.invoice.data.SportStaette;
public interface SportstaetteRepository extends CrudRepository<SportStaette, Long> {
List<SportStaette> findByUserId(long userId);
}

@ -35,6 +35,8 @@ public class InvoiceReportSource implements JRDataSource, JRDataSourceProvider {
public static final String FIELD_USER_ADRESS2 = "USER_ADRESS2";
public static final String FIELD_USER_ZIP = "USER_ZIPCODE";
public static final String FIELD_ITEM_SPORTART = "ITEM_SPORTART";
public static final String FIELD_ITEM_SPORTSTAETTE = "ITEM_SPORTSTAETTE";
public static final String FIELD_USER_CITY = "USER_CITY";
@ -69,10 +71,10 @@ public class InvoiceReportSource implements JRDataSource, JRDataSourceProvider {
private InvoiceItem currentItem;
private Article article;
public InvoiceReportSource() {
InvoiceReportSource() {
}
public void setInvoice(Invoice invoice) {
void setInvoice(Invoice invoice) {
this.invoice = invoice;
List<InvoiceItem> items = invoice.getItems();
items.sort(this::compare);
@ -148,6 +150,11 @@ public class InvoiceReportSource implements JRDataSource, JRDataSourceProvider {
return currentItem.getSumPrice();
case FIELD_ITEM_PARTICIPANTS:
return currentItem.getParticipants();
case FIELD_ITEM_SPORTART:
return currentItem.getSportArt() != null ? currentItem.getSportArt().getName() : "Trampolin";
case FIELD_ITEM_SPORTSTAETTE:
return currentItem.getSportStaette() != null ? currentItem.getSportStaette().getName()
: "IGS Roderbruch";
default:
break;
@ -171,8 +178,10 @@ public class InvoiceReportSource implements JRDataSource, JRDataSourceProvider {
return null;
}
public static JRDataSource getDataSource() {
return new InvoiceReportSource();
public static InvoiceReportSource create(Invoice invoice) {
InvoiceReportSource invoiceReportSource = new InvoiceReportSource();
invoiceReportSource.setInvoice(invoice);
return invoiceReportSource;
}
@Override

@ -34,6 +34,8 @@ import de.kreth.invoice.data.InvoiceItem;
import de.kreth.invoice.data.User;
import de.kreth.invoice.data.UserAdress;
import de.kreth.invoice.data.UserBank;
import de.kreth.invoice.persistence.SportArtRepository;
import de.kreth.invoice.persistence.SportstaetteRepository;
import de.kreth.invoice.security.UserManager;
import de.kreth.invoice.views.article.ArticleDialog;
import de.kreth.invoice.views.invoiceitem.InvoiceItemOverviewComponent;
@ -53,15 +55,21 @@ public class View extends VerticalLayout implements BeforeEnterObserver {
private User user;
private InvoiceBusiness invoiceRepository;
private InvoiceOverviewComponent invoiceCompoent;
private SportArtRepository sportArtRepository;
private SportstaetteRepository sportstaetteRepository;
public View(@Autowired UserManager userRepository,
@Autowired InvoiceItemBusiness invoiceItemRepository,
@Autowired InvoiceBusiness invoiceRepository,
@Autowired ArticleBusiness articleRepository) {
@Autowired ArticleBusiness articleRepository,
@Autowired SportArtRepository sportArtRepository,
@Autowired SportstaetteRepository sportstaetteRepository) {
this.userManager = userRepository;
this.invoiceItemBusiness = invoiceItemRepository;
this.invoiceRepository = invoiceRepository;
this.articleBusiness = articleRepository;
this.sportArtRepository = sportArtRepository;
this.sportstaetteRepository = sportstaetteRepository;
}
@Override
@ -156,7 +164,8 @@ public class View extends VerticalLayout implements BeforeEnterObserver {
FormLayout layout = new FormLayout(name, email, openDetailDialog, openArticleDialog);
add(layout);
invoiceItems = new InvoiceItemOverviewComponent(invoiceItemBusiness, articleBusiness, user);
invoiceItems = new InvoiceItemOverviewComponent(invoiceItemBusiness, articleBusiness, sportArtRepository,
sportstaetteRepository, user);
final List<InvoiceItem> itemsForInvoice = new ArrayList<>();
invoiceItems.addSeelctionListener(ev -> {

@ -245,8 +245,7 @@ public class InvoiceDialog extends Dialog {
}
private JasperPrint createJasperPrint() throws JRException {
InvoiceReportSource source = new InvoiceReportSource();
source.setInvoice(invoice);
InvoiceReportSource source = InvoiceReportSource.create(invoice);
JasperReport report = JasperCompileManager
.compileReport(getClass().getResourceAsStream(invoice.getReportRessource()));
return JasperFillManager.fillReport(report, new HashMap<>(), source);

@ -8,9 +8,12 @@ import java.util.List;
import com.vaadin.flow.component.ClickEvent;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.combobox.ComboBox;
import com.vaadin.flow.component.combobox.GeneratedVaadinComboBox.CustomValueSetEvent;
import com.vaadin.flow.component.datepicker.DatePicker;
import com.vaadin.flow.component.dialog.Dialog;
import com.vaadin.flow.component.dialog.GeneratedVaadinDialog.OpenedChangeEvent;
import com.vaadin.flow.component.formlayout.FormLayout;
import com.vaadin.flow.component.html.Label;
import com.vaadin.flow.component.orderedlayout.HorizontalLayout;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.component.timepicker.TimePicker;
@ -18,6 +21,10 @@ import com.vaadin.flow.data.provider.Query;
import de.kreth.invoice.data.Article;
import de.kreth.invoice.data.InvoiceItem;
import de.kreth.invoice.data.SportArt;
import de.kreth.invoice.data.SportStaette;
import de.kreth.invoice.persistence.SportArtRepository;
import de.kreth.invoice.persistence.SportstaetteRepository;
public class InvoiceItemDialog {
@ -27,17 +34,27 @@ public class InvoiceItemDialog {
private TimePicker startTime;
private TimePicker endTime;
private TextField participants;
private ComboBox<SportArt> sportart;
private ComboBox<SportStaette> sportstaette;
private boolean closedWithOk;
private DialogCloseListener listener;
private SportArtRepository sportarten;
private SportstaetteRepository sportstaetten;
private long userId;
public InvoiceItemDialog(InvoiceItem item, List<Article> articles, DialogCloseListener listener) {
this(articles, listener);
public InvoiceItemDialog(InvoiceItem item, List<Article> articles, SportArtRepository sportarten,
SportstaetteRepository sportstaetten, DialogCloseListener listener) {
this(articles, sportarten, sportstaetten, listener);
readFrom(item);
}
public InvoiceItemDialog(List<Article> articles, DialogCloseListener listener) {
public InvoiceItemDialog(List<Article> articles, SportArtRepository sportarten,
SportstaetteRepository sportstaetten,
DialogCloseListener listener) {
this.listener = listener;
this.sportarten = sportarten;
this.sportstaetten = sportstaetten;
this.startDate = new DatePicker(LocalDate.now());
startDate.setLabel("Datum");
this.startTime = new TimePicker(LocalTime.of(17, 0));
@ -48,14 +65,89 @@ public class InvoiceItemDialog {
article = new ComboBox<Article>("Artikel", articles);
article.setItemLabelGenerator(Article::getTitle);
this.userId = articles.get(0).getUserId();
sportart = new ComboBox<SportArt>("Sportart");
sportart.setItemLabelGenerator(SportArt::getName);
sportart.setAllowCustomValue(true);
sportart.addCustomValueSetListener(this::newCustomSportart);
sportstaette = new ComboBox<SportStaette>("Sportstätte");
sportstaette.setItemLabelGenerator(SportStaette::getName);
sportstaette.setAllowCustomValue(true);
sportstaette.addCustomValueSetListener(this::newCustomSportstaette);
Button ok = new Button("Speichern", this::closeWithOk);
Button discard = new Button("Abbrechen", ev -> dialog.close());
dialog.add(article, startDate, startTime, endTime, participants, new HorizontalLayout(ok, discard));
dialog.add(article, sportart, sportstaette, startDate, startTime, endTime, participants,
new HorizontalLayout(ok, discard));
dialog.addOpenedChangeListener(this::dialogCloseCalled);
}
private void newCustomSportstaette(CustomValueSetEvent<ComboBox<SportStaette>> event) {
Label text = new Label("Die Sportstätte wurde noch nie verwendet. Soll sie neu angelegt werden?");
Label t2 = new Label("Sportstätte: " + event.getDetail());
Button cancel = new Button("Abbrechen");
Button store = new Button("Speichern");
FormLayout buttonLayout = new FormLayout(store, cancel);
FormLayout dlgLayout = new FormLayout(text, t2, buttonLayout);
Dialog dlg = new Dialog();
dlg.add(dlgLayout);
cancel.addClickListener(e1 -> {
List<SportStaette> items = refreshSportstaetten();
if (!items.isEmpty()) {
sportstaette.setValue(items.get(0));
} else {
this.sportstaette.clear();
}
dlg.close();
});
store.addClickListener(e -> {
SportStaette sportStaette = new SportStaette();
sportStaette.setName(event.getDetail());
sportStaette.setUserId(article.getValue().getUserId());
sportStaette = sportstaetten.save(sportStaette);
refreshSportstaetten();
this.sportstaette.setValue(sportStaette);
dlg.close();
});
dlg.open();
}
private void newCustomSportart(CustomValueSetEvent<ComboBox<SportArt>> event) {
Label text = new Label("Die Sportart wurde noch nie verwendet. Soll sie neu angelegt werden?");
Label t2 = new Label("Sportart: " + event.getDetail());
Button cancel = new Button("Abbrechen");
Button store = new Button("Speichern");
FormLayout buttonLayout = new FormLayout(store, cancel);
FormLayout dlgLayout = new FormLayout(text, t2, buttonLayout);
Dialog dlg = new Dialog();
dlg.add(dlgLayout);
cancel.addClickListener(e1 -> {
List<SportArt> sportartItems = refreshSportarten();
if (!sportartItems.isEmpty()) {
sportart.setValue(sportartItems.get(0));
}
dlg.close();
});
store.addClickListener(e -> {
SportArt sportArt = new SportArt();
sportArt.setName(event.getDetail());
sportArt.setUserId(article.getValue().getUserId());
sportArt = sportarten.save(sportArt);
refreshSportarten();
this.sportart.setValue(sportArt);
dlg.close();
});
dlg.open();
}
private void dialogCloseCalled(OpenedChangeEvent<Dialog> ev) {
if (!ev.isOpened()) {
listener.dialogClosed(this);
@ -84,6 +176,7 @@ public class InvoiceItemDialog {
article.getDataProvider().fetch(new Query<>())
.findAny().ifPresent(article::setValue);
}
if (item.getStart() != null) {
startDate.setValue(item.getStart().toLocalDate());
startTime.setValue(item.getStart().toLocalTime());
@ -96,6 +189,39 @@ public class InvoiceItemDialog {
if (item.getParticipants() != null) {
this.participants.setValue(item.getParticipants());
}
refreshSportarten();
refreshSportstaetten();
if (item.getSportStaette() != null) {
sportstaette.setValue(item.getSportStaette());
}
if (item.getSportArt() != null) {
sportart.setValue(item.getSportArt());
}
}
private List<SportStaette> refreshSportstaetten() {
List<SportStaette> sportstaettenItems = sportstaetten.findByUserId(userId);
sportstaette.setItems(sportstaettenItems);
if (!sportstaettenItems.isEmpty()) {
sportstaette.setAutoOpen(false);
} else {
sportstaette.setAutoOpen(true);
}
return sportstaettenItems;
}
private List<SportArt> refreshSportarten() {
List<SportArt> sportartItems = sportarten.findByUserId(userId);
sportart.setItems(sportartItems);
if (!sportartItems.isEmpty()) {
sportart.setAutoOpen(true);
} else {
sportart.setAutoOpen(false);
}
return sportartItems;
}
public void writeTo(InvoiceItem item) {
@ -110,6 +236,8 @@ public class InvoiceItemDialog {
item.setStart(LocalDateTime.of(startDate.getValue(), startTime.getValue()));
item.setEnd(LocalDateTime.of(startDate.getValue(), endTime.getValue()));
item.setParticipants(participants.getValue());
item.setSportArt(sportart.getValue());
item.setSportStaette(sportstaette.getValue());
item.getSumPrice();
}

@ -31,6 +31,8 @@ import de.kreth.invoice.business.InvoiceItemBusiness;
import de.kreth.invoice.data.Article;
import de.kreth.invoice.data.InvoiceItem;
import de.kreth.invoice.data.User;
import de.kreth.invoice.persistence.SportArtRepository;
import de.kreth.invoice.persistence.SportstaetteRepository;
public class InvoiceItemOverviewComponent extends VerticalLayout {
@ -40,11 +42,16 @@ public class InvoiceItemOverviewComponent extends VerticalLayout {
private final ArticleBusiness articleRepository;
private final User user;
private final List<ItemSelectionChangeListener> selectListener;
private final SportArtRepository sportArtRepository;
private final SportstaetteRepository sportstaetteRepository;
public InvoiceItemOverviewComponent(InvoiceItemBusiness invoiceItemRepository,
ArticleBusiness articleRepository, User user) {
ArticleBusiness articleRepository, SportArtRepository sportArtRepository,
SportstaetteRepository sportstaetteRepository, User user) {
this.invoiceItemRepository = invoiceItemRepository;
this.articleRepository = articleRepository;
this.sportArtRepository = sportArtRepository;
this.sportstaetteRepository = sportstaetteRepository;
this.user = user;
this.selectListener = new ArrayList<>();
@ -126,20 +133,27 @@ public class InvoiceItemOverviewComponent extends VerticalLayout {
private void createNewitem(ClickEvent<Button> ev) {
InvoiceItem item = new InvoiceItem();
editItem(item);
}
private void editItem(InvoiceItem item) {
List<Article> articles = articleRepository.findByUserId(user.getId());
InvoiceItemDialog dialog = new InvoiceItemDialog(articles, dlg -> {
if (dlg.isClosedWithOk()) {
dlg.writeTo(item);
invoiceItemRepository.save(item);
refreshData();
}
});
dialog.readFrom(item);
dialog.setVisible();
if (!articles.isEmpty()) {
InvoiceItemDialog dialog = new InvoiceItemDialog(articles, sportArtRepository, sportstaetteRepository,
dlg -> {
if (dlg.isClosedWithOk()) {
dlg.writeTo(item);
invoiceItemRepository.save(item);
refreshData();
}
});
dialog.readFrom(item);
dialog.setVisible();
} else {
ConfirmDialog dlg = new ConfirmDialog("Fehler", "Es sind keine Artikel gespeichert. Bitte zuerst anlegen.",
"Abbrechen", ev -> {
});
dlg.open();
}
}
public List<InvoiceItem> getAllItems() {

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0 -->
<!-- Created with Jaspersoft Studio version 6.19.1.final using JasperReports Library version 6.19.1-867c00bf88cd4d784d404379d6c05e1b419e8a4c -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="mtv_gross_buchholz" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ba0e72ff-086d-4045-a69c-ff65b323c201">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="One Empty Record"/>
<property name="com.jaspersoft.studio.property.dataset.dialog.DatasetDialog.sash.w1" value="380"/>
@ -43,6 +43,12 @@
<field name="ITEM_SUM" class="java.math.BigDecimal">
<fieldDescription><![CDATA[Item Sum]]></fieldDescription>
</field>
<field name="ITEM_SPORTSTAETTE" class="java.lang.String">
<fieldDescription><![CDATA[Sportstätte]]></fieldDescription>
</field>
<field name="ITEM_SPORTART" class="java.lang.String">
<fieldDescription><![CDATA[Sportart]]></fieldDescription>
</field>
<field name="USER_ADRESS1" class="java.lang.String"/>
<field name="USER_ADRESS2" class="java.lang.String"/>
<field name="USER_ZIPCODE" class="java.lang.String"/>
@ -476,8 +482,8 @@ des Unterrichts]]></text>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{DURATION_PER_ITEM}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="151" y="0" width="90" height="15" uuid="7593911e-405a-49c4-89bc-4da3a4c53e7c"/>
<textField>
<reportElement x="151" y="0" width="90" height="15" uuid="db519b9d-f2ad-4fd2-be44-70b95fd3403f"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
@ -487,10 +493,10 @@ des Unterrichts]]></text>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="false"/>
</textElement>
<text><![CDATA[Trampolinturnen]]></text>
</staticText>
<staticText>
<reportElement x="241" y="0" width="88" height="15" uuid="13055bef-6718-4c0d-8060-dfb1f307654e"/>
<textFieldExpression><![CDATA[$F{ITEM_SPORTART}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="241" y="0" width="88" height="15" uuid="0d01356a-47d2-44ae-bc40-11597747315a"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
@ -500,8 +506,8 @@ des Unterrichts]]></text>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="false"/>
</textElement>
<text><![CDATA[IGS Roderbruch]]></text>
</staticText>
<textFieldExpression><![CDATA[$F{ITEM_SPORTSTAETTE}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="329" y="0" width="113" height="15" uuid="f92bf1eb-4dc0-4c56-b478-1559caa3d7e6">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="7141045b-35fa-4d89-bd0a-5dff9fe6e263"/>

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.6.0.final using JasperReports Library version 6.6.0 -->
<!-- Created with Jaspersoft Studio version 6.19.1.final using JasperReports Library version 6.19.1-867c00bf88cd4d784d404379d6c05e1b419e8a4c -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="mtv_gross_buchholz" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="ba0e72ff-086d-4045-a69c-ff65b323c201">
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Invoice2"/>
<property name="com.jaspersoft.studio.property.dataset.dialog.DatasetDialog.sash.w1" value="380"/>
@ -43,6 +43,12 @@
<field name="ITEM_SUM" class="java.math.BigDecimal">
<fieldDescription><![CDATA[Item Sum]]></fieldDescription>
</field>
<field name="ITEM_SPORTSTAETTE" class="java.lang.String">
<fieldDescription><![CDATA[Sportstätte]]></fieldDescription>
</field>
<field name="ITEM_SPORTART" class="java.lang.String">
<fieldDescription><![CDATA[Sportart]]></fieldDescription>
</field>
<field name="USER_ADRESS1" class="java.lang.String"/>
<field name="USER_ADRESS2" class="java.lang.String"/>
<field name="USER_ZIPCODE" class="java.lang.String"/>
@ -485,8 +491,8 @@ des Unterrichts]]></text>
<textElement textAlignment="Center" verticalAlignment="Middle"/>
<textFieldExpression><![CDATA[$V{DURATION_PER_ITEM}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="151" y="0" width="90" height="15" uuid="7593911e-405a-49c4-89bc-4da3a4c53e7c"/>
<textField isBlankWhenNull="true">
<reportElement x="151" y="0" width="90" height="15" uuid="86906a4a-444f-4bba-8998-23c12c7f30df"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
@ -496,10 +502,10 @@ des Unterrichts]]></text>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="false"/>
</textElement>
<text><![CDATA[Trampolinturnen]]></text>
</staticText>
<staticText>
<reportElement x="241" y="0" width="88" height="15" uuid="13055bef-6718-4c0d-8060-dfb1f307654e"/>
<textFieldExpression><![CDATA[$F{ITEM_SPORTART}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="241" y="0" width="88" height="15" uuid="54c00a5d-0c59-4c85-a1d0-9e10c0dc1e3b"/>
<box>
<topPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
<leftPen lineWidth="1.0" lineStyle="Solid" lineColor="#000000"/>
@ -509,8 +515,8 @@ des Unterrichts]]></text>
<textElement textAlignment="Center" verticalAlignment="Middle">
<font isBold="false"/>
</textElement>
<text><![CDATA[IGS Roderbruch]]></text>
</staticText>
<textFieldExpression><![CDATA[$F{ITEM_SPORTSTAETTE}]]></textFieldExpression>
</textField>
<textField>
<reportElement x="329" y="0" width="113" height="15" uuid="f92bf1eb-4dc0-4c56-b478-1559caa3d7e6">
<property name="com.jaspersoft.studio.spreadsheet.connectionID" value="7141045b-35fa-4d89-bd0a-5dff9fe6e263"/>

Loading…
Cancel
Save