package fi.lpam.gui; import fi.lpam.dataluokat.RaporttiRivi; import fi.lpam.tulostajat.KuljetusRaporttiTulostaja; import fi.lpam.gui.tableCell.PaivamaaraTableCell; import fi.lpam.gui.elementit.TabPohja; import javafx.collections.FXCollections; import javafx.geometry.Pos; import javafx.scene.control.*; import javafx.scene.control.cell.PropertyValueFactory; import javafx.scene.layout.BorderPane; import javafx.scene.layout.HBox; import java.time.LocalDate; import java.util.ArrayList; import java.util.Objects; @SuppressWarnings("unchecked") public class KuljetusRaportit extends TabPohja { private final TableView tableView = new TableView<>(); private final DatePicker alkuPvm, loppuPvm; private ArrayList raportti; private final CheckBox tarkka; void haeRaportti() { raportti = RaporttiRivi.haeRaportti(alkuPvm.getValue(), loppuPvm.getValue(), tarkka.isSelected()); tableView.setItems(FXCollections.observableArrayList(Objects.requireNonNull(raportti))); tableView.refresh(); } void tulostaRaportti() { new KuljetusRaporttiTulostaja().luoRaportti(raportti, alkuPvm.getValue(), loppuPvm.getValue()); } public KuljetusRaportit() { BorderPane root = new BorderPane(); root.setPadding(oletusInsets); this.getChildren().add(root); BorderPane yläpalkki = new BorderPane(); root.setTop(yläpalkki); Label infoTeksti = new Label("Kuljetusraportit. \nTarkka-valinnalla koostetun raportin tulostaminen paperille ei suositeltua."); infoTeksti.setFont(tekstiFont); yläpalkki.setLeft(infoTeksti); HBox yläpalkinNapit = new HBox(); yläpalkinNapit.setAlignment(Pos.CENTER); yläpalkinNapit.setSpacing(5); yläpalkki.setRight(yläpalkinNapit); tarkka = new CheckBox("Tarkka"); alkuPvm = new DatePicker(LocalDate.now().minusDays(LocalDate.now().getDayOfMonth() - 1)); loppuPvm = new DatePicker(LocalDate.now()); Button haeKuljetukset = new Button("Hae"); haeKuljetukset.setFont(buttonFont); haeKuljetukset.setOnAction(_ ->haeRaportti()); Button tulostaRaportti = new Button("Tulosta raportti"); tulostaRaportti.setFont(buttonFont); tulostaRaportti.setOnAction(_ ->tulostaRaportti()); yläpalkinNapit.getChildren().addAll(tarkka, new Label("Hae kuljetukset välillä:"), alkuPvm, new Label("-"), loppuPvm, haeKuljetukset, tulostaRaportti); root.setCenter(tableView); TableColumn tcNimi = new TableColumn<>("Nimi"); tcNimi.setMinWidth(200); tcNimi.setCellValueFactory(new PropertyValueFactory<>("nimi")); TableColumn tcPvm = new TableColumn<>("Päivämäärä"); tcPvm.setMinWidth(150); tcPvm.setCellFactory(_ ->new PaivamaaraTableCell()); tcPvm.setCellValueFactory(new PropertyValueFactory<>("pvm")); TableColumn tcSalaatit = new TableColumn<>("Salaatit"); tcSalaatit.setMinWidth(100); tcSalaatit.setCellValueFactory(new PropertyValueFactory<>("salaatit")); TableColumn tcPääruoat = new TableColumn<>("Pääruoat"); tcPääruoat.setMinWidth(100); tcPääruoat.setCellValueFactory(new PropertyValueFactory<>("pääruoat")); TableColumn tcJälkiruoat = new TableColumn<>("Jälkiruoat"); tcJälkiruoat.setMinWidth(100); tcJälkiruoat.setCellValueFactory(new PropertyValueFactory<>("jälkiruoat")); TableColumn tcLisätiedot = new TableColumn<>("Lisätiedot"); tcLisätiedot.setMinWidth(300); tcLisätiedot.setCellValueFactory(new PropertyValueFactory<>("lisätiedot")); TableColumn tcYhteyshenkilönNimi = new TableColumn<>("Yhteyshenkilön nimi"); tcYhteyshenkilönNimi.setMinWidth(200); tcYhteyshenkilönNimi.setCellValueFactory(new PropertyValueFactory<>("yhteyshenkilönNimi")); TableColumn tcLaskutusOsoite = new TableColumn<>("Laskutusosoite"); tcLaskutusOsoite.setMinWidth(200); tcLaskutusOsoite.setCellValueFactory(new PropertyValueFactory<>("laskutusOsoite")); TableColumn tcYhteyshenkilönPuhelinnumero = new TableColumn<>("Puhelinnumero"); tcYhteyshenkilönPuhelinnumero.setMinWidth(200); tcYhteyshenkilönPuhelinnumero.setCellValueFactory(new PropertyValueFactory<>("yhteyshenkilönPuhelinnumero")); TableColumn tcYhteyshenkilönSähköposti = new TableColumn<>("Sähköposti"); tcYhteyshenkilönSähköposti.setMinWidth(200); tcYhteyshenkilönSähköposti.setCellValueFactory(new PropertyValueFactory<>("yhteyshenkilönSähköposti")); tableView.getColumns().addAll(tcNimi, tcPvm, tcSalaatit, tcPääruoat, tcJälkiruoat, tcLisätiedot, tcYhteyshenkilönNimi, tcLaskutusOsoite, tcYhteyshenkilönPuhelinnumero, tcYhteyshenkilönSähköposti); tableView.setPlaceholder(new Label("Hae raportti")); for (TableColumn sarake : tableView.getColumns()) { sarake.setSortable(false); sarake.setEditable(false); sarake.setResizable(true); sarake.setStyle("-fx-alignment: CENTER; -fx-font-size: 16px;"); } } }