Aplikasi POS Amigo, dibangun dengan JavaFX dengan Maven
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

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