-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddBillController.java
More file actions
206 lines (173 loc) · 6.44 KB
/
Copy pathAddBillController.java
File metadata and controls
206 lines (173 loc) · 6.44 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
package openconsignment.controller.entry.bill;
import static openconsignment.common.Utils.formatDate;
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.*;
import javafx.scene.control.cell.PropertyValueFactory;
import javax.inject.Inject;
import openconsignment.common.Utils;
import openconsignment.entity.BillEntity;
import openconsignment.entity.LREntity;
import openconsignment.model.LR;
import openconsignment.service.*;
import org.controlsfx.control.textfield.TextFields;
public class AddBillController implements Initializable {
@FXML
private TextField supplier_field;
@FXML
private TextField buyer_name_field;
@FXML
private TextField bill_no_field;
@FXML
private TextField transport_field;
@FXML
private DatePicker date_field;
@FXML
private DatePicker lr_date;
@FXML
private TextField bill_amount_field;
@FXML
private TextField pm_field;
@FXML
private TextField lr_field;
@FXML
private Button save_btn;
@FXML
private Button clear_btn;
@FXML
private Button add_btn;
@FXML
private TableView<LR> lrTable;
@FXML
private TableColumn<LR, String> lr_no_col;
@FXML
private TableColumn<LR, String> pm_col;
@FXML
private Button replace_btn;
@FXML
private Button delete_btn;
final ObservableList<LR> lrList = FXCollections.observableArrayList();
private final BillService billService;
private final SupplierService supplierService;
private final BuyerService buyerService;
private final TransportService transportService;
@Inject
public AddBillController(
BillService billService,
SupplierService supplierService,
BuyerService buyerService,
TransportService transportService) {
this.billService = billService;
this.supplierService = supplierService;
this.buyerService = buyerService;
this.transportService = transportService;
}
@Override
public void initialize(URL url, ResourceBundle rb) {
try {
TextFields.bindAutoCompletion(supplier_field, supplierService.getAllSuppliers());
TextFields.bindAutoCompletion(buyer_name_field, buyerService.getAllBuyers());
TextFields.bindAutoCompletion(transport_field, transportService.getAllTransports());
lr_no_col.setCellValueFactory(new PropertyValueFactory<>("lrNo"));
pm_col.setCellValueFactory(new PropertyValueFactory<>("pm"));
} catch (Exception ex) {
Utils.showAlert(ex.toString());
Logger.getLogger(BillEntryController.class.getName()).log(Level.SEVERE, ex.toString(), ex);
}
}
@FXML
private void addToList(ActionEvent event) {
if (bill_no_field.getText().isEmpty()
|| lr_field.getText().isEmpty()
|| pm_field.getText().isEmpty()) {
Utils.showAlert("Please ensure that the Bill No., LR No. and PM fields are filled up properly.", 2);
return;
}
lrList.add(new LR(bill_no_field.getText(), lr_field.getText(), pm_field.getText()));
lrTable.setItems(lrList);
lr_field.clear();
pm_field.clear();
}
@FXML
private void save(ActionEvent event) {
if (supplier_field.getText().isEmpty()
|| buyer_name_field.getText().isEmpty()
|| bill_no_field.getText().isEmpty()
|| date_field.getValue().toString().isEmpty()
|| transport_field.getText().isEmpty()
|| lr_date.getValue().toString().isEmpty()
|| bill_amount_field.getText().isEmpty()
|| lrList.isEmpty()) {
Utils.showAlert("Please ensure to fill up all the fields");
return;
}
List<LREntity> lrEntityList = lrList.stream()
.map(it -> new LREntity(it.getBillNo(), it.getLrNo(), it.getPm()))
.toList();
BillEntity billEntity = BillEntity.builder()
.supplierName(supplier_field.getText())
.buyerName(buyer_name_field.getText())
.billNo(bill_no_field.getText())
.billDate(formatDate(date_field.getValue().toString()))
.transport(transport_field.getText())
.lrDate(formatDate(lr_date.getValue().toString()))
.billAmount(bill_amount_field.getText())
.lrEntities(lrEntityList)
.build();
try {
billService.saveBill(billEntity);
clearAllFields();
Utils.showAlert("Saved Successfully", 1);
} catch (Exception ex) {
Utils.showAlert(ex.toString());
Logger.getLogger(BillEntryController.class.getName()).log(Level.SEVERE, ex.toString(), ex);
}
}
@FXML
private void clearAllFields() {
supplier_field.clear();
buyer_name_field.clear();
bill_no_field.clear();
transport_field.clear();
date_field.setValue(null);
lr_date.setValue(null);
bill_amount_field.clear();
pm_field.clear();
lr_field.clear();
lrList.clear();
}
@FXML
private void replaceInList(ActionEvent event) {
if (lrTable.getSelectionModel().getSelectedIndex() == -1) {
Utils.showAlert("Please select an item from the LR Table", 2);
return;
}
if (bill_no_field.getText().isEmpty()
|| lr_field.getText().isEmpty()
|| pm_field.getText().isEmpty()) {
Utils.showAlert("Please ensure that the Bill No., LR No. and PM fields are filled up properly.", 2);
return;
}
lrList.set(
lrTable.getSelectionModel().getSelectedIndex(),
new LR(bill_no_field.getText(), lr_field.getText(), pm_field.getText()));
lr_field.clear();
pm_field.clear();
}
@FXML
private void deleteFromList(ActionEvent event) {
if (lrTable.getSelectionModel().getSelectedIndex() == -1) {
Utils.showAlert("Please select an item from the LR Table", 2);
return;
}
lrList.remove(lrTable.getSelectionModel().getSelectedIndex());
}
}