|
|
|
|
@ -5,34 +5,19 @@
|
|
|
|
|
*/
|
|
|
|
|
package id.amigogroup.posterminal.pencarian;
|
|
|
|
|
|
|
|
|
|
import id.amigogroup.posterminal.FormUtamaController;
|
|
|
|
|
import id.amigogroup.posterminal.SystemValue;
|
|
|
|
|
import id.amigogroup.posterminal.api.AmigoPosRx;
|
|
|
|
|
import id.amigogroup.posterminal.model.Barang;
|
|
|
|
|
import id.amigogroup.posterminal.model.DNotaTunai;
|
|
|
|
|
import id.amigogroup.posterminal.model.MNotaTunai;
|
|
|
|
|
import id.amigogroup.posterminal.model.Pagination;
|
|
|
|
|
import id.amigogroup.posterminal.transaksi.NotaWithListDetail;
|
|
|
|
|
import id.amigogroup.posterminal.transaksi.TabelBarangTunai;
|
|
|
|
|
import id.amigogroup.posterminal.util.AlertUtil;
|
|
|
|
|
import id.amigogroup.posterminal.util.AmigoPosCache;
|
|
|
|
|
import id.amigogroup.posterminal.util.ButtonUtility;
|
|
|
|
|
import id.amigogroup.posterminal.util.Fucout;
|
|
|
|
|
import io.reactivex.Observable;
|
|
|
|
|
import io.reactivex.Observer;
|
|
|
|
|
import io.reactivex.disposables.Disposable;
|
|
|
|
|
import java.io.IOException;
|
|
|
|
|
import java.net.HttpURLConnection;
|
|
|
|
|
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.beans.property.ReadOnlyObjectWrapper;
|
|
|
|
|
import javafx.collections.FXCollections;
|
|
|
|
|
import javafx.collections.ObservableList;
|
|
|
|
|
import javafx.event.ActionEvent;
|
|
|
|
|
@ -41,20 +26,12 @@ import javafx.fxml.FXMLLoader;
|
|
|
|
|
import javafx.fxml.Initializable;
|
|
|
|
|
import javafx.scene.Parent;
|
|
|
|
|
import javafx.scene.control.Alert;
|
|
|
|
|
import javafx.scene.control.Button;
|
|
|
|
|
import javafx.scene.control.ButtonBar.ButtonData;
|
|
|
|
|
import javafx.scene.control.ButtonType;
|
|
|
|
|
import javafx.scene.control.ComboBox;
|
|
|
|
|
import javafx.scene.control.Dialog;
|
|
|
|
|
import javafx.scene.control.Label;
|
|
|
|
|
import javafx.scene.control.TableColumn;
|
|
|
|
|
import javafx.scene.control.TableView;
|
|
|
|
|
import javafx.scene.control.TextField;
|
|
|
|
|
import javafx.scene.control.cell.PropertyValueFactory;
|
|
|
|
|
import javafx.scene.input.KeyCode;
|
|
|
|
|
import javafx.scene.input.KeyCodeCombination;
|
|
|
|
|
import javafx.scene.input.KeyCombination;
|
|
|
|
|
import javafx.scene.input.KeyEvent;
|
|
|
|
|
import javafx.scene.layout.AnchorPane;
|
|
|
|
|
import javafx.stage.Window;
|
|
|
|
|
import retrofit2.HttpException;
|
|
|
|
|
@ -69,8 +46,6 @@ public class DialogCariNotaTundaController extends Dialog<String> implements Ini
|
|
|
|
|
@FXML
|
|
|
|
|
AnchorPane apContent;
|
|
|
|
|
@FXML
|
|
|
|
|
private AnchorPane apMain;
|
|
|
|
|
@FXML
|
|
|
|
|
private ComboBox<String> cbxCariNotaTunda;
|
|
|
|
|
@FXML
|
|
|
|
|
private TableView<TabelBarangTunai> tbvBarangTunda;
|
|
|
|
|
@ -83,7 +58,7 @@ public class DialogCariNotaTundaController extends Dialog<String> implements Ini
|
|
|
|
|
@FXML
|
|
|
|
|
private TableColumn<TabelBarangTunai, String> tcUkur;
|
|
|
|
|
@FXML
|
|
|
|
|
private TableColumn<TabelBarangTunai, String> tcJumlah;
|
|
|
|
|
private TableColumn<TabelBarangTunai, String> tcJml;
|
|
|
|
|
@FXML
|
|
|
|
|
private TableColumn<TabelBarangTunai, String> tcHarga;
|
|
|
|
|
@FXML
|
|
|
|
|
@ -95,35 +70,17 @@ public class DialogCariNotaTundaController extends Dialog<String> implements Ini
|
|
|
|
|
@FXML
|
|
|
|
|
private TableColumn<TabelBarangTunai, String> tcPromo;
|
|
|
|
|
@FXML
|
|
|
|
|
private Label lblKasir;
|
|
|
|
|
private TableColumn<TabelBarangTunai, String> tcPramuniaga;
|
|
|
|
|
final ObservableList<TabelBarangTunai> daftarTabelBarangTunai = FXCollections.observableArrayList();
|
|
|
|
|
AmigoPosRx posRx = new AmigoPosRx();
|
|
|
|
|
private FormUtamaController parent;
|
|
|
|
|
private ButtonType btnTambah = new ButtonType("Tambah", ButtonData.YES);
|
|
|
|
|
private String noNota = "";
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Initializes the controller class.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
|
|
|
|
public void initialize(URL url, ResourceBundle rb) {
|
|
|
|
|
getDialogPane().getButtonTypes().add(btnTambah);
|
|
|
|
|
getDialogPane().getButtonTypes().add(new ButtonType("Tutup", ButtonData.CANCEL_CLOSE));
|
|
|
|
|
tcNo.setCellValueFactory((TableColumn.CellDataFeatures<TabelBarangTunai, Integer> cell) -> {
|
|
|
|
|
return new ReadOnlyObjectWrapper(tbvBarangTunda.getItems().indexOf(cell.getValue()) + 1);
|
|
|
|
|
});
|
|
|
|
|
tcKode.setCellValueFactory(new PropertyValueFactory<>("kode"));
|
|
|
|
|
tcNama.setCellValueFactory(new PropertyValueFactory<>("nama"));
|
|
|
|
|
tcUkur.setCellValueFactory(new PropertyValueFactory<>("ukur"));
|
|
|
|
|
tcJumlah.setCellValueFactory(new PropertyValueFactory<>("jumlah"));
|
|
|
|
|
tcHarga.setCellValueFactory(new PropertyValueFactory<>("harga"));
|
|
|
|
|
tcDisc1.setCellValueFactory(new PropertyValueFactory<>("disc1"));
|
|
|
|
|
tcDisc2.setCellValueFactory(new PropertyValueFactory<>("disc2"));
|
|
|
|
|
tcPromo.setCellValueFactory(new PropertyValueFactory<>("cbxPromo"));
|
|
|
|
|
tcSubTotal.setCellValueFactory(new PropertyValueFactory<>("subTotal"));
|
|
|
|
|
// tcPramuniaga.setCellValueFactory(new PropertyValueFactory<>("fldPramuniaga"));
|
|
|
|
|
tbvBarangTunda.setItems(daftarTabelBarangTunai);
|
|
|
|
|
//
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DialogCariNotaTundaController(/*FormPresensiController parent*/) {
|
|
|
|
|
@ -138,159 +95,21 @@ public class DialogCariNotaTundaController extends Dialog<String> implements Ini
|
|
|
|
|
getDialogPane().setContent(root);
|
|
|
|
|
setTitle("Cari Nota Tunda");
|
|
|
|
|
posRx.getMNotaTunaiByStatus("T", 25).subscribe(getNotaTunaiTundaObserver);
|
|
|
|
|
|
|
|
|
|
setResultConverter(buttonType -> {
|
|
|
|
|
if (buttonType == btnTambah) {
|
|
|
|
|
return "Tunda:" + noNota;
|
|
|
|
|
}
|
|
|
|
|
return "Batal";
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
// getDialogPane().getButtonTypes().add(ButtonType.CANCEL);
|
|
|
|
|
// setResultConverter(buttonType -> {
|
|
|
|
|
// return str;
|
|
|
|
|
// });
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
Logger.getLogger(DialogCariBarangController.class
|
|
|
|
|
.getName()).log(Level.SEVERE, null, e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void refreshData(List<DNotaTunai> daftarNotaTunai) {
|
|
|
|
|
daftarTabelBarangTunai.clear();
|
|
|
|
|
//hitungTotal(daftarNotaTunai);
|
|
|
|
|
|
|
|
|
|
String[] promo = {"Ulang Tahun", "Harbolnas", "Ultah Amigo"};
|
|
|
|
|
for (DNotaTunai dNotaTunai : daftarNotaTunai) {
|
|
|
|
|
//ComboBox
|
|
|
|
|
ComboBox<String> cbxPromo = new ComboBox<>(FXCollections.observableArrayList(promo));
|
|
|
|
|
cbxPromo.getSelectionModel().select("Ulang Tahun");
|
|
|
|
|
//Button
|
|
|
|
|
Button btnBatal = ButtonUtility.generateButton(ButtonUtility.CLOSE_ICON);
|
|
|
|
|
btnBatal.setOnAction((t) -> {
|
|
|
|
|
Alert alert = AlertUtil.getAlertError(
|
|
|
|
|
AlertUtil.DIALOG_KONFIRMASI_MESSAGE,
|
|
|
|
|
"Yakin ingin menghapus barang?");
|
|
|
|
|
alert.initOwner(apMain.getScene().getWindow());
|
|
|
|
|
alert.show();
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
//TextField
|
|
|
|
|
TextField fldPramuniaga = new TextField(dNotaTunai.getKodePram());
|
|
|
|
|
fldPramuniaga.setOnKeyPressed((t) -> {
|
|
|
|
|
if (t.getCode() == KeyCode.ENTER) {
|
|
|
|
|
fldPramuniaga.requestFocus();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
String namaBarang = "...";
|
|
|
|
|
if (AmigoPosCache.getInstance().getDaftarBarang().containsKey(dNotaTunai.getKdBarang())) {
|
|
|
|
|
namaBarang = Fucout.getText(AmigoPosCache.getInstance().getDaftarBarang()
|
|
|
|
|
.get(dNotaTunai.getKdBarang()).getNamaBarang());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
daftarTabelBarangTunai.add(new TabelBarangTunai(
|
|
|
|
|
Fucout.getText(dNotaTunai.getKdBarang()),
|
|
|
|
|
namaBarang,
|
|
|
|
|
Fucout.getText(dNotaTunai.getNoBarang()),
|
|
|
|
|
Fucout.getText(String.valueOf(dNotaTunai.getJumlah())),
|
|
|
|
|
Fucout.getText(Fucout.formatRibuan(dNotaTunai.getHargaJual())),
|
|
|
|
|
Fucout.getText(Fucout.formatPersentase(dNotaTunai.getDiskon())),
|
|
|
|
|
Fucout.getText(Fucout.formatPersentase(dNotaTunai.getDiskon2())),
|
|
|
|
|
cbxPromo,
|
|
|
|
|
Fucout.getText(Fucout.formatRibuan(
|
|
|
|
|
dNotaTunai.getHargaJual() * dNotaTunai.getJumlah()
|
|
|
|
|
)),
|
|
|
|
|
fldPramuniaga,
|
|
|
|
|
btnBatal));
|
|
|
|
|
|
|
|
|
|
if (!AmigoPosCache.getInstance().getDaftarBarang().containsKey(dNotaTunai.getKdBarang())) {
|
|
|
|
|
posRx.getBarangByKodeBarang(dNotaTunai.getKdBarang()).subscribe(getBarangObserver);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
void cbxNotaTundaOnAction(ActionEvent event) {
|
|
|
|
|
posRx.getDNotaTunaiByNoNota(cbxCariNotaTunda.getSelectionModel().getSelectedItem())
|
|
|
|
|
.subscribe(getDNotaTunaiObserver);
|
|
|
|
|
}
|
|
|
|
|
//
|
|
|
|
|
//OBSERVER
|
|
|
|
|
Observer<List<DNotaTunai>> getDNotaTunaiObserver = new Observer<>() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onSubscribe(Disposable dspsbl) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onNext(List<DNotaTunai> daftarDNotaTunai) {
|
|
|
|
|
if (daftarDNotaTunai.size() > 0) {
|
|
|
|
|
noNota = daftarDNotaTunai.get(0).getNoNota();
|
|
|
|
|
}
|
|
|
|
|
refreshData(daftarDNotaTunai);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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 {
|
|
|
|
|
AmigoPosRx.handleGenericError(error, apMain.getScene().getWindow());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onComplete() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
//Observer untuk menampilkan data sebuah barang ke tabel, yang sudah mempunyai DNotaTunai
|
|
|
|
|
Observer<Barang> getBarangObserver = new Observer<>() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onSubscribe(Disposable dspsbl) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onNext(Barang b) {
|
|
|
|
|
AmigoPosCache.getInstance().getDaftarBarang().put(b.getKodeBarang(), b);
|
|
|
|
|
for (TabelBarangTunai tbt : daftarTabelBarangTunai) {
|
|
|
|
|
if (tbt.getKode().equals(b.getKodeBarang())) {
|
|
|
|
|
tbt.setNama(b.getNamaBarang());
|
|
|
|
|
tbvBarangTunda.refresh();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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,
|
|
|
|
|
"Barang dengan kode tersebut tidak ditemukan.");
|
|
|
|
|
alert.initOwner(apMain.getScene().getWindow());
|
|
|
|
|
alert.show();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
AmigoPosRx.handleGenericError(error, apMain.getScene().getWindow());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onComplete() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
//Observer Nota Tunda
|
|
|
|
|
public Observer<Pagination<MNotaTunai>> getNotaTunaiTundaObserver = new Observer<Pagination<MNotaTunai>>() {
|
|
|
|
|
@Override
|
|
|
|
|
public void onSubscribe(Disposable dspsbl) {
|
|
|
|
|
@ -313,6 +132,9 @@ public class DialogCariNotaTundaController extends Dialog<String> implements Ini
|
|
|
|
|
"Nota Tunda Tidak Ditemukan");
|
|
|
|
|
alert.initOwner(apContent.getScene().getWindow());
|
|
|
|
|
alert.show();
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
Logger.getLogger(DialogCariNotaTundaController.class.getName()).log(Level.SEVERE, null, error);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
AmigoPosRx.handleGenericError(error, apContent.getScene().getWindow());
|
|
|
|
|
|