-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReport.java
More file actions
269 lines (234 loc) · 7.49 KB
/
Report.java
File metadata and controls
269 lines (234 loc) · 7.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
package model;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;
/**
* Represents a report in the POS system.
* Contains aggregated data for reporting purposes including sales, stock, and
* profit information.
*/
public class Report {
// Instance variables
private String reportId;
private String branchCode;
private Date reportDate;
private String reportType;
private List<Sale> salesData;
private List<Product> stockData;
private List<Double> profitData;
// Constants
private static final String DEFAULT_REPORT_TYPE = "GENERAL";
/**
* Default constructor
*/
public Report() {
this.reportDate = new Date();
this.reportType = DEFAULT_REPORT_TYPE;
this.salesData = new ArrayList<>();
this.stockData = new ArrayList<>();
this.profitData = new ArrayList<>();
}
/**
* Constructor with basic report information
*
* @param reportId unique identifier for the report
* @param branchCode branch code for the report
* @param reportType type of report
*/
public Report(String reportId, String branchCode, String reportType) {
this.reportId = reportId;
this.branchCode = branchCode;
this.reportType = reportType != null ? reportType : DEFAULT_REPORT_TYPE;
this.reportDate = new Date();
this.salesData = new ArrayList<>();
this.stockData = new ArrayList<>();
this.profitData = new ArrayList<>();
}
/**
* Constructor with all report details
*
* @param reportId unique identifier for the report
* @param branchCode branch code for the report
* @param reportDate date of the report
* @param reportType type of report
* @param salesData sales data for the report
* @param stockData stock data for the report
* @param profitData profit data for the report
*/
public Report(String reportId, String branchCode, Date reportDate, String reportType,
List<Sale> salesData, List<Product> stockData, List<Double> profitData) {
this.reportId = reportId;
this.branchCode = branchCode;
this.reportDate = reportDate != null ? new Date(reportDate.getTime()) : new Date();
this.reportType = reportType != null ? reportType : DEFAULT_REPORT_TYPE;
this.salesData = salesData != null ? new ArrayList<>(salesData) : new ArrayList<>();
this.stockData = stockData != null ? new ArrayList<>(stockData) : new ArrayList<>();
this.profitData = profitData != null ? new ArrayList<>(profitData) : new ArrayList<>();
}
// Business logic methods
/**
* Get the total sales amount from sales data
*
* @return total sales amount
*/
public double getTotalSalesAmount() {
return salesData.stream()
.mapToDouble(Sale::getTotalAmount)
.sum();
}
/**
* Get the total number of sales transactions
*
* @return number of sales
*/
public int getTotalSalesCount() {
return salesData.size();
}
/**
* Get the total stock value from stock data
*
* @return total stock value
*/
public double getTotalStockValue() {
return stockData.stream()
.mapToDouble(Product::getStockValue)
.sum();
}
/**
* Get the total number of products in stock
*
* @return number of products
*/
public int getTotalProductCount() {
return stockData.size();
}
/**
* Get the total profit from profit data
*
* @return total profit
*/
public double getTotalProfit() {
return profitData.stream()
.mapToDouble(Double::doubleValue)
.sum();
}
/**
* Get the average profit per transaction
*
* @return average profit, or 0 if no sales
*/
public double getAverageProfit() {
if (salesData.isEmpty()) {
return 0.0;
}
return getTotalProfit() / salesData.size();
}
/**
* Check if the report has any data
*
* @return true if report has any data, false otherwise
*/
public boolean hasData() {
return !salesData.isEmpty() || !stockData.isEmpty() || !profitData.isEmpty();
}
/**
* Get the report summary as a formatted string
*
* @return formatted summary
*/
public String getSummary() {
return String.format("Report %s - Branch: %s, Sales: %d, Stock Value: $%.2f, Profit: $%.2f",
reportId, branchCode, getTotalSalesCount(), getTotalStockValue(), getTotalProfit());
}
/**
* Add a sale to the report
*
* @param sale sale to add
*/
public void addSale(Sale sale) {
if (sale != null) {
salesData.add(sale);
}
}
/**
* Add a product to the stock data
*
* @param product product to add
*/
public void addProduct(Product product) {
if (product != null) {
stockData.add(product);
}
}
/**
* Add profit data to the report
*
* @param profit profit amount to add
*/
public void addProfit(double profit) {
profitData.add(profit);
}
// Getters and Setters
public String getReportId() {
return reportId;
}
public void setReportId(String reportId) {
this.reportId = reportId;
}
public String getBranchCode() {
return branchCode;
}
public void setBranchCode(String branchCode) {
this.branchCode = branchCode;
}
public Date getReportDate() {
return reportDate != null ? new Date(reportDate.getTime()) : null;
}
public void setReportDate(Date reportDate) {
this.reportDate = reportDate != null ? new Date(reportDate.getTime()) : new Date();
}
public String getReportType() {
return reportType;
}
public void setReportType(String reportType) {
this.reportType = reportType != null ? reportType : DEFAULT_REPORT_TYPE;
}
public List<Sale> getSalesData() {
return new ArrayList<>(salesData); // Return a copy to prevent external modification
}
public void setSalesData(List<Sale> salesData) {
this.salesData = salesData != null ? new ArrayList<>(salesData) : new ArrayList<>();
}
public List<Product> getStockData() {
return new ArrayList<>(stockData); // Return a copy to prevent external modification
}
public void setStockData(List<Product> stockData) {
this.stockData = stockData != null ? new ArrayList<>(stockData) : new ArrayList<>();
}
public List<Double> getProfitData() {
return new ArrayList<>(profitData); // Return a copy to prevent external modification
}
public void setProfitData(List<Double> profitData) {
this.profitData = profitData != null ? new ArrayList<>(profitData) : new ArrayList<>();
}
// Object methods
@Override
public String toString() {
return String.format("Report{id='%s', branch='%s', type='%s', date=%s}",
reportId, branchCode, reportType, reportDate);
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null || getClass() != obj.getClass())
return false;
Report report = (Report) obj;
return Objects.equals(reportId, report.reportId);
}
@Override
public int hashCode() {
return Objects.hash(reportId);
}
}