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.

288 lines
11 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.FormUtamaController;
  8. import id.amigogroup.posterminal.pencarian.DialogCariBarangController;
  9. import id.amigogroup.posterminal.pencarian.DialogCetakNotaController;
  10. import id.amigogroup.posterminal.util.AlertUtil;
  11. import id.amigogroup.posterminal.util.Fucout;
  12. import java.io.IOException;
  13. import java.net.URL;
  14. import java.util.ArrayList;
  15. import java.util.HashMap;
  16. import java.util.List;
  17. import java.util.Map;
  18. import java.util.Optional;
  19. import java.util.ResourceBundle;
  20. import java.util.logging.Level;
  21. import java.util.logging.Logger;
  22. import javafx.application.Platform;
  23. import javafx.event.ActionEvent;
  24. import javafx.fxml.FXML;
  25. import javafx.fxml.FXMLLoader;
  26. import javafx.fxml.Initializable;
  27. import javafx.scene.Node;
  28. import javafx.scene.Parent;
  29. import javafx.scene.control.Alert;
  30. import javafx.scene.control.ButtonBar;
  31. import javafx.scene.control.ButtonType;
  32. import javafx.scene.control.CheckBox;
  33. import javafx.scene.control.Dialog;
  34. import javafx.scene.control.Label;
  35. import javafx.scene.input.KeyCode;
  36. import javafx.scene.input.KeyCodeCombination;
  37. import javafx.scene.input.KeyCombination;
  38. import javafx.scene.layout.AnchorPane;
  39. import javafx.scene.layout.VBox;
  40. import javafx.stage.Window;
  41. /**
  42. * FXML Controller class
  43. *
  44. * @author ronal
  45. */
  46. public class DialogSelesaiBayarTidakLunasController extends Dialog implements Initializable, BayarInterface {
  47. @FXML
  48. private AnchorPane apContent;
  49. @FXML
  50. private CheckBox chkTunai;
  51. @FXML
  52. private CheckBox chkKartu;
  53. @FXML
  54. private CheckBox chkPromo;
  55. @FXML
  56. private CheckBox chkRetur;
  57. @FXML
  58. private CheckBox chkGopay;
  59. @FXML
  60. private CheckBox chkOvo;
  61. @FXML
  62. private CheckBox chkPoin;
  63. @FXML
  64. private VBox vbContent;
  65. @FXML
  66. private Label lblPerluBayar;
  67. private BayarInterface parent;
  68. private int kurangBayar;
  69. private List<CheckBox> daftarChkBayarSyarat;
  70. private List<CheckBox> daftarChkBayarOpsional;
  71. public BayarContent bayarContent = new BayarContent();
  72. private FormUtamaController parentFormUtamaController = null;
  73. /**
  74. * Initializes the controller class.
  75. */
  76. @Override
  77. public void initialize(URL url, ResourceBundle rb) {
  78. daftarChkBayarSyarat.add(chkTunai);
  79. daftarChkBayarSyarat.add(chkKartu);
  80. daftarChkBayarOpsional.add(chkPromo);
  81. daftarChkBayarOpsional.add(chkRetur);
  82. daftarChkBayarOpsional.add(chkGopay);
  83. daftarChkBayarOpsional.add(chkOvo);
  84. daftarChkBayarOpsional.add(chkPoin);
  85. getDialogPane().getButtonTypes().add(new ButtonType("Tutup", ButtonBar.ButtonData.CANCEL_CLOSE));
  86. initShortcuts();
  87. }
  88. public void initData(FormUtamaController parent) {
  89. this.parentFormUtamaController = parent;
  90. }
  91. private void initShortcuts() {
  92. Map<KeyCombination, Runnable> listShortcuts = new HashMap<>();
  93. KeyCombination kcSelesaiBayar = new KeyCodeCombination(KeyCode.F10);
  94. Runnable rnSelesaiBayar = () -> {
  95. if (bayarContent.getTotalBayar() >= bayarContent.getTotalPerluBayar()) {
  96. if (parentFormUtamaController != null) {
  97. DialogCetakNotaController dialogCetakNotaController = new DialogCetakNotaController();
  98. dialogCetakNotaController.initOwner(parent.getWindow());
  99. dialogCetakNotaController.initData(
  100. parentFormUtamaController.notaContent.getControllerTunai() != null
  101. ? parentFormUtamaController.notaContent.getControllerTunai().daftarTabelTransaksi : null,
  102. parentFormUtamaController.notaContent.getControllerRetur() != null
  103. ? parentFormUtamaController.notaContent.getControllerRetur().daftarTabelRetur : null,
  104. this);
  105. Optional<String> result = dialogCetakNotaController.showAndWait();
  106. }
  107. } else {
  108. Alert alert = AlertUtil.getAlertWarning(
  109. AlertUtil.DIALOG_UANG_BELUM_CUKUP,
  110. "Nominal yang anda masukan masih kurang");
  111. alert.show();
  112. }
  113. };
  114. listShortcuts.put(kcSelesaiBayar, rnSelesaiBayar);
  115. Platform.runLater(() -> {
  116. apContent.getScene().getAccelerators().putAll(listShortcuts);
  117. });
  118. }
  119. public DialogSelesaiBayarTidakLunasController(BayarInterface parent, int kurangBayar) {
  120. this.daftarChkBayarSyarat = new ArrayList<>();
  121. this.daftarChkBayarOpsional = new ArrayList<>();
  122. this.parent = parent;
  123. bayarContent.setTotalPerluBayar(kurangBayar);
  124. try {
  125. Window window = getDialogPane().getScene().getWindow();
  126. window.setOnCloseRequest(event -> this.close());
  127. FXMLLoader loader = new FXMLLoader(getClass().getResource("/fxml/DialogSelesaiBayarTidakLunas.fxml"));
  128. loader.setController(this);
  129. Parent root = loader.load();
  130. getDialogPane().setContent(root);
  131. setTitle("Pembayaran Belum Lunas!");
  132. lblPerluBayar.setText(Fucout.getTextColon(Fucout.formatRupiah(
  133. bayarContent.getTotalPerluBayar())));
  134. } catch (IOException e) {
  135. Logger.getLogger(DialogCariBarangController.class
  136. .getName()).log(Level.SEVERE, null, e);
  137. }
  138. }
  139. @FXML
  140. void chkPilihanOnAction(ActionEvent event) {
  141. CheckBox chkSource = (CheckBox) event.getSource();
  142. FXMLLoader loader = new FXMLLoader();
  143. Node node = null;
  144. try {
  145. switch (chkSource.getText()) {
  146. case FormBayarController.BAYAR_TUNAI:
  147. if (bayarContent.getNodeTunai() == null && chkSource.selectedProperty().get()) {
  148. loader.setLocation(getClass().getResource("/fxml/FormBayarTunai.fxml"));
  149. node = loader.load();
  150. FormBayarTunaiController fbtc = loader.getController();
  151. fbtc.initData(this);
  152. vbContent.getChildren().add(node);
  153. bayarContent.setNodeTunai(node);
  154. } else {
  155. if (bayarContent.getNodeTunai() != null) {
  156. vbContent.getChildren().remove(bayarContent.getNodeTunai());
  157. bayarContent.setNodeTunai(null);
  158. }
  159. }
  160. break;
  161. case FormBayarController.BAYAR_KARTU:
  162. if (bayarContent.getNodeKartu() == null && chkSource.selectedProperty().get()) {
  163. loader.setLocation(getClass().getResource("/fxml/FormBayarKartu.fxml"));
  164. node = loader.load();
  165. FormBayarKartuController fbkc = loader.getController();
  166. fbkc.initData(this);
  167. vbContent.getChildren().add(node);
  168. bayarContent.setNodeKartu(node);
  169. } else {
  170. if (bayarContent.getNodeKartu() != null) {
  171. vbContent.getChildren().remove(bayarContent.getNodeKartu());
  172. bayarContent.setNodeKartu(null);
  173. }
  174. }
  175. break;
  176. case FormBayarController.BAYAR_RETUR:
  177. if (bayarContent.getNodeRetur() == null && chkSource.selectedProperty().get()) {
  178. loader.setLocation(getClass().getResource("/fxml/FormBayarRetur.fxml"));
  179. node = loader.load();
  180. vbContent.getChildren().add(node);
  181. bayarContent.setNodeRetur(node);
  182. } else {
  183. if (bayarContent.getNodeRetur() != null) {
  184. vbContent.getChildren().remove(bayarContent.getNodeRetur());
  185. bayarContent.setNodeRetur(null);
  186. }
  187. }
  188. break;
  189. case FormBayarController.BAYAR_PROMO:
  190. if (bayarContent.getNodePromo() == null && chkSource.selectedProperty().get()) {
  191. loader.setLocation(getClass().getResource("/fxml/FormBayarVoucherPromo.fxml"));
  192. node = loader.load();
  193. vbContent.getChildren().add(node);
  194. bayarContent.setNodePromo(node);
  195. } else {
  196. if (bayarContent.getNodePromo() != null) {
  197. vbContent.getChildren().remove(bayarContent.getNodePromo());
  198. bayarContent.setNodePromo(null);
  199. }
  200. }
  201. break;
  202. case FormBayarController.BAYAR_GOPAY:
  203. break;
  204. case FormBayarController.BAYAR_OVO:
  205. break;
  206. case FormBayarController.BAYAR_POIN:
  207. if (bayarContent.getNodePoin() == null && chkSource.selectedProperty().get()) {
  208. loader.setLocation(getClass().getResource("/fxml/FormBayarPoin.fxml"));
  209. node = loader.load();
  210. vbContent.getChildren().add(node);
  211. bayarContent.setNodePoin(node);
  212. } else {
  213. if (bayarContent.getNodePoin() != null) {
  214. vbContent.getChildren().remove(bayarContent.getNodePoin());
  215. bayarContent.setNodePoin(null);
  216. }
  217. }
  218. break;
  219. }
  220. if (daftarChkBayarSyarat.contains(chkSource)) {
  221. chkSyaratValueOnChanged();
  222. }
  223. } catch (IOException ex) {
  224. Logger.getLogger(FormBayarController.class.getName()).log(Level.SEVERE, null, ex);
  225. }
  226. }
  227. private void chkSyaratValueOnChanged() {
  228. boolean isSyaratTerpenuhi = false;
  229. for (CheckBox chkSyarat : daftarChkBayarSyarat) {
  230. if (chkSyarat.selectedProperty().get()) {
  231. isSyaratTerpenuhi = true;
  232. break;
  233. }
  234. }
  235. if (isSyaratTerpenuhi) {
  236. for (CheckBox chk : daftarChkBayarOpsional) {
  237. chk.setDisable(false);
  238. }
  239. } else {
  240. for (CheckBox chk : daftarChkBayarOpsional) {
  241. if (chk.selectedProperty().get()) {
  242. chk.fire();
  243. }
  244. chk.setDisable(true);
  245. }
  246. }
  247. }
  248. @Override
  249. public BayarContent getBayarContent() {
  250. return bayarContent;
  251. }
  252. @Override
  253. public void updateKurangBayarView() {
  254. lblPerluBayar.setText(Fucout.getTextColon(Fucout.formatRupiah(
  255. bayarContent.getTotalPerluBayar() - bayarContent.getTotalBayar())));
  256. }
  257. @Override
  258. public Window getWindow() {
  259. return apContent.getScene().getWindow();
  260. }
  261. }