Aplikasi POS Amigo, dibangun dengan JavaFX dengan Maven
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

124 行
4.1 KiB

  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package id.amigogroup.posterminal.bayar;
  7. import id.amigogroup.posterminal.FormUtamaController;
  8. import id.amigogroup.posterminal.api.AmigoPosRx;
  9. import id.amigogroup.posterminal.model.MNotaRetur;
  10. import id.amigogroup.posterminal.util.AlertUtil;
  11. import id.amigogroup.posterminal.util.Fucout;
  12. import io.reactivex.Observer;
  13. import io.reactivex.disposables.Disposable;
  14. import java.net.HttpURLConnection;
  15. import java.net.SocketTimeoutException;
  16. import java.net.URL;
  17. import java.util.ResourceBundle;
  18. import java.util.logging.Level;
  19. import java.util.logging.Logger;
  20. import javafx.application.Platform;
  21. import javafx.fxml.FXML;
  22. import javafx.fxml.Initializable;
  23. import javafx.scene.control.Alert;
  24. import javafx.scene.control.Label;
  25. import javafx.scene.control.TextField;
  26. import javafx.scene.input.KeyCode;
  27. import javafx.scene.input.KeyEvent;
  28. import javafx.scene.layout.AnchorPane;
  29. import retrofit2.HttpException;
  30. /**
  31. * FXML Controller class
  32. *
  33. * @author ronal
  34. */
  35. public class FormBayarReturController implements Initializable {
  36. @FXML
  37. private AnchorPane apMain;
  38. @FXML
  39. private TextField fldNoUrutRetur;
  40. @FXML
  41. private Label lblNominalRetur;
  42. private BayarInterface parent;
  43. private final AmigoPosRx posRx = new AmigoPosRx();
  44. /**
  45. * Initializes the controller class.
  46. */
  47. @Override
  48. public void initialize(URL url, ResourceBundle rb) {
  49. }
  50. public void initData(BayarInterface parent) {
  51. this.parent = parent;
  52. }
  53. @FXML
  54. void fldNoUrutReturOnKeyPressed(KeyEvent event) {
  55. if (event.getCode() == KeyCode.ENTER) {
  56. posRx.getMNotaReturByNoNota(fldNoUrutRetur.getText()).subscribe(getMNotaReturObserver);
  57. }
  58. }
  59. Observer<MNotaRetur> getMNotaReturObserver = new Observer<>() {
  60. @Override
  61. public void onSubscribe(Disposable dspsbl) {
  62. }
  63. @Override
  64. public void onNext(MNotaRetur mNotaRetur) {
  65. if (parent != null && parent.getBayarContent() != null
  66. && parent.getBayarContent().getNodeTunai() != null) {
  67. lblNominalRetur.setText(Fucout.formatRupiah(mNotaRetur.getTotalDiskon()));
  68. parent.getBayarContent().setBayarRetur(mNotaRetur.getTotalDiskon());
  69. parent.updateKurangBayarView();
  70. }
  71. }
  72. @Override
  73. public void onError(Throwable error) {
  74. if (error instanceof HttpException) {
  75. switch (((HttpException) error).code()) {
  76. case HttpURLConnection.HTTP_NOT_FOUND:
  77. Platform.runLater(() -> {
  78. Alert alert = AlertUtil.getAlertError(
  79. AlertUtil.ERROR_TIDAK_DITEMUKAN_TITLE,
  80. "Data nota tidak ditemukan.");
  81. alert.initOwner(apMain.getScene().getWindow());
  82. alert.show();
  83. });
  84. }
  85. } else if (error instanceof SocketTimeoutException) {
  86. Platform.runLater(() -> {
  87. Alert alert = AlertUtil.getAlertError(
  88. AlertUtil.ERROR_KONEKSI_TIMEOUT_TITLE,
  89. AlertUtil.ERROR_KONEKSI_TIMEOUT_MESSAGE);
  90. alert.initOwner(apMain.getScene().getWindow());
  91. alert.show();
  92. });
  93. } else {
  94. Platform.runLater(() -> {
  95. Alert alert = AlertUtil.getAlertError(
  96. AlertUtil.ERROR_TIDAK_TERDUGA_TITLE,
  97. AlertUtil.ERROR_TIDAK_TERDUGA_MESSAGE);
  98. alert.initOwner(apMain.getScene().getWindow());
  99. alert.show();
  100. Logger.getLogger(FormUtamaController.class
  101. .getName()).log(Level.SEVERE, null, error);
  102. });
  103. }
  104. }
  105. @Override
  106. public void onComplete() {
  107. }
  108. };
  109. }