KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > knowgate > hipergate > InvoiceLine


1 /*
2   Copyright (C) 2003 Know Gate S.L. All rights reserved.
3                       C/Oņa, 107 1š2 28050 Madrid (Spain)
4
5   Redistribution and use in source and binary forms, with or without
6   modification, are permitted provided that the following conditions
7   are met:
8
9   1. Redistributions of source code must retain the above copyright
10      notice, this list of conditions and the following disclaimer.
11
12   2. The end-user documentation included with the redistribution,
13      if any, must include the following acknowledgment:
14      "This product includes software parts from hipergate
15      (http://www.hipergate.org/)."
16      Alternately, this acknowledgment may appear in the software itself,
17      if and wherever such third-party acknowledgments normally appear.
18
19   3. The name hipergate must not be used to endorse or promote products
20      derived from this software without prior written permission.
21      Products derived from this software may not be called hipergate,
22      nor may hipergate appear in their name, without prior written
23      permission.
24
25   This library is distributed in the hope that it will be useful,
26   but WITHOUT ANY WARRANTY; without even the implied warranty of
27   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28
29   You should have received a copy of hipergate License with this code;
30   if not, visit http://www.hipergate.org or mail to info@hipergate.org
31 */

32
33 package com.knowgate.hipergate;
34
35 import java.math.BigDecimal JavaDoc;
36
37 import java.sql.Types JavaDoc;
38 import java.sql.PreparedStatement JavaDoc;
39 import java.sql.SQLException JavaDoc;
40
41 import com.knowgate.jdc.JDCConnection;
42 import com.knowgate.dataobjs.DBPersist;
43 import com.knowgate.dataobjs.DB;
44 import com.knowgate.dataobjs.DBBind;
45
46 /**
47  * Invoice Line
48  * @author Sergio Montoro Ten
49  * @version 3.0
50  */

51 //----------------------------------------------------------------------------
52

53 public class InvoiceLine extends DBPersist {
54   public InvoiceLine() {
55     super(DB.k_invoice_lines, "InvoiceLine");
56   }
57
58   //--------------------------------------------------------------------------
59

60   /**
61    * <p>Store invoice line</p>
62    * This method updated k_invoices.dt_modified to current datetime as a side effect
63    * @param oConn JDCConnection
64    * @return boolean
65    * @throws SQLException
66    */

67   public boolean store (JDCConnection oConn) throws SQLException JavaDoc {
68     PreparedStatement JavaDoc oStmt = oConn.prepareStatement("UPDATE "+DB.k_invoices+" SET "+DB.dt_modified+"="+DBBind.Functions.GETDATE+" WHERE "+DB.gu_invoice+"=?");
69     oStmt.setObject(1, get(DB.gu_invoice), Types.CHAR);
70     oStmt.executeUpdate();
71     oStmt.close();
72     return super.store(oConn);
73   }
74
75   //--------------------------------------------------------------------------
76

77   /**
78    * <p>Compute line total from base price, number of units and taxes</p>
79    * If is_tax_included==1 Or is_tax_included is null Then pct_tax_rate is applied Else it is ignored
80    * @return BigDecimal pr_sale * nu_quantity * pct_tax_rate
81    */

82   public BigDecimal JavaDoc computeTotal () {
83     BigDecimal JavaDoc dTotal, dQuantity, dTax, dHundred = new BigDecimal JavaDoc(100), dOne = new BigDecimal JavaDoc(1);
84     boolean bTaxIncluded = false;
85
86     if (isNull(DB.pr_sale)) return null;
87
88     if (isNull(DB.nu_quantity))
89       dQuantity = new BigDecimal JavaDoc(1);
90     else
91       dQuantity = new BigDecimal JavaDoc(getFloat(DB.nu_quantity));
92
93     if (isNull(DB.pct_tax_rate))
94       dTotal = getDecimal(DB.pr_sale).multiply(dQuantity);
95     else {
96       dTotal = getDecimal(DB.pr_sale).multiply(dQuantity);
97       if (!isNull(DB.is_tax_included))
98         bTaxIncluded = (getShort(DB.is_tax_included)==(short)1);
99       if (!bTaxIncluded) {
100         if (getFloat(DB.pct_tax_rate)>1f)
101           dTax = new BigDecimal JavaDoc(getFloat(DB.pct_tax_rate)/100f);
102         else
103           dTax = new BigDecimal JavaDoc(getFloat(DB.pct_tax_rate));
104         dTotal = dTotal.add(dTotal.multiply(dTax));
105       }
106     }
107     replace(DB.pr_total, dTotal);
108     return dTotal;
109   } // computeTotal
110
}
111
Popular Tags