@ -5,9 +5,12 @@
* /
* /
package id.amigogroup.posterminal.transaksi ;
package id.amigogroup.posterminal.transaksi ;
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.Barang ;
import id.amigogroup.posterminal.model.DNotaTunai ;
import id.amigogroup.posterminal.model.DNotaTunai ;
import id.amigogroup.posterminal.model.MNotaTunai ;
import id.amigogroup.posterminal.model.NoBarang ;
import id.amigogroup.posterminal.model.NoBarang ;
import id.amigogroup.posterminal.util.AmigoPosCache ;
import id.amigogroup.posterminal.util.AmigoPosCache ;
import id.amigogroup.posterminal.util.AlertUtil ;
import id.amigogroup.posterminal.util.AlertUtil ;
@ -17,7 +20,10 @@ import io.reactivex.Observer;
import io.reactivex.disposables.Disposable ;
import io.reactivex.disposables.Disposable ;
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.List ;
import java.util.Map ;
import java.util.ResourceBundle ;
import java.util.ResourceBundle ;
import javafx.application.Platform ;
import javafx.application.Platform ;
import javafx.beans.property.ReadOnlyObjectWrapper ;
import javafx.beans.property.ReadOnlyObjectWrapper ;
@ -36,6 +42,8 @@ import javafx.scene.control.TableView;
import javafx.scene.control.TextField ;
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.scene.text.Text ;
import javafx.scene.text.Text ;
@ -90,6 +98,7 @@ public class FormTransaksiTunaiController implements Initializable {
private String noNota = "" ;
private String noNota = "" ;
private AmigoPosRx posRx = new AmigoPosRx ( ) ;
private AmigoPosRx posRx = new AmigoPosRx ( ) ;
public int total = 0 ;
public int total = 0 ;
private FormUtamaController parent ;
/ * *
/ * *
* Initializes the controller class .
* Initializes the controller class .
@ -98,6 +107,7 @@ public class FormTransaksiTunaiController implements Initializable {
public void initialize ( URL url , ResourceBundle rb ) {
public void initialize ( URL url , ResourceBundle rb ) {
Platform . runLater ( ( ) - > {
Platform . runLater ( ( ) - > {
fldScan . requestFocus ( ) ;
fldScan . requestFocus ( ) ;
initShortcuts ( ) ;
} ) ;
} ) ;
tcNo . setCellValueFactory ( ( TableColumn . CellDataFeatures < TabelBarangTunai , Integer > cell ) - > {
tcNo . setCellValueFactory ( ( TableColumn . CellDataFeatures < TabelBarangTunai , Integer > cell ) - > {
@ -119,15 +129,72 @@ public class FormTransaksiTunaiController implements Initializable {
lblGrandTotal . setText ( Fucout . formatRupiah ( 0 ) ) ;
lblGrandTotal . setText ( Fucout . formatRupiah ( 0 ) ) ;
}
}
public void initData ( String noNota , boolean baru ) {
public void initData ( FormUtamaController parent , String noNota , boolean baru ) {
if ( ! baru ) {
if ( ! baru ) {
posRx . getDNotaTunaiByNoNota ( noNota ) . subscribe ( getDNotaTunaiObserver ) ;
posRx . getDNotaTunaiByNoNota ( noNota ) . subscribe ( getDNotaTunaiObserver ) ;
}
}
this . parent = parent ;
this . noNota = noNota ;
this . noNota = noNota ;
lblNoNota . setText ( Fucout . getTextColon ( noNota ) ) ;
lblNoNota . setText ( Fucout . getTextColon ( noNota ) ) ;
setTanggal ( ) ;
setTanggal ( ) ;
}
}
private void initShortcuts ( ) {
Map < KeyCombination , Runnable > listShortcuts = new HashMap < > ( ) ;
KeyCombination kcTundaNota = new KeyCodeCombination ( KeyCode . T , KeyCombination . CONTROL_DOWN ) ;
Runnable rnTundaNota = ( ) - > {
//Tunda Nota
System . out . println ( "Tunda" ) ;
List < DNotaTunai > daftarDNotaTunai = new ArrayList < > ( ) ;
if ( noNota ! = null & & ! noNota . equals ( "" ) ) {
for ( TabelBarangTunai tbt : daftarTabelTransaksi ) {
tbt . getData ( ) . setNoNota ( noNota ) ;
daftarDNotaTunai . add ( tbt . getData ( ) ) ;
}
MNotaTunai mNotaTunai = new MNotaTunai ( ) ;
if ( SystemValue . isMember ) {
mNotaTunai . setKdCustomer ( SystemValue . member . getAlias ( ) ) ;
} else {
mNotaTunai . setKdCustomer ( Fucout . KODE_NON_MEMBER ) ;
}
mNotaTunai . setJumlahTotal ( hitungTotal ( daftarDNotaTunai ) ) ;
mNotaTunai . setKasir ( SystemValue . karyawanLogin . getNik ( ) ) ;
mNotaTunai . setTotalUang ( 0 ) ;
mNotaTunai . setTotalDiskon ( 0 ) ;
mNotaTunai . setStatusBayar ( null ) ;
mNotaTunai . setBank ( null ) ;
mNotaTunai . setEdc ( null ) ;
mNotaTunai . setNoKartu ( null ) ;
mNotaTunai . setNoValidasiBank ( null ) ;
mNotaTunai . setStatusNota ( 'T' ) ;
mNotaTunai . setNoNotaRetur ( null ) ;
mNotaTunai . setJumlahTotalRetur ( null ) ;
mNotaTunai . setJenisDiskon ( null ) ;
mNotaTunai . setJenisHadiah ( null ) ;
mNotaTunai . setTglAmbilhadiah ( null ) ;
mNotaTunai . setUserAmbilhadiah ( null ) ;
Observable . zip (
posRx . addMNotaTunai ( SystemValue . idToko , mNotaTunai ) ,
Observable . just ( daftarDNotaTunai ) ,
( mT , daftarDT ) - > {
NotaWithListDetail < MNotaTunai , DNotaTunai > notaWithListDetail = new NotaWithListDetail < > ( ) ;
notaWithListDetail . setNota ( mT ) ;
notaWithListDetail . setDaftarDetail ( daftarDT ) ;
return notaWithListDetail ;
} ) . subscribe ( postMNotaTunai ) ;
}
} ;
listShortcuts . put ( kcTundaNota , rnTundaNota ) ;
apMain . getScene ( ) . getAccelerators ( ) . putAll ( listShortcuts ) ;
}
public void setTanggal ( ) {
public void setTanggal ( ) {
java . util . Date skrg = new java . util . Date ( ) ;
java . util . Date skrg = new java . util . Date ( ) ;
java . text . SimpleDateFormat kal = new java . text . SimpleDateFormat ( "dd/MM/yyyy" ) ;
java . text . SimpleDateFormat kal = new java . text . SimpleDateFormat ( "dd/MM/yyyy" ) ;
@ -247,7 +314,7 @@ public class FormTransaksiTunaiController implements Initializable {
DNotaTunai dNotaTunai = new DNotaTunai (
DNotaTunai dNotaTunai = new DNotaTunai (
noNota ,
noNota ,
barang . getKodeBarang ( ) ,
barang . getKodeBarang ( ) ,
barang. getNamaBarang ( ) ,
noBarang. getNomor ( ) ,
1 ,
1 ,
0 ,
0 ,
0 ,
0 ,
@ -339,6 +406,7 @@ public class FormTransaksiTunaiController implements Initializable {
}
}
//Observer untuk menampilkan DNotaTunai ke tabel melalui ambil dari checkout
Observer < List < DNotaTunai > > getDNotaTunaiObserver = new Observer < > ( ) {
Observer < List < DNotaTunai > > getDNotaTunaiObserver = new Observer < > ( ) {
@Override
@Override
public void onSubscribe ( Disposable dspsbl ) {
public void onSubscribe ( Disposable dspsbl ) {
@ -373,6 +441,7 @@ public class FormTransaksiTunaiController implements Initializable {
} ;
} ;
//Observer untuk menampilkan data sebuah barang ke tabel, yang sudah mempunyai DNotaTunai
Observer < Barang > getBarangObserver = new Observer < > ( ) {
Observer < Barang > getBarangObserver = new Observer < > ( ) {
@Override
@Override
public void onSubscribe ( Disposable dspsbl ) {
public void onSubscribe ( Disposable dspsbl ) {
@ -413,6 +482,7 @@ public class FormTransaksiTunaiController implements Initializable {
} ;
} ;
//Observer untuk menampilkan data sebuah barang ke tabel, hasil scan tambah baru
Observer < Barang > getTambahBarangObserver = new Observer < > ( ) {
Observer < Barang > getTambahBarangObserver = new Observer < > ( ) {
@Override
@Override
public void onSubscribe ( Disposable dspsbl ) {
public void onSubscribe ( Disposable dspsbl ) {
@ -461,6 +531,7 @@ public class FormTransaksiTunaiController implements Initializable {
} ;
} ;
//Observer untuk menampilkan data no barang ke tabel, hasil scan tambah baru
Observer < BarangFull > getBarangFullGetNoBarangFromBarangObserver = new Observer < > ( ) {
Observer < BarangFull > getBarangFullGetNoBarangFromBarangObserver = new Observer < > ( ) {
@Override
@Override
public void onSubscribe ( Disposable dspsbl ) {
public void onSubscribe ( Disposable dspsbl ) {
@ -493,4 +564,71 @@ public class FormTransaksiTunaiController implements Initializable {
public void onComplete ( ) {
public void onComplete ( ) {
}
}
} ;
} ;
//Observer untuk menambahkan no nota baru
Observer < NotaWithListDetail < MNotaTunai , DNotaTunai > > postMNotaTunai = new Observer < > ( ) {
@Override
public void onSubscribe ( Disposable dspsbl ) {
}
@Override
public void onNext ( NotaWithListDetail < MNotaTunai , DNotaTunai > notaWithListDetail ) {
for ( DNotaTunai dNotaTunai : notaWithListDetail . getDaftarDetail ( ) ) {
MNotaTunai mNotaTunai = notaWithListDetail . getNota ( ) ;
dNotaTunai . setNoNota ( mNotaTunai . getNoNota ( ) ) ;
posRx . addDNotaTunai ( dNotaTunai ) . subscribe ( postDNotaTunai ) ;
}
}
@Override
public void onError ( Throwable error ) {
if ( false ) {
} else {
AmigoPosRx . handleGenericError ( error , apMain . getScene ( ) . getWindow ( ) ) ;
}
}
@Override
public void onComplete ( ) {
}
} ;
Observer < Void > postDNotaTunai = new Observer < Void > ( ) {
@Override
public void onSubscribe ( Disposable dspsbl ) {
}
@Override
public void onNext ( Void v ) {
}
@Override
public void onError ( Throwable error ) {
if ( false ) {
} else {
AmigoPosRx . handleGenericError ( error , apMain . getScene ( ) . getWindow ( ) ) ;
}
}
@Override
public void onComplete ( ) {
Platform . runLater ( ( ) - > {
Alert alert = AlertUtil . getAlertInfo (
"Berhasil Ditunda" ,
"Nota berhasil ditunda!" ) ;
alert . initOwner ( apMain . getScene ( ) . getWindow ( ) ) ;
alert . show ( ) ;
if ( parent ! = null ) {
parent . notaContent . setControllerTunai ( null ) ;
parent . notaContent . setNodeTunai ( null ) ;
parent . removeNota ( parent . notaContent . getBtnTunai ( ) ) ;
}
} ) ;
}
} ;
}
}