/* * 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.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.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.control.CheckBox; 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; /** * FXML Controller class * * @author ronal */ public class FormBayarController 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 Label lblKurangBayar; @FXML private VBox vbContent; @FXML private Label lblGrandTotal; private final List daftarChkBayarSyarat; private final List daftarChkBayarOpsional; public BayarContent bayarContent = new BayarContent(); public FormBayarController() { daftarChkBayarSyarat = new ArrayList<>(); daftarChkBayarOpsional = new ArrayList<>(); } /** * Initializes the controller class. */ @Override public void initialize(URL url, ResourceBundle rb) { lblGrandTotal.setText(Fucout.formatRupiah(bayarContent.getTotalPerluBayar())); lblKurangBayar.setText(Fucout.formatRupiah(bayarContent.getTotalPerluBayar())); daftarChkBayarSyarat.add(chkTunai); daftarChkBayarSyarat.add(chkKartu); daftarChkBayarOpsional.add(chkPromo); daftarChkBayarOpsional.add(chkRetur); daftarChkBayarOpsional.add(chkGopay); daftarChkBayarOpsional.add(chkOvo); daftarChkBayarOpsional.add(chkPoin); initShortcuts(); } private void initShortcuts() { Map listShortcuts = new HashMap<>(); KeyCombination kcSelesaiBayar = new KeyCodeCombination(KeyCode.F10); Runnable rnSelesaiBayar = () -> { if (bayarContent.getTotalBayar() >= bayarContent.getTotalPerluBayar()) { } else { DialogSelesaiBayarTidakLunasController dsbtlc = new DialogSelesaiBayarTidakLunasController(this, bayarContent.getTotalPerluBayar() - bayarContent.getTotalBayar()); dsbtlc.initOwner(apContent.getScene().getWindow()); dsbtlc.show(); } }; listShortcuts.put(kcSelesaiBayar, rnSelesaiBayar); Platform.runLater(() -> { apContent.getScene().getAccelerators().putAll(listShortcuts); }); } @FXML void chkPilihanOnAction(ActionEvent event) { CheckBox chkSource = (CheckBox) event.getSource(); FXMLLoader loader = new FXMLLoader(); Node node = null; try { switch (chkSource.getText()) { case BAYAR_TUNAI: if (bayarContent.getNodeTunai() == null && chkSource.selectedProperty().get()) { loader.setLocation(getClass().getResource("/fxml/FormBayarTunai.fxml")); node = loader.load(); vbContent.getChildren().add(node); bayarContent.setNodeTunai(node); FormBayarTunaiController fbtc = loader.getController(); fbtc.initData(this); } else { if (bayarContent.getNodeTunai() != null) { vbContent.getChildren().remove(bayarContent.getNodeTunai()); bayarContent.setNodeTunai(null); bayarContent.setBayarTunai(0); updateKurangBayarView(); } } break; case BAYAR_KARTU: if (bayarContent.getNodeKartu() == null && chkSource.selectedProperty().get()) { loader.setLocation(getClass().getResource("/fxml/FormBayarKartu.fxml")); node = loader.load(); vbContent.getChildren().add(node); bayarContent.setNodeKartu(node); FormBayarKartuController fbkc = loader.getController(); fbkc.initData(this); } else { if (bayarContent.getNodeKartu() != null) { vbContent.getChildren().remove(bayarContent.getNodeKartu()); bayarContent.setNodeKartu(null); bayarContent.setBayarKartu(0); updateKurangBayarView(); } } break; case 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); FormBayarReturController fbrc = loader.getController(); fbrc.initData(this); } else { if (bayarContent.getNodeRetur() != null) { vbContent.getChildren().remove(bayarContent.getNodeRetur()); bayarContent.setNodeRetur(null); bayarContent.setBayarRetur(0); updateKurangBayarView(); } } break; case 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); bayarContent.setBayarPromo(0); updateKurangBayarView(); } } break; case BAYAR_GOPAY: break; case BAYAR_OVO: break; case 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); FormBayarPoinController fbpc = loader.getController(); fbpc.initData(this); } else { if (bayarContent.getNodePoin() != null) { vbContent.getChildren().remove(bayarContent.getNodePoin()); bayarContent.setNodePoin(null); bayarContent.setBayarPoin(0); updateKurangBayarView(); } } 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() { lblKurangBayar.setText(Fucout.formatRupiah( bayarContent.getTotalPerluBayar() - bayarContent.getTotalBayar())); } }