|
- /*
- * 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.api.AmigoPosRx;
- import id.amigogroup.posterminal.model.MNotaRetur;
- import id.amigogroup.posterminal.util.AlertUtil;
- import id.amigogroup.posterminal.util.Fucout;
- import io.reactivex.Observer;
- import io.reactivex.disposables.Disposable;
- import java.net.HttpURLConnection;
- import java.net.SocketTimeoutException;
- import java.net.URL;
- import java.util.ResourceBundle;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javafx.application.Platform;
- import javafx.fxml.FXML;
- import javafx.fxml.Initializable;
- import javafx.scene.control.Alert;
- import javafx.scene.control.Label;
- import javafx.scene.control.TextField;
- import javafx.scene.input.KeyCode;
- import javafx.scene.input.KeyEvent;
- import javafx.scene.layout.AnchorPane;
- import retrofit2.HttpException;
-
- /**
- * FXML Controller class
- *
- * @author ronal
- */
- public class FormBayarReturController implements Initializable {
-
- @FXML
- private AnchorPane apMain;
- @FXML
- private TextField fldNoUrutRetur;
- @FXML
- private Label lblNominalRetur;
-
- private BayarInterface parent;
- private final AmigoPosRx posRx = new AmigoPosRx();
-
- /**
- * Initializes the controller class.
- */
- @Override
- public void initialize(URL url, ResourceBundle rb) {
-
- }
-
- public void initData(BayarInterface parent) {
- this.parent = parent;
- }
-
- @FXML
- void fldNoUrutReturOnKeyPressed(KeyEvent event) {
- if (event.getCode() == KeyCode.ENTER) {
- posRx.getMNotaReturByNoNota(fldNoUrutRetur.getText()).subscribe(getMNotaReturObserver);
- }
- }
-
- Observer<MNotaRetur> getMNotaReturObserver = new Observer<>() {
- @Override
- public void onSubscribe(Disposable dspsbl) {
- }
-
- @Override
- public void onNext(MNotaRetur mNotaRetur) {
- if (parent != null && parent.getBayarContent() != null
- && parent.getBayarContent().getNodeTunai() != null) {
- lblNominalRetur.setText(Fucout.formatRupiah(mNotaRetur.getTotalDiskon()));
-
- parent.getBayarContent().setBayarRetur(mNotaRetur.getTotalDiskon());
- parent.updateKurangBayarView();
- }
- }
-
- @Override
- public void onError(Throwable error) {
- if (error instanceof HttpException) {
- switch (((HttpException) error).code()) {
- case HttpURLConnection.HTTP_NOT_FOUND:
- Platform.runLater(() -> {
- Alert alert = AlertUtil.getAlertError(
- AlertUtil.ERROR_TIDAK_DITEMUKAN_TITLE,
- "Data nota tidak ditemukan.");
- alert.initOwner(apMain.getScene().getWindow());
- alert.show();
- });
- }
- } else if (error instanceof SocketTimeoutException) {
- Platform.runLater(() -> {
- Alert alert = AlertUtil.getAlertError(
- AlertUtil.ERROR_KONEKSI_TIMEOUT_TITLE,
- AlertUtil.ERROR_KONEKSI_TIMEOUT_MESSAGE);
- alert.initOwner(apMain.getScene().getWindow());
- alert.show();
- });
- } else {
- Platform.runLater(() -> {
- Alert alert = AlertUtil.getAlertError(
- AlertUtil.ERROR_TIDAK_TERDUGA_TITLE,
- AlertUtil.ERROR_TIDAK_TERDUGA_MESSAGE);
- alert.initOwner(apMain.getScene().getWindow());
- alert.show();
- Logger.getLogger(FormUtamaController.class
- .getName()).log(Level.SEVERE, null, error);
- });
- }
- }
-
- @Override
- public void onComplete() {
- }
-
- };
- }
|