@Override public void aksiReset() { code.setText("AUTO"); tgl.setDate(new Date()); clearText(pelanggan); cust = null; clearText(jml); double p = DataUser.getProduct().field(ProductDao.harga); harga.setValue(p); clearText(total1); diskon.setText("0"); diskonp.setText("0.00"); clearText(total); bayar.setText(""); k.setText("0"); kembali.setText("0"); setCursor(); }
public boolean validate(ODatabaseDocumentTx db) { if (!(code.getText().equalsIgnoreCase("AUTO") || code.getText().trim().equalsIgnoreCase(""))) { long tmp = App.getPenjualanDao().getCountByColumn(db, PenjualanDao.code, code.getText()); if (tmp > 0) { codea = ""; App.showErrorDataSudahAda(db, PenjualanDao.fcode); return false; } } codea = code.getText(); tgla = tgl.getDate(); if (tgla == null) { tgl.setDate(new Date()); tgla = new Date(); App.showErrorFieldEmpty(db, PenjualanDao.ftgl); return false; } if (cust == null) { pelanggan.setText(""); App.showErrorFieldEmpty(db, PenjualanDao.fpelanggan); return false; } else { pelanggana = cust; } try { hargaa = Double.parseDouble(harga.getValue() + ""); if (hargaa < 0) { return false; } } catch (Exception e) { harga.setText("1"); try { harga.commitEdit(); } catch (ParseException e1) { } App.printErr(e); return false; } try { jmla = Double.parseDouble(jml.getValue() + ""); if (jmla <= 0) { App.showErrorJumlahTidakFalid(); } } catch (Exception e) { jml.setText(""); App.showErrorFieldEmpty(db, PenjualanDao.fjml); return false; } try { diskon.commitEdit(); diskona = Double.parseDouble(diskon.getValue() + ""); if (diskona < 0) { App.showErrorNotValid(db, PenjualanDao.fdiskon); } } catch (Exception e) { App.showErrorFieldEmpty(db, PenjualanDao.fdiskon); App.printErr(e); return false; } try { diskonp.commitEdit(); diskonpa = Double.parseDouble(diskonp.getValue() + ""); if (diskonpa < 0) { App.showErrorNotValid(db, PenjualanDao.fdiskonp); } } catch (Exception e) { App.showErrorFieldEmpty(db, PenjualanDao.fdiskonp); App.printErr(e); return false; } try { if (bayar.getText().equals("")) { App.showErrorFieldEmpty(db, PenjualanDao.fbayar); return false; } String stmp = bayar.getText().replaceAll("\\,", ""); if (stmp == null || stmp.equalsIgnoreCase("")) { App.showErrorFieldEmpty(db, PenjualanDao.fbayar); return false; } bayara = Double.parseDouble(stmp); if (bayara < 0) { App.showErrorNotValid(db, PenjualanDao.fbayar); } } catch (Exception e) { App.showErrorFieldEmpty(db, PenjualanDao.fbayar); App.printErr(e); return false; } try { k.commitEdit(); ka = Double.parseDouble(k.getValue() + ""); } catch (Exception e) { App.printErr(e); return false; } try { total1.commitEdit(); total1a = Double.parseDouble(total1.getValue() + ""); } catch (Exception e) { App.printErr(e); return false; } try { total.commitEdit(); totala = Double.parseDouble(total.getValue() + ""); } catch (Exception e) { App.printErr(e); return false; } if (ka > 0) { da = bayara; notea = App.getT(db, "Hutang"); } else { da = totala; notea = App.getT(db, "Lunas"); } producta = DataUser.getProduct(); return true; }
public void initComponent(ODatabaseDocumentTx db) { // amountFormat = NumberFormat.getNumberInstance(); // // percentFormat = NumberFormat.getNumberInstance(); // percentFormat.setMinimumFractionDigits(2); listModel = new DefaultListModel(); custList = new JXList(listModel); custList.setHighlighters(HighlighterFactory.createAlternateStriping()); popup = new JPopupMenu(); popup.add(new JScrollPane(custList), BorderLayout.CENTER); code = new TextField(); tgl = new DatePicker(); tgl.setFormats(App.dateFormat); pelanggan = new TextField(); jml = new FormattedTextField(App.paymentFormat); harga = new FormattedTextField(App.paymentFormat); harga.setEditable(false); harga.setBackground(App.whiteSmoke); total1 = new FormattedTextField(App.paymentFormat); total1.setEditable(false); total1.setBackground(App.whiteSmoke); diskon = new FormattedTextField(App.paymentFormat); diskonp = new FormattedTextField(App.paymentFormat2); total = new FormattedTextField(App.paymentFormat); total.setEditable(false); total.setBackground(App.whiteSmoke); bayar = new TextField(); k = new FormattedTextField(App.paymentFormat); k.setEditable(false); k.setBackground(App.whiteSmoke); kembali = new FormattedTextField(App.paymentFormat); kembali.setEditable(false); kembali.setBackground(App.whiteSmoke); Font f = UIManager.getFont("TextField.font"); f2 = f.deriveFont((float) 24.0); total1.setFont(f2); total.setFont(f2); kembali.setFont(f2); harga.setFont(f2); bayar.setFont(f2); jml.setFont(f2); k.setFont(f2); harga.setHorizontalAlignment(SwingConstants.RIGHT); total1.setHorizontalAlignment(SwingConstants.RIGHT); total.setHorizontalAlignment(SwingConstants.RIGHT); diskon.setHorizontalAlignment(SwingConstants.RIGHT); bayar.setHorizontalAlignment(SwingConstants.RIGHT); k.setHorizontalAlignment(SwingConstants.RIGHT); kembali.setHorizontalAlignment(SwingConstants.RIGHT); setFocusEnter(code, tgl.getEditor()); setFocusEnter(tgl.getEditor(), pelanggan); setFocusEnter(jml, diskon); setFocusEnter(diskon, diskonp); setFocusEnter(diskonp, bayar); setFocusEnter(bayar, kembali); kembali.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { save.requestFocus(); } }); pelanggan.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // bila pelanggan null maka menampilkan popup // bila tidak null berarti tidak menampilkan popup // karena dianggap sudah benar, sehingga bila inggin mengganti // menggani harus menghapus terlebih dahulu if (cust == null) { // hapus semua elemaent yang terdapat pada list listModel.removeAllElements(); ODatabaseDocumentTx db = App.getDbd(); ODatabaseRecordThreadLocal.INSTANCE.set(db); // ambil dari database dengan batasan 0-10 List<ODocument> ps = null; try { ps = App.getPelangganDao() .getAllByColumnLike( db, PelangganDao.name, pelanggan.getText() + "%", 0, 50); } catch (Exception e2) { } // cek apakah ps null atau hasilnya kosong // bila kosong maka mengambil 10 default if (ps == null || ps.size() == 0) { ps = App.getPelangganDao().getAll(db, 0, 50); } // masukkan list ps kedalam model // untuk split menggunakan ": " for (ODocument pelanggan : ps) { listModel.addElement( pelanggan.field(PelangganDao.code) + ", " + pelanggan.field(PelangganDao.name)); } // pengaturan preferred size pada jlist // - 19 digunakan untuk scrol custList.setPreferredSize( new Dimension(pelanggan.getSize().width - 4, custList.getPreferredSize().height)); // +8 digunakan untuk meletakkan di bawah persis pd // jtextfiled popup.show(pelanggan, 0, 18); // pengaturan default custList.requestFocus(); custList.setSelectedIndex(0); } } }); custList.addKeyListener( new KeyAdapter() { @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == 10) { popup.setVisible(false); if (custList.getSelectedIndex() != -1) { String tmp = (String) listModel.getElementAt(custList.getSelectedIndex()); if (tmp != null) { pelanggan.setText(tmp); jml.requestFocus(); } } listModel.removeAllElements(); } } }); pelanggan.addFocusListener( new FocusListener() { @Override public void focusLost(FocusEvent e) { String value = pelanggan.getText(); String[] split = ((String) value).split(", "); ODatabaseDocumentTx db = App.getDbd(); ODatabaseRecordThreadLocal.INSTANCE.set(db); try { String id = split[0]; cust = App.getPelangganDao().getOne(db, PelangganDao.code, id); } catch (Exception ex) { cust = null; } finally { db.close(); } if (cust == null) { pelanggan.setText(""); } } @Override public void focusGained(FocusEvent e) { harga.setValue(DataUser.getProduct().field(ProductDao.harga)); } }); jml.addFocusListener( new FocusListener() { @Override public void focusLost(FocusEvent e) { ODatabaseDocumentTx db = App.getDbd(); ODatabaseRecordThreadLocal.INSTANCE.set(db); if (jml.getText().equalsIgnoreCase("")) { App.showErrorFieldEmpty(db, "Jumlah"); jml.setText("1"); jml.requestFocus(); jml.selectAll(); } else { try { int tmp = Integer.parseInt(jml.getText()); if (tmp == 0) { App.showErrorFieldEmpty(db, "Jumlah"); jml.setText("1"); jml.requestFocus(); jml.selectAll(); } } catch (Exception e2) { App.showErrorFieldEmpty(db, "Jumlah"); jml.setText("1"); jml.requestFocus(); jml.selectAll(); } autoHarga(); } } @Override public void focusGained(FocusEvent e) {} }); diskon.addFocusListener( new FocusListener() { @Override public void focusLost(FocusEvent e) { autoHarga(); } @Override public void focusGained(FocusEvent e) { diskon.selectAll(); } }); diskonp.addFocusListener( new FocusListener() { @Override public void focusLost(FocusEvent e) { autoHarga(); } @Override public void focusGained(FocusEvent e) { diskonp.selectAll(); } }); bayar.addFocusListener( new FocusListener() { @Override public void focusLost(FocusEvent e) { autoKembali(); } @Override public void focusGained(FocusEvent e) { bayar.selectAll(); } }); bayar.addKeyListener( new KeyListener() { @Override public void keyTyped(KeyEvent e) {} @Override public void keyReleased(KeyEvent e) { String tmp = bayar.getText(); try { if (tmp != null && !tmp.equalsIgnoreCase("")) { double tmp2 = Double.parseDouble(tmp.replaceAll("\\,", "")); bayar.setText(App.paymentFormat.format(tmp2)); } } catch (Exception e2) { App.printErr(e2); bayar.setText(""); } } @Override public void keyPressed(KeyEvent e) {} }); save = new JButton(App.getT(db, "Save")); save.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { aksiSave(); } }); reset = new JButton(App.getT(db, "Reset")); reset.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { aksiReset(); } }); }