1 14 package org.compiere.grid; 15 16 import java.awt.*; 17 import java.awt.event.*; 18 import java.text.*; 19 import javax.swing.*; 20 import java.util.*; 21 import java.sql.*; 22 import java.math.*; 23 24 import org.compiere.apps.*; 25 import org.compiere.grid.ed.*; 26 import org.compiere.util.*; 27 import org.compiere.model.*; 28 import org.compiere.plaf.*; 29 import org.compiere.swing.*; 30 31 58 public class VPayment extends JDialog implements ActionListener 59 { 60 67 public VPayment (int WindowNo, MTab mTab, VButton button) 68 { 69 super(Env.getWindow(WindowNo), Msg.getMsg(Env.getCtx(), "Payment"), true); 70 m_WindowNo = WindowNo; 71 m_isSOTrx = "Y".equals(Env.getContext(Env.getCtx(), WindowNo, "IsSOTrx")); 72 m_mTab = mTab; 73 try 74 { 75 bDateField = new VDate("DateAcct", false, false, true, DisplayType.Date, "DateAcct"); 76 jbInit(); 77 m_initOK = dynInit(button); } 79 catch(Exception ex) 80 { 81 Log.error("VPayment", ex); 82 m_initOK = false; 83 } 84 AEnv.positionCenterWindow(Env.getWindow(WindowNo), this); 86 } 88 89 private int m_WindowNo = 0; 90 91 private MTab m_mTab; 92 93 private String m_DocStatus = null; 95 96 private String m_PaymentRule = ""; 97 98 private int m_C_PaymentTerm_ID = 0; 99 100 private Timestamp m_DateAcct = null; 101 102 private int m_C_Payment_ID = 0; 103 private MPayment m_mPayment = null; 104 private MPayment m_mPaymentOriginal = null; 105 106 private int m_C_CashLine_ID = 0; 107 private MCashBook m_mCashBook = null; 108 109 private String m_CCType = ""; 110 111 private int m_C_BankAccount_ID = 0; 112 113 private int m_C_CashBook_ID = 0; 114 115 116 private boolean m_isSOTrx = true; 117 118 119 private int m_C_Currency_ID = 0; 120 private int m_AD_Client_ID = 0; 121 private int m_AD_Org_ID = 0; 122 private int m_C_BPartner_ID = 0; 123 private BigDecimal m_Amount = Env.ZERO; private boolean m_initOK = false; 126 127 private boolean m_onlyRule = false; 128 private DecimalFormat m_Format = DisplayType.getNumberFormat(DisplayType.Amount); 129 private static Hashtable s_Currencies = null; 131 private CPanel mainPanel = new CPanel(); 133 private BorderLayout mainLayout = new BorderLayout(); 134 private CPanel northPanel = new CPanel(); 135 private CPanel centerPanel = new CPanel(); 136 private FlowLayout northLayout = new FlowLayout(); 137 private CComboBox paymentCombo = new CComboBox(); 138 private CLabel paymentLabel = new CLabel(); 139 private CardLayout centerLayout = new CardLayout(); 140 private CPanel bPanel = new CPanel(); 141 private CPanel kPanel = new CPanel(); 142 private GridBagLayout kLayout = new GridBagLayout(); 143 private CLabel kTypeLabel = new CLabel(); 144 private CComboBox kTypeCombo = new CComboBox(); 145 private CLabel kNumnerLabel = new CLabel(); 146 private CTextField kNumberField = new CTextField(); 147 private CLabel kExpLabel = new CLabel(); 148 private CTextField kExpField = new CTextField(); 149 private CLabel kApprovalLabel = new CLabel(); 150 private CTextField kApprovalField = new CTextField(); 151 private CPanel tPanel = new CPanel(); 152 private CLabel tAccountLabel = new CLabel(); 153 private CComboBox tAccountCombo = new CComboBox(); 154 private CPanel sPanel = new CPanel(); 155 private GridBagLayout sPanelLayout = new GridBagLayout(); 156 private CLabel sNumberLabel = new CLabel(); 157 private CTextField sNumberField = new CTextField(); 158 private CLabel sRoutingLabel = new CLabel(); 159 private CTextField sRoutingField = new CTextField(); 160 private CLabel sCurrencyLabel = new CLabel(); 161 private CComboBox sCurrencyCombo = new CComboBox(); 162 private CLabel bCurrencyLabel = new CLabel(); 163 private CComboBox bCurrencyCombo = new CComboBox(); 164 private CPanel pPanel = new CPanel(); 165 private CLabel pTermLabel = new CLabel(); 166 private CComboBox pTermCombo = new CComboBox(); 167 private GridBagLayout bPanelLayout = new GridBagLayout(); 168 private CLabel bAmountLabel = new CLabel(); 169 private CLabel bAmountField = new CLabel(); 170 private CLabel sAmountLabel = new CLabel(); 171 private CLabel sAmountField = new CLabel(); 172 private VDate bDateField; 173 private CLabel bDateLabel = new CLabel(); 174 private ConfirmPanel confirmPanel = new ConfirmPanel(true); 175 private CTextField sCheckField = new CTextField(); 176 private CLabel sCheckLabel = new CLabel(); 177 private CButton kOnline = new CButton(); 178 private CButton sOnline = new CButton(); 179 private CComboBox sBankAccountCombo = new CComboBox(); 180 private CLabel sBankAccountLabel = new CLabel(); 181 private GridBagLayout pPanelLayout = new GridBagLayout(); 182 private CLabel bCashBookLabel = new CLabel(); 183 private CComboBox bCashBookCombo = new CComboBox(); 184 private GridBagLayout tPanelLayout = new GridBagLayout(); 185 private CButton tOnline = new CButton(); 186 private CLabel kStatus = new CLabel(); 187 private CTextField tRoutingField = new CTextField(); 188 private CTextField tNumberField = new CTextField(); 189 private CLabel tStatus = new CLabel(); 190 private CLabel tRoutingText = new CLabel(); 191 private CLabel tNumberText = new CLabel(); 192 private CLabel sStatus = new CLabel(); 193 194 198 private void jbInit() throws Exception 199 { 200 CompiereColor.setBackground(this); 201 centerPanel.setBorder(BorderFactory.createRaisedBevelBorder()); 202 getContentPane().add(mainPanel); 203 mainPanel.setLayout(mainLayout); 204 mainPanel.add(centerPanel, BorderLayout.CENTER); 205 northPanel.setLayout(northLayout); 207 paymentLabel.setText(Msg.translate(Env.getCtx(), "PaymentRule")); 208 mainPanel.add(northPanel, BorderLayout.NORTH); 209 northPanel.add(paymentLabel, null); 210 northPanel.add(paymentCombo, null); 211 centerPanel.setLayout(centerLayout); 213 kPanel.setLayout(kLayout); 215 kNumberField.setPreferredSize(new Dimension(120, 21)); 216 kExpField.setPreferredSize(new Dimension(40, 21)); 217 kApprovalField.setPreferredSize(new Dimension(120, 21)); 218 kTypeLabel.setText(Msg.translate(Env.getCtx(), "CreditCardType")); 219 kNumnerLabel.setText(Msg.translate(Env.getCtx(), "CreditCardNumber")); 220 kExpLabel.setText(Msg.getMsg(Env.getCtx(), "Expires")); 221 kApprovalLabel.setText(Msg.translate(Env.getCtx(), "VoiceAuthCode")); 222 kOnline.setText(Msg.getMsg(Env.getCtx(), "Online")); 223 kOnline.addActionListener(this); 224 kStatus.setText(" "); 225 centerPanel.add(kPanel, "kPanel"); 226 centerLayout.addLayoutComponent(kPanel, "kPanel"); 227 kPanel.add(kTypeLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 228 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 0, 2, 0), 0, 0)); 229 kPanel.add(kTypeCombo, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0 230 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 5, 2, 5), 0, 0)); 231 kPanel.add(kNumnerLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 232 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 0, 2, 0), 0, 0)); 233 kPanel.add(kNumberField, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0 234 ,GridBagConstraints.WEST, GridBagConstraints.VERTICAL, new Insets(2, 5, 2, 5), 0, 0)); 235 kPanel.add(kExpLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0 236 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 0, 2, 0), 0, 0)); 237 kPanel.add(kExpField, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0 238 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 5, 2, 5), 0, 0)); 239 kPanel.add(kApprovalLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0 240 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 0), 0, 0)); 241 kPanel.add(kApprovalField, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0 242 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 243 kPanel.add(kStatus, new GridBagConstraints(0, 4, 2, 1, 0.0, 0.0 244 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 245 kPanel.add(kOnline, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0 246 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 247 tPanel.setLayout(tPanelLayout); 249 tAccountLabel.setText(Msg.translate(Env.getCtx(), "C_BP_BankAccount_ID")); 250 tRoutingField.setColumns(8); 251 tNumberField.setColumns(10); 252 tRoutingText.setText(Msg.translate(Env.getCtx(), "RoutingNo")); 253 tNumberText.setText(Msg.translate(Env.getCtx(), "AccountNo")); 254 tOnline.setText(Msg.getMsg(Env.getCtx(), "Online")); 255 tStatus.setText(" "); 256 centerPanel.add(tPanel, "tPanel"); 257 centerLayout.addLayoutComponent(tPanel, "tPanel"); 258 tPanel.add(tAccountLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 259 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 0), 0, 0)); 260 tPanel.add(tAccountCombo, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0 261 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 262 tPanel.add(tRoutingField, new GridBagConstraints(1, 1, 2, 1, 0.0, 0.0 263 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0)); 264 tPanel.add(tNumberField, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0 265 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 0, 5), 0, 0)); 266 tPanel.add(tStatus, new GridBagConstraints(0, 3, 2, 1, 0.0, 0.0 267 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 268 tPanel.add(tRoutingText, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 269 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 0), 0, 0)); 270 tPanel.add(tNumberText, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0 271 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 0, 0), 0, 0)); 272 tPanel.add(tOnline, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0 273 ,GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 274 sPanel.setLayout(sPanelLayout); 276 sBankAccountLabel.setText(Msg.translate(Env.getCtx(), "C_BankAccount_ID")); 277 sAmountLabel.setText(Msg.getMsg(Env.getCtx(), "Amount")); 278 sAmountField.setText(""); 279 sRoutingLabel.setText(Msg.translate(Env.getCtx(), "RoutingNo")); 280 sNumberLabel.setText(Msg.translate(Env.getCtx(), "AccountNo")); 281 sCheckLabel.setText(Msg.translate(Env.getCtx(), "CheckNo")); 282 sCheckField.setColumns(8); 283 sCurrencyLabel.setText(Msg.translate(Env.getCtx(), "C_Currency_ID")); 284 sNumberField.setPreferredSize(new Dimension(100, 21)); 285 sRoutingField.setPreferredSize(new Dimension(70, 21)); 286 sStatus.setText(" "); 287 sOnline.setText(Msg.getMsg(Env.getCtx(), "Online")); 288 centerPanel.add(sPanel, "sPanel"); 289 centerLayout.addLayoutComponent(sPanel, "sPanel"); 290 sPanel.add(sCurrencyLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 291 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 0, 2, 0), 0, 0)); 292 sPanel.add(sCurrencyCombo, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0 293 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 5, 2, 5), 0, 0)); 294 sPanel.add(sRoutingField, new GridBagConstraints(1, 4, 2, 1, 0.0, 0.0 295 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 2, 0), 0, 0)); 296 sPanel.add(sNumberField, new GridBagConstraints(1, 5, 2, 1, 0.0, 0.0 297 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 5, 2, 0), 0, 0)); 298 sPanel.add(sCheckField, new GridBagConstraints(1, 6, 1, 1, 0.0, 0.0 299 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 5, 2, 0), 0, 0)); 300 sPanel.add(sRoutingLabel, new GridBagConstraints(0, 3, 1, 2, 0.0, 0.0 301 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 0, 2, 0), 0, 0)); 302 sPanel.add(sNumberLabel, new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0 303 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 0, 2, 0), 0, 0)); 304 sPanel.add(sCheckLabel, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0 305 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 0, 2, 0), 0, 0)); 306 sPanel.add(sBankAccountCombo, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0 307 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 2, 5), 0, 0)); 308 sPanel.add(sBankAccountLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 309 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 0, 2, 0), 0, 0)); 310 sPanel.add(sStatus, new GridBagConstraints(0, 7, 3, 1, 0.0, 0.0 311 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 312 sPanel.add(sOnline, new GridBagConstraints(3, 6, 1, 1, 0.0, 0.0 313 ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 314 sPanel.add(sAmountField, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0 315 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 5, 5, 5), 0, 0)); 316 sPanel.add(sAmountLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0 317 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 0, 5, 0), 0, 0)); 318 pPanel.setLayout(pPanelLayout); 320 pTermLabel.setText(Msg.translate(Env.getCtx(), "C_PaymentTerm_ID")); 321 centerPanel.add(pPanel, "pPanel"); 322 centerLayout.addLayoutComponent(pPanel, "pPanel"); 323 pPanel.add(pTermLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 324 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 5, 2, 0), 0, 0)); 325 pPanel.add(pTermCombo, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0 326 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 5, 2, 5), 0, 0)); 327 bCashBookLabel.setText(Msg.translate(Env.getCtx(), "C_CashBook_ID")); 329 bCurrencyLabel.setText(Msg.translate(Env.getCtx(), "C_Currency_ID")); 330 bPanel.setLayout(bPanelLayout); 331 bAmountLabel.setText(Msg.getMsg(Env.getCtx(), "Amount")); 332 bAmountField.setText(""); 333 bDateLabel.setText(Msg.translate(Env.getCtx(), "DateAcct")); 334 centerLayout.addLayoutComponent(bPanel, "bPanel"); 335 centerPanel.add(bPanel, "bPanel"); 336 bPanel.add(bCurrencyLabel, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0 337 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 0, 2, 0), 0, 0)); 338 bPanel.add(bCurrencyCombo, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0 339 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 5, 2, 5), 0, 0)); 340 bPanel.add(bDateField, new GridBagConstraints(1, 2, 2, 1, 0.0, 0.0 341 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 2, 5), 0, 0)); 342 bPanel.add(bDateLabel, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0 343 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 0, 2, 0), 0, 0)); 344 bPanel.add(bCashBookLabel, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0 345 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(2, 0, 2, 0), 0, 0)); 346 bPanel.add(bCashBookCombo, new GridBagConstraints(1, 0, 2, 1, 0.0, 0.0 347 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(2, 5, 2, 5), 0, 0)); 348 bPanel.add(bAmountLabel, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0 349 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 0, 2, 0), 0, 0)); 350 bPanel.add(bAmountField, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0 351 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 2, 5), 0, 0)); 352 mainPanel.add(confirmPanel, BorderLayout.SOUTH); 354 confirmPanel.addActionListener(this); 355 } 357 358 359 372 private boolean dynInit (VButton button) throws Exception 373 { 374 Log.trace(Log.l3_Util, "VPayment.dynInit"); 375 376 if (m_mTab.getValue("C_BPartner_ID") == null) 377 { 378 ADialog.error(0, this, "SaveErrorRowNotFound"); 379 return false; 380 } 381 382 387 m_DocStatus = (String )m_mTab.getValue("DocStatus"); 389 if (m_DocStatus == null) 390 m_DocStatus = ""; 391 if (m_DocStatus.equals("RE") || m_DocStatus.equals("VO") || m_DocStatus.equals("CL")) 393 return false; 394 if (m_DocStatus.equals("CO")) 396 m_onlyRule = false; 397 else 398 { 399 m_onlyRule = true; 400 centerPanel.setVisible(false); 401 } 404 405 m_Amount = (BigDecimal)m_mTab.getValue("GrandTotal"); 407 if (!m_onlyRule && m_Amount.compareTo(Env.ZERO) == 0) 408 { 409 ADialog.error(m_WindowNo, this, "PaymentZero"); 410 return false; 411 } 412 bAmountField.setText(m_Format.format(m_Amount)); 413 sAmountField.setText(m_Format.format(m_Amount)); 414 415 418 m_AD_Client_ID = ((Integer )m_mTab.getValue("AD_Client_ID")).intValue(); 419 m_AD_Org_ID = ((Integer )m_mTab.getValue("AD_Org_ID")).intValue(); 420 m_C_BPartner_ID = ((Integer )m_mTab.getValue("C_BPartner_ID")).intValue(); 421 m_PaymentRule = (String )m_mTab.getValue("PaymentRule"); 422 m_C_Currency_ID = ((Integer )m_mTab.getValue("C_Currency_ID")).intValue(); 423 m_DateAcct = (Timestamp)m_mTab.getValue("DateAcct"); 424 if (m_mTab.getValue("C_PaymentTerm_ID") != null) 425 m_C_PaymentTerm_ID = ((Integer )m_mTab.getValue("C_PaymentTerm_ID")).intValue(); 426 if (m_mTab.getValue("C_Payment_ID") != null) 428 { 429 m_C_Payment_ID = ((Integer )m_mTab.getValue("C_Payment_ID")).intValue(); 430 if (m_C_Payment_ID != 0) 431 { 432 m_mPayment = new MPayment(Env.getCtx(), m_C_Payment_ID); 433 m_mPaymentOriginal = new MPayment(Env.getCtx(), m_C_Payment_ID); m_CCType = m_mPayment.getCreditCardType(); 436 kNumberField.setText(m_mPayment.getCreditCardNumber()); 437 kExpField.setText(m_mPayment.getCreditCardExp()); 438 kApprovalField.setText(m_mPayment.getVoiceAuthCode()); 439 kStatus.setText(m_mPayment.getR_PnRef()); 440 kTypeCombo.setReadWrite(!m_mPayment.isApproved()); 442 kNumberField.setReadWrite(!m_mPayment.isApproved()); 443 kExpField.setReadWrite(!m_mPayment.isApproved()); 444 kApprovalField.setReadWrite(!m_mPayment.isApproved()); 445 kOnline.setReadWrite(!m_mPayment.isApproved()); 446 m_C_BankAccount_ID = m_mPayment.getC_BankAccount_ID(); 448 sRoutingField.setText(m_mPayment.getRoutingNo()); 449 sNumberField.setText(m_mPayment.getAccountNo()); 450 sCheckField.setText(m_mPayment.getCheckNo()); 451 sStatus.setText(m_mPayment.getR_PnRef()); 452 tRoutingField.setText(m_mPayment.getRoutingNo()); 454 tNumberField.setText(m_mPayment.getAccountNo()); 455 tStatus.setText(m_mPayment.getR_PnRef()); 456 } 457 } 458 if (m_mPayment == null) 459 { 460 m_mPayment = new MPayment (Env.getCtx (), 0); 461 m_mPayment.setAmount (m_C_Currency_ID, m_Amount); 462 } 463 464 if (m_mTab.getValue("C_CashLine_ID") != null) 466 { 467 m_C_CashLine_ID = ((Integer )m_mTab.getValue("C_CashLine_ID")).intValue(); 468 if (m_C_CashLine_ID != 0) 469 m_mCashBook = new MCashBook(m_C_CashLine_ID); 470 if (m_mCashBook != null && m_mCashBook.getC_CashLine_ID() != 0) 471 { 472 m_DateAcct = m_mCashBook.getStatementDate(); 473 m_C_CashBook_ID = m_mCashBook.getC_CashBook_ID(); 474 } 475 } 476 else 477 m_C_CashLine_ID = 0; 478 479 bDateField.setValue(m_DateAcct); 481 482 if (s_Currencies == null) 483 loadCurrencies(); 484 485 Integer C_Currency_ID = new Integer (m_C_Currency_ID); 487 if (s_Currencies.containsKey(C_Currency_ID)) 488 { 489 Enumeration en = s_Currencies.keys(); 490 while (en.hasMoreElements()) 491 { 492 Object key = en.nextElement(); 493 bCurrencyCombo.addItem(s_Currencies.get(key)); 494 sCurrencyCombo.addItem(s_Currencies.get(key)); 495 } 496 sCurrencyCombo.addActionListener(this); 497 sCurrencyCombo.setSelectedItem(s_Currencies.get(C_Currency_ID)); 498 bCurrencyCombo.addActionListener(this); 499 bCurrencyCombo.setSelectedItem(s_Currencies.get(C_Currency_ID)); 500 } 501 else { 503 bCurrencyLabel.setVisible(false); bCurrencyCombo.setVisible(false); 505 sCurrencyLabel.setVisible(false); sCurrencyCombo.setVisible(false); 507 } 508 509 512 if (m_PaymentRule == null) 513 m_PaymentRule = ""; 514 ValueNamePair vp = null; 515 HashMap values = button.getValues(); 516 Object [] a = values.keySet().toArray(); 517 for (int i = 0; i < a.length; i++) 518 { 519 String PaymentRule = (String )a[i]; 520 ValueNamePair pp = new ValueNamePair(PaymentRule, (String )values.get(a[i])); 521 paymentCombo.addItem(pp); 522 if (PaymentRule.toString().equals(m_PaymentRule)) vp = pp; 524 } 525 526 paymentCombo.addActionListener(this); 528 if (vp != null) 529 paymentCombo.setSelectedItem(vp); 530 531 534 String SQL = MRole.getDefault().addAccessSQL( 535 "SELECT C_PaymentTerm_ID, Name FROM C_PaymentTerm", 536 "C_PaymentTerm", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO); 537 KeyNamePair kp = null; 538 try 539 { 540 PreparedStatement pstmt = DB.prepareStatement(SQL); 541 ResultSet rs = pstmt.executeQuery(); 542 while (rs.next()) 543 { 544 int key = rs.getInt(1); 545 String name = rs.getString(2); 546 KeyNamePair pp = new KeyNamePair(key, name); 547 pTermCombo.addItem(pp); 548 if (key == m_C_PaymentTerm_ID) 549 kp = pp; 550 } 551 rs.close(); 552 pstmt.close(); 553 } 554 catch (SQLException ept) 555 { 556 Log.error ("VPayment.dynInit -PaymentTerm-", ept); 557 } 558 if (kp != null) 560 pTermCombo.setSelectedItem(kp); 561 562 565 SQL = "SELECT a.C_BP_BankAccount_ID, NVL(b.Name, ' ')||a.AccountNo AS Acct " 566 + "FROM C_BP_BankAccount a,C_Bank b " 567 + "WHERE C_BPartner_ID=?"; 568 kp = null; 569 try 570 { 571 PreparedStatement pstmt = DB.prepareStatement(SQL); 572 pstmt.setInt(1, m_C_BPartner_ID); 573 ResultSet rs = pstmt.executeQuery(); 574 while (rs.next()) 575 { 576 int key = rs.getInt(1); 577 String name = rs.getString(2); 578 KeyNamePair pp = new KeyNamePair(key, name); 579 tAccountCombo.addItem(pp); 580 } 582 rs.close(); 583 pstmt.close(); 584 } 585 catch (SQLException eac) 586 { 587 Log.error ("VPayment.dynInit -BPAcct-", eac); 588 } 589 if (kp != null) 591 tAccountCombo.setSelectedItem(kp); 592 593 596 ValueNamePair[] ccs = m_mPayment.getCreditCards(); 597 vp = null; 598 for (int i = 0; i < ccs.length; i++) 599 { 600 kTypeCombo.addItem(ccs[i]); 601 if (ccs[i].getValue().equals(m_CCType)) 602 vp = ccs[i]; 603 } 604 if (vp != null) 606 kTypeCombo.setSelectedItem(vp); 607 608 611 SQL = MRole.getDefault().addAccessSQL( 612 "SELECT C_BankAccount_ID, Name || ' ' || AccountNo, IsDefault " 613 + "FROM C_BankAccount, C_Bank WHERE C_BankAccount.C_Bank_ID=C_Bank.C_Bank_ID", 614 "C_BankAccount", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO); 615 kp = null; 616 try 617 { 618 PreparedStatement pstmt = DB.prepareStatement(SQL); 619 ResultSet rs = pstmt.executeQuery(); 620 while (rs.next()) 621 { 622 int key = rs.getInt(1); 623 String name = rs.getString(2); 624 KeyNamePair pp = new KeyNamePair(key, name); 625 sBankAccountCombo.addItem(pp); 626 if (key == m_C_BankAccount_ID) 627 kp = pp; 628 if (kp == null && rs.getString(3).equals("Y")) kp = pp; 630 } 631 rs.close(); 632 pstmt.close(); 633 } 634 catch (SQLException ept) 635 { 636 Log.error ("VPayment.dynInit -PaymentTerm-", ept); 637 } 638 if (kp != null) 640 sBankAccountCombo.setSelectedItem(kp); 641 642 643 646 SQL = MRole.getDefault().addAccessSQL( 647 "SELECT C_CashBook_ID, Name, AD_Org_ID FROM C_CashBook WHERE IsActive='Y'", 648 "C_CashBook", MRole.SQL_NOTQUALIFIED, MRole.SQL_RO); 649 kp = null; 650 try 651 { 652 PreparedStatement pstmt = DB.prepareStatement(SQL); 653 ResultSet rs = pstmt.executeQuery(); 654 while (rs.next()) 655 { 656 int key = rs.getInt(1); 657 String name = rs.getString(2); 658 KeyNamePair pp = new KeyNamePair(key, name); 659 bCashBookCombo.addItem(pp); 660 if (key == m_C_CashBook_ID) 661 kp = pp; 662 if (kp == null && key == m_AD_Org_ID) kp = pp; 664 } 665 rs.close(); 666 pstmt.close(); 667 } 668 catch (SQLException epc) 669 { 670 Log.error ("VPayment.dynInit -CashBook-", epc); 671 } 672 if (kp != null) 674 { 675 bCashBookCombo.setSelectedItem(kp); 676 if (m_C_CashBook_ID == 0) 677 m_C_CashBook_ID = kp.getKey(); } 679 680 return true; 682 } 684 688 public boolean isInitOK() 689 { 690 return m_initOK; 691 } 693 694 697 private void loadCurrencies() 698 { 699 s_Currencies = new Hashtable(12); String SQL = "SELECT C_Currency_ID, ISO_Code FROM C_Currency " 701 + "WHERE (IsEMUMember='Y' AND EMUEntryDate<SysDate) OR IsEuro='Y' " 702 + "ORDER BY 2"; 703 try 704 { 705 PreparedStatement pstmt = DB.prepareStatement(SQL); 706 ResultSet rs = pstmt.executeQuery(); 707 while (rs.next()) 708 { 709 int id = rs.getInt(1); 710 String name = rs.getString(2); 711 s_Currencies.put(new Integer (id), new KeyNamePair(id, name)); 712 } 713 rs.close(); 714 pstmt.close(); 715 } 716 catch (SQLException e) 717 { 718 Log.error("VPayment.loadCurrencies", e); 719 } 720 } 722 723 724 725 729 public void actionPerformed(ActionEvent e) 730 { 731 733 if (e.getActionCommand().equals(ConfirmPanel.A_OK)) 735 { 736 if (checkMandatory()) 737 { 738 saveChanges (); dispose (); 740 } 741 } 742 else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) 743 dispose(); 744 745 else if (e.getSource() == paymentCombo) 747 { 748 ValueNamePair pp = (ValueNamePair)paymentCombo.getSelectedItem(); 750 if (pp != null) 751 { 752 String s = pp.getValue().toLowerCase() + "Panel"; 753 centerLayout.show(centerPanel, s); } 755 } 756 757 else if (e.getSource() == sCurrencyCombo) 759 { 760 KeyNamePair pp = (KeyNamePair)sCurrencyCombo.getSelectedItem(); 761 BigDecimal amt = DB.getConvertedAmt(m_Amount, m_C_Currency_ID, pp.getKey(), m_AD_Client_ID, m_AD_Org_ID); 762 sAmountField.setText(m_Format.format(amt)); 763 } 764 else if (e.getSource() == bCurrencyCombo) 766 { 767 KeyNamePair pp = (KeyNamePair)bCurrencyCombo.getSelectedItem(); 768 BigDecimal amt = DB.getConvertedAmt(m_Amount, m_C_Currency_ID, pp.getKey(), m_AD_Client_ID, m_AD_Org_ID); 769 bAmountField.setText(m_Format.format(amt)); 770 } 771 772 else if (e.getSource() == kOnline || e.getSource() == sOnline || e.getSource() == tOnline) 774 processOnline(); 775 } 777 778 779 780 784 private boolean saveChanges() 785 { 786 Log.trace(Log.l3_Util, "VPayment.saveChanges"); 787 788 ValueNamePair vp = (ValueNamePair)paymentCombo.getSelectedItem(); 789 String PaymentRule = vp.getValue(); 790 if (m_onlyRule) 792 { 793 if (!PaymentRule.equals(m_PaymentRule)) 794 m_mTab.setValue("PaymentRule", PaymentRule); 795 return true; 796 } 797 798 Timestamp DateAcct = m_DateAcct; 800 int C_PaymentTerm_ID = m_C_PaymentTerm_ID; 801 int C_CashLine_ID = m_C_CashLine_ID; 802 int C_CashBook_ID = m_C_CashBook_ID; 803 String CCType = m_CCType; 804 int C_BankAccount_ID = 0; 806 807 if (PaymentRule.equals(X_C_Order.PAYMENTRULE_Cash)) 809 { 810 KeyNamePair kp = (KeyNamePair)bCashBookCombo.getSelectedItem(); 811 if (kp != null) 812 C_CashBook_ID = kp.getKey(); 813 DateAcct = (Timestamp)bDateField.getValue(); 814 } 815 816 else if (PaymentRule.equals(X_C_Order.PAYMENTRULE_CreditCard)) 818 { 819 vp = (ValueNamePair)kTypeCombo.getSelectedItem(); 820 if (vp != null) 821 CCType = vp.getValue(); 822 } 823 824 else if (PaymentRule.equals(X_C_Order.PAYMENTRULE_TransferACH)) 826 { 827 tAccountCombo.getSelectedItem(); 828 } 829 830 else if (PaymentRule.equals(X_C_Order.PAYMENTRULE_OnCredit)) 832 { 833 KeyNamePair kp = (KeyNamePair)pTermCombo.getSelectedItem(); 834 if (kp != null) 835 C_PaymentTerm_ID = kp.getKey(); 836 } 837 838 else if (PaymentRule.equals(X_C_Order.PAYMENTRULE_Check)) 840 { 841 KeyNamePair kp = (KeyNamePair)sBankAccountCombo.getSelectedItem(); 843 if (kp != null) 844 C_BankAccount_ID = kp.getKey(); 845 } 846 else 847 return false; 848 849 if ("KTS".indexOf(PaymentRule) != -1 && C_BankAccount_ID == 0) 851 { 852 String tender = MPayment.TENDERTYPE_CreditCard; 853 if (PaymentRule.equals("T")) 854 tender = MPayment.TENDERTYPE_ACH; 855 else if (PaymentRule.equals("S")) 856 tender = MPayment.TENDERTYPE_Check; 857 } 858 859 862 if (!PaymentRule.equals(m_PaymentRule)) 863 { 864 if (m_PaymentRule.equals(X_C_Order.PAYMENTRULE_Cash)) 866 { 867 if (m_mCashBook != null) 868 { 869 if (m_mCashBook.reverse(Env.getCtx(), m_WindowNo)) Log.trace(Log.l4_Data, "CashCancelled"); 871 else 872 ADialog.error(m_WindowNo, this, "PaymentError", "CashNotCancelled"); 873 } 874 C_CashLine_ID = 0; } 876 else if ("KTS".indexOf(m_PaymentRule) != -1 && "KTS".indexOf(PaymentRule) != -1 && m_mPaymentOriginal != null) 878 { 879 if (m_mPaymentOriginal.cancel()) 880 Log.trace(Log.l1_User, "Payment Canecelled - " + m_mPaymentOriginal); 881 else 882 ADialog.error(m_WindowNo, this, "PaymentError", "PaymentNotCancelled " + m_mPaymentOriginal.getDocumentNo()); 883 m_mPayment.resetNew(); 884 } 885 else if ("KTS".indexOf(m_PaymentRule) != -1 && "KTS".indexOf(PaymentRule) == -1) 887 { 888 if (m_mPaymentOriginal != null) 889 { 890 if (m_mPaymentOriginal.cancel()) { 892 Log.trace (Log.l4_Data, "PaymentCancelled " + m_mPayment.getDocumentNo ()); 893 m_mTab.getTableModel().dataSave(true); 894 m_mPayment.resetNew(); 895 m_mPayment.setAmount(m_C_Currency_ID, m_Amount); 896 } 897 else 898 ADialog.error(m_WindowNo, this, "PaymentError", "PaymentNotCancelled " + m_mPayment.getDocumentNo()); 899 } 900 } 901 } 902 903 int C_Order_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "C_Order_ID"); 905 int C_Invoice_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "C_Invoice_ID"); 906 if (C_Invoice_ID == 0 && m_DocStatus.equals("CO")) 907 C_Invoice_ID = getInvoiceID (C_Order_ID); 908 909 boolean negateAmt = false; 911 String sql = "SELECT DECODE (dt.DocBaseType, 'ARC','Y', 'API','Y', 'N'), dt.DocBaseType " 912 + "FROM C_DocType dt, C_Invoice i " 913 + "WHERE dt.C_DocType_ID = i.C_DocType_ID" 914 + " AND i.C_Invoice_ID=?"; 915 try 916 { 917 PreparedStatement pstmt = DB.prepareStatement(sql); 918 pstmt.setInt(1, C_Invoice_ID); 919 ResultSet rs = pstmt.executeQuery(); 920 if (rs.next()) 921 negateAmt = "Y".equals(rs.getString(1)); 922 else 923 Log.error("VPayment.saveChanges - NegateAmount not found C_Invoice_ID=" + C_Invoice_ID); 924 rs.close(); 925 pstmt.close(); 926 } 927 catch (SQLException e) 928 { 929 Log.error("VPayment.saveChanges - NegateAmount", e); 930 } 931 BigDecimal payAmount = m_Amount; 932 if (negateAmt) 933 payAmount = m_Amount.negate(); 934 935 Log.trace(Log.l4_Data, "VPayment.saveChanges", 937 "C_Order_ID=" + C_Order_ID + ", C_Invoice_ID=" + C_Invoice_ID + ", NegateAmt=" + negateAmt); 938 939 942 if (PaymentRule.equals(X_C_Order.PAYMENTRULE_Cash)) 943 { 944 String description = (String )m_mTab.getValue("DocumentNo"); 945 946 if (m_mCashBook == null) 948 { 949 if (C_Invoice_ID == 0) 950 { 951 Log.trace(Log.l4_Data, "VPayment.saveChanges - No Invoice!"); 952 ADialog.error(m_WindowNo, this, "PaymentError", "CashNotCreated"); 953 } 954 else 955 { 956 Log.trace(Log.l4_Data, "VPayment.saveChanges - New CashBook"); 957 C_CashLine_ID = MCashBook.createCashBookEntry(Env.getCtx(), m_WindowNo, 958 m_AD_Client_ID, m_AD_Org_ID, DateAcct, C_Invoice_ID, 959 payAmount, description, C_CashBook_ID); 960 if (C_CashLine_ID != 0) 961 Log.trace(Log.l4_Data, "VPayment.saveChanges - CashCreated"); 962 else 963 ADialog.error(m_WindowNo, this, "PaymentError", "CashNotCreated"); 964 } 965 } 966 else if (C_CashBook_ID != m_C_CashBook_ID || !m_mCashBook.isSameDate(DateAcct)) 968 { 969 Log.trace(Log.l4_Data, "VPayment.saveChanges - Changed CashBook/Date"); 970 boolean reversal = m_mCashBook.reverse(Env.getCtx(), m_WindowNo); 971 C_CashLine_ID = MCashBook.createCashBookEntry(Env.getCtx(), m_WindowNo, 972 m_AD_Client_ID, m_AD_Org_ID, DateAcct, C_Invoice_ID, 973 payAmount, description, C_CashBook_ID); 974 if (reversal && C_CashLine_ID != 0) 975 Log.trace(Log.l4_Data, "VPayment.saveChanges - CashChanged"); 976 else 977 ADialog.error(m_WindowNo, this, "PaymentError", "CashNotChanged"); 978 } 979 else if (payAmount.compareTo(m_mCashBook.getAmount()) != 0) 981 { 982 Log.trace(Log.l4_Data, "VPayment.saveChanges - Changed CashBook Amount"); 983 m_mCashBook.setAmount(payAmount); 984 m_mCashBook.update(); 985 Log.trace(Log.l4_Data, "VPayment.saveChanges - CashChanged"); 986 } 987 else 988 Log.trace(Log.l4_Data, "VPayment.saveChanges - No Change"); 989 } 990 993 if ("KTS".indexOf(PaymentRule) != -1) 994 { 995 m_mPayment.setAmount(m_C_Currency_ID, payAmount); 997 if (PaymentRule.equals(MOrder.PAYMENTRULE_CreditCard)) 998 { 999 m_mPayment.setCreditCard(MPayment.TRXTYPE_Sales, CCType, 1000 kNumberField.getText(), "", kExpField.getText()); 1001 m_mPayment.setPaymentProcessor(); 1002 } 1003 else if (PaymentRule.equals(MOrder.PAYMENTRULE_TransferACH)) 1004 { 1005 m_mPayment.setBankACH(C_BankAccount_ID, m_isSOTrx, tRoutingField.getText(), 1006 tNumberField.getText()); 1007 } 1008 else if (PaymentRule.equals(MOrder.PAYMENTRULE_Check)) 1009 { 1010 m_mPayment.setBankCheck(C_BankAccount_ID, m_isSOTrx, sRoutingField.getText(), 1011 sNumberField.getText(), sCheckField.getText()); 1012 } 1013 m_mPayment.setC_BPartner_ID(m_C_BPartner_ID); 1014 m_mPayment.setC_Invoice_ID(C_Invoice_ID); 1015 m_mPayment.setDateTrx(m_DateAcct); 1016 if (m_mPayment.save() && m_mPayment.post()) 1018 ADialog.info(m_WindowNo, this, "PaymentCreated", m_mPayment.getDocumentNo()); 1019 else 1020 ADialog.error(m_WindowNo, this, "PaymentError", "PaymentNotCreated"); 1021 } 1022 1023 1024 1027 Log.trace(Log.l4_Data, "VPayment.saveChanges", "Saving changes"); 1028 if (!PaymentRule.equals(m_PaymentRule)) 1029 m_mTab.setValue("PaymentRule", PaymentRule); 1030 if (!DateAcct.equals(m_DateAcct)) 1032 m_mTab.setValue("DateAcct", DateAcct); 1033 if (C_PaymentTerm_ID != m_C_PaymentTerm_ID) 1035 m_mTab.setValue("C_PaymentTerm_ID", new Integer (C_PaymentTerm_ID)); 1036 if (m_mPayment.getC_Payment_ID() != m_C_Payment_ID) 1038 { 1039 if (m_mPayment.getC_Payment_ID() == 0) 1040 m_mTab.setValue("C_Payment_ID", null); 1041 else 1042 m_mTab.setValue("C_Payment_ID", new Integer (m_mPayment.getC_Payment_ID())); 1043 } 1044 if (C_CashLine_ID != m_C_CashLine_ID) 1046 { 1047 if (C_CashLine_ID == 0) 1048 m_mTab.setValue("C_CashLine_ID", null); 1049 else 1050 m_mTab.setValue("C_CashLine_ID", new Integer (C_CashLine_ID)); 1051 } 1052 return true; 1054 } 1056 1060 private boolean checkMandatory() 1061 { 1062 Log.trace(Log.l4_Data, "VPayment.checkMandatory"); 1063 1064 ValueNamePair vp = (ValueNamePair)paymentCombo.getSelectedItem(); 1065 String PaymentRule = vp.getValue(); 1066 if (m_onlyRule) 1068 return true; 1069 1070 Timestamp DateAcct = m_DateAcct; 1071 int C_PaymentTerm_ID = m_C_PaymentTerm_ID; 1072 int C_CashLine_ID = m_C_CashLine_ID; 1073 int C_CashBook_ID = m_C_CashBook_ID; 1074 String CCType = m_CCType; 1075 int C_BankAccount_ID = 0; 1077 1078 1081 boolean dataOK = true; 1082 if (PaymentRule.equals(MOrder.PAYMENTRULE_Cash)) 1084 { 1085 KeyNamePair kp = (KeyNamePair)bCashBookCombo.getSelectedItem(); 1086 if (kp != null) 1087 C_CashBook_ID = kp.getKey(); 1088 DateAcct = (Timestamp)bDateField.getValue(); 1089 } 1090 1091 else if (PaymentRule.equals(MOrder.PAYMENTRULE_CreditCard)) 1093 { 1094 vp = (ValueNamePair)kTypeCombo.getSelectedItem(); 1095 if (vp != null) 1096 CCType = vp.getValue(); 1097 String error = MPayment.validateCreditCardNumber(kNumberField.getText(), CCType); 1099 if (error.length() != 0) 1100 { 1101 kNumberField.setBackground(CompierePLAF.getFieldBackground_Error()); 1102 if (error.indexOf("?") == -1) 1103 { 1104 ADialog.error(m_WindowNo, this, error); 1105 dataOK = false; 1106 } 1107 else { 1109 if (!ADialog.ask(m_WindowNo, this, error)) 1110 dataOK = false; 1111 } 1112 } 1113 error = MPayment.validateCreditCardExp(kExpField.getText()); 1114 if(error.length() != 0) 1115 { 1116 kExpField.setBackground(CompierePLAF.getFieldBackground_Error()); 1117 ADialog.error(m_WindowNo, this, error); 1118 dataOK = false; 1119 } 1120 } 1121 1122 else if (PaymentRule.equals(MOrder.PAYMENTRULE_TransferACH)) 1124 { 1125 tAccountCombo.getSelectedItem(); 1126 String error = MPayment.validateRoutingNo(tRoutingField.getText()); 1127 if (error.length() != 0) 1128 { 1129 tRoutingField.setBackground(CompierePLAF.getFieldBackground_Error()); 1130 ADialog.error(m_WindowNo, this, error); 1131 dataOK = false; 1132 } 1133 error = MPayment.validateAccountNo(tNumberField.getText()); 1134 if (error.length() != 0) 1135 { 1136 tNumberField.setBackground(CompierePLAF.getFieldBackground_Error()); 1137 ADialog.error(m_WindowNo, this, error); 1138 dataOK = false; 1139 } 1140 } 1141 1142 else if (PaymentRule.equals(MOrder.PAYMENTRULE_OnCredit)) 1144 { 1145 KeyNamePair kp = (KeyNamePair)pTermCombo.getSelectedItem(); 1146 if (kp != null) 1147 C_PaymentTerm_ID = kp.getKey(); 1148 } 1149 1150 else if (PaymentRule.equals(MOrder.PAYMENTRULE_Check)) 1152 { 1153 KeyNamePair kp = (KeyNamePair)sBankAccountCombo.getSelectedItem(); 1155 if (kp != null) 1156 C_BankAccount_ID = kp.getKey(); 1157 String error = MPayment.validateRoutingNo(sRoutingField.getText()); 1158 if (error.length() != 0) 1159 { 1160 sRoutingField.setBackground(CompierePLAF.getFieldBackground_Error()); 1161 ADialog.error(m_WindowNo, this, error); 1162 dataOK = false; 1163 } 1164 error = MPayment.validateAccountNo(sNumberField.getText()); 1165 if (error.length() != 0) 1166 { 1167 sNumberField.setBackground(CompierePLAF.getFieldBackground_Error()); 1168 ADialog.error(m_WindowNo, this, error); 1169 dataOK = false; 1170 } 1171 error = MPayment.validateCheckNo(sCheckField.getText()); 1172 if (error.length() != 0) 1173 { 1174 sCheckField.setBackground(CompierePLAF.getFieldBackground_Error()); 1175 ADialog.error(m_WindowNo, this, error); 1176 dataOK = false; 1177 } 1178 } 1179 else 1180 { 1181 Log.error("VPayment.checkMandatory - Unknown PaymentRule " + PaymentRule); 1182 return false; 1183 } 1184 1185 if ("KTS".indexOf(PaymentRule) != -1 && C_BankAccount_ID == 0) 1187 { 1188 String tender = MPayment.TENDERTYPE_CreditCard; 1189 if (PaymentRule.equals("T")) 1190 tender = MPayment.TENDERTYPE_ACH; 1191 else if (PaymentRule.equals("S")) 1192 tender = MPayment.TENDERTYPE_Check; 1193 if (C_BankAccount_ID == 0 && "TS".indexOf(PaymentRule) != -1) 1195 { 1196 ADialog.error(m_WindowNo, this, "PaymentNoProcessor"); 1197 dataOK = false; 1198 } 1199 } 1200 Log.trace(Log.l3_Util, "VPayment.checkMandatory - OK=" + dataOK); 1202 return dataOK; 1203 } 1205 1210 private static int getInvoiceID (int C_Order_ID) 1211 { 1212 int retValue = 0; 1213 String sql = "SELECT C_Invoice_ID FROM C_Invoice WHERE C_Order_ID=? " 1214 + "ORDER BY C_Invoice_ID DESC"; try 1216 { 1217 PreparedStatement pstmt = DB.prepareStatement(sql); 1218 pstmt.setInt(1, C_Order_ID); 1219 ResultSet rs = pstmt.executeQuery(); 1220 if (rs.next()) 1221 retValue = rs.getInt(1); 1222 rs.close(); 1223 pstmt.close(); 1224 } 1225 catch (SQLException e) 1226 { 1227 Log.error ("VPayment.getInvoiceID", e); 1228 } 1229 return retValue; 1230 } 1232 1233 1234 1237 private void processOnline() 1238 { 1239 Log.trace(Log.l3_Util, "VPayment.processOnline"); 1240 if (!checkMandatory()) 1241 return; 1242 1243 boolean approved = false; 1244 String info = ""; 1245 ValueNamePair vp = (ValueNamePair)paymentCombo.getSelectedItem(); 1247 String PaymentRule = vp.getValue(); 1248 1249 if (PaymentRule.equals(X_C_Order.PAYMENTRULE_CreditCard)) 1251 { 1252 vp = (ValueNamePair)kTypeCombo.getSelectedItem(); 1253 String CCType = vp.getValue(); 1254 1255 m_mPayment.setCreditCard(MPayment.TRXTYPE_Sales, CCType, 1256 kNumberField.getText(), "", kExpField.getText()); 1257 m_mPayment.setAmount(m_C_Currency_ID, m_Amount); 1258 m_mPayment.setPaymentProcessor(); 1259 m_mPayment.setC_BPartner_ID(m_C_BPartner_ID); 1260 int C_Invoice_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "C_Invoice_ID"); 1262 if (C_Invoice_ID == 0 && m_DocStatus.equals("CO")) 1263 { 1264 int C_Order_ID = Env.getContextAsInt(Env.getCtx(), m_WindowNo, "C_Order_ID"); 1265 C_Invoice_ID = getInvoiceID (C_Order_ID); 1266 } 1267 m_mPayment.setC_Invoice_ID(C_Invoice_ID); 1268 m_mPayment.setDateTrx(m_DateAcct); 1269 m_mPayment.setAmount(m_C_Currency_ID, m_Amount); 1271 1272 approved = m_mPayment.processOnline(); 1273 info = m_mPayment.getR_RespMsg() + " (" + m_mPayment.getR_AuthCode() 1274 + ") ID=" + m_mPayment.getR_PnRef(); 1275 boolean saved = m_mPayment.save(); 1276 1277 if (approved) 1278 { 1279 if (m_mPayment.post()) 1280 ADialog.info(m_WindowNo, this, "PaymentProcessed", info + "\n" + m_mPayment.getDocumentNo()); 1281 else 1282 ADialog.error(m_WindowNo, this, "PaymentError", "PaymentNotCreated"); 1283 saveChanges(); 1284 dispose(); 1285 } 1286 else 1287 { 1288 ADialog.error(m_WindowNo, this, "PaymentNotProcessed", info); 1289 } 1290 } 1291 else 1292 ADialog.error(m_WindowNo, this, "PaymentNoProcessor"); 1293 } 1295} | Popular Tags |