212738ce83
Signed-off-by: laurimaaninka <lauri.maaninka@gmail.com>
100 lines
4.3 KiB
Java
100 lines
4.3 KiB
Java
package fi.lpam.ruokamanageri.gui;
|
|
|
|
import fi.lpam.ruokamanageri.dataluokat.RaporttiRivi;
|
|
import fi.lpam.ruokamanageri.tulostajat.KuljetusRaporttiTulostaja;
|
|
import fi.lpam.ruokamanageri.gui.elementit.PaivamaaraTableCell;
|
|
import fi.lpam.ruokamanageri.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<RaporttiRivi> tableView = new TableView<>();
|
|
private final DatePicker alkuPvm, loppuPvm;
|
|
private ArrayList<RaporttiRivi> 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<RaporttiRivi, String> tcNimi = new TableColumn<>("Nimi");
|
|
tcNimi.setMinWidth(150);
|
|
tcNimi.setCellValueFactory(new PropertyValueFactory<>("nimi"));
|
|
|
|
TableColumn<RaporttiRivi, LocalDate> tcPvm = new TableColumn<>("Päivämäärä");
|
|
tcPvm.setMinWidth(150);
|
|
tcPvm.setCellFactory(_ ->new PaivamaaraTableCell());
|
|
tcPvm.setCellValueFactory(new PropertyValueFactory<>("loppuPvm"));
|
|
|
|
TableColumn<RaporttiRivi, Integer> tcSalaatit = new TableColumn<>("Salaatit");
|
|
tcSalaatit.setMinWidth(100);
|
|
tcSalaatit.setCellValueFactory(new PropertyValueFactory<>("salaatit"));
|
|
|
|
TableColumn<RaporttiRivi, Integer> tcPääruoat = new TableColumn<>("Pääruoat");
|
|
tcPääruoat.setMinWidth(100);
|
|
tcPääruoat.setCellValueFactory(new PropertyValueFactory<>("pääruoat"));
|
|
|
|
TableColumn<RaporttiRivi, Integer> tcJälkiruoat = new TableColumn<>("Jälkiruoat");
|
|
tcJälkiruoat.setMinWidth(100);
|
|
tcJälkiruoat.setCellValueFactory(new PropertyValueFactory<>("jälkiruoat"));
|
|
|
|
TableColumn<RaporttiRivi, String> tcLisätiedot = new TableColumn<>("Lisätiedot");
|
|
tcLisätiedot.setMinWidth(500);
|
|
tcLisätiedot.setCellValueFactory(new PropertyValueFactory<>("lisätiedot"));
|
|
|
|
tableView.getColumns().addAll(tcNimi, tcPvm, tcSalaatit, tcPääruoat, tcJälkiruoat, tcLisätiedot);
|
|
tableView.setPlaceholder(new Label("Hae raportti"));
|
|
for (TableColumn<RaporttiRivi, ?> sarake : tableView.getColumns()) {
|
|
sarake.setSortable(false);
|
|
sarake.setEditable(false);
|
|
sarake.setResizable(true);
|
|
sarake.setStyle("-fx-alignment: CENTER; -fx-font-size: 16px;");
|
|
}
|
|
}
|
|
} |