351 lines
15 KiB
Java
351 lines
15 KiB
Java
import javax.swing.*;
|
|
import java.awt.*;
|
|
import java.awt.event.*;
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
public class FakturamaGUI {
|
|
private JFrame frame;
|
|
private JTextArea textArea;
|
|
|
|
public FakturamaGUI() {
|
|
initialize();
|
|
}
|
|
|
|
private void initialize() {
|
|
frame = new JFrame("Fakturama");
|
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
frame.setSize(800, 600);
|
|
frame.setLayout(new BorderLayout());
|
|
|
|
// Menüleiste
|
|
JMenuBar menuBar = new JMenuBar();
|
|
frame.setJMenuBar(menuBar);
|
|
|
|
JMenu menu = new JMenu("Optionen");
|
|
menuBar.add(menu);
|
|
|
|
JMenuItem addCustomerItem = new JMenuItem("Kunde hinzufügen");
|
|
menu.add(addCustomerItem);
|
|
addCustomerItem.addActionListener(e -> showAddCustomerPanel());
|
|
|
|
JMenuItem addArticleItem = new JMenuItem("Artikel hinzufügen");
|
|
menu.add(addArticleItem);
|
|
addArticleItem.addActionListener(e -> showAddArticlePanel());
|
|
|
|
JMenuItem createOfferItem = new JMenuItem("Angebot erstellen");
|
|
menu.add(createOfferItem);
|
|
createOfferItem.addActionListener(e -> showCreateOfferPanel());
|
|
|
|
JMenuItem createOrderConfirmationItem = new JMenuItem("Auftragsbestätigung erstellen");
|
|
menu.add(createOrderConfirmationItem);
|
|
createOrderConfirmationItem.addActionListener(e -> showCreateOrderConfirmationPanel());
|
|
|
|
JMenuItem createDeliveryNoteItem = new JMenuItem("Lieferschein erstellen");
|
|
menu.add(createDeliveryNoteItem);
|
|
createDeliveryNoteItem.addActionListener(e -> showCreateDeliveryNotePanel());
|
|
|
|
JMenuItem createInvoiceItem = new JMenuItem("Rechnung erstellen");
|
|
menu.add(createInvoiceItem);
|
|
createInvoiceItem.addActionListener(e -> showCreateInvoicePanel());
|
|
|
|
JMenuItem saveDataItem = new JMenuItem("Daten speichern");
|
|
menu.add(saveDataItem);
|
|
saveDataItem.addActionListener(e -> {
|
|
Main.saveData();
|
|
updateTextArea();
|
|
});
|
|
|
|
JMenuItem loadDataItem = new JMenuItem("Daten laden");
|
|
menu.add(loadDataItem);
|
|
loadDataItem.addActionListener(e -> {
|
|
Main.loadData();
|
|
updateTextArea();
|
|
});
|
|
|
|
JMenuItem exitItem = new JMenuItem("Beenden");
|
|
menu.add(exitItem);
|
|
exitItem.addActionListener(e -> System.exit(0));
|
|
|
|
textArea = new JTextArea();
|
|
textArea.setEditable(false);
|
|
JScrollPane scrollPane = new JScrollPane(textArea);
|
|
frame.add(scrollPane, BorderLayout.CENTER);
|
|
|
|
frame.setVisible(true);
|
|
updateTextArea();
|
|
}
|
|
|
|
private void showAddCustomerPanel() {
|
|
JPanel panel = new JPanel(new GridLayout(6, 2));
|
|
JLabel nameLabel = new JLabel("Name:");
|
|
JTextField nameField = new JTextField();
|
|
JLabel addressLabel = new JLabel("Adresse:");
|
|
JTextField addressField = new JTextField();
|
|
JLabel contactLabel = new JLabel("Ansprechpartner:");
|
|
JTextField contactField = new JTextField();
|
|
JLabel taxExemptLabel = new JLabel("Unter § 4 UStG:");
|
|
JCheckBox taxExemptBox = new JCheckBox();
|
|
JLabel smallBusinessLabel = new JLabel("Kleinunternehmer:");
|
|
JCheckBox smallBusinessBox = new JCheckBox();
|
|
|
|
JButton addButton = new JButton("Hinzufügen");
|
|
addButton.setBackground(new Color(144, 238, 144)); // Hellgrün
|
|
addButton.addActionListener(e -> {
|
|
String name = nameField.getText();
|
|
String address = addressField.getText();
|
|
String contactPerson = contactField.getText();
|
|
boolean taxExempt = taxExemptBox.isSelected();
|
|
boolean smallBusiness = smallBusinessBox.isSelected();
|
|
Main.customers.add(new Main.Customer(name, address, contactPerson, taxExempt, smallBusiness));
|
|
updateTextArea();
|
|
});
|
|
|
|
panel.add(nameLabel);
|
|
panel.add(nameField);
|
|
panel.add(addressLabel);
|
|
panel.add(addressField);
|
|
panel.add(contactLabel);
|
|
panel.add(contactField);
|
|
panel.add(taxExemptLabel);
|
|
panel.add(taxExemptBox);
|
|
panel.add(smallBusinessLabel);
|
|
panel.add(smallBusinessBox);
|
|
panel.add(new JLabel());
|
|
panel.add(addButton);
|
|
|
|
showPanel(panel);
|
|
}
|
|
|
|
private void showAddArticlePanel() {
|
|
JPanel panel = new JPanel(new GridLayout(5, 2));
|
|
JLabel unitLabel = new JLabel("Einheit:");
|
|
JTextField unitField = new JTextField();
|
|
JLabel descriptionLabel = new JLabel("Bezeichnung:");
|
|
JTextField descriptionField = new JTextField();
|
|
JLabel netPriceLabel = new JLabel("Nettopreis:");
|
|
JTextField netPriceField = new JTextField();
|
|
JLabel vatRateLabel = new JLabel("Mehrwertsteuersatz:");
|
|
JTextField vatRateField = new JTextField();
|
|
|
|
JButton addButton = new JButton("Hinzufügen");
|
|
addButton.setBackground(new Color(144, 238, 144)); // Hellgrün
|
|
addButton.addActionListener(e -> {
|
|
String unit = unitField.getText();
|
|
String description = descriptionField.getText();
|
|
double netPrice = Double.parseDouble(netPriceField.getText());
|
|
double vatRate = Double.parseDouble(vatRateField.getText());
|
|
Main.articles.add(new Main.Article(unit, description, netPrice, vatRate));
|
|
updateTextArea();
|
|
});
|
|
|
|
panel.add(unitLabel);
|
|
panel.add(unitField);
|
|
panel.add(descriptionLabel);
|
|
panel.add(descriptionField);
|
|
panel.add(netPriceLabel);
|
|
panel.add(netPriceField);
|
|
panel.add(vatRateLabel);
|
|
panel.add(vatRateField);
|
|
panel.add(new JLabel());
|
|
panel.add(addButton);
|
|
|
|
showPanel(panel);
|
|
}
|
|
|
|
private void showCreateOfferPanel() {
|
|
JPanel panel = new JPanel(new BorderLayout());
|
|
JPanel formPanel = new JPanel(new GridLayout(4, 2));
|
|
|
|
JLabel customerLabel = new JLabel("Kunde:");
|
|
JComboBox<String> customerBox = new JComboBox<>();
|
|
for (Main.Customer customer : Main.customers) {
|
|
customerBox.addItem(customer.name);
|
|
}
|
|
|
|
JLabel articlesLabel = new JLabel("Artikel:");
|
|
JList<String> articlesList = new JList<>(Main.articles.stream().map(a -> a.description).toArray(String[]::new));
|
|
articlesList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
|
JScrollPane articlesScrollPane = new JScrollPane(articlesList);
|
|
|
|
JLabel dateLabel = new JLabel("Datum:");
|
|
JTextField dateField = new JTextField();
|
|
|
|
formPanel.add(customerLabel);
|
|
formPanel.add(customerBox);
|
|
formPanel.add(dateLabel);
|
|
formPanel.add(dateField);
|
|
|
|
JButton addButton = new JButton("Erstellen");
|
|
addButton.setBackground(new Color(144, 238, 144)); // Hellgrün
|
|
addButton.addActionListener(e -> {
|
|
String customerName = (String) customerBox.getSelectedItem();
|
|
Main.Customer customer = Main.customers.stream().filter(c -> c.name.equals(customerName)).findFirst().orElse(null);
|
|
List<Main.Article> selectedArticles = new ArrayList<>();
|
|
for (String articleDesc : articlesList.getSelectedValuesList()) {
|
|
Main.Article article = Main.articles.stream().filter(a -> a.description.equals(articleDesc)).findFirst().orElse(null);
|
|
selectedArticles.add(article);
|
|
}
|
|
String date = dateField.getText();
|
|
Main.offers.add(new Main.Offer(Main.nextOfferId++, customer, selectedArticles, date, "Angebot erstellt"));
|
|
updateTextArea();
|
|
});
|
|
|
|
panel.add(formPanel, BorderLayout.NORTH);
|
|
panel.add(new JLabel("Artikel auswählen:"), BorderLayout.CENTER);
|
|
panel.add(articlesScrollPane, BorderLayout.CENTER);
|
|
panel.add(addButton, BorderLayout.SOUTH);
|
|
|
|
showPanel(panel);
|
|
}
|
|
|
|
private void showCreateOrderConfirmationPanel() {
|
|
JPanel panel = new JPanel(new GridLayout(4, 2));
|
|
JLabel offerLabel = new JLabel("Angebot:");
|
|
JComboBox<String> offerBox = new JComboBox<>();
|
|
for (Main.Offer offer : Main.offers) {
|
|
offerBox.addItem("Angebot #" + offer.id + " - Kunde: " + offer.customer.name);
|
|
}
|
|
|
|
JLabel dateLabel = new JLabel("Datum:");
|
|
JTextField dateField = new JTextField();
|
|
|
|
JButton addButton = new JButton("Erstellen");
|
|
addButton.setBackground(new Color(144, 238, 144)); // Hellgrün
|
|
addButton.addActionListener(e -> {
|
|
int offerIndex = offerBox.getSelectedIndex();
|
|
Main.Offer selectedOffer = Main.offers.get(offerIndex);
|
|
String date = dateField.getText();
|
|
Main.orderConfirmations.add(new Main.OrderConfirmation(Main.nextOrderConfirmationId++, selectedOffer, date, "Auftragsbestätigung erstellt"));
|
|
selectedOffer.status = "Auftragsbestätigung erstellt";
|
|
updateTextArea();
|
|
});
|
|
|
|
panel.add(offerLabel);
|
|
panel.add(offerBox);
|
|
panel.add(dateLabel);
|
|
panel.add(dateField);
|
|
panel.add(new JLabel());
|
|
panel.add(addButton);
|
|
|
|
showPanel(panel);
|
|
}
|
|
|
|
private void showCreateDeliveryNotePanel() {
|
|
JPanel panel = new JPanel(new GridLayout(4, 2));
|
|
JLabel orderConfirmationLabel = new JLabel("Auftragsbestätigung:");
|
|
JComboBox<String> orderConfirmationBox = new JComboBox<>();
|
|
for (Main.OrderConfirmation orderConfirmation : Main.orderConfirmations) {
|
|
orderConfirmationBox.addItem("Auftragsbestätigung #" + orderConfirmation.id + " - Kunde: " + orderConfirmation.offer.customer.name);
|
|
}
|
|
|
|
JLabel dateLabel = new JLabel("Datum:");
|
|
JTextField dateField = new JTextField();
|
|
|
|
JButton addButton = new JButton("Erstellen");
|
|
addButton.setBackground(new Color(144, 238, 144)); // Hellgrün
|
|
addButton.addActionListener(e -> {
|
|
int orderConfirmationIndex = orderConfirmationBox.getSelectedIndex();
|
|
Main.OrderConfirmation selectedOrderConfirmation = Main.orderConfirmations.get(orderConfirmationIndex);
|
|
String date = dateField.getText();
|
|
Main.deliveryNotes.add(new Main.DeliveryNote(Main.nextDeliveryNoteId++, selectedOrderConfirmation, date, "Lieferschein erstellt"));
|
|
selectedOrderConfirmation.status = "Lieferschein erstellt";
|
|
selectedOrderConfirmation.offer.status = "Lieferschein erstellt";
|
|
updateTextArea();
|
|
});
|
|
|
|
panel.add(orderConfirmationLabel);
|
|
panel.add(orderConfirmationBox);
|
|
panel.add(dateLabel);
|
|
panel.add(dateField);
|
|
panel.add(new JLabel());
|
|
panel.add(addButton);
|
|
|
|
showPanel(panel);
|
|
}
|
|
|
|
private void showCreateInvoicePanel() {
|
|
JPanel panel = new JPanel(new GridLayout(4, 2));
|
|
JLabel deliveryNoteLabel = new JLabel("Lieferschein:");
|
|
JComboBox<String> deliveryNoteBox = new JComboBox<>();
|
|
for (Main.DeliveryNote deliveryNote : Main.deliveryNotes) {
|
|
deliveryNoteBox.addItem("Lieferschein #" + deliveryNote.id + " - Kunde: " + deliveryNote.orderConfirmation.offer.customer.name);
|
|
}
|
|
|
|
JLabel dateLabel = new JLabel("Datum:");
|
|
JTextField dateField = new JTextField();
|
|
|
|
JButton addButton = new JButton("Erstellen");
|
|
addButton.setBackground(new Color(144, 238, 144)); // Hellgrün
|
|
addButton.addActionListener(e -> {
|
|
int deliveryNoteIndex = deliveryNoteBox.getSelectedIndex();
|
|
Main.DeliveryNote selectedDeliveryNote = Main.deliveryNotes.get(deliveryNoteIndex);
|
|
String date = dateField.getText();
|
|
Main.invoices.add(new Main.Invoice(Main.nextInvoiceId++, selectedDeliveryNote, date, "Rechnung erstellt"));
|
|
selectedDeliveryNote.status = "Rechnung erstellt";
|
|
selectedDeliveryNote.orderConfirmation.status = "Rechnung erstellt";
|
|
selectedDeliveryNote.orderConfirmation.offer.status = "Rechnung erstellt";
|
|
updateTextArea();
|
|
});
|
|
|
|
panel.add(deliveryNoteLabel);
|
|
panel.add(deliveryNoteBox);
|
|
panel.add(dateLabel);
|
|
panel.add(dateField);
|
|
panel.add(new JLabel());
|
|
panel.add(addButton);
|
|
|
|
showPanel(panel);
|
|
}
|
|
|
|
private void showPanel(JPanel panel) {
|
|
frame.getContentPane().removeAll();
|
|
frame.getContentPane().add(panel, BorderLayout.NORTH);
|
|
frame.revalidate();
|
|
frame.repaint();
|
|
}
|
|
|
|
private void updateTextArea() {
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append("Kunden:\n");
|
|
for (Main.Customer customer : Main.customers) {
|
|
sb.append(customer.name).append(" - ").append(customer.address).append(" - ").append(customer.contactPerson).append(" - ").append(customer.taxExempt ? "§ 4 UStG" : "").append(" - ").append(customer.smallBusiness ? "Kleinunternehmer" : "").append("\n");
|
|
}
|
|
sb.append("\nArtikel:\n");
|
|
for (Main.Article article : Main.articles) {
|
|
sb.append(article.description).append(" - ").append(article.unit).append(" - ").append(article.netPrice).append(" € - ").append(article.vatRate).append(" %").append("\n");
|
|
}
|
|
sb.append("\nAngebote:\n");
|
|
for (Main.Offer offer : Main.offers) {
|
|
sb.append("Angebot #").append(offer.id).append(" - ").append(offer.customer.name).append(" - ").append(offer.date).append(" - ").append(offer.status).append("\n");
|
|
for (Main.Article article : offer.articles) {
|
|
sb.append(" ").append(article.description).append(" - ").append(article.unit).append(" - ").append(article.netPrice).append(" € - ").append(article.vatRate).append(" %").append("\n");
|
|
}
|
|
}
|
|
sb.append("\nAuftragsbestätigungen:\n");
|
|
for (Main.OrderConfirmation orderConfirmation : Main.orderConfirmations) {
|
|
sb.append("Auftragsbestätigung #").append(orderConfirmation.id).append(" - ").append(orderConfirmation.offer.customer.name).append(" - ").append(orderConfirmation.date).append(" - ").append(orderConfirmation.status).append("\n");
|
|
}
|
|
sb.append("\nLieferscheine:\n");
|
|
for (Main.DeliveryNote deliveryNote : Main.deliveryNotes) {
|
|
sb.append("Lieferschein #").append(deliveryNote.id).append(" - ").append(deliveryNote.orderConfirmation.offer.customer.name).append(" - ").append(deliveryNote.date).append(" - ").append(deliveryNote.status).append("\n");
|
|
}
|
|
sb.append("\nRechnungen:\n");
|
|
for (Main.Invoice invoice : Main.invoices) {
|
|
sb.append("Rechnung #").append(invoice.id).append(" - ").append(invoice.deliveryNote.orderConfirmation.offer.customer.name).append(" - ").append(invoice.date).append(" - ").append(invoice.status).append("\n");
|
|
}
|
|
textArea.setText(sb.toString());
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
EventQueue.invokeLater(() -> {
|
|
try {
|
|
FakturamaGUI window = new FakturamaGUI();
|
|
window.frame.setVisible(true);
|
|
} catch (Exception e) {
|
|
e.printStackTrace();
|
|
}
|
|
});
|
|
}
|
|
}
|