Aplikasi POS Amigo, dibangun dengan JavaFX dengan Maven
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

230 lines
8.6 KiB

  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package id.amigogroup.posterminal.bayar;
  7. import id.amigogroup.posterminal.pencarian.DialogCariBarangController;
  8. import id.amigogroup.posterminal.util.Fucout;
  9. import java.io.IOException;
  10. import java.net.URL;
  11. import java.util.ArrayList;
  12. import java.util.List;
  13. import java.util.ResourceBundle;
  14. import java.util.logging.Level;
  15. import java.util.logging.Logger;
  16. import javafx.event.ActionEvent;
  17. import javafx.fxml.FXML;
  18. import javafx.fxml.FXMLLoader;
  19. import javafx.fxml.Initializable;
  20. import javafx.scene.Node;
  21. import javafx.scene.Parent;
  22. import javafx.scene.control.ButtonBar;
  23. import javafx.scene.control.ButtonType;
  24. import javafx.scene.control.CheckBox;
  25. import javafx.scene.control.Dialog;
  26. import javafx.scene.control.Label;
  27. import javafx.scene.layout.VBox;
  28. import javafx.stage.Window;
  29. /**
  30. * FXML Controller class
  31. *
  32. * @author ronal
  33. */
  34. public class DialogSelesaiBayarTidakLunasController extends Dialog implements Initializable, BayarInterface {
  35. @FXML
  36. private CheckBox chkTunai;
  37. @FXML
  38. private CheckBox chkKartu;
  39. @FXML
  40. private CheckBox chkPromo;
  41. @FXML
  42. private CheckBox chkRetur;
  43. @FXML
  44. private CheckBox chkGopay;
  45. @FXML
  46. private CheckBox chkOvo;
  47. @FXML
  48. private CheckBox chkPoin;
  49. @FXML
  50. private VBox vbContent;
  51. @FXML
  52. private Label lblPerluBayar;
  53. private BayarInterface parent;
  54. private int kurangBayar;
  55. private List<CheckBox> daftarChkBayarSyarat;
  56. private List<CheckBox> daftarChkBayarOpsional;
  57. public BayarContent bayarContent = new BayarContent();
  58. /**
  59. * Initializes the controller class.
  60. */
  61. @Override
  62. public void initialize(URL url, ResourceBundle rb) {
  63. daftarChkBayarSyarat.add(chkTunai);
  64. daftarChkBayarSyarat.add(chkKartu);
  65. daftarChkBayarOpsional.add(chkPromo);
  66. daftarChkBayarOpsional.add(chkRetur);
  67. daftarChkBayarOpsional.add(chkGopay);
  68. daftarChkBayarOpsional.add(chkOvo);
  69. daftarChkBayarOpsional.add(chkPoin);
  70. getDialogPane().getButtonTypes().add(new ButtonType("Tutup", ButtonBar.ButtonData.CANCEL_CLOSE));
  71. }
  72. public DialogSelesaiBayarTidakLunasController(BayarInterface parent, int kurangBayar) {
  73. this.daftarChkBayarSyarat = new ArrayList<>();
  74. this.daftarChkBayarOpsional = new ArrayList<>();
  75. this.parent = parent;
  76. bayarContent.setTotalPerluBayar(kurangBayar);
  77. try {
  78. Window window = getDialogPane().getScene().getWindow();
  79. window.setOnCloseRequest(event -> this.close());
  80. FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/DialogSelesaiBayarTidakLunas.fxml"));
  81. loader.setController(this);
  82. Parent root = loader.load();
  83. getDialogPane().setContent(root);
  84. setTitle("Pembayaran Belum Lunas!");
  85. lblPerluBayar.setText(Fucout.getTextColon(Fucout.formatRupiah(
  86. bayarContent.getTotalPerluBayar())));
  87. } catch (IOException e) {
  88. Logger.getLogger(DialogCariBarangController.class
  89. .getName()).log(Level.SEVERE, null, e);
  90. }
  91. }
  92. @FXML
  93. void chkPilihanOnAction(ActionEvent event) {
  94. CheckBox chkSource = (CheckBox) event.getSource();
  95. FXMLLoader loader = new FXMLLoader();
  96. Node node = null;
  97. try {
  98. switch (chkSource.getText()) {
  99. case FormBayarController.BAYAR_TUNAI:
  100. if (bayarContent.getNodeTunai() == null && chkSource.selectedProperty().get()) {
  101. loader.setLocation(getClass().getResource("/fxml/FormBayarTunai.fxml"));
  102. node = loader.load();
  103. FormBayarTunaiController fbtc = loader.getController();
  104. fbtc.initData(this);
  105. vbContent.getChildren().add(node);
  106. bayarContent.setNodeTunai(node);
  107. } else {
  108. if (bayarContent.getNodeTunai() != null) {
  109. vbContent.getChildren().remove(bayarContent.getNodeTunai());
  110. bayarContent.setNodeTunai(null);
  111. }
  112. }
  113. break;
  114. case FormBayarController.BAYAR_KARTU:
  115. if (bayarContent.getNodeKartu() == null && chkSource.selectedProperty().get()) {
  116. loader.setLocation(getClass().getResource("/fxml/FormBayarKartu.fxml"));
  117. node = loader.load();
  118. vbContent.getChildren().add(node);
  119. bayarContent.setNodeKartu(node);
  120. } else {
  121. if (bayarContent.getNodeKartu() != null) {
  122. vbContent.getChildren().remove(bayarContent.getNodeKartu());
  123. bayarContent.setNodeKartu(null);
  124. }
  125. }
  126. break;
  127. case FormBayarController.BAYAR_RETUR:
  128. if (bayarContent.getNodeRetur() == null && chkSource.selectedProperty().get()) {
  129. loader.setLocation(getClass().getResource("/fxml/FormBayarRetur.fxml"));
  130. node = loader.load();
  131. vbContent.getChildren().add(node);
  132. bayarContent.setNodeRetur(node);
  133. } else {
  134. if (bayarContent.getNodeRetur() != null) {
  135. vbContent.getChildren().remove(bayarContent.getNodeRetur());
  136. bayarContent.setNodeRetur(null);
  137. }
  138. }
  139. break;
  140. case FormBayarController.BAYAR_PROMO:
  141. if (bayarContent.getNodePromo() == null && chkSource.selectedProperty().get()) {
  142. loader.setLocation(getClass().getResource("/fxml/FormBayarVoucherPromo.fxml"));
  143. node = loader.load();
  144. vbContent.getChildren().add(node);
  145. bayarContent.setNodePromo(node);
  146. } else {
  147. if (bayarContent.getNodePromo() != null) {
  148. vbContent.getChildren().remove(bayarContent.getNodePromo());
  149. bayarContent.setNodePromo(null);
  150. }
  151. }
  152. break;
  153. case FormBayarController.BAYAR_GOPAY:
  154. break;
  155. case FormBayarController.BAYAR_OVO:
  156. break;
  157. case FormBayarController.BAYAR_POIN:
  158. if (bayarContent.getNodePoin() == null && chkSource.selectedProperty().get()) {
  159. loader.setLocation(getClass().getResource("/fxml/FormBayarPoin.fxml"));
  160. node = loader.load();
  161. vbContent.getChildren().add(node);
  162. bayarContent.setNodePoin(node);
  163. } else {
  164. if (bayarContent.getNodePoin() != null) {
  165. vbContent.getChildren().remove(bayarContent.getNodePoin());
  166. bayarContent.setNodePoin(null);
  167. }
  168. }
  169. break;
  170. }
  171. if (daftarChkBayarSyarat.contains(chkSource)) {
  172. chkSyaratValueOnChanged();
  173. }
  174. } catch (IOException ex) {
  175. Logger.getLogger(FormBayarController.class.getName()).log(Level.SEVERE, null, ex);
  176. }
  177. }
  178. private void chkSyaratValueOnChanged() {
  179. boolean isSyaratTerpenuhi = false;
  180. for (CheckBox chkSyarat : daftarChkBayarSyarat) {
  181. if (chkSyarat.selectedProperty().get()) {
  182. isSyaratTerpenuhi = true;
  183. break;
  184. }
  185. }
  186. if (isSyaratTerpenuhi) {
  187. for (CheckBox chk : daftarChkBayarOpsional) {
  188. chk.setDisable(false);
  189. }
  190. } else {
  191. for (CheckBox chk : daftarChkBayarOpsional) {
  192. if (chk.selectedProperty().get()) {
  193. chk.fire();
  194. }
  195. chk.setDisable(true);
  196. }
  197. }
  198. }
  199. @Override
  200. public BayarContent getBayarContent() {
  201. return bayarContent;
  202. }
  203. @Override
  204. public void updateKurangBayarView() {
  205. lblPerluBayar.setText(Fucout.getTextColon(Fucout.formatRupiah(
  206. bayarContent.getTotalPerluBayar() - bayarContent.getTotalBayar())));
  207. }
  208. }