|
|
|
@ -5,90 +5,233 @@
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
package id.amigogroup.posterminal.pencarian;
|
|
|
|
package id.amigogroup.posterminal.pencarian;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
|
|
|
import id.amigogroup.posterminal.FormUtamaController;
|
|
|
|
|
|
|
|
import id.amigogroup.posterminal.SystemValue;
|
|
|
|
|
|
|
|
import id.amigogroup.posterminal.api.AmigoPosRx;
|
|
|
|
|
|
|
|
import id.amigogroup.posterminal.model.Pagination;
|
|
|
|
|
|
|
|
import id.amigogroup.posterminal.model.Pelanggan;
|
|
|
|
|
|
|
|
import id.amigogroup.posterminal.util.AlertUtil;
|
|
|
|
|
|
|
|
import io.reactivex.Observer;
|
|
|
|
|
|
|
|
import io.reactivex.disposables.Disposable;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.net.URL;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.ResourceBundle;
|
|
|
|
import java.util.ResourceBundle;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Level;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
import javafx.beans.property.ReadOnlyObjectWrapper;
|
|
|
|
import javafx.collections.FXCollections;
|
|
|
|
import javafx.collections.FXCollections;
|
|
|
|
import javafx.collections.ObservableList;
|
|
|
|
import javafx.collections.ObservableList;
|
|
|
|
|
|
|
|
import javafx.event.ActionEvent;
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
import javafx.fxml.FXMLLoader;
|
|
|
|
import javafx.fxml.FXMLLoader;
|
|
|
|
import javafx.fxml.Initializable;
|
|
|
|
import javafx.fxml.Initializable;
|
|
|
|
import javafx.scene.Parent;
|
|
|
|
import javafx.scene.Parent;
|
|
|
|
|
|
|
|
import javafx.scene.control.Alert;
|
|
|
|
|
|
|
|
import javafx.scene.control.ButtonType;
|
|
|
|
import javafx.scene.control.Dialog;
|
|
|
|
import javafx.scene.control.Dialog;
|
|
|
|
|
|
|
|
import javafx.scene.control.RadioButton;
|
|
|
|
import javafx.scene.control.TableColumn;
|
|
|
|
import javafx.scene.control.TableColumn;
|
|
|
|
import javafx.scene.control.TableView;
|
|
|
|
import javafx.scene.control.TableView;
|
|
|
|
|
|
|
|
import javafx.scene.control.TextField;
|
|
|
|
|
|
|
|
import javafx.scene.control.ToggleGroup;
|
|
|
|
import javafx.scene.control.cell.PropertyValueFactory;
|
|
|
|
import javafx.scene.control.cell.PropertyValueFactory;
|
|
|
|
|
|
|
|
import javafx.scene.input.KeyCode;
|
|
|
|
|
|
|
|
import javafx.scene.input.KeyEvent;
|
|
|
|
import javafx.scene.layout.AnchorPane;
|
|
|
|
import javafx.scene.layout.AnchorPane;
|
|
|
|
import javafx.stage.Window;
|
|
|
|
import javafx.stage.Window;
|
|
|
|
|
|
|
|
import retrofit2.HttpException;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* FXML Controller class
|
|
|
|
* FXML Controller class
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* @author ronal
|
|
|
|
* @author ronal
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class DialogCariPelangganController extends Dialog<String> implements Initializable {
|
|
|
|
public class DialogCariPelangganController extends Dialog<Pelanggan> implements Initializable {
|
|
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
@FXML
|
|
|
|
AnchorPane apContent;
|
|
|
|
AnchorPane apContent;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
|
|
|
private TextField tfPencarian;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
|
|
|
private ToggleGroup tgTipe;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
|
|
|
private RadioButton rbMember;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
|
|
|
private RadioButton rbNama;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
|
|
|
private RadioButton rbNoTelpNoHp;
|
|
|
|
@FXML
|
|
|
|
@FXML
|
|
|
|
private TableView<TabelPelanggan> tbvPelanggan;
|
|
|
|
private TableView<TabelPelanggan> tbvPelanggan;
|
|
|
|
@FXML
|
|
|
|
@FXML
|
|
|
|
|
|
|
|
private TableColumn<TabelPelanggan, Integer> tcNo;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
private TableColumn<TabelPelanggan, String> tcKode;
|
|
|
|
private TableColumn<TabelPelanggan, String> tcKode;
|
|
|
|
@FXML
|
|
|
|
@FXML
|
|
|
|
private TableColumn<TabelPelanggan, String> tcNama;
|
|
|
|
private TableColumn<TabelPelanggan, String> tcNama;
|
|
|
|
@FXML
|
|
|
|
@FXML
|
|
|
|
private TableColumn<TabelPelanggan, String> tcAlamat;
|
|
|
|
private TableColumn<TabelPelanggan, String> tcAlamat;
|
|
|
|
@FXML
|
|
|
|
@FXML
|
|
|
|
|
|
|
|
private TableColumn<TabelPelanggan, String> tcNoTelp;
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
private TableColumn<TabelPelanggan, String> tcUpline;
|
|
|
|
private TableColumn<TabelPelanggan, String> tcUpline;
|
|
|
|
|
|
|
|
|
|
|
|
final ObservableList<TabelPelanggan> daftarTabelPelanggan = FXCollections.observableArrayList();
|
|
|
|
final ObservableList<TabelPelanggan> daftarTabelPelanggan = FXCollections.observableArrayList();
|
|
|
|
|
|
|
|
AmigoPosRx posRx = new AmigoPosRx();
|
|
|
|
|
|
|
|
private Pelanggan pelanggan = null;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Initializes the controller class.
|
|
|
|
* Initializes the controller class.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void initialize(URL url, ResourceBundle rb) {
|
|
|
|
public void initialize(URL url, ResourceBundle rb) {
|
|
|
|
|
|
|
|
getDialogPane().getButtonTypes().add(ButtonType.CLOSE);
|
|
|
|
|
|
|
|
tcNo.setCellValueFactory((TableColumn.CellDataFeatures<TabelPelanggan, Integer> cell) -> {
|
|
|
|
|
|
|
|
return new ReadOnlyObjectWrapper(tbvPelanggan.getItems().indexOf(cell.getValue()) + 1);
|
|
|
|
|
|
|
|
});
|
|
|
|
tcKode.setCellValueFactory(new PropertyValueFactory<>("kode"));
|
|
|
|
tcKode.setCellValueFactory(new PropertyValueFactory<>("kode"));
|
|
|
|
tcNama.setCellValueFactory(new PropertyValueFactory<>("nama"));
|
|
|
|
tcNama.setCellValueFactory(new PropertyValueFactory<>("nama"));
|
|
|
|
tcAlamat.setCellValueFactory(new PropertyValueFactory<>("nomor"));
|
|
|
|
tcAlamat.setCellValueFactory(new PropertyValueFactory<>("alamat"));
|
|
|
|
|
|
|
|
tcNoTelp.setCellValueFactory(new PropertyValueFactory<>("noTelp"));
|
|
|
|
tcUpline.setCellValueFactory(new PropertyValueFactory<>("upline"));
|
|
|
|
tcUpline.setCellValueFactory(new PropertyValueFactory<>("upline"));
|
|
|
|
tbvPelanggan.setItems(daftarTabelPelanggan);
|
|
|
|
tbvPelanggan.setItems(daftarTabelPelanggan);
|
|
|
|
fillTable(new ArrayList<>());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public DialogCariPelangganController(/*FormPresensiController parent*/) {
|
|
|
|
public DialogCariPelangganController(/*FormPresensiController parent*/) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Window window = getDialogPane().getScene().getWindow();
|
|
|
|
Window window = getDialogPane().getScene().getWindow();
|
|
|
|
window.setOnCloseRequest(event -> this.close());
|
|
|
|
window.setOnCloseRequest(event -> this.close());
|
|
|
|
|
|
|
|
|
|
|
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/DialogCariPelanggan.fxml"));
|
|
|
|
FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/DialogCariPelanggan.fxml"));
|
|
|
|
loader.setController(this);
|
|
|
|
loader.setController(this);
|
|
|
|
// DialogCariBarangController controller = loader.<DialogCariBarangController>getController();
|
|
|
|
// DialogCariBarangController controller = loader.<DialogCariBarangController>getController();
|
|
|
|
Parent root = loader.load();
|
|
|
|
Parent root = loader.load();
|
|
|
|
getDialogPane().setContent(root);
|
|
|
|
getDialogPane().setContent(root);
|
|
|
|
setTitle("Cari Pelanggan");
|
|
|
|
setTitle("Cari Pelanggan");
|
|
|
|
|
|
|
|
|
|
|
|
// getDialogPane().getButtonTypes().add(ButtonType.CANCEL);
|
|
|
|
// getDialogPane().getButtonTypes().add(ButtonType.CANCEL);
|
|
|
|
// setResultConverter(buttonType -> {
|
|
|
|
setResultConverter(buttonType -> {
|
|
|
|
// return str;
|
|
|
|
return pelanggan;
|
|
|
|
// });
|
|
|
|
});
|
|
|
|
} catch (IOException e) {
|
|
|
|
} catch (IOException e) {
|
|
|
|
Logger.getLogger(DialogCariBarangController.class
|
|
|
|
Logger.getLogger(DialogCariBarangController.class
|
|
|
|
.getName()).log(Level.SEVERE, null, e);
|
|
|
|
.getName()).log(Level.SEVERE, null, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void fillTable(List<TabelPelanggan> daftarBarang) {
|
|
|
|
public void fillTable() {
|
|
|
|
// Button btnTambah = new Button("Tambah");
|
|
|
|
// Button btnTambah = new Button("Tambah");
|
|
|
|
// btnTambah.setOnAction((event) -> {
|
|
|
|
// btnTambah.setOnAction((event) -> {
|
|
|
|
// setResult("Pak Coba");
|
|
|
|
// setResult("Pak Coba");
|
|
|
|
// this.close();
|
|
|
|
// this.close();
|
|
|
|
// });
|
|
|
|
// });
|
|
|
|
daftarTabelPelanggan.add(new TabelPelanggan("0103201401", "Pak Coba","Jl. Wates Percobaan", "-"));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void updateTabelPelanggan(List<Pelanggan> daftarPelanggan) {
|
|
|
|
|
|
|
|
daftarTabelPelanggan.clear();
|
|
|
|
|
|
|
|
for (Pelanggan pelanggan : daftarPelanggan) {
|
|
|
|
|
|
|
|
daftarTabelPelanggan.add(new TabelPelanggan(
|
|
|
|
|
|
|
|
pelanggan.getAlias(),
|
|
|
|
|
|
|
|
pelanggan.getNama(),
|
|
|
|
|
|
|
|
pelanggan.getAlamat(),
|
|
|
|
|
|
|
|
pelanggan.getTelp() + " / " +pelanggan.getPonsel(),
|
|
|
|
|
|
|
|
pelanggan.getUpline()));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
|
|
|
void tfPencarianOnKeyReleased(KeyEvent event) {
|
|
|
|
|
|
|
|
if (((RadioButton) tgTipe.getSelectedToggle()) == rbMember
|
|
|
|
|
|
|
|
&& event.getCode() == KeyCode.ENTER) {
|
|
|
|
|
|
|
|
System.out.println("MASUK DONGssssssss");
|
|
|
|
|
|
|
|
posRx.getPelangganByKodeMember(tfPencarian.getText()).subscribe(pelangganMemberObserver);
|
|
|
|
|
|
|
|
} else if (((RadioButton) tgTipe.getSelectedToggle()) == rbNama
|
|
|
|
|
|
|
|
&& tfPencarian.getText().length() >= 3) {
|
|
|
|
|
|
|
|
posRx.getPelangganByNama(tfPencarian.getText()).subscribe(daftarPelangganObserver);
|
|
|
|
|
|
|
|
} else if (((RadioButton) tgTipe.getSelectedToggle()) == rbNoTelpNoHp
|
|
|
|
|
|
|
|
&& tfPencarian.getText().length() >= 3) {
|
|
|
|
|
|
|
|
posRx.getPelangganByNoTelpNoHp(tfPencarian.getText()).subscribe(daftarPelangganObserver);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Observer<Pelanggan> pelangganMemberObserver = new Observer<Pelanggan>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onSubscribe(Disposable dspsbl) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onNext(Pelanggan p) {
|
|
|
|
|
|
|
|
System.out.println("COBA AJA");
|
|
|
|
|
|
|
|
if (p != null) {
|
|
|
|
|
|
|
|
pelanggan = p;
|
|
|
|
|
|
|
|
close();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onError(Throwable error) {
|
|
|
|
|
|
|
|
if (error instanceof HttpException) {
|
|
|
|
|
|
|
|
switch (((HttpException) error).code()) {
|
|
|
|
|
|
|
|
case HttpURLConnection.HTTP_NOT_FOUND:
|
|
|
|
|
|
|
|
Alert alert = AlertUtil.getAlertError(
|
|
|
|
|
|
|
|
AlertUtil.ERROR_TIDAK_DITEMUKAN_TITLE,
|
|
|
|
|
|
|
|
"Pelanggan dengan kode member tersebut tidak ditemukan.");
|
|
|
|
|
|
|
|
alert.initOwner(apContent.getScene().getWindow());
|
|
|
|
|
|
|
|
alert.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Alert alert = AlertUtil.getAlertError(
|
|
|
|
|
|
|
|
AlertUtil.ERROR_TIDAK_TERDUGA_TITLE,
|
|
|
|
|
|
|
|
"Terjadi kesalahan yang tidak terduga.");
|
|
|
|
|
|
|
|
alert.initOwner(apContent.getScene().getWindow());
|
|
|
|
|
|
|
|
alert.show();
|
|
|
|
|
|
|
|
Logger.getLogger(FormUtamaController.class.getName()).log(Level.SEVERE, null, error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onComplete() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Observer<Pagination<Pelanggan>> daftarPelangganObserver = new Observer<Pagination<Pelanggan>>() {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onSubscribe(Disposable dspsbl) {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onNext(Pagination<Pelanggan> p) {
|
|
|
|
|
|
|
|
if (p != null) {
|
|
|
|
|
|
|
|
updateTabelPelanggan(p.getData());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onError(Throwable error) {
|
|
|
|
|
|
|
|
if (error instanceof HttpException) {
|
|
|
|
|
|
|
|
switch (((HttpException) error).code()) {
|
|
|
|
|
|
|
|
case HttpURLConnection.HTTP_NOT_FOUND:
|
|
|
|
|
|
|
|
Alert alert = AlertUtil.getAlertError(
|
|
|
|
|
|
|
|
AlertUtil.ERROR_TIDAK_DITEMUKAN_TITLE,
|
|
|
|
|
|
|
|
"Pelanggan dengan kode member tersebut tidak ditemukan.");
|
|
|
|
|
|
|
|
alert.initOwner(apContent.getScene().getWindow());
|
|
|
|
|
|
|
|
alert.show();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Alert alert = AlertUtil.getAlertError(
|
|
|
|
|
|
|
|
AlertUtil.ERROR_TIDAK_TERDUGA_TITLE,
|
|
|
|
|
|
|
|
"Terjadi kesalahan yang tidak terduga.");
|
|
|
|
|
|
|
|
alert.initOwner(apContent.getScene().getWindow());
|
|
|
|
|
|
|
|
alert.show();
|
|
|
|
|
|
|
|
Logger.getLogger(FormUtamaController.class.getName()).log(Level.SEVERE, null, error);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public void onComplete() {
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|