KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > domain > Quote


1 package sellwin.domain;
2
3 import java.util.*;
4 import java.io.*;
5 import java.text.*;
6 import javax.swing.text.*;
7
8 // SellWin http://sourceforge.net/projects/sellwincrm
9
//Contact support@open-app.com for commercial help with SellWin
10
//This software is provided "AS IS", without a warranty of any kind.
11

12
13 /**
14  * This class relates to a quote in Sellwin. A quote is
15  * owned by a particular Opportunity. A quote object relates
16  * to the quote table in the database;
17  */

18 public class Quote implements Serializable {
19     private long pk;
20     private long oppPK;
21     private String JavaDoc name;
22     private ArrayList lines = new ArrayList();
23     private Date modifiedDate;
24     private String JavaDoc modifiedBy;
25     private boolean modified;
26     private boolean updatedLocally=false;
27     private boolean addedLocally=false;
28
29     public Quote() {
30         modifiedDate = new Date();
31         modified = false;
32     }
33
34     public final void setPK(long pk) { this.pk = pk; }
35     public final void setOppPK(long pk) { this.oppPK = pk; }
36     public final long getOppPK() { return oppPK; }
37     public final void setName(String JavaDoc n) { name = n;}
38     public final void addLine(QuoteLine t) {
39         lines.add(t);
40     }
41     public final void setModified(boolean t) { modified = t; }
42     public final boolean getModified() { return modified; }
43     public final void setModifiedBy(String JavaDoc by) { modifiedBy = by; }
44     public final void setModifiedDate(Date d) { modifiedDate = d; }
45
46     public final void deleteLine(long linePK)
47         throws AngError {
48
49         ArrayList lines = getLines();
50         QuoteLine line=null;
51
52         for (int i=0;i<lines.size();i++) {
53             line = (QuoteLine)(lines.get(i));
54             if (line.getPK() == linePK) {
55                 lines.remove(i);
56                 return;
57             }
58         }
59         throw new AngError("deleteLine "+linePK+ " not found");
60     }
61
62     public final double calcSubTotal() {
63         ArrayList lines = getLines();
64         QuoteLine line=null;
65         double subTotal=0.00;
66
67         for (int i=0;i<lines.size();i++) {
68             line = (QuoteLine)(lines.get(i));
69             subTotal = subTotal +
70                     (line.getQuantity().intValue() *
71                     line.getProduct().getPrice().doubleValue());
72         }
73         
74         return subTotal;
75     }
76         
77
78     public final String JavaDoc getName() { return name; }
79     public final ArrayList getLines() { return lines; }
80     public final long getPK() { return pk; }
81     public final Date getModifiedDate() { return modifiedDate; }
82     public final String JavaDoc getModifiedBy() { return modifiedBy; }
83
84     public final void setUpdatedLocally(boolean b) { updatedLocally=b; }
85     public final void setAddedLocally(boolean b) { addedLocally=b; }
86     public final boolean getUpdatedLocally() { return updatedLocally; }
87     public final boolean getAddedLocally() { return addedLocally; }
88
89     public final Quote copy() {
90         Quote copy = new Quote();
91         copy.setPK(getPK());
92         if (name != null)
93             copy.name = new String JavaDoc(name);
94         if (modifiedDate != null)
95             copy.modifiedDate = new Date(modifiedDate.getTime());
96         if (modifiedBy != null)
97             copy.modifiedBy = new String JavaDoc(modifiedBy);
98         QuoteLine lineCopy;
99         QuoteLine line;
100         for (int i=0;i<lines.size();i++) {
101             line = (QuoteLine)lines.get(i);
102             lineCopy = line.copy();
103             copy.lines.add(lineCopy);
104         }
105         return copy;
106     }
107
108     public final void print() {
109         System.out.println("<<Quote>>");
110         System.out.println("pk=["+getPK()+"]");
111         System.out.println("opppk=["+getOppPK()+"]");
112         System.out.println("Name=["+getName()+"]");
113         System.out.println("Modified =["+getModified()+"]");
114         System.out.println("Modified By =["+getModifiedBy()+"]");
115         System.out.println("Modified Date =["+getModifiedDate()+"]");
116         QuoteLine line;
117         for (int i=0;i<lines.size();i++) {
118             line = (QuoteLine)lines.get(i);
119             line.print();
120         }
121     }
122 }
123
Popular Tags