-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewDeletePaymentController.java
More file actions
190 lines (152 loc) · 6.26 KB
/
Copy pathViewDeletePaymentController.java
File metadata and controls
190 lines (152 loc) · 6.26 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
package openconsignment.controller.entry.payment;
import java.io.IOException;
import java.net.URL;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import net.sf.jasperreports.engine.*;
import openconsignment.common.Constants;
import openconsignment.common.DatabaseHandler;
import openconsignment.common.Utils;
import openconsignment.entity.PaymentEntity;
import openconsignment.model.PaymentItem;
import openconsignment.repository.PaymentRepository;
import openconsignment.service.PaymentService;
public class ViewDeletePaymentController implements Initializable {
@FXML
private TextField voucher_no_field;
@FXML
private TableColumn<?, ?> bill_no_col;
@FXML
private TableColumn<?, ?> bill_amt_col;
@FXML
private TableColumn<?, ?> bill_date_col;
@FXML
private TableColumn<?, ?> buyer_col;
@FXML
private TableColumn<?, ?> amount_paid_col;
@FXML
private TableColumn<?, ?> bank_col;
@FXML
private TableColumn<?, ?> dd_no_col;
@FXML
private TableColumn<?, ?> dd_date_col;
@FXML
private Label display_board_label;
@FXML
private TextField total_amount_field;
@FXML
private Button get_details_btn;
@FXML
private Button delete_entry_btn;
@FXML
private TextField voucher_date;
@FXML
private TextField supplier_name;
@FXML
private TableColumn<?, ?> due_col;
@FXML
private TableView<PaymentItem> payment_tableview;
@FXML
private Button print_payment_btn;
private PaymentService paymentService;
@Override
public void initialize(URL url, ResourceBundle rb) {
paymentService = new PaymentService(new PaymentRepository());
bill_no_col.setCellValueFactory(new PropertyValueFactory<>("billNo"));
bill_amt_col.setCellValueFactory(new PropertyValueFactory<>("billAmount"));
buyer_col.setCellValueFactory(new PropertyValueFactory<>("buyerName"));
bill_date_col.setCellValueFactory(new PropertyValueFactory<>("billDate"));
due_col.setCellValueFactory(new PropertyValueFactory<>("due"));
amount_paid_col.setCellValueFactory(new PropertyValueFactory<>("amountPaid"));
dd_no_col.setCellValueFactory(new PropertyValueFactory<>("ddNo"));
bank_col.setCellValueFactory(new PropertyValueFactory<>("bank"));
dd_date_col.setCellValueFactory(new PropertyValueFactory<>("ddDate"));
}
@FXML
private void getDetails(ActionEvent event) {
if (voucher_no_field.getText().isEmpty()) {
Utils.showAlert("Voucher No. Field is kept empty. Please fill the voucher no.");
return;
}
try {
PaymentEntity paymentEntity = paymentService.getPayment(voucher_no_field.getText());
if (null == paymentEntity) {
Utils.showAlert("Payment voucher not found");
return;
}
List<PaymentItem> paymentItemList = paymentEntity.getItems().stream()
.map(it -> PaymentItem.builder()
.billNo(it.getBillNo())
.billAmount(it.getBillAmount())
.billDate(it.getBillDate())
.buyerName(it.getBuyerName())
.amountPaid(it.getAmountPaid())
.bank(it.getBank())
.ddNo(it.getDdNo())
.ddDate(it.getDdDate())
.build())
.toList();
voucher_date.setText(paymentEntity.getVoucherDate());
supplier_name.setText(paymentEntity.getSupplierName());
total_amount_field.setText(paymentEntity.getTotalAmount());
display_board_label.setText(paymentEntity.getSupplierName());
payment_tableview.setItems(FXCollections.observableArrayList(paymentItemList));
delete_entry_btn.setDisable(false);
} catch (SQLException ex) {
Utils.showAlert(ex.toString());
Logger.getLogger(ViewDeletePaymentController.class.getName()).log(Level.SEVERE, ex.toString(), ex);
}
}
@FXML
private void deleteEntry(ActionEvent event) {
Alert alert = new Alert(
Alert.AlertType.CONFIRMATION,
"Are you sure that you want delete " + voucher_no_field.getText() + " ?",
ButtonType.YES,
ButtonType.NO,
ButtonType.CANCEL);
alert.showAndWait();
if (alert.getResult() != ButtonType.YES) {
return;
}
Connection conn = DatabaseHandler.getInstance().getConnection();
try {
paymentService.deletePayment(voucher_no_field.getText());
payment_tableview.setItems(FXCollections.observableArrayList());
voucher_date.setText("");
supplier_name.setText("");
display_board_label.setText("");
total_amount_field.setText("");
Utils.showAlert(voucher_no_field.getText().toUpperCase() + " Entry was successfully deleted.", 1);
} catch (SQLException ex) {
Utils.showAlert(ex.toString());
try {
conn.rollback();
} catch (SQLException ex1) {
Utils.showAlert(ex1.toString());
Logger.getLogger(PaymentEntryController.class.getName()).log(Level.SEVERE, ex1.toString(), ex1);
}
Logger.getLogger(PaymentEntryController.class.getName()).log(Level.SEVERE, ex.toString(), ex);
}
}
@FXML
private void printPayment(ActionEvent event) {
try {
paymentService.generatePdf(voucher_no_field.getText());
Utils.launchPdf(Constants.REPORT_FILE_NAME);
Utils.showAlert("Report Successfully Generated", 1);
} catch (IOException | JRException | SQLException ex) {
Utils.showAlert(ex.toString());
Logger.getLogger(PaymentEntryController.class.getName()).log(Level.SEVERE, ex.toString(), ex);
}
}
}