Skip to content

Commit a2b9288

Browse files
committed
fix: fixed Add payment
Signed-off-by: Rajdeep Roy Chowdhury <rrajdeeproychowdhury@gmail.com>
1 parent b2b00da commit a2b9288

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

src/main/java/satyamconsignment/common/Constants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22

33
public class Constants {
44
public static final String REPORT_FILE_NAME = "report.pdf";
5+
public static final String DATE_TIME_FORMAT = "dd-MM-yyyy";
56
}

src/main/java/satyamconsignment/ui/Input/BillEntry/AddBill/AddBill.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import javafx.scene.control.*;
1818
import javafx.scene.control.cell.PropertyValueFactory;
1919
import org.controlsfx.control.textfield.TextFields;
20+
import satyamconsignment.common.Constants;
2021
import satyamconsignment.common.DatabaseHandler;
2122
import satyamconsignment.common.Utils;
2223
import satyamconsignment.ui.Input.BillEntry.BillEntryController;
@@ -132,7 +133,7 @@ private void save(ActionEvent event) {
132133
/* Code for saving data into Bill_Entry_Table */
133134
Connection connection = DatabaseHandler.getInstance().getConnection();
134135
try {
135-
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
136+
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(Constants.DATE_TIME_FORMAT);
136137
String sql = "INSERT INTO `Bill_Entry_Table`(`Supplier Name`,`Buyer Name`,`Bill No.`,`Bill Date`,`Transport`,`LR Date`,`Bill Amount`,`Collection Due`,`Due`) VALUES (?,?,?,?,?,?,?,?,?);";
137138

138139
connection.setAutoCommit(false);

src/main/java/satyamconsignment/ui/Input/CollectionEntry/AddCollection/AddCollection.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import javafx.fxml.Initializable;
1616
import javafx.scene.control.*;
1717
import javafx.scene.control.cell.PropertyValueFactory;
18+
import satyamconsignment.common.Constants;
1819
import satyamconsignment.common.DatabaseHandler;
1920
import satyamconsignment.common.Utils;
2021
import satyamconsignment.model.CollectionItem;
@@ -212,7 +213,8 @@ private void addCollection(ActionEvent ignoredEvent) {
212213
return;
213214
}
214215

215-
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
216+
DateTimeFormatter dateTimeFormatter = DateTimeFormatter
217+
.ofPattern(Constants.DATE_TIME_FORMAT);
216218

217219
collectionItemList.add(new CollectionItem(bill_no_combo.getValue(), bill_date.getText(),
218220
bill_amount.getText(), supplier_name.getText(), collection_due_field.getText(),
@@ -312,7 +314,8 @@ private void saveData(ActionEvent ignoredEvent) {
312314
return;
313315
}
314316
Connection connection = DatabaseHandler.getInstance().getConnection();
315-
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
317+
DateTimeFormatter dateTimeFormatter = DateTimeFormatter
318+
.ofPattern(Constants.DATE_TIME_FORMAT);
316319
try {
317320
connection.setAutoCommit(false);
318321
String sql = "INSERT INTO `Collection_Entry_Table`(`Voucher No.`,`Voucher Date`,`Buyer Name`,`Total Amount`) VALUES (?,?,?,?)";

src/main/java/satyamconsignment/ui/Input/PaymentEntry/AddPayment/AddPayment.java

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
import java.sql.ResultSet;
77
import java.sql.SQLException;
88
import java.time.format.DateTimeFormatter;
9-
import java.util.HashMap;
10-
import java.util.List;
11-
import java.util.Map;
12-
import java.util.ResourceBundle;
9+
import java.util.*;
1310
import java.util.logging.Level;
1411
import java.util.logging.Logger;
1512
import javafx.collections.FXCollections;
@@ -19,14 +16,14 @@
1916
import javafx.scene.control.*;
2017
import javafx.scene.control.cell.PropertyValueFactory;
2118
import javafx.scene.text.Text;
19+
import satyamconsignment.common.Constants;
2220
import satyamconsignment.common.DatabaseHandler;
2321
import satyamconsignment.common.Utils;
2422
import satyamconsignment.ui.Input.PaymentEntry.PaymentEntryController;
2523
import satyamconsignment.model.PaymentItem;
2624

2725
public class AddPayment implements Initializable {
2826

29-
private DateTimeFormatter formatter;
3027
private List<PaymentItem> paymentItems;
3128
private List<String> supplierNameComboList;
3229
private List<String> billNoComboList;
@@ -97,10 +94,9 @@ public class AddPayment implements Initializable {
9794

9895
@Override
9996
public void initialize(URL url, ResourceBundle rb) {
100-
formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
101-
paymentItems = FXCollections.observableArrayList();
102-
supplierNameComboList = FXCollections.observableArrayList();
103-
billNoComboList = FXCollections.observableArrayList();
97+
paymentItems = new ArrayList<>();
98+
supplierNameComboList = new ArrayList<>();
99+
billNoComboList = new ArrayList<>();
104100

105101
bill_no_col.setCellValueFactory(new PropertyValueFactory<>("billNo"));
106102
bill_amt_col.setCellValueFactory(new PropertyValueFactory<>("billAmount"));
@@ -112,12 +108,16 @@ public void initialize(URL url, ResourceBundle rb) {
112108
due_col.setCellValueFactory(new PropertyValueFactory<>("due"));
113109
amount_paid_col.setCellValueFactory(new PropertyValueFactory<>("amountPaid"));
114110

115-
payment_tableview.setItems(FXCollections.observableArrayList(paymentItems));
111+
refreshPaymentTableView();
116112
fillSupplierCombo();
117113

118114
updateLastVoucher();
119115
}
120116

117+
private void refreshPaymentTableView() {
118+
payment_tableview.setItems(FXCollections.observableArrayList(paymentItems));
119+
}
120+
121121
@FXML
122122
private void addPayment(ActionEvent ignoredEvent) {
123123
if (bill_no_combo.getValue().isEmpty() || bill_amount_field.getText().isEmpty()
@@ -130,12 +130,15 @@ private void addPayment(ActionEvent ignoredEvent) {
130130
return;
131131
}
132132

133+
DateTimeFormatter dateTimeFormatter = DateTimeFormatter
134+
.ofPattern(Constants.DATE_TIME_FORMAT);
135+
133136
paymentItems.add(new PaymentItem(bill_no_combo.getValue(), bill_amount_field.getText(),
134137
bill_date_field.getText(), buyer_name_field.getText(), due_amount_field.getText(),
135138
amount_paid_field.getText(), bank_field.getText(), dd_no_field.getText(),
136-
formatter.format(dd_date_field.getValue())));
139+
dateTimeFormatter.format(dd_date_field.getValue())));
137140

138-
payment_tableview.setItems(FXCollections.observableArrayList(paymentItems));
141+
refreshPaymentTableView();
139142

140143
clearRepeatingFields();
141144
updateTotalAmountPaid();
@@ -159,12 +162,18 @@ private void replacePayment(ActionEvent ignoredEvent) {
159162
return;
160163
}
161164

165+
DateTimeFormatter dateTimeFormatter = DateTimeFormatter
166+
.ofPattern(Constants.DATE_TIME_FORMAT);
167+
162168
paymentItems.set(payment_tableview.getSelectionModel().getSelectedIndex(),
163169
new PaymentItem(bill_no_combo.getValue(), bill_amount_field.getText(),
164170
bill_date_field.getText(), buyer_name_field.getText(),
165171
due_amount_field.getText(), amount_paid_field.getText(),
166172
bank_field.getText(), dd_no_field.getText(),
167-
formatter.format(dd_date_field.getValue())));
173+
dateTimeFormatter.format(dd_date_field.getValue())));
174+
175+
refreshPaymentTableView();
176+
168177
clearRepeatingFields();
169178
updateTotalAmountPaid();
170179
}
@@ -176,6 +185,7 @@ private void deletePayment(ActionEvent ignoredEvent) {
176185
return;
177186
}
178187
paymentItems.remove(payment_tableview.getSelectionModel().getSelectedIndex());
188+
refreshPaymentTableView();
179189
updateTotalAmountPaid();
180190
}
181191

@@ -216,12 +226,14 @@ private void saveData(ActionEvent ignoredEvent) {
216226
return;
217227
}
218228
Connection connection = DatabaseHandler.getInstance().getConnection();
229+
DateTimeFormatter dateTimeFormatter = DateTimeFormatter
230+
.ofPattern(Constants.DATE_TIME_FORMAT);
219231
try {
220232
connection.setAutoCommit(false);
221233
String sql = "INSERT INTO `Payment_Entry_Table`(`Voucher No.`,`Voucher Date`,`Supplier Name`,`Total Amount`) VALUES (?,?,?,?)";
222234
PreparedStatement preparedStatement = connection.prepareStatement(sql);
223235
preparedStatement.setString(1, voucher_no_field.getText());
224-
preparedStatement.setString(2, formatter.format(voucher_date_field.getValue()));
236+
preparedStatement.setString(2, dateTimeFormatter.format(voucher_date_field.getValue()));
225237
preparedStatement.setString(3, supplier_name_combo.getValue());
226238
preparedStatement.setString(4, total_amount_paid_field.getText());
227239
preparedStatement.execute();
@@ -263,6 +275,7 @@ private void saveData(ActionEvent ignoredEvent) {
263275
Logger.getLogger(PaymentEntryController.class.getName()).log(Level.SEVERE, null, ex);
264276
}
265277
paymentItems.clear();
278+
refreshPaymentTableView();
266279
}
267280

268281
private void updateLastVoucher() {

0 commit comments

Comments
 (0)