KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > sellwin > domain > Forecast


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 represents a sales forecast which is associated
15  * to some opportunity. This class is used to hold database
16  * column values found in the 'forecast' database table.
17  */

18 public class Forecast implements Serializable {
19     private long pk;
20     private long oppPK;
21     private String JavaDoc name;
22     private Date closeDate;
23     private Boolean JavaDoc submitted;
24     private Date submittedDate;
25     private String JavaDoc submittedBy;
26     private Integer JavaDoc revenue;
27     private Integer JavaDoc profit;
28     private Double JavaDoc margin;
29     private String JavaDoc scenario;
30     private Integer JavaDoc amountJan;
31     private Integer JavaDoc amountFeb;
32     private Integer JavaDoc amountMar;
33     private Integer JavaDoc Q1;
34     private Integer JavaDoc amountApr;
35     private Integer JavaDoc amountMay;
36     private Integer JavaDoc amountJun;
37     private Integer JavaDoc Q2;
38     private Integer JavaDoc amountJul;
39     private Integer JavaDoc amountAug;
40     private Integer JavaDoc amountSep;
41     private Integer JavaDoc Q3;
42     private Integer JavaDoc amountOct;
43     private Integer JavaDoc amountNov;
44     private Integer JavaDoc amountDec;
45     private Integer JavaDoc Q4;
46     private String JavaDoc modifiedBy;
47     private Date modifiedDate;
48     private boolean addedLocally=false;
49     private boolean updatedLocally=false;
50
51     public static final String JavaDoc SCEN_BEST_CASE = "Best Case";
52     public static final String JavaDoc SCEN_MOST_LIKELY_CASE = "Most Likely";
53     public static final String JavaDoc SCEN_WORST_CASE = "Worst Case";
54
55     public static final double BEST_CASE_FACTOR = 1.0;
56     public static final double MOST_LIKELY_FACTOR = 0.75;
57     public static final double WORST_CASE_FACTOR = 0.50;
58
59     public static final String JavaDoc[] SCENARIOS = {
60         SCEN_BEST_CASE, SCEN_MOST_LIKELY_CASE, SCEN_WORST_CASE
61     };
62
63     public final static int PERIOD_ALL = 0;
64     public final static int PERIOD_Q1 = 1;
65     public final static int PERIOD_Q2 = 2;
66     public final static int PERIOD_Q3 = 3;
67     public final static int PERIOD_Q4 = 4;
68
69     public final static String JavaDoc[] PERIODS = new String JavaDoc[5];
70     
71     static {
72         PERIODS[PERIOD_ALL] = "All Quarters";
73         PERIODS[PERIOD_Q1] = "Q1 - Current Year (Jan-Mar)";
74         PERIODS[PERIOD_Q2] = "Q2 - Current Year (Apr-Jun)";
75         PERIODS[PERIOD_Q3] = "Q3 - Current Year (Jul-Sep)";
76         PERIODS[PERIOD_Q4] = "Q4 - Current Year (Oct-Dec)";
77     }
78
79     
80     public Forecast() {
81         submitted=new Boolean JavaDoc(false);
82         closeDate = new Date();
83         submittedDate = new Date();
84         submittedBy = "SYSTEM";
85         revenue = new Integer JavaDoc(0);
86         profit = new Integer JavaDoc(0);
87         margin = new Double JavaDoc(0.00);
88         scenario = SCEN_BEST_CASE;
89         amountJan = new Integer JavaDoc(0);
90         amountFeb = new Integer JavaDoc(0);
91         amountMar = new Integer JavaDoc(0);
92         amountApr = new Integer JavaDoc(0);
93         amountMay = new Integer JavaDoc(0);
94         amountJun = new Integer JavaDoc(0);
95         amountJul = new Integer JavaDoc(0);
96         amountAug = new Integer JavaDoc(0);
97         amountSep = new Integer JavaDoc(0);
98         amountOct = new Integer JavaDoc(0);
99         amountNov = new Integer JavaDoc(0);
100         amountDec = new Integer JavaDoc(0);
101         Q1 = new Integer JavaDoc(0);
102         Q2 = new Integer JavaDoc(0);
103         Q3 = new Integer JavaDoc(0);
104         Q4 = new Integer JavaDoc(0);
105         modifiedBy="SYSTEM";
106         modifiedDate = new Date();
107     }
108
109     public final void setPK(long pk) { this.pk = pk; }
110     public final long getPK() { return pk; }
111
112     public final void setOppKey(long pk) { this.oppPK = pk; }
113     public final long getOppKey() { return oppPK; }
114
115     public final void setName(String JavaDoc n) { name = n;}
116     public final String JavaDoc getName() { return name; }
117
118     public final void setCloseDate(Date t) { closeDate = t; }
119     public final Date getCloseDate() { return closeDate; }
120
121     public final void setSubmitted(Boolean JavaDoc t) { submitted = t; }
122     public final Boolean JavaDoc getSubmitted() { return submitted; }
123
124     public final void setSubmittedDate(Date t) { submittedDate = t; }
125     public final Date getSubmittedDate() { return submittedDate; }
126
127     public final void setSubmittedBy(String JavaDoc t) { submittedBy = t; }
128     public final String JavaDoc getSubmittedBy() { return submittedBy; }
129
130     public final void setRevenue(Integer JavaDoc d) { revenue=d; }
131     public final Integer JavaDoc getRevenue() { return revenue; }
132
133     public final void setProfit(Integer JavaDoc d) { profit = d; }
134     public final Integer JavaDoc getProfit() { return profit; }
135
136     public final void setMargin(Double JavaDoc d) {
137         margin = d;
138         calcProfit();
139     }
140     public final Double JavaDoc getMargin() { return margin; }
141
142     public final void setScenario(String JavaDoc s) { scenario = s; }
143     public final String JavaDoc getScenario() { return scenario; }
144
145     public final void setModifiedBy(String JavaDoc s) { modifiedBy = s; }
146     public final String JavaDoc getModifiedBy() { return modifiedBy; }
147
148     public final void setModifiedDate(Date s) { modifiedDate = s; }
149     public final Date getModifiedDate() { return modifiedDate; }
150
151
152     public final void setAmountJan(Integer JavaDoc i) {
153         amountJan = i;
154         calcQ1();
155     }
156     public final void setAmountFeb(Integer JavaDoc i) {
157         amountFeb = i;
158         calcQ1();
159     }
160     public final void setAmountMar(Integer JavaDoc i) {
161         amountMar = i;
162         calcQ1();
163     }
164     public final void setAmountApr(Integer JavaDoc i) {
165         amountApr = i;
166         calcQ2();
167     }
168     public final void setAmountMay(Integer JavaDoc i) {
169         amountMay = i;
170         calcQ2();
171     }
172     public final void setAmountJun(Integer JavaDoc i) {
173         amountJun = i;
174         calcQ2();
175     }
176     public final void setAmountJul(Integer JavaDoc i) {
177         amountJul = i;
178         calcQ3();
179     }
180     public final void setAmountAug(Integer JavaDoc i) {
181         amountAug = i;
182         calcQ3();
183     }
184     public final void setAmountSep(Integer JavaDoc i) {
185         amountSep = i;
186         calcQ3();
187     }
188     public final void setAmountOct(Integer JavaDoc i) {
189         amountOct = i;
190         calcQ4();
191     }
192     public final void setAmountNov(Integer JavaDoc i) {
193         amountNov = i;
194         calcQ4();
195     }
196     public final void setAmountDec(Integer JavaDoc i) {
197         amountDec = i;
198         calcQ4();
199     }
200
201     public final void setQ1(Integer JavaDoc i) { Q1 = i; }
202     public final void setQ2(Integer JavaDoc i) { Q2 = i; }
203     public final void setQ3(Integer JavaDoc i) { Q3 = i; }
204     public final void setQ4(Integer JavaDoc i) { Q4 = i; }
205
206     public final Integer JavaDoc getAmountJan() { return amountJan; }
207     public final Integer JavaDoc getAmountFeb() { return amountFeb; }
208     public final Integer JavaDoc getAmountMar() { return amountMar; }
209     public final Integer JavaDoc getAmountApr() { return amountApr; }
210     public final Integer JavaDoc getAmountMay() { return amountMay; }
211     public final Integer JavaDoc getAmountJun() { return amountJun; }
212     public final Integer JavaDoc getAmountJul() { return amountJul; }
213     public final Integer JavaDoc getAmountAug() { return amountAug; }
214     public final Integer JavaDoc getAmountSep() { return amountSep; }
215     public final Integer JavaDoc getAmountOct() { return amountOct; }
216     public final Integer JavaDoc getAmountNov() { return amountNov; }
217     public final Integer JavaDoc getAmountDec() { return amountDec; }
218
219     public final Integer JavaDoc getQ1() { return Q1; }
220     public final Integer JavaDoc getQ2() { return Q2; }
221     public final Integer JavaDoc getQ3() { return Q3; }
222     public final Integer JavaDoc getQ4() { return Q4; }
223
224     public final void setAddedLocally(boolean b) { addedLocally=b; }
225     public final void setUpdatedLocally(boolean b) { updatedLocally=b; }
226     public final boolean getAddedLocally() { return addedLocally; }
227     public final boolean getUpdatedLocally() { return updatedLocally; }
228
229
230     public final Forecast copy() {
231         Forecast copy = new Forecast();
232         if (name != null)
233             copy.name = new String JavaDoc(name);
234         if (closeDate != null)
235             copy.closeDate = new Date( closeDate.getTime());
236         copy.revenue= new Integer JavaDoc(revenue.intValue());
237         copy.submitted = new Boolean JavaDoc(submitted.booleanValue());
238         copy.profit = new Integer JavaDoc(profit.intValue());
239         copy.margin = new Double JavaDoc(margin.doubleValue());
240         copy.submittedDate = new Date(submittedDate.getTime());
241         copy.submittedBy = new String JavaDoc(submittedBy);
242         copy.modifiedDate = new Date(modifiedDate.getTime());
243         copy.modifiedBy = new String JavaDoc(modifiedBy);
244         if (scenario != null)
245             copy.scenario = new String JavaDoc( scenario);
246
247         copy.amountJan = new Integer JavaDoc(amountJan.intValue());
248         copy.amountFeb = new Integer JavaDoc(amountFeb.intValue());
249         copy.amountMar = new Integer JavaDoc(amountMar.intValue());
250         copy.amountApr = new Integer JavaDoc(amountApr.intValue());
251         copy.amountMay = new Integer JavaDoc(amountMay.intValue());
252         copy.amountJun = new Integer JavaDoc(amountJun.intValue());
253         copy.amountJul = new Integer JavaDoc(amountJul.intValue());
254         copy.amountAug = new Integer JavaDoc(amountAug.intValue());
255         copy.amountSep = new Integer JavaDoc(amountSep.intValue());
256         copy.amountOct = new Integer JavaDoc(amountOct.intValue());
257         copy.amountNov = new Integer JavaDoc(amountNov.intValue());
258         copy.amountDec = new Integer JavaDoc(amountDec.intValue());
259         copy.Q1 = new Integer JavaDoc(Q1.intValue());
260         copy.Q2 = new Integer JavaDoc(Q2.intValue());
261         copy.Q3 = new Integer JavaDoc(Q3.intValue());
262         copy.Q4 = new Integer JavaDoc(Q4.intValue());
263         
264         return copy;
265
266     }
267
268     public final void factorChange() {
269         calcQ1();
270         calcQ2();
271         calcQ3();
272         calcQ4();
273     }
274
275     public final void calcQ1() {
276         int val =
277             getAmountJan().intValue() +
278             getAmountFeb().intValue() +
279             getAmountMar().intValue();
280         Double JavaDoc temp = new Double JavaDoc(val * getFactor());
281         setQ1(new Integer JavaDoc(temp.intValue()));
282         calcAll();
283     }
284
285     public final void calcQ2() {
286         int val =
287             getAmountApr().intValue() +
288             getAmountMay().intValue() +
289             getAmountJun().intValue();
290         Double JavaDoc temp = new Double JavaDoc(val * getFactor());
291         setQ2(new Integer JavaDoc(temp.intValue()));
292         calcAll();
293     }
294     public final void calcQ3() {
295         int val =
296             getAmountJul().intValue() +
297             getAmountAug().intValue() +
298             getAmountSep().intValue();
299
300         Double JavaDoc temp = new Double JavaDoc(val * getFactor());
301         setQ3(new Integer JavaDoc(temp.intValue()));
302         calcAll();
303     }
304     public final void calcQ4() {
305         int val =
306             getAmountOct().intValue() +
307             getAmountNov().intValue() +
308             getAmountDec().intValue();
309         
310         Double JavaDoc temp = new Double JavaDoc(val * getFactor());
311         setQ4(new Integer JavaDoc(temp.intValue()));
312         calcAll();
313     }
314     public final void calcAll() {
315         int val =
316             getQ1().intValue() +
317             getQ2().intValue() +
318             getQ3().intValue() +
319             getQ4().intValue();
320     
321         setRevenue(new Integer JavaDoc(val));
322
323         calcProfit();
324     }
325
326     public final void calcProfit() {
327         int rev = getRevenue().intValue();
328         double marg = getMargin().doubleValue();
329         Double JavaDoc temp = new Double JavaDoc(rev * marg);
330
331         setProfit( new Integer JavaDoc(temp.intValue()));
332     }
333
334
335     public final double getFactor() {
336         if (scenario.equals(SCEN_BEST_CASE))
337             return BEST_CASE_FACTOR;
338         if (scenario.equals(SCEN_MOST_LIKELY_CASE))
339             return MOST_LIKELY_FACTOR;
340         if (scenario.equals(SCEN_WORST_CASE))
341             return WORST_CASE_FACTOR;
342
343         Exception JavaDoc e = new Exception JavaDoc();
344         e.printStackTrace();
345         System.exit(0);
346
347         return BEST_CASE_FACTOR;
348     }
349
350     public final void print() {
351         System.out.println("<<Forecast>>");
352         System.out.println("pk=["+getPK()+"]");
353         System.out.println("Name=["+getName()+"]");
354         System.out.println("Close Date="+getCloseDate());
355         System.out.println("Revenue="+getRevenue());
356         System.out.println("Profit="+getProfit());
357         System.out.println("Margin="+getMargin());
358         System.out.println("Scenario=["+getScenario()+"]");
359         System.out.println("Submitted="+getSubmitted());
360         System.out.println("Submit Date="+ getSubmittedDate());
361         System.out.println("SubmittedBy="+ getSubmittedBy());
362         System.out.println("Jan="+getAmountJan() + " Feb="+getAmountFeb());
363         System.out.println("Mar="+getAmountMar() + " Apr="+getAmountApr());
364         System.out.println("May="+getAmountMay() + " Jun="+getAmountJun());
365         System.out.println("Jul="+getAmountJul() + " Aug="+getAmountAug());
366         System.out.println("Sep="+getAmountSep() + " Oct="+getAmountOct());
367         System.out.println("Nov="+getAmountNov() + " Dec="+getAmountDec());
368         System.out.println("Q1="+getQ1()+" Q2="+getQ2()+" Q3="+getQ3() +" Q4="+getQ4());
369         System.out.println("ModifiedBy="+ getModifiedBy());
370         System.out.println("ModifiedDate="+ getModifiedDate());
371     }
372 }
373
Popular Tags