KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > apps > form > VPaySelect


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2001 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.apps.form;
15
16 import javax.swing.*;
17 import javax.swing.event.*;
18 import java.awt.*;
19 import java.awt.event.*;
20 import java.sql.*;
21 import java.math.*;
22 import java.text.*;
23 import java.util.*;
24
25 import org.compiere.util.*;
26 import org.compiere.apps.*;
27 import org.compiere.grid.ed.*;
28 import org.compiere.minigrid.*;
29 import org.compiere.model.*;
30 import org.compiere.swing.*;
31 import org.compiere.plaf.*;
32 import org.compiere.process.*;
33
34 /**
35  * Create Manual Payments From (AP) Invoices or (AR) Credit Memos.
36  * Allows user to select Invoices for payment.
37  * When Processed, PaySelection is created
38  * and optionally posted/generated and printed
39  *
40  * @author Jorg Janke
41  * @version $Id: VPaySelect.java,v 1.26 2003/10/27 15:22:02 jjanke Exp $
42  */

43 public class VPaySelect extends CPanel
44     implements FormPanel, ActionListener, TableModelListener, ASyncProcess
45 {
46     /** @todo withholding */
47
48     /**
49      * VPaySelect Constructor
50      */

51     public VPaySelect()
52     {
53     } // VPaySelect
54

55     /**
56      * Initialize Panel
57      * @param WindowNo window
58      * @param frame frame
59      */

60     public void init (int WindowNo, FormFrame frame)
61     {
62         Log.trace(Log.l1_User, "VPaySelect.init");
63         m_WindowNo = WindowNo;
64         m_frame = frame;
65         try
66         {
67             jbInit();
68             dynInit();
69             frame.getContentPane().add(commandPanel, BorderLayout.SOUTH);
70             frame.getContentPane().add(mainPanel, BorderLayout.CENTER);
71         }
72         catch(Exception JavaDoc e)
73         {
74             Log.error("VPaySelect.init", e);
75         }
76     } // init
77

78     /** Window No */
79     private int m_WindowNo = 0;
80     /** FormFrame */
81     private FormFrame m_frame;
82
83     /** Format */
84     private DecimalFormat m_format = DisplayType.getNumberFormat(DisplayType.Amount);
85     /** Bank Balance */
86     private BigDecimal m_bankBalance = new BigDecimal(0.0);
87     /** SQL for Query */
88     private String JavaDoc m_sql;
89     /** Number of selected rows */
90     private int m_noSelected = 0;
91     /** Client ID */
92     private int m_AD_Client_ID = 0;
93     /**/
94     private boolean m_isLocked = false;
95
96     //
97
private CPanel mainPanel = new CPanel();
98     private BorderLayout mainLayout = new BorderLayout();
99     private CPanel parameterPanel = new CPanel();
100     private CLabel labelBankAccount = new CLabel();
101     private VComboBox fieldBankAccount = new VComboBox();
102     private GridBagLayout parameterLayout = new GridBagLayout();
103     private CLabel labelBankBalance = new CLabel();
104     private CLabel labelCurrency = new CLabel();
105     private CLabel labelBalance = new CLabel();
106     private VCheckBox onlyDue = new VCheckBox();
107     private CLabel labelBPartner = new CLabel();
108     private VComboBox fieldBPartner = new VComboBox();
109     private JLabel dataStatus = new JLabel();
110     private JScrollPane dataPane = new JScrollPane();
111     private MiniTable miniTable = new MiniTable();
112     private CPanel commandPanel = new CPanel();
113     private JButton bCancel = ConfirmPanel.createCancelButton(true);
114     private JButton bGenerate = ConfirmPanel.createProcessButton(true);
115     private FlowLayout commandLayout = new FlowLayout();
116     private JButton bRefresh = ConfirmPanel.createRefreshButton(true);
117     private CLabel labelPayDate = new CLabel();
118     private VDate fieldPayDate = new VDate();
119     private CLabel labelPaymentRule = new CLabel();
120     private VComboBox fieldPaymentRule = new VComboBox();
121
122     /**
123      * Static Init
124      * @throws Exception
125      */

126     private void jbInit() throws Exception JavaDoc
127     {
128         CompiereColor.setBackground(this);
129         //
130
mainPanel.setLayout(mainLayout);
131         parameterPanel.setLayout(parameterLayout);
132         //
133
labelBankAccount.setText(Msg.translate(Env.getCtx(), "C_BankAccount_ID"));
134         fieldBankAccount.addActionListener(this);
135         labelBPartner.setText(Msg.translate(Env.getCtx(), "C_BPartner_ID"));
136         fieldBPartner.addActionListener(this);
137         bRefresh.addActionListener(this);
138         labelPayDate.setText(Msg.translate(Env.getCtx(), "PayDate"));
139         labelPaymentRule.setText(Msg.translate(Env.getCtx(), "PaymentRule"));
140         //
141
labelBankBalance.setText(Msg.translate(Env.getCtx(), "CurrentBalance"));
142         labelBalance.setText("0");
143         onlyDue.setText(Msg.getMsg(Env.getCtx(), "OnlyDue"));
144         dataStatus.setText(" ");
145         //
146
bGenerate.addActionListener(this);
147         bCancel.addActionListener(this);
148         //
149
mainPanel.add(parameterPanel, BorderLayout.NORTH);
150         parameterPanel.add(labelBankAccount, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0
151             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
152         parameterPanel.add(fieldBankAccount, new GridBagConstraints(1, 0, 1, 1, 0.0, 0.0
153             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
154         parameterPanel.add(labelBankBalance, new GridBagConstraints(2, 0, 1, 1, 0.0, 0.0
155             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
156         parameterPanel.add(labelCurrency, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0
157             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 0, 5, 5), 0, 0));
158         parameterPanel.add(labelBalance, new GridBagConstraints(3, 0, 1, 1, 0.0, 0.0
159             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
160         parameterPanel.add(labelBPartner, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0
161             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
162         parameterPanel.add(fieldBPartner, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0
163             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
164         parameterPanel.add(bRefresh, new GridBagConstraints(4, 2, 1, 1, 0.0, 0.0
165             ,GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
166         parameterPanel.add(labelPayDate, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0
167             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
168         parameterPanel.add(fieldPayDate, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0
169             ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));
170         parameterPanel.add(labelPaymentRule, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0
171             ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
172         parameterPanel.add(fieldPaymentRule, new GridBagConstraints(3, 2, 1, 1, 0.0, 0.0
173             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
174         parameterPanel.add(onlyDue, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0
175             ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0));
176         mainPanel.add(dataStatus, BorderLayout.SOUTH);
177         mainPanel.add(dataPane, BorderLayout.CENTER);
178         dataPane.getViewport().add(miniTable, null);
179         //
180
commandPanel.setLayout(commandLayout);
181         commandLayout.setAlignment(FlowLayout.RIGHT);
182         commandLayout.setHgap(10);
183         commandPanel.add(bCancel, null);
184         commandPanel.add(bGenerate, null);
185     } // jbInit
186

187     /**
188      * Dynamic Init.
189      * - Load Bank Info
190      * - Load BPartner
191      * - Init Table
192      */

193     private void dynInit()
194     {
195         Properties ctx = Env.getCtx();
196
197         // Bank Account Info
198
String JavaDoc sql = MRole.getDefault().addAccessSQL(
199             "SELECT ba.C_BankAccount_ID," // 1
200
+ "b.Name || ' ' || ba.AccountNo AS Name," // 2
201
+ "ba.C_Currency_ID, c.ISO_Code," // 3..4
202
+ "ba.CurrentBalance " // 5
203
+ "FROM C_Bank b, C_BankAccount ba, C_Currency c "
204             + "WHERE b.C_Bank_ID=ba.C_Bank_ID"
205             + " AND ba.C_Currency_ID=c.C_Currency_ID "
206             + " AND EXISTS (SELECT * FROM C_BankAccountDoc d WHERE d.C_BankAccount_ID=ba.C_BankAccount_ID)",
207             "ba", MRole.SQL_FULLYQUALIFIED, MRole.SQL_RW);
208         try
209         {
210             PreparedStatement pstmt = DB.prepareStatement(sql);
211             ResultSet rs = pstmt.executeQuery();
212             while (rs.next())
213             {
214                 boolean transfers = false;
215                 BankInfo bi = new BankInfo (rs.getInt(1), rs.getInt(3),
216                     rs.getString(2), rs.getString(4),
217                     rs.getBigDecimal(5), transfers);
218                 fieldBankAccount.addItem(bi);
219             }
220             rs.close();
221             pstmt.close();
222         }
223         catch (SQLException e)
224         {
225             Log.error ("VPaySelect.dynInit - BA", e);
226         }
227         if (fieldBankAccount.getItemCount() == 0)
228             ADialog.error(m_WindowNo, this, "VPaySelectNoBank");
229         else
230             fieldBankAccount.setSelectedIndex(0);
231
232         // Optional BusinessPartner with unpaid AP Invoices
233
KeyNamePair pp = new KeyNamePair(0, "");
234         fieldBPartner.addItem(pp);
235         sql = MRole.getDefault().addAccessSQL(
236             "SELECT bp.C_BPartner_ID, bp.Name FROM C_BPartner bp", "bp",
237             MRole.SQL_FULLYQUALIFIED, MRole.SQL_RO)
238             + " AND EXISTS (SELECT * FROM C_Invoice i WHERE bp.C_BPartner_ID=i.C_BPartner_ID"
239               + " AND i.IsSOTrx='N' AND i.IsPaid<>'Y')";
240         try
241         {
242             PreparedStatement pstmt = DB.prepareStatement(sql);
243             ResultSet rs = pstmt.executeQuery();
244             while (rs.next())
245             {
246                 pp = new KeyNamePair(rs.getInt(1), rs.getString(2));
247                 fieldBPartner.addItem(pp);
248             }
249             rs.close();
250             pstmt.close();
251         }
252         catch (SQLException e)
253         {
254             Log.error ("VPaySelect.dynInit - BP", e);
255         }
256         fieldBPartner.setSelectedIndex(0);
257
258         /** prepare MiniTable
259          *
260         SELECT i.C_Invoice_ID, i.DateInvoiced+p.NetDays AS DateDue,
261         bp.Name, i.DocumentNo, c.ISO_Code, i.GrandTotal,
262         C_PaymentTerm_Discount(i.GrandTotal, i.C_PaymentTerm_ID, i.DateInvoiced, SysDate) AS Discount,
263         SysDate-C_PaymentTerm_DueDays(i.C_PaymentTerm_ID,i.DateInvoiced) AS DiscountDate,
264         i.GrandTotal-C_PaymentTerm_Discount(i.GrandTotal,i.C_PaymentTerm_ID,i.DateInvoiced,SysDate) AS DueAmount,
265         C_Currency_Convert(i.GrandTotal-C_PaymentTerm_Discount(i.GrandTotal,i.C_PaymentTerm_ID,i.DateInvoiced,SysDate,null),
266             i.C_Currency_ID,100,SysDate) AS PayAmt
267         FROM C_Invoice i, C_BPartner bp, C_Currency c, C_PaymentTerm p
268         WHERE i.IsSOTrx='N'
269         AND i.C_BPartner_ID=bp.C_BPartner_ID
270         AND i.C_Currency_ID=c.C_Currency_ID
271         AND i.C_PaymentTerm_ID=p.C_PaymentTerm_ID
272         AND i.DocStatus IN ('CO','CL')
273         ORDER BY 2,3
274          */

275
276         m_sql = miniTable.prepareTable(new ColumnInfo[] {
277             // 0..4
278
new ColumnInfo(" ", "i.C_Invoice_ID", IDColumn.class, false, false, null),
279             new ColumnInfo(Msg.translate(ctx, "DateDue"), "i.DateInvoiced+p.NetDays AS DateDue", Timestamp.class, true, true, null),
280             new ColumnInfo(Msg.translate(ctx, "C_BPartner_ID"), "bp.Name", KeyNamePair.class, true, false, "i.C_BPartner_ID"),
281             new ColumnInfo(Msg.translate(ctx, "DocumentNo"), "i.DocumentNo", String JavaDoc.class),
282             new ColumnInfo(Msg.translate(ctx, "C_Currency_ID"), "c.ISO_Code", KeyNamePair.class, true, false, "i.C_Currency_ID"),
283             // 5..9
284
new ColumnInfo(Msg.translate(ctx, "GrandTotal"), "i.GrandTotal", BigDecimal.class),
285             new ColumnInfo(Msg.translate(ctx, "DifferenceAmt"), "C_PaymentTerm_Discount(i.GrandTotal,i.C_PaymentTerm_ID,i.DateInvoiced, ?) AS DifferenceAm", BigDecimal.class),
286             new ColumnInfo(Msg.getMsg(ctx, "DiscountDate"), "SysDate-C_PaymentTerm_DueDays(i.C_PaymentTerm_ID,i.DateInvoiced) AS DiscountDate", Timestamp.class),
287             new ColumnInfo(Msg.getMsg(ctx, "AmountDue"), "i.GrandTotal-C_PaymentTerm_Discount(i.GrandTotal,i.C_PaymentTerm_ID,i.DateInvoiced, ?) AS DueAmount", BigDecimal.class),
288             new ColumnInfo(Msg.getMsg(ctx, "AmountPay"), "C_Currency_Convert(i.GrandTotal-C_PaymentTerm_Discount(i.GrandTotal,i.C_PaymentTerm_ID,i.DateInvoiced, ?),i.C_Currency_ID, ?,?,null, i.AD_Client_ID,i.AD_Org_ID) AS PayAmt", BigDecimal.class)
289             },
290             "C_Invoice i, C_BPartner bp, C_Currency c, C_PaymentTerm p",
291             "i.IsSOTrx='N' AND IsPaid='N' AND i.C_BPartner_ID=bp.C_BPartner_ID"
292             + " AND NOT EXISTS (SELECT * FROM C_PaySelectionLine psl"
293                 + " WHERE i.C_Invoice_ID=psl.C_Invoice_ID AND psl.C_PaySelectionCheck_ID IS NOT NULL)"
294             + " AND i.C_Currency_ID=c.C_Currency_ID"
295             + " AND i.C_PaymentTerm_ID=p.C_PaymentTerm_ID"
296             + " AND i.DocStatus IN ('CO','CL')"
297             + " AND i.AD_Client_ID=?",
298             true, "i");
299         //
300
miniTable.getModel().addTableModelListener(this);
301         //
302
fieldPayDate.setMandatory(true);
303         fieldPayDate.setValue(new Timestamp(System.currentTimeMillis()));
304         //
305
m_AD_Client_ID = Integer.parseInt(Env.getContext(Env.getCtx(), "#AD_Client_ID"));
306     } // dynInit
307

308     /**
309      * Load Bank Info - Load Info from Bank Account and valid Documents (PaymentRule)
310      */

311     private void loadBankInfo()
312     {
313         BankInfo bi = (BankInfo)fieldBankAccount.getSelectedItem();
314         if (bi == null)
315             return;
316         labelCurrency.setText(bi.Currency);
317         labelBalance.setText(m_format.format(bi.Balance));
318         m_bankBalance = bi.Balance;
319
320         // PaymentRule
321
fieldPaymentRule.removeAllItems();
322         int AD_Reference_ID = 195; // MLookupInfo.getAD_Reference_ID("All_Payment Rule");
323
Language language = Env.getLanguage(Env.getCtx());
324         MLookupInfo info = MLookupFactory.getLookup_List(language, AD_Reference_ID);
325         String JavaDoc sql = info.Query.substring(0, info.Query.indexOf(" ORDER BY"))
326             + " AND " + info.KeyColumn
327             + " IN (SELECT PaymentRule FROM C_BankAccountDoc WHERE C_BankAccount_ID=?) "
328             + info.Query.substring(info.Query.indexOf(" ORDER BY"));
329         try
330         {
331             PreparedStatement pstmt = DB.prepareStatement(sql);
332             pstmt.setInt(1, bi.C_BankAccount_ID);
333             ResultSet rs = pstmt.executeQuery();
334             ValueNamePair vp = null;
335             while (rs.next())
336             {
337                 vp = new ValueNamePair(rs.getString(2), rs.getString(3)); // returns also not active
338
fieldPaymentRule.addItem(vp);
339             }
340             rs.close();
341             pstmt.close();
342         }
343         catch (SQLException e)
344         {
345             Log.error ("VPaySelect.loadBankInfo - SQL=" + sql, e);
346         }
347         fieldPaymentRule.setSelectedIndex(0);
348
349     } // loadBankInfo
350

351     /**
352      * Query and create TableInfo
353      */

354     private void loadTableInfo()
355     {
356         Log.trace(Log.l3_Util, "VPaySelect.loadTableInfo");
357         // not yet initialized
358
if (m_sql == null)
359             return;
360
361         String JavaDoc sql = m_sql;
362         // Parameters
363
Timestamp payDate = (Timestamp)fieldPayDate.getValue();
364         miniTable.setColorCompare(payDate);
365         Log.trace(Log.l4_Data, "PayDate", payDate.toString());
366         BankInfo bi = (BankInfo)fieldBankAccount.getSelectedItem();
367         //
368
if (onlyDue.isSelected())
369             sql += " AND i.DateInvoiced+p.NetDays <= ?";
370         //
371
KeyNamePair pp = (KeyNamePair)fieldBPartner.getSelectedItem();
372         int C_BPartner_ID = pp.getKey();
373         if (C_BPartner_ID != 0)
374             sql += " AND i.C_BPartner_ID=?";
375         sql += " ORDER BY 2,3";
376
377         // Get Open Invoices
378
try
379         {
380             int index = 1;
381             PreparedStatement pstmt = DB.prepareStatement(sql);
382             pstmt.setTimestamp(index++, payDate);
383             pstmt.setTimestamp(index++, payDate);
384             pstmt.setTimestamp(index++, payDate);
385             pstmt.setInt(index++, bi.C_Currency_ID);
386             pstmt.setTimestamp(index++, payDate);
387             pstmt.setInt(index++, m_AD_Client_ID);
388             if (onlyDue.isSelected())
389                 pstmt.setTimestamp(index++, payDate);
390             if (C_BPartner_ID != 0)
391                 pstmt.setInt(index++, C_BPartner_ID);
392             //
393
ResultSet rs = pstmt.executeQuery();
394             miniTable.loadTable(rs);
395             rs.close();
396             pstmt.close();
397         }
398         catch (SQLException e)
399         {
400             Log.error ("VPaySelect.loadTableInfo", e);
401         }
402         calculateSelection();
403     } // loadTableInfo
404

405     /**
406      * Dispose
407      */

408     public void dispose()
409     {
410         m_frame.dispose();
411     } // dispose
412

413     /*************************************************************************/
414
415     /**
416      * ActionListener
417      * @param e event
418      */

419     public void actionPerformed (ActionEvent e)
420     {
421         // Update Bank Info
422
if (e.getSource() == fieldBankAccount)
423             loadBankInfo();
424
425         // Generate PaySelection
426
else if (e.getSource() == bGenerate)
427         {
428             cmd_generate();
429             dispose();
430         }
431
432         else if (e.getSource() == bCancel)
433             dispose();
434
435         // Update Open Invoices
436
else if (e.getSource() == fieldBPartner || e.getSource() == bRefresh)
437             loadTableInfo();
438
439     } // actionPerformed
440

441     /**
442      * Table Model Listener
443      * @param e event
444      */

445     public void tableChanged(TableModelEvent e)
446     {
447         if (e.getColumn() == 0)
448             calculateSelection();
449     } // valueChanged
450

451     /**
452      * Calculate selected rows.
453      * - add up selected rows
454      */

455     public void calculateSelection()
456     {
457         m_noSelected = 0;
458         BigDecimal invoiceAmt = new BigDecimal(0.0);
459
460         int rows = miniTable.getRowCount();
461         for (int i = 0; i < rows; i++)
462         {
463             IDColumn id = (IDColumn)miniTable.getModel().getValueAt(i, 0);
464             if (id.isSelected())
465             {
466                 BigDecimal amt = (BigDecimal)miniTable.getModel().getValueAt(i, 9);
467                 invoiceAmt = invoiceAmt.add(amt);
468                 m_noSelected++;
469             }
470         }
471
472         // Information
473
BigDecimal remaining = m_bankBalance.subtract(invoiceAmt);
474         StringBuffer JavaDoc info = new StringBuffer JavaDoc();
475         info.append(m_noSelected).append(" ").append(Msg.getMsg(Env.getCtx(), "Selected")).append(" - ");
476         info.append(m_format.format(invoiceAmt)).append(", ");
477         info.append(Msg.getMsg(Env.getCtx(), "Remaining")).append(" ").append(m_format.format(remaining));
478         dataStatus.setText(info.toString());
479         //
480
bGenerate.setEnabled(m_noSelected != 0);
481     } // calculateSelection
482

483     /**
484      * Generate PaySelection
485      */

486     private void cmd_generate()
487     {
488         Log.trace(Log.l1_User, "VPaySelect.cmd_generate");
489         miniTable.stopEditor(true);
490         if (miniTable.getRowCount() == 0)
491             return;
492         miniTable.setRowSelectionInterval(0,0);
493         calculateSelection();
494         if (m_noSelected == 0)
495             return;
496
497         String JavaDoc PaymentRule = ((ValueNamePair)fieldPaymentRule.getSelectedItem()).getValue();
498
499         // Create Header
500
int C_PaySelection_ID = DB.getKeyNextNo(Env.getCtx(), m_WindowNo, "C_PaySelection");
501         int AD_Org_ID = Integer.parseInt(Env.getContext(Env.getCtx(), "#AD_Org_ID"));
502         int AD_User_ID = Integer.parseInt(Env.getContext(Env.getCtx(), "#AD_User_ID"));
503         Timestamp now = new Timestamp(System.currentTimeMillis());
504         String JavaDoc Name = Msg.getMsg(Env.getCtx(), "VPaySelect") + " - " + now.toString();
505         BankInfo bi = (BankInfo)fieldBankAccount.getSelectedItem();
506         int C_BankAccount_ID = bi.C_BankAccount_ID;
507         int C_Currency_ID = bi.C_Currency_ID;
508         String JavaDoc PayDate = DB.TO_DATE((Timestamp)fieldPayDate.getValue(), true);
509
510         StringBuffer JavaDoc sql = new StringBuffer JavaDoc("INSERT INTO C_PaySelection (");
511         sql.append("C_PaySelection_ID,AD_Client_ID,AD_Org_ID, IsActive,Created,CreatedBy,Updated,UpdatedBy, ")
512             .append("Name,Description, C_BankAccount_ID,PayDate, ")
513             .append("IsApproved,TotalAmt,Processing,CreateFrom,Processed");
514         sql.append(") VALUES (");
515         sql.append(C_PaySelection_ID).append(",").append(m_AD_Client_ID).append(",").append(AD_Org_ID)
516                 .append(", 'Y',SysDate,").append(AD_User_ID).append(",SysDate,").append(AD_User_ID).append(", ")
517             .append("'").append(Name).append("',null, ")
518                 .append(C_BankAccount_ID).append(",").append(PayDate).append(", 'Y',0,'N','N','N')");
519         // execute cmd
520
int no = DB.executeUpdate(sql.toString());
521         if (no != 1)
522         {
523             ValueNamePair pp = Log.retrieveError();
524             ADialog.error(m_WindowNo, this, pp.getValue(), pp.getName());
525             return;
526         }
527         else
528             Log.trace(Log.l4_Data, "PaySelect.cmd_generate", "PaySelection=" + Name);
529
530         // Create Lines
531
int rows = miniTable.getRowCount();
532         int line = 0;
533         for (int i = 0; i < rows; i++)
534         {
535             IDColumn id = (IDColumn)miniTable.getModel().getValueAt(i, 0);
536             if (id.isSelected())
537             {
538                 int C_PaySelectionLine_ID = DB.getKeyNextNo(Env.getCtx(), m_WindowNo, "C_PaySelectionLine");
539                 line += 10;
540                 int C_Invoice_ID = id.getRecord_ID().intValue();
541                 BigDecimal DiffAmt = (BigDecimal)miniTable.getModel().getValueAt(i, 6);
542                 BigDecimal PayAmt = (BigDecimal)miniTable.getModel().getValueAt(i, 9);
543                 //
544
sql = new StringBuffer JavaDoc("INSERT INTO C_PaySelectionLine (");
545                 sql.append("C_PaySelectionLine_ID,C_PaySelection_ID, ")
546                     .append("AD_Client_ID,AD_Org_ID, IsActive,Created,CreatedBy,Updated,UpdatedBy, ")
547                     .append("Line,PaymentRule,IsManual, ")
548                     .append("C_Invoice_ID,PayAmt,DifferenceAmt");
549                 sql.append(") VALUES (");
550                 sql.append(C_PaySelectionLine_ID).append(",").append(C_PaySelection_ID)
551                     .append(",").append(m_AD_Client_ID).append(",").append(AD_Org_ID)
552                     .append(", 'Y',SysDate,").append(AD_User_ID).append(",SysDate,").append(AD_User_ID).append(", ")
553                     .append(line).append(",'").append(PaymentRule).append("','N', ")
554                     .append(C_Invoice_ID).append(",").append(PayAmt).append(",").append(DiffAmt)
555                     .append(")");
556                 // execute cmd
557
no = DB.executeUpdate(sql.toString());
558                 if (no != 1)
559                 {
560                     ValueNamePair pp = Log.retrieveError();
561                     ADialog.error(m_WindowNo, this, pp.getValue(), pp.getName());
562                     return;
563                 }
564                 else
565                     Log.trace(Log.l6_Database, "PaySelect.cmd_generate", "C_Invoice_ID=" + C_Invoice_ID + ", PayAmt=" + PayAmt);
566             }
567         } // for all rows in table
568

569
570         // Ask to Post it
571
if (!ADialog.ask(m_WindowNo, this, "VPaySelectGenerate?", "(" + Name + ")"))
572             return;
573
574         // Run Process
575
ProcessInfo pi = new ProcessInfo (m_frame.getTitle(), 155, C_PaySelection_ID);
576         ProcessCtl.process(this, m_WindowNo, pi); // calls lockUI/..
577
} // cmd_generate
578

579     /**
580      * Lock User Interface
581      * Called from the Worker before processing
582      * @param pi process info
583      */

584     public void lockUI (ProcessInfo pi)
585     {
586         this.setEnabled(false);
587         m_isLocked = true;
588     } // lockUI
589

590     /**
591      * Unlock User Interface.
592      * Called from the Worker when processing is done
593      * @param pi process info
594      */

595     public void unlockUI (ProcessInfo pi)
596     {
597     // this.setEnabled(true);
598
// m_isLocked = false;
599
// Ask to Print it
600
if (!ADialog.ask(m_WindowNo, this, "VPaySelectPrint?", "(" + pi.getSummary() + ")"))
601             return;
602
603         // Start PayPrint
604
int AD_Form_ID = 106; // Payment Print/Export
605
FormFrame ff = new FormFrame();
606         ff.openForm (AD_Form_ID);
607         ff.pack();
608         this.setVisible(false);
609         AEnv.showCenterScreen(ff);
610         this.dispose();
611     } // unlockUI
612

613     /**
614      * Is the UI locked (Internal method)
615      * @return true, if UI is locked
616      */

617     public boolean isUILocked()
618     {
619         return m_isLocked;
620     } // isLoacked
621

622     /**
623      * Method to be executed async.
624      * Called from the ASyncProcess worker
625      * @param pi process info
626      */

627     public void executeASync (ProcessInfo pi)
628     {
629         Log.trace(Log.l3_Util, "VPaySelect.executeASync");
630     } // executeASync
631

632     /*************************************************************************/
633
634     /**
635      * Bank Account Info
636      */

637     public class BankInfo
638     {
639         public BankInfo (int newC_BankAccount_ID, int newC_Currency_ID,
640             String JavaDoc newName, String JavaDoc newCurrency, BigDecimal newBalance, boolean newTransfers)
641         {
642             C_BankAccount_ID = newC_BankAccount_ID;
643             C_Currency_ID = newC_Currency_ID;
644             Name = newName;
645             Currency = newCurrency;
646             Balance = newBalance;
647         }
648         int C_BankAccount_ID;
649         int C_Currency_ID;
650         String JavaDoc Name;
651         String JavaDoc Currency;
652         BigDecimal Balance;
653         boolean Transfers;
654
655         public String JavaDoc toString()
656         {
657             return Name;
658         }
659     } // BankInfo
660

661 } // VPaySelect
662
Popular Tags