|
|
@@ -5,19 +5,33 @@ |
|
|
*/ |
|
|
*/ |
|
|
package id.amigogroup.posterminal.pencarian; |
|
|
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.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.MNotaTunai; |
|
|
import id.amigogroup.posterminal.model.Pagination; |
|
|
import id.amigogroup.posterminal.model.Pagination; |
|
|
|
|
|
import id.amigogroup.posterminal.transaksi.NotaWithListDetail; |
|
|
import id.amigogroup.posterminal.transaksi.TabelBarangTunai; |
|
|
import id.amigogroup.posterminal.transaksi.TabelBarangTunai; |
|
|
import id.amigogroup.posterminal.util.AlertUtil; |
|
|
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.Observer; |
|
|
import io.reactivex.disposables.Disposable; |
|
|
import io.reactivex.disposables.Disposable; |
|
|
import java.io.IOException; |
|
|
import java.io.IOException; |
|
|
import java.net.HttpURLConnection; |
|
|
import java.net.HttpURLConnection; |
|
|
import java.net.URL; |
|
|
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.ResourceBundle; |
|
|
import java.util.logging.Level; |
|
|
import java.util.logging.Level; |
|
|
import java.util.logging.Logger; |
|
|
import java.util.logging.Logger; |
|
|
|
|
|
import javafx.application.Platform; |
|
|
import javafx.beans.property.ReadOnlyObjectWrapper; |
|
|
import javafx.beans.property.ReadOnlyObjectWrapper; |
|
|
import javafx.collections.FXCollections; |
|
|
import javafx.collections.FXCollections; |
|
|
import javafx.collections.ObservableList; |
|
|
import javafx.collections.ObservableList; |
|
|
@@ -27,14 +41,19 @@ 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.Alert; |
|
|
|
|
|
import javafx.scene.control.Button; |
|
|
import javafx.scene.control.ButtonBar.ButtonData; |
|
|
import javafx.scene.control.ButtonBar.ButtonData; |
|
|
import javafx.scene.control.ButtonType; |
|
|
import javafx.scene.control.ButtonType; |
|
|
import javafx.scene.control.ComboBox; |
|
|
import javafx.scene.control.ComboBox; |
|
|
import javafx.scene.control.Dialog; |
|
|
import javafx.scene.control.Dialog; |
|
|
|
|
|
import javafx.scene.control.Label; |
|
|
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.cell.PropertyValueFactory; |
|
|
import javafx.scene.control.cell.PropertyValueFactory; |
|
|
import javafx.scene.input.KeyCode; |
|
|
import javafx.scene.input.KeyCode; |
|
|
|
|
|
import javafx.scene.input.KeyCodeCombination; |
|
|
|
|
|
import javafx.scene.input.KeyCombination; |
|
|
import javafx.scene.input.KeyEvent; |
|
|
import javafx.scene.input.KeyEvent; |
|
|
import javafx.scene.layout.AnchorPane; |
|
|
import javafx.scene.layout.AnchorPane; |
|
|
import javafx.stage.Window; |
|
|
import javafx.stage.Window; |
|
|
@@ -50,6 +69,8 @@ public class DialogCariNotaTundaController extends Dialog<String> implements Ini |
|
|
@FXML |
|
|
@FXML |
|
|
AnchorPane apContent; |
|
|
AnchorPane apContent; |
|
|
@FXML |
|
|
@FXML |
|
|
|
|
|
private AnchorPane apMain; |
|
|
|
|
|
@FXML |
|
|
private ComboBox<String> cbxCariNotaTunda; |
|
|
private ComboBox<String> cbxCariNotaTunda; |
|
|
@FXML |
|
|
@FXML |
|
|
private TableView<TabelBarangTunai> tbvBarangTunda; |
|
|
private TableView<TabelBarangTunai> tbvBarangTunda; |
|
|
@@ -62,7 +83,7 @@ public class DialogCariNotaTundaController extends Dialog<String> implements Ini |
|
|
@FXML |
|
|
@FXML |
|
|
private TableColumn<TabelBarangTunai, String> tcUkur; |
|
|
private TableColumn<TabelBarangTunai, String> tcUkur; |
|
|
@FXML |
|
|
@FXML |
|
|
private TableColumn<TabelBarangTunai, String> tcJml; |
|
|
|
|
|
|
|
|
private TableColumn<TabelBarangTunai, String> tcJumlah; |
|
|
@FXML |
|
|
@FXML |
|
|
private TableColumn<TabelBarangTunai, String> tcHarga; |
|
|
private TableColumn<TabelBarangTunai, String> tcHarga; |
|
|
@FXML |
|
|
@FXML |
|
|
@@ -74,20 +95,37 @@ public class DialogCariNotaTundaController extends Dialog<String> implements Ini |
|
|
@FXML |
|
|
@FXML |
|
|
private TableColumn<TabelBarangTunai, String> tcPromo; |
|
|
private TableColumn<TabelBarangTunai, String> tcPromo; |
|
|
@FXML |
|
|
@FXML |
|
|
|
|
|
private Label lblKasir; |
|
|
private TableColumn<TabelBarangTunai, String> tcPramuniaga; |
|
|
private TableColumn<TabelBarangTunai, String> tcPramuniaga; |
|
|
final ObservableList<TabelBarangTunai> daftarTabelBarangTunai = FXCollections.observableArrayList(); |
|
|
final ObservableList<TabelBarangTunai> daftarTabelBarangTunai = FXCollections.observableArrayList(); |
|
|
AmigoPosRx posRx = new AmigoPosRx(); |
|
|
AmigoPosRx posRx = new AmigoPosRx(); |
|
|
|
|
|
private FormUtamaController parent; |
|
|
|
|
|
private ButtonType btnTambah = new ButtonType("Tambah", ButtonData.YES); |
|
|
|
|
|
private String noNota = ""; |
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* 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(btnTambah); |
|
|
getDialogPane().getButtonTypes().add(new ButtonType("Tutup", ButtonData.CANCEL_CLOSE)); |
|
|
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*/) { |
|
|
public DialogCariNotaTundaController(/*FormPresensiController parent*/) { |
|
|
try { |
|
|
try { |
|
|
Window window = getDialogPane().getScene().getWindow(); |
|
|
Window window = getDialogPane().getScene().getWindow(); |
|
|
@@ -100,21 +138,161 @@ public class DialogCariNotaTundaController extends Dialog<String> implements Ini |
|
|
getDialogPane().setContent(root); |
|
|
getDialogPane().setContent(root); |
|
|
setTitle("Cari Nota Tunda"); |
|
|
setTitle("Cari Nota Tunda"); |
|
|
posRx.getMNotaTunaiByStatus("T", 25).subscribe(getNotaTunaiTundaObserver); |
|
|
posRx.getMNotaTunaiByStatus("T", 25).subscribe(getNotaTunaiTundaObserver); |
|
|
// getDialogPane().getButtonTypes().add(ButtonType.CANCEL); |
|
|
|
|
|
// setResultConverter(buttonType -> { |
|
|
|
|
|
// return str; |
|
|
|
|
|
// }); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setResultConverter(buttonType -> { |
|
|
|
|
|
if (buttonType == btnTambah) { |
|
|
|
|
|
return "Tunda:" + noNota; |
|
|
|
|
|
} |
|
|
|
|
|
return "Batal"; |
|
|
|
|
|
|
|
|
|
|
|
}); |
|
|
} 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); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
@FXML |
|
|
void cbxNotaTundaOnAction(ActionEvent event) { |
|
|
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(); |
|
|
|
|
|
System.out.println(".onNext()"); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@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>>() { |
|
|
public Observer<Pagination<MNotaTunai>> getNotaTunaiTundaObserver = new Observer<Pagination<MNotaTunai>>() { |
|
|
@Override |
|
|
@Override |
|
|
public void onSubscribe(Disposable dspsbl) { |
|
|
public void onSubscribe(Disposable dspsbl) { |
|
|
@@ -122,7 +300,7 @@ public class DialogCariNotaTundaController extends Dialog<String> implements Ini |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public void onNext(Pagination<MNotaTunai> daftarMNotaTunai) { |
|
|
public void onNext(Pagination<MNotaTunai> daftarMNotaTunai) { |
|
|
for (MNotaTunai mNotaTunai : daftarMNotaTunai.getData()){ |
|
|
|
|
|
|
|
|
for (MNotaTunai mNotaTunai : daftarMNotaTunai.getData()) { |
|
|
cbxCariNotaTunda.getItems().add(mNotaTunai.getNoNota()); |
|
|
cbxCariNotaTunda.getItems().add(mNotaTunai.getNoNota()); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|