KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > domain > Opportunity


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

10
11 /**
12  * This class represents an Opportunity within SellWin, these
13  * act as containers for various other entities such as Activity,
14  * Order, Contact, etc. Opportunities are mapped/stored within
15  * the database table 'opportunity'.
16  */

17 public class Opportunity implements Serializable {
18     private long pk;
19     private String JavaDoc name;
20     private int dollarValue;
21     private String JavaDoc probability;
22     private String JavaDoc stage;
23     private String JavaDoc leadSource;
24     private String JavaDoc leadType;
25     private String JavaDoc desc;
26     private String JavaDoc groupName;
27     private long primeSalesPersonPK;
28     private SalesPerson primeSalesPerson;
29     private long customerPK;
30     private Customer cust;
31     private Date modifiedDate;
32     private Date closeDate;
33     private String JavaDoc modifiedBy;
34     private long leadPK;
35     private Lead lead;
36     private ArrayList quotes = new ArrayList();
37     private ArrayList orders = new ArrayList();
38     private ArrayList contacts = new ArrayList();
39     private ArrayList activities = new ArrayList();
40     private ArrayList forecasts = new ArrayList();
41     private boolean modified=false;
42     private boolean updatedLocally=false;
43     private boolean addedLocally=false;
44
45     public final static String JavaDoc PROB[] = {
46         "0%", "10%", "20%", "30%", "40%", "50%", "60%", "70%", "80%", "90%", "100%" };
47
48     public final static String JavaDoc STAGE_IDENTIFIED = "Identified";
49     public final static String JavaDoc STAGE_CONTACTED = "Contacted";
50     public final static String JavaDoc STAGE_BIDDING = "Bidding";
51     public final static String JavaDoc STAGE_CHANCE = "Chance of Winning";
52     public final static String JavaDoc STAGE_WINNING = "Winning";
53     public final static String JavaDoc STAGE_AWARDED = "Awarded";
54     public final static String JavaDoc STAGE_CONTRACT = "Contract";
55     public final static String JavaDoc STAGE_BILLED = "Billed";
56
57     public final static String JavaDoc[] ALL_STAGES = {
58     STAGE_IDENTIFIED,
59     STAGE_CONTACTED,
60     STAGE_BIDDING,
61     STAGE_CHANCE,
62     STAGE_WINNING,
63     STAGE_AWARDED,
64     STAGE_CONTRACT,
65     STAGE_BILLED
66     };
67
68     public final static String JavaDoc LEAD_TRADE_SHOW = "Trade Show";
69     public final static String JavaDoc LEAD_EMAIL = "E-Mail";
70     public final static String JavaDoc LEAD_DIRECT = "Direct";
71     public final static String JavaDoc LEAD_SURVEY = "Survey";
72     public final static String JavaDoc LEAD_TELE = "Telesales";
73     public final static String JavaDoc LEAD_WEB = "Web";
74
75     public final static String JavaDoc[] ALL_LEADS = {
76     LEAD_TRADE_SHOW,
77     LEAD_EMAIL,
78     LEAD_DIRECT,
79     LEAD_SURVEY,
80     LEAD_TELE,
81     LEAD_WEB
82     };
83
84     public final static String JavaDoc TYPE_EXISTING = "Existing Business";
85     public final static String JavaDoc TYPE_NEW = "New Business";
86     
87     public final static String JavaDoc[] ALL_LEAD_TYPES = {
88         TYPE_EXISTING,
89         TYPE_NEW };
90
91     public Opportunity() {
92         this(null, null);
93     }
94
95     public Opportunity(String JavaDoc n, String JavaDoc creator) {
96         clear();
97         Date d = new java.util.Date JavaDoc();
98         pk = d.getTime();
99         setName(n);
100
101         leadType = TYPE_NEW;
102         leadSource=LEAD_TRADE_SHOW;
103         desc=" ";
104         stage=STAGE_IDENTIFIED;
105         modifiedDate = new java.util.Date JavaDoc();
106         closeDate = new java.util.Date JavaDoc();
107         modifiedBy = creator;
108     }
109
110     public final void clear() {
111         name = "";
112         cust = new Customer();
113         cust.setName(Customer.UNASSIGNED);
114         dollarValue = 0;
115         probability = PROB[0];
116         stage = STAGE_IDENTIFIED;
117         leadSource = LEAD_DIRECT;
118         leadType = TYPE_NEW;
119         modifiedBy = "SYSTEM";
120     }
121
122     public final void setLeadPK(long k) { leadPK = k; }
123     public final long getLeadPK() { return leadPK; }
124
125     public final Lead getLead() { return lead; }
126     public final void setLead(Lead lead) { this.lead = lead; }
127
128     public final String JavaDoc getGroupName() { return groupName; }
129     public final void setGroupName(String JavaDoc g) { groupName = g; }
130
131     public final ArrayList getOrders() { return orders; }
132     public final ArrayList getQuotes() { return quotes; }
133
134     public final void addOrder(Order o) { orders.add(o); setModified(); }
135
136     public final void addQuote(Quote f) {
137         quotes.add(f);
138         setModified();
139     }
140
141     public final ArrayList getForecasts() { return forecasts; }
142
143     public final void addForecast(Forecast f) {
144         forecasts.add(f);
145         setModified();
146     }
147
148     public final ArrayList getActivities() { return activities; }
149
150     public final void addActivity(Activity a) {
151         activities.add(a);
152         setModified();
153     }
154
155     public final ArrayList getContacts() { return contacts; }
156
157     public final void addContact(Contact c) {
158         contacts.add(c);
159         setModified();
160     }
161
162     public final long getPK() { return pk; }
163
164     public final void setPK(long i) { pk = i; }
165         
166     public final void setName(String JavaDoc name) { this.name = name; }
167
168     public final String JavaDoc getName() { return name; }
169
170     public final void setDollarValue(int d) { dollarValue = d; }
171
172     public final int getDollarValue() { return dollarValue; }
173
174     public final void setProbability(String JavaDoc i) { probability = i; }
175     
176     public final String JavaDoc getProbability() { return probability; }
177     
178     public final void setStage(String JavaDoc s) { stage = s; }
179     
180     public final String JavaDoc getStage() { return stage; }
181
182     public final void setDesc(String JavaDoc s) { desc = s; }
183     
184     public final String JavaDoc getDesc() { return desc; }
185
186     public final void setPrimeSalesPersonPK(long p) { primeSalesPersonPK = p; }
187     public final long getPrimeSalesPersonPK() { return primeSalesPersonPK; }
188
189     public final void setPrimeSalesPerson(SalesPerson s) { primeSalesPerson = s; }
190
191     public final SalesPerson getPrimeSalesPerson() { return primeSalesPerson; }
192
193
194     public final long getCustomerPK() { return customerPK; }
195     public final void setCustomerPK(long k) { customerPK = k; }
196
197     public final Customer getCustomer() { return cust; }
198
199     public final void setCustomer(Customer c) {
200         cust = c;
201         customerPK = c.getPK();
202     }
203
204     public final void setCloseDate(Date t) { closeDate = t; }
205     public final Date getCloseDate() { return closeDate; }
206
207     public final void setModifiedDate(Date t) { modifiedDate = t; }
208     public final Date getModifiedDate() { return modifiedDate; }
209
210     public final void setModifiedBy(String JavaDoc d) { modifiedBy = d; }
211     public final String JavaDoc getModifiedBy() { return modifiedBy; }
212
213     public final Contact findContact(String JavaDoc formattedName) {
214         Contact c = null;
215         for (int i = 0;i<contacts.size();i++) {
216             c = (Contact)contacts.get(i);
217             if (c.getAddress().getFormattedName().equals(formattedName))
218                 return c;
219         }
220
221         return null; //not found
222
}
223
224     public final void setLeadSource(String JavaDoc l) { leadSource = l; }
225     public final String JavaDoc getLeadSource() { return leadSource; }
226
227     public final void setLeadType(String JavaDoc l) { leadType = l; }
228     public final String JavaDoc getLeadType() { return leadType; }
229
230     public final void setModified() { modified=true; }
231     public final boolean isModified() { return modified; }
232
233     public final void setUpdatedLocally(boolean b) { updatedLocally=b; }
234     public final void setAddedLocally(boolean b) { addedLocally=b; }
235     public final boolean getUpdatedLocally() { return updatedLocally; }
236     public final boolean getAddedLocally() { return addedLocally; }
237
238     public final void print() {
239         System.out.print( "Opportunity: " + pk);
240         System.out.println( " name="+name);
241         System.out.println( "leadPK="+lead.getPK());
242         System.out.println( "Group="+groupName);
243         System.out.println( "dollarValue="+ dollarValue);
244         System.out.println( "probability="+ probability);
245         System.out.println( "stage="+ stage);
246         System.out.println( "lead source="+ leadSource);
247         System.out.println( "lead type="+ leadType);
248         System.out.println( " desc="+desc);
249         System.out.println( "prime sales person="+ primeSalesPerson.getAddress().getFormattedName());
250         System.out.println( "customer=" + cust.getName());
251         System.out.println( "modifiedDate="+ modifiedDate);
252         System.out.println( "closeDate="+ closeDate);
253         System.out.println( "modifiedBy="+ modifiedBy);
254         System.out.println( "modified="+ modified);
255         ArrayList contacts = getContacts();
256         Contact contact = null;
257         for (int i=0;i<contacts.size();i++) {
258             System.out.println("Contact #"+i);
259             contact = (Contact)contacts.get(i);
260             contact.print();
261         }
262     }
263
264     public final void deleteQuote(Quote q) {
265         ArrayList quotes = getQuotes();
266         Quote quote = null;
267         for (int i=0;i<quotes.size();i++) {
268             quote = (Quote)quotes.get(i);
269             if (quote.getPK() == q.getPK())
270                 quotes.remove(i);
271         }
272     }
273
274     //local remove of an activity from this opp
275
//not to be confused with remote delete
276
public final void deleteActivity(Activity a) {
277         ArrayList acts = getActivities();
278         Activity act = null;
279         for (int i=0;i<acts.size();i++) {
280             act = (Activity)acts.get(i);
281             if (act.getPK() == a.getPK())
282                 acts.remove(i);
283         }
284     }
285
286     public final Opportunity copy() {
287         String JavaDoc copyName = new String JavaDoc(name);
288
289         Opportunity copy = new Opportunity(copyName, getModifiedBy());
290
291         copy.setGroupName(new String JavaDoc(groupName));
292         copy.setModifiedBy(new String JavaDoc(modifiedBy));
293         Contact contact, contactCopy;
294         ArrayList contacts = getContacts();
295         for (int i=0;i<contacts.size();i++) {
296             contact = (Contact)contacts.get(i);
297             contactCopy = contact.copy();
298             copy.addContact(contactCopy);
299         }
300
301         Activity activity, activityCopy;
302         ArrayList activities = getActivities();
303         for (int j=0;j<activities.size();j++) {
304             activity = (Activity)activities.get(j);
305             activityCopy = activity.copy();
306             copy.addActivity(activityCopy);
307         }
308
309         Forecast forecast, forecastCopy;
310         ArrayList forecasts = getForecasts();
311         for (int k=0;k<forecasts.size();k++) {
312             forecast = (Forecast)forecasts.get(k);
313             forecastCopy = forecast.copy();
314             copy.addForecast(forecastCopy);
315         }
316
317         Quote quote, quoteCopy;
318         ArrayList quotes = getQuotes();
319         for (int k=0;k<quotes.size();k++) {
320             quote = (Quote)quotes.get(k);
321             quoteCopy = quote.copy();
322             copy.addQuote(quoteCopy);
323         }
324         Order order, orderCopy;
325         ArrayList orders = getOrders();
326         for (int k=0;k<orders.size();k++) {
327             order = (Order)orders.get(k);
328             orderCopy = order.copy();
329             copy.addOrder(orderCopy);
330         }
331
332         if (primeSalesPerson != null)
333             copy.setPrimeSalesPerson(primeSalesPerson.copy());
334         if (cust != null)
335             copy.setCustomer(cust.copy());
336
337         copy.pk = pk;
338         if (lead != null)
339             copy.lead = lead.copy();
340         copy.dollarValue = dollarValue;
341         copy.probability = new String JavaDoc(probability);
342         if (stage != null)
343             copy.stage = new String JavaDoc(stage);
344         if (desc != null)
345             copy.desc = new String JavaDoc(desc);
346         if (leadSource != null)
347             copy.leadSource = new String JavaDoc(leadSource);
348         if (leadType != null)
349             copy.leadType = new String JavaDoc(leadType);
350         if (modifiedDate != null)
351             copy.modifiedDate = new Date(modifiedDate.getTime());
352         if (closeDate != null)
353             copy.closeDate = new Date(closeDate.getTime());
354
355         return copy;
356     }
357     
358     public final void printActivities() {
359         Activity a;
360         for (int i=0;i<getActivities().size();i++) {
361             a = (Activity)getActivities().get(i);
362             a.print();
363         }
364     }
365
366 }
367
Popular Tags