1 14 package org.compiere.apps.form; 15 16 import java.awt.*; 17 import java.awt.event.*; 18 import java.sql.*; 19 import javax.swing.*; 20 import java.text.*; 21 import java.math.*; 22 23 import org.compiere.util.*; 24 import org.compiere.apps.*; 25 import org.compiere.grid.ed.*; 26 import org.compiere.model.*; 27 import org.compiere.print.*; 28 import org.compiere.plaf.*; 29 import org.compiere.swing.*; 30 31 37 public class VPayPrint extends CPanel 38 implements FormPanel, ActionListener 39 { 40 41 42 45 public VPayPrint() 46 { 47 } 49 54 public void init (int WindowNo, FormFrame frame) 55 { 56 Log.trace(Log.l1_User, "VPayPrint.init"); 57 m_WindowNo = WindowNo; 58 m_frame = frame; 59 try 60 { 61 jbInit(); 62 dynInit(); 63 frame.getContentPane().add(centerPanel, BorderLayout.CENTER); 64 frame.getContentPane().add(southPanel, BorderLayout.SOUTH); 65 } 66 catch(Exception e) 67 { 68 Log.error("VPayPrint.init", e); 69 } 70 } 72 73 private int m_WindowNo = 0; 74 75 private FormFrame m_frame; 76 77 private int m_C_BankAccount_ID = -1; 78 79 80 private MPaySelectionCheck[] m_checks = null; 81 82 private CPanel centerPanel = new CPanel(); 84 private CPanel southPanel = new CPanel(); 85 private FlowLayout southLayout = new FlowLayout(); 86 private GridBagLayout centerLayout = new GridBagLayout(); 87 private JButton bPrint = ConfirmPanel.createPrintButton(true); 88 private JButton bExport = ConfirmPanel.createExportButton(true); 89 private JButton bCancel = ConfirmPanel.createCancelButton(true); 90 private JButton bProcess = ConfirmPanel.createProcessButton(Msg.getMsg(Env.getCtx(), "VPayPrintProcess")); 91 private CLabel lPaySelect = new CLabel(); 92 private CComboBox fPaySelect = new CComboBox(); 93 private CLabel lBank = new CLabel(); 94 private CLabel fBank = new CLabel(); 95 private CLabel lPaymentRule = new CLabel(); 96 private CComboBox fPaymentRule = new CComboBox(); 97 private CLabel lDocumentNo = new CLabel(); 98 private VNumber fDocumentNo = new VNumber(); 99 private CLabel lNoPayments = new CLabel(); 100 private CLabel fNoPayments = new CLabel(); 101 private CLabel lBalance = new CLabel(); 102 private VNumber fBalance = new VNumber(); 103 private CLabel lCurrency = new CLabel(); 104 private CLabel fCurrency = new CLabel(); 105 106 110 private void jbInit() throws Exception 111 { 112 CompiereColor.setBackground(this); 113 southPanel.setLayout(southLayout); 115 southLayout.setAlignment(FlowLayout.RIGHT); 116 centerPanel.setLayout(centerLayout); 117 bPrint.addActionListener(this); 119 bExport.addActionListener(this); 120 bCancel.addActionListener(this); 121 bProcess.setText(Msg.getMsg(Env.getCtx(), "EFT")); 123 bProcess.setEnabled(false); 124 bProcess.addActionListener(this); 125 lPaySelect.setText(Msg.translate(Env.getCtx(), "C_PaySelection_ID")); 127 fPaySelect.addActionListener(this); 128 lBank.setText(Msg.translate(Env.getCtx(), "C_BankAccount_ID")); 130 lPaymentRule.setText(Msg.translate(Env.getCtx(), "PaymentRule")); 132 fPaymentRule.addActionListener(this); 133 lDocumentNo.setText(Msg.translate(Env.getCtx(), "DocumentNo")); 135 fDocumentNo.setDisplayType(DisplayType.Integer); 136 lNoPayments.setText(Msg.getMsg(Env.getCtx(), "NoOfPayments")); 137 fNoPayments.setText("0"); 138 lBalance.setText(Msg.translate(Env.getCtx(), "CurrentBalance")); 139 fBalance.setReadWrite(false); 140 fBalance.setDisplayType(DisplayType.Amount); 141 lCurrency.setText(Msg.translate(Env.getCtx(), "C_Currency_ID")); 142 southPanel.add(bCancel, null); 144 southPanel.add(bExport, null); 145 southPanel.add(bPrint, null); 146 southPanel.add(bProcess, null); 147 centerPanel.add(lPaySelect, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 149 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(12, 12, 5, 5), 0, 0)); 150 centerPanel.add(fPaySelect, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0 151 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(12, 0, 5, 12), 0, 0)); 152 centerPanel.add(lBank, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 153 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0)); 154 centerPanel.add(fBank, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0 155 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 12), 0, 0)); 156 centerPanel.add(lPaymentRule, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0 157 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0)); 158 centerPanel.add(fPaymentRule, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0 159 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 12), 0, 0)); 160 centerPanel.add(lDocumentNo, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0 161 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0)); 162 centerPanel.add(fDocumentNo, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0 163 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 12), 0, 0)); 164 centerPanel.add(lNoPayments, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0 165 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0)); 166 centerPanel.add(fNoPayments, new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0 167 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 12), 0, 0)); 168 centerPanel.add(lBalance, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0 169 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 5, 5), 0, 0)); 170 centerPanel.add(fBalance, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0 171 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 5, 12), 0, 0)); 172 centerPanel.add(lCurrency, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0 173 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 12, 12, 5), 0, 0)); 174 centerPanel.add(fCurrency, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0 175 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 12, 12), 0, 0)); 176 } 178 181 private void dynInit() 182 { 183 Log.trace(Log.l3_Util, "VPayPrint.dynInit"); 184 int AD_Client_ID = Integer.parseInt(Env.getContext(Env.getCtx(), "#AD_Client_ID")); 185 186 String sql = "SELECT C_PaySelection_ID, Name || ' - ' || TotalAmt FROM C_PaySelection " 188 + "WHERE AD_Client_ID=? AND Processed='Y' AND IsActive='Y'" 189 + "ORDER BY PayDate DESC"; 190 try 191 { 192 PreparedStatement pstmt = DB.prepareStatement(sql); 193 pstmt.setInt(1, AD_Client_ID); 194 ResultSet rs = pstmt.executeQuery(); 195 while (rs.next()) 197 { 198 KeyNamePair pp = new KeyNamePair(rs.getInt(1), rs.getString(2)); 199 fPaySelect.addItem(pp); 200 } 201 rs.close(); 202 pstmt.close(); 203 } 204 catch (SQLException e) 205 { 206 Log.error("VPayPrint.dynInit", e); 207 } 208 if (fPaySelect.getItemCount() == 0) 209 ADialog.info(m_WindowNo, this, "VPayPrintNoRecords"); 210 } 212 215 public void dispose() 216 { 217 m_frame.dispose(); 218 } 220 221 222 226 public void actionPerformed(ActionEvent e) 227 { 228 if (e.getSource() == fPaySelect) 230 loadPaySelectInfo(); 231 else if (e.getSource() == fPaymentRule) 232 loadPaymentRuleInfo(); 233 else if (e.getSource() == bCancel) 235 dispose(); 236 else if (e.getSource() == bExport) 237 cmd_export(); 238 else if (e.getSource() == bProcess) 239 cmd_EFT(); 240 else if (e.getSource() == bPrint) 241 cmd_print(); 242 } 244 247 private void loadPaySelectInfo() 248 { 249 Log.trace(Log.l1_User, "VPayPrint.loadPaySelectInfo"); 250 if (fPaySelect.getSelectedIndex() == -1) 251 return; 252 253 int C_PaySelection_ID = ((KeyNamePair)fPaySelect.getSelectedItem()).getKey(); 255 m_C_BankAccount_ID = -1; 256 String sql = "SELECT ps.C_BankAccount_ID, b.Name || ' ' || ba.AccountNo," + " c.ISO_Code, CurrentBalance " + "FROM C_PaySelection ps" 259 + " INNER JOIN C_BankAccount ba ON (ps.C_BankAccount_ID=ba.C_BankAccount_ID)" 260 + " INNER JOIN C_Bank b ON (ba.C_Bank_ID=b.C_Bank_ID)" 261 + " INNER JOIN C_Currency c ON (ba.C_Currency_ID=c.C_Currency_ID) " 262 + "WHERE ps.C_PaySelection_ID=? AND ps.Processed='Y' AND ba.IsActive='Y'"; 263 try 264 { 265 PreparedStatement pstmt = DB.prepareStatement(sql); 266 pstmt.setInt(1, C_PaySelection_ID); 267 ResultSet rs = pstmt.executeQuery(); 268 if (rs.next()) 269 { 270 m_C_BankAccount_ID = rs.getInt(1); 271 fBank.setText(rs.getString(2)); 272 fCurrency.setText(rs.getString(3)); 273 fBalance.setValue(rs.getBigDecimal(4)); 274 } 275 else 276 { 277 m_C_BankAccount_ID = -1; 278 fBank.setText(""); 279 fCurrency.setText(""); 280 fBalance.setValue(Env.ZERO); 281 Log.error("VPayPrint.loadPaySelectInfo - No active BankAccount for C_PaySelection_ID=" + C_PaySelection_ID); 282 } 283 rs.close(); 284 pstmt.close(); 285 } 286 catch (SQLException e) 287 { 288 Log.error("VPayPrint.loadPaySelectInfo", e); 289 } 290 loadPaymentRule(); 291 } 293 296 private void loadPaymentRule() 297 { 298 Log.trace(Log.l1_User, "VPayPrint.loadPaymentRule"); 299 if (m_C_BankAccount_ID == -1) 300 return; 301 302 int C_PaySelection_ID = ((KeyNamePair)fPaySelect.getSelectedItem()).getKey(); 304 fPaymentRule.removeAllItems(); 305 int AD_Reference_ID = 195; Language language = Language.getLanguage(Env.getAD_Language(Env.getCtx())); 307 MLookupInfo info = MLookupFactory.getLookup_List(language, AD_Reference_ID); 308 String sql = info.Query.substring(0, info.Query.indexOf(" ORDER BY")) 309 + " AND " + info.KeyColumn 310 + " IN (SELECT PaymentRule FROM C_PaySelectionCheck WHERE C_PaySelection_ID=?) " 311 + info.Query.substring(info.Query.indexOf(" ORDER BY")); 312 try 313 { 314 PreparedStatement pstmt = DB.prepareStatement(sql); 315 pstmt.setInt(1, C_PaySelection_ID); 316 ResultSet rs = pstmt.executeQuery(); 317 while (rs.next()) 319 { 320 ValueNamePair pp = new ValueNamePair(rs.getString(2), rs.getString(3)); 321 fPaymentRule.addItem(pp); 322 } 323 rs.close(); 324 pstmt.close(); 325 } 326 catch (SQLException e) 327 { 328 Log.error("VPayPrint.loadPayBankInfo - SQL=" + sql, e); 329 } 330 if (fPaymentRule.getItemCount() == 0) 331 Log.trace(Log.l3_Util, "PaySel=" + C_PaySelection_ID + ", BAcct=" + m_C_BankAccount_ID, sql); 332 loadPaymentRuleInfo(); 333 } 335 339 private void loadPaymentRuleInfo() 340 { 341 ValueNamePair pp = (ValueNamePair)fPaymentRule.getSelectedItem(); 342 if (pp == null) 343 return; 344 String PaymentRule = pp.getValue(); 345 346 Log.trace(Log.l1_User, "VPayPrint.loadPaymentRuleInfo", "PaymentRule=" + PaymentRule); 347 fNoPayments.setText(" "); 348 349 int C_PaySelection_ID = ((KeyNamePair)fPaySelect.getSelectedItem()).getKey(); 350 String sql = "SELECT COUNT(*) " 351 + "FROM C_PaySelectionCheck " 352 + "WHERE C_PaySelection_ID=?"; 353 try 354 { 355 PreparedStatement pstmt = DB.prepareStatement(sql); 356 pstmt.setInt(1, C_PaySelection_ID); 357 ResultSet rs = pstmt.executeQuery(); 358 if (rs.next()) 360 fNoPayments.setText(String.valueOf(rs.getInt(1))); 361 rs.close(); 362 pstmt.close(); 363 } 364 catch (SQLException e) 365 { 366 Log.error("VPayPrint.loadPaymentRuleInfo", e); 367 } 368 bProcess.setEnabled(PaymentRule.equals("T")); 369 370 sql = "SELECT CurrentNext " 372 + "FROM C_BankAccountDoc " 373 + "WHERE C_BankAccount_ID=? AND PaymentRule=? AND IsActive='Y'"; 374 try 375 { 376 PreparedStatement pstmt = DB.prepareStatement(sql); 377 pstmt.setInt(1, m_C_BankAccount_ID); 378 pstmt.setString(2, PaymentRule); 379 ResultSet rs = pstmt.executeQuery(); 380 if (rs.next()) 382 fDocumentNo.setValue(new Integer (rs.getInt(1))); 383 else 384 { 385 Log.error ("VPayPrint.loadPaymentRuleInfo - No active BankAccountDoc for C_BankAccount_ID=" 386 + m_C_BankAccount_ID + " AND PaymentRule=" + PaymentRule); 387 ADialog.error (m_WindowNo, this, "VPayPrintNoDoc"); 388 } 389 rs.close(); 390 pstmt.close(); 391 } 392 catch (SQLException e) 393 { 394 Log.error("VPayPrint.loadPaymentRuleInfo ba", e); 395 } 396 } 398 399 400 401 404 private void cmd_export() 405 { 406 String PaymentRule = ((ValueNamePair)fPaymentRule.getSelectedItem()).getValue(); 407 Log.trace(Log.l1_User, "VPayPrint.cmd_export", PaymentRule); 408 if (!getChecks(PaymentRule)) 409 return; 410 411 JFileChooser fc = new JFileChooser(); 413 fc.setDialogTitle(Msg.getMsg(Env.getCtx(), "Export")); 414 fc.setFileSelectionMode(JFileChooser.FILES_ONLY); 415 fc.setMultiSelectionEnabled(false); 416 fc.setSelectedFile(new java.io.File ("paymentExport.txt")); 417 if (fc.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) 418 return; 419 420 int no = MPaySelectionCheck.exportToFile(m_checks, fc.getSelectedFile()); 422 ADialog.info(m_WindowNo, this, "Saved", 423 fc.getSelectedFile().getAbsolutePath() + "\n" 424 + Msg.getMsg(Env.getCtx(), "NoOfLines") + "=" + no); 425 426 if (ADialog.ask(m_WindowNo, this, "VPayPrintSuccess?")) 427 { 428 int lastDocumentNo = MPaySelectionCheck.confirmPrint (m_checks); 429 } 431 dispose(); 432 } 434 437 private void cmd_EFT() 438 { 439 String PaymentRule = ((ValueNamePair)fPaymentRule.getSelectedItem()).getValue(); 440 Log.trace(Log.l1_User, "VPayPrint.cmd_EFT", PaymentRule); 441 if (!getChecks(PaymentRule)) 442 return; 443 dispose(); 444 } 446 449 private void cmd_print() 450 { 451 String PaymentRule = ((ValueNamePair)fPaymentRule.getSelectedItem()).getValue(); 452 Log.trace(Log.l1_User, "VPayPrint.cmd_print", PaymentRule); 453 if (!getChecks(PaymentRule)) 454 return; 455 456 457 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 458 459 boolean somethingPrinted = false; 460 boolean directPrint = !Ini.getPropertyBool(Ini.P_PRINTPREVIEW); 461 for (int i = 0; i < m_checks.length; i++) 463 { 464 MPaySelectionCheck check = m_checks[i]; 465 boolean ok = ReportCtl.startDocumentPrint(ReportCtl.CHECK, check.getID(), directPrint); 467 if (!somethingPrinted && ok) 468 somethingPrinted = true; 469 } 470 471 if (somethingPrinted && ADialog.ask(m_WindowNo, this, "VPayPrintSuccess?")) 473 { 474 int lastDocumentNo = MPaySelectionCheck.confirmPrint (m_checks); 475 if (lastDocumentNo != 0) 476 { 477 StringBuffer sb = new StringBuffer (); 478 sb.append("UPDATE C_BankAccountDoc SET CurrentNext=").append(++lastDocumentNo) 479 .append(" WHERE C_BankAccount_ID=").append(m_C_BankAccount_ID) 480 .append(" AND PaymentRule='").append(PaymentRule).append("'"); 481 DB.executeUpdate(sb.toString()); 482 } 483 } 485 if (ADialog.ask(m_WindowNo, this, "VPayPrintPrintRemittance")) 486 { 487 for (int i = 0; i < m_checks.length; i++) 488 { 489 MPaySelectionCheck check = m_checks[i]; 490 ReportCtl.startDocumentPrint(ReportCtl.REMITTANCE, check.getID(), directPrint); 491 } 492 } 494 this.setCursor(Cursor.getDefaultCursor()); 495 dispose(); 496 } 498 499 500 505 private boolean getChecks(String PaymentRule) 506 { 507 if (fPaySelect.getSelectedIndex() == -1 || m_C_BankAccount_ID == -1 509 || fPaymentRule.getSelectedIndex() == -1 || fDocumentNo.getValue() == null) 510 { 511 ADialog.error(m_WindowNo, this, "VPayPrintNoRecords", 512 "(" + Msg.translate(Env.getCtx(), "C_PaySelectionLine_ID") + "=0)"); 513 return false; 514 } 515 516 int C_PaySelection_ID = ((KeyNamePair)fPaySelect.getSelectedItem()).getKey(); 518 int startDocumentNo = ((BigDecimal)fDocumentNo.getValue()).intValue(); 519 520 Log.trace(Log.l3_Util, "VPayPrint.createPayments", 521 "C_PaySelection_ID=" + C_PaySelection_ID + ", PaymentRule=" + PaymentRule + ", DocumentNo=" + startDocumentNo); 522 this.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); 524 525 m_checks = MPaySelectionCheck.get(C_PaySelection_ID, PaymentRule, startDocumentNo); 526 527 this.setCursor(Cursor.getDefaultCursor()); 528 if (m_checks == null || m_checks.length == 0) 530 { 531 ADialog.error(m_WindowNo, this, "VPayPrintNoRecords", 532 "(" + Msg.translate(Env.getCtx(), "C_PaySelectionLine_ID") + " #0"); 533 return false; 534 } 535 return true; 536 } 538 } | Popular Tags |