Programm erstellt und bis zu 6.6 vorgearbeiet

master
athar 2024-06-30 20:26:08 +02:00
parent b75b3b09f1
commit d11cdf6f4c
26 changed files with 1361 additions and 2840 deletions

View File

@ -6,5 +6,6 @@
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="src" path="src"/> <classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/5"/>
<classpathentry kind="output" path="bin"/> <classpathentry kind="output" path="bin"/>
</classpath> </classpath>

View File

@ -1 +0,0 @@
1,Athar,Manager,A,2500.0

View File

@ -1,40 +0,0 @@
class Customer {
private int id;
private String name;
private String address;
private String contact;
private String segment;
public Customer(int id, String name, String address, String contact, String segment) {
this.id = id;
this.name = name;
this.address = address;
this.contact = contact;
this.segment = segment;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getAddress() {
return address;
}
public String getContact() {
return contact;
}
public String getSegment() {
return segment;
}
@Override
public String toString() {
return name;
}
}

View File

@ -1,18 +0,0 @@
import java.awt.BorderLayout;
import java.awt.Component;
import javax.swing.*;
class CustomerCellRenderer extends DefaultListCellRenderer {
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (component instanceof JLabel && value instanceof Customer) {
JLabel label = (JLabel) component;
Customer customer = (Customer) value;
label.setText(customer.getName());
}
return component;
}
}

View File

@ -1,21 +0,0 @@
import java.awt.*;
import javax.swing.*;
class EmployeeCellRenderer extends JLabel implements ListCellRenderer<Employee> {
@Override
public Component getListCellRendererComponent(JList<? extends Employee> list, Employee value, int index, boolean isSelected, boolean cellHasFocus) {
setText(value.getName() + " - " + value.getPosition());
if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
} else {
setBackground(list.getBackground());
setForeground(list.getForeground());
}
setEnabled(list.isEnabled());
setFont(list.getFont());
setOpaque(true);
return this;
}
}

View File

@ -1,81 +0,0 @@
import java.util.List;
import java.util.ArrayList;
class Employee {
private int id;
private String name;
private String position;
private String department;
private double salary;
private String employmentStatus;
private List<Vacation> vacations;
private List<Transfer> transfers;
private List<Termination> terminations;
public Employee(int id, String name, String position, String department, double salary) {
this.id = id;
this.name = name;
this.position = position;
this.department = department;
this.salary = salary;
this.employmentStatus = "Active";
this.vacations = new ArrayList<>();
this.transfers = new ArrayList<>();
this.terminations = new ArrayList<>();
}
// Getter und Setter
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getPosition() {
return position;
}
public String getDepartment() {
return department;
}
public double getSalary() {
return salary;
}
public String getEmploymentStatus() {
return employmentStatus;
}
public void setEmploymentStatus(String employmentStatus) {
this.employmentStatus = employmentStatus;
}
public List<Vacation> getVacations() {
return vacations;
}
public List<Transfer> getTransfers() {
return transfers;
}
public List<Termination> getTerminations() {
return terminations;
}
public void addVacation(Vacation vacation) {
vacations.add(vacation);
}
public void addTransfer(Transfer transfer) {
transfers.add(transfer);
}
public void addTermination(Termination termination) {
terminations.add(termination);
}
}

View File

@ -0,0 +1,350 @@
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();
}
});
}
}

View File

@ -0,0 +1,814 @@
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
public class Main {
static class Customer {
String name;
String address;
String contactPerson;
boolean taxExempt;
boolean smallBusiness;
Customer(String name, String address, String contactPerson, boolean taxExempt, boolean smallBusiness) {
this.name = name;
this.address = address;
this.contactPerson = contactPerson;
this.taxExempt = taxExempt;
this.smallBusiness = smallBusiness;
}
}
static class Article {
static int nextId = 1;
int id;
String unit;
String description;
double netPrice;
double vatRate;
Article(String unit, String description, double netPrice, double vatRate) {
this.id = nextId++;
this.unit = unit;
this.description = description;
this.netPrice = netPrice;
this.vatRate = vatRate;
}
}
static class Offer {
int id;
Customer customer;
List<Article> articles;
String date;
String status;
Offer(int id, Customer customer, List<Article> articles, String date, String status) {
this.id = id;
this.customer = customer;
this.articles = articles;
this.date = date;
this.status = status;
}
}
static class OrderConfirmation {
int id;
Offer offer;
String date;
String status;
OrderConfirmation(int id, Offer offer, String date, String status) {
this.id = id;
this.offer = offer;
this.date = date;
this.status = status;
}
}
static class DeliveryNote {
int id;
OrderConfirmation orderConfirmation;
String date;
String status;
DeliveryNote(int id, OrderConfirmation orderConfirmation, String date, String status) {
this.id = id;
this.orderConfirmation = orderConfirmation;
this.date = date;
this.status = status;
}
}
static class Invoice {
int id;
DeliveryNote deliveryNote;
String date;
String status;
Invoice(int id, DeliveryNote deliveryNote, String date, String status) {
this.id = id;
this.deliveryNote = deliveryNote;
this.date = date;
this.status = status;
}
}
static List<Customer> customers = new ArrayList<>();
static List<Article> articles = new ArrayList<>();
static List<Offer> offers = new ArrayList<>();
static List<OrderConfirmation> orderConfirmations = new ArrayList<>();
static List<DeliveryNote> deliveryNotes = new ArrayList<>();
static List<Invoice> invoices = new ArrayList<>();
private static Scanner scanner = new Scanner(System.in);
static int nextOfferId = 1;
static int nextOrderConfirmationId = 1;
static int nextDeliveryNoteId = 1;
static int nextInvoiceId = 1;
public static void main(String[] args) {
while (true) {
System.out.println("1. Kunde hinzufügen");
System.out.println("2. Kunden anzeigen");
System.out.println("3. Artikel hinzufügen");
System.out.println("4. Artikel anzeigen");
System.out.println("5. Angebot erstellen");
System.out.println("6. Angebote anzeigen");
System.out.println("7. Auftragsbestätigung erstellen");
System.out.println("8. Auftragsbestätigungen anzeigen");
System.out.println("9. Lieferschein erstellen");
System.out.println("10. Lieferscheine anzeigen");
System.out.println("11. Rechnung erstellen");
System.out.println("12. Rechnungen anzeigen");
System.out.println("13. Daten speichern");
System.out.println("14. Daten laden");
System.out.println("15. Beenden");
System.out.print("Wählen Sie eine Option: ");
int choice = scanner.nextInt();
scanner.nextLine(); // consume newline
switch (choice) {
case 1:
addCustomer();
break;
case 2:
displayCustomers();
break;
case 3:
addArticle();
break;
case 4:
displayArticles();
break;
case 5:
createOffer();
break;
case 6:
displayOffers();
break;
case 7:
createOrderConfirmation();
break;
case 8:
displayOrderConfirmations();
break;
case 9:
createDeliveryNote();
break;
case 10:
displayDeliveryNotes();
break;
case 11:
createInvoice();
break;
case 12:
displayInvoices();
break;
case 13:
saveData();
break;
case 14:
loadData();
break;
case 15:
System.exit(0);
break;
default:
System.out.println("Ungültige Option. Bitte versuchen Sie es erneut.");
}
}
}
private static void addCustomer() {
System.out.print("Kundenname: ");
String name = scanner.nextLine();
System.out.print("Adresse: ");
String address = scanner.nextLine();
System.out.print("Ansprechpartner: ");
String contactPerson = scanner.nextLine();
System.out.print("Fällt der Kunde unter § 4 Umsatzsteuergesetz (ja/nein): ");
boolean taxExempt = scanner.nextLine().equalsIgnoreCase("ja");
System.out.print("Kleinunternehmer (ja/nein): ");
boolean smallBusiness = scanner.nextLine().equalsIgnoreCase("ja");
customers.add(new Customer(name, address, contactPerson, taxExempt, smallBusiness));
}
private static void displayCustomers() {
if (customers.isEmpty()) {
System.out.println("Keine Kunden vorhanden.");
} else {
for (Customer customer : customers) {
System.out.println("Name: " + customer.name);
System.out.println("Adresse: " + customer.address);
System.out.println("Ansprechpartner: " + customer.contactPerson);
System.out.println("Unter § 4 UStG: " + (customer.taxExempt ? "Ja" : "Nein"));
System.out.println("Kleinunternehmer: " + (customer.smallBusiness ? "Ja" : "Nein"));
System.out.println();
}
}
}
private static void addArticle() {
System.out.print("Einheit: ");
String unit = scanner.nextLine();
System.out.print("Bezeichnung: ");
String description = scanner.nextLine();
System.out.print("Nettopreis: ");
double netPrice = scanner.nextDouble();
System.out.print("Mehrwertsteuersatz: ");
double vatRate = scanner.nextDouble();
scanner.nextLine(); // consume newline
articles.add(new Article(unit, description, netPrice, vatRate));
}
private static void displayArticles() {
if (articles.isEmpty()) {
System.out.println("Keine Artikel vorhanden.");
} else {
for (Article article : articles) {
System.out.println("Artikelnummer: " + article.id);
System.out.println("Einheit: " + article.unit);
System.out.println("Bezeichnung: " + article.description);
System.out.println("Nettopreis: " + article.netPrice);
System.out.println("Mehrwertsteuersatz: " + article.vatRate);
System.out.println();
}
}
}
private static void createOffer() {
if (customers.isEmpty() || articles.isEmpty()) {
System.out.println("Es müssen zuerst Kunden und Artikel angelegt werden.");
return;
}
System.out.println("Wählen Sie einen Kunden aus:");
for (int i = 0; i < customers.size(); i++) {
System.out.println((i + 1) + ". " + customers.get(i).name);
}
System.out.print("Kundennummer: ");
int customerIndex = scanner.nextInt() - 1;
scanner.nextLine(); // consume newline
if (customerIndex < 0 || customerIndex >= customers.size()) {
System.out.println("Ungültige Kundennummer.");
return;
}
Customer selectedCustomer = customers.get(customerIndex);
List<Article> selectedArticles = new ArrayList<>();
while (true) {
System.out.println("Wählen Sie einen Artikel aus (0 zum Beenden):");
for (int i = 0; i < articles.size(); i++) {
System.out.println((i + 1) + ". " + articles.get(i).description);
}
System.out.print("Artikelnummer: ");
int articleIndex = scanner.nextInt() - 1;
scanner.nextLine(); // consume newline
if (articleIndex == -1) break;
if (articleIndex < 0 || articleIndex >= articles.size()) {
System.out.println("Ungültige Artikelnummer.");
continue;
}
selectedArticles.add(articles.get(articleIndex));
}
System.out.print("Datum des Angebots (z.B. 2024-06-30): ");
String date = scanner.nextLine();
offers.add(new Offer(nextOfferId++, selectedCustomer, selectedArticles, date, "Angebot erstellt"));
System.out.println("Angebot erfolgreich erstellt.");
}
private static void displayOffers() {
if (offers.isEmpty()) {
System.out.println("Keine Angebote vorhanden.");
} else {
for (Offer offer : offers) {
System.out.println("Angebotsnummer: " + offer.id);
System.out.println("Kunde: " + offer.customer.name);
System.out.println("Datum: " + offer.date);
System.out.println("Status: " + offer.status);
System.out.println("Artikel:");
for (Article article : offer.articles) {
System.out.println("- " + article.description + " (Einheit: " + article.unit + ", Nettopreis: " + article.netPrice + ", MwSt.: " + article.vatRate + ")");
}
System.out.println();
}
}
}
private static void createOrderConfirmation() {
if (offers.isEmpty()) {
System.out.println("Es müssen zuerst Angebote erstellt werden.");
return;
}
System.out.println("Wählen Sie ein Angebot aus:");
for (int i = 0; i < offers.size(); i++) {
System.out.println((i + 1) + ". Angebot #" + offers.get(i).id + " - Kunde: " + offers.get(i).customer.name);
}
System.out.print("Angebotsnummer: ");
int offerIndex = scanner.nextInt() - 1;
scanner.nextLine(); // consume newline
if (offerIndex < 0 || offerIndex >= offers.size()) {
System.out.println("Ungültige Angebotsnummer.");
return;
}
Offer selectedOffer = offers.get(offerIndex);
System.out.print("Datum der Auftragsbestätigung (z.B. 2024-06-30): ");
String date = scanner.nextLine();
orderConfirmations.add(new OrderConfirmation(nextOrderConfirmationId++, selectedOffer, date, "Auftragsbestätigung erstellt"));
selectedOffer.status = "Auftragsbestätigung erstellt";
System.out.println("Auftragsbestätigung erfolgreich erstellt.");
}
private static void displayOrderConfirmations() {
if (orderConfirmations.isEmpty()) {
System.out.println("Keine Auftragsbestätigungen vorhanden.");
} else {
for (OrderConfirmation orderConfirmation : orderConfirmations) {
System.out.println("Auftragsbestätigungsnummer: " + orderConfirmation.id);
System.out.println("Angebotsnummer: " + orderConfirmation.offer.id);
System.out.println("Kunde: " + orderConfirmation.offer.customer.name);
System.out.println("Datum: " + orderConfirmation.date);
System.out.println("Status: " + orderConfirmation.status);
System.out.println();
}
}
}
private static void createDeliveryNote() {
if (orderConfirmations.isEmpty()) {
System.out.println("Es müssen zuerst Auftragsbestätigungen erstellt werden.");
return;
}
System.out.println("Wählen Sie eine Auftragsbestätigung aus:");
for (int i = 0; i < orderConfirmations.size(); i++) {
System.out.println((i + 1) + ". Auftragsbestätigung #" + orderConfirmations.get(i).id + " - Kunde: " + orderConfirmations.get(i).offer.customer.name);
}
System.out.print("Auftragsbestätigungsnummer: ");
int orderConfirmationIndex = scanner.nextInt() - 1;
scanner.nextLine(); // consume newline
if (orderConfirmationIndex < 0 || orderConfirmationIndex >= orderConfirmations.size()) {
System.out.println("Ungültige Auftragsbestätigungsnummer.");
return;
}
OrderConfirmation selectedOrderConfirmation = orderConfirmations.get(orderConfirmationIndex);
System.out.print("Datum des Lieferscheins (z.B. 2024-06-30): ");
String date = scanner.nextLine();
deliveryNotes.add(new DeliveryNote(nextDeliveryNoteId++, selectedOrderConfirmation, date, "Lieferschein erstellt"));
selectedOrderConfirmation.status = "Lieferschein erstellt";
selectedOrderConfirmation.offer.status = "Lieferschein erstellt";
System.out.println("Lieferschein erfolgreich erstellt.");
}
private static void displayDeliveryNotes() {
if (deliveryNotes.isEmpty()) {
System.out.println("Keine Lieferscheine vorhanden.");
} else {
for (DeliveryNote deliveryNote : deliveryNotes) {
System.out.println("Lieferscheinnummer: " + deliveryNote.id);
System.out.println("Auftragsbestätigungsnummer: " + deliveryNote.orderConfirmation.id);
System.out.println("Kunde: " + deliveryNote.orderConfirmation.offer.customer.name);
System.out.println("Datum: " + deliveryNote.date);
System.out.println("Status: " + deliveryNote.status);
System.out.println();
}
}
}
private static void createInvoice() {
if (deliveryNotes.isEmpty()) {
System.out.println("Es müssen zuerst Lieferscheine erstellt werden.");
return;
}
System.out.println("Wählen Sie einen Lieferschein aus:");
for (int i = 0; i < deliveryNotes.size(); i++) {
System.out.println((i + 1) + ". Lieferschein #" + deliveryNotes.get(i).id + " - Kunde: " + deliveryNotes.get(i).orderConfirmation.offer.customer.name);
}
System.out.print("Lieferscheinnummer: ");
int deliveryNoteIndex = scanner.nextInt() - 1;
scanner.nextLine(); // consume newline
if (deliveryNoteIndex < 0 || deliveryNoteIndex >= deliveryNotes.size()) {
System.out.println("Ungültige Lieferscheinnummer.");
return;
}
DeliveryNote selectedDeliveryNote = deliveryNotes.get(deliveryNoteIndex);
System.out.print("Datum der Rechnung (z.B. 2024-06-30): ");
String date = scanner.nextLine();
invoices.add(new Invoice(nextInvoiceId++, selectedDeliveryNote, date, "Rechnung erstellt"));
selectedDeliveryNote.status = "Rechnung erstellt";
selectedDeliveryNote.orderConfirmation.status = "Rechnung erstellt";
selectedDeliveryNote.orderConfirmation.offer.status = "Rechnung erstellt";
System.out.println("Rechnung erfolgreich erstellt.");
}
private static void displayInvoices() {
if (invoices.isEmpty()) {
System.out.println("Keine Rechnungen vorhanden.");
} else {
for (Invoice invoice : invoices) {
System.out.println("Rechnungsnummer: " + invoice.id);
System.out.println("Lieferscheinnummer: " + invoice.deliveryNote.id);
System.out.println("Kunde: " + invoice.deliveryNote.orderConfirmation.offer.customer.name);
System.out.println("Datum: " + invoice.date);
System.out.println("Status: " + invoice.status);
System.out.println();
}
}
}
static void saveData() {
try {
DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentFactory.newDocumentBuilder();
Document document = documentBuilder.newDocument();
Element root = document.createElement("Fakturama");
document.appendChild(root);
Element customersElement = document.createElement("Customers");
root.appendChild(customersElement);
for (Customer customer : customers) {
Element customerElement = document.createElement("Customer");
Element name = document.createElement("Name");
name.appendChild(document.createTextNode(customer.name));
customerElement.appendChild(name);
Element address = document.createElement("Address");
address.appendChild(document.createTextNode(customer.address));
customerElement.appendChild(address);
Element contactPerson = document.createElement("ContactPerson");
contactPerson.appendChild(document.createTextNode(customer.contactPerson));
customerElement.appendChild(contactPerson);
Element taxExempt = document.createElement("TaxExempt");
taxExempt.appendChild(document.createTextNode(Boolean.toString(customer.taxExempt)));
customerElement.appendChild(taxExempt);
Element smallBusiness = document.createElement("SmallBusiness");
smallBusiness.appendChild(document.createTextNode(Boolean.toString(customer.smallBusiness)));
customerElement.appendChild(smallBusiness);
customersElement.appendChild(customerElement);
}
Element articlesElement = document.createElement("Articles");
root.appendChild(articlesElement);
for (Article article : articles) {
Element articleElement = document.createElement("Article");
Element id = document.createElement("ID");
id.appendChild(document.createTextNode(Integer.toString(article.id)));
articleElement.appendChild(id);
Element unit = document.createElement("Unit");
unit.appendChild(document.createTextNode(article.unit));
articleElement.appendChild(unit);
Element description = document.createElement("Description");
description.appendChild(document.createTextNode(article.description));
articleElement.appendChild(description);
Element netPrice = document.createElement("NetPrice");
netPrice.appendChild(document.createTextNode(Double.toString(article.netPrice)));
articleElement.appendChild(netPrice);
Element vatRate = document.createElement("VatRate");
vatRate.appendChild(document.createTextNode(Double.toString(article.vatRate)));
articleElement.appendChild(vatRate);
articlesElement.appendChild(articleElement);
}
Element offersElement = document.createElement("Offers");
root.appendChild(offersElement);
for (Offer offer : offers) {
Element offerElement = document.createElement("Offer");
Element id = document.createElement("ID");
id.appendChild(document.createTextNode(Integer.toString(offer.id)));
offerElement.appendChild(id);
Element customerName = document.createElement("CustomerName");
customerName.appendChild(document.createTextNode(offer.customer.name));
offerElement.appendChild(customerName);
Element date = document.createElement("Date");
date.appendChild(document.createTextNode(offer.date));
offerElement.appendChild(date);
Element status = document.createElement("Status");
status.appendChild(document.createTextNode(offer.status));
offerElement.appendChild(status);
Element offerArticles = document.createElement("Articles");
offerElement.appendChild(offerArticles);
for (Article article : offer.articles) {
Element articleElement = document.createElement("Article");
Element articleId = document.createElement("ID");
articleId.appendChild(document.createTextNode(Integer.toString(article.id)));
articleElement.appendChild(articleId);
offerArticles.appendChild(articleElement);
}
offersElement.appendChild(offerElement);
}
Element orderConfirmationsElement = document.createElement("OrderConfirmations");
root.appendChild(orderConfirmationsElement);
for (OrderConfirmation orderConfirmation : orderConfirmations) {
Element orderConfirmationElement = document.createElement("OrderConfirmation");
Element id = document.createElement("ID");
id.appendChild(document.createTextNode(Integer.toString(orderConfirmation.id)));
orderConfirmationElement.appendChild(id);
Element offerId = document.createElement("OfferID");
offerId.appendChild(document.createTextNode(Integer.toString(orderConfirmation.offer.id)));
orderConfirmationElement.appendChild(offerId);
Element date = document.createElement("Date");
date.appendChild(document.createTextNode(orderConfirmation.date));
orderConfirmationElement.appendChild(date);
Element status = document.createElement("Status");
status.appendChild(document.createTextNode(orderConfirmation.status));
orderConfirmationElement.appendChild(status);
orderConfirmationsElement.appendChild(orderConfirmationElement);
}
Element deliveryNotesElement = document.createElement("DeliveryNotes");
root.appendChild(deliveryNotesElement);
for (DeliveryNote deliveryNote : deliveryNotes) {
Element deliveryNoteElement = document.createElement("DeliveryNote");
Element id = document.createElement("ID");
id.appendChild(document.createTextNode(Integer.toString(deliveryNote.id)));
deliveryNoteElement.appendChild(id);
Element orderConfirmationId = document.createElement("OrderConfirmationID");
orderConfirmationId.appendChild(document.createTextNode(Integer.toString(deliveryNote.orderConfirmation.id)));
deliveryNoteElement.appendChild(orderConfirmationId);
Element date = document.createElement("Date");
date.appendChild(document.createTextNode(deliveryNote.date));
deliveryNoteElement.appendChild(date);
Element status = document.createElement("Status");
status.appendChild(document.createTextNode(deliveryNote.status));
deliveryNoteElement.appendChild(status);
deliveryNotesElement.appendChild(deliveryNoteElement);
}
Element invoicesElement = document.createElement("Invoices");
root.appendChild(invoicesElement);
for (Invoice invoice : invoices) {
Element invoiceElement = document.createElement("Invoice");
Element id = document.createElement("ID");
id.appendChild(document.createTextNode(Integer.toString(invoice.id)));
invoiceElement.appendChild(id);
Element deliveryNoteId = document.createElement("DeliveryNoteID");
deliveryNoteId.appendChild(document.createTextNode(Integer.toString(invoice.deliveryNote.id)));
invoiceElement.appendChild(deliveryNoteId);
Element date = document.createElement("Date");
date.appendChild(document.createTextNode(invoice.date));
invoiceElement.appendChild(date);
Element status = document.createElement("Status");
status.appendChild(document.createTextNode(invoice.status));
invoiceElement.appendChild(status);
invoicesElement.appendChild(invoiceElement);
}
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
DOMSource domSource = new DOMSource(document);
StreamResult streamResult = new StreamResult("fakturama_data.xml");
transformer.transform(domSource, streamResult);
System.out.println("Daten erfolgreich gespeichert.");
} catch (Exception e) {
e.printStackTrace();
}
}
static void loadData() {
try {
File xmlFile = new File("fakturama_data.xml");
if (!xmlFile.exists()) {
System.out.println("Keine Daten zum Laden vorhanden.");
return;
}
DocumentBuilderFactory documentFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentFactory.newDocumentBuilder();
Document document = documentBuilder.parse(xmlFile);
document.getDocumentElement().normalize();
NodeList customerList = document.getElementsByTagName("Customer");
customers.clear(); // Vor dem Laden die aktuelle Liste leeren
for (int i = 0; i < customerList.getLength(); i++) {
Node customerNode = customerList.item(i);
if (customerNode.getNodeType() == Node.ELEMENT_NODE) {
Element customerElement = (Element) customerNode;
String name = customerElement.getElementsByTagName("Name").item(0).getTextContent();
String address = customerElement.getElementsByTagName("Address").item(0).getTextContent();
String contactPerson = customerElement.getElementsByTagName("ContactPerson").item(0).getTextContent();
boolean taxExempt = Boolean.parseBoolean(customerElement.getElementsByTagName("TaxExempt").item(0).getTextContent());
boolean smallBusiness = Boolean.parseBoolean(customerElement.getElementsByTagName("SmallBusiness").item(0).getTextContent());
customers.add(new Customer(name, address, contactPerson, taxExempt, smallBusiness));
}
}
NodeList articleList = document.getElementsByTagName("Article");
articles.clear(); // Vor dem Laden die aktuelle Liste leeren
for (int i = 0; i < articleList.getLength(); i++) {
Node articleNode = articleList.item(i);
if (articleNode.getNodeType() == Node.ELEMENT_NODE) {
Element articleElement = (Element) articleNode;
int id = Integer.parseInt(articleElement.getElementsByTagName("ID").item(0).getTextContent());
String unit = articleElement.getElementsByTagName("Unit").item(0).getTextContent();
String description = articleElement.getElementsByTagName("Description").item(0).getTextContent();
double netPrice = Double.parseDouble(articleElement.getElementsByTagName("NetPrice").item(0).getTextContent());
double vatRate = Double.parseDouble(articleElement.getElementsByTagName("VatRate").item(0).getTextContent());
Article article = new Article(unit, description, netPrice, vatRate);
article.id = id; // Set the ID explicitly
articles.add(article);
}
}
NodeList offerList = document.getElementsByTagName("Offer");
offers.clear(); // Vor dem Laden die aktuelle Liste leeren
for (int i = 0; i < offerList.getLength(); i++) {
Node offerNode = offerList.item(i);
if (offerNode.getNodeType() == Node.ELEMENT_NODE) {
Element offerElement = (Element) offerNode;
int id = Integer.parseInt(offerElement.getElementsByTagName("ID").item(0).getTextContent());
String customerName = offerElement.getElementsByTagName("CustomerName").item(0).getTextContent();
Customer offerCustomer = customers.stream().filter(c -> c.name.equals(customerName)).findFirst().orElse(null);
String date = offerElement.getElementsByTagName("Date").item(0).getTextContent();
String status = offerElement.getElementsByTagName("Status").item(0).getTextContent();
NodeList offerArticles = offerElement.getElementsByTagName("Article");
List<Article> offerArticleList = new ArrayList<>();
for (int j = 0; j < offerArticles.getLength(); j++) {
Node offerArticleNode = offerArticles.item(j);
if (offerArticleNode.getNodeType() == Node.ELEMENT_NODE) {
Element offerArticleElement = (Element) offerArticleNode;
int articleId = Integer.parseInt(offerArticleElement.getElementsByTagName("ID").item(0).getTextContent());
Article offerArticle = articles.stream().filter(a -> a.id == articleId).findFirst().orElse(null);
if (offerArticle != null) {
offerArticleList.add(offerArticle);
}
}
}
if (offerCustomer != null) {
offers.add(new Offer(id, offerCustomer, offerArticleList, date, status));
}
}
}
NodeList orderConfirmationList = document.getElementsByTagName("OrderConfirmation");
orderConfirmations.clear(); // Vor dem Laden die aktuelle Liste leeren
for (int i = 0; i < orderConfirmationList.getLength(); i++) {
Node orderConfirmationNode = orderConfirmationList.item(i);
if (orderConfirmationNode.getNodeType() == Node.ELEMENT_NODE) {
Element orderConfirmationElement = (Element) orderConfirmationNode;
int id = Integer.parseInt(orderConfirmationElement.getElementsByTagName("ID").item(0).getTextContent());
int offerId = Integer.parseInt(orderConfirmationElement.getElementsByTagName("OfferID").item(0).getTextContent());
Offer orderConfirmationOffer = offers.stream().filter(o -> o.id == offerId).findFirst().orElse(null);
String date = orderConfirmationElement.getElementsByTagName("Date").item(0).getTextContent();
String status = orderConfirmationElement.getElementsByTagName("Status").item(0).getTextContent();
if (orderConfirmationOffer != null) {
orderConfirmations.add(new OrderConfirmation(id, orderConfirmationOffer, date, status));
}
}
}
NodeList deliveryNoteList = document.getElementsByTagName("DeliveryNote");
deliveryNotes.clear(); // Vor dem Laden die aktuelle Liste leeren
for (int i = 0; i < deliveryNoteList.getLength(); i++) {
Node deliveryNoteNode = deliveryNoteList.item(i);
if (deliveryNoteNode.getNodeType() == Node.ELEMENT_NODE) {
Element deliveryNoteElement = (Element) deliveryNoteNode;
int id = Integer.parseInt(deliveryNoteElement.getElementsByTagName("ID").item(0).getTextContent());
int orderConfirmationId = Integer.parseInt(deliveryNoteElement.getElementsByTagName("OrderConfirmationID").item(0).getTextContent());
OrderConfirmation deliveryNoteOrderConfirmation = orderConfirmations.stream().filter(oc -> oc.id == orderConfirmationId).findFirst().orElse(null);
String date = deliveryNoteElement.getElementsByTagName("Date").item(0).getTextContent();
String status = deliveryNoteElement.getElementsByTagName("Status").item(0).getTextContent();
if (deliveryNoteOrderConfirmation != null) {
deliveryNotes.add(new DeliveryNote(id, deliveryNoteOrderConfirmation, date, status));
}
}
}
NodeList invoiceList = document.getElementsByTagName("Invoice");
invoices.clear(); // Vor dem Laden die aktuelle Liste leeren
for (int i = 0; i < invoiceList.getLength(); i++) {
Node invoiceNode = invoiceList.item(i);
if (invoiceNode.getNodeType() == Node.ELEMENT_NODE) {
Element invoiceElement = (Element) invoiceNode;
int id = Integer.parseInt(invoiceElement.getElementsByTagName("ID").item(0).getTextContent());
int deliveryNoteId = Integer.parseInt(invoiceElement.getElementsByTagName("DeliveryNoteID").item(0).getTextContent());
DeliveryNote invoiceDeliveryNote = deliveryNotes.stream().filter(dn -> dn.id == deliveryNoteId).findFirst().orElse(null);
String date = invoiceElement.getElementsByTagName("Date").item(0).getTextContent();
String status = invoiceElement.getElementsByTagName("Status").item(0).getTextContent();
if (invoiceDeliveryNote != null) {
invoices.add(new Invoice(id, invoiceDeliveryNote, date, status));
}
}
}
System.out.println("Daten erfolgreich geladen.");
} catch (Exception e) {
e.printStackTrace();
}
}
}

View File

@ -0,0 +1,127 @@
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.List;
public class MainTest {
@BeforeEach
public void setUp() {
Main.customers = new ArrayList<>();
Main.articles = new ArrayList<>();
Main.offers = new ArrayList<>();
Main.orderConfirmations = new ArrayList<>();
Main.deliveryNotes = new ArrayList<>();
Main.invoices = new ArrayList<>();
}
@Test
public void testAddCustomer() {
Main.customers.add(new Main.Customer("Test Kunde", "Test Adresse", "Test Kontakt", true, false));
assertEquals(1, Main.customers.size());
assertEquals("Test Kunde", Main.customers.get(0).name);
assertEquals("Test Adresse", Main.customers.get(0).address);
assertEquals("Test Kontakt", Main.customers.get(0).contactPerson);
assertTrue(Main.customers.get(0).taxExempt);
assertFalse(Main.customers.get(0).smallBusiness);
}
@Test
public void testAddArticle() {
Main.articles.add(new Main.Article("Stück", "Test Artikel", 100.0, 19.0));
assertEquals(1, Main.articles.size());
assertEquals("Stück", Main.articles.get(0).unit);
assertEquals("Test Artikel", Main.articles.get(0).description);
assertEquals(100.0, Main.articles.get(0).netPrice);
assertEquals(19.0, Main.articles.get(0).vatRate);
}
@Test
public void testCreateOffer() {
Main.Customer customer = new Main.Customer("Test Kunde", "Test Adresse", "Test Kontakt", true, false);
Main.customers.add(customer);
Main.Article article = new Main.Article("Stück", "Test Artikel", 100.0, 19.0);
Main.articles.add(article);
List<Main.Article> articles = new ArrayList<>();
articles.add(article);
Main.offers.add(new Main.Offer(1, customer, articles, "2024-06-30", "Angebot erstellt"));
assertEquals(1, Main.offers.size());
assertEquals(customer, Main.offers.get(0).customer);
assertEquals(1, Main.offers.get(0).articles.size());
assertEquals(article, Main.offers.get(0).articles.get(0));
assertEquals("2024-06-30", Main.offers.get(0).date);
assertEquals("Angebot erstellt", Main.offers.get(0).status);
}
@Test
public void testCreateOrderConfirmation() {
Main.Customer customer = new Main.Customer("Test Kunde", "Test Adresse", "Test Kontakt", true, false);
Main.customers.add(customer);
Main.Article article = new Main.Article("Stück", "Test Artikel", 100.0, 19.0);
Main.articles.add(article);
List<Main.Article> articles = new ArrayList<>();
articles.add(article);
Main.Offer offer = new Main.Offer(1, customer, articles, "2024-06-30", "Angebot erstellt");
Main.offers.add(offer);
Main.orderConfirmations.add(new Main.OrderConfirmation(1, offer, "2024-07-01", "Auftragsbestätigung erstellt"));
assertEquals(1, Main.orderConfirmations.size());
assertEquals(offer, Main.orderConfirmations.get(0).offer);
assertEquals("2024-07-01", Main.orderConfirmations.get(0).date);
assertEquals("Auftragsbestätigung erstellt", Main.orderConfirmations.get(0).status);
}
@Test
public void testCreateDeliveryNote() {
Main.Customer customer = new Main.Customer("Test Kunde", "Test Adresse", "Test Kontakt", true, false);
Main.customers.add(customer);
Main.Article article = new Main.Article("Stück", "Test Artikel", 100.0, 19.0);
Main.articles.add(article);
List<Main.Article> articles = new ArrayList<>();
articles.add(article);
Main.Offer offer = new Main.Offer(1, customer, articles, "2024-06-30", "Angebot erstellt");
Main.offers.add(offer);
Main.OrderConfirmation orderConfirmation = new Main.OrderConfirmation(1, offer, "2024-07-01", "Auftragsbestätigung erstellt");
Main.orderConfirmations.add(orderConfirmation);
Main.deliveryNotes.add(new Main.DeliveryNote(1, orderConfirmation, "2024-07-05", "Lieferschein erstellt"));
assertEquals(1, Main.deliveryNotes.size());
assertEquals(orderConfirmation, Main.deliveryNotes.get(0).orderConfirmation);
assertEquals("2024-07-05", Main.deliveryNotes.get(0).date);
assertEquals("Lieferschein erstellt", Main.deliveryNotes.get(0).status);
}
@Test
public void testCreateInvoice() {
Main.Customer customer = new Main.Customer("Test Kunde", "Test Adresse", "Test Kontakt", true, false);
Main.customers.add(customer);
Main.Article article = new Main.Article("Stück", "Test Artikel", 100.0, 19.0);
Main.articles.add(article);
List<Main.Article> articles = new ArrayList<>();
articles.add(article);
Main.Offer offer = new Main.Offer(1, customer, articles, "2024-06-30", "Angebot erstellt");
Main.offers.add(offer);
Main.OrderConfirmation orderConfirmation = new Main.OrderConfirmation(1, offer, "2024-07-01", "Auftragsbestätigung erstellt");
Main.orderConfirmations.add(orderConfirmation);
Main.DeliveryNote deliveryNote = new Main.DeliveryNote(1, orderConfirmation, "2024-07-05", "Lieferschein erstellt");
Main.deliveryNotes.add(deliveryNote);
Main.invoices.add(new Main.Invoice(1, deliveryNote, "2024-07-10", "Rechnung erstellt"));
assertEquals(1, Main.invoices.size());
assertEquals(deliveryNote, Main.invoices.get(0).deliveryNote);
assertEquals("2024-07-10", Main.invoices.get(0).date);
assertEquals("Rechnung erstellt", Main.invoices.get(0).status);
}
}

View File

@ -1,46 +0,0 @@
class Order {
private int id;
private String product;
private int quantity;
private String date;
private String deliveryDate;
private String status;
public Order(int id, String product, int quantity, String date, String deliveryDate, String status) {
this.id = id;
this.product = product;
this.quantity = quantity;
this.date = date;
this.deliveryDate = deliveryDate;
this.status = status;
}
public int getId() {
return id;
}
public String getProduct() {
return product;
}
public int getQuantity() {
return quantity;
}
public String getDate() {
return date;
}
public String getDeliveryDate() {
return deliveryDate;
}
public String getStatus() {
return status;
}
@Override
public String toString() {
return "Order " + id + " - " + product;
}
}

View File

@ -1,15 +0,0 @@
import java.awt.Component;
import javax.swing.*;
class OrderCellRenderer extends DefaultListCellRenderer {
@Override
public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
Component component = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
if (component instanceof JLabel && value instanceof Order) {
JLabel label = (JLabel) component;
Order order = (Order) value;
label.setText(order.getProduct());
}
return component;
}
}

View File

@ -1,82 +0,0 @@
class Product {
private int id;
private String itemNumber;
private String productName;
private String description;
private String category;
private int availableStock;
private int minimumStock;
private String storageLocation;
private double purchasePrice;
private double sellingPrice;
private String mainSupplier;
private String imagePath;
public Product(int id, String itemNumber, String productName, String description, String category, int availableStock, int minimumStock, String storageLocation, double purchasePrice, double sellingPrice, String mainSupplier, String imagePath) {
this.id = id;
this.itemNumber = itemNumber;
this.productName = productName;
this.description = description;
this.category = category;
this.availableStock = availableStock;
this.minimumStock = minimumStock;
this.storageLocation = storageLocation;
this.purchasePrice = purchasePrice;
this.sellingPrice = sellingPrice;
this.mainSupplier = mainSupplier;
this.imagePath = imagePath;
}
public int getId() {
return id;
}
public String getItemNumber() {
return itemNumber;
}
public String getProductName() {
return productName;
}
public String getDescription() {
return description;
}
public String getCategory() {
return category;
}
public int getAvailableStock() {
return availableStock;
}
public int getMinimumStock() {
return minimumStock;
}
public String getStorageLocation() {
return storageLocation;
}
public double getPurchasePrice() {
return purchasePrice;
}
public double getSellingPrice() {
return sellingPrice;
}
public String getMainSupplier() {
return mainSupplier;
}
public String getImagePath() {
return imagePath;
}
@Override
public String toString() {
return productName;
}
}

View File

@ -1,19 +0,0 @@
import java.awt.*;
import javax.swing.*;
class ProductCellRenderer extends JLabel implements ListCellRenderer<Product> {
@Override
public Component getListCellRendererComponent(JList<? extends Product> list, Product product, int index, boolean isSelected, boolean cellHasFocus) {
setText(product.getProductName());
setOpaque(true);
if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
} else {
setBackground(list.getBackground());
setForeground(list.getForeground());
}
return this;
}
}

View File

@ -1,52 +0,0 @@
class Supplier {
private int id;
private String name;
private String address;
private String contact;
private String contractDetails;
private String orderHistory;
private String qualityRating;
public Supplier(int id, String name, String address, String contact, String contractDetails, String orderHistory, String qualityRating) {
this.id = id;
this.name = name;
this.address = address;
this.contact = contact;
this.contractDetails = contractDetails;
this.orderHistory = orderHistory;
this.qualityRating = qualityRating;
}
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getAddress() {
return address;
}
public String getContact() {
return contact;
}
public String getContractDetails() {
return contractDetails;
}
public String getOrderHistory() {
return orderHistory;
}
public String getQualityRating() {
return qualityRating;
}
@Override
public String toString() {
return name;
}
}

View File

@ -1,18 +0,0 @@
import java.awt.*;
import javax.swing.*;
class SupplierCellRenderer extends JLabel implements ListCellRenderer<Supplier> {
@Override
public Component getListCellRendererComponent(JList<? extends Supplier> list, Supplier supplier, int index, boolean isSelected, boolean cellHasFocus) {
setText(supplier.getName());
setOpaque(true);
if (isSelected) {
setBackground(list.getSelectionBackground());
setForeground(list.getSelectionForeground());
} else {
setBackground(list.getBackground());
setForeground(list.getForeground());
}
return this;
}
}

View File

@ -1,25 +0,0 @@
class Termination {
private String date;
private String type;
private String reason;
public Termination(String date, String type, String reason) {
this.date = date;
this.type = type;
this.reason = reason;
}
// Getter und Setter
public String getDate() {
return date;
}
public String getType() {
return type;
}
public String getReason() {
return reason;
}
}

View File

@ -1,31 +0,0 @@
class Transfer {
private String date;
private String fromDepartment;
private String toDepartment;
private String reason;
public Transfer(String date, String fromDepartment, String toDepartment, String reason) {
this.date = date;
this.fromDepartment = fromDepartment;
this.toDepartment = toDepartment;
this.reason = reason;
}
// Getter und Setter
public String getDate() {
return date;
}
public String getFromDepartment() {
return fromDepartment;
}
public String getToDepartment() {
return toDepartment;
}
public String getReason() {
return reason;
}
}

View File

@ -1,29 +0,0 @@
class User {
private int id;
private String username;
private String password;
private String role;
public User(int id, String username, String password, String role) {
this.id = id;
this.username = username;
this.password = password;
this.role = role;
}
public int getId() {
return id;
}
public String getUsername() {
return username;
}
public String getPassword() {
return password;
}
public String getRole() {
return role;
}
}

View File

@ -1,25 +0,0 @@
class Vacation {
private String startDate;
private String endDate;
private String reason;
public Vacation(String startDate, String endDate, String reason) {
this.startDate = startDate;
this.endDate = endDate;
this.reason = reason;
}
// Getter und Setter
public String getStartDate() {
return startDate;
}
public String getEndDate() {
return endDate;
}
public String getReason() {
return reason;
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,69 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>fakturama</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- JUnit 5 dependencies -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.7.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.7.1</version>
<scope>test</scope>
</dependency>
<!-- JUnit Vintage Engine for running JUnit 3 and 4 tests -->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.7.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<!-- JaCoCo Maven Plugin -->
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- Maven Surefire Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<includes>
<include>**/MainTest.java</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,6 +0,0 @@
1,admin,admin123,Administrator
2,manager,manager123,Manager
3,user,user123,User
4,Abbas,12,Administrator
5,Abbas,12,Administrator
6,Athar,A,Administrator