-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBillingInfo.java
More file actions
263 lines (213 loc) · 10.4 KB
/
Copy pathBillingInfo.java
File metadata and controls
263 lines (213 loc) · 10.4 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
import java.util.Scanner;
import java.io.IOException;
import java.io.*;
import java.util.*;
import java.io.BufferedWriter;
import java.io.BufferedReader;
import java.io.FileWriter;
import java.io.FileReader;
public class BillingInfo
{
public String cus_id;
int billing_month;
int curr_reg_meter;
int curr_reg_peak;
String reading_date;
int cost_of_elec;
int sales_tax;
int fixed_charges;
int total_amnt;
String due_date;
String bill_paid_status;
String payment_date;
public BillingInfo(){}
public BillingInfo(String cus_id,int billing_m, int curr_reg_meter, int curr_reg_peak, String reading_date,
int cost_of_elec, int sales_tax, int fixed_charges, int total_amnt,
String due_date, String bill_paid_status, String payment_date) {
this.cus_id = cus_id;
this.billing_month=billing_m;
this.curr_reg_meter = curr_reg_meter;
this.curr_reg_peak = curr_reg_peak;
this.reading_date = reading_date;
this.cost_of_elec = cost_of_elec;
this.sales_tax = sales_tax;
this.fixed_charges = fixed_charges;
this.total_amnt = total_amnt;
this.due_date = due_date;
this.bill_paid_status = bill_paid_status;
this.payment_date = payment_date;
}
public void displayBillingInfo() {
System.out.println("Customer ID: " + cus_id);
System.out.println("Billing_Month is "+billing_month);
System.out.println("Current Regular Meter Reading: " + curr_reg_meter);
System.out.println("Current Peak Meter Reading: " + curr_reg_peak);
System.out.println("Reading Date: " + reading_date);
System.out.println("Cost of Electricity: " + cost_of_elec);
System.out.println("Sales Tax: " + sales_tax);
System.out.println("Fixed Charges: " + fixed_charges);
System.out.println("Total Amount: " + total_amnt);
System.out.println("Due Date: " + due_date);
System.out.println("Bill Paid Status: " + bill_paid_status);
System.out.println("Payment Date: " + payment_date);
System.out.println();
}
public static List<BillingInfo> loadBillingData(String filename) {
List<BillingInfo> billingList = new ArrayList<>();
try {
BufferedReader reader = new BufferedReader(new FileReader(filename));
String line;
// Read file line by line
while ((line = reader.readLine()) != null) {
// Remove any extra spaces and split line into parts by comma
String[] parts = line.split(",");
if (parts.length == 12) {
String cus_id = parts[0];
int billing_month=Integer.parseInt(parts[1]);
int curr_reg_meter = Integer.parseInt(parts[2]);
int curr_reg_peak = Integer.parseInt(parts[3]);
String reading_date = parts[4];
int cost_of_elec = Integer.parseInt(parts[5]);
int sales_tax = Integer.parseInt(parts[6]);
int fixed_charges = Integer.parseInt(parts[7]);
int total_amnt = Integer.parseInt(parts[8]);
String due_date = parts[9];
String bill_paid_status = parts[10];
String payment_date = parts[11].trim().equals("0") ? "" : parts[11].trim(); // Handle '0' as empty payment date
// Create new BillingInfo object and add to list
BillingInfo billingInfo = new BillingInfo(cus_id,billing_month, curr_reg_meter, curr_reg_peak, reading_date,
cost_of_elec, sales_tax, fixed_charges, total_amnt, due_date, bill_paid_status, payment_date);
billingList.add(billingInfo);
}
}
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
return billingList;
}
public void Show_Bill_reports(List<BillingInfo> billingInfos)
{
int count1=0;
int count2=0;
for (BillingInfo billingInfo : billingInfos)
{
if(billingInfo.bill_paid_status.equals("paid"))
{
count1++;
}
else
{
count2++;
}
}
System.out.println("The amount of Paid Bills "+count1);
System.out.println("The amount of Unpaid Bills is "+count2);
}
public void view_bill(List<BillingInfo> billingInfos) {
Scanner scanner = new Scanner(System.in);
// Prompt user for customer ID
System.out.print("Enter Customer ID to view the bill: ");
String customerId = scanner.nextLine();
boolean billFound = false;
// Iterate through the list of billing info to find the matching customer ID
for (BillingInfo billingInfo : billingInfos) {
if (billingInfo.cus_id.equals(customerId)) {
// Display billing information
billingInfo.displayBillingInfo();
billFound = true;
break; // Exit the loop once the bill is found and displayed
}
}
if (!billFound) {
System.out.println("No bill found for Customer ID: " + customerId);
}
}
public void update_status(List<BillingInfo> billingInfos, List<Customer> cusInfos) {
Scanner scanner = new Scanner(System.in);
// Prompt user for Customer ID
System.out.print("Enter Customer ID to update bill status: ");
String customerId = scanner.nextLine();
boolean billingInfoFound = false;
boolean customerInfoFound = false;
// Find the corresponding BillingInfo and update the bill paid status
for (BillingInfo billingInfo : billingInfos) {
if (billingInfo.cus_id.equals(customerId)) {
billingInfoFound = true;
// Display current bill status
System.out.println("Current Bill Paid Status: " + billingInfo.bill_paid_status);
// Update bill status
if (billingInfo.bill_paid_status.equals("unpaid")) {
billingInfo.bill_paid_status = "paid"; // Update to paid
System.out.println("Bill status updated to 'paid'.");
// Now update the corresponding customer information if customer is domestic
for (Customer customer : cusInfos) {
if (customer.cus_id.equals(customerId)) {
customerInfoFound = true;
if (customer.Cus_type == 'D') { // Check if customer is domestic
// Prompt the user to enter the updated regular and peak hour units
System.out.print("Enter the updated regular hour units: ");
customer.reg_hour_units = scanner.nextInt();
if (customer.Meter_type.equalsIgnoreCase("3Phase")) {
System.out.print("Enter the updated peak hour units: ");
customer.peak_hour_units = scanner.nextInt();
}
System.out.println("Updated regular and peak hour units have been saved for the customer.");
}
break;
}
}
} else {
System.out.println("Bill is already marked as paid.");
}
break;
}
}
if (!billingInfoFound) {
System.out.println("No billing information found for Customer ID: " + customerId);
} else if (!customerInfoFound) {
System.out.println("No customer information found for Customer ID: " + customerId);
}
// Save updated billing information and customer information back to files
saveBillingData(billingInfos, "C:\\Users\\city\\Desktop\\java\\LESCO_Billing_System_in_Java\\data\\BillingInfo.txt");
saveCustomerData(cusInfos, "C:\\Users\\city\\Desktop\\java\\LESCO_Billing_System_in_Java\\data\\CustomerInfo.txt");
}
// Method to save updated billing information back to the file
// Method to save updated billing information back to the file
private void saveBillingData(List<BillingInfo> billingInfos, String filename) {
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(filename));
// Write each billing info back to the file
for (BillingInfo billingInfo : billingInfos) {
writer.write(billingInfo.cus_id + "," + billingInfo.billing_month + "," + billingInfo.curr_reg_meter + "," + billingInfo.curr_reg_peak + ","
+ billingInfo.reading_date + "," + billingInfo.cost_of_elec + "," + billingInfo.sales_tax + ","
+ billingInfo.fixed_charges + "," + billingInfo.total_amnt + "," + billingInfo.due_date + ","
+ billingInfo.bill_paid_status + "," + (billingInfo.payment_date.equals("") ? "0" : billingInfo.payment_date));
writer.newLine();
}
writer.close();
System.out.println("Billing data updated and saved successfully.");
} catch (IOException e) {
e.printStackTrace();
System.out.println("Error updating billing data.");
}
}
// Method to save updated customer information back to the file
private void saveCustomerData(List<Customer> cusInfos, String filename) {
try {
BufferedWriter writer = new BufferedWriter(new FileWriter(filename));
// Write each customer info back to the file
for (Customer customer : cusInfos) {
writer.write(customer.cus_id + "," + customer.CNIC + "," + customer.Name + "," + customer.Address + ","
+ customer.Phone_no + "," + customer.Cus_type + "," + customer.Meter_type + "," + customer.connec_date + ","
+ customer.reg_hour_units + "," + customer.peak_hour_units);
writer.newLine();
}
writer.close();
System.out.println("Customer data updated and saved successfully.");
} catch (IOException e) {
e.printStackTrace();
System.out.println("Error updating customer data.");
}
}
}