Aplikasi POS Amigo, dibangun dengan JavaFX dengan Maven
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

261 行
9.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.DialogCetakNotaController;
  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.HashMap;
  13. import java.util.List;
  14. import java.util.Map;
  15. import java.util.Optional;
  16. import java.util.ResourceBundle;
  17. import java.util.logging.Level;
  18. import java.util.logging.Logger;
  19. import javafx.application.Platform;
  20. import javafx.event.ActionEvent;
  21. import javafx.fxml.FXML;
  22. import javafx.fxml.FXMLLoader;
  23. import javafx.fxml.Initializable;
  24. import javafx.scene.Node;
  25. import javafx.scene.control.CheckBox;
  26. import javafx.scene.control.Label;
  27. import javafx.scene.input.KeyCode;
  28. import javafx.scene.input.KeyCodeCombination;
  29. import javafx.scene.input.KeyCombination;
  30. import javafx.scene.layout.AnchorPane;
  31. import javafx.scene.layout.VBox;
  32. /**
  33. * FXML Controller class
  34. *
  35. * @author ronal
  36. */
  37. public class FormBayarController implements Initializable, BayarInterface {
  38. @FXML
  39. private AnchorPane apContent;
  40. @FXML
  41. private CheckBox chkTunai;
  42. @FXML
  43. private CheckBox chkKartu;
  44. @FXML
  45. private CheckBox chkPromo;
  46. @FXML
  47. private CheckBox chkRetur;
  48. @FXML
  49. private CheckBox chkGopay;
  50. @FXML
  51. private CheckBox chkOvo;
  52. @FXML
  53. private CheckBox chkPoin;
  54. @FXML
  55. private Label lblKurangBayar;
  56. @FXML
  57. private VBox vbContent;
  58. @FXML
  59. private Label lblGrandTotal;
  60. private final List<CheckBox> daftarChkBayarSyarat;
  61. private final List<CheckBox> daftarChkBayarOpsional;
  62. public BayarContent bayarContent = new BayarContent();
  63. public FormBayarController() {
  64. daftarChkBayarSyarat = new ArrayList<>();
  65. daftarChkBayarOpsional = new ArrayList<>();
  66. }
  67. /**
  68. * Initializes the controller class.
  69. */
  70. @Override
  71. public void initialize(URL url, ResourceBundle rb) {
  72. lblGrandTotal.setText(Fucout.formatRupiah(bayarContent.getTotalPerluBayar()));
  73. lblKurangBayar.setText(Fucout.formatRupiah(bayarContent.getTotalPerluBayar()));
  74. daftarChkBayarSyarat.add(chkTunai);
  75. daftarChkBayarSyarat.add(chkKartu);
  76. daftarChkBayarOpsional.add(chkPromo);
  77. daftarChkBayarOpsional.add(chkRetur);
  78. daftarChkBayarOpsional.add(chkGopay);
  79. daftarChkBayarOpsional.add(chkOvo);
  80. daftarChkBayarOpsional.add(chkPoin);
  81. initShortcuts();
  82. }
  83. private void initShortcuts() {
  84. Map<KeyCombination, Runnable> listShortcuts = new HashMap<>();
  85. KeyCombination kcSelesaiBayar = new KeyCodeCombination(KeyCode.F10);
  86. Runnable rnSelesaiBayar = () -> {
  87. if (bayarContent.getTotalBayar() >= bayarContent.getTotalPerluBayar()) {
  88. } else {
  89. DialogSelesaiBayarTidakLunasController dsbtlc
  90. = new DialogSelesaiBayarTidakLunasController(this,
  91. bayarContent.getTotalPerluBayar()
  92. - bayarContent.getTotalBayar());
  93. dsbtlc.initOwner(apContent.getScene().getWindow());
  94. dsbtlc.show();
  95. }
  96. };
  97. listShortcuts.put(kcSelesaiBayar, rnSelesaiBayar);
  98. Platform.runLater(() -> {
  99. apContent.getScene().getAccelerators().putAll(listShortcuts);
  100. });
  101. }
  102. @FXML
  103. void chkPilihanOnAction(ActionEvent event) {
  104. CheckBox chkSource = (CheckBox) event.getSource();
  105. FXMLLoader loader = new FXMLLoader();
  106. Node node = null;
  107. try {
  108. switch (chkSource.getText()) {
  109. case BAYAR_TUNAI:
  110. if (bayarContent.getNodeTunai() == null && chkSource.selectedProperty().get()) {
  111. loader.setLocation(getClass().getResource("/fxml/FormBayarTunai.fxml"));
  112. node = loader.load();
  113. vbContent.getChildren().add(node);
  114. bayarContent.setNodeTunai(node);
  115. FormBayarTunaiController fbtc = loader.getController();
  116. fbtc.initData(this);
  117. } else {
  118. if (bayarContent.getNodeTunai() != null) {
  119. vbContent.getChildren().remove(bayarContent.getNodeTunai());
  120. bayarContent.setNodeTunai(null);
  121. bayarContent.setBayarTunai(0);
  122. updateKurangBayarView();
  123. }
  124. }
  125. break;
  126. case BAYAR_KARTU:
  127. if (bayarContent.getNodeKartu() == null && chkSource.selectedProperty().get()) {
  128. loader.setLocation(getClass().getResource("/fxml/FormBayarKartu.fxml"));
  129. node = loader.load();
  130. vbContent.getChildren().add(node);
  131. bayarContent.setNodeKartu(node);
  132. FormBayarKartuController fbkc = loader.getController();
  133. fbkc.initData(this);
  134. } else {
  135. if (bayarContent.getNodeKartu() != null) {
  136. vbContent.getChildren().remove(bayarContent.getNodeKartu());
  137. bayarContent.setNodeKartu(null);
  138. bayarContent.setBayarKartu(0);
  139. updateKurangBayarView();
  140. }
  141. }
  142. break;
  143. case BAYAR_RETUR:
  144. if (bayarContent.getNodeRetur() == null && chkSource.selectedProperty().get()) {
  145. loader.setLocation(getClass().getResource("/fxml/FormBayarRetur.fxml"));
  146. node = loader.load();
  147. vbContent.getChildren().add(node);
  148. bayarContent.setNodeRetur(node);
  149. FormBayarReturController fbrc = loader.getController();
  150. fbrc.initData(this);
  151. } else {
  152. if (bayarContent.getNodeRetur() != null) {
  153. vbContent.getChildren().remove(bayarContent.getNodeRetur());
  154. bayarContent.setNodeRetur(null);
  155. bayarContent.setBayarRetur(0);
  156. updateKurangBayarView();
  157. }
  158. }
  159. break;
  160. case BAYAR_PROMO:
  161. if (bayarContent.getNodePromo() == null && chkSource.selectedProperty().get()) {
  162. loader.setLocation(getClass().getResource("/fxml/FormBayarVoucherPromo.fxml"));
  163. node = loader.load();
  164. vbContent.getChildren().add(node);
  165. bayarContent.setNodePromo(node);
  166. } else {
  167. if (bayarContent.getNodePromo() != null) {
  168. vbContent.getChildren().remove(bayarContent.getNodePromo());
  169. bayarContent.setNodePromo(null);
  170. bayarContent.setBayarPromo(0);
  171. updateKurangBayarView();
  172. }
  173. }
  174. break;
  175. case BAYAR_GOPAY:
  176. break;
  177. case BAYAR_OVO:
  178. break;
  179. case BAYAR_POIN:
  180. if (bayarContent.getNodePoin() == null && chkSource.selectedProperty().get()) {
  181. loader.setLocation(getClass().getResource("/fxml/FormBayarPoin.fxml"));
  182. node = loader.load();
  183. vbContent.getChildren().add(node);
  184. bayarContent.setNodePoin(node);
  185. FormBayarPoinController fbpc = loader.getController();
  186. fbpc.initData(this);
  187. } else {
  188. if (bayarContent.getNodePoin() != null) {
  189. vbContent.getChildren().remove(bayarContent.getNodePoin());
  190. bayarContent.setNodePoin(null);
  191. bayarContent.setBayarPoin(0);
  192. updateKurangBayarView();
  193. }
  194. }
  195. break;
  196. }
  197. if (daftarChkBayarSyarat.contains(chkSource)) {
  198. chkSyaratValueOnChanged();
  199. }
  200. } catch (IOException ex) {
  201. Logger.getLogger(FormBayarController.class.getName()).log(Level.SEVERE, null, ex);
  202. }
  203. }
  204. private void chkSyaratValueOnChanged() {
  205. boolean isSyaratTerpenuhi = false;
  206. for (CheckBox chkSyarat : daftarChkBayarSyarat) {
  207. if (chkSyarat.selectedProperty().get()) {
  208. isSyaratTerpenuhi = true;
  209. break;
  210. }
  211. }
  212. if (isSyaratTerpenuhi) {
  213. for (CheckBox chk : daftarChkBayarOpsional) {
  214. chk.setDisable(false);
  215. }
  216. } else {
  217. for (CheckBox chk : daftarChkBayarOpsional) {
  218. if (chk.selectedProperty().get()) {
  219. chk.fire();
  220. }
  221. chk.setDisable(true);
  222. }
  223. }
  224. }
  225. @Override
  226. public BayarContent getBayarContent() {
  227. return bayarContent;
  228. }
  229. @Override
  230. public void updateKurangBayarView() {
  231. lblKurangBayar.setText(Fucout.formatRupiah(
  232. bayarContent.getTotalPerluBayar() - bayarContent.getTotalBayar()));
  233. }
  234. }