|
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package id.amigogroup.posterminal.bayar;
-
- import id.amigogroup.posterminal.FormUtamaController;
- import id.amigogroup.posterminal.pencarian.DialogCariBarangController;
- import id.amigogroup.posterminal.pencarian.DialogCetakNotaController;
- import id.amigogroup.posterminal.util.AlertUtil;
- import id.amigogroup.posterminal.util.Fucout;
- import java.io.IOException;
- import java.net.URL;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- import java.util.Map;
- import java.util.Optional;
- import java.util.ResourceBundle;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javafx.application.Platform;
- import javafx.event.ActionEvent;
- import javafx.fxml.FXML;
- import javafx.fxml.FXMLLoader;
- import javafx.fxml.Initializable;
- import javafx.scene.Node;
- import javafx.scene.Parent;
- import javafx.scene.control.Alert;
- import javafx.scene.control.ButtonBar;
- import javafx.scene.control.ButtonType;
- import javafx.scene.control.CheckBox;
- import javafx.scene.control.Dialog;
- import javafx.scene.control.Label;
- import javafx.scene.input.KeyCode;
- import javafx.scene.input.KeyCodeCombination;
- import javafx.scene.input.KeyCombination;
- import javafx.scene.layout.AnchorPane;
- import javafx.scene.layout.VBox;
- import javafx.stage.Window;
-
- /**
- * FXML Controller class
- *
- * @author ronal
- */
- public class DialogSelesaiBayarTidakLunasController extends Dialog implements Initializable, BayarInterface {
-
- @FXML
- private AnchorPane apContent;
- @FXML
- private CheckBox chkTunai;
- @FXML
- private CheckBox chkKartu;
- @FXML
- private CheckBox chkPromo;
- @FXML
- private CheckBox chkRetur;
- @FXML
- private CheckBox chkGopay;
- @FXML
- private CheckBox chkOvo;
- @FXML
- private CheckBox chkPoin;
- @FXML
- private VBox vbContent;
- @FXML
- private Label lblPerluBayar;
-
- private BayarInterface parent;
- private int kurangBayar;
-
- private List<CheckBox> daftarChkBayarSyarat;
- private List<CheckBox> daftarChkBayarOpsional;
- public BayarContent bayarContent = new BayarContent();
- private FormUtamaController parentFormUtamaController = null;
-
- /**
- * Initializes the controller class.
- */
- @Override
- public void initialize(URL url, ResourceBundle rb) {
- daftarChkBayarSyarat.add(chkTunai);
- daftarChkBayarSyarat.add(chkKartu);
- daftarChkBayarOpsional.add(chkPromo);
- daftarChkBayarOpsional.add(chkRetur);
- daftarChkBayarOpsional.add(chkGopay);
- daftarChkBayarOpsional.add(chkOvo);
- daftarChkBayarOpsional.add(chkPoin);
- getDialogPane().getButtonTypes().add(new ButtonType("Tutup", ButtonBar.ButtonData.CANCEL_CLOSE));
- initShortcuts();
- }
-
- public void initData(FormUtamaController parent) {
- this.parentFormUtamaController = parent;
- }
-
- private void initShortcuts() {
- Map<KeyCombination, Runnable> listShortcuts = new HashMap<>();
-
- KeyCombination kcSelesaiBayar = new KeyCodeCombination(KeyCode.F10);
- Runnable rnSelesaiBayar = () -> {
- if (bayarContent.getTotalBayar() >= bayarContent.getTotalPerluBayar()) {
- if (parentFormUtamaController != null) {
- DialogCetakNotaController dialogCetakNotaController = new DialogCetakNotaController();
- dialogCetakNotaController.initOwner(parent.getWindow());
- dialogCetakNotaController.initData(
- parentFormUtamaController.notaContent.getControllerTunai() != null
- ? parentFormUtamaController.notaContent.getControllerTunai().daftarTabelTransaksi : null,
- parentFormUtamaController.notaContent.getControllerRetur() != null
- ? parentFormUtamaController.notaContent.getControllerRetur().daftarTabelRetur : null,
- this);
- Optional<String> result = dialogCetakNotaController.showAndWait();
- }
- } else {
- Alert alert = AlertUtil.getAlertWarning(
- AlertUtil.DIALOG_UANG_BELUM_CUKUP,
- "Nominal yang anda masukan masih kurang");
- alert.show();
- }
- };
- listShortcuts.put(kcSelesaiBayar, rnSelesaiBayar);
-
- Platform.runLater(() -> {
- apContent.getScene().getAccelerators().putAll(listShortcuts);
- });
- }
-
- public DialogSelesaiBayarTidakLunasController(BayarInterface parent, int kurangBayar) {
- this.daftarChkBayarSyarat = new ArrayList<>();
- this.daftarChkBayarOpsional = new ArrayList<>();
- this.parent = parent;
- bayarContent.setTotalPerluBayar(kurangBayar);
-
- try {
- Window window = getDialogPane().getScene().getWindow();
- window.setOnCloseRequest(event -> this.close());
-
- FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/DialogSelesaiBayarTidakLunas.fxml"));
- loader.setController(this);
- Parent root = loader.load();
- getDialogPane().setContent(root);
-
- setTitle("Pembayaran Belum Lunas!");
- lblPerluBayar.setText(Fucout.getTextColon(Fucout.formatRupiah(
- bayarContent.getTotalPerluBayar())));
- } catch (IOException e) {
- Logger.getLogger(DialogCariBarangController.class
- .getName()).log(Level.SEVERE, null, e);
- }
- }
-
- @FXML
- void chkPilihanOnAction(ActionEvent event) {
- CheckBox chkSource = (CheckBox) event.getSource();
- FXMLLoader loader = new FXMLLoader();
- Node node = null;
- try {
- switch (chkSource.getText()) {
- case FormBayarController.BAYAR_TUNAI:
- if (bayarContent.getNodeTunai() == null && chkSource.selectedProperty().get()) {
- loader.setLocation(getClass().getResource("/fxml/FormBayarTunai.fxml"));
- node = loader.load();
-
- FormBayarTunaiController fbtc = loader.getController();
- fbtc.initData(this);
- vbContent.getChildren().add(node);
- bayarContent.setNodeTunai(node);
- } else {
- if (bayarContent.getNodeTunai() != null) {
- vbContent.getChildren().remove(bayarContent.getNodeTunai());
- bayarContent.setNodeTunai(null);
- }
- }
- break;
- case FormBayarController.BAYAR_KARTU:
- if (bayarContent.getNodeKartu() == null && chkSource.selectedProperty().get()) {
- loader.setLocation(getClass().getResource("/fxml/FormBayarKartu.fxml"));
- node = loader.load();
-
- FormBayarKartuController fbkc = loader.getController();
- fbkc.initData(this);
- vbContent.getChildren().add(node);
- bayarContent.setNodeKartu(node);
- } else {
- if (bayarContent.getNodeKartu() != null) {
- vbContent.getChildren().remove(bayarContent.getNodeKartu());
- bayarContent.setNodeKartu(null);
- }
- }
- break;
- case FormBayarController.BAYAR_RETUR:
- if (bayarContent.getNodeRetur() == null && chkSource.selectedProperty().get()) {
- loader.setLocation(getClass().getResource("/fxml/FormBayarRetur.fxml"));
- node = loader.load();
-
- vbContent.getChildren().add(node);
- bayarContent.setNodeRetur(node);
- } else {
- if (bayarContent.getNodeRetur() != null) {
- vbContent.getChildren().remove(bayarContent.getNodeRetur());
- bayarContent.setNodeRetur(null);
- }
- }
- break;
- case FormBayarController.BAYAR_PROMO:
- if (bayarContent.getNodePromo() == null && chkSource.selectedProperty().get()) {
- loader.setLocation(getClass().getResource("/fxml/FormBayarVoucherPromo.fxml"));
- node = loader.load();
-
- vbContent.getChildren().add(node);
- bayarContent.setNodePromo(node);
- } else {
- if (bayarContent.getNodePromo() != null) {
- vbContent.getChildren().remove(bayarContent.getNodePromo());
- bayarContent.setNodePromo(null);
- }
- }
- break;
- case FormBayarController.BAYAR_GOPAY:
- break;
- case FormBayarController.BAYAR_OVO:
- break;
- case FormBayarController.BAYAR_POIN:
- if (bayarContent.getNodePoin() == null && chkSource.selectedProperty().get()) {
- loader.setLocation(getClass().getResource("/fxml/FormBayarPoin.fxml"));
- node = loader.load();
-
- vbContent.getChildren().add(node);
- bayarContent.setNodePoin(node);
- } else {
- if (bayarContent.getNodePoin() != null) {
- vbContent.getChildren().remove(bayarContent.getNodePoin());
- bayarContent.setNodePoin(null);
- }
- }
- break;
- }
-
- if (daftarChkBayarSyarat.contains(chkSource)) {
- chkSyaratValueOnChanged();
- }
- } catch (IOException ex) {
- Logger.getLogger(FormBayarController.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
-
- private void chkSyaratValueOnChanged() {
- boolean isSyaratTerpenuhi = false;
- for (CheckBox chkSyarat : daftarChkBayarSyarat) {
- if (chkSyarat.selectedProperty().get()) {
- isSyaratTerpenuhi = true;
- break;
- }
- }
-
- if (isSyaratTerpenuhi) {
- for (CheckBox chk : daftarChkBayarOpsional) {
- chk.setDisable(false);
- }
- } else {
- for (CheckBox chk : daftarChkBayarOpsional) {
- if (chk.selectedProperty().get()) {
- chk.fire();
- }
- chk.setDisable(true);
- }
- }
- }
-
- @Override
- public BayarContent getBayarContent() {
- return bayarContent;
- }
-
- @Override
- public void updateKurangBayarView() {
- lblPerluBayar.setText(Fucout.getTextColon(Fucout.formatRupiah(
- bayarContent.getTotalPerluBayar() - bayarContent.getTotalBayar())));
- }
-
- @Override
- public Window getWindow() {
- return apContent.getScene().getWindow();
- }
- }
|