|
1 | 1 | package satyamconsignment.ui.Input.PaymentEntry.ViewAndDeletePayment; |
2 | 2 |
|
3 | | -import java.io.IOException; |
4 | 3 | import java.net.URL; |
5 | 4 | import java.sql.Connection; |
6 | 5 | import java.sql.PreparedStatement; |
7 | 6 | import java.sql.ResultSet; |
8 | 7 | import java.sql.SQLException; |
9 | | -import java.time.format.DateTimeFormatter; |
10 | | -import java.util.HashMap; |
11 | | -import java.util.Map; |
12 | | -import java.util.ResourceBundle; |
| 8 | +import java.util.*; |
13 | 9 | import java.util.logging.Level; |
14 | 10 | import java.util.logging.Logger; |
15 | 11 | import javafx.collections.FXCollections; |
16 | | -import javafx.collections.ObservableList; |
17 | 12 | import javafx.event.ActionEvent; |
18 | 13 | import javafx.fxml.FXML; |
19 | | -import javafx.fxml.FXMLLoader; |
20 | 14 | import javafx.fxml.Initializable; |
21 | | -import javafx.scene.Group; |
22 | | -import javafx.scene.Parent; |
23 | 15 | import javafx.scene.control.*; |
24 | 16 | import javafx.scene.control.cell.PropertyValueFactory; |
25 | | -import javafx.scene.text.Text; |
26 | 17 | import net.sf.jasperreports.engine.*; |
| 18 | +import satyamconsignment.common.Constants; |
27 | 19 | import satyamconsignment.common.DatabaseHandler; |
28 | 20 | import satyamconsignment.common.Utils; |
29 | 21 | import satyamconsignment.ui.Input.CollectionEntry.CollectionEntryController; |
30 | 22 | import satyamconsignment.ui.Input.PaymentEntry.PaymentEntryController; |
31 | 23 | import satyamconsignment.model.PaymentItem; |
32 | 24 |
|
33 | 25 | public class ViewAndDeletePayment implements Initializable { |
34 | | - // My variables |
35 | | - Utils utils; |
36 | | - DatabaseHandler databaseHandler; |
37 | | - Connection conn; |
38 | | - PreparedStatement ps; |
39 | | - ResultSet rs; |
40 | | - String sql; |
41 | | - DateTimeFormatter formatter; |
42 | | - ObservableList<PaymentItem> list; |
43 | | - ObservableList<String> supplierNameComboList; |
44 | | - ObservableList<String> billNoComboList; |
45 | | - int previouslyDue; |
46 | | - int totalAmountPaid; |
| 26 | + |
47 | 27 | @FXML |
48 | | - private TextField voucher_no_field_2; |
49 | | - private TableView<?> collection_tableview_2; |
| 28 | + private TextField voucher_no_field; |
50 | 29 | @FXML |
51 | | - private TableColumn<?, ?> bill_no_col_2; |
| 30 | + private TableColumn<?, ?> bill_no_col; |
52 | 31 | @FXML |
53 | | - private TableColumn<?, ?> bill_amt_col_2; |
| 32 | + private TableColumn<?, ?> bill_amt_col; |
54 | 33 | @FXML |
55 | | - private TableColumn<?, ?> bill_date_col_2; |
| 34 | + private TableColumn<?, ?> bill_date_col; |
56 | 35 | @FXML |
57 | | - private TableColumn<?, ?> buyer_col_2; |
58 | | - private TableColumn<?, ?> gr_col_2; |
59 | | - private TableColumn<?, ?> rd_col_2; |
60 | | - private TableColumn<?, ?> cd_col_2; |
61 | | - private TableColumn<?, ?> bc_col_2; |
| 36 | + private TableColumn<?, ?> buyer_col; |
62 | 37 | @FXML |
63 | | - private TableColumn<?, ?> amount_paid_col_2; |
| 38 | + private TableColumn<?, ?> amount_paid_col; |
64 | 39 | @FXML |
65 | | - private TableColumn<?, ?> bank_col_2; |
| 40 | + private TableColumn<?, ?> bank_col; |
66 | 41 | @FXML |
67 | | - private TableColumn<?, ?> dd_no_col_2; |
| 42 | + private TableColumn<?, ?> dd_no_col; |
68 | 43 | @FXML |
69 | | - private TableColumn<?, ?> dd_date_col_2; |
| 44 | + private TableColumn<?, ?> dd_date_col; |
70 | 45 | @FXML |
71 | | - private Label display_board_label_2; |
| 46 | + private Label display_board_label; |
72 | 47 | @FXML |
73 | | - private TextField total_amount_field_2; |
| 48 | + private TextField total_amount_field; |
74 | 49 | @FXML |
75 | 50 | private Button get_details_btn; |
76 | 51 | @FXML |
77 | 52 | private Button delete_entry_btn; |
78 | 53 | @FXML |
79 | | - private TextField voucher_date_2; |
80 | | - @FXML |
81 | | - private TextField supplier_name_2; |
| 54 | + private TextField voucher_date; |
82 | 55 | @FXML |
83 | | - private TableColumn<?, ?> due_col_2; |
| 56 | + private TextField supplier_name; |
84 | 57 | @FXML |
85 | | - private TableView<PaymentItem> payment_tableview_2; |
| 58 | + private TableColumn<?, ?> due_col; |
86 | 59 | @FXML |
87 | | - private Group root2; |
| 60 | + private TableView<PaymentItem> payment_tableview; |
88 | 61 | @FXML |
89 | 62 | private Button print_payment_btn; |
90 | | - @FXML |
91 | | - private Text last_voucher_field; |
92 | 63 |
|
93 | 64 | @Override |
94 | 65 | public void initialize(URL url, ResourceBundle rb) { |
95 | | - utils = new Utils(); |
96 | | - databaseHandler = DatabaseHandler.getInstance(); |
97 | | - conn = databaseHandler.getConnection(); |
98 | | - formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); |
99 | | - list = FXCollections.observableArrayList(); |
100 | | - supplierNameComboList = FXCollections.observableArrayList(); |
101 | | - billNoComboList = FXCollections.observableArrayList(); |
102 | | - |
103 | | - bill_no_col_2.setCellValueFactory(new PropertyValueFactory("billNo")); |
104 | | - bill_amt_col_2.setCellValueFactory(new PropertyValueFactory("billAmount")); |
105 | | - buyer_col_2.setCellValueFactory(new PropertyValueFactory("buyerName")); |
106 | | - bill_date_col_2.setCellValueFactory(new PropertyValueFactory("billDate")); |
107 | | - due_col_2.setCellValueFactory(new PropertyValueFactory("due")); |
108 | | - amount_paid_col_2.setCellValueFactory(new PropertyValueFactory("amountPaid")); |
109 | | - dd_no_col_2.setCellValueFactory(new PropertyValueFactory("ddNo")); |
110 | | - bank_col_2.setCellValueFactory(new PropertyValueFactory("bank")); |
111 | | - dd_date_col_2.setCellValueFactory(new PropertyValueFactory("ddDate")); |
| 66 | + bill_no_col.setCellValueFactory(new PropertyValueFactory<>("billNo")); |
| 67 | + bill_amt_col.setCellValueFactory(new PropertyValueFactory<>("billAmount")); |
| 68 | + buyer_col.setCellValueFactory(new PropertyValueFactory<>("buyerName")); |
| 69 | + bill_date_col.setCellValueFactory(new PropertyValueFactory<>("billDate")); |
| 70 | + due_col.setCellValueFactory(new PropertyValueFactory<>("due")); |
| 71 | + amount_paid_col.setCellValueFactory(new PropertyValueFactory<>("amountPaid")); |
| 72 | + dd_no_col.setCellValueFactory(new PropertyValueFactory<>("ddNo")); |
| 73 | + bank_col.setCellValueFactory(new PropertyValueFactory<>("bank")); |
| 74 | + dd_date_col.setCellValueFactory(new PropertyValueFactory<>("ddDate")); |
112 | 75 | } |
113 | 76 |
|
114 | 77 | @FXML |
115 | 78 | private void getDetails(ActionEvent event) { |
116 | | - // Copy Paste Edit |
117 | 79 |
|
118 | | - if (voucher_no_field_2.getText().isEmpty()) { |
| 80 | + if (voucher_no_field.getText().isEmpty()) { |
119 | 81 | Utils.showAlert("Voucher No. Field is kept empty. Please fill the voucher no."); |
120 | | - } else { |
121 | | - try { |
122 | | - sql = "select * from `Payment_Entry_Table` where `Voucher No.`=? collate nocase"; |
123 | | - ps = conn.prepareStatement(sql); |
124 | | - ps.setString(1, voucher_no_field_2.getText()); |
125 | | - rs = ps.executeQuery(); |
| 82 | + return; |
| 83 | + } |
| 84 | + try { |
| 85 | + String sql = "select * from `Payment_Entry_Table` where `Voucher No.`=? collate nocase"; |
| 86 | + Connection conn = DatabaseHandler.getInstance().getConnection(); |
| 87 | + PreparedStatement ps = conn.prepareStatement(sql); |
| 88 | + ps.setString(1, voucher_no_field.getText()); |
| 89 | + ResultSet rs = ps.executeQuery(); |
126 | 90 |
|
127 | | - voucher_date_2.setText(rs.getString("Voucher Date")); |
128 | | - supplier_name_2.setText(rs.getString("Supplier Name")); |
129 | | - total_amount_field_2.setText(rs.getString("Total Amount")); |
130 | | - display_board_label_2.setText(rs.getString("Supplier Name")); |
| 91 | + voucher_date.setText(rs.getString("Voucher Date")); |
| 92 | + supplier_name.setText(rs.getString("Supplier Name")); |
| 93 | + total_amount_field.setText(rs.getString("Total Amount")); |
| 94 | + display_board_label.setText(rs.getString("Supplier Name")); |
131 | 95 |
|
132 | | - list.clear(); |
133 | | - sql = "select * from `Payment_Entry_Extended_Table` where `Voucher No.`=? collate nocase"; |
134 | | - ps = conn.prepareStatement(sql); |
135 | | - ps.setString(1, voucher_no_field_2.getText()); |
136 | | - rs = ps.executeQuery(); |
137 | | - if (rs.isClosed()) { |
138 | | - Utils.showAlert("No Results found", 1); |
139 | | - } else { |
140 | | - while (rs.next()) { |
141 | | - PaymentItem paymentItem = PaymentItem.builder() |
142 | | - .billNo(rs.getString("Bill No.")) |
143 | | - .billAmount(rs.getString("Bill Amount")) |
144 | | - .billDate(rs.getString("Bill Date")) |
145 | | - .buyerName(rs.getString("Buyer Name")) |
146 | | - .due(rs.getString("due amount")) |
147 | | - .amountPaid(rs.getString("amount paid")).bank(rs.getString("bank")) |
148 | | - .ddNo(rs.getString("DD No.")).ddDate(rs.getString("DD Date")) |
149 | | - .build(); |
150 | | - |
151 | | - list.add(paymentItem); |
152 | | - } |
153 | | - payment_tableview_2.setItems(list); |
154 | | - delete_entry_btn.setDisable(false); |
| 96 | + List<PaymentItem> list = new ArrayList<>(); |
| 97 | + sql = "select * from `Payment_Entry_Extended_Table` where `Voucher No.`=? collate nocase"; |
| 98 | + ps = conn.prepareStatement(sql); |
| 99 | + ps.setString(1, voucher_no_field.getText()); |
| 100 | + rs = ps.executeQuery(); |
| 101 | + if (rs.isClosed()) { |
| 102 | + Utils.showAlert("No Results found", 1); |
| 103 | + } else { |
| 104 | + while (rs.next()) { |
| 105 | + PaymentItem paymentItem = PaymentItem.builder().billNo(rs.getString("Bill No.")) |
| 106 | + .billAmount(rs.getString("Bill Amount")) |
| 107 | + .billDate(rs.getString("Bill Date")) |
| 108 | + .buyerName(rs.getString("Buyer Name")).due(rs.getString("due amount")) |
| 109 | + .amountPaid(rs.getString("amount paid")).bank(rs.getString("bank")) |
| 110 | + .ddNo(rs.getString("DD No.")).ddDate(rs.getString("DD Date")).build(); |
| 111 | + |
| 112 | + list.add(paymentItem); |
155 | 113 | } |
156 | | - } catch (SQLException ex) { |
157 | | - Utils.showAlert(ex.toString()); |
158 | | - Logger.getLogger(CollectionEntryController.class.getName()).log(Level.SEVERE, null, |
159 | | - ex); |
| 114 | + payment_tableview.setItems(FXCollections.observableArrayList(list)); |
| 115 | + delete_entry_btn.setDisable(false); |
160 | 116 | } |
| 117 | + } catch (SQLException ex) { |
| 118 | + Utils.showAlert(ex.toString()); |
| 119 | + Logger.getLogger(CollectionEntryController.class.getName()).log(Level.SEVERE, null, ex); |
161 | 120 | } |
| 121 | + |
162 | 122 | } |
163 | 123 |
|
164 | 124 | @FXML |
165 | 125 | private void deleteEntry(ActionEvent event) { |
166 | 126 | Alert alert = new Alert(Alert.AlertType.CONFIRMATION, |
167 | | - "Are you sure that you want delete " + voucher_no_field_2.getText() + " ?", |
| 127 | + "Are you sure that you want delete " + voucher_no_field.getText() + " ?", |
168 | 128 | ButtonType.YES, ButtonType.NO, ButtonType.CANCEL); |
169 | 129 | alert.showAndWait(); |
170 | 130 |
|
171 | | - if (alert.getResult() == ButtonType.YES) { |
172 | | - try { |
173 | | - conn.setAutoCommit(false); |
174 | | - sql = "SELECT `Bill No.`,`Amount Paid` FROM `Payment_Entry_Extended_Table` where `Voucher No.`=? collate nocase"; |
175 | | - ps = conn.prepareStatement(sql); |
176 | | - ps.setString(1, voucher_no_field_2.getText()); |
177 | | - rs = ps.executeQuery(); |
178 | | - while (rs.next()) { |
179 | | - sql = "UPDATE `Bill_Entry_Table` SET `Due`=`Due`+? WHERE `BILL NO.`=?"; |
180 | | - ps = conn.prepareStatement(sql); |
181 | | - ps.setString(1, rs.getString("Amount Paid")); |
182 | | - ps.setString(2, rs.getString("Bill No.")); |
183 | | - ps.execute(); |
184 | | - } |
185 | | - sql = "DELETE FROM `Payment_Entry_Table` where `Voucher No.`=? collate nocase"; |
186 | | - ps = conn.prepareStatement(sql); |
187 | | - ps.setString(1, voucher_no_field_2.getText()); |
188 | | - ps.execute(); |
| 131 | + if (alert.getResult() != ButtonType.YES) { |
| 132 | + return; |
| 133 | + } |
189 | 134 |
|
190 | | - sql = "DELETE FROM `Payment_Entry_Extended_Table` where `Voucher No.`=? collate nocase"; |
| 135 | + Connection conn = DatabaseHandler.getInstance().getConnection(); |
| 136 | + |
| 137 | + try { |
| 138 | + conn.setAutoCommit(false); |
| 139 | + String sql = "SELECT `Bill No.`,`Amount Paid` FROM `Payment_Entry_Extended_Table` where `Voucher No.`=? collate nocase"; |
| 140 | + PreparedStatement ps = conn.prepareStatement(sql); |
| 141 | + ps.setString(1, voucher_no_field.getText()); |
| 142 | + ResultSet rs = ps.executeQuery(); |
| 143 | + while (rs.next()) { |
| 144 | + sql = "UPDATE `Bill_Entry_Table` SET `Due`=`Due`+? WHERE `BILL NO.`=?"; |
191 | 145 | ps = conn.prepareStatement(sql); |
192 | | - ps.setString(1, voucher_no_field_2.getText()); |
| 146 | + ps.setString(1, rs.getString("Amount Paid")); |
| 147 | + ps.setString(2, rs.getString("Bill No.")); |
193 | 148 | ps.execute(); |
194 | | - list.clear(); |
195 | | - |
196 | | - voucher_date_2.setText(""); |
197 | | - supplier_name_2.setText(""); |
198 | | - display_board_label_2.setText(""); |
199 | | - total_amount_field_2.setText(""); |
200 | | - conn.commit(); |
201 | | - Utils.showAlert(voucher_no_field_2.getText().toUpperCase() |
202 | | - + " Entry was successfully deleted.", 1); |
203 | | - } catch (SQLException ex) { |
204 | | - Utils.showAlert(ex.toString()); |
205 | | - try { |
206 | | - conn.rollback(); |
207 | | - } catch (SQLException ex1) { |
208 | | - Utils.showAlert(ex1.toString()); |
209 | | - Logger.getLogger(PaymentEntryController.class.getName()).log(Level.SEVERE, null, |
210 | | - ex1); |
211 | | - } |
212 | | - Logger.getLogger(PaymentEntryController.class.getName()).log(Level.SEVERE, null, |
213 | | - ex); |
214 | 149 | } |
215 | | - } |
216 | | - } |
| 150 | + sql = "DELETE FROM `Payment_Entry_Table` where `Voucher No.`=? collate nocase"; |
| 151 | + ps = conn.prepareStatement(sql); |
| 152 | + ps.setString(1, voucher_no_field.getText()); |
| 153 | + ps.execute(); |
217 | 154 |
|
218 | | - private void loadScreenAgain() { |
219 | | - try { |
220 | | - Parent parent = FXMLLoader.load(getClass() |
221 | | - .getResource("/satyamconsignment/ui/Input/PaymentEntry/PaymentEntry.fxml")); |
222 | | - root2.getChildren().setAll(parent); |
223 | | - } catch (IOException ex) { |
| 155 | + sql = "DELETE FROM `Payment_Entry_Extended_Table` where `Voucher No.`=? collate nocase"; |
| 156 | + ps = conn.prepareStatement(sql); |
| 157 | + ps.setString(1, voucher_no_field.getText()); |
| 158 | + ps.execute(); |
| 159 | + |
| 160 | + payment_tableview.setItems(FXCollections.observableArrayList()); |
| 161 | + |
| 162 | + voucher_date.setText(""); |
| 163 | + supplier_name.setText(""); |
| 164 | + display_board_label.setText(""); |
| 165 | + total_amount_field.setText(""); |
| 166 | + conn.commit(); |
| 167 | + Utils.showAlert( |
| 168 | + voucher_no_field.getText().toUpperCase() + " Entry was successfully deleted.", |
| 169 | + 1); |
| 170 | + } catch (SQLException ex) { |
224 | 171 | Utils.showAlert(ex.toString()); |
225 | | - Logger.getLogger(PaymentEntryController.class.getName()).log(Level.SEVERE, null, ex); |
| 172 | + try { |
| 173 | + conn.rollback(); |
| 174 | + } catch (SQLException ex1) { |
| 175 | + Utils.showAlert(ex1.toString()); |
| 176 | + Logger.getLogger(PaymentEntryController.class.getName()).log(Level.SEVERE, |
| 177 | + ex1.toString(), ex1); |
| 178 | + } |
| 179 | + Logger.getLogger(PaymentEntryController.class.getName()).log(Level.SEVERE, |
| 180 | + ex.toString(), ex); |
226 | 181 | } |
| 182 | + |
227 | 183 | } |
228 | 184 |
|
229 | 185 | @FXML |
230 | 186 | private void printPayment(ActionEvent event) { |
231 | 187 | try { |
232 | | - String pdfFileName = "Report.pdf"; |
| 188 | + Connection conn = DatabaseHandler.getInstance().getConnection(); |
233 | 189 | String jrxmlFileName = "Payment.jrxml"; |
234 | 190 | JasperReport jasperReport = JasperCompileManager |
235 | 191 | .compileReport(getClass().getResourceAsStream(jrxmlFileName)); |
236 | | - Map map = new HashMap(); |
237 | | - map.put("voucherNo", voucher_no_field_2.getText()); |
238 | | - map.put("voucherDate", voucher_date_2.getText()); |
239 | | - map.put("supplierName", supplier_name_2.getText()); |
240 | | - map.put("billAmount", total_amount_field_2.getText()); |
| 192 | + Map<String, Object> map = new HashMap<>(); |
| 193 | + map.put("voucherNo", voucher_no_field.getText()); |
| 194 | + map.put("voucherDate", voucher_date.getText()); |
| 195 | + map.put("supplierName", supplier_name.getText()); |
| 196 | + map.put("billAmount", total_amount_field.getText()); |
241 | 197 | JasperPrint jprint = JasperFillManager.fillReport(jasperReport, map, conn); |
242 | | - JasperExportManager.exportReportToPdfFile(jprint, pdfFileName); |
| 198 | + JasperExportManager.exportReportToPdfFile(jprint, Constants.REPORT_FILE_NAME); |
243 | 199 | Utils.showAlert("Report Successfully Generated", 1); |
244 | 200 | } catch (JRException ex) { |
245 | 201 | Utils.showAlert(ex.toString()); |
246 | | - Logger.getLogger(PaymentEntryController.class.getName()).log(Level.SEVERE, null, ex); |
| 202 | + Logger.getLogger(PaymentEntryController.class.getName()).log(Level.SEVERE, |
| 203 | + ex.toString(), ex); |
247 | 204 | } |
248 | 205 | } |
249 | 206 | } |
0 commit comments