KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > acct > DocLine


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.acct;
15
16 import java.math.*;
17 import java.sql.*;
18
19 import org.apache.log4j.Logger;
20
21 import org.compiere.util.Env;
22 import org.compiere.util.DB;
23 import org.compiere.model.*;
24
25 /**
26  * Standard Document Line
27  *
28  * @author Jorg Janke
29  * @version $Id: DocLine.java,v 1.15 2003/10/10 01:03:41 jjanke Exp $
30  */

31 public class DocLine
32 {
33     /**
34      * Create Document Line
35      * @param DocumentType document type
36      * @param TrxHeader_ID Record_ID
37      * @param TrxLine_ID Line_ID
38      */

39     public DocLine(String JavaDoc DocumentType, int TrxHeader_ID, int TrxLine_ID)
40     {
41         if (DocumentType == null)
42             throw new IllegalArgumentException JavaDoc("DocLine - DocumentType is null");
43         p_DocumentType = DocumentType;
44         m_TrxHeader_ID = TrxHeader_ID;
45         m_TrxLine_ID = TrxLine_ID;
46     } // DocLine
47

48     /** Log */
49     protected Logger log = Logger.getLogger(getClass());
50
51     /** ID - Document Type */
52     protected String JavaDoc p_DocumentType = null;
53     /** ID - Trx Header */
54     private int m_TrxHeader_ID = 0;
55     /** ID - Line ID */
56     private int m_TrxLine_ID = 0;
57     /** Line */
58     private int m_Line = 0;
59
60     /** Qty UOM */
61     private int m_C_UOM_ID = 0;
62     /** Qty */
63     private BigDecimal m_qty = null;
64
65
66     /** Currency */
67     private int m_C_Currency_ID = 0;
68
69     // -- GL Amounts
70
/** Debit Journal Amt */
71     private BigDecimal m_AmtSourceDr = Env.ZERO;
72     /** Credit Journal Amt */
73     private BigDecimal m_AmtSourceCr = Env.ZERO;
74
75     /** Converted Amounts */
76     private BigDecimal m_AmtAcctDr = null;
77     private BigDecimal m_AmtAcctCr = null;
78     private int m_C_AcctSchema_ID = 0;
79
80     protected ProductInfo p_productInfo = null;
81
82     /** Account used only for GL Journal */
83     private Account m_account = null;
84
85     // Dimensions
86
private int m_AD_Org_ID = 0;
87     private int m_C_BPartner_ID = 0;
88     private int m_M_Product_ID = 0;
89     private int m_AD_OrgTrx_ID = 0;
90     private int m_C_SalesRegion_ID = 0;
91     private int m_C_Project_ID = 0;
92     private int m_C_Campaign_ID = 0;
93     private int m_C_Activity_ID = 0;
94     private int m_C_LocFrom_ID = 0;
95     private int m_C_LocTo_ID = 0;
96     private int m_User1_ID = 0;
97     private int m_User2_ID = 0;
98     //
99
private int m_C_Charge_ID = 0;
100     private BigDecimal m_ChargeAmt = Env.ZERO;
101     /** Description */
102     private String JavaDoc m_description = null;
103     /** Tax ID */
104     private int m_C_Tax_ID = 0;
105
106     private Timestamp m_DateAcct = null;
107     private Timestamp m_DateDoc = null;
108     
109     private int m_M_AttributSetInstance_ID = 0;
110
111     /*************************************************************************/
112
113     /**
114      * Load Attributes from ResultSet
115      * @param rs result set
116      * @param vo doc value object
117      */

118     public void loadAttributes (ResultSet rs, DocVO vo)
119     {
120     // Log.trace(this,Log.l4_Data, "DocLine.loadAttributes");
121
try
122         {
123             ResultSetMetaData rsmd = rs.getMetaData();
124             for (int i = 1; i <= rsmd.getColumnCount(); i++)
125             {
126                 String JavaDoc col = rsmd.getColumnName(i);
127                 if (col.equalsIgnoreCase("AD_Org_ID"))
128                     m_AD_Org_ID = rs.getInt(i);
129                 else if (col.equalsIgnoreCase("C_BPartner_ID"))
130                     m_C_BPartner_ID = rs.getInt(i);
131                 else if (col.equalsIgnoreCase("M_Product_ID"))
132                     m_M_Product_ID = rs.getInt(i);
133                 else if (col.equalsIgnoreCase("AD_OrgTrx_ID"))
134                     m_AD_OrgTrx_ID = rs.getInt(i);
135                 else if (col.equalsIgnoreCase("C_SalesRegion_ID"))
136                     m_C_SalesRegion_ID = rs.getInt(i);
137                 else if (col.equalsIgnoreCase("C_Project_ID"))
138                     m_C_Project_ID = rs.getInt(i);
139                 else if (col.equalsIgnoreCase("C_Campaign_ID"))
140                     m_C_Campaign_ID = rs.getInt(i);
141                 else if (col.equalsIgnoreCase("C_Activity_ID"))
142                     m_C_Activity_ID = rs.getInt(i);
143                 else if (col.equalsIgnoreCase("C_LocFrom_ID"))
144                     m_C_LocFrom_ID = rs.getInt(i);
145                 else if (col.equalsIgnoreCase("C_LocTo_ID"))
146                     m_C_LocTo_ID = rs.getInt(i);
147                 else if (col.equalsIgnoreCase("User1_ID"))
148                     m_User1_ID = rs.getInt(i);
149                 else if (col.equalsIgnoreCase("User2_ID"))
150                     m_User2_ID = rs.getInt(i);
151                 // Line, Description, Currency
152
else if (col.equalsIgnoreCase("Line"))
153                     m_Line = rs.getInt(i);
154                 else if (col.equalsIgnoreCase("Description"))
155                     m_description = rs.getString(i);
156                 else if (col.equalsIgnoreCase("C_Currency_ID"))
157                     m_C_Currency_ID = rs.getInt(i);
158                 // Qty
159
else if (col.equalsIgnoreCase("C_UOM_ID"))
160                     m_C_UOM_ID = rs.getInt(i);
161                 else if (col.equalsIgnoreCase("Qty"))
162                     m_qty = rs.getBigDecimal(i);
163                 //
164
else if (col.equalsIgnoreCase("C_Tax_ID"))
165                     m_C_Tax_ID = rs.getInt(i);
166                 else if (col.equalsIgnoreCase("C_Charge_ID"))
167                     m_C_Charge_ID = rs.getInt(i);
168                 else if (col.equalsIgnoreCase("ChargeAmt"))
169                     m_ChargeAmt = rs.getBigDecimal(i);
170                 //
171
else if (col.equalsIgnoreCase("DateAcct"))
172                     m_DateAcct = rs.getTimestamp(i);
173                 else if (col.equalsIgnoreCase("DateDoc"))
174                     m_DateDoc = rs.getTimestamp(i);
175                 //
176
else if (col.equalsIgnoreCase("M_AttributSetInstance_ID"))
177                     m_M_AttributSetInstance_ID = rs.getInt(i);
178             } // for all columns
179
}
180         catch (SQLException e)
181         {
182             log.error ("loadAttributes", e);
183         }
184         // Product Info
185
p_productInfo = new ProductInfo(m_M_Product_ID);
186
187         // Document Consistency
188
if (m_AD_Org_ID == 0)
189             m_AD_Org_ID = vo.AD_Org_ID;
190         if (m_C_Currency_ID == 0)
191             m_C_Currency_ID = vo.C_Currency_ID;
192     } // loadAttributes
193

194
195     /*************************************************************************/
196
197     /**
198      * Set Currency
199      * @param C_Currency_ID currency
200      */

201     public void setC_Currency_ID (int C_Currency_ID)
202     {
203         m_C_Currency_ID = C_Currency_ID;
204     } // setC_Currency_ID
205

206     /**
207      * Get Currency
208      * @return c_Currency_ID
209      */

210     public int getC_Currency_ID ()
211     {
212         return m_C_Currency_ID;
213     } // getC_Currency_ID
214

215     /**
216      * Set Amount (DR)
217      * @param sourceAmt source amt
218      */

219     public void setAmount (BigDecimal sourceAmt)
220     {
221         m_AmtSourceDr = sourceAmt == null ? Env.ZERO : sourceAmt;
222         m_AmtSourceCr = Env.ZERO;
223     } // setAmounts
224

225     /**
226      * Set Amounts
227      * @param amtSourceDr source amount dr
228      * @param amtSourceCr source amount cr
229      */

230     public void setAmount (BigDecimal amtSourceDr, BigDecimal amtSourceCr)
231     {
232         m_AmtSourceDr = amtSourceDr == null ? Env.ZERO : amtSourceDr;
233         m_AmtSourceCr = amtSourceCr == null ? Env.ZERO : amtSourceCr;
234     } // setAmounts
235

236     /**
237      * Set Converted Amounts
238      * @param C_AcctSchema_ID acct schema
239      * @param amtAcctDr acct amount dr
240      * @param amtAcctCr acct amount cr
241      */

242     public void setConvertedAmt (int C_AcctSchema_ID, BigDecimal amtAcctDr, BigDecimal amtAcctCr)
243     {
244         m_C_AcctSchema_ID = C_AcctSchema_ID;
245         m_AmtAcctDr = amtAcctDr;
246         m_AmtAcctCr = amtAcctCr;
247     } // setConvertedAmt
248

249     /**
250      * Line Net Amount or Dr-Cr
251      * @return balance
252      */

253     public BigDecimal getAmount()
254     {
255         return m_AmtSourceDr.subtract(m_AmtSourceCr);
256     } // getAmount
257

258     /**
259      * Get (Journal) Line Source Dr Amount
260      * @return DR source amount
261      */

262     public BigDecimal getAmtSourceDr()
263     {
264         return m_AmtSourceDr;
265     } // getAmtSourceDr
266

267     /**
268      * Get (Journal) Line Source Cr Amount
269      * @return CR source amount
270      */

271     public BigDecimal getAmtSourceCr()
272     {
273         return m_AmtSourceCr;
274     } // getAmtSourceCr
275

276     /**
277      * Line Journal Accounted Dr Amount
278      * @return DR accounted amount
279      */

280     public BigDecimal getAmtAcctDr()
281     {
282         return m_AmtAcctDr;
283     } // getAmtAcctDr
284

285     /**
286      * Line Journal Accounted Cr Amount
287      * @return CR accounted amount
288      */

289     public BigDecimal getAmtAcctCr()
290     {
291         return m_AmtAcctCr;
292     } // getAmtAccrCr
293

294     /**
295      * Charge Amount
296      * @param chargeAmt charge amt
297      */

298     public void setChargeAmt (BigDecimal chargeAmt)
299     {
300         m_ChargeAmt = chargeAmt == null ? Env.ZERO : chargeAmt;
301     } // setChargeAmt
302

303     /**
304      * Charge Amount
305      * @return charge amount
306      */

307     public BigDecimal getChargeAmt()
308     {
309         return m_ChargeAmt;
310     } // getChargeAmt
311

312     /*************************************************************************/
313
314     /**
315      * Set Accounting Date
316      * @param dateAcct acct date
317      */

318     public void setDateAcct (Timestamp dateAcct)
319     {
320         m_DateAcct = dateAcct;
321     } // setDateAcct
322

323     /**
324      * Get Accounting Date
325      * @return accounting date
326      */

327     public Timestamp getDateAcct ()
328     {
329         return m_DateAcct;
330     } // getDateAcct
331

332     /**
333      * Set Document Date
334      * @param dateDoc doc date
335      */

336     public void setDateDoc (Timestamp dateDoc)
337     {
338         m_DateDoc = dateDoc;
339     } // setDateDoc
340

341     /**
342      * Get Document Date
343      * @return document date
344      */

345     public Timestamp getDateDoc ()
346     {
347         return m_DateDoc;
348     } // getDateDoc
349

350     /*************************************************************************/
351
352     /**
353      * Set Journal Account
354      * @param acct account
355      */

356     public void setAccount (Account acct)
357     {
358         m_account = acct;
359     } // setAccount
360

361     /**
362      * Get Journal Account
363      * @return account
364      */

365     public Account getAccount()
366     {
367         return m_account;
368     } // getAccount
369

370     /**
371      * Get Charge Account
372      * @param as account schema
373      * @param amount amount for expense(+)/revenue(-)
374      * @return Charge Account or null
375      */

376     public Account getChargeAccount (AcctSchema as, BigDecimal amount)
377     {
378         if (m_C_Charge_ID == 0)
379             return null;
380
381         int acct_index = 1; // Expense (positive amt)
382
if (amount != null && amount.signum() < 0)
383             acct_index = 2; // Revenue (negative amt)
384
String JavaDoc sql = "SELECT CH_Expense_Acct, CH_Revenue_Acct FROM C_Charge_Acct WHERE C_Charge_ID=? AND C_AcctSchema_ID=?";
385         int Account_ID = 0;
386         try
387         {
388             PreparedStatement pstmt = DB.prepareStatement(sql);
389             pstmt.setInt (1, m_C_Charge_ID);
390             pstmt.setInt (2, as.getC_AcctSchema_ID());
391             ResultSet rs = pstmt.executeQuery();
392             if (rs.next())
393                 Account_ID = rs.getInt(acct_index);
394             rs.close();
395             pstmt.close();
396         }
397         catch (SQLException e)
398         {
399             log.error ("getChargeAccount", e);
400             return null;
401         }
402         // No account
403
if (Account_ID == 0)
404         {
405             log.error ("getChargeAccount - NO account for C_Charge_ID=" + m_C_Charge_ID);
406             return null;
407         }
408
409         // Return Account
410
Account acct = Account.getAccount (Account_ID);
411         return acct;
412     } // getChargeAccount
413

414     /*************************************************************************/
415
416     /**
417      * Get (Journal) AcctSchema
418      * @return C_AcctSchema_ID
419      */

420     public int getC_AcctSchema_ID()
421     {
422         return m_C_AcctSchema_ID;
423     } // getC_AcctSchema_ID
424

425     /**
426      * Product
427      * @return M_Product_ID
428      */

429     public int getM_Product_ID()
430     {
431         return m_M_Product_ID;
432     } // getM_Product_ID
433

434     /**
435      * Location From
436      * @return C_LocFrom_ID
437      */

438     public int getC_LocFrom_ID()
439     {
440         return m_C_LocFrom_ID;
441     } // getC_LocFrom_ID
442

443     /**
444      * Location To
445      * @return C_LocTo_ID
446      */

447     public int getC_LocTo_ID()
448     {
449         return m_C_LocTo_ID;
450     } // getC_LocTo_ID
451

452     /**
453      * Is Product
454      * @return true if product, false if service
455      */

456     public boolean isProduct()
457     {
458         return p_productInfo.isProduct();
459     } // isProduct
460

461     /**
462      * Is BOM Product
463      * @return true if product, false if service
464      */

465     public boolean isBOM()
466     {
467         return p_productInfo.isBOM();
468     } // isProduct
469

470     /**
471      * Is Service
472      * @return true if service, false if product
473      */

474     public boolean isService()
475     {
476         return !p_productInfo.isProduct();
477     } // isService
478

479     /**
480      * Get Product Category (Value)
481      * @return M_Product_Category_ID
482      */

483     public String JavaDoc getProductCategory()
484     {
485         return p_productInfo.getProductCategory();
486     } // getProductCategpry
487

488     /**
489      * Has Revenue Recognition
490      * @return true if product has Revenue Recognition rules
491      */

492     public boolean isRevenueRecognition()
493     {
494         return p_productInfo.isRevenueRecognition();
495     } // isRevenueRecognition
496

497     /**
498      * Get Revenue Recognition
499      * @return C_RevenueRecognition_ID
500      */

501     public int getC_RevenueRecognition_ID()
502     {
503         return p_productInfo.getC_RevenueRecognition_ID();
504     } // getC_RevenueRecognition_ID
505

506     /**
507      * Quantity UOM
508      * @return Transaction M_UOM_ID
509      */

510     public int getC_UOM_ID()
511     {
512         return m_C_UOM_ID;
513     } // getC_UOM
514

515     /**
516      * Quantity
517      * @param qty transaction Qty
518      */

519     public void setQty (BigDecimal qty)
520     {
521         m_qty = qty == null ? Env.ZERO : qty;
522     } // getQty
523

524     /**
525      * Quantity
526      * @return transaction Qty
527      */

528     public BigDecimal getQty()
529     {
530         return m_qty;
531     } // getQty
532

533     /**
534      * Description
535      * @return doc line description
536      */

537     public String JavaDoc getDescription()
538     {
539         return m_description;
540     }
541
542     /**
543      * Line Tax
544      * @return C_Tax_ID
545      */

546     public int getC_Tax_ID()
547     {
548         return m_C_Tax_ID;
549     }
550
551     /**
552      * Get Line Number
553      * @return line no
554      */

555     public int getLine()
556     {
557         return m_Line;
558     } // getLine
559

560     /**
561      * Get AD_Org_ID
562      * @return AD_Org_ID
563      */

564     public int getAD_Org_ID()
565     {
566         return m_AD_Org_ID;
567     } // getAD_Org_ID
568

569     /**
570      * Set AD_Org_ID.
571      * For GL Journal overwrite
572      * @param AD_Org_ID org
573      */

574     protected void setAD_Org_ID(int AD_Org_ID)
575     {
576         m_AD_Org_ID = AD_Org_ID;
577     } // setAD_Org_ID
578

579     /**
580      * Get BPartner
581      * @return C_BPartner_ID
582      */

583     public int getC_BPartner_ID()
584     {
585         return m_C_BPartner_ID;
586     } // getC_BPartner_ID
587

588     /**
589      * Get TrxOrg
590      * @return AD_OrgTrx_ID
591      */

592     public int getAD_OrgTrx_ID()
593     {
594         return m_AD_OrgTrx_ID;
595     } // getAD_OrgTrx_ID
596

597     /**
598      * Get SalesRegion.
599      * - get Sales Region from BPartner
600      * @return C_SalesRegion_ID
601      */

602     public int getC_SalesRegion_ID()
603     {
604         return m_C_SalesRegion_ID;
605     } // getC_SalesRegion_ID
606

607     /**
608      * Get Project
609      * @return C_Project_ID
610      */

611     public int getC_Project_ID()
612     {
613         return m_C_Project_ID;
614     } // getC_Project_ID
615

616     /**
617      * Get Campaign
618      * @return C_Campaign_ID
619      */

620     public int getC_Campaign_ID()
621     {
622         return m_C_Campaign_ID;
623     } // getC_Campaign_ID
624

625     /**
626      * Get Activity
627      * @return C_Activity_ID
628      */

629     public int getC_Activity_ID()
630     {
631         return m_C_Activity_ID;
632     } // getC_Activity_ID
633

634     /**
635      * Get User 1
636      * @return user defined 1
637      */

638     public int getUser1_ID()
639     {
640         return m_User1_ID;
641     } // getUser1_ID
642

643     /**
644      * Get User 2
645      * @return user defined 2
646      */

647     public int getUser2_ID()
648     {
649         return m_User2_ID;
650     } // getUser2_ID
651

652     /**
653      * Line ID
654      * @return TrxLine_ID
655      */

656     public int getTrxLine_ID()
657     {
658         return m_TrxLine_ID;
659     } // getTrxLine_ID
660

661     /**
662      * Get Charge
663      * @return C_Charge_ID
664      */

665     protected int getC_Charge_ID()
666     {
667         return m_C_Charge_ID;
668     } // getC_Charge_ID
669

670     /**
671      * Set Charge
672      * @patam C_Charge_ID charge
673      */

674     protected void setC_Charge_ID(int C_Charge_ID)
675     {
676         m_C_Charge_ID = C_Charge_ID;
677     } // setC_Charge_ID
678

679     /**
680      * String representation
681      * @return String
682      */

683     public String JavaDoc toString()
684     {
685         StringBuffer JavaDoc sb = new StringBuffer JavaDoc("DocLine=[");
686         sb.append(m_TrxLine_ID);
687         sb.append(",").append(m_description);
688         sb.append(",Qty=").append(m_qty);
689         sb.append(",Amt=").append(getAmount());
690         sb.append("]");
691         return sb.toString();
692     } // toString
693

694 } // DocumentLine
695
Popular Tags